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