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