@drincs/pixi-vn 0.1.2 → 0.1.3

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.
package/dist/index.js ADDED
@@ -0,0 +1,2293 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
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 __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+ var __decorateClass = (decorators, target, key, kind) => {
47
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
48
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
49
+ if (decorator = decorators[i])
50
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
51
+ if (kind && result)
52
+ __defProp(target, key, result);
53
+ return result;
54
+ };
55
+ var __async = (__this, __arguments, generator) => {
56
+ return new Promise((resolve, reject) => {
57
+ var fulfilled = (value) => {
58
+ try {
59
+ step(generator.next(value));
60
+ } catch (e) {
61
+ reject(e);
62
+ }
63
+ };
64
+ var rejected = (value) => {
65
+ try {
66
+ step(generator.throw(value));
67
+ } catch (e) {
68
+ reject(e);
69
+ }
70
+ };
71
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
72
+ step((generator = generator.apply(__this, __arguments)).next());
73
+ });
74
+ };
75
+
76
+ // src/index.ts
77
+ var src_exports = {};
78
+ __export(src_exports, {
79
+ CanvasBase: () => CanvasBase,
80
+ CanvasContainer: () => CanvasContainer,
81
+ CanvasEvent: () => CanvasEvent,
82
+ CanvasImage: () => CanvasImage,
83
+ CanvasSprite: () => CanvasSprite,
84
+ CanvasText: () => CanvasText,
85
+ CharacterModelBase: () => CharacterModelBase,
86
+ DialogueModelBase: () => DialogueModelBase,
87
+ GameStepManager: () => GameStepManager,
88
+ GameStorageManager: () => GameStorageManager,
89
+ GameWindowManager: () => GameWindowManager,
90
+ Label: () => Label,
91
+ LabelRunModeEnum: () => LabelRunModeEnum,
92
+ MenuOptionLabel: () => MenuOptionLabel,
93
+ Pause: () => Pause,
94
+ PauseValueType: () => PauseValueType,
95
+ Repeat: () => Repeat,
96
+ StoredClassModel: () => StoredClassModel,
97
+ TickerBase: () => TickerBase,
98
+ TickerFadeAlpha: () => TickerFadeAlpha,
99
+ TickerRotate: () => TickerRotate,
100
+ addImage: () => addImage,
101
+ canvasElementDecorator: () => canvasElementDecorator,
102
+ clearAllGameDatas: () => clearAllGameDatas,
103
+ clearDialogue: () => clearDialogue,
104
+ clearMenuOptions: () => clearMenuOptions,
105
+ eventDecorator: () => eventDecorator,
106
+ getCharacterByTag: () => getCharacterByTag,
107
+ getDialogue: () => getDialogue,
108
+ getDialogueHistory: () => getDialogueHistory,
109
+ getMenuOptions: () => getMenuOptions,
110
+ getSaveData: () => getSaveData,
111
+ getSaveJson: () => getSaveJson,
112
+ getTexture: () => getTexture,
113
+ labelDecorator: () => labelDecorator,
114
+ loadSave: () => loadSave,
115
+ loadSaveJsonString: () => loadSaveJsonString,
116
+ removeCanvasElement: () => removeCanvasElement,
117
+ saveCharacter: () => saveCharacter,
118
+ setDialogue: () => setDialogue,
119
+ setMenuOptions: () => setMenuOptions,
120
+ showCanvasImages: () => showCanvasImages,
121
+ showImageWithDisolveEffect: () => showImageWithDisolveEffect,
122
+ tickerDecorator: () => tickerDecorator
123
+ });
124
+ module.exports = __toCommonJS(src_exports);
125
+
126
+ // src/classes/CanvasEvent.ts
127
+ var CanvasEvent = class {
128
+ fn(_event, _element) {
129
+ throw new Error("[Pixi'VM] The method CanvasEvent.fn() must be overridden");
130
+ }
131
+ };
132
+
133
+ // src/decorators/LabelDecorator.ts
134
+ var registeredLabels = {};
135
+ function labelDecorator(name) {
136
+ return function(target) {
137
+ if (!name) {
138
+ name = target.name;
139
+ }
140
+ if (registeredLabels[name]) {
141
+ console.warn(`Label ${name} already exists, it will be overwritten`);
142
+ }
143
+ registeredLabels[name] = target;
144
+ };
145
+ }
146
+ function getLabelTypeByClassName(labelName) {
147
+ try {
148
+ let labelType = registeredLabels[labelName];
149
+ if (!labelType) {
150
+ console.error(`Label ${labelName} not found`);
151
+ return;
152
+ }
153
+ new labelType();
154
+ return labelType;
155
+ } catch (e) {
156
+ console.error(e);
157
+ return;
158
+ }
159
+ }
160
+ function getLabelInstanceByClassName(labelName) {
161
+ try {
162
+ let labelType = registeredLabels[labelName];
163
+ if (!labelType) {
164
+ console.error(`Label ${labelName} not found`);
165
+ return;
166
+ }
167
+ let label = new labelType();
168
+ let step = label.steps;
169
+ if (step.length = 0) {
170
+ console.warn(`Label ${labelName} has no steps`);
171
+ }
172
+ return label;
173
+ } catch (e) {
174
+ console.error(e);
175
+ return;
176
+ }
177
+ }
178
+
179
+ // src/functions/ExportUtility.ts
180
+ function createExportElement(element) {
181
+ try {
182
+ let elementString = JSON.stringify(element);
183
+ return JSON.parse(elementString);
184
+ } catch (e) {
185
+ throw new Error("[Pixi'VM] The element could not be created");
186
+ }
187
+ }
188
+
189
+ // src/functions/StepLabelUtility.ts
190
+ var import_sha1 = __toESM(require("crypto-js/sha1"));
191
+ function getStepSha1(step) {
192
+ let sha1String = (0, import_sha1.default)(step.toString().toLocaleLowerCase());
193
+ return sha1String.toString();
194
+ }
195
+ function checkIfStepsIsEqual(step1, step2) {
196
+ return step1 === step2;
197
+ }
198
+
199
+ // src/managers/StorageManager.ts
200
+ var _GameStorageManager = class _GameStorageManager {
201
+ constructor() {
202
+ }
203
+ static get keysSystem() {
204
+ return {
205
+ CURRENT_DIALOGUE_MEMORY_KEY: "current_dialogue_memory_key",
206
+ LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY: "last_dialogue_added_in_step_memory_key",
207
+ CURRENT_MENU_OPTIONS_MEMORY_KEY: "current_menu_options_memory_key"
208
+ };
209
+ }
210
+ /**
211
+ * Get a new oid that is not used yet
212
+ * @returns A new oid that is not used yet
213
+ */
214
+ static getNewOid() {
215
+ let oid = "";
216
+ do {
217
+ oid = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
218
+ } while (_GameStorageManager.oidsUsed.includes(oid));
219
+ _GameStorageManager.oidsUsed.push(oid);
220
+ return oid;
221
+ }
222
+ /**
223
+ * Set a variable in the storage
224
+ * @param key The key of the variable
225
+ * @param value The value of the variable. If undefined, the variable will be removed
226
+ * @returns
227
+ */
228
+ static setVariable(key, value) {
229
+ key = key.toLowerCase();
230
+ if (value === void 0) {
231
+ if (_GameStorageManager.storage.hasOwnProperty(key)) {
232
+ delete _GameStorageManager.storage[key];
233
+ }
234
+ return;
235
+ }
236
+ _GameStorageManager.storage[key] = value;
237
+ }
238
+ /**
239
+ * Get a variable from the storage
240
+ * @param key The key of the variable
241
+ * @returns The value of the variable. If the variable does not exist, it will return undefined
242
+ */
243
+ static getVariable(key) {
244
+ key = key.toLowerCase();
245
+ if (_GameStorageManager.storage.hasOwnProperty(key)) {
246
+ return _GameStorageManager.storage[key];
247
+ }
248
+ return void 0;
249
+ }
250
+ /**
251
+ * Remove a variable from the storage
252
+ * @param key The key of the variable
253
+ * @returns
254
+ */
255
+ static removeVariable(key) {
256
+ key = key.toLowerCase();
257
+ if (_GameStorageManager.storage.hasOwnProperty(key)) {
258
+ delete _GameStorageManager.storage[key];
259
+ }
260
+ }
261
+ /**
262
+ * Clear the storage and the oidsUsed
263
+ * @returns
264
+ */
265
+ static clear() {
266
+ _GameStorageManager.oidsUsed = [];
267
+ _GameStorageManager.storage = {};
268
+ }
269
+ static exportJson() {
270
+ return JSON.stringify(this.export());
271
+ }
272
+ static export() {
273
+ return {
274
+ storage: createExportElement(_GameStorageManager.storage),
275
+ stepOidUsedList: createExportElement(_GameStorageManager.oidsUsed)
276
+ };
277
+ }
278
+ static importJson(dataString) {
279
+ _GameStorageManager.import(JSON.parse(dataString));
280
+ }
281
+ static import(data) {
282
+ _GameStorageManager.clear();
283
+ try {
284
+ if (data.hasOwnProperty("storage")) {
285
+ _GameStorageManager.storage = data["storage"];
286
+ } else {
287
+ console.warn("[Pixi'VM] No storage data found");
288
+ }
289
+ if (data.hasOwnProperty("stepOidUsedList")) {
290
+ _GameStorageManager.oidsUsed = data["stepOidUsedList"];
291
+ } else {
292
+ console.warn("[Pixi'VM] No stepOidUsed data found");
293
+ }
294
+ } catch (e) {
295
+ console.error("[Pixi'VM] Error importing data", e);
296
+ }
297
+ }
298
+ };
299
+ _GameStorageManager.oidsUsed = [];
300
+ _GameStorageManager.storage = {};
301
+ var GameStorageManager = _GameStorageManager;
302
+
303
+ // src/managers/WindowManager.ts
304
+ var import_pixi = require("pixi.js");
305
+
306
+ // src/classes/ticker/TickerBase.ts
307
+ var TickerBase = class {
308
+ constructor(args, duration, priority) {
309
+ this.args = args;
310
+ this.duration = duration;
311
+ this.priority = priority;
312
+ }
313
+ /**
314
+ * The method that will be called every frame.
315
+ * This method should be overridden and you can use GameWindowManager.addCanvasElement() to get the canvas element of the canvas, and edit them.
316
+ * @param t The ticker that is calling this method
317
+ * @param args The arguments that you passed when you added the ticker
318
+ * @param tags The tags of the canvas elements that are connected to this ticker
319
+ */
320
+ fn(_t, _args, _tags) {
321
+ throw new Error("[Pixi'VM] The method TickerBase.fn() must be overridden");
322
+ }
323
+ };
324
+
325
+ // src/decorators/TickerDecorator.ts
326
+ var registeredTickers = {};
327
+ function tickerDecorator(name) {
328
+ return function(target) {
329
+ if (!name) {
330
+ name = target.name;
331
+ }
332
+ if (registeredTickers[name]) {
333
+ console.warn(`Ticker ${name} already exists, it will be overwritten`);
334
+ }
335
+ registeredTickers[name] = target;
336
+ };
337
+ }
338
+ function geTickerInstanceByClassName(tickerName, args, duration, priority) {
339
+ try {
340
+ let ticker = registeredTickers[tickerName];
341
+ if (!ticker) {
342
+ console.error(`Ticker ${tickerName} not found`);
343
+ return;
344
+ }
345
+ return new ticker(args, duration, priority);
346
+ } catch (e) {
347
+ console.error(e);
348
+ return;
349
+ }
350
+ }
351
+
352
+ // src/decorators/CanvasElementDecorator.ts
353
+ var registeredCanvasElement = {};
354
+ function canvasElementDecorator(name) {
355
+ return function(target) {
356
+ if (!name) {
357
+ name = target.name;
358
+ }
359
+ if (registeredCanvasElement[name]) {
360
+ console.warn(`CanvasElement ${name} already registered`);
361
+ }
362
+ registeredCanvasElement[name] = target;
363
+ };
364
+ }
365
+ function getCanvasElementInstanceByClassName(canvasName) {
366
+ try {
367
+ let eventType = registeredCanvasElement[canvasName];
368
+ if (!eventType) {
369
+ console.error(`CanvasElement ${canvasName} not found`);
370
+ return;
371
+ }
372
+ let canvasElement = new eventType();
373
+ return canvasElement;
374
+ } catch (e) {
375
+ console.error(e);
376
+ return;
377
+ }
378
+ }
379
+
380
+ // src/functions/CanvasUtility.ts
381
+ function getTextureMemory(texture) {
382
+ let sourceTexture = texture.source;
383
+ let textureMemory = {
384
+ image: sourceTexture.label
385
+ };
386
+ return textureMemory;
387
+ }
388
+ function exportCanvasElement(element) {
389
+ return element.memory;
390
+ }
391
+ function importCanvasElement(memory) {
392
+ let element = getCanvasElementInstanceByClassName(memory.className);
393
+ if (element) {
394
+ element.memory = memory;
395
+ } else {
396
+ throw new Error("[Pixi'VM] The element could not be created");
397
+ }
398
+ return element;
399
+ }
400
+
401
+ // src/types/PauseType.ts
402
+ var PauseValueType = "Pause";
403
+ function Pause(duration) {
404
+ return {
405
+ type: PauseValueType,
406
+ duration
407
+ };
408
+ }
409
+
410
+ // src/types/RepeatType.ts
411
+ var Repeat = "Repeat";
412
+
413
+ // src/managers/WindowManager.ts
414
+ var _GameWindowManager = class _GameWindowManager {
415
+ constructor() {
416
+ }
417
+ /**
418
+ * The PIXI Application instance.
419
+ * It not recommended to use this property directly.
420
+ */
421
+ static get app() {
422
+ if (!_GameWindowManager._app) {
423
+ throw new Error("[Pixi'VM] GameWindowManager.app is undefined");
424
+ }
425
+ return _GameWindowManager._app;
426
+ }
427
+ /**
428
+ * If the manager is initialized.
429
+ */
430
+ static get isInitialized() {
431
+ return _GameWindowManager._isInitialized;
432
+ }
433
+ static get screen() {
434
+ return _GameWindowManager.app.screen;
435
+ }
436
+ /**
437
+ * Initialize the PIXI Application and the interface div.
438
+ * This method should be called before any other method.
439
+ * @param element The html element where I will put the canvas. Example: document.body
440
+ * @param width The width of the canvas
441
+ * @param height The height of the canvas
442
+ * @param options The options of PIXI Application
443
+ * @example
444
+ * ```typescript
445
+ * const body = document.body
446
+ * if (!body) {
447
+ * throw new Error('body element not found')
448
+ * }
449
+ * await GameWindowManager.initialize(body, 1920, 1080, {
450
+ * backgroundColor: "#303030"
451
+ * })
452
+ * ```
453
+ */
454
+ static initialize(element, width, height, options) {
455
+ return __async(this, null, function* () {
456
+ _GameWindowManager.canvasWidth = width;
457
+ _GameWindowManager.canvasHeight = height;
458
+ _GameWindowManager._app = new import_pixi.Application();
459
+ return _GameWindowManager.app.init(__spreadValues({
460
+ resolution: window.devicePixelRatio || 1,
461
+ autoDensity: true,
462
+ width,
463
+ height
464
+ }, options)).then(() => {
465
+ _GameWindowManager._isInitialized = true;
466
+ this.addCanvasIntoElement(element);
467
+ window.addEventListener("resize", _GameWindowManager.resize);
468
+ _GameWindowManager.resize();
469
+ });
470
+ });
471
+ }
472
+ /**
473
+ * Add the canvas into a html element.
474
+ * @param element it is the html element where I will put the canvas. Example: document.body
475
+ */
476
+ static addCanvasIntoElement(element) {
477
+ if (_GameWindowManager.isInitialized) {
478
+ element.appendChild(_GameWindowManager.app.canvas);
479
+ } else {
480
+ console.error("[Pixi'VM] GameWindowManager is not initialized");
481
+ }
482
+ }
483
+ /**
484
+ * Initialize the interface div and add it into a html element.
485
+ * @param element it is the html element where I will put the interface div. Example: document.getElementById('root')
486
+ * @example
487
+ * ```typescript
488
+ * const root = document.getElementById('root')
489
+ * if (!root) {
490
+ * throw new Error('root element not found')
491
+ * }
492
+ * GameWindowManager.initializeHTMLLayout(root)
493
+ * const reactRoot = createRoot(GameWindowManager.htmlLayout)
494
+ * reactRoot.render(
495
+ * <App />
496
+ * )
497
+ * ```
498
+ */
499
+ static initializeHTMLLayout(element) {
500
+ let div = document.createElement("div");
501
+ div.style.position = "absolute";
502
+ div.style.pointerEvents = "none";
503
+ element.appendChild(div);
504
+ _GameWindowManager.htmlLayout = div;
505
+ _GameWindowManager.resize();
506
+ }
507
+ /* Resize Metods */
508
+ /**
509
+ * This method returns the scale of the screen.
510
+ */
511
+ static get screenScale() {
512
+ let screenWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
513
+ let screenHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
514
+ return Math.min(screenWidth / _GameWindowManager.canvasWidth, screenHeight / _GameWindowManager.canvasHeight);
515
+ }
516
+ /**
517
+ * This method returns the width of the screen enlarged by the scale.
518
+ */
519
+ static get screenWidth() {
520
+ return Math.floor(_GameWindowManager.screenScale * _GameWindowManager.canvasWidth);
521
+ }
522
+ /**
523
+ * This method returns the height of the screen enlarged by the scale.
524
+ */
525
+ static get screenHeight() {
526
+ return Math.floor(_GameWindowManager.screenScale * _GameWindowManager.canvasHeight);
527
+ }
528
+ /**
529
+ * This method returns the horizontal margin of the screen.
530
+ */
531
+ static get horizontalMargin() {
532
+ let screenWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
533
+ return (screenWidth - _GameWindowManager.screenWidth) / 2;
534
+ }
535
+ /**
536
+ * This method returns the vertical margin of the screen.
537
+ */
538
+ static get verticalMargin() {
539
+ let screenHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
540
+ return (screenHeight - _GameWindowManager.screenHeight) / 2;
541
+ }
542
+ /**
543
+ * This method is called when the screen is resized.
544
+ */
545
+ static resize() {
546
+ if (_GameWindowManager.isInitialized) {
547
+ let style = _GameWindowManager.app.canvas.style;
548
+ style.width = `${_GameWindowManager.screenWidth}px`;
549
+ style.height = `${_GameWindowManager.screenHeight}px`;
550
+ style.marginLeft = `${_GameWindowManager.horizontalMargin}px`;
551
+ style.marginRight = `${_GameWindowManager.horizontalMargin}px`;
552
+ style.marginTop = `${_GameWindowManager.verticalMargin}px`;
553
+ style.marginBottom = `${_GameWindowManager.verticalMargin}px`;
554
+ }
555
+ if (_GameWindowManager.htmlLayout) {
556
+ _GameWindowManager.htmlLayout.style.width = `${_GameWindowManager.screenWidth}px`;
557
+ _GameWindowManager.htmlLayout.style.height = `${_GameWindowManager.screenHeight}px`;
558
+ _GameWindowManager.htmlLayout.style.marginLeft = `${_GameWindowManager.horizontalMargin}px`;
559
+ _GameWindowManager.htmlLayout.style.marginRight = `${_GameWindowManager.horizontalMargin}px`;
560
+ _GameWindowManager.htmlLayout.style.marginTop = `${_GameWindowManager.verticalMargin}px`;
561
+ _GameWindowManager.htmlLayout.style.marginBottom = `${_GameWindowManager.verticalMargin}px`;
562
+ }
563
+ }
564
+ /* Edit Canvas Elements Methods */
565
+ /**
566
+ * This is a dictionary that contains all Canvas Elements of Canvas, currently.
567
+ */
568
+ static get currentCanvasElements() {
569
+ return _GameWindowManager._children;
570
+ }
571
+ /**
572
+ * Add a canvas element to the canvas.
573
+ * If there is a canvas element with the same tag, it will be removed.
574
+ * @param tag The tag of the canvas element.
575
+ * @param canvasElement The canvas elements to be added.
576
+ * @example
577
+ * ```typescript
578
+ * const texture = await Assets.load('https://pixijs.com/assets/bunny.png');
579
+ * const sprite = CanvasSprite.from(texture);
580
+ * GameWindowManager.addCanvasElement("bunny", sprite);
581
+ * ```
582
+ */
583
+ static addCanvasElement(tag, canvasElement) {
584
+ if (_GameWindowManager._children[tag]) {
585
+ _GameWindowManager.removeCanvasElement(tag);
586
+ }
587
+ _GameWindowManager.app.stage.addChild(canvasElement);
588
+ _GameWindowManager._children[tag] = canvasElement;
589
+ _GameWindowManager.childrenTagsOrder.push(tag);
590
+ }
591
+ /**
592
+ * Remove a canvas element from the canvas.
593
+ * And remove all tickers that are not connected to any canvas element.
594
+ * @param tag The tag of the canvas element to be removed.
595
+ * @returns
596
+ * @example
597
+ * ```typescript
598
+ * GameWindowManager.removeCanvasElement("bunny");
599
+ * ```
600
+ */
601
+ static removeCanvasElement(tag) {
602
+ if (typeof tag === "string") {
603
+ tag = [tag];
604
+ }
605
+ tag.forEach((t) => {
606
+ if (_GameWindowManager._children[t]) {
607
+ _GameWindowManager.app.stage.removeChild(_GameWindowManager._children[t]);
608
+ delete _GameWindowManager._children[t];
609
+ }
610
+ });
611
+ _GameWindowManager.removeTickersWithoutAssociatedCanvasElement();
612
+ _GameWindowManager.childrenTagsOrder = _GameWindowManager.childrenTagsOrder.filter((t) => !tag.includes(t));
613
+ }
614
+ /**
615
+ * Get a canvas element by the tag.
616
+ * @param tag The tag of the canvas element.
617
+ * @returns The canvas element.
618
+ * @example
619
+ * ```typescript
620
+ * const sprite = GameWindowManager.getCanvasElement<CanvasSprite>("bunny");
621
+ * ```
622
+ */
623
+ static getCanvasElement(tag) {
624
+ return _GameWindowManager._children[tag];
625
+ }
626
+ /**
627
+ * Check if a DisplayObject is on the canvas.
628
+ * @param pixiElement The DisplayObject to be checked.
629
+ * @returns If the DisplayObject is on the canvas.
630
+ */
631
+ static canvasElementIsOnCanvas(pixiElement) {
632
+ return _GameWindowManager.app.stage.children.includes(pixiElement);
633
+ }
634
+ /**
635
+ * Remove all canvas elements from the canvas.
636
+ * And remove all tickers that are not connected to any canvas element.
637
+ */
638
+ static removeCanvasElements() {
639
+ _GameWindowManager.app.stage.removeChildren();
640
+ _GameWindowManager._children = {};
641
+ _GameWindowManager.childrenTagsOrder = [];
642
+ _GameWindowManager.removeTickers();
643
+ }
644
+ /**
645
+ * Edit the tag of a canvas element.
646
+ * @param oldTag The old tag of the canvas element.
647
+ * @param newTag The new tag of the canvas element.
648
+ */
649
+ static editTagCanvasElement(oldTag, newTag) {
650
+ if (_GameWindowManager._children[oldTag]) {
651
+ _GameWindowManager._children[newTag] = _GameWindowManager._children[oldTag];
652
+ delete _GameWindowManager._children[oldTag];
653
+ }
654
+ }
655
+ /** Edit Tickers Methods */
656
+ /**
657
+ * Currently tickers that are running.
658
+ */
659
+ static get currentTickers() {
660
+ return _GameWindowManager._currentTickers;
661
+ }
662
+ /**
663
+ * The steps of the tickers
664
+ */
665
+ static get currentTickersSteps() {
666
+ return _GameWindowManager._currentTickersSteps;
667
+ }
668
+ /**
669
+ * Run a ticker.
670
+ * @param canvasEslementTag The tag of the canvas element that will use the ticker.
671
+ * @param ticker The ticker class to be run.
672
+ * @param args The arguments to be used in the ticker.
673
+ * @param duration The time to be used in the ticker. This number is in milliseconds. If it is undefined, the ticker will run forever.
674
+ * @param priority The priority to be used in the ticker.
675
+ * @returns
676
+ * @example
677
+ * ```typescript
678
+ * GameWindowManager.addTicker("alien", new TickerRotate({ speed: 0.2 }))
679
+ * ```
680
+ */
681
+ static addTicker(canvasElementTag, ticker) {
682
+ let tickerName = ticker.constructor.name;
683
+ if (typeof canvasElementTag === "string") {
684
+ canvasElementTag = [canvasElementTag];
685
+ }
686
+ let t = geTickerInstanceByClassName(tickerName, ticker.args, ticker.duration, ticker.priority);
687
+ if (!t) {
688
+ console.error(`[Pixi'VM] Ticker ${tickerName} not found`);
689
+ return;
690
+ }
691
+ _GameWindowManager.removeAssociationBetweenTickerCanvasElement(canvasElementTag, ticker);
692
+ let tickerHistory = {
693
+ fn: () => {
694
+ },
695
+ className: tickerName,
696
+ args: ticker.args,
697
+ canvasElementTags: canvasElementTag,
698
+ priority: ticker.priority,
699
+ duration: ticker.duration
700
+ };
701
+ _GameWindowManager.pushTicker(tickerHistory, t);
702
+ _GameWindowManager.removeTickersWithoutAssociatedCanvasElement();
703
+ if (ticker.duration) {
704
+ let timeout = setTimeout(() => {
705
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
706
+ _GameWindowManager.nextTickerStep(canvasElementTag);
707
+ }, ticker.duration);
708
+ _GameWindowManager.addTickerTimeoutInfo(canvasElementTag, tickerName, timeout.toString());
709
+ }
710
+ }
711
+ static pushTicker(tickerData, ticker) {
712
+ _GameWindowManager.removeAssociationBetweenTickerCanvasElement(tickerData.canvasElementTags, tickerData);
713
+ _GameWindowManager._currentTickers.push(tickerData);
714
+ tickerData.fn = (t) => {
715
+ ticker == null ? void 0 : ticker.fn(t, tickerData.args, tickerData.canvasElementTags);
716
+ };
717
+ _GameWindowManager.app.ticker.add(tickerData.fn, void 0, tickerData.priority);
718
+ }
719
+ /**
720
+ * Run a sequence of tickers.
721
+ * @param tag The tag of canvas element that will use the tickers.
722
+ * @param steps The steps of the tickers.
723
+ * @returns
724
+ * @example
725
+ * ```typescript
726
+ * GameWindowManager.addTickersSteps("alien", [
727
+ * new TickerRotate({ speed: 0.1, clockwise: true }, 2000),
728
+ * Pause(500),
729
+ * new TickerRotate({ speed: 0.2, clockwise: false }, 2000),
730
+ * Repeat,
731
+ * ])
732
+ * ```
733
+ */
734
+ static addTickersSteps(tag, steps) {
735
+ if (steps.length == 0) {
736
+ console.warn("[Pixi'VM] The steps of the tickers is empty");
737
+ return;
738
+ }
739
+ let alredyExists = _GameWindowManager._currentTickersSteps[tag] !== void 0;
740
+ _GameWindowManager._currentTickersSteps[tag] = {
741
+ currentStepNumber: 0,
742
+ steps: steps.map((s) => {
743
+ if (s === Repeat) {
744
+ return s;
745
+ }
746
+ if (!s.duration) {
747
+ console.warn("[Pixi'VM] Duration is not defined, so it will be set to 1000");
748
+ s.duration = 1e3;
749
+ }
750
+ if (s.hasOwnProperty("type") && s.type === PauseValueType) {
751
+ return s;
752
+ }
753
+ let tickerName = s.constructor.name;
754
+ return {
755
+ ticker: tickerName,
756
+ args: s.args,
757
+ duration: s.duration
758
+ };
759
+ })
760
+ };
761
+ if (!alredyExists) {
762
+ _GameWindowManager.runTickersSteps(tag);
763
+ }
764
+ }
765
+ static runTickersSteps(tag) {
766
+ let step = _GameWindowManager._currentTickersSteps[tag].steps[_GameWindowManager._currentTickersSteps[tag].currentStepNumber];
767
+ if (step === Repeat) {
768
+ step = _GameWindowManager._currentTickersSteps[tag].steps[0];
769
+ _GameWindowManager._currentTickersSteps[tag].currentStepNumber = 0;
770
+ if (step === Repeat) {
771
+ console.error("[Pixi'VM] TikersSteps has a RepeatType in the first step");
772
+ return;
773
+ }
774
+ }
775
+ if (step.hasOwnProperty("type") && step.type === PauseValueType) {
776
+ let timeout = setTimeout(() => {
777
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
778
+ _GameWindowManager.nextTickerStep(tag);
779
+ }, step.duration);
780
+ _GameWindowManager.addTickerTimeoutInfo(tag, "steps", timeout.toString());
781
+ return;
782
+ }
783
+ let ticker = geTickerInstanceByClassName(step.ticker, step.args, step.duration, step.priority);
784
+ if (!ticker) {
785
+ console.error(`[Pixi'VM] Ticker ${step.ticker} not found`);
786
+ return;
787
+ }
788
+ _GameWindowManager.addTicker(tag, ticker);
789
+ }
790
+ static nextTickerStep(tag) {
791
+ if (typeof tag === "string") {
792
+ tag = [tag];
793
+ }
794
+ tag.forEach((tag2) => {
795
+ if (_GameWindowManager._currentTickersSteps[tag2]) {
796
+ let steps = _GameWindowManager._currentTickersSteps[tag2];
797
+ if (steps.currentStepNumber + 1 < steps.steps.length) {
798
+ steps.currentStepNumber++;
799
+ _GameWindowManager._currentTickersSteps[tag2] = steps;
800
+ _GameWindowManager.runTickersSteps(tag2);
801
+ } else {
802
+ delete _GameWindowManager._currentTickersSteps[tag2];
803
+ }
804
+ }
805
+ });
806
+ }
807
+ /**
808
+ * Remove a connection between a canvas element and a ticker.
809
+ * And remove the ticker if there is no canvas element connected to it.
810
+ * @param tag The tag of the canvas element that will use the ticker.
811
+ * @param ticker The ticker class to be removed.
812
+ * @example
813
+ * ```typescript
814
+ * GameWindowManager.removeAssociationBetweenTickerCanvasElement("alien", TickerRotate)
815
+ * ```
816
+ */
817
+ static removeAssociationBetweenTickerCanvasElement(tag, ticker) {
818
+ let tickerName;
819
+ if (ticker instanceof TickerBase) {
820
+ tickerName = ticker.constructor.name;
821
+ } else {
822
+ tickerName = ticker.name;
823
+ }
824
+ if (typeof tag === "string") {
825
+ tag = [tag];
826
+ }
827
+ _GameWindowManager._currentTickers = _GameWindowManager._currentTickers.map((t) => {
828
+ if (t.className === tickerName) {
829
+ t.canvasElementTags = t.canvasElementTags.filter((e) => !tag.includes(e));
830
+ }
831
+ return t;
832
+ });
833
+ for (let timeout in _GameWindowManager.currentTickersTimeouts) {
834
+ let t = _GameWindowManager.currentTickersTimeouts[timeout].tags.filter((e) => !tag.includes(e));
835
+ if (t.length == 0) {
836
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
837
+ } else {
838
+ _GameWindowManager.currentTickersTimeouts[timeout].tags = t;
839
+ }
840
+ }
841
+ _GameWindowManager.removeTickersWithoutAssociatedCanvasElement();
842
+ }
843
+ /**
844
+ * Remove all tickers that are not connected to any existing canvas element.
845
+ */
846
+ static removeTickersWithoutAssociatedCanvasElement() {
847
+ let currentTickers = _GameWindowManager._currentTickers.map((t) => {
848
+ t.canvasElementTags = t.canvasElementTags.filter((e) => _GameWindowManager._children[e]);
849
+ return t;
850
+ });
851
+ currentTickers.filter((t) => t.canvasElementTags.length === 0).forEach((t) => {
852
+ _GameWindowManager.app.ticker.remove(t.fn);
853
+ });
854
+ currentTickers = currentTickers.filter((t) => t.canvasElementTags.length > 0);
855
+ _GameWindowManager._currentTickers = currentTickers;
856
+ for (let tag in _GameWindowManager._currentTickersSteps) {
857
+ if (_GameWindowManager._children[tag] === void 0) {
858
+ delete _GameWindowManager._currentTickersSteps[tag];
859
+ }
860
+ }
861
+ }
862
+ static addTickerTimeoutInfo(tags, ticker, timeout) {
863
+ if (typeof tags === "string") {
864
+ tags = [tags];
865
+ }
866
+ _GameWindowManager.currentTickersTimeouts[timeout] = {
867
+ tags,
868
+ ticker
869
+ };
870
+ }
871
+ static removeTickerTimeoutInfo(timeout) {
872
+ if (typeof timeout !== "string") {
873
+ timeout = timeout.toString();
874
+ }
875
+ if (_GameWindowManager.currentTickersTimeouts[timeout]) {
876
+ delete _GameWindowManager.currentTickersTimeouts[timeout];
877
+ }
878
+ }
879
+ /**
880
+ * Remove all tickers from the canvas.
881
+ */
882
+ static removeTickers() {
883
+ _GameWindowManager._currentTickersSteps = {};
884
+ _GameWindowManager._currentTickers.forEach((t) => {
885
+ _GameWindowManager.app.ticker.remove(t.fn);
886
+ });
887
+ _GameWindowManager._currentTickers = [];
888
+ for (let timeout in _GameWindowManager.currentTickersTimeouts) {
889
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
890
+ }
891
+ }
892
+ /**
893
+ * Clear the canvas and the tickers.
894
+ */
895
+ static clear() {
896
+ _GameWindowManager.removeCanvasElements();
897
+ }
898
+ /* Export and Import Methods */
899
+ /**
900
+ * Export the canvas and the tickers to a JSON string.
901
+ * @returns The JSON string.
902
+ */
903
+ static exportJson() {
904
+ return JSON.stringify(this.export());
905
+ }
906
+ /**
907
+ * Export the canvas and the tickers to an object.
908
+ * @returns The object.
909
+ */
910
+ static export() {
911
+ let currentElements = {};
912
+ for (let tag in _GameWindowManager._children) {
913
+ currentElements[tag] = exportCanvasElement(_GameWindowManager._children[tag]);
914
+ }
915
+ return {
916
+ currentTickers: createExportElement(_GameWindowManager._currentTickers),
917
+ currentElements: createExportElement(currentElements),
918
+ childrenTagsOrder: createExportElement(_GameWindowManager.childrenTagsOrder)
919
+ };
920
+ }
921
+ /**
922
+ * Import the canvas and the tickers from a JSON string.
923
+ * @param dataString The JSON string.
924
+ */
925
+ static importJson(dataString) {
926
+ _GameWindowManager.import(JSON.parse(dataString));
927
+ }
928
+ /**
929
+ * Import the canvas and the tickers from an object.
930
+ * @param data The object.
931
+ */
932
+ static import(data) {
933
+ _GameWindowManager.clear();
934
+ try {
935
+ if (data.hasOwnProperty("childrenTagsOrder") && data.hasOwnProperty("currentElements")) {
936
+ let currentElements = data["currentElements"];
937
+ let childrenTagsOrder = data["childrenTagsOrder"];
938
+ childrenTagsOrder.forEach((tag) => {
939
+ if (currentElements[tag]) {
940
+ let element = importCanvasElement(currentElements[tag]);
941
+ _GameWindowManager.addCanvasElement(tag, element);
942
+ _GameWindowManager.childrenTagsOrder.push(tag);
943
+ }
944
+ });
945
+ } else {
946
+ console.error("[Pixi'VM] The data does not have the properties childrenTagsOrder and currentElements");
947
+ return;
948
+ }
949
+ if (data.hasOwnProperty("currentTickers")) {
950
+ let currentTickers = data["currentTickers"];
951
+ currentTickers.forEach((t) => {
952
+ let tags = t.canvasElementTags;
953
+ let ticker = geTickerInstanceByClassName(t.className, t.args, t.duration, t.priority);
954
+ if (ticker) {
955
+ _GameWindowManager.addTicker(tags, ticker);
956
+ } else {
957
+ console.error(`[Pixi'VM] Ticker ${t.className} not found`);
958
+ }
959
+ });
960
+ }
961
+ } catch (e) {
962
+ console.error("[Pixi'VM] Error importing data", e);
963
+ }
964
+ }
965
+ };
966
+ _GameWindowManager._app = void 0;
967
+ _GameWindowManager._isInitialized = false;
968
+ _GameWindowManager._children = {};
969
+ /**
970
+ * The order of the children tags.
971
+ */
972
+ _GameWindowManager.childrenTagsOrder = [];
973
+ _GameWindowManager._currentTickers = [];
974
+ _GameWindowManager._currentTickersSteps = {};
975
+ _GameWindowManager.currentTickersTimeouts = {};
976
+ var GameWindowManager = _GameWindowManager;
977
+
978
+ // src/managers/StepManager.ts
979
+ var _GameStepManager = class _GameStepManager {
980
+ constructor() {
981
+ }
982
+ static get stepsHistory() {
983
+ return _GameStepManager._stepsHistory;
984
+ }
985
+ static get lastStepIndex() {
986
+ return _GameStepManager.stepsHistory.length;
987
+ }
988
+ static get openedLabels() {
989
+ return _GameStepManager._openedLabels;
990
+ }
991
+ /**
992
+ * currentLabel is the current label that occurred during the progression of the steps.
993
+ */
994
+ static get currentLabel() {
995
+ if (_GameStepManager._openedLabels.length > 0) {
996
+ let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
997
+ return item.label;
998
+ }
999
+ return null;
1000
+ }
1001
+ /**
1002
+ * currentLabelStepIndex is the current step index of the current label that occurred during the progression of the steps.
1003
+ */
1004
+ static get currentLabelStepIndex() {
1005
+ if (_GameStepManager._openedLabels.length > 0) {
1006
+ let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
1007
+ return item.currentStepIndex;
1008
+ }
1009
+ return null;
1010
+ }
1011
+ /**
1012
+ * lastHistoryStep is the last history step that occurred during the progression of the steps.
1013
+ */
1014
+ static get lastHistoryStep() {
1015
+ if (_GameStepManager._stepsHistory.length > 0) {
1016
+ return _GameStepManager._stepsHistory[_GameStepManager._stepsHistory.length - 1];
1017
+ }
1018
+ return null;
1019
+ }
1020
+ /* Edit History Methods */
1021
+ /**
1022
+ * Add a label to the history.
1023
+ * @param label The label to add to the history.
1024
+ */
1025
+ static addStepHistory(step) {
1026
+ let stepHistory = getStepSha1(step);
1027
+ let historyStep = {
1028
+ path: window.location.pathname,
1029
+ storage: GameStorageManager.export(),
1030
+ stepSha1: stepHistory,
1031
+ canvas: GameWindowManager.export(),
1032
+ stepIndex: _GameStepManager.currentLabelStepIndex || 0,
1033
+ openedLabels: createExportElement(_GameStepManager._openedLabels)
1034
+ };
1035
+ let lastStepData = _GameStepManager.lastHistoryStep;
1036
+ if (lastStepData) {
1037
+ if (lastStepData.openedLabels.length === historyStep.openedLabels.length) {
1038
+ try {
1039
+ let lastStepDataOpenedLabelsString = JSON.stringify(lastStepData.openedLabels);
1040
+ let historyStepOpenedLabelsString = JSON.stringify(historyStep.openedLabels);
1041
+ if (lastStepDataOpenedLabelsString === historyStepOpenedLabelsString) {
1042
+ return;
1043
+ }
1044
+ } catch (e) {
1045
+ console.error("[Pixi'VM] Error comparing openedLabels", e);
1046
+ }
1047
+ }
1048
+ }
1049
+ _GameStepManager._stepsHistory.push(historyStep);
1050
+ }
1051
+ /**
1052
+ * Add a label to the history.
1053
+ * @param label The label to add to the history.
1054
+ */
1055
+ static pushNewLabel(label) {
1056
+ let currentLabel = getLabelInstanceByClassName(label);
1057
+ if (!currentLabel) {
1058
+ throw new Error("[Pixi'VM] Label not found");
1059
+ }
1060
+ _GameStepManager._openedLabels.push({
1061
+ label,
1062
+ currentStepIndex: 0
1063
+ });
1064
+ }
1065
+ /**
1066
+ * Close the current label and add it to the history.
1067
+ * @returns
1068
+ */
1069
+ static closeLabel() {
1070
+ if (!_GameStepManager.currentLabel) {
1071
+ console.warn("[Pixi'VM] No label to close");
1072
+ return;
1073
+ }
1074
+ let currentLabel = getLabelInstanceByClassName(_GameStepManager.currentLabel);
1075
+ if (!currentLabel) {
1076
+ console.error("[Pixi'VM] Label not found");
1077
+ return;
1078
+ }
1079
+ _GameStepManager._openedLabels.pop();
1080
+ }
1081
+ /**
1082
+ * Close all labels and add them to the history.
1083
+ */
1084
+ static closeAllLabels() {
1085
+ while (_GameStepManager._openedLabels.length > 0) {
1086
+ _GameStepManager.closeLabel();
1087
+ }
1088
+ }
1089
+ /**
1090
+ * Increase the current step index of the current label.
1091
+ */
1092
+ static increaseCurrentStepIndex() {
1093
+ let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
1094
+ _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1] = __spreadProps(__spreadValues({}, item), {
1095
+ currentStepIndex: item.currentStepIndex + 1
1096
+ });
1097
+ }
1098
+ /* Run Methods */
1099
+ /**
1100
+ * Execute the next step and add it to the history.
1101
+ * @returns
1102
+ * @example
1103
+ * ```typescript
1104
+ * function nextOnClick() {
1105
+ * setLoading(true)
1106
+ * GameStepManager.runNextStep()
1107
+ * .then(() => {
1108
+ * setUpdate((p) => p + 1)
1109
+ * setLoading(false)
1110
+ * })
1111
+ * .catch((e) => {
1112
+ * setLoading(false)
1113
+ * console.error(e)
1114
+ * })
1115
+ * }
1116
+ * ```
1117
+ */
1118
+ static runNextStep() {
1119
+ return __async(this, null, function* () {
1120
+ if (_GameStepManager._openedLabels.length === 0) {
1121
+ console.warn("[Pixi'VM] There are no labels to run");
1122
+ return;
1123
+ }
1124
+ _GameStepManager.increaseCurrentStepIndex();
1125
+ return yield _GameStepManager.runCurrentStep();
1126
+ });
1127
+ }
1128
+ /**
1129
+ * Execute the current step and add it to the history.
1130
+ * @returns
1131
+ */
1132
+ static runCurrentStep() {
1133
+ return __async(this, null, function* () {
1134
+ if (_GameStepManager.currentLabel) {
1135
+ let lasteStepsLength = _GameStepManager.currentLabelStepIndex;
1136
+ if (lasteStepsLength === null) {
1137
+ console.error("[Pixi'VM] currentLabelStepIndex is null");
1138
+ return;
1139
+ }
1140
+ let currentLabel = getLabelInstanceByClassName(_GameStepManager.currentLabel);
1141
+ if (!currentLabel) {
1142
+ console.error("[Pixi'VM] Label not found");
1143
+ return;
1144
+ }
1145
+ let n = currentLabel.steps.length;
1146
+ if (n > lasteStepsLength) {
1147
+ let nextStep = currentLabel.steps[lasteStepsLength];
1148
+ yield nextStep();
1149
+ _GameStepManager.addStepHistory(nextStep);
1150
+ } else if (n === lasteStepsLength) {
1151
+ _GameStepManager.closeLabel();
1152
+ yield _GameStepManager.runNextStep();
1153
+ } else {
1154
+ console.warn("[Pixi'VM] There are no steps to run");
1155
+ }
1156
+ }
1157
+ });
1158
+ }
1159
+ /**
1160
+ * Execute the label and add it to the history.
1161
+ * Is a call function in Ren'Py.
1162
+ * @param label The label to execute.
1163
+ * @returns
1164
+ * @example
1165
+ * ```typescript
1166
+ * GameStepManager.callLabel(StartLabel)
1167
+ * ```
1168
+ */
1169
+ static callLabel(label) {
1170
+ return __async(this, null, function* () {
1171
+ try {
1172
+ if (label instanceof Label) {
1173
+ label = label.constructor;
1174
+ }
1175
+ let labelName = label.name;
1176
+ _GameStepManager.pushNewLabel(labelName);
1177
+ } catch (e) {
1178
+ console.error("[Pixi'VM] Error calling label", e);
1179
+ return;
1180
+ }
1181
+ return yield _GameStepManager.runCurrentStep();
1182
+ });
1183
+ }
1184
+ /**
1185
+ * Execute the label, close all labels and add them to the history.
1186
+ * Is a jump function in Ren'Py.
1187
+ * @param label
1188
+ * @returns
1189
+ * @example
1190
+ * ```typescript
1191
+ * GameStepManager.jumpLabel(StartLabel)
1192
+ * ```
1193
+ */
1194
+ static jumpLabel(label) {
1195
+ return __async(this, null, function* () {
1196
+ _GameStepManager.closeAllLabels();
1197
+ try {
1198
+ if (label instanceof Label) {
1199
+ label = label.constructor;
1200
+ }
1201
+ let labelName = label.name;
1202
+ _GameStepManager.pushNewLabel(labelName);
1203
+ } catch (e) {
1204
+ console.error("[Pixi'VM] Error jumping label", e);
1205
+ return;
1206
+ }
1207
+ return yield _GameStepManager.runCurrentStep();
1208
+ });
1209
+ }
1210
+ /* After Update Methods */
1211
+ // /**
1212
+ // * After the update or code edit, some steps or labels may no longer match.
1213
+ // * - In case of step mismatch, the game will be updated to the last matching step.
1214
+ // * - In case of label mismatch, the game gives an error.
1215
+ // * @returns
1216
+ // */
1217
+ // private static afterUpdate() {
1218
+ // // TODO: implement
1219
+ // if (!GameStepManager.currentLabel) {
1220
+ // // TODO: implement
1221
+ // return
1222
+ // }
1223
+ // let currentLabel = getLabelInstanceByClassName(GameStepManager.currentLabel)
1224
+ // if (!currentLabel) {
1225
+ // console.error("Label not found")
1226
+ // return
1227
+ // }
1228
+ // let oldSteps = GameStepManager.stepsAfterLastHistoryLabel
1229
+ // let currentStepIndex = currentLabel.getCorrespondingStepsNumber(oldSteps)
1230
+ // let stepToRemove = oldSteps.length - currentStepIndex
1231
+ // GameStepManager.removeLastHistoryNodes(stepToRemove)
1232
+ // GameStepManager.loadLastStep()
1233
+ // }
1234
+ // private static loadLastStep() {
1235
+ // // TODO: implement
1236
+ // }
1237
+ // /**
1238
+ // * Remove a number of items from the last of the history.
1239
+ // * @param itemNumber The number of items to remove from the last of the history.
1240
+ // */
1241
+ // private static removeLastHistoryNodes(itemNumber: number) {
1242
+ // // TODO: implement
1243
+ // for (let i = 0; i < itemNumber; i++) {
1244
+ // GameStepManager._stepsHistory.pop()
1245
+ // }
1246
+ // }
1247
+ // /**
1248
+ // * stepsAfterLastHistoryLabel is a list of steps that occurred after the last history label.
1249
+ // */
1250
+ // private static get stepsAfterLastHistoryLabel(): StepHistoryDataType[] {
1251
+ // let length = GameStepManager._stepsHistory.length
1252
+ // let steps: StepHistoryDataType[] = []
1253
+ // for (let i = length - 1; i >= 0; i--) {
1254
+ // let element = GameStepManager._stepsHistory[i]
1255
+ // if (typeof element === "object" && "stepSha1" in element) {
1256
+ // steps.push(element.stepSha1)
1257
+ // }
1258
+ // else {
1259
+ // break
1260
+ // }
1261
+ // }
1262
+ // steps = steps.reverse()
1263
+ // return steps
1264
+ // }
1265
+ /* Go Back & Refresh Methods */
1266
+ /**
1267
+ * Go back to the last step and add it to the history.
1268
+ * @param navigate The navigate function.
1269
+ * @param steps The number of steps to go back.
1270
+ * @returns
1271
+ * @example
1272
+ * ```typescript
1273
+ * export function goBack(navigate: (path: string) => void, afterBack?: () => void) {
1274
+ * GameStepManager.goBack(navigate)
1275
+ * afterBack && afterBack()
1276
+ * }
1277
+ * ```
1278
+ */
1279
+ static goBack(navigate, steps = 1) {
1280
+ if (steps <= 0) {
1281
+ console.warn("[Pixi'VM] Steps must be greater than 0");
1282
+ return;
1283
+ }
1284
+ if (_GameStepManager._stepsHistory.length <= 1) {
1285
+ console.warn("[Pixi'VM] No steps to go back");
1286
+ return;
1287
+ }
1288
+ _GameStepManager.goBackInstrnal(steps);
1289
+ let lastHistoryStep = _GameStepManager.lastHistoryStep;
1290
+ if (lastHistoryStep) {
1291
+ _GameStepManager._openedLabels = createExportElement(lastHistoryStep.openedLabels);
1292
+ GameStorageManager.import(createExportElement(lastHistoryStep.storage));
1293
+ GameWindowManager.import(createExportElement(lastHistoryStep.canvas));
1294
+ navigate(lastHistoryStep.path);
1295
+ } else {
1296
+ console.error("[Pixi'VM] Error going back");
1297
+ }
1298
+ }
1299
+ static goBackInstrnal(steps) {
1300
+ if (steps <= 0) {
1301
+ return;
1302
+ }
1303
+ if (_GameStepManager._stepsHistory.length == 0) {
1304
+ return;
1305
+ }
1306
+ _GameStepManager._stepsHistory.pop();
1307
+ _GameStepManager.goBackInstrnal(steps - 1);
1308
+ }
1309
+ /**
1310
+ * Add a label to the history.
1311
+ */
1312
+ static clear() {
1313
+ _GameStepManager._stepsHistory = [];
1314
+ _GameStepManager._openedLabels = [];
1315
+ }
1316
+ /* Export and Import Methods */
1317
+ /**
1318
+ * Export the history to a JSON string.
1319
+ * @returns The history in a JSON string.
1320
+ */
1321
+ static exportJson() {
1322
+ return JSON.stringify(this.export());
1323
+ }
1324
+ /**
1325
+ * Export the history to an object.
1326
+ * @returns The history in an object.
1327
+ */
1328
+ static export() {
1329
+ return {
1330
+ stepsHistory: _GameStepManager._stepsHistory,
1331
+ openedLabels: _GameStepManager._openedLabels
1332
+ };
1333
+ }
1334
+ /**
1335
+ * Import the history from a JSON string.
1336
+ * @param dataString The history in a JSON string.
1337
+ */
1338
+ static importJson(dataString) {
1339
+ _GameStepManager.import(JSON.parse(dataString));
1340
+ }
1341
+ /**
1342
+ * Import the history from an object.
1343
+ * @param data The history in an object.
1344
+ */
1345
+ static import(data) {
1346
+ _GameStepManager.clear();
1347
+ try {
1348
+ if (data.hasOwnProperty("stepsHistory")) {
1349
+ _GameStepManager._stepsHistory = data["stepsHistory"];
1350
+ } else {
1351
+ console.warn("[Pixi'VM] No stepsHistory data found");
1352
+ }
1353
+ if (data.hasOwnProperty("openedLabels")) {
1354
+ _GameStepManager._openedLabels = data["openedLabels"];
1355
+ } else {
1356
+ console.warn("[Pixi'VM] No openedLabels data found");
1357
+ }
1358
+ } catch (e) {
1359
+ console.error("[Pixi'VM] Error importing data", e);
1360
+ }
1361
+ }
1362
+ };
1363
+ /**
1364
+ * stepHistory is a list of label events and steps that occurred during the progression of the steps.
1365
+ */
1366
+ _GameStepManager._stepsHistory = [];
1367
+ _GameStepManager._openedLabels = [];
1368
+ var GameStepManager = _GameStepManager;
1369
+
1370
+ // src/classes/StoredClassModel.ts
1371
+ var StoredClassModel = class {
1372
+ constructor(id) {
1373
+ this.id = id;
1374
+ }
1375
+ get nameClass() {
1376
+ return this.constructor.name + "Storage";
1377
+ }
1378
+ updateStorage(value) {
1379
+ let storage = GameStorageManager.getVariable(this.nameClass);
1380
+ if (!storage) {
1381
+ storage = {};
1382
+ }
1383
+ storage[this.id] = value;
1384
+ GameStorageManager.setVariable(this.nameClass, storage);
1385
+ }
1386
+ getStorageProperty(key) {
1387
+ let storage = GameStorageManager.getVariable(this.nameClass);
1388
+ if (!storage) {
1389
+ return void 0;
1390
+ }
1391
+ if (storage[this.id].hasOwnProperty(key)) {
1392
+ return storage[this.id][key];
1393
+ }
1394
+ return void 0;
1395
+ }
1396
+ };
1397
+
1398
+ // src/classes/CharacterModelBase.ts
1399
+ var CharacterModelBase = class extends StoredClassModel {
1400
+ constructor(tag, props) {
1401
+ super(tag);
1402
+ this.defaultName = "";
1403
+ this.defaultName = props.name;
1404
+ this.defaultSurname = props.surname;
1405
+ this.defaultAge = props.age;
1406
+ this.icon = props.icon;
1407
+ this.color = props.color;
1408
+ }
1409
+ get name() {
1410
+ return this.getStorageProperty("name") || this.defaultName;
1411
+ }
1412
+ set name(value) {
1413
+ this.updateStorage(__spreadProps(__spreadValues({}, this), { name: value }));
1414
+ }
1415
+ get surname() {
1416
+ return this.getStorageProperty("surname") || this.defaultSurname;
1417
+ }
1418
+ set surname(value) {
1419
+ this.updateStorage(__spreadProps(__spreadValues({}, this), { surname: value }));
1420
+ }
1421
+ get age() {
1422
+ return this.getStorageProperty("age") || this.defaultAge;
1423
+ }
1424
+ set age(value) {
1425
+ this.updateStorage(__spreadProps(__spreadValues({}, this), { age: value }));
1426
+ }
1427
+ };
1428
+
1429
+ // src/classes/DialogueModelBase.ts
1430
+ var DialogueModelBase = class {
1431
+ constructor(text, characterTag) {
1432
+ /**
1433
+ * The text of the dialogue.
1434
+ */
1435
+ this.text = "";
1436
+ this.text = text;
1437
+ this.characterTag = characterTag;
1438
+ }
1439
+ };
1440
+
1441
+ // src/classes/Label.ts
1442
+ var Label = class {
1443
+ /**
1444
+ * Get the steps of the label.
1445
+ * This class should be extended and the steps method should be overridden.
1446
+ * Every time you update this list will also be updated when the other game versions load.
1447
+ */
1448
+ get steps() {
1449
+ throw new Error("[Pixi'VM] The method Label.steps must be overridden");
1450
+ }
1451
+ /**
1452
+ * Get the corresponding steps number
1453
+ * @param externalSteps
1454
+ * @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
1455
+ */
1456
+ getCorrespondingStepsNumber(externalSteps) {
1457
+ if (externalSteps.length === 0) {
1458
+ return 0;
1459
+ }
1460
+ let res = 0;
1461
+ externalSteps.forEach((step, index) => {
1462
+ if (checkIfStepsIsEqual(step, this.steps[index])) {
1463
+ res = index;
1464
+ }
1465
+ });
1466
+ return res;
1467
+ }
1468
+ };
1469
+
1470
+ // src/enums/LabelRunModeEnum.ts
1471
+ var LabelRunModeEnum = /* @__PURE__ */ ((LabelRunModeEnum2) => {
1472
+ LabelRunModeEnum2["OpenByCall"] = "openbycall";
1473
+ LabelRunModeEnum2["OpenByJump"] = "openbyjump";
1474
+ return LabelRunModeEnum2;
1475
+ })(LabelRunModeEnum || {});
1476
+
1477
+ // src/classes/MenuOptionLabel.ts
1478
+ var MenuOptionLabel = class {
1479
+ constructor(text, label, type = "openbycall" /* OpenByCall */) {
1480
+ this.text = text;
1481
+ this.label = label;
1482
+ this.type = type;
1483
+ }
1484
+ };
1485
+
1486
+ // src/classes/canvas/CanvasBase.ts
1487
+ var import_pixi2 = require("pixi.js");
1488
+ var CanvasBase = class extends import_pixi2.Container {
1489
+ /**
1490
+ * This method return the memory of the canvas element.
1491
+ */
1492
+ get memory() {
1493
+ throw new Error("[Pixi'VM] The method CanvasBase.memory must be overridden");
1494
+ }
1495
+ /**
1496
+ * This method set the memory of the canvas element.
1497
+ */
1498
+ set memory(_value) {
1499
+ throw new Error("[Pixi'VM] The method CanvasBase.memory must be overridden");
1500
+ }
1501
+ };
1502
+
1503
+ // src/classes/canvas/CanvasContainer.ts
1504
+ var import_pixi3 = require("pixi.js");
1505
+
1506
+ // src/decorators/CharacterDecorator.ts
1507
+ var registeredCharacters = {};
1508
+ function saveCharacter(character) {
1509
+ if (Array.isArray(character)) {
1510
+ character.forEach((c) => saveCharacter(c));
1511
+ return;
1512
+ }
1513
+ if (registeredCharacters[character.id]) {
1514
+ console.warn(`Character tag ${character.id} already exists, it will be overwritten`);
1515
+ }
1516
+ registeredCharacters[character.id] = character;
1517
+ }
1518
+ function getCharacterByTag(tag) {
1519
+ try {
1520
+ let character = registeredCharacters[tag];
1521
+ if (!character) {
1522
+ console.error(`Character ${tag} not found`);
1523
+ return;
1524
+ }
1525
+ return character;
1526
+ } catch (e) {
1527
+ console.error(e);
1528
+ return;
1529
+ }
1530
+ }
1531
+
1532
+ // src/decorators/EventDecorator.ts
1533
+ var registeredEvents = {};
1534
+ function eventDecorator(name) {
1535
+ return function(target) {
1536
+ if (!name) {
1537
+ name = target.name;
1538
+ }
1539
+ if (registeredEvents[name]) {
1540
+ console.warn(`Event ${name} already exists, it will be overwritten`);
1541
+ }
1542
+ registeredEvents[name] = target;
1543
+ };
1544
+ }
1545
+ function getEventTypeByClassName(eventName) {
1546
+ try {
1547
+ let eventType = registeredEvents[eventName];
1548
+ if (!eventType) {
1549
+ console.error(`Event ${eventName} not found`);
1550
+ return;
1551
+ }
1552
+ new eventType();
1553
+ return eventType;
1554
+ } catch (e) {
1555
+ console.error(e);
1556
+ return;
1557
+ }
1558
+ }
1559
+ function getEventInstanceByClassName(eventName) {
1560
+ try {
1561
+ let eventType = registeredEvents[eventName];
1562
+ if (!eventType) {
1563
+ console.error(`Event ${eventName} not found`);
1564
+ return;
1565
+ }
1566
+ let event = new eventType();
1567
+ return event;
1568
+ } catch (e) {
1569
+ console.error(e);
1570
+ return;
1571
+ }
1572
+ }
1573
+
1574
+ // src/classes/canvas/CanvasContainer.ts
1575
+ var CanvasContainer = class extends import_pixi3.Container {
1576
+ get memory() {
1577
+ let memory = getMemoryContainer(this);
1578
+ this.children.forEach((child) => {
1579
+ memory.elements.push(exportCanvasElement(child));
1580
+ });
1581
+ return memory;
1582
+ }
1583
+ set memory(value) {
1584
+ setMemoryContainer(this, value);
1585
+ value.elements.forEach((child) => {
1586
+ this.addChild(importCanvasElement(child));
1587
+ });
1588
+ }
1589
+ };
1590
+ CanvasContainer = __decorateClass([
1591
+ canvasElementDecorator()
1592
+ ], CanvasContainer);
1593
+ function getMemoryContainer(element) {
1594
+ return {
1595
+ className: "CanvasContainer",
1596
+ elements: [],
1597
+ width: element.width,
1598
+ height: element.height,
1599
+ isRenderGroup: element.isRenderGroup,
1600
+ blendMode: element.blendMode,
1601
+ tint: element.tint,
1602
+ alpha: element.alpha,
1603
+ angle: element.angle,
1604
+ renderable: element.renderable,
1605
+ rotation: element.rotation,
1606
+ scale: { x: element.scale.x, y: element.scale.y },
1607
+ pivot: { x: element.pivot.x, y: element.pivot.y },
1608
+ position: { x: element.position.x, y: element.position.y },
1609
+ skew: { x: element.skew.x, y: element.skew.y },
1610
+ visible: element.visible,
1611
+ culled: element.culled,
1612
+ x: element.x,
1613
+ y: element.y,
1614
+ boundsArea: element.boundsArea,
1615
+ cursor: element.cursor,
1616
+ eventMode: element.eventMode,
1617
+ interactive: element.interactive,
1618
+ interactiveChildren: element.interactiveChildren,
1619
+ hitArea: element.hitArea
1620
+ };
1621
+ }
1622
+ function setMemoryContainer(element, memory) {
1623
+ memory.width && (element.width = memory.width);
1624
+ memory.height && (element.height = memory.height);
1625
+ memory.isRenderGroup && (element.isRenderGroup = memory.isRenderGroup);
1626
+ memory.blendMode && (element.blendMode = memory.blendMode);
1627
+ memory.tint && (element.tint = memory.tint);
1628
+ memory.alpha && (element.alpha = memory.alpha);
1629
+ memory.angle && (element.angle = memory.angle);
1630
+ memory.renderable && (element.renderable = memory.renderable);
1631
+ memory.rotation && (element.rotation = memory.rotation);
1632
+ if (memory.scale) {
1633
+ if (typeof memory.scale === "number") {
1634
+ element.scale.set(memory.scale, memory.scale);
1635
+ } else {
1636
+ element.scale.set(memory.scale.x, memory.scale.y);
1637
+ }
1638
+ }
1639
+ if (memory.pivot) {
1640
+ if (typeof memory.pivot === "number") {
1641
+ element.pivot.set(memory.pivot, memory.pivot);
1642
+ } else {
1643
+ element.pivot.set(memory.pivot.x, memory.pivot.y);
1644
+ }
1645
+ }
1646
+ memory.position && element.position.set(memory.position.x, memory.position.y);
1647
+ memory.skew && element.skew.set(memory.skew.x, memory.skew.y);
1648
+ memory.visible && (element.visible = memory.visible);
1649
+ memory.culled && (element.culled = memory.culled);
1650
+ memory.x && (element.x = memory.x);
1651
+ memory.y && (element.y = memory.y);
1652
+ memory.boundsArea && (element.boundsArea = memory.boundsArea);
1653
+ memory.cursor && (element.cursor = memory.cursor);
1654
+ memory.eventMode && (element.eventMode = memory.eventMode);
1655
+ memory.interactive && (element.interactive = memory.interactive);
1656
+ memory.interactiveChildren && (element.interactiveChildren = memory.interactiveChildren);
1657
+ memory.hitArea && (element.hitArea = memory.hitArea);
1658
+ }
1659
+
1660
+ // src/classes/canvas/CanvasImage.ts
1661
+ var import_pixi6 = require("pixi.js");
1662
+
1663
+ // src/functions/TextureUtility.ts
1664
+ var import_pixi4 = require("pixi.js");
1665
+ function getTexture(imageUrl) {
1666
+ return __async(this, null, function* () {
1667
+ if (import_pixi4.Assets.cache.has(imageUrl)) {
1668
+ return import_pixi4.Assets.get(imageUrl);
1669
+ }
1670
+ return import_pixi4.Assets.load(imageUrl).then((texture) => {
1671
+ if (!texture) {
1672
+ console.error("[Pixi'VM] Texture not found", imageUrl);
1673
+ return;
1674
+ }
1675
+ if (!(texture instanceof import_pixi4.Texture)) {
1676
+ console.error("[Pixi'VM] File not is a image", imageUrl);
1677
+ return;
1678
+ }
1679
+ return texture;
1680
+ }).catch((e) => {
1681
+ console.error("[Pixi'VM] Error loading image", e);
1682
+ return;
1683
+ });
1684
+ });
1685
+ }
1686
+ function getTextStyle(style) {
1687
+ let fill = style.fill;
1688
+ if (fill instanceof Object) {
1689
+ console.warn("[Pixi'VM] CanvasText.style.fill is a FillGradient or FillPattern, this is not supported yet.", fill);
1690
+ fill = "#00FF00";
1691
+ }
1692
+ return {
1693
+ align: style.align,
1694
+ breakWords: style.breakWords,
1695
+ dropShadow: style.dropShadow,
1696
+ fill,
1697
+ fontFamily: style.fontFamily,
1698
+ fontSize: style.fontSize,
1699
+ fontStyle: style.fontStyle,
1700
+ fontVariant: style.fontVariant,
1701
+ fontWeight: style.fontWeight,
1702
+ leading: style.leading,
1703
+ letterSpacing: style.letterSpacing,
1704
+ lineHeight: style.lineHeight,
1705
+ padding: style.padding,
1706
+ stroke: style.stroke,
1707
+ textBaseline: style.textBaseline,
1708
+ trim: style.trim,
1709
+ whiteSpace: style.whiteSpace,
1710
+ wordWrap: style.wordWrap,
1711
+ wordWrapWidth: style.wordWrapWidth
1712
+ };
1713
+ }
1714
+
1715
+ // src/classes/canvas/CanvasSprite.ts
1716
+ var import_pixi5 = require("pixi.js");
1717
+ var CanvasSprite = class extends import_pixi5.Sprite {
1718
+ constructor() {
1719
+ super(...arguments);
1720
+ this._onEvents = {};
1721
+ }
1722
+ get memory() {
1723
+ return getMemorySprite(this);
1724
+ }
1725
+ set memory(value) {
1726
+ setMemorySprite(this, value);
1727
+ }
1728
+ get onEvents() {
1729
+ return this._onEvents;
1730
+ }
1731
+ /**
1732
+ * is same function as on(), but it keeps in memory the children.
1733
+ * @param event The event type, e.g., 'click', 'mousedown', 'mouseup', 'pointerdown', etc.
1734
+ * @param eventClass The class that extends CanvasEvent.
1735
+ * @returns
1736
+ * @example
1737
+ * ```typescript
1738
+ * \@eventDecorator()
1739
+ * export class EventTest extends CanvasEvent<CanvasSprite> {
1740
+ * override fn(event: CanvasEventNamesType, sprite: CanvasSprite): void {
1741
+ * if (event === 'pointerdown') {
1742
+ * sprite.scale.x *= 1.25;
1743
+ * sprite.scale.y *= 1.25;
1744
+ * }
1745
+ * }
1746
+ * }
1747
+ * ```
1748
+ *
1749
+ * ```typescript
1750
+ * let sprite = addImage("alien", 'https://pixijs.com/assets/eggHead.png')
1751
+ * await sprite.load()
1752
+ *
1753
+ * sprite.eventMode = 'static';
1754
+ * sprite.cursor = 'pointer';
1755
+ * sprite.onEvent('pointerdown', EventTest);
1756
+ *
1757
+ * GameWindowManager.addCanvasElement("bunny", sprite);
1758
+ * ```
1759
+ */
1760
+ onEvent(event, eventClass) {
1761
+ let className = eventClass.name;
1762
+ let instance = getEventInstanceByClassName(className);
1763
+ this._onEvents[event] = className;
1764
+ if (instance) {
1765
+ super.on(event, () => {
1766
+ instance.fn(event, this);
1767
+ });
1768
+ }
1769
+ return this;
1770
+ }
1771
+ /**
1772
+ * on() does not keep in memory the event class, use onEvent() instead
1773
+ * @deprecated
1774
+ * @private
1775
+ * @param event
1776
+ * @param fn
1777
+ * @param context
1778
+ */
1779
+ on(event, fn, context) {
1780
+ return super.on(event, fn, context);
1781
+ }
1782
+ static from(source, skipCache) {
1783
+ let sprite = import_pixi5.Sprite.from(source, skipCache);
1784
+ let mySprite = new CanvasSprite();
1785
+ mySprite.texture = sprite.texture;
1786
+ return mySprite;
1787
+ }
1788
+ };
1789
+ CanvasSprite = __decorateClass([
1790
+ canvasElementDecorator()
1791
+ ], CanvasSprite);
1792
+ function getMemorySprite(element) {
1793
+ let temp = getMemoryContainer(element);
1794
+ return __spreadProps(__spreadValues({}, temp), {
1795
+ className: "CanvasSprite",
1796
+ textureImage: getTextureMemory(element.texture),
1797
+ anchor: { x: element.anchor.x, y: element.anchor.y },
1798
+ roundPixels: element.roundPixels,
1799
+ onEvents: element.onEvents
1800
+ });
1801
+ }
1802
+ function setMemorySprite(element, memory) {
1803
+ setMemoryContainer(element, memory);
1804
+ getTexture(memory.textureImage.image).then((texture) => {
1805
+ if (texture) {
1806
+ element.texture = texture;
1807
+ }
1808
+ });
1809
+ if (memory.anchor) {
1810
+ if (typeof memory.anchor === "number") {
1811
+ element.anchor.set(memory.anchor, memory.anchor);
1812
+ } else {
1813
+ element.anchor.set(memory.anchor.x, memory.anchor.y);
1814
+ }
1815
+ }
1816
+ memory.roundPixels && (element.roundPixels = memory.roundPixels);
1817
+ for (let event in memory.onEvents) {
1818
+ let className = memory.onEvents[event];
1819
+ let instance = getEventTypeByClassName(className);
1820
+ if (instance) {
1821
+ element.onEvent(event, instance);
1822
+ }
1823
+ }
1824
+ }
1825
+
1826
+ // src/classes/canvas/CanvasImage.ts
1827
+ var CanvasImage = class extends CanvasSprite {
1828
+ constructor() {
1829
+ super(...arguments);
1830
+ this.imageLink = "";
1831
+ }
1832
+ get memory() {
1833
+ return __spreadProps(__spreadValues({}, getMemorySprite(this)), {
1834
+ className: "CanvasImage",
1835
+ textureImage: { image: this.imageLink }
1836
+ });
1837
+ }
1838
+ set memory(memory) {
1839
+ setMemorySprite(this, memory);
1840
+ }
1841
+ static from(source, skipCache) {
1842
+ let sprite = import_pixi6.Sprite.from(source, skipCache);
1843
+ let mySprite = new CanvasImage();
1844
+ mySprite.texture = sprite.texture;
1845
+ return mySprite;
1846
+ }
1847
+ /**
1848
+ * Load the image in the canvas.
1849
+ * @returns a promise that resolves when the image is loaded.
1850
+ */
1851
+ load() {
1852
+ return __async(this, null, function* () {
1853
+ return getTexture(this.imageLink).then((texture) => {
1854
+ if (texture) {
1855
+ this.texture = texture;
1856
+ }
1857
+ }).catch((e) => {
1858
+ console.error("[Pixi'VM] Error into CanvasImage.load()", e);
1859
+ });
1860
+ });
1861
+ }
1862
+ };
1863
+ CanvasImage = __decorateClass([
1864
+ canvasElementDecorator()
1865
+ ], CanvasImage);
1866
+
1867
+ // src/classes/canvas/CanvasText.ts
1868
+ var import_pixi7 = require("pixi.js");
1869
+ var CanvasText = class extends import_pixi7.Text {
1870
+ constructor() {
1871
+ super(...arguments);
1872
+ this._onEvents = {};
1873
+ }
1874
+ get memory() {
1875
+ return getMemoryText(this);
1876
+ }
1877
+ set memory(value) {
1878
+ setMemoryText(this, value);
1879
+ }
1880
+ get onEvents() {
1881
+ return this._onEvents;
1882
+ }
1883
+ /**
1884
+ * is same function as on(), but it keeps in memory the children.
1885
+ * @param event The event type, e.g., 'click', 'mousedown', 'mouseup', 'pointerdown', etc.
1886
+ * @param eventClass The class that extends CanvasEvent.
1887
+ * @returns
1888
+ * @example
1889
+ * ```typescript
1890
+ * \@eventDecorator()
1891
+ * export class EventTest extends CanvasEvent<CanvasText> {
1892
+ * override fn(event: CanvasEventNamesType, text: CanvasText): void {
1893
+ * if (event === 'pointerdown') {
1894
+ * text.scale.x *= 1.25;
1895
+ * text.scale.y *= 1.25;
1896
+ * }
1897
+ * }
1898
+ * }
1899
+ * ```
1900
+ *
1901
+ * ```typescript
1902
+ * const text = new CanvasText();
1903
+ * text.text = "Hello World"
1904
+ *
1905
+ * text.eventMode = 'static';
1906
+ * text.cursor = 'pointer';
1907
+ * text.onEvent('pointerdown', EventTest);
1908
+ *
1909
+ * GameWindowManager.addCanvasElement("text", text);
1910
+ * ```
1911
+ */
1912
+ onEvent(event, eventClass) {
1913
+ let className = eventClass.name;
1914
+ let instance = getEventInstanceByClassName(className);
1915
+ this._onEvents[event] = className;
1916
+ if (instance) {
1917
+ super.on(event, () => {
1918
+ instance.fn(event, this);
1919
+ });
1920
+ }
1921
+ return this;
1922
+ }
1923
+ /**
1924
+ * on() does not keep in memory the event class, use onEvent() instead
1925
+ * @deprecated
1926
+ * @private
1927
+ * @param event
1928
+ * @param fn
1929
+ * @param context
1930
+ */
1931
+ on(event, fn, context) {
1932
+ return super.on(event, fn, context);
1933
+ }
1934
+ };
1935
+ CanvasText = __decorateClass([
1936
+ canvasElementDecorator()
1937
+ ], CanvasText);
1938
+ function getMemoryText(element) {
1939
+ let temp = getMemoryContainer(element);
1940
+ return __spreadProps(__spreadValues({}, temp), {
1941
+ className: "CanvasText",
1942
+ anchor: { x: element.anchor.x, y: element.anchor.y },
1943
+ text: element.text,
1944
+ resolution: element.resolution,
1945
+ style: getTextStyle(element.style),
1946
+ roundPixels: element.roundPixels,
1947
+ onEvents: element.onEvents
1948
+ });
1949
+ }
1950
+ function setMemoryText(element, memory) {
1951
+ setMemoryContainer(element, memory);
1952
+ if (memory.anchor) {
1953
+ if (typeof memory.anchor === "number") {
1954
+ element.anchor.set(memory.anchor, memory.anchor);
1955
+ } else {
1956
+ element.anchor.set(memory.anchor.x, memory.anchor.y);
1957
+ }
1958
+ }
1959
+ memory.text && (element.text = memory.text);
1960
+ memory.resolution && (element.resolution = memory.resolution);
1961
+ memory.style && (element.style = memory.style);
1962
+ memory.roundPixels && (element.roundPixels = memory.roundPixels);
1963
+ for (let event in memory.onEvents) {
1964
+ let className = memory.onEvents[event];
1965
+ let instance = getEventTypeByClassName(className);
1966
+ if (instance) {
1967
+ element.onEvent(event, instance);
1968
+ }
1969
+ }
1970
+ }
1971
+
1972
+ // src/classes/ticker/TickerFadeAlpha.ts
1973
+ var import_pixi8 = require("pixi.js");
1974
+ var TickerFadeAlpha = class extends TickerBase {
1975
+ /**
1976
+ * The method that will be called every frame to fade the alpha of the canvas element of the canvas.
1977
+ * @param delta The delta time
1978
+ * @param args The arguments that are passed to the ticker
1979
+ * @param tags The tags of the canvas element that are connected to this ticker
1980
+ */
1981
+ fn(t, args, tags) {
1982
+ let type = args.type === void 0 ? "hide" : args.type;
1983
+ let speed = args.speed === void 0 ? 0.1 : args.speed;
1984
+ let limit = args.limit === void 0 ? type === "hide" ? 0 : 1 : args.limit;
1985
+ let removeElementAfter = args.tagToRemoveAfter || [];
1986
+ if (typeof removeElementAfter === "string") {
1987
+ removeElementAfter = [removeElementAfter];
1988
+ }
1989
+ if (type === "hide" && limit < 0) {
1990
+ limit = 0;
1991
+ }
1992
+ if (type === "show" && limit > 1) {
1993
+ limit = 1;
1994
+ }
1995
+ tags.filter((tag) => {
1996
+ var _a;
1997
+ let element = GameWindowManager.getCanvasElement(tag);
1998
+ if (args.startOnlyIfHaveTexture) {
1999
+ if (element && element instanceof import_pixi8.Sprite && ((_a = element.texture) == null ? void 0 : _a.label) == "EMPTY") {
2000
+ return false;
2001
+ }
2002
+ }
2003
+ return true;
2004
+ }).forEach((tag) => {
2005
+ let element = GameWindowManager.getCanvasElement(tag);
2006
+ if (element && element instanceof import_pixi8.Container) {
2007
+ if (type === "show" && element.alpha < limit) {
2008
+ element.alpha += speed * t.deltaTime;
2009
+ } else if (type === "hide" && element.alpha > limit) {
2010
+ element.alpha -= speed * t.deltaTime;
2011
+ } else {
2012
+ element.alpha = limit;
2013
+ GameWindowManager.removeAssociationBetweenTickerCanvasElement(tag, this);
2014
+ GameWindowManager.removeCanvasElement(removeElementAfter);
2015
+ }
2016
+ }
2017
+ });
2018
+ }
2019
+ };
2020
+ TickerFadeAlpha = __decorateClass([
2021
+ tickerDecorator()
2022
+ ], TickerFadeAlpha);
2023
+
2024
+ // src/classes/ticker/TickerRotate.ts
2025
+ var import_pixi9 = require("pixi.js");
2026
+
2027
+ // src/functions/TickerUtility.ts
2028
+ function updateTickerProgression(args, propertyName, progression) {
2029
+ if (args.hasOwnProperty(propertyName) && typeof args[propertyName] !== "number") {
2030
+ return;
2031
+ }
2032
+ if (args[propertyName] !== void 0 && progression && args[propertyName] !== progression.limit) {
2033
+ if (progression.type === "linear") {
2034
+ args[propertyName] += progression.amt;
2035
+ if (progression.limit !== void 0) {
2036
+ if (args[propertyName] > progression.limit && progression.amt > 0) {
2037
+ args[propertyName] = progression.limit;
2038
+ } else if (args[propertyName] < progression.limit && progression.amt < 0) {
2039
+ args[propertyName] = progression.limit;
2040
+ }
2041
+ }
2042
+ } else if (progression.type === "exponential") {
2043
+ args[propertyName] += args[propertyName] * progression.percentage;
2044
+ if (progression.limit !== void 0) {
2045
+ if (args[propertyName] > progression.limit && progression.percentage > 0) {
2046
+ args[propertyName] = progression.limit;
2047
+ } else if (args[propertyName] < progression.limit && progression.percentage < 0) {
2048
+ args[propertyName] = progression.limit;
2049
+ }
2050
+ }
2051
+ }
2052
+ }
2053
+ }
2054
+
2055
+ // src/classes/ticker/TickerRotate.ts
2056
+ var TickerRotate = class extends TickerBase {
2057
+ /**
2058
+ * The method that will be called every frame to rotate the canvas element of the canvas.
2059
+ * @param delta The delta time
2060
+ * @param args The arguments that are passed to the ticker
2061
+ * @param tags The tags of the canvas element that are connected to this ticker
2062
+ */
2063
+ fn(t, args, tags) {
2064
+ let speed = args.speed === void 0 ? 0.1 : args.speed;
2065
+ let clockwise = args.clockwise === void 0 ? true : args.clockwise;
2066
+ tags.filter((tag) => {
2067
+ var _a;
2068
+ let element = GameWindowManager.getCanvasElement(tag);
2069
+ if (args.startOnlyIfHaveTexture) {
2070
+ if (element && element instanceof import_pixi9.Sprite && ((_a = element.texture) == null ? void 0 : _a.label) == "EMPTY") {
2071
+ return false;
2072
+ }
2073
+ }
2074
+ return true;
2075
+ }).forEach((tag) => {
2076
+ let element = GameWindowManager.getCanvasElement(tag);
2077
+ if (element && element instanceof import_pixi9.Container) {
2078
+ if (clockwise)
2079
+ element.rotation += speed * t.deltaTime;
2080
+ else
2081
+ element.rotation -= speed * t.deltaTime;
2082
+ }
2083
+ });
2084
+ if (args.speedProgression)
2085
+ updateTickerProgression(args, "speed", args.speedProgression);
2086
+ }
2087
+ };
2088
+ TickerRotate = __decorateClass([
2089
+ tickerDecorator()
2090
+ ], TickerRotate);
2091
+
2092
+ // src/functions/DialogueUtility.ts
2093
+ function setDialogue(props) {
2094
+ let text = "";
2095
+ let characterTag = void 0;
2096
+ if (typeof props === "string") {
2097
+ text = props;
2098
+ } else {
2099
+ text = props.text;
2100
+ if (props.character) {
2101
+ if (typeof props.character === "string") {
2102
+ characterTag = props.character;
2103
+ } else {
2104
+ characterTag = props.character.id;
2105
+ }
2106
+ }
2107
+ }
2108
+ let dialogue = new DialogueModelBase(text, characterTag);
2109
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY, dialogue);
2110
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY, GameStepManager.lastStepIndex);
2111
+ }
2112
+ function getDialogue() {
2113
+ return GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY);
2114
+ }
2115
+ function clearDialogue() {
2116
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY, void 0);
2117
+ }
2118
+ function setMenuOptions(options) {
2119
+ let value = options.map((option) => {
2120
+ return __spreadProps(__spreadValues({}, option), {
2121
+ label: option.label.name
2122
+ });
2123
+ });
2124
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, value);
2125
+ }
2126
+ function getMenuOptions() {
2127
+ let d = GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY);
2128
+ if (d) {
2129
+ let options = [];
2130
+ d.forEach((option) => {
2131
+ let label = getLabelTypeByClassName(option.label);
2132
+ if (label) {
2133
+ options.push(__spreadProps(__spreadValues({}, option), {
2134
+ label
2135
+ }));
2136
+ }
2137
+ });
2138
+ return options;
2139
+ }
2140
+ return void 0;
2141
+ }
2142
+ function clearMenuOptions() {
2143
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, void 0);
2144
+ }
2145
+ function getDialogueHistory() {
2146
+ let list = GameStepManager.stepsHistory.map((step, index) => {
2147
+ if (step.storage.storage[GameStorageManager.keysSystem.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY] !== index)
2148
+ return void 0;
2149
+ return step.storage.storage[GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY];
2150
+ });
2151
+ return list.filter((d) => d !== void 0);
2152
+ }
2153
+
2154
+ // src/functions/GameUtility.ts
2155
+ function clearAllGameDatas() {
2156
+ GameStorageManager.clear();
2157
+ GameWindowManager.clear();
2158
+ GameStepManager.clear();
2159
+ }
2160
+
2161
+ // src/functions/ImageUtility.ts
2162
+ function addImage(tag, imageUrl) {
2163
+ let image = new CanvasImage();
2164
+ image.imageLink = imageUrl;
2165
+ GameWindowManager.addCanvasElement(tag, image);
2166
+ return image;
2167
+ }
2168
+ function showCanvasImages(canvasImages) {
2169
+ return __async(this, null, function* () {
2170
+ if (!Array.isArray(canvasImages)) {
2171
+ return [canvasImages];
2172
+ }
2173
+ let promises = Array(canvasImages.length);
2174
+ for (let i = 0; i < canvasImages.length; i++) {
2175
+ promises[i] = getTexture(canvasImages[i].imageLink);
2176
+ }
2177
+ return Promise.all(promises).then((textures) => {
2178
+ return textures.map((texture, index) => {
2179
+ if (texture) {
2180
+ canvasImages[index].texture = texture;
2181
+ return canvasImages[index];
2182
+ }
2183
+ canvasImages[index].load();
2184
+ return canvasImages[index];
2185
+ });
2186
+ });
2187
+ });
2188
+ }
2189
+ function removeCanvasElement(tag) {
2190
+ GameWindowManager.removeCanvasElement(tag);
2191
+ }
2192
+ function showImageWithDisolveEffect(tag, imageUrl, speed, priority) {
2193
+ return __async(this, null, function* () {
2194
+ if (!GameWindowManager.getCanvasElement(tag)) {
2195
+ let image2 = addImage(tag, imageUrl);
2196
+ image2.alpha = 0;
2197
+ let effect2 = new TickerFadeAlpha({
2198
+ speed,
2199
+ type: "show",
2200
+ startOnlyIfHaveTexture: true
2201
+ }, 1e4, priority);
2202
+ GameWindowManager.addTicker(tag, effect2);
2203
+ return image2.load();
2204
+ }
2205
+ let specialTag = tag + "_temp_disolve";
2206
+ let effect = new TickerFadeAlpha({
2207
+ speed,
2208
+ type: "show",
2209
+ tagToRemoveAfter: specialTag,
2210
+ startOnlyIfHaveTexture: true
2211
+ }, 1e4, priority);
2212
+ GameWindowManager.editTagCanvasElement(tag, specialTag);
2213
+ let image = addImage(tag, imageUrl);
2214
+ image.alpha = 0;
2215
+ GameWindowManager.addTicker(tag, effect);
2216
+ return image.load();
2217
+ });
2218
+ }
2219
+
2220
+ // src/constants.ts
2221
+ var PIXIVM_VERSION = "0.1.0";
2222
+
2223
+ // src/functions/SavesUtility.ts
2224
+ function getSaveData() {
2225
+ return {
2226
+ version: PIXIVM_VERSION,
2227
+ stepData: GameStepManager.export(),
2228
+ storageData: GameStorageManager.export(),
2229
+ canvasData: GameWindowManager.export(),
2230
+ path: window.location.pathname
2231
+ };
2232
+ }
2233
+ function getSaveJson() {
2234
+ const saveData = getSaveData();
2235
+ return JSON.stringify(saveData);
2236
+ }
2237
+ function loadSave(data, navigate) {
2238
+ GameStepManager.import(data.stepData);
2239
+ GameStorageManager.import(data.storageData);
2240
+ GameWindowManager.import(data.canvasData);
2241
+ navigate(data.path);
2242
+ }
2243
+ function loadSaveJsonString(dataString, navigate) {
2244
+ loadSave(JSON.parse(dataString), navigate);
2245
+ }
2246
+ // Annotate the CommonJS export names for ESM import in node:
2247
+ 0 && (module.exports = {
2248
+ CanvasBase,
2249
+ CanvasContainer,
2250
+ CanvasEvent,
2251
+ CanvasImage,
2252
+ CanvasSprite,
2253
+ CanvasText,
2254
+ CharacterModelBase,
2255
+ DialogueModelBase,
2256
+ GameStepManager,
2257
+ GameStorageManager,
2258
+ GameWindowManager,
2259
+ Label,
2260
+ LabelRunModeEnum,
2261
+ MenuOptionLabel,
2262
+ Pause,
2263
+ PauseValueType,
2264
+ Repeat,
2265
+ StoredClassModel,
2266
+ TickerBase,
2267
+ TickerFadeAlpha,
2268
+ TickerRotate,
2269
+ addImage,
2270
+ canvasElementDecorator,
2271
+ clearAllGameDatas,
2272
+ clearDialogue,
2273
+ clearMenuOptions,
2274
+ eventDecorator,
2275
+ getCharacterByTag,
2276
+ getDialogue,
2277
+ getDialogueHistory,
2278
+ getMenuOptions,
2279
+ getSaveData,
2280
+ getSaveJson,
2281
+ getTexture,
2282
+ labelDecorator,
2283
+ loadSave,
2284
+ loadSaveJsonString,
2285
+ removeCanvasElement,
2286
+ saveCharacter,
2287
+ setDialogue,
2288
+ setMenuOptions,
2289
+ showCanvasImages,
2290
+ showImageWithDisolveEffect,
2291
+ tickerDecorator
2292
+ });
2293
+ //# sourceMappingURL=index.js.map