@drincs/pixi-vn 0.5.3 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/classes/CharacterBaseModel.js +110 -112
  2. package/dist/classes/CharacterBaseModel.js.map +1 -1
  3. package/dist/classes/CharacterBaseModel.mjs +110 -112
  4. package/dist/classes/CharacterBaseModel.mjs.map +1 -1
  5. package/dist/classes/ChoiceMenuOption.d.mts +19 -7
  6. package/dist/classes/ChoiceMenuOption.d.ts +19 -7
  7. package/dist/classes/ChoiceMenuOption.js +1386 -9
  8. package/dist/classes/ChoiceMenuOption.js.map +1 -1
  9. package/dist/classes/ChoiceMenuOption.mjs +1386 -9
  10. package/dist/classes/ChoiceMenuOption.mjs.map +1 -1
  11. package/dist/classes/CloseLabel.d.mts +8 -5
  12. package/dist/classes/CloseLabel.d.ts +8 -5
  13. package/dist/classes/CloseLabel.js +44 -4
  14. package/dist/classes/CloseLabel.js.map +1 -1
  15. package/dist/classes/CloseLabel.mjs +41 -4
  16. package/dist/classes/CloseLabel.mjs.map +1 -1
  17. package/dist/classes/Label.d.mts +47 -21
  18. package/dist/classes/Label.d.ts +47 -21
  19. package/dist/classes/Label.js +36 -1
  20. package/dist/classes/Label.js.map +1 -1
  21. package/dist/classes/Label.mjs +36 -1
  22. package/dist/classes/Label.mjs.map +1 -1
  23. package/dist/classes/StoredClassModel.js +55 -57
  24. package/dist/classes/StoredClassModel.js.map +1 -1
  25. package/dist/classes/StoredClassModel.mjs +55 -57
  26. package/dist/classes/StoredClassModel.mjs.map +1 -1
  27. package/dist/classes/index.d.mts +2 -2
  28. package/dist/classes/index.d.ts +2 -2
  29. package/dist/classes/index.js +125 -73
  30. package/dist/classes/index.js.map +1 -1
  31. package/dist/classes/index.mjs +125 -73
  32. package/dist/classes/index.mjs.map +1 -1
  33. package/dist/classes/ticker/TickerFadeAlpha.js +27 -27
  34. package/dist/classes/ticker/TickerFadeAlpha.js.map +1 -1
  35. package/dist/classes/ticker/TickerFadeAlpha.mjs +27 -27
  36. package/dist/classes/ticker/TickerFadeAlpha.mjs.map +1 -1
  37. package/dist/classes/ticker/TickerMove.js +57 -55
  38. package/dist/classes/ticker/TickerMove.js.map +1 -1
  39. package/dist/classes/ticker/TickerMove.mjs +57 -55
  40. package/dist/classes/ticker/TickerMove.mjs.map +1 -1
  41. package/dist/classes/ticker/TickerRotate.js +57 -55
  42. package/dist/classes/ticker/TickerRotate.js.map +1 -1
  43. package/dist/classes/ticker/TickerRotate.mjs +57 -55
  44. package/dist/classes/ticker/TickerRotate.mjs.map +1 -1
  45. package/dist/classes/ticker/index.js +17 -17
  46. package/dist/classes/ticker/index.js.map +1 -1
  47. package/dist/classes/ticker/index.mjs +17 -17
  48. package/dist/classes/ticker/index.mjs.map +1 -1
  49. package/dist/constants.d.mts +1 -1
  50. package/dist/constants.d.ts +1 -1
  51. package/dist/constants.js +1 -1
  52. package/dist/constants.js.map +1 -1
  53. package/dist/constants.mjs +1 -1
  54. package/dist/constants.mjs.map +1 -1
  55. package/dist/decorators/LabelDecorator.d.mts +13 -20
  56. package/dist/decorators/LabelDecorator.d.ts +13 -20
  57. package/dist/decorators/LabelDecorator.js +1388 -28
  58. package/dist/decorators/LabelDecorator.js.map +1 -1
  59. package/dist/decorators/LabelDecorator.mjs +1388 -25
  60. package/dist/decorators/LabelDecorator.mjs.map +1 -1
  61. package/dist/decorators/index.d.mts +4 -4
  62. package/dist/decorators/index.d.ts +4 -4
  63. package/dist/decorators/index.js +1385 -13
  64. package/dist/decorators/index.js.map +1 -1
  65. package/dist/decorators/index.mjs +1384 -13
  66. package/dist/decorators/index.mjs.map +1 -1
  67. package/dist/functions/DialogueUtility.d.mts +7 -7
  68. package/dist/functions/DialogueUtility.d.ts +7 -7
  69. package/dist/functions/DialogueUtility.js +96 -68
  70. package/dist/functions/DialogueUtility.js.map +1 -1
  71. package/dist/functions/DialogueUtility.mjs +96 -68
  72. package/dist/functions/DialogueUtility.mjs.map +1 -1
  73. package/dist/functions/FlagsUtility.js +55 -57
  74. package/dist/functions/FlagsUtility.js.map +1 -1
  75. package/dist/functions/FlagsUtility.mjs +55 -57
  76. package/dist/functions/FlagsUtility.mjs.map +1 -1
  77. package/dist/functions/GameUtility.js +55 -57
  78. package/dist/functions/GameUtility.js.map +1 -1
  79. package/dist/functions/GameUtility.mjs +55 -57
  80. package/dist/functions/GameUtility.mjs.map +1 -1
  81. package/dist/functions/ImageUtility.js +17 -17
  82. package/dist/functions/ImageUtility.js.map +1 -1
  83. package/dist/functions/ImageUtility.mjs +17 -17
  84. package/dist/functions/ImageUtility.mjs.map +1 -1
  85. package/dist/functions/SavesUtility.d.mts +2 -2
  86. package/dist/functions/SavesUtility.d.ts +2 -2
  87. package/dist/functions/SavesUtility.js +113 -141
  88. package/dist/functions/SavesUtility.js.map +1 -1
  89. package/dist/functions/SavesUtility.mjs +113 -141
  90. package/dist/functions/SavesUtility.mjs.map +1 -1
  91. package/dist/functions/StepLabelUtility.d.mts +0 -1
  92. package/dist/functions/StepLabelUtility.d.ts +0 -1
  93. package/dist/functions/index.d.mts +4 -4
  94. package/dist/functions/index.d.ts +4 -4
  95. package/dist/functions/index.js +97 -69
  96. package/dist/functions/index.js.map +1 -1
  97. package/dist/functions/index.mjs +97 -69
  98. package/dist/functions/index.mjs.map +1 -1
  99. package/dist/index.d.mts +3 -3
  100. package/dist/index.d.ts +3 -3
  101. package/dist/index.js +359 -327
  102. package/dist/index.js.map +1 -1
  103. package/dist/index.mjs +358 -327
  104. package/dist/index.mjs.map +1 -1
  105. package/dist/interface/{IDialogueHistory.d.mts → DialogueHistory.d.mts} +5 -5
  106. package/dist/interface/{IDialogueHistory.d.ts → DialogueHistory.d.ts} +5 -5
  107. package/dist/interface/{IDialogueHistory.js → DialogueHistory.js} +1 -1
  108. package/dist/interface/DialogueHistory.mjs +3 -0
  109. package/dist/interface/IHistoryStep.d.mts +2 -2
  110. package/dist/interface/IHistoryStep.d.ts +2 -2
  111. package/dist/interface/ISaveData.d.mts +2 -2
  112. package/dist/interface/ISaveData.d.ts +2 -2
  113. package/dist/interface/export/ExportedStep.d.mts +2 -2
  114. package/dist/interface/export/ExportedStep.d.ts +2 -2
  115. package/dist/interface/export/index.d.mts +2 -2
  116. package/dist/interface/export/index.d.ts +2 -2
  117. package/dist/interface/index.d.mts +6 -6
  118. package/dist/interface/index.d.ts +6 -6
  119. package/dist/managers/StepManager.d.mts +12 -12
  120. package/dist/managers/StepManager.d.ts +12 -12
  121. package/dist/managers/StepManager.js +53 -79
  122. package/dist/managers/StepManager.js.map +1 -1
  123. package/dist/managers/StepManager.mjs +53 -79
  124. package/dist/managers/StepManager.mjs.map +1 -1
  125. package/dist/managers/WindowManager.d.mts +1 -1
  126. package/dist/managers/WindowManager.d.ts +1 -1
  127. package/dist/managers/index.d.mts +2 -2
  128. package/dist/managers/index.d.ts +2 -2
  129. package/dist/managers/index.js +112 -140
  130. package/dist/managers/index.js.map +1 -1
  131. package/dist/managers/index.mjs +112 -140
  132. package/dist/managers/index.mjs.map +1 -1
  133. package/dist/types/ChoiceMenuOptionsType.d.mts +3 -3
  134. package/dist/types/ChoiceMenuOptionsType.d.ts +3 -3
  135. package/dist/types/StepLabelType.d.mts +2 -3
  136. package/dist/types/StepLabelType.d.ts +2 -3
  137. package/dist/types/index.d.mts +1 -1
  138. package/dist/types/index.d.ts +1 -1
  139. package/package.json +2 -2
  140. package/dist/interface/IDialogueHistory.mjs +0 -3
  141. /package/dist/interface/{IDialogueHistory.js.map → DialogueHistory.js.map} +0 -0
  142. /package/dist/interface/{IDialogueHistory.mjs.map → DialogueHistory.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -69,13 +69,31 @@ function checkIfStepsIsEqual(step1, step2) {
69
69
 
70
70
  // src/classes/Label.ts
71
71
  var Label = class {
72
+ /**
73
+ * @param id is the id of the label
74
+ * @param steps is the list of steps that the label will perform
75
+ * @param onStepRun is a function that will be executed before any step is executed, is useful for example to make sure all images used have been cached
76
+ * @param choiseIndex is the index of the choice that the label will perform
77
+ */
78
+ constructor(id, steps, onStepRun, choiseIndex) {
79
+ this._id = id;
80
+ this._steps = steps;
81
+ this._onStepRun = onStepRun;
82
+ this._choiseIndex = choiseIndex;
83
+ }
84
+ /**
85
+ * Get the id of the label
86
+ */
87
+ get id() {
88
+ return this._id;
89
+ }
72
90
  /**
73
91
  * Get the steps of the label.
74
92
  * This class should be extended and the steps method should be overridden.
75
93
  * Every time you update this list will also be updated when the other game versions load.
76
94
  */
77
95
  get steps() {
78
- throw new Error("[Pixi'VN] The method Label.steps must be overridden");
96
+ return this._steps;
79
97
  }
80
98
  /**
81
99
  * Get the corresponding steps number
@@ -94,253 +112,48 @@ var Label = class {
94
112
  });
95
113
  return res;
96
114
  }
97
- };
98
-
99
- // src/classes/CloseLabel.ts
100
- var CloseLabel = class extends Label {
101
- };
102
-
103
- // src/decorators/LabelDecorator.ts
104
- var registeredLabels = {};
105
- function labelDecorator(name) {
106
- return function(target) {
107
- if (!name) {
108
- name = target.name;
109
- }
110
- if (registeredLabels[name]) {
111
- console.warn(`[Pixi'VN] Label ${name} already exists, it will be overwritten`);
112
- }
113
- registeredLabels[name] = target;
114
- };
115
- }
116
- function getLabelTypeByClassName(labelName) {
117
- try {
118
- let labelType = registeredLabels[labelName];
119
- if (!labelType) {
120
- console.error(`[Pixi'VN] Label ${labelName} not found`);
121
- return;
122
- }
123
- new labelType();
124
- return labelType;
125
- } catch (e) {
126
- console.error(`[Pixi'VN] Error while getting Label ${labelName}`, e);
127
- return;
128
- }
129
- }
130
- function getLabelInstanceByClassName(labelName) {
131
- try {
132
- let labelType = registeredLabels[labelName];
133
- if (!labelType) {
134
- console.error(`[Pixi'VN] Label ${labelName} not found`);
135
- return;
136
- }
137
- let label = new labelType();
138
- let step = label.steps;
139
- if (step.length = 0) {
140
- console.warn(`[Pixi'VN] Label ${labelName} has no steps`);
141
- }
142
- return label;
143
- } catch (e) {
144
- console.error(`[Pixi'VN] Error while getting Label ${labelName}`, e);
145
- return;
146
- }
147
- }
148
-
149
- // src/types/CloseType.ts
150
- var Close = "close";
151
-
152
- // src/types/PauseType.ts
153
- var PauseValueType = "pause";
154
- function Pause(duration) {
155
- return {
156
- type: PauseValueType,
157
- duration
158
- };
159
- }
160
-
161
- // src/types/RepeatType.ts
162
- var Repeat = "repeat";
163
-
164
- // src/classes/ChoiceMenuOption.ts
165
- var ChoiceMenuOption = class {
166
115
  /**
167
- * @param text Text to be displayed in the menu
168
- * @param label Label to be opened when the option is selected
169
- * @param type Type of the label to be opened
170
- * @param props Properties to be passed to the label, when the label is called. it cannot contain functions or classes.
116
+ * Get the function that will be executed before any step is executed, is useful for example to make sure all images used have been cached
117
+ * @returns Promise<void> or void
118
+ * @example
119
+ * ```typescript
120
+ * newLabel("id", [], () => {
121
+ * Assets.load('path/to/image1.png')
122
+ * Assets.load('path/to/image2.png')
123
+ * })
124
+ * ```
171
125
  */
172
- constructor(text, label, type = "call", props) {
173
- /**
174
- * Properties to be passed to the label
175
- */
176
- this.props = {};
177
- this.text = text;
178
- this.label = new label();
179
- this.type = type;
180
- if (props) {
181
- this.props = props;
182
- }
126
+ get onStepRun() {
127
+ return this._onStepRun;
183
128
  }
184
- };
185
- var ChoiceMenuOptionClose = class {
186
- /**
187
- * @param text Text to be displayed in the menu
188
- */
189
- constructor(text) {
190
- /**
191
- * Label to be opened when the option is selected
192
- */
193
- this.label = new CloseLabel();
194
- /**
195
- * Type of the label to be opened
196
- */
197
- this.type = Close;
198
- /**
199
- * Properties to be passed to the label
200
- */
201
- this.props = {};
202
- this.text = text;
129
+ get choiseIndex() {
130
+ return this._choiseIndex;
203
131
  }
204
132
  };
205
133
 
206
- // src/functions/DialogueUtility.ts
207
- function setDialogue(props) {
208
- let text = "";
209
- let characterId = void 0;
210
- let dialogue;
211
- if (typeof props === "string") {
212
- text = props;
213
- dialogue = new DialogueBaseModel(text, characterId);
214
- } else if (!(props instanceof DialogueBaseModel)) {
215
- text = props.text;
216
- if (props.character) {
217
- if (typeof props.character === "string") {
218
- characterId = props.character;
219
- } else {
220
- characterId = props.character.id;
221
- }
222
- }
223
- dialogue = new DialogueBaseModel(text, characterId);
224
- } else {
225
- dialogue = props;
226
- }
227
- GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY, dialogue);
228
- GameStorageManager.setVariable(GameStorageManager.keysSystem.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY, GameStepManager.lastStepIndex);
229
- }
230
- function getDialogue() {
231
- return GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY);
232
- }
233
- function clearDialogue() {
234
- GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY, void 0);
235
- }
236
- function setChoiceMenuOptions(options) {
237
- let value = options.map((option) => {
238
- if (option instanceof ChoiceMenuOptionClose) {
239
- return {
240
- text: option.text,
241
- type: Close
242
- };
243
- }
244
- return __spreadProps(__spreadValues({}, option), {
245
- label: option.label.constructor.name
246
- });
247
- });
248
- GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, value);
249
- GameStorageManager.setVariable(GameStorageManager.keysSystem.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY, GameStepManager.lastStepIndex);
250
- }
251
- function getChoiceMenuOptions() {
252
- let d = GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY);
253
- if (d) {
254
- let options = [];
255
- d.forEach((option, index) => {
256
- if (option.type === Close) {
257
- let itemLabel = new CloseLabel();
258
- itemLabel.choiseIndex = index;
259
- options.push({
260
- text: option.text,
261
- label: itemLabel,
262
- type: Close,
263
- props: {}
264
- });
265
- return;
266
- }
267
- let label = getLabelTypeByClassName(option.label);
268
- if (label) {
269
- let itemLabel = new label();
270
- itemLabel.choiseIndex = index;
271
- options.push(__spreadProps(__spreadValues({}, option), {
272
- label: itemLabel
273
- }));
274
- }
275
- });
276
- return options;
277
- }
278
- return void 0;
279
- }
280
- function clearChoiceMenuOptions() {
281
- GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, void 0);
282
- }
283
- function getDialogueHistory() {
284
- let list = [];
285
- GameStepManager.stepsHistory.forEach((step) => {
286
- let dialoge = step.dialoge;
287
- let requiredChoices = step.choices;
288
- if (list.length > 0 && list[list.length - 1].choices && !list[list.length - 1].playerMadeChoice && step.currentLabel) {
289
- let oldChoices = list[list.length - 1].choices;
290
- if (oldChoices) {
291
- let choiceMade = false;
292
- if (step.choiceIndexMade !== void 0 && oldChoices.length > step.choiceIndexMade) {
293
- oldChoices[step.choiceIndexMade].isMadeChoice = true;
294
- choiceMade = true;
295
- }
296
- list[list.length - 1].playerMadeChoice = choiceMade;
297
- list[list.length - 1].choices = oldChoices;
298
- }
299
- }
300
- if (dialoge || requiredChoices) {
301
- let choices = requiredChoices == null ? void 0 : requiredChoices.map((choice) => {
302
- return {
303
- text: choice.text,
304
- type: choice.type,
305
- isMadeChoice: false
306
- };
307
- });
308
- list.push({
309
- dialoge,
310
- playerMadeChoice: false,
311
- choices,
312
- stepIndex: step.index
313
- });
314
- }
315
- });
316
- return list;
134
+ // src/classes/CloseLabel.ts
135
+ var CLOSE_LABEL_ID = "__close-label-id__";
136
+ function newCloseLabel(choiseIndex) {
137
+ return new Label(CLOSE_LABEL_ID, [], void 0, choiseIndex);
317
138
  }
318
139
 
319
- // src/functions/FlagsUtility.ts
320
- function setFlag(name, value) {
321
- let flags = GameStorageManager.getVariable(GameStorageManager.keysSystem.FLAGS_CATEGORY_KEY) || [];
322
- if (value) {
323
- if (!flags.includes(name)) {
324
- flags.push(name);
325
- }
326
- } else {
327
- let index = flags.indexOf(name);
328
- if (index > -1) {
329
- flags.splice(index, 1);
330
- }
140
+ // src/decorators/LabelDecorator.ts
141
+ var registeredLabels = {};
142
+ function newLabel(id, steps, onStepRun) {
143
+ if (registeredLabels[id]) {
144
+ console.warn(`[Pixi'VN] Label ${id} already exists, it will be overwritten`);
331
145
  }
332
- GameStorageManager.setVariable(GameStorageManager.keysSystem.FLAGS_CATEGORY_KEY, flags);
146
+ let label = new Label(id, steps, onStepRun);
147
+ registeredLabels[id] = label;
148
+ return label;
333
149
  }
334
- function getFlag(name) {
335
- let flags = GameStorageManager.getVariable(GameStorageManager.keysSystem.FLAGS_CATEGORY_KEY) || [];
336
- return flags.includes(name);
337
- }
338
-
339
- // src/functions/GameUtility.ts
340
- function clearAllGameDatas() {
341
- GameStorageManager.clear();
342
- GameWindowManager.clear();
343
- GameStepManager.clear();
150
+ function getLabelById(id) {
151
+ let label = registeredLabels[id];
152
+ if (!label) {
153
+ console.error(`[Pixi'VN] Label ${id} not found`);
154
+ return;
155
+ }
156
+ return label;
344
157
  }
345
158
  var CanvasBase = class extends Container {
346
159
  /**
@@ -357,45 +170,6 @@ var CanvasBase = class extends Container {
357
170
  }
358
171
  };
359
172
 
360
- // src/decorators/CanvasElementDecorator.ts
361
- var registeredCanvasElement = {};
362
- function canvasElementDecorator(name) {
363
- return function(target) {
364
- if (!name) {
365
- name = target.name;
366
- }
367
- if (registeredCanvasElement[name]) {
368
- console.warn(`[Pixi'VN] CanvasElement ${name} already registered`);
369
- }
370
- registeredCanvasElement[name] = target;
371
- };
372
- }
373
- function getCanvasElementInstanceByClassName(canvasName) {
374
- try {
375
- let eventType = registeredCanvasElement[canvasName];
376
- if (!eventType) {
377
- if (canvasName === "CanvasContainer") {
378
- eventType = CanvasContainer;
379
- } else if (canvasName === "CanvasImage") {
380
- eventType = CanvasImage;
381
- } else if (canvasName === "CanvasSprite") {
382
- eventType = CanvasSprite;
383
- } else if (canvasName === "CanvasText") {
384
- eventType = CanvasText;
385
- }
386
- }
387
- if (!eventType) {
388
- console.error(`[Pixi'VN] CanvasElement ${canvasName} not found`);
389
- return;
390
- }
391
- let canvasElement = new eventType();
392
- return canvasElement;
393
- } catch (e) {
394
- console.error(`[Pixi'VN] Error while getting CanvasElement ${canvasName}`, e);
395
- return;
396
- }
397
- }
398
-
399
173
  // src/functions/CanvasUtility.ts
400
174
  function getTextureMemory(texture) {
401
175
  let sourceTexture = texture.source;
@@ -842,30 +616,45 @@ function setMemoryText(element, memory) {
842
616
  }
843
617
  }
844
618
 
845
- // src/classes/ticker/TickerBase.ts
846
- var TickerBase = class {
847
- /**
848
- * @param args The arguments that you want to pass to the ticker.
849
- * @param duration The duration of the ticker. If is undefined, the ticker will be called every frame.
850
- * @param priority The priority of the ticker. If is undefined, the priority will be UPDATE_PRIORITY.NORMAL.
851
- */
852
- constructor(args, duration, priority) {
853
- this.args = args;
854
- this.duration = duration;
855
- this.priority = priority;
856
- }
857
- /**
858
- * The method that will be called every frame.
859
- * This method should be overridden and you can use GameWindowManager.addCanvasElement() to get the canvas element of the canvas, and edit them.
860
- * @param t The ticker that is calling this method
861
- * @param args The arguments that you passed when you added the ticker
862
- * @param tags The tags of the canvas elements that are connected to this ticker
863
- */
864
- fn(_t, _args, _tags) {
865
- throw new Error("[Pixi'VN] The method TickerBase.fn() must be overridden");
866
- }
867
- };
868
-
619
+ // src/decorators/CanvasElementDecorator.ts
620
+ var registeredCanvasElement = {};
621
+ function canvasElementDecorator(name) {
622
+ return function(target) {
623
+ if (!name) {
624
+ name = target.name;
625
+ }
626
+ if (registeredCanvasElement[name]) {
627
+ console.warn(`[Pixi'VN] CanvasElement ${name} already registered`);
628
+ }
629
+ registeredCanvasElement[name] = target;
630
+ };
631
+ }
632
+ function getCanvasElementInstanceByClassName(canvasName) {
633
+ try {
634
+ let eventType = registeredCanvasElement[canvasName];
635
+ if (!eventType) {
636
+ if (canvasName === "CanvasContainer") {
637
+ eventType = CanvasContainer;
638
+ } else if (canvasName === "CanvasImage") {
639
+ eventType = CanvasImage;
640
+ } else if (canvasName === "CanvasSprite") {
641
+ eventType = CanvasSprite;
642
+ } else if (canvasName === "CanvasText") {
643
+ eventType = CanvasText;
644
+ }
645
+ }
646
+ if (!eventType) {
647
+ console.error(`[Pixi'VN] CanvasElement ${canvasName} not found`);
648
+ return;
649
+ }
650
+ let canvasElement = new eventType();
651
+ return canvasElement;
652
+ } catch (e) {
653
+ console.error(`[Pixi'VN] Error while getting CanvasElement ${canvasName}`, e);
654
+ return;
655
+ }
656
+ }
657
+
869
658
  // src/decorators/CharacterDecorator.ts
870
659
  var registeredCharacters = {};
871
660
  function saveCharacter(character) {
@@ -922,7 +711,232 @@ function geTickerInstanceByClassName(tickerName, args, duration, priority) {
922
711
  }
923
712
  }
924
713
 
925
- // src/classes/ticker/TickerFadeAlpha.ts
714
+ // src/types/CloseType.ts
715
+ var Close = "close";
716
+
717
+ // src/types/PauseType.ts
718
+ var PauseValueType = "pause";
719
+ function Pause(duration) {
720
+ return {
721
+ type: PauseValueType,
722
+ duration
723
+ };
724
+ }
725
+
726
+ // src/types/RepeatType.ts
727
+ var Repeat = "repeat";
728
+
729
+ // src/classes/ChoiceMenuOption.ts
730
+ var ChoiceMenuOption = class {
731
+ /**
732
+ * @param text Text to be displayed in the menu
733
+ * @param label Label to be opened when the option is selected or the id of the label
734
+ * @param type Type of the label to be opened. @default "call"
735
+ * @param props Properties to be passed to the label, when the label is called. it cannot contain functions or classes. @default {}
736
+ */
737
+ constructor(text, label, type = "call", props) {
738
+ /**
739
+ * Properties to be passed to the label
740
+ */
741
+ this.props = {};
742
+ if (typeof label === "string") {
743
+ let tLabel = getLabelById(label);
744
+ if (!tLabel) {
745
+ throw new Error(`[Pixi'VN] Label ${label} not found`);
746
+ } else {
747
+ label = tLabel;
748
+ }
749
+ }
750
+ this.text = text;
751
+ this.label = label;
752
+ this.type = type;
753
+ if (props) {
754
+ this.props = props;
755
+ }
756
+ }
757
+ };
758
+ var ChoiceMenuOptionClose = class {
759
+ /**
760
+ * @param text Text to be displayed in the menu
761
+ */
762
+ constructor(text) {
763
+ /**
764
+ * Label to be opened when the option is selected
765
+ */
766
+ this.label = newCloseLabel();
767
+ /**
768
+ * Type of the label to be opened
769
+ */
770
+ this.type = Close;
771
+ /**
772
+ * Properties to be passed to the label
773
+ */
774
+ this.props = {};
775
+ this.text = text;
776
+ }
777
+ };
778
+
779
+ // src/functions/DialogueUtility.ts
780
+ function setDialogue(props) {
781
+ let text = "";
782
+ let characterId = void 0;
783
+ let dialogue;
784
+ if (typeof props === "string") {
785
+ text = props;
786
+ dialogue = new DialogueBaseModel(text, characterId);
787
+ } else if (!(props instanceof DialogueBaseModel)) {
788
+ text = props.text;
789
+ if (props.character) {
790
+ if (typeof props.character === "string") {
791
+ characterId = props.character;
792
+ } else {
793
+ characterId = props.character.id;
794
+ }
795
+ }
796
+ dialogue = new DialogueBaseModel(text, characterId);
797
+ } else {
798
+ dialogue = props;
799
+ }
800
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY, dialogue);
801
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY, GameStepManager.lastStepIndex);
802
+ }
803
+ function getDialogue() {
804
+ return GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY);
805
+ }
806
+ function clearDialogue() {
807
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY, void 0);
808
+ }
809
+ function setChoiceMenuOptions(options) {
810
+ let value = options.map((option) => {
811
+ if (option instanceof ChoiceMenuOptionClose) {
812
+ return {
813
+ text: option.text,
814
+ type: Close
815
+ };
816
+ }
817
+ return __spreadProps(__spreadValues({}, option), {
818
+ label: option.label.id
819
+ });
820
+ });
821
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, value);
822
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY, GameStepManager.lastStepIndex);
823
+ }
824
+ function getChoiceMenuOptions() {
825
+ let d = GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY);
826
+ if (d) {
827
+ let options = [];
828
+ d.forEach((option, index) => {
829
+ if (option.type === Close) {
830
+ let itemLabel = newCloseLabel(index);
831
+ options.push({
832
+ text: option.text,
833
+ label: itemLabel,
834
+ type: Close,
835
+ props: {}
836
+ });
837
+ return;
838
+ }
839
+ let label = getLabelById(option.label);
840
+ if (label) {
841
+ let itemLabel = new Label(label.id, label.steps, label.onStepRun, index);
842
+ options.push(__spreadProps(__spreadValues({}, option), {
843
+ label: itemLabel
844
+ }));
845
+ }
846
+ });
847
+ return options;
848
+ }
849
+ return void 0;
850
+ }
851
+ function clearChoiceMenuOptions() {
852
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, void 0);
853
+ }
854
+ function getDialogueHistory() {
855
+ let list = [];
856
+ GameStepManager.stepsHistory.forEach((step) => {
857
+ let dialoge = step.dialoge;
858
+ let requiredChoices = step.choices;
859
+ if (list.length > 0 && list[list.length - 1].choices && !list[list.length - 1].playerMadeChoice && step.currentLabel) {
860
+ let oldChoices = list[list.length - 1].choices;
861
+ if (oldChoices) {
862
+ let choiceMade = false;
863
+ if (step.choiceIndexMade !== void 0 && oldChoices.length > step.choiceIndexMade) {
864
+ oldChoices[step.choiceIndexMade].isResponse = true;
865
+ choiceMade = true;
866
+ }
867
+ list[list.length - 1].playerMadeChoice = choiceMade;
868
+ list[list.length - 1].choices = oldChoices;
869
+ }
870
+ }
871
+ if (dialoge || requiredChoices) {
872
+ let choices = requiredChoices == null ? void 0 : requiredChoices.map((choice) => {
873
+ return {
874
+ text: choice.text,
875
+ type: choice.type,
876
+ isResponse: false
877
+ };
878
+ });
879
+ list.push({
880
+ dialoge,
881
+ playerMadeChoice: false,
882
+ choices,
883
+ stepIndex: step.index
884
+ });
885
+ }
886
+ });
887
+ return list;
888
+ }
889
+
890
+ // src/functions/FlagsUtility.ts
891
+ function setFlag(name, value) {
892
+ let flags = GameStorageManager.getVariable(GameStorageManager.keysSystem.FLAGS_CATEGORY_KEY) || [];
893
+ if (value) {
894
+ if (!flags.includes(name)) {
895
+ flags.push(name);
896
+ }
897
+ } else {
898
+ let index = flags.indexOf(name);
899
+ if (index > -1) {
900
+ flags.splice(index, 1);
901
+ }
902
+ }
903
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.FLAGS_CATEGORY_KEY, flags);
904
+ }
905
+ function getFlag(name) {
906
+ let flags = GameStorageManager.getVariable(GameStorageManager.keysSystem.FLAGS_CATEGORY_KEY) || [];
907
+ return flags.includes(name);
908
+ }
909
+
910
+ // src/functions/GameUtility.ts
911
+ function clearAllGameDatas() {
912
+ GameStorageManager.clear();
913
+ GameWindowManager.clear();
914
+ GameStepManager.clear();
915
+ }
916
+
917
+ // src/classes/ticker/TickerBase.ts
918
+ var TickerBase = class {
919
+ /**
920
+ * @param args The arguments that you want to pass to the ticker.
921
+ * @param duration The duration of the ticker. If is undefined, the ticker will be called every frame.
922
+ * @param priority The priority of the ticker. If is undefined, the priority will be UPDATE_PRIORITY.NORMAL.
923
+ */
924
+ constructor(args, duration, priority) {
925
+ this.args = args;
926
+ this.duration = duration;
927
+ this.priority = priority;
928
+ }
929
+ /**
930
+ * The method that will be called every frame.
931
+ * This method should be overridden and you can use GameWindowManager.addCanvasElement() to get the canvas element of the canvas, and edit them.
932
+ * @param t The ticker that is calling this method
933
+ * @param args The arguments that you passed when you added the ticker
934
+ * @param tags The tags of the canvas elements that are connected to this ticker
935
+ */
936
+ fn(_t, _args, _tags) {
937
+ throw new Error("[Pixi'VN] The method TickerBase.fn() must be overridden");
938
+ }
939
+ };
926
940
  var TickerFadeAlpha = class extends TickerBase {
927
941
  /**
928
942
  * The method that will be called every frame to fade the alpha of the canvas element of the canvas.
@@ -1145,7 +1159,7 @@ function showWithDissolveTransition(tag, image, speed, priority) {
1145
1159
  }
1146
1160
 
1147
1161
  // src/constants.ts
1148
- var PIXIVN_VERSION = "0.5.3";
1162
+ var PIXIVN_VERSION = "0.5.5";
1149
1163
 
1150
1164
  // src/functions/SavesUtility.ts
1151
1165
  function getSaveData() {
@@ -1925,7 +1939,7 @@ var _GameStepManager = class _GameStepManager {
1925
1939
  */
1926
1940
  static get currentLabel() {
1927
1941
  if (_GameStepManager.currentLabelId) {
1928
- return getLabelInstanceByClassName(_GameStepManager.currentLabelId);
1942
+ return getLabelById(_GameStepManager.currentLabelId);
1929
1943
  }
1930
1944
  }
1931
1945
  static get currentLabelStepIndex() {
@@ -1946,7 +1960,7 @@ var _GameStepManager = class _GameStepManager {
1946
1960
  return true;
1947
1961
  } else {
1948
1962
  this.openedLabels.forEach((item) => {
1949
- let label = getLabelInstanceByClassName(item.label);
1963
+ let label = getLabelById(item.label);
1950
1964
  if (label && label.steps.length > item.currentStepIndex) {
1951
1965
  return false;
1952
1966
  }
@@ -2039,9 +2053,9 @@ var _GameStepManager = class _GameStepManager {
2039
2053
  * @param label The label to add to the history.
2040
2054
  */
2041
2055
  static pushNewLabel(label) {
2042
- let currentLabel = getLabelInstanceByClassName(label);
2056
+ let currentLabel = getLabelById(label);
2043
2057
  if (!currentLabel) {
2044
- throw new Error("[Pixi'VN] Label not found");
2058
+ throw new Error(`[Pixi'VN] Label ${label} not found`);
2045
2059
  }
2046
2060
  _GameStepManager._openedLabels.push({
2047
2061
  label,
@@ -2058,7 +2072,7 @@ var _GameStepManager = class _GameStepManager {
2058
2072
  return;
2059
2073
  }
2060
2074
  if (!_GameStepManager.currentLabel) {
2061
- console.error("[Pixi'VN] Label not found");
2075
+ console.error("[Pixi'VN] currentLabel not found");
2062
2076
  return;
2063
2077
  }
2064
2078
  _GameStepManager._openedLabels.pop();
@@ -2130,7 +2144,7 @@ var _GameStepManager = class _GameStepManager {
2130
2144
  }
2131
2145
  let currentLabel = _GameStepManager.currentLabel;
2132
2146
  if (!currentLabel) {
2133
- console.error("[Pixi'VN] Label not found");
2147
+ console.error("[Pixi'VN] currentLabel not found");
2134
2148
  return;
2135
2149
  }
2136
2150
  let n = currentLabel.steps.length;
@@ -2151,12 +2165,12 @@ var _GameStepManager = class _GameStepManager {
2151
2165
  /**
2152
2166
  * Execute the label and add it to the history.
2153
2167
  * Is a call function in Ren'Py.
2154
- * @param label The label to execute.
2168
+ * @param label The label to execute or the id of the label
2155
2169
  * @param props The props to pass to the label.
2156
2170
  * @returns StepLabelResultType or undefined.
2157
2171
  * @example
2158
2172
  * ```typescript
2159
- * GameStepManager.callLabel(StartLabel, yourParams).then((result) => {
2173
+ * GameStepManager.callLabel(startLabel, yourParams).then((result) => {
2160
2174
  * if (result) {
2161
2175
  * // your code
2162
2176
  * }
@@ -2165,7 +2179,7 @@ var _GameStepManager = class _GameStepManager {
2165
2179
  * @example
2166
2180
  * ```typescript
2167
2181
  * // if you use it in a step label you should return the result.
2168
- * return GameStepManager.callLabel(StartLabel).then((result) => {
2182
+ * return GameStepManager.callLabel(startLabel).then((result) => {
2169
2183
  * return result
2170
2184
  * })
2171
2185
  * ```
@@ -2173,16 +2187,24 @@ var _GameStepManager = class _GameStepManager {
2173
2187
  static callLabel(label, props) {
2174
2188
  return __async(this, null, function* () {
2175
2189
  let choiseMade = void 0;
2190
+ let labelId;
2191
+ if (typeof label === "string") {
2192
+ labelId = label;
2193
+ } else {
2194
+ labelId = label.id;
2195
+ if (typeof label.choiseIndex === "number") {
2196
+ choiseMade = label.choiseIndex;
2197
+ }
2198
+ }
2176
2199
  try {
2177
- if (label instanceof CloseLabel) {
2200
+ if (labelId === CLOSE_LABEL_ID) {
2178
2201
  return _GameStepManager.runNextStep(props);
2179
2202
  }
2180
- if (label instanceof Label) {
2181
- choiseMade = label.choiseIndex;
2182
- label = label.constructor;
2203
+ let tempLabel = getLabelById(labelId);
2204
+ if (!tempLabel) {
2205
+ throw new Error(`[Pixi'VN] Label ${labelId} not found`);
2183
2206
  }
2184
- let labelName = label.name;
2185
- _GameStepManager.pushNewLabel(labelName);
2207
+ _GameStepManager.pushNewLabel(tempLabel.id);
2186
2208
  } catch (e) {
2187
2209
  console.error("[Pixi'VN] Error calling label", e);
2188
2210
  return;
@@ -2194,11 +2216,11 @@ var _GameStepManager = class _GameStepManager {
2194
2216
  * Execute the label, close all labels and add them to the history.
2195
2217
  * Is a jump function in Ren'Py.
2196
2218
  * @param label The label to execute.
2197
- * @param props The props to pass to the label.
2219
+ * @param props The props to pass to the label or the id of the label
2198
2220
  * @returns StepLabelResultType or undefined.
2199
2221
  * @example
2200
2222
  * ```typescript
2201
- * GameStepManager.jumpLabel(StartLabel, yourParams).then((result) => {
2223
+ * GameStepManager.jumpLabel(startLabel, yourParams).then((result) => {
2202
2224
  * if (result) {
2203
2225
  * // your code
2204
2226
  * }
@@ -2207,7 +2229,7 @@ var _GameStepManager = class _GameStepManager {
2207
2229
  * @example
2208
2230
  * ```typescript
2209
2231
  * // if you use it in a step label you should return the result.
2210
- * return GameStepManager.jumpLabel(StartLabel).then((result) => {
2232
+ * return GameStepManager.jumpLabel(startLabel).then((result) => {
2211
2233
  * return result
2212
2234
  * })
2213
2235
  * ```
@@ -2215,15 +2237,24 @@ var _GameStepManager = class _GameStepManager {
2215
2237
  static jumpLabel(label, props) {
2216
2238
  return __async(this, null, function* () {
2217
2239
  _GameStepManager.closeAllLabels();
2240
+ let labelId;
2241
+ if (typeof label === "string") {
2242
+ labelId = label;
2243
+ } else {
2244
+ labelId = label.id;
2245
+ if (typeof label.choiseIndex === "number") {
2246
+ label.choiseIndex;
2247
+ }
2248
+ }
2218
2249
  try {
2219
- if (label instanceof CloseLabel) {
2250
+ if (labelId === CLOSE_LABEL_ID) {
2220
2251
  return _GameStepManager.runNextStep(props);
2221
2252
  }
2222
- if (label instanceof Label) {
2223
- label = label.constructor;
2253
+ let tempLabel = getLabelById(labelId);
2254
+ if (!tempLabel) {
2255
+ throw new Error(`[Pixi'VN] Label ${labelId} not found`);
2224
2256
  }
2225
- let labelName = label.name;
2226
- _GameStepManager.pushNewLabel(labelName);
2257
+ _GameStepManager.pushNewLabel(tempLabel.id);
2227
2258
  } catch (e) {
2228
2259
  console.error("[Pixi'VN] Error jumping label", e);
2229
2260
  return;
@@ -2601,6 +2632,6 @@ var DialogueBaseModel = class {
2601
2632
  }
2602
2633
  };
2603
2634
 
2604
- export { CanvasBase, CanvasContainer, CanvasEvent, CanvasImage, CanvasSprite, CanvasText, CharacterBaseModel2 as CharacterBaseModel, ChoiceMenuOption, Close, DialogueBaseModel, GameStepManager, GameStorageManager, GameWindowManager, Label, Pause, PauseValueType, Repeat, StoredClassModel, TickerBase, TickerFadeAlpha, TickerMove, TickerRotate, addImage, canvasElementDecorator, clearAllGameDatas, clearChoiceMenuOptions, clearDialogue, eventDecorator, getAllCharacters, getCharacterById, getChoiceMenuOptions, getDialogue, getDialogueHistory, getFlag, getSaveData, getSaveJson, getTexture, labelDecorator, loadImages, loadSaveData, loadSaveJson, removeCanvasElement, saveCharacter, setChoiceMenuOptions, setDialogue, setFlag, showWithDissolveTransition, tickerDecorator };
2635
+ export { CanvasBase, CanvasContainer, CanvasEvent, CanvasImage, CanvasSprite, CanvasText, CharacterBaseModel2 as CharacterBaseModel, ChoiceMenuOption, Close, DialogueBaseModel, GameStepManager, GameStorageManager, GameWindowManager, Label, Pause, PauseValueType, Repeat, StoredClassModel, TickerBase, TickerFadeAlpha, TickerMove, TickerRotate, addImage, canvasElementDecorator, clearAllGameDatas, clearChoiceMenuOptions, clearDialogue, eventDecorator, getAllCharacters, getCharacterById, getChoiceMenuOptions, getDialogue, getDialogueHistory, getFlag, getLabelById, getSaveData, getSaveJson, getTexture, loadImages, loadSaveData, loadSaveJson, newLabel, removeCanvasElement, saveCharacter, setChoiceMenuOptions, setDialogue, setFlag, showWithDissolveTransition, tickerDecorator };
2605
2636
  //# sourceMappingURL=out.js.map
2606
2637
  //# sourceMappingURL=index.mjs.map