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