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