@drincs/pixi-vn 0.5.2 → 0.5.4

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 -7
  8. package/dist/classes/ChoiceMenuOption.js.map +1 -1
  9. package/dist/classes/ChoiceMenuOption.mjs +1386 -7
  10. package/dist/classes/ChoiceMenuOption.mjs.map +1 -1
  11. package/dist/classes/CloseLabel.d.mts +8 -3
  12. package/dist/classes/CloseLabel.d.ts +8 -3
  13. package/dist/classes/CloseLabel.js +44 -2
  14. package/dist/classes/CloseLabel.js.map +1 -1
  15. package/dist/classes/CloseLabel.mjs +41 -2
  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 +97 -67
  70. package/dist/functions/DialogueUtility.js.map +1 -1
  71. package/dist/functions/DialogueUtility.mjs +97 -67
  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 +115 -143
  88. package/dist/functions/SavesUtility.js.map +1 -1
  89. package/dist/functions/SavesUtility.mjs +115 -143
  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 +98 -68
  96. package/dist/functions/index.js.map +1 -1
  97. package/dist/functions/index.mjs +98 -68
  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 +361 -327
  102. package/dist/index.js.map +1 -1
  103. package/dist/index.mjs +360 -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 +55 -81
  122. package/dist/managers/StepManager.js.map +1 -1
  123. package/dist/managers/StepManager.mjs +55 -81
  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 +114 -142
  130. package/dist/managers/index.js.map +1 -1
  131. package/dist/managers/index.mjs +114 -142
  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
@@ -2,23 +2,553 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var pixi_js = require('pixi.js');
6
+ require('deep-diff');
5
7
  require('crypto-js/sha1');
6
8
 
7
- // src/types/CloseType.ts
8
- var Close = "close";
9
+ var __defProp = Object.defineProperty;
10
+ var __defProps = Object.defineProperties;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
13
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
16
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
+ var __spreadValues = (a, b) => {
18
+ for (var prop in b || (b = {}))
19
+ if (__hasOwnProp.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ if (__getOwnPropSymbols)
22
+ for (var prop of __getOwnPropSymbols(b)) {
23
+ if (__propIsEnum.call(b, prop))
24
+ __defNormalProp(a, prop, b[prop]);
25
+ }
26
+ return a;
27
+ };
28
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
29
+ var __decorateClass = (decorators, target, key, kind) => {
30
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
31
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
32
+ if (decorator = decorators[i])
33
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
34
+ if (kind && result)
35
+ __defProp(target, key, result);
36
+ return result;
37
+ };
38
+ var __async = (__this, __arguments, generator) => {
39
+ return new Promise((resolve, reject) => {
40
+ var fulfilled = (value) => {
41
+ try {
42
+ step(generator.next(value));
43
+ } catch (e) {
44
+ reject(e);
45
+ }
46
+ };
47
+ var rejected = (value) => {
48
+ try {
49
+ step(generator.throw(value));
50
+ } catch (e) {
51
+ reject(e);
52
+ }
53
+ };
54
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
55
+ step((generator = generator.apply(__this, __arguments)).next());
56
+ });
57
+ };
58
+
59
+ // src/functions/CanvasUtility.ts
60
+ function getTextureMemory(texture) {
61
+ let sourceTexture = texture.source;
62
+ let textureMemory = {
63
+ image: sourceTexture.label
64
+ };
65
+ return textureMemory;
66
+ }
67
+ function exportCanvasElement(element) {
68
+ return element.memory;
69
+ }
70
+ function importCanvasElement(memory) {
71
+ let element = getCanvasElementInstanceByClassName(memory.className);
72
+ if (element) {
73
+ element.memory = memory;
74
+ } else {
75
+ throw new Error("[Pixi'VN] The element " + memory.className + " could not be created");
76
+ }
77
+ return element;
78
+ }
79
+
80
+ // src/classes/canvas/CanvasContainer.ts
81
+ var CanvasContainer = class extends pixi_js.Container {
82
+ get memory() {
83
+ let memory = getMemoryContainer(this);
84
+ this.children.forEach((child) => {
85
+ memory.elements.push(exportCanvasElement(child));
86
+ });
87
+ return memory;
88
+ }
89
+ set memory(value) {
90
+ setMemoryContainer(this, value);
91
+ value.elements.forEach((child) => {
92
+ this.addChild(importCanvasElement(child));
93
+ });
94
+ }
95
+ };
96
+ function getMemoryContainer(element) {
97
+ return {
98
+ className: "CanvasContainer",
99
+ elements: [],
100
+ width: element.width,
101
+ height: element.height,
102
+ isRenderGroup: element.isRenderGroup,
103
+ blendMode: element.blendMode,
104
+ tint: element.tint,
105
+ alpha: element.alpha,
106
+ angle: element.angle,
107
+ renderable: element.renderable,
108
+ rotation: element.rotation,
109
+ scale: { x: element.scale.x, y: element.scale.y },
110
+ pivot: { x: element.pivot.x, y: element.pivot.y },
111
+ position: { x: element.position.x, y: element.position.y },
112
+ skew: { x: element.skew.x, y: element.skew.y },
113
+ visible: element.visible,
114
+ culled: element.culled,
115
+ x: element.x,
116
+ y: element.y,
117
+ boundsArea: element.boundsArea,
118
+ cursor: element.cursor,
119
+ eventMode: element.eventMode,
120
+ interactive: element.interactive,
121
+ interactiveChildren: element.interactiveChildren,
122
+ hitArea: element.hitArea
123
+ };
124
+ }
125
+ function setMemoryContainer(element, memory) {
126
+ memory.width && (element.width = memory.width);
127
+ memory.height && (element.height = memory.height);
128
+ memory.isRenderGroup && (element.isRenderGroup = memory.isRenderGroup);
129
+ memory.blendMode && (element.blendMode = memory.blendMode);
130
+ memory.tint && (element.tint = memory.tint);
131
+ memory.alpha && (element.alpha = memory.alpha);
132
+ memory.angle && (element.angle = memory.angle);
133
+ memory.renderable && (element.renderable = memory.renderable);
134
+ memory.rotation && (element.rotation = memory.rotation);
135
+ if (memory.scale) {
136
+ if (typeof memory.scale === "number") {
137
+ element.scale.set(memory.scale, memory.scale);
138
+ } else {
139
+ element.scale.set(memory.scale.x, memory.scale.y);
140
+ }
141
+ }
142
+ if (memory.pivot) {
143
+ if (typeof memory.pivot === "number") {
144
+ element.pivot.set(memory.pivot, memory.pivot);
145
+ } else {
146
+ element.pivot.set(memory.pivot.x, memory.pivot.y);
147
+ }
148
+ }
149
+ memory.position && element.position.set(memory.position.x, memory.position.y);
150
+ memory.skew && element.skew.set(memory.skew.x, memory.skew.y);
151
+ memory.visible && (element.visible = memory.visible);
152
+ memory.culled && (element.culled = memory.culled);
153
+ memory.x && (element.x = memory.x);
154
+ memory.y && (element.y = memory.y);
155
+ memory.boundsArea && (element.boundsArea = memory.boundsArea);
156
+ memory.cursor && (element.cursor = memory.cursor);
157
+ memory.eventMode && (element.eventMode = memory.eventMode);
158
+ memory.interactive && (element.interactive = memory.interactive);
159
+ memory.interactiveChildren && (element.interactiveChildren = memory.interactiveChildren);
160
+ memory.hitArea && (element.hitArea = memory.hitArea);
161
+ }
162
+ function getTexture(imageUrl) {
163
+ return __async(this, null, function* () {
164
+ if (pixi_js.Assets.cache.has(imageUrl)) {
165
+ return pixi_js.Assets.get(imageUrl);
166
+ }
167
+ return pixi_js.Assets.load(imageUrl).then((texture) => {
168
+ if (!texture) {
169
+ console.error("[Pixi'VN] Texture not found", imageUrl);
170
+ return;
171
+ }
172
+ if (!(texture instanceof pixi_js.Texture)) {
173
+ console.error("[Pixi'VN] File not is a image", imageUrl);
174
+ return;
175
+ }
176
+ return texture;
177
+ }).catch((e) => {
178
+ console.error("[Pixi'VN] Error loading image", e);
179
+ return;
180
+ });
181
+ });
182
+ }
183
+ function getTextStyle(style) {
184
+ let fill = style.fill;
185
+ if (fill instanceof Object) {
186
+ console.warn("[Pixi'VN] CanvasText.style.fill is a FillGradient or FillPattern, this is not supported yet.", fill);
187
+ fill = "#00FF00";
188
+ }
189
+ return {
190
+ align: style.align,
191
+ breakWords: style.breakWords,
192
+ dropShadow: style.dropShadow,
193
+ fill,
194
+ fontFamily: style.fontFamily,
195
+ fontSize: style.fontSize,
196
+ fontStyle: style.fontStyle,
197
+ fontVariant: style.fontVariant,
198
+ fontWeight: style.fontWeight,
199
+ leading: style.leading,
200
+ letterSpacing: style.letterSpacing,
201
+ lineHeight: style.lineHeight,
202
+ padding: style.padding,
203
+ stroke: style.stroke,
204
+ textBaseline: style.textBaseline,
205
+ trim: style.trim,
206
+ whiteSpace: style.whiteSpace,
207
+ wordWrap: style.wordWrap,
208
+ wordWrapWidth: style.wordWrapWidth
209
+ };
210
+ }
211
+
212
+ // src/decorators/EventDecorator.ts
213
+ var registeredEvents = {};
214
+ function getEventTypeByClassName(eventName) {
215
+ try {
216
+ let eventType = registeredEvents[eventName];
217
+ if (!eventType) {
218
+ console.error(`[Pixi'VN] Event ${eventName} not found`);
219
+ return;
220
+ }
221
+ new eventType();
222
+ return eventType;
223
+ } catch (e) {
224
+ console.error(`[Pixi'VN] Error while getting Event ${eventName}`, e);
225
+ return;
226
+ }
227
+ }
228
+ function getEventInstanceByClassName(eventName) {
229
+ try {
230
+ let eventType = registeredEvents[eventName];
231
+ if (!eventType) {
232
+ console.error(`[Pixi'VN] Event ${eventName} not found`);
233
+ return;
234
+ }
235
+ let event = new eventType();
236
+ return event;
237
+ } catch (e) {
238
+ console.error(`[Pixi'VN] Error while getting Event ${eventName}`, e);
239
+ return;
240
+ }
241
+ }
242
+
243
+ // src/classes/canvas/CanvasSprite.ts
244
+ var CanvasSprite = class _CanvasSprite extends pixi_js.Sprite {
245
+ constructor() {
246
+ super(...arguments);
247
+ this._onEvents = {};
248
+ }
249
+ get memory() {
250
+ return getMemorySprite(this);
251
+ }
252
+ set memory(value) {
253
+ setMemorySprite(this, value);
254
+ }
255
+ get onEvents() {
256
+ return this._onEvents;
257
+ }
258
+ /**
259
+ * is same function as on(), but it keeps in memory the children.
260
+ * @param event The event type, e.g., 'click', 'mousedown', 'mouseup', 'pointerdown', etc.
261
+ * @param eventClass The class that extends CanvasEvent.
262
+ * @returns
263
+ * @example
264
+ * ```typescript
265
+ * \@eventDecorator()
266
+ * export class EventTest extends CanvasEvent<CanvasSprite> {
267
+ * override fn(event: CanvasEventNamesType, sprite: CanvasSprite): void {
268
+ * if (event === 'pointerdown') {
269
+ * sprite.scale.x *= 1.25;
270
+ * sprite.scale.y *= 1.25;
271
+ * }
272
+ * }
273
+ * }
274
+ * ```
275
+ *
276
+ * ```typescript
277
+ * let sprite = addImage("alien", 'https://pixijs.com/assets/eggHead.png')
278
+ * await sprite.load()
279
+ *
280
+ * sprite.eventMode = 'static';
281
+ * sprite.cursor = 'pointer';
282
+ * sprite.onEvent('pointerdown', EventTest);
283
+ *
284
+ * GameWindowManager.addCanvasElement("bunny", sprite);
285
+ * ```
286
+ */
287
+ onEvent(event, eventClass) {
288
+ let className = eventClass.name;
289
+ let instance = getEventInstanceByClassName(className);
290
+ this._onEvents[event] = className;
291
+ if (instance) {
292
+ super.on(event, () => {
293
+ instance.fn(event, this);
294
+ });
295
+ }
296
+ return this;
297
+ }
298
+ /**
299
+ * on() does not keep in memory the event class, use onEvent() instead
300
+ * @deprecated
301
+ * @private
302
+ * @param event
303
+ * @param fn
304
+ * @param context
305
+ */
306
+ on(event, fn, context) {
307
+ return super.on(event, fn, context);
308
+ }
309
+ static from(source, skipCache) {
310
+ let sprite = pixi_js.Sprite.from(source, skipCache);
311
+ let mySprite = new _CanvasSprite();
312
+ mySprite.texture = sprite.texture;
313
+ return mySprite;
314
+ }
315
+ };
316
+ function getMemorySprite(element) {
317
+ let temp = getMemoryContainer(element);
318
+ return __spreadProps(__spreadValues({}, temp), {
319
+ className: "CanvasSprite",
320
+ textureImage: getTextureMemory(element.texture),
321
+ anchor: { x: element.anchor.x, y: element.anchor.y },
322
+ roundPixels: element.roundPixels,
323
+ onEvents: element.onEvents
324
+ });
325
+ }
326
+ function setMemorySprite(element, memory) {
327
+ setMemoryContainer(element, memory);
328
+ getTexture(memory.textureImage.image).then((texture) => {
329
+ if (texture) {
330
+ element.texture = texture;
331
+ }
332
+ });
333
+ if (memory.anchor) {
334
+ if (typeof memory.anchor === "number") {
335
+ element.anchor.set(memory.anchor, memory.anchor);
336
+ } else {
337
+ element.anchor.set(memory.anchor.x, memory.anchor.y);
338
+ }
339
+ }
340
+ memory.roundPixels && (element.roundPixels = memory.roundPixels);
341
+ for (let event in memory.onEvents) {
342
+ let className = memory.onEvents[event];
343
+ let instance = getEventTypeByClassName(className);
344
+ if (instance) {
345
+ element.onEvent(event, instance);
346
+ }
347
+ }
348
+ }
349
+
350
+ // src/classes/canvas/CanvasImage.ts
351
+ var CanvasImage = class _CanvasImage extends CanvasSprite {
352
+ constructor(options, imageLink) {
353
+ super(options);
354
+ this.imageLink = "";
355
+ if (imageLink) {
356
+ this.imageLink = imageLink;
357
+ }
358
+ }
359
+ get memory() {
360
+ return __spreadProps(__spreadValues({}, getMemorySprite(this)), {
361
+ className: "CanvasImage",
362
+ textureImage: { image: this.imageLink }
363
+ });
364
+ }
365
+ set memory(memory) {
366
+ setMemorySprite(this, memory);
367
+ }
368
+ static from(source, skipCache) {
369
+ let sprite = pixi_js.Sprite.from(source, skipCache);
370
+ let mySprite = new _CanvasImage();
371
+ mySprite.texture = sprite.texture;
372
+ return mySprite;
373
+ }
374
+ /**
375
+ * Load the image from the link and set the texture of the sprite.
376
+ * @param image The link of the image. If it is not set, it will use the imageLink property.
377
+ * @returns A promise that resolves when the image is loaded.
378
+ */
379
+ load(image) {
380
+ return __async(this, null, function* () {
381
+ if (!image) {
382
+ image = this.imageLink;
383
+ }
384
+ return getTexture(this.imageLink).then((texture) => {
385
+ if (texture) {
386
+ this.texture = texture;
387
+ }
388
+ }).catch((e) => {
389
+ console.error("[Pixi'VN] Error into CanvasImage.load()", e);
390
+ });
391
+ });
392
+ }
393
+ };
394
+ var CanvasText = class extends pixi_js.Text {
395
+ constructor() {
396
+ super(...arguments);
397
+ this._onEvents = {};
398
+ }
399
+ get memory() {
400
+ return getMemoryText(this);
401
+ }
402
+ set memory(value) {
403
+ setMemoryText(this, value);
404
+ }
405
+ get onEvents() {
406
+ return this._onEvents;
407
+ }
408
+ /**
409
+ * is same function as on(), but it keeps in memory the children.
410
+ * @param event The event type, e.g., 'click', 'mousedown', 'mouseup', 'pointerdown', etc.
411
+ * @param eventClass The class that extends CanvasEvent.
412
+ * @returns
413
+ * @example
414
+ * ```typescript
415
+ * \@eventDecorator()
416
+ * export class EventTest extends CanvasEvent<CanvasText> {
417
+ * override fn(event: CanvasEventNamesType, text: CanvasText): void {
418
+ * if (event === 'pointerdown') {
419
+ * text.scale.x *= 1.25;
420
+ * text.scale.y *= 1.25;
421
+ * }
422
+ * }
423
+ * }
424
+ * ```
425
+ *
426
+ * ```typescript
427
+ * const text = new CanvasText();
428
+ * text.text = "Hello World"
429
+ *
430
+ * text.eventMode = 'static';
431
+ * text.cursor = 'pointer';
432
+ * text.onEvent('pointerdown', EventTest);
433
+ *
434
+ * GameWindowManager.addCanvasElement("text", text);
435
+ * ```
436
+ */
437
+ onEvent(event, eventClass) {
438
+ let className = eventClass.name;
439
+ let instance = getEventInstanceByClassName(className);
440
+ this._onEvents[event] = className;
441
+ if (instance) {
442
+ super.on(event, () => {
443
+ instance.fn(event, this);
444
+ });
445
+ }
446
+ return this;
447
+ }
448
+ /**
449
+ * on() does not keep in memory the event class, use onEvent() instead
450
+ * @deprecated
451
+ * @private
452
+ * @param event
453
+ * @param fn
454
+ * @param context
455
+ */
456
+ on(event, fn, context) {
457
+ return super.on(event, fn, context);
458
+ }
459
+ };
460
+ function getMemoryText(element) {
461
+ let temp = getMemoryContainer(element);
462
+ return __spreadProps(__spreadValues({}, temp), {
463
+ className: "CanvasText",
464
+ anchor: { x: element.anchor.x, y: element.anchor.y },
465
+ text: element.text,
466
+ resolution: element.resolution,
467
+ style: getTextStyle(element.style),
468
+ roundPixels: element.roundPixels,
469
+ onEvents: element.onEvents
470
+ });
471
+ }
472
+ function setMemoryText(element, memory) {
473
+ setMemoryContainer(element, memory);
474
+ if (memory.anchor) {
475
+ if (typeof memory.anchor === "number") {
476
+ element.anchor.set(memory.anchor, memory.anchor);
477
+ } else {
478
+ element.anchor.set(memory.anchor.x, memory.anchor.y);
479
+ }
480
+ }
481
+ memory.text && (element.text = memory.text);
482
+ memory.resolution && (element.resolution = memory.resolution);
483
+ memory.style && (element.style = memory.style);
484
+ memory.roundPixels && (element.roundPixels = memory.roundPixels);
485
+ for (let event in memory.onEvents) {
486
+ let className = memory.onEvents[event];
487
+ let instance = getEventTypeByClassName(className);
488
+ if (instance) {
489
+ element.onEvent(event, instance);
490
+ }
491
+ }
492
+ }
493
+
494
+ // src/decorators/CanvasElementDecorator.ts
495
+ var registeredCanvasElement = {};
496
+ function getCanvasElementInstanceByClassName(canvasName) {
497
+ try {
498
+ let eventType = registeredCanvasElement[canvasName];
499
+ if (!eventType) {
500
+ if (canvasName === "CanvasContainer") {
501
+ eventType = CanvasContainer;
502
+ } else if (canvasName === "CanvasImage") {
503
+ eventType = CanvasImage;
504
+ } else if (canvasName === "CanvasSprite") {
505
+ eventType = CanvasSprite;
506
+ } else if (canvasName === "CanvasText") {
507
+ eventType = CanvasText;
508
+ }
509
+ }
510
+ if (!eventType) {
511
+ console.error(`[Pixi'VN] CanvasElement ${canvasName} not found`);
512
+ return;
513
+ }
514
+ let canvasElement = new eventType();
515
+ return canvasElement;
516
+ } catch (e) {
517
+ console.error(`[Pixi'VN] Error while getting CanvasElement ${canvasName}`, e);
518
+ return;
519
+ }
520
+ }
9
521
  function checkIfStepsIsEqual(step1, step2) {
10
522
  return step1 === step2;
11
523
  }
12
524
 
13
525
  // src/classes/Label.ts
14
526
  var Label = class {
527
+ /**
528
+ * @param id is the id of the label
529
+ * @param steps is the list of steps that the label will perform
530
+ * @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
531
+ * @param choiseIndex is the index of the choice that the label will perform
532
+ */
533
+ constructor(id, steps, onStepRun, choiseIndex) {
534
+ this._id = id;
535
+ this._steps = steps;
536
+ this._onStepRun = onStepRun;
537
+ this._choiseIndex = choiseIndex;
538
+ }
539
+ /**
540
+ * Get the id of the label
541
+ */
542
+ get id() {
543
+ return this._id;
544
+ }
15
545
  /**
16
546
  * Get the steps of the label.
17
547
  * This class should be extended and the steps method should be overridden.
18
548
  * Every time you update this list will also be updated when the other game versions load.
19
549
  */
20
550
  get steps() {
21
- throw new Error("[Pixi'VN] The method Label.steps must be overridden");
551
+ return this._steps;
22
552
  }
23
553
  /**
24
554
  * Get the corresponding steps number
@@ -37,27 +567,876 @@ var Label = class {
37
567
  });
38
568
  return res;
39
569
  }
570
+ /**
571
+ * 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
572
+ * @returns Promise<void> or void
573
+ * @example
574
+ * ```typescript
575
+ * newLabel("id", [], () => {
576
+ * Assets.load('path/to/image1.png')
577
+ * Assets.load('path/to/image2.png')
578
+ * })
579
+ * ```
580
+ */
581
+ get onStepRun() {
582
+ return this._onStepRun;
583
+ }
584
+ get choiseIndex() {
585
+ return this._choiseIndex;
586
+ }
40
587
  };
41
588
 
42
589
  // src/classes/CloseLabel.ts
590
+ var CLOSE_LABEL_ID = "__close-label-id__";
43
591
  var CloseLabel = class extends Label {
592
+ constructor(choiseIndex) {
593
+ super(CLOSE_LABEL_ID, [], void 0, choiseIndex);
594
+ }
44
595
  };
45
596
 
597
+ // src/types/CloseType.ts
598
+ var Close = "close";
599
+
600
+ // src/types/PauseType.ts
601
+ var PauseValueType = "pause";
602
+
603
+ // src/types/RepeatType.ts
604
+ var Repeat = "repeat";
605
+
606
+ // src/classes/ticker/TickerBase.ts
607
+ var TickerBase = class {
608
+ /**
609
+ * @param args The arguments that you want to pass to the ticker.
610
+ * @param duration The duration of the ticker. If is undefined, the ticker will be called every frame.
611
+ * @param priority The priority of the ticker. If is undefined, the priority will be UPDATE_PRIORITY.NORMAL.
612
+ */
613
+ constructor(args, duration, priority) {
614
+ this.args = args;
615
+ this.duration = duration;
616
+ this.priority = priority;
617
+ }
618
+ /**
619
+ * The method that will be called every frame.
620
+ * This method should be overridden and you can use GameWindowManager.addCanvasElement() to get the canvas element of the canvas, and edit them.
621
+ * @param t The ticker that is calling this method
622
+ * @param args The arguments that you passed when you added the ticker
623
+ * @param tags The tags of the canvas elements that are connected to this ticker
624
+ */
625
+ fn(_t, _args, _tags) {
626
+ throw new Error("[Pixi'VN] The method TickerBase.fn() must be overridden");
627
+ }
628
+ };
629
+ var TickerFadeAlpha = class extends TickerBase {
630
+ /**
631
+ * The method that will be called every frame to fade the alpha of the canvas element of the canvas.
632
+ * @param delta The delta time
633
+ * @param args The arguments that are passed to the ticker
634
+ * @param tags The tags of the canvas element that are connected to this ticker
635
+ */
636
+ fn(t, args, tags) {
637
+ let type = args.type === void 0 ? "hide" : args.type;
638
+ let speed = args.speed === void 0 ? 0.1 : args.speed;
639
+ let limit = args.limit === void 0 ? type === "hide" ? 0 : 1 : args.limit;
640
+ let removeElementAfter = args.tagToRemoveAfter || [];
641
+ if (typeof removeElementAfter === "string") {
642
+ removeElementAfter = [removeElementAfter];
643
+ }
644
+ if (type === "hide" && limit < 0) {
645
+ limit = 0;
646
+ }
647
+ if (type === "show" && limit > 1) {
648
+ limit = 1;
649
+ }
650
+ tags.filter((tag) => {
651
+ var _a;
652
+ let element = GameWindowManager.getCanvasElement(tag);
653
+ if (args.startOnlyIfHaveTexture) {
654
+ if (element && element instanceof pixi_js.Sprite && ((_a = element.texture) == null ? void 0 : _a.label) == "EMPTY") {
655
+ return false;
656
+ }
657
+ }
658
+ return true;
659
+ }).forEach((tag) => {
660
+ let element = GameWindowManager.getCanvasElement(tag);
661
+ if (element && element instanceof pixi_js.Container) {
662
+ if (type === "show" && element.alpha < limit) {
663
+ element.alpha += speed * t.deltaTime;
664
+ } else if (type === "hide" && element.alpha > limit) {
665
+ element.alpha -= speed * t.deltaTime;
666
+ } else {
667
+ element.alpha = limit;
668
+ GameWindowManager.removeAssociationBetweenTickerCanvasElement(tag, this);
669
+ GameWindowManager.removeCanvasElement(removeElementAfter);
670
+ }
671
+ }
672
+ });
673
+ }
674
+ };
675
+ TickerFadeAlpha = __decorateClass([
676
+ tickerDecorator()
677
+ ], TickerFadeAlpha);
678
+
679
+ // src/functions/TickerUtility.ts
680
+ function updateTickerProgression(args, propertyName, progression) {
681
+ if (args.hasOwnProperty(propertyName) && typeof args[propertyName] !== "number") {
682
+ return;
683
+ }
684
+ if (args[propertyName] !== void 0 && progression && args[propertyName] !== progression.limit) {
685
+ if (progression.type === "linear") {
686
+ args[propertyName] += progression.amt;
687
+ if (progression.limit !== void 0) {
688
+ if (args[propertyName] > progression.limit && progression.amt > 0) {
689
+ args[propertyName] = progression.limit;
690
+ } else if (args[propertyName] < progression.limit && progression.amt < 0) {
691
+ args[propertyName] = progression.limit;
692
+ }
693
+ }
694
+ } else if (progression.type === "exponential") {
695
+ args[propertyName] += args[propertyName] * progression.percentage;
696
+ if (progression.limit !== void 0) {
697
+ if (args[propertyName] > progression.limit && progression.percentage > 0) {
698
+ args[propertyName] = progression.limit;
699
+ } else if (args[propertyName] < progression.limit && progression.percentage < 0) {
700
+ args[propertyName] = progression.limit;
701
+ }
702
+ }
703
+ }
704
+ }
705
+ }
706
+
707
+ // src/classes/ticker/TickerMove.ts
708
+ var TickerMove = class extends TickerBase {
709
+ /**
710
+ * The method that will be called every frame to move the canvas element of the canvas.
711
+ * @param t The ticker that is calling this method
712
+ * @param args The arguments that are passed to the ticker
713
+ * @param tags The tags of the canvas element that are connected to this ticker
714
+ */
715
+ fn(t, args, tags) {
716
+ let speed = args.speed === void 0 ? 0.1 : args.speed;
717
+ let destination = args.destination;
718
+ tags.filter((tag) => {
719
+ var _a;
720
+ let element = GameWindowManager.getCanvasElement(tag);
721
+ if (args.startOnlyIfHaveTexture) {
722
+ if (element && element instanceof pixi_js.Sprite && ((_a = element.texture) == null ? void 0 : _a.label) == "EMPTY") {
723
+ return false;
724
+ }
725
+ }
726
+ return true;
727
+ }).forEach((tag) => {
728
+ let element = GameWindowManager.getCanvasElement(tag);
729
+ if (element && element instanceof pixi_js.Container) {
730
+ let xDistance = destination.x - element.x;
731
+ if (xDistance != 0) {
732
+ element.x += xDistance / speed * t.deltaTime;
733
+ let newDistance = destination.x - element.x;
734
+ if (xDistance < 0 && newDistance > 0 || xDistance > 0 && newDistance < 0) {
735
+ element.x = destination.x;
736
+ }
737
+ }
738
+ let yDistance = destination.y - element.y;
739
+ if (yDistance != 0) {
740
+ element.y += yDistance / speed * t.deltaTime;
741
+ let newDistance = destination.y - element.y;
742
+ if (yDistance < 0 && newDistance > 0 || yDistance > 0 && newDistance < 0) {
743
+ element.y = destination.y;
744
+ }
745
+ }
746
+ }
747
+ });
748
+ if (args.speedProgression)
749
+ updateTickerProgression(args, "speed", args.speedProgression);
750
+ }
751
+ };
752
+ TickerMove = __decorateClass([
753
+ tickerDecorator()
754
+ ], TickerMove);
755
+ var TickerRotate = class extends TickerBase {
756
+ /**
757
+ * The method that will be called every frame to rotate the canvas element of the canvas.
758
+ * @param delta The delta time
759
+ * @param args The arguments that are passed to the ticker
760
+ * @param tags The tags of the canvas element that are connected to this ticker
761
+ */
762
+ fn(t, args, tags) {
763
+ let speed = args.speed === void 0 ? 0.1 : args.speed;
764
+ let clockwise = args.clockwise === void 0 ? true : args.clockwise;
765
+ tags.filter((tag) => {
766
+ var _a;
767
+ let element = GameWindowManager.getCanvasElement(tag);
768
+ if (args.startOnlyIfHaveTexture) {
769
+ if (element && element instanceof pixi_js.Sprite && ((_a = element.texture) == null ? void 0 : _a.label) == "EMPTY") {
770
+ return false;
771
+ }
772
+ }
773
+ return true;
774
+ }).forEach((tag) => {
775
+ let element = GameWindowManager.getCanvasElement(tag);
776
+ if (element && element instanceof pixi_js.Container) {
777
+ if (clockwise)
778
+ element.rotation += speed * t.deltaTime;
779
+ else
780
+ element.rotation -= speed * t.deltaTime;
781
+ }
782
+ });
783
+ if (args.speedProgression)
784
+ updateTickerProgression(args, "speed", args.speedProgression);
785
+ }
786
+ };
787
+ TickerRotate = __decorateClass([
788
+ tickerDecorator()
789
+ ], TickerRotate);
790
+
791
+ // src/functions/ExportUtility.ts
792
+ function createExportableElement(element) {
793
+ try {
794
+ let elementString = JSON.stringify(element);
795
+ return JSON.parse(elementString);
796
+ } catch (e) {
797
+ console.error("[Pixi'VN] Error creating exportable element", e);
798
+ throw new Error("[Pixi'VN] Error creating exportable element");
799
+ }
800
+ }
801
+
802
+ // src/decorators/TickerDecorator.ts
803
+ var registeredTickers = {};
804
+ function tickerDecorator(name) {
805
+ return function(target) {
806
+ if (!name) {
807
+ name = target.name;
808
+ }
809
+ if (registeredTickers[name]) {
810
+ console.warn(`[Pixi'VN] Ticker ${name} already exists, it will be overwritten`);
811
+ }
812
+ registeredTickers[name] = target;
813
+ };
814
+ }
815
+ function geTickerInstanceByClassName(tickerName, args, duration, priority) {
816
+ try {
817
+ let ticker = registeredTickers[tickerName];
818
+ if (!ticker) {
819
+ console.error(`[Pixi'VN] Ticker ${tickerName} not found`);
820
+ return;
821
+ }
822
+ return new ticker(args, duration, priority);
823
+ } catch (e) {
824
+ console.error(`[Pixi'VN] Error while getting Ticker ${tickerName}`, e);
825
+ return;
826
+ }
827
+ }
828
+
829
+ // src/functions/EasterEgg.ts
830
+ function asciiArtLog() {
831
+ console.info(`
832
+ ____ _ _ ___ ___ _
833
+ | _ \\(_)_ _(_| ) \\ / / \\ | |
834
+ | |_) | \\ \\/ / |/ \\ \\ / /| \\| |
835
+ | __/| |> <| | \\ V / | |\\ |
836
+ |_| |_/_/\\_\\_| \\_/ |_| \\_|
837
+ `);
838
+ }
839
+
840
+ // src/managers/WindowManager.ts
841
+ var _GameWindowManager = class _GameWindowManager {
842
+ constructor() {
843
+ }
844
+ /**
845
+ * The PIXI Application instance.
846
+ * It not recommended to use this property directly.
847
+ */
848
+ static get app() {
849
+ if (!_GameWindowManager._app) {
850
+ throw new Error("[Pixi'VN] GameWindowManager.app is undefined");
851
+ }
852
+ return _GameWindowManager._app;
853
+ }
854
+ /**
855
+ * If the manager is initialized.
856
+ */
857
+ static get isInitialized() {
858
+ return _GameWindowManager._isInitialized;
859
+ }
860
+ static get screen() {
861
+ return _GameWindowManager.app.screen;
862
+ }
863
+ /**
864
+ * Initialize the PIXI Application and the interface div.
865
+ * This method should be called before any other method.
866
+ * @param element The html element where I will put the canvas. Example: document.body
867
+ * @param width The width of the canvas
868
+ * @param height The height of the canvas
869
+ * @param options The options of PIXI Application
870
+ * @example
871
+ * ```typescript
872
+ * const body = document.body
873
+ * if (!body) {
874
+ * throw new Error('body element not found')
875
+ * }
876
+ * await GameWindowManager.initialize(body, 1920, 1080, {
877
+ * backgroundColor: "#303030"
878
+ * })
879
+ * ```
880
+ */
881
+ static initialize(element, width, height, options) {
882
+ return __async(this, null, function* () {
883
+ _GameWindowManager.canvasWidth = width;
884
+ _GameWindowManager.canvasHeight = height;
885
+ _GameWindowManager._app = new pixi_js.Application();
886
+ return _GameWindowManager.app.init(__spreadValues({
887
+ resolution: window.devicePixelRatio || 1,
888
+ autoDensity: true,
889
+ width,
890
+ height
891
+ }, options)).then(() => {
892
+ _GameWindowManager._isInitialized = true;
893
+ this.addCanvasIntoElement(element);
894
+ window.addEventListener("resize", _GameWindowManager.resize);
895
+ _GameWindowManager.resize();
896
+ asciiArtLog();
897
+ });
898
+ });
899
+ }
900
+ /**
901
+ * Add the canvas into a html element.
902
+ * @param element it is the html element where I will put the canvas. Example: document.body
903
+ */
904
+ static addCanvasIntoElement(element) {
905
+ if (_GameWindowManager.isInitialized) {
906
+ element.appendChild(_GameWindowManager.app.canvas);
907
+ } else {
908
+ console.error("[Pixi'VN] GameWindowManager is not initialized");
909
+ }
910
+ }
911
+ /**
912
+ * Initialize the interface div and add it into a html element.
913
+ * @param element it is the html element where I will put the interface div. Example: document.getElementById('root')
914
+ * @example
915
+ * ```typescript
916
+ * const root = document.getElementById('root')
917
+ * if (!root) {
918
+ * throw new Error('root element not found')
919
+ * }
920
+ * GameWindowManager.initializeHTMLLayout(root)
921
+ * const reactRoot = createRoot(GameWindowManager.htmlLayout)
922
+ * reactRoot.render(
923
+ * <App />
924
+ * )
925
+ * ```
926
+ */
927
+ static initializeHTMLLayout(element) {
928
+ let div = document.createElement("div");
929
+ div.style.position = "absolute";
930
+ div.style.pointerEvents = "none";
931
+ element.appendChild(div);
932
+ _GameWindowManager.htmlLayout = div;
933
+ _GameWindowManager.resize();
934
+ }
935
+ /* Resize Metods */
936
+ /**
937
+ * This method returns the scale of the screen.
938
+ */
939
+ static get screenScale() {
940
+ let screenWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
941
+ let screenHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
942
+ return Math.min(screenWidth / _GameWindowManager.canvasWidth, screenHeight / _GameWindowManager.canvasHeight);
943
+ }
944
+ /**
945
+ * This method returns the width of the screen enlarged by the scale.
946
+ */
947
+ static get screenWidth() {
948
+ return Math.floor(_GameWindowManager.screenScale * _GameWindowManager.canvasWidth);
949
+ }
950
+ /**
951
+ * This method returns the height of the screen enlarged by the scale.
952
+ */
953
+ static get screenHeight() {
954
+ return Math.floor(_GameWindowManager.screenScale * _GameWindowManager.canvasHeight);
955
+ }
956
+ /**
957
+ * This method returns the horizontal margin of the screen.
958
+ */
959
+ static get horizontalMargin() {
960
+ let screenWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
961
+ return (screenWidth - _GameWindowManager.screenWidth) / 2;
962
+ }
963
+ /**
964
+ * This method returns the vertical margin of the screen.
965
+ */
966
+ static get verticalMargin() {
967
+ let screenHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
968
+ return (screenHeight - _GameWindowManager.screenHeight) / 2;
969
+ }
970
+ /**
971
+ * This method is called when the screen is resized.
972
+ */
973
+ static resize() {
974
+ if (_GameWindowManager.isInitialized) {
975
+ let style = _GameWindowManager.app.canvas.style;
976
+ style.width = `${_GameWindowManager.screenWidth}px`;
977
+ style.height = `${_GameWindowManager.screenHeight}px`;
978
+ style.marginLeft = `${_GameWindowManager.horizontalMargin}px`;
979
+ style.marginRight = `${_GameWindowManager.horizontalMargin}px`;
980
+ style.marginTop = `${_GameWindowManager.verticalMargin}px`;
981
+ style.marginBottom = `${_GameWindowManager.verticalMargin}px`;
982
+ }
983
+ if (_GameWindowManager.htmlLayout) {
984
+ _GameWindowManager.htmlLayout.style.width = `${_GameWindowManager.screenWidth}px`;
985
+ _GameWindowManager.htmlLayout.style.height = `${_GameWindowManager.screenHeight}px`;
986
+ _GameWindowManager.htmlLayout.style.marginLeft = `${_GameWindowManager.horizontalMargin}px`;
987
+ _GameWindowManager.htmlLayout.style.marginRight = `${_GameWindowManager.horizontalMargin}px`;
988
+ _GameWindowManager.htmlLayout.style.marginTop = `${_GameWindowManager.verticalMargin}px`;
989
+ _GameWindowManager.htmlLayout.style.marginBottom = `${_GameWindowManager.verticalMargin}px`;
990
+ }
991
+ }
992
+ /* Edit Canvas Elements Methods */
993
+ /**
994
+ * This is a dictionary that contains all Canvas Elements of Canvas, currently.
995
+ */
996
+ static get currentCanvasElements() {
997
+ return _GameWindowManager._children;
998
+ }
999
+ /**
1000
+ * Add a canvas element to the canvas.
1001
+ * If there is a canvas element with the same tag, it will be removed.
1002
+ * @param tag The tag of the canvas element.
1003
+ * @param canvasElement The canvas elements to be added.
1004
+ * @example
1005
+ * ```typescript
1006
+ * const texture = await Assets.load('https://pixijs.com/assets/bunny.png');
1007
+ * const sprite = CanvasSprite.from(texture);
1008
+ * GameWindowManager.addCanvasElement("bunny", sprite);
1009
+ * ```
1010
+ */
1011
+ static addCanvasElement(tag, canvasElement) {
1012
+ if (_GameWindowManager._children[tag]) {
1013
+ _GameWindowManager.removeCanvasElement(tag);
1014
+ }
1015
+ _GameWindowManager.app.stage.addChild(canvasElement);
1016
+ _GameWindowManager._children[tag] = canvasElement;
1017
+ _GameWindowManager.childrenTagsOrder.push(tag);
1018
+ }
1019
+ /**
1020
+ * Remove a canvas element from the canvas.
1021
+ * And remove all tickers that are not connected to any canvas element.
1022
+ * @param tag The tag of the canvas element to be removed.
1023
+ * @returns
1024
+ * @example
1025
+ * ```typescript
1026
+ * GameWindowManager.removeCanvasElement("bunny");
1027
+ * ```
1028
+ */
1029
+ static removeCanvasElement(tag) {
1030
+ if (typeof tag === "string") {
1031
+ tag = [tag];
1032
+ }
1033
+ tag.forEach((t) => {
1034
+ if (_GameWindowManager._children[t]) {
1035
+ _GameWindowManager.app.stage.removeChild(_GameWindowManager._children[t]);
1036
+ delete _GameWindowManager._children[t];
1037
+ }
1038
+ });
1039
+ _GameWindowManager.removeTickersWithoutAssociatedCanvasElement();
1040
+ _GameWindowManager.childrenTagsOrder = _GameWindowManager.childrenTagsOrder.filter((t) => !tag.includes(t));
1041
+ }
1042
+ /**
1043
+ * Get a canvas element by the tag.
1044
+ * @param tag The tag of the canvas element.
1045
+ * @returns The canvas element.
1046
+ * @example
1047
+ * ```typescript
1048
+ * const sprite = GameWindowManager.getCanvasElement<CanvasSprite>("bunny");
1049
+ * ```
1050
+ */
1051
+ static getCanvasElement(tag) {
1052
+ return _GameWindowManager._children[tag];
1053
+ }
1054
+ /**
1055
+ * Check if a DisplayObject is on the canvas.
1056
+ * @param pixiElement The DisplayObject to be checked.
1057
+ * @returns If the DisplayObject is on the canvas.
1058
+ */
1059
+ static canvasElementIsOnCanvas(pixiElement) {
1060
+ return _GameWindowManager.app.stage.children.includes(pixiElement);
1061
+ }
1062
+ /**
1063
+ * Remove all canvas elements from the canvas.
1064
+ * And remove all tickers that are not connected to any canvas element.
1065
+ */
1066
+ static removeCanvasElements() {
1067
+ _GameWindowManager.app.stage.removeChildren();
1068
+ _GameWindowManager._children = {};
1069
+ _GameWindowManager.childrenTagsOrder = [];
1070
+ _GameWindowManager.removeTickers();
1071
+ }
1072
+ /**
1073
+ * Edit the tag of a canvas element.
1074
+ * @param oldTag The old tag of the canvas element.
1075
+ * @param newTag The new tag of the canvas element.
1076
+ */
1077
+ static editTagCanvasElement(oldTag, newTag) {
1078
+ if (_GameWindowManager._children[oldTag]) {
1079
+ _GameWindowManager._children[newTag] = _GameWindowManager._children[oldTag];
1080
+ delete _GameWindowManager._children[oldTag];
1081
+ }
1082
+ }
1083
+ /** Edit Tickers Methods */
1084
+ /**
1085
+ * Currently tickers that are running.
1086
+ */
1087
+ static get currentTickers() {
1088
+ return _GameWindowManager._currentTickers;
1089
+ }
1090
+ /**
1091
+ * The steps of the tickers
1092
+ */
1093
+ static get currentTickersSteps() {
1094
+ return _GameWindowManager._currentTickersSteps;
1095
+ }
1096
+ /**
1097
+ * Run a ticker.
1098
+ * @param canvasEslementTag The tag of the canvas element that will use the ticker.
1099
+ * @param ticker The ticker class to be run.
1100
+ * @param args The arguments to be used in the ticker.
1101
+ * @param duration The time to be used in the ticker. This number is in milliseconds. If it is undefined, the ticker will run forever.
1102
+ * @param priority The priority to be used in the ticker.
1103
+ * @returns
1104
+ * @example
1105
+ * ```typescript
1106
+ * GameWindowManager.addTicker("alien", new TickerRotate({ speed: 0.2 }))
1107
+ * ```
1108
+ */
1109
+ static addTicker(canvasElementTag, ticker) {
1110
+ let tickerName = ticker.constructor.name;
1111
+ if (typeof canvasElementTag === "string") {
1112
+ canvasElementTag = [canvasElementTag];
1113
+ }
1114
+ let t = geTickerInstanceByClassName(tickerName, ticker.args, ticker.duration, ticker.priority);
1115
+ if (!t) {
1116
+ console.error(`[Pixi'VN] Ticker ${tickerName} not found`);
1117
+ return;
1118
+ }
1119
+ _GameWindowManager.removeAssociationBetweenTickerCanvasElement(canvasElementTag, ticker);
1120
+ let tickerHistory = {
1121
+ fn: () => {
1122
+ },
1123
+ className: tickerName,
1124
+ args: ticker.args,
1125
+ canvasElementTags: canvasElementTag,
1126
+ priority: ticker.priority,
1127
+ duration: ticker.duration
1128
+ };
1129
+ _GameWindowManager.pushTicker(tickerHistory, t);
1130
+ _GameWindowManager.removeTickersWithoutAssociatedCanvasElement();
1131
+ if (ticker.duration) {
1132
+ let timeout = setTimeout(() => {
1133
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
1134
+ _GameWindowManager.nextTickerStep(canvasElementTag);
1135
+ }, ticker.duration);
1136
+ _GameWindowManager.addTickerTimeoutInfo(canvasElementTag, tickerName, timeout.toString());
1137
+ }
1138
+ }
1139
+ static pushTicker(tickerData, ticker) {
1140
+ _GameWindowManager.removeAssociationBetweenTickerCanvasElement(tickerData.canvasElementTags, tickerData);
1141
+ _GameWindowManager._currentTickers.push(tickerData);
1142
+ tickerData.fn = (t) => {
1143
+ ticker == null ? void 0 : ticker.fn(t, tickerData.args, tickerData.canvasElementTags);
1144
+ };
1145
+ _GameWindowManager.app.ticker.add(tickerData.fn, void 0, tickerData.priority);
1146
+ }
1147
+ /**
1148
+ * Run a sequence of tickers.
1149
+ * @param tag The tag of canvas element that will use the tickers.
1150
+ * @param steps The steps of the tickers.
1151
+ * @returns
1152
+ * @example
1153
+ * ```typescript
1154
+ * GameWindowManager.addTickersSteps("alien", [
1155
+ * new TickerRotate({ speed: 0.1, clockwise: true }, 2000),
1156
+ * Pause(500),
1157
+ * new TickerRotate({ speed: 0.2, clockwise: false }, 2000),
1158
+ * Repeat,
1159
+ * ])
1160
+ * ```
1161
+ */
1162
+ static addTickersSteps(tag, steps) {
1163
+ if (steps.length == 0) {
1164
+ console.warn("[Pixi'VN] The steps of the tickers is empty");
1165
+ return;
1166
+ }
1167
+ let alredyExists = _GameWindowManager._currentTickersSteps[tag] !== void 0;
1168
+ _GameWindowManager._currentTickersSteps[tag] = {
1169
+ currentStepNumber: 0,
1170
+ steps: steps.map((s) => {
1171
+ if (s === Repeat) {
1172
+ return s;
1173
+ }
1174
+ if (!s.duration) {
1175
+ console.warn("[Pixi'VN] Duration is not defined, so it will be set to 1000");
1176
+ s.duration = 1e3;
1177
+ }
1178
+ if (s.hasOwnProperty("type") && s.type === PauseValueType) {
1179
+ return s;
1180
+ }
1181
+ let tickerName = s.constructor.name;
1182
+ return {
1183
+ ticker: tickerName,
1184
+ args: s.args,
1185
+ duration: s.duration
1186
+ };
1187
+ })
1188
+ };
1189
+ if (!alredyExists) {
1190
+ _GameWindowManager.runTickersSteps(tag);
1191
+ }
1192
+ }
1193
+ static runTickersSteps(tag) {
1194
+ let step = _GameWindowManager._currentTickersSteps[tag].steps[_GameWindowManager._currentTickersSteps[tag].currentStepNumber];
1195
+ if (step === Repeat) {
1196
+ step = _GameWindowManager._currentTickersSteps[tag].steps[0];
1197
+ _GameWindowManager._currentTickersSteps[tag].currentStepNumber = 0;
1198
+ if (step === Repeat) {
1199
+ console.error("[Pixi'VN] TikersSteps has a RepeatType in the first step");
1200
+ return;
1201
+ }
1202
+ }
1203
+ if (step.hasOwnProperty("type") && step.type === PauseValueType) {
1204
+ let timeout = setTimeout(() => {
1205
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
1206
+ _GameWindowManager.nextTickerStep(tag);
1207
+ }, step.duration);
1208
+ _GameWindowManager.addTickerTimeoutInfo(tag, "steps", timeout.toString());
1209
+ return;
1210
+ }
1211
+ let ticker = geTickerInstanceByClassName(step.ticker, step.args, step.duration, step.priority);
1212
+ if (!ticker) {
1213
+ console.error(`[Pixi'VN] Ticker ${step.ticker} not found`);
1214
+ return;
1215
+ }
1216
+ _GameWindowManager.addTicker(tag, ticker);
1217
+ }
1218
+ static nextTickerStep(tag) {
1219
+ if (typeof tag === "string") {
1220
+ tag = [tag];
1221
+ }
1222
+ tag.forEach((tag2) => {
1223
+ if (_GameWindowManager._currentTickersSteps[tag2]) {
1224
+ let steps = _GameWindowManager._currentTickersSteps[tag2];
1225
+ if (steps.currentStepNumber + 1 < steps.steps.length) {
1226
+ steps.currentStepNumber++;
1227
+ _GameWindowManager._currentTickersSteps[tag2] = steps;
1228
+ _GameWindowManager.runTickersSteps(tag2);
1229
+ } else {
1230
+ delete _GameWindowManager._currentTickersSteps[tag2];
1231
+ }
1232
+ }
1233
+ });
1234
+ }
1235
+ /**
1236
+ * Remove a connection between a canvas element and a ticker.
1237
+ * And remove the ticker if there is no canvas element connected to it.
1238
+ * @param tag The tag of the canvas element that will use the ticker.
1239
+ * @param ticker The ticker class to be removed.
1240
+ * @example
1241
+ * ```typescript
1242
+ * GameWindowManager.removeAssociationBetweenTickerCanvasElement("alien", TickerRotate)
1243
+ * ```
1244
+ */
1245
+ static removeAssociationBetweenTickerCanvasElement(tag, ticker) {
1246
+ let tickerName;
1247
+ if (ticker instanceof TickerBase) {
1248
+ tickerName = ticker.constructor.name;
1249
+ } else {
1250
+ tickerName = ticker.name;
1251
+ }
1252
+ if (typeof tag === "string") {
1253
+ tag = [tag];
1254
+ }
1255
+ _GameWindowManager._currentTickers = _GameWindowManager._currentTickers.map((t) => {
1256
+ if (t.className === tickerName) {
1257
+ t.canvasElementTags = t.canvasElementTags.filter((e) => !tag.includes(e));
1258
+ }
1259
+ return t;
1260
+ });
1261
+ for (let timeout in _GameWindowManager.currentTickersTimeouts) {
1262
+ let t = _GameWindowManager.currentTickersTimeouts[timeout].tags.filter((e) => !tag.includes(e));
1263
+ if (t.length == 0) {
1264
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
1265
+ } else {
1266
+ _GameWindowManager.currentTickersTimeouts[timeout].tags = t;
1267
+ }
1268
+ }
1269
+ _GameWindowManager.removeTickersWithoutAssociatedCanvasElement();
1270
+ }
1271
+ /**
1272
+ * Remove all tickers that are not connected to any existing canvas element.
1273
+ */
1274
+ static removeTickersWithoutAssociatedCanvasElement() {
1275
+ let currentTickers = _GameWindowManager._currentTickers.map((t) => {
1276
+ t.canvasElementTags = t.canvasElementTags.filter((e) => _GameWindowManager._children[e]);
1277
+ return t;
1278
+ });
1279
+ currentTickers.filter((t) => t.canvasElementTags.length === 0).forEach((t) => {
1280
+ _GameWindowManager.app.ticker.remove(t.fn);
1281
+ });
1282
+ currentTickers = currentTickers.filter((t) => t.canvasElementTags.length > 0);
1283
+ _GameWindowManager._currentTickers = currentTickers;
1284
+ for (let tag in _GameWindowManager._currentTickersSteps) {
1285
+ if (_GameWindowManager._children[tag] === void 0) {
1286
+ delete _GameWindowManager._currentTickersSteps[tag];
1287
+ }
1288
+ }
1289
+ }
1290
+ static addTickerTimeoutInfo(tags, ticker, timeout) {
1291
+ if (typeof tags === "string") {
1292
+ tags = [tags];
1293
+ }
1294
+ _GameWindowManager.currentTickersTimeouts[timeout] = {
1295
+ tags,
1296
+ ticker
1297
+ };
1298
+ }
1299
+ static removeTickerTimeoutInfo(timeout) {
1300
+ if (typeof timeout !== "string") {
1301
+ timeout = timeout.toString();
1302
+ }
1303
+ if (_GameWindowManager.currentTickersTimeouts[timeout]) {
1304
+ delete _GameWindowManager.currentTickersTimeouts[timeout];
1305
+ }
1306
+ }
1307
+ /**
1308
+ * Remove all tickers from the canvas.
1309
+ */
1310
+ static removeTickers() {
1311
+ _GameWindowManager._currentTickersSteps = {};
1312
+ _GameWindowManager._currentTickers.forEach((t) => {
1313
+ _GameWindowManager.app.ticker.remove(t.fn);
1314
+ });
1315
+ _GameWindowManager._currentTickers = [];
1316
+ for (let timeout in _GameWindowManager.currentTickersTimeouts) {
1317
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
1318
+ }
1319
+ }
1320
+ /**
1321
+ * Clear the canvas and the tickers.
1322
+ */
1323
+ static clear() {
1324
+ _GameWindowManager.removeCanvasElements();
1325
+ }
1326
+ /* Export and Import Methods */
1327
+ /**
1328
+ * Export the canvas and the tickers to a JSON string.
1329
+ * @returns The JSON string.
1330
+ */
1331
+ static exportJson() {
1332
+ return JSON.stringify(this.export());
1333
+ }
1334
+ /**
1335
+ * Export the canvas and the tickers to an object.
1336
+ * @returns The object.
1337
+ */
1338
+ static export() {
1339
+ let currentElements = {};
1340
+ for (let tag in _GameWindowManager._children) {
1341
+ currentElements[tag] = exportCanvasElement(_GameWindowManager._children[tag]);
1342
+ }
1343
+ return {
1344
+ currentTickers: createExportableElement(_GameWindowManager._currentTickers),
1345
+ currentElements: createExportableElement(currentElements),
1346
+ childrenTagsOrder: createExportableElement(_GameWindowManager.childrenTagsOrder)
1347
+ };
1348
+ }
1349
+ /**
1350
+ * Import the canvas and the tickers from a JSON string.
1351
+ * @param dataString The JSON string.
1352
+ */
1353
+ static importJson(dataString) {
1354
+ _GameWindowManager.import(JSON.parse(dataString));
1355
+ }
1356
+ /**
1357
+ * Import the canvas and the tickers from an object.
1358
+ * @param data The object.
1359
+ */
1360
+ static import(data) {
1361
+ _GameWindowManager.clear();
1362
+ try {
1363
+ if (data.hasOwnProperty("childrenTagsOrder") && data.hasOwnProperty("currentElements")) {
1364
+ let currentElements = data["currentElements"];
1365
+ let childrenTagsOrder = data["childrenTagsOrder"];
1366
+ childrenTagsOrder.forEach((tag) => {
1367
+ if (currentElements[tag]) {
1368
+ let element = importCanvasElement(currentElements[tag]);
1369
+ _GameWindowManager.addCanvasElement(tag, element);
1370
+ _GameWindowManager.childrenTagsOrder.push(tag);
1371
+ }
1372
+ });
1373
+ } else {
1374
+ console.error("[Pixi'VN] The data does not have the properties childrenTagsOrder and currentElements");
1375
+ return;
1376
+ }
1377
+ if (data.hasOwnProperty("currentTickers")) {
1378
+ let currentTickers = data["currentTickers"];
1379
+ currentTickers.forEach((t) => {
1380
+ let tags = t.canvasElementTags;
1381
+ let ticker = geTickerInstanceByClassName(t.className, t.args, t.duration, t.priority);
1382
+ if (ticker) {
1383
+ _GameWindowManager.addTicker(tags, ticker);
1384
+ } else {
1385
+ console.error(`[Pixi'VN] Ticker ${t.className} not found`);
1386
+ }
1387
+ });
1388
+ }
1389
+ } catch (e) {
1390
+ console.error("[Pixi'VN] Error importing data", e);
1391
+ }
1392
+ }
1393
+ };
1394
+ _GameWindowManager._app = void 0;
1395
+ _GameWindowManager._isInitialized = false;
1396
+ _GameWindowManager._children = {};
1397
+ /**
1398
+ * The order of the children tags.
1399
+ */
1400
+ _GameWindowManager.childrenTagsOrder = [];
1401
+ _GameWindowManager._currentTickers = [];
1402
+ _GameWindowManager._currentTickersSteps = {};
1403
+ _GameWindowManager.currentTickersTimeouts = {};
1404
+ var GameWindowManager = _GameWindowManager;
1405
+
1406
+ // src/decorators/LabelDecorator.ts
1407
+ var registeredLabels = {};
1408
+ function getLabelById(id) {
1409
+ let label = registeredLabels[id];
1410
+ if (!label) {
1411
+ console.error(`[Pixi'VN] Label ${id} not found`);
1412
+ return;
1413
+ }
1414
+ return label;
1415
+ }
1416
+
46
1417
  // src/classes/ChoiceMenuOption.ts
47
1418
  var ChoiceMenuOption = class {
48
1419
  /**
49
1420
  * @param text Text to be displayed in the menu
50
- * @param label Label to be opened when the option is selected
51
- * @param type Type of the label to be opened
52
- * @param props Properties to be passed to the label, when the label is called. it cannot contain functions or classes.
1421
+ * @param label Label to be opened when the option is selected or the id of the label
1422
+ * @param type Type of the label to be opened. @default "call"
1423
+ * @param props Properties to be passed to the label, when the label is called. it cannot contain functions or classes. @default {}
53
1424
  */
54
1425
  constructor(text, label, type = "call", props) {
55
1426
  /**
56
1427
  * Properties to be passed to the label
57
1428
  */
58
1429
  this.props = {};
1430
+ if (typeof label === "string") {
1431
+ let tLabel = getLabelById(label);
1432
+ if (!tLabel) {
1433
+ throw new Error(`[Pixi'VN] Label ${label} not found`);
1434
+ } else {
1435
+ label = tLabel;
1436
+ }
1437
+ }
59
1438
  this.text = text;
60
- this.label = new label();
1439
+ this.label = label;
61
1440
  this.type = type;
62
1441
  if (props) {
63
1442
  this.props = props;