@drincs/pixi-vn 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/README.md +56 -7
  2. package/dist/classes/CharacterBaseModel.js +99 -90
  3. package/dist/classes/CharacterBaseModel.js.map +1 -1
  4. package/dist/classes/CharacterBaseModel.mjs +99 -90
  5. package/dist/classes/CharacterBaseModel.mjs.map +1 -1
  6. package/dist/classes/ChoiceMenuOption.d.mts +71 -8
  7. package/dist/classes/ChoiceMenuOption.d.ts +71 -8
  8. package/dist/classes/ChoiceMenuOption.js +160 -77
  9. package/dist/classes/ChoiceMenuOption.js.map +1 -1
  10. package/dist/classes/ChoiceMenuOption.mjs +160 -77
  11. package/dist/classes/ChoiceMenuOption.mjs.map +1 -1
  12. package/dist/classes/CloseLabel.d.mts +3 -1
  13. package/dist/classes/CloseLabel.d.ts +3 -1
  14. package/dist/classes/CloseLabel.js +77 -32
  15. package/dist/classes/CloseLabel.js.map +1 -1
  16. package/dist/classes/CloseLabel.mjs +77 -32
  17. package/dist/classes/CloseLabel.mjs.map +1 -1
  18. package/dist/classes/Label.d.mts +6 -33
  19. package/dist/classes/Label.d.ts +6 -33
  20. package/dist/classes/Label.js +74 -31
  21. package/dist/classes/Label.js.map +1 -1
  22. package/dist/classes/Label.mjs +74 -31
  23. package/dist/classes/Label.mjs.map +1 -1
  24. package/dist/classes/LabelAbstract.d.mts +50 -0
  25. package/dist/classes/LabelAbstract.d.ts +50 -0
  26. package/dist/classes/LabelAbstract.js +100 -0
  27. package/dist/classes/LabelAbstract.js.map +1 -0
  28. package/dist/classes/LabelAbstract.mjs +98 -0
  29. package/dist/classes/LabelAbstract.mjs.map +1 -0
  30. package/dist/classes/LabelJson.d.mts +30 -0
  31. package/dist/classes/LabelJson.d.ts +30 -0
  32. package/dist/classes/LabelJson.js +2766 -0
  33. package/dist/classes/LabelJson.js.map +1 -0
  34. package/dist/classes/LabelJson.mjs +2760 -0
  35. package/dist/classes/LabelJson.mjs.map +1 -0
  36. package/dist/classes/StoredClassModel.js +42 -33
  37. package/dist/classes/StoredClassModel.js.map +1 -1
  38. package/dist/classes/StoredClassModel.mjs +42 -33
  39. package/dist/classes/StoredClassModel.mjs.map +1 -1
  40. package/dist/classes/canvas/CanvasContainer.js +2 -2
  41. package/dist/classes/canvas/CanvasContainer.js.map +1 -1
  42. package/dist/classes/canvas/CanvasContainer.mjs +2 -2
  43. package/dist/classes/canvas/CanvasContainer.mjs.map +1 -1
  44. package/dist/classes/canvas/CanvasImage.js +2 -2
  45. package/dist/classes/canvas/CanvasImage.js.map +1 -1
  46. package/dist/classes/canvas/CanvasImage.mjs +2 -2
  47. package/dist/classes/canvas/CanvasImage.mjs.map +1 -1
  48. package/dist/classes/canvas/CanvasSprite.js +2 -2
  49. package/dist/classes/canvas/CanvasSprite.js.map +1 -1
  50. package/dist/classes/canvas/CanvasSprite.mjs +2 -2
  51. package/dist/classes/canvas/CanvasSprite.mjs.map +1 -1
  52. package/dist/classes/canvas/CanvasText.js +2 -2
  53. package/dist/classes/canvas/CanvasText.js.map +1 -1
  54. package/dist/classes/canvas/CanvasText.mjs +2 -2
  55. package/dist/classes/canvas/CanvasText.mjs.map +1 -1
  56. package/dist/classes/canvas/index.js +2 -2
  57. package/dist/classes/canvas/index.js.map +1 -1
  58. package/dist/classes/canvas/index.mjs +2 -2
  59. package/dist/classes/canvas/index.mjs.map +1 -1
  60. package/dist/classes/index.d.mts +6 -1
  61. package/dist/classes/index.d.ts +6 -1
  62. package/dist/classes/index.js +945 -78
  63. package/dist/classes/index.js.map +1 -1
  64. package/dist/classes/index.mjs +945 -79
  65. package/dist/classes/index.mjs.map +1 -1
  66. package/dist/classes/ticker/FadeAlphaTicker.js +42 -33
  67. package/dist/classes/ticker/FadeAlphaTicker.js.map +1 -1
  68. package/dist/classes/ticker/FadeAlphaTicker.mjs +42 -33
  69. package/dist/classes/ticker/FadeAlphaTicker.mjs.map +1 -1
  70. package/dist/classes/ticker/MoveTicker.d.mts +1 -0
  71. package/dist/classes/ticker/MoveTicker.d.ts +1 -0
  72. package/dist/classes/ticker/MoveTicker.js +42 -33
  73. package/dist/classes/ticker/MoveTicker.js.map +1 -1
  74. package/dist/classes/ticker/MoveTicker.mjs +42 -33
  75. package/dist/classes/ticker/MoveTicker.mjs.map +1 -1
  76. package/dist/classes/ticker/RotateTicker.d.mts +1 -0
  77. package/dist/classes/ticker/RotateTicker.d.ts +1 -0
  78. package/dist/classes/ticker/RotateTicker.js +42 -33
  79. package/dist/classes/ticker/RotateTicker.js.map +1 -1
  80. package/dist/classes/ticker/RotateTicker.mjs +42 -33
  81. package/dist/classes/ticker/RotateTicker.mjs.map +1 -1
  82. package/dist/classes/ticker/ZoomTicker.d.mts +1 -0
  83. package/dist/classes/ticker/ZoomTicker.d.ts +1 -0
  84. package/dist/classes/ticker/ZoomTicker.js +42 -33
  85. package/dist/classes/ticker/ZoomTicker.js.map +1 -1
  86. package/dist/classes/ticker/ZoomTicker.mjs +42 -33
  87. package/dist/classes/ticker/ZoomTicker.mjs.map +1 -1
  88. package/dist/classes/ticker/index.js +42 -33
  89. package/dist/classes/ticker/index.js.map +1 -1
  90. package/dist/classes/ticker/index.mjs +42 -33
  91. package/dist/classes/ticker/index.mjs.map +1 -1
  92. package/dist/constants.d.mts +1 -1
  93. package/dist/constants.d.ts +1 -1
  94. package/dist/constants.js +1 -1
  95. package/dist/constants.js.map +1 -1
  96. package/dist/constants.mjs +1 -1
  97. package/dist/constants.mjs.map +1 -1
  98. package/dist/decorators/CanvasElementDecorator.js +2 -2
  99. package/dist/decorators/CanvasElementDecorator.js.map +1 -1
  100. package/dist/decorators/CanvasElementDecorator.mjs +2 -2
  101. package/dist/decorators/CanvasElementDecorator.mjs.map +1 -1
  102. package/dist/decorators/LabelDecorator.d.mts +19 -5
  103. package/dist/decorators/LabelDecorator.d.ts +19 -5
  104. package/dist/decorators/LabelDecorator.js +102 -65
  105. package/dist/decorators/LabelDecorator.js.map +1 -1
  106. package/dist/decorators/LabelDecorator.mjs +102 -66
  107. package/dist/decorators/LabelDecorator.mjs.map +1 -1
  108. package/dist/decorators/index.d.mts +10 -2
  109. package/dist/decorators/index.d.ts +10 -2
  110. package/dist/decorators/index.js +98 -65
  111. package/dist/decorators/index.js.map +1 -1
  112. package/dist/decorators/index.mjs +98 -65
  113. package/dist/decorators/index.mjs.map +1 -1
  114. package/dist/functions/CanvasUtility.js +2 -2
  115. package/dist/functions/CanvasUtility.js.map +1 -1
  116. package/dist/functions/CanvasUtility.mjs +2 -2
  117. package/dist/functions/CanvasUtility.mjs.map +1 -1
  118. package/dist/functions/DialogueUtility.d.mts +10 -8
  119. package/dist/functions/DialogueUtility.d.ts +10 -8
  120. package/dist/functions/DialogueUtility.js +268 -131
  121. package/dist/functions/DialogueUtility.js.map +1 -1
  122. package/dist/functions/DialogueUtility.mjs +268 -131
  123. package/dist/functions/DialogueUtility.mjs.map +1 -1
  124. package/dist/functions/FlagsUtility.js +42 -33
  125. package/dist/functions/FlagsUtility.js.map +1 -1
  126. package/dist/functions/FlagsUtility.mjs +42 -33
  127. package/dist/functions/FlagsUtility.mjs.map +1 -1
  128. package/dist/functions/GameUtility.js +42 -33
  129. package/dist/functions/GameUtility.js.map +1 -1
  130. package/dist/functions/GameUtility.mjs +42 -33
  131. package/dist/functions/GameUtility.mjs.map +1 -1
  132. package/dist/functions/ImageUtility.js +45 -36
  133. package/dist/functions/ImageUtility.js.map +1 -1
  134. package/dist/functions/ImageUtility.mjs +45 -36
  135. package/dist/functions/ImageUtility.mjs.map +1 -1
  136. package/dist/functions/Importer.d.mts +24 -0
  137. package/dist/functions/Importer.d.ts +24 -0
  138. package/dist/functions/Importer.js +2804 -0
  139. package/dist/functions/Importer.js.map +1 -0
  140. package/dist/functions/Importer.mjs +2798 -0
  141. package/dist/functions/Importer.mjs.map +1 -0
  142. package/dist/functions/SavesUtility.d.mts +5 -3
  143. package/dist/functions/SavesUtility.d.ts +5 -3
  144. package/dist/functions/SavesUtility.js +310 -145
  145. package/dist/functions/SavesUtility.js.map +1 -1
  146. package/dist/functions/SavesUtility.mjs +310 -145
  147. package/dist/functions/SavesUtility.mjs.map +1 -1
  148. package/dist/functions/TickerUtility.d.mts +2 -1
  149. package/dist/functions/TickerUtility.d.ts +2 -1
  150. package/dist/functions/TickerUtility.js +19 -15
  151. package/dist/functions/TickerUtility.js.map +1 -1
  152. package/dist/functions/TickerUtility.mjs +19 -15
  153. package/dist/functions/TickerUtility.mjs.map +1 -1
  154. package/dist/functions/index.d.mts +7 -2
  155. package/dist/functions/index.d.ts +7 -2
  156. package/dist/functions/index.js +364 -140
  157. package/dist/functions/index.js.map +1 -1
  158. package/dist/functions/index.mjs +364 -141
  159. package/dist/functions/index.mjs.map +1 -1
  160. package/dist/index.d.mts +6 -0
  161. package/dist/index.d.ts +6 -0
  162. package/dist/index.js +453 -219
  163. package/dist/index.js.map +1 -1
  164. package/dist/index.mjs +453 -221
  165. package/dist/index.mjs.map +1 -1
  166. package/dist/interface/IHistoryStep.d.mts +3 -1
  167. package/dist/interface/IHistoryStep.d.ts +3 -1
  168. package/dist/interface/ISaveData.d.mts +3 -1
  169. package/dist/interface/ISaveData.d.ts +3 -1
  170. package/dist/interface/LabelProps.d.mts +38 -0
  171. package/dist/interface/LabelProps.d.ts +38 -0
  172. package/dist/interface/LabelProps.js +4 -0
  173. package/dist/interface/LabelProps.js.map +1 -0
  174. package/dist/interface/LabelProps.mjs +3 -0
  175. package/dist/interface/LabelProps.mjs.map +1 -0
  176. package/dist/interface/export/ExportedStep.d.mts +3 -1
  177. package/dist/interface/export/ExportedStep.d.ts +3 -1
  178. package/dist/interface/export/index.d.mts +3 -1
  179. package/dist/interface/export/index.d.ts +3 -1
  180. package/dist/interface/index.d.mts +3 -1
  181. package/dist/interface/index.d.ts +3 -1
  182. package/dist/labels/BaseCanvasElementTestLabel.d.mts +3 -1
  183. package/dist/labels/BaseCanvasElementTestLabel.d.ts +3 -1
  184. package/dist/labels/BaseCanvasElementTestLabel.js +303 -136
  185. package/dist/labels/BaseCanvasElementTestLabel.js.map +1 -1
  186. package/dist/labels/BaseCanvasElementTestLabel.mjs +304 -137
  187. package/dist/labels/BaseCanvasElementTestLabel.mjs.map +1 -1
  188. package/dist/labels/CanvasEventsTestLabel.d.mts +4 -5
  189. package/dist/labels/CanvasEventsTestLabel.d.ts +4 -5
  190. package/dist/labels/CanvasEventsTestLabel.js +313 -148
  191. package/dist/labels/CanvasEventsTestLabel.js.map +1 -1
  192. package/dist/labels/CanvasEventsTestLabel.mjs +314 -149
  193. package/dist/labels/CanvasEventsTestLabel.mjs.map +1 -1
  194. package/dist/labels/CustomTickerCanvasElementTestLabel.d.mts +3 -1
  195. package/dist/labels/CustomTickerCanvasElementTestLabel.d.ts +3 -1
  196. package/dist/labels/CustomTickerCanvasElementTestLabel.js +294 -133
  197. package/dist/labels/CustomTickerCanvasElementTestLabel.js.map +1 -1
  198. package/dist/labels/CustomTickerCanvasElementTestLabel.mjs +295 -134
  199. package/dist/labels/CustomTickerCanvasElementTestLabel.mjs.map +1 -1
  200. package/dist/labels/ImagesAnimationsTestLabel.d.mts +3 -1
  201. package/dist/labels/ImagesAnimationsTestLabel.d.ts +3 -1
  202. package/dist/labels/ImagesAnimationsTestLabel.js +298 -181
  203. package/dist/labels/ImagesAnimationsTestLabel.js.map +1 -1
  204. package/dist/labels/ImagesAnimationsTestLabel.mjs +299 -182
  205. package/dist/labels/ImagesAnimationsTestLabel.mjs.map +1 -1
  206. package/dist/labels/MarkdownTest.d.mts +3 -1
  207. package/dist/labels/MarkdownTest.d.ts +3 -1
  208. package/dist/labels/MarkdownTest.js +294 -133
  209. package/dist/labels/MarkdownTest.js.map +1 -1
  210. package/dist/labels/MarkdownTest.mjs +294 -133
  211. package/dist/labels/MarkdownTest.mjs.map +1 -1
  212. package/dist/labels/StartLabel.d.mts +3 -1
  213. package/dist/labels/StartLabel.d.ts +3 -1
  214. package/dist/labels/StartLabel.js +360 -213
  215. package/dist/labels/StartLabel.js.map +1 -1
  216. package/dist/labels/StartLabel.mjs +361 -214
  217. package/dist/labels/StartLabel.mjs.map +1 -1
  218. package/dist/labels/StepLabelTest.d.mts +11 -0
  219. package/dist/labels/StepLabelTest.d.ts +11 -0
  220. package/dist/labels/StepLabelTest.js +2861 -0
  221. package/dist/labels/StepLabelTest.js.map +1 -0
  222. package/dist/labels/StepLabelTest.mjs +2855 -0
  223. package/dist/labels/StepLabelTest.mjs.map +1 -0
  224. package/dist/labels/TestConstant.js +43 -34
  225. package/dist/labels/TestConstant.js.map +1 -1
  226. package/dist/labels/TestConstant.mjs +43 -34
  227. package/dist/labels/TestConstant.mjs.map +1 -1
  228. package/dist/labels/index.d.mts +3 -1
  229. package/dist/labels/index.d.ts +3 -1
  230. package/dist/labels/index.js +360 -213
  231. package/dist/labels/index.js.map +1 -1
  232. package/dist/labels/index.mjs +361 -214
  233. package/dist/labels/index.mjs.map +1 -1
  234. package/dist/managers/StepManager.d.mts +10 -7
  235. package/dist/managers/StepManager.d.ts +10 -7
  236. package/dist/managers/StepManager.js +300 -139
  237. package/dist/managers/StepManager.js.map +1 -1
  238. package/dist/managers/StepManager.mjs +300 -139
  239. package/dist/managers/StepManager.mjs.map +1 -1
  240. package/dist/managers/WindowManager.js +2 -2
  241. package/dist/managers/WindowManager.js.map +1 -1
  242. package/dist/managers/WindowManager.mjs +2 -2
  243. package/dist/managers/WindowManager.mjs.map +1 -1
  244. package/dist/managers/index.d.mts +7 -5
  245. package/dist/managers/index.d.ts +7 -5
  246. package/dist/managers/index.js +300 -139
  247. package/dist/managers/index.js.map +1 -1
  248. package/dist/managers/index.mjs +300 -139
  249. package/dist/managers/index.mjs.map +1 -1
  250. package/dist/types/ChoiceMenuOptionsType.d.mts +3 -1
  251. package/dist/types/ChoiceMenuOptionsType.d.ts +3 -1
  252. package/dist/types/LabelJsonType.d.mts +22 -0
  253. package/dist/types/LabelJsonType.d.ts +22 -0
  254. package/dist/types/LabelJsonType.js +4 -0
  255. package/dist/types/LabelJsonType.js.map +1 -0
  256. package/dist/types/LabelJsonType.mjs +3 -0
  257. package/dist/types/LabelJsonType.mjs.map +1 -0
  258. package/dist/types/StepLabelJsonType.d.mts +30 -0
  259. package/dist/types/StepLabelJsonType.d.ts +30 -0
  260. package/dist/types/StepLabelJsonType.js +4 -0
  261. package/dist/types/StepLabelJsonType.js.map +1 -0
  262. package/dist/types/StepLabelJsonType.mjs +3 -0
  263. package/dist/types/StepLabelJsonType.mjs.map +1 -0
  264. package/dist/types/index.d.mts +4 -0
  265. package/dist/types/index.d.ts +4 -0
  266. package/package.json +7 -6
@@ -0,0 +1,2798 @@
1
+ import { diff } from 'deep-diff';
2
+ import sha1 from 'crypto-js/sha1';
3
+ import { Sprite, Container, Application, Text, Assets, Texture } from 'pixi.js';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __defProps = Object.defineProperties;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
9
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __decorateClass = (decorators, target, key, kind) => {
26
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
27
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
28
+ if (decorator = decorators[i])
29
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
30
+ if (kind && result) __defProp(target, key, result);
31
+ return result;
32
+ };
33
+ var __async = (__this, __arguments, generator) => {
34
+ return new Promise((resolve, reject) => {
35
+ var fulfilled = (value) => {
36
+ try {
37
+ step(generator.next(value));
38
+ } catch (e) {
39
+ reject(e);
40
+ }
41
+ };
42
+ var rejected = (value) => {
43
+ try {
44
+ step(generator.throw(value));
45
+ } catch (e) {
46
+ reject(e);
47
+ }
48
+ };
49
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
50
+ step((generator = generator.apply(__this, __arguments)).next());
51
+ });
52
+ };
53
+ function getStepSha1(step) {
54
+ let sha1String = sha1(step.toString().toLocaleLowerCase());
55
+ return sha1String.toString();
56
+ }
57
+ function checkIfStepsIsEqual(step1, step2) {
58
+ return step1 === step2;
59
+ }
60
+
61
+ // src/classes/LabelAbstract.ts
62
+ var LabelAbstract = class {
63
+ /**
64
+ * @param id is the id of the label
65
+ * @param props is the properties of the label
66
+ */
67
+ constructor(id, props) {
68
+ this._id = id;
69
+ this._onStepStart = props == null ? void 0 : props.onStepStart;
70
+ this._onLoadStep = props == null ? void 0 : props.onLoadStep;
71
+ this._onStepEnd = props == null ? void 0 : props.onStepEnd;
72
+ this._choiseIndex = props == null ? void 0 : props.choiseIndex;
73
+ }
74
+ /**
75
+ * Get the id of the label. This variable is used in the system to get the label by id, {@link getLabelById}
76
+ */
77
+ get id() {
78
+ return this._id;
79
+ }
80
+ /**
81
+ * Get the corresponding steps number
82
+ * @param externalSteps
83
+ * @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
84
+ */
85
+ getCorrespondingStepsNumber(externalSteps) {
86
+ if (externalSteps.length === 0) {
87
+ return 0;
88
+ }
89
+ let res = 0;
90
+ externalSteps.forEach((step, index) => {
91
+ if (checkIfStepsIsEqual(step, this.steps[index])) {
92
+ res = index;
93
+ }
94
+ });
95
+ return res;
96
+ }
97
+ /**
98
+ * Is a function that will be executed in {@link Label#onStepStart} and when the user goes back to it or when the user laods a save file.
99
+ * @returns Promise<void> or void
100
+ */
101
+ get onStepStart() {
102
+ return (stepIndex, label) => __async(this, null, function* () {
103
+ if (this._onLoadStep) {
104
+ yield this._onLoadStep(stepIndex, label);
105
+ }
106
+ if (this._onStepStart) {
107
+ return yield this._onStepStart(stepIndex, label);
108
+ }
109
+ });
110
+ }
111
+ /**
112
+ * Get the function that will be executed a old step is reloaded. A step is reloaded when the user goes back to it or when the user laods a save file.
113
+ * @returns Promise<void> or void
114
+ */
115
+ get onLoadStep() {
116
+ return this._onLoadStep;
117
+ }
118
+ /**
119
+ * Is a function that will be executed when the step ends.
120
+ * @returns Promise<void> or void
121
+ */
122
+ get onStepEnd() {
123
+ return this._onStepEnd;
124
+ }
125
+ get choiseIndex() {
126
+ return this._choiseIndex;
127
+ }
128
+ };
129
+
130
+ // src/classes/Label.ts
131
+ var Label = class extends LabelAbstract {
132
+ /**
133
+ * @param id is the id of the label
134
+ * @param steps is the list of steps that the label will perform
135
+ * @param props is the properties of the label
136
+ */
137
+ constructor(id, steps, props) {
138
+ super(id, props);
139
+ this._steps = steps;
140
+ }
141
+ /**
142
+ * Get the steps of the label.
143
+ */
144
+ get steps() {
145
+ if (typeof this._steps === "function") {
146
+ return this._steps();
147
+ }
148
+ return this._steps;
149
+ }
150
+ };
151
+
152
+ // src/classes/CloseLabel.ts
153
+ var CLOSE_LABEL_ID = "__close-label-id__";
154
+ function newCloseLabel(choiseIndex) {
155
+ return new Label(CLOSE_LABEL_ID, [], {
156
+ choiseIndex
157
+ });
158
+ }
159
+
160
+ // src/decorators/LabelDecorator.ts
161
+ var registeredLabels = {};
162
+ function getLabelById(id) {
163
+ let label = registeredLabels[id];
164
+ if (!label) {
165
+ console.error(`[Pixi'VN] Label ${id} not found`);
166
+ return;
167
+ }
168
+ return label;
169
+ }
170
+ function saveLabel(label) {
171
+ registeredLabels[label.id] = label;
172
+ }
173
+
174
+ // src/functions/CanvasUtility.ts
175
+ function getTextureMemory(texture) {
176
+ let sourceTexture = texture.source;
177
+ let textureMemory = {
178
+ image: sourceTexture.label
179
+ };
180
+ return textureMemory;
181
+ }
182
+ function exportCanvasElement(element) {
183
+ return element.memory;
184
+ }
185
+ function importCanvasElement(memory) {
186
+ let element = getCanvasElementInstanceById(memory.pixivnId);
187
+ if (element) {
188
+ element.memory = memory;
189
+ } else {
190
+ throw new Error("[Pixi'VN] The element " + memory.pixivnId + " could not be created");
191
+ }
192
+ return element;
193
+ }
194
+
195
+ // src/classes/canvas/CanvasContainer.ts
196
+ var CANVAS_CONTAINER_ID = "CanvasContainer";
197
+ var CanvasContainer = class extends Container {
198
+ constructor(options) {
199
+ super(options);
200
+ this.pixivnId = CANVAS_CONTAINER_ID;
201
+ this.pixivnId = this.constructor.prototype.pixivnId || CANVAS_CONTAINER_ID;
202
+ }
203
+ get memory() {
204
+ let memory = getMemoryContainer(this);
205
+ this.children.forEach((child) => {
206
+ memory.elements.push(exportCanvasElement(child));
207
+ });
208
+ return memory;
209
+ }
210
+ set memory(value) {
211
+ setMemoryContainer(this, value);
212
+ value.elements.forEach((child) => {
213
+ this.addChild(importCanvasElement(child));
214
+ });
215
+ }
216
+ };
217
+ function getMemoryContainer(element) {
218
+ let className = "CanvasContainer";
219
+ if (element.hasOwnProperty("pixivnId")) {
220
+ className = element.pixivnId;
221
+ }
222
+ return {
223
+ pixivnId: className,
224
+ elements: [],
225
+ width: element.width,
226
+ height: element.height,
227
+ isRenderGroup: element.isRenderGroup,
228
+ blendMode: element.blendMode,
229
+ tint: element.tint,
230
+ alpha: element.alpha,
231
+ angle: element.angle,
232
+ renderable: element.renderable,
233
+ rotation: element.rotation,
234
+ scale: { x: element.scale.x, y: element.scale.y },
235
+ pivot: { x: element.pivot.x, y: element.pivot.y },
236
+ position: { x: element.position.x, y: element.position.y },
237
+ skew: { x: element.skew.x, y: element.skew.y },
238
+ visible: element.visible,
239
+ x: element.x,
240
+ y: element.y,
241
+ boundsArea: element.boundsArea,
242
+ cursor: element.cursor,
243
+ eventMode: element.eventMode,
244
+ interactive: element.interactive,
245
+ interactiveChildren: element.interactiveChildren,
246
+ hitArea: element.hitArea
247
+ };
248
+ }
249
+ function setMemoryContainer(element, memory) {
250
+ memory.isRenderGroup && (element.isRenderGroup = memory.isRenderGroup);
251
+ memory.blendMode && (element.blendMode = memory.blendMode);
252
+ memory.tint && (element.tint = memory.tint);
253
+ memory.alpha && (element.alpha = memory.alpha);
254
+ memory.angle && (element.angle = memory.angle);
255
+ memory.renderable && (element.renderable = memory.renderable);
256
+ memory.rotation && (element.rotation = memory.rotation);
257
+ if (memory.scale) {
258
+ if (typeof memory.scale === "number") {
259
+ element.scale.set(memory.scale, memory.scale);
260
+ } else {
261
+ element.scale.set(memory.scale.x, memory.scale.y);
262
+ }
263
+ }
264
+ if (memory.pivot) {
265
+ if (typeof memory.pivot === "number") {
266
+ element.pivot.set(memory.pivot, memory.pivot);
267
+ } else {
268
+ element.pivot.set(memory.pivot.x, memory.pivot.y);
269
+ }
270
+ }
271
+ memory.position && element.position.set(memory.position.x, memory.position.y);
272
+ memory.skew && element.skew.set(memory.skew.x, memory.skew.y);
273
+ memory.visible && (element.visible = memory.visible);
274
+ memory.x && (element.x = memory.x);
275
+ memory.y && (element.y = memory.y);
276
+ memory.boundsArea && (element.boundsArea = memory.boundsArea);
277
+ memory.cursor && (element.cursor = memory.cursor);
278
+ memory.eventMode && (element.eventMode = memory.eventMode);
279
+ memory.interactive && (element.interactive = memory.interactive);
280
+ memory.interactiveChildren && (element.interactiveChildren = memory.interactiveChildren);
281
+ memory.hitArea && (element.hitArea = memory.hitArea);
282
+ memory.width && (element.width = memory.width);
283
+ memory.height && (element.height = memory.height);
284
+ }
285
+ function getTexture(imageUrl) {
286
+ return __async(this, null, function* () {
287
+ if (Assets.cache.has(imageUrl)) {
288
+ return Assets.get(imageUrl);
289
+ }
290
+ return Assets.load(imageUrl).then((texture) => {
291
+ if (!texture) {
292
+ console.error("[Pixi'VN] Texture not found", imageUrl);
293
+ return;
294
+ }
295
+ if (!(texture instanceof Texture)) {
296
+ console.error("[Pixi'VN] File not is a image", imageUrl);
297
+ return;
298
+ }
299
+ return texture;
300
+ }).catch((e) => {
301
+ console.error("[Pixi'VN] Error loading image", e);
302
+ return;
303
+ });
304
+ });
305
+ }
306
+ function getFillGradientFillPattern(prop, propName) {
307
+ if (!(prop instanceof Object)) {
308
+ return prop;
309
+ }
310
+ console.warn(`[Pixi'VN] CanvasText.style.${propName} is a FillGradient or FillPattern, this is not supported yet.`, prop);
311
+ return void 0;
312
+ }
313
+ function getTextStyle(style) {
314
+ return {
315
+ align: style.align,
316
+ breakWords: style.breakWords,
317
+ dropShadow: style.dropShadow,
318
+ fill: getFillGradientFillPattern(style.stroke, "fill"),
319
+ fontFamily: style.fontFamily,
320
+ fontSize: style.fontSize,
321
+ fontStyle: style.fontStyle,
322
+ fontVariant: style.fontVariant,
323
+ fontWeight: style.fontWeight,
324
+ leading: style.leading,
325
+ letterSpacing: style.letterSpacing,
326
+ lineHeight: style.lineHeight,
327
+ padding: style.padding,
328
+ stroke: getFillGradientFillPattern(style.stroke, "stroke"),
329
+ textBaseline: style.textBaseline,
330
+ trim: style.trim,
331
+ whiteSpace: style.whiteSpace,
332
+ wordWrap: style.wordWrap,
333
+ wordWrapWidth: style.wordWrapWidth
334
+ };
335
+ }
336
+
337
+ // src/decorators/EventDecorator.ts
338
+ var registeredEvents = {};
339
+ function getEventTypeById(eventId) {
340
+ try {
341
+ let eventType = registeredEvents[eventId];
342
+ if (!eventType) {
343
+ console.error(`[Pixi'VN] Event ${eventId} not found`);
344
+ return;
345
+ }
346
+ new eventType();
347
+ return eventType;
348
+ } catch (e) {
349
+ console.error(`[Pixi'VN] Error while getting Event ${eventId}`, e);
350
+ return;
351
+ }
352
+ }
353
+ function getEventInstanceById(eventId) {
354
+ try {
355
+ let eventType = registeredEvents[eventId];
356
+ if (!eventType) {
357
+ console.error(`[Pixi'VN] Event ${eventId} not found`);
358
+ return;
359
+ }
360
+ let event = new eventType();
361
+ return event;
362
+ } catch (e) {
363
+ console.error(`[Pixi'VN] Error while getting Event ${eventId}`, e);
364
+ return;
365
+ }
366
+ }
367
+
368
+ // src/classes/canvas/CanvasSprite.ts
369
+ var CANVAS_SPRITE_ID = "CanvasSprite";
370
+ var CanvasSprite = class _CanvasSprite extends Sprite {
371
+ constructor(options) {
372
+ super(options);
373
+ this.pixivnId = CANVAS_SPRITE_ID;
374
+ this._onEvents = {};
375
+ this.pixivnId = this.constructor.prototype.pixivnId || CANVAS_SPRITE_ID;
376
+ }
377
+ get memory() {
378
+ return getMemorySprite(this);
379
+ }
380
+ set memory(value) {
381
+ setMemorySprite(this, value);
382
+ }
383
+ get onEvents() {
384
+ return this._onEvents;
385
+ }
386
+ /**
387
+ * is same function as on(), but it keeps in memory the children.
388
+ * @param event The event type, e.g., 'click', 'mousedown', 'mouseup', 'pointerdown', etc.
389
+ * @param eventClass The class that extends CanvasEvent.
390
+ * @returns
391
+ * @example
392
+ * ```typescript
393
+ * \@eventDecorator()
394
+ * export class EventTest extends CanvasEvent<CanvasSprite> {
395
+ * override fn(event: CanvasEventNamesType, sprite: CanvasSprite): void {
396
+ * if (event === 'pointerdown') {
397
+ * sprite.scale.x *= 1.25;
398
+ * sprite.scale.y *= 1.25;
399
+ * }
400
+ * }
401
+ * }
402
+ * ```
403
+ *
404
+ * ```typescript
405
+ * let sprite = addImage("alien", 'https://pixijs.com/assets/eggHead.png')
406
+ * await sprite.load()
407
+ *
408
+ * sprite.eventMode = 'static';
409
+ * sprite.cursor = 'pointer';
410
+ * sprite.onEvent('pointerdown', EventTest);
411
+ *
412
+ * GameWindowManager.addCanvasElement("bunny", sprite);
413
+ * ```
414
+ */
415
+ onEvent(event, eventClass) {
416
+ let id = eventClass.prototype.id;
417
+ let instance = getEventInstanceById(id);
418
+ this._onEvents[event] = id;
419
+ if (instance) {
420
+ super.on(event, () => {
421
+ instance.fn(event, this);
422
+ });
423
+ }
424
+ return this;
425
+ }
426
+ /**
427
+ * on() does not keep in memory the event class, use onEvent() instead
428
+ * @deprecated
429
+ * @private
430
+ * @param event
431
+ * @param fn
432
+ * @param context
433
+ */
434
+ on(event, fn, context) {
435
+ return super.on(event, fn, context);
436
+ }
437
+ static from(source, skipCache) {
438
+ let sprite = Sprite.from(source, skipCache);
439
+ let mySprite = new _CanvasSprite();
440
+ mySprite.texture = sprite.texture;
441
+ return mySprite;
442
+ }
443
+ };
444
+ function getMemorySprite(element) {
445
+ let temp = getMemoryContainer(element);
446
+ return __spreadProps(__spreadValues({}, temp), {
447
+ pixivnId: element.pixivnId,
448
+ textureImage: getTextureMemory(element.texture),
449
+ anchor: { x: element.anchor.x, y: element.anchor.y },
450
+ roundPixels: element.roundPixels,
451
+ onEvents: element.onEvents
452
+ });
453
+ }
454
+ function setMemorySprite(element, memory) {
455
+ setMemoryContainer(element, memory);
456
+ getTexture(memory.textureImage.image).then((texture) => {
457
+ if (texture) {
458
+ element.texture = texture;
459
+ }
460
+ });
461
+ if (memory.anchor) {
462
+ if (typeof memory.anchor === "number") {
463
+ element.anchor.set(memory.anchor, memory.anchor);
464
+ } else {
465
+ element.anchor.set(memory.anchor.x, memory.anchor.y);
466
+ }
467
+ }
468
+ memory.roundPixels && (element.roundPixels = memory.roundPixels);
469
+ for (let event in memory.onEvents) {
470
+ let id = memory.onEvents[event];
471
+ let instance = getEventTypeById(id);
472
+ if (instance) {
473
+ element.onEvent(event, instance);
474
+ }
475
+ }
476
+ }
477
+
478
+ // src/classes/canvas/CanvasImage.ts
479
+ var CANVAS_IMAGE_ID = "CanvasImage";
480
+ var CanvasImage = class _CanvasImage extends CanvasSprite {
481
+ constructor(options, imageLink) {
482
+ super(options);
483
+ this.pixivnId = CANVAS_IMAGE_ID;
484
+ this.imageLink = "";
485
+ if (imageLink) {
486
+ this.imageLink = imageLink;
487
+ }
488
+ }
489
+ get memory() {
490
+ return __spreadProps(__spreadValues({}, getMemorySprite(this)), {
491
+ pixivnId: this.pixivnId,
492
+ imageLink: this.imageLink
493
+ });
494
+ }
495
+ set memory(memory) {
496
+ setMemorySprite(this, memory);
497
+ this.imageLink = memory.imageLink;
498
+ }
499
+ static from(source, skipCache) {
500
+ let sprite = Sprite.from(source, skipCache);
501
+ let mySprite = new _CanvasImage();
502
+ mySprite.texture = sprite.texture;
503
+ return mySprite;
504
+ }
505
+ /**
506
+ * Load the image from the link and set the texture of the sprite.
507
+ * @param image The link of the image. If it is not set, it will use the imageLink property.
508
+ * @returns A promise that resolves when the image is loaded.
509
+ */
510
+ load(image) {
511
+ return __async(this, null, function* () {
512
+ if (!image) {
513
+ image = this.imageLink;
514
+ }
515
+ return getTexture(this.imageLink).then((texture) => {
516
+ if (texture) {
517
+ this.texture = texture;
518
+ }
519
+ }).catch((e) => {
520
+ console.error("[Pixi'VN] Error into CanvasImage.load()", e);
521
+ });
522
+ });
523
+ }
524
+ };
525
+ var CANVAS_TEXT_ID = "CanvasText";
526
+ var CanvasText = class extends Text {
527
+ constructor(options) {
528
+ super(options);
529
+ this.pixivnId = CANVAS_TEXT_ID;
530
+ this._onEvents = {};
531
+ this.pixivnId = this.constructor.prototype.pixivnId || CANVAS_TEXT_ID;
532
+ }
533
+ get memory() {
534
+ return getMemoryText(this);
535
+ }
536
+ set memory(value) {
537
+ setMemoryText(this, value);
538
+ }
539
+ get onEvents() {
540
+ return this._onEvents;
541
+ }
542
+ /**
543
+ * is same function as on(), but it keeps in memory the children.
544
+ * @param event The event type, e.g., 'click', 'mousedown', 'mouseup', 'pointerdown', etc.
545
+ * @param eventClass The class that extends CanvasEvent.
546
+ * @returns
547
+ * @example
548
+ * ```typescript
549
+ * \@eventDecorator()
550
+ * export class EventTest extends CanvasEvent<CanvasText> {
551
+ * override fn(event: CanvasEventNamesType, text: CanvasText): void {
552
+ * if (event === 'pointerdown') {
553
+ * text.scale.x *= 1.25;
554
+ * text.scale.y *= 1.25;
555
+ * }
556
+ * }
557
+ * }
558
+ * ```
559
+ *
560
+ * ```typescript
561
+ * const text = new CanvasText();
562
+ * text.text = "Hello World"
563
+ *
564
+ * text.eventMode = 'static';
565
+ * text.cursor = 'pointer';
566
+ * text.onEvent('pointerdown', EventTest);
567
+ *
568
+ * GameWindowManager.addCanvasElement("text", text);
569
+ * ```
570
+ */
571
+ onEvent(event, eventClass) {
572
+ let id = eventClass.prototype.id;
573
+ let instance = getEventInstanceById(id);
574
+ this._onEvents[event] = id;
575
+ if (instance) {
576
+ super.on(event, () => {
577
+ instance.fn(event, this);
578
+ });
579
+ }
580
+ return this;
581
+ }
582
+ /**
583
+ * on() does not keep in memory the event class, use onEvent() instead
584
+ * @deprecated
585
+ * @private
586
+ * @param event
587
+ * @param fn
588
+ * @param context
589
+ */
590
+ on(event, fn, context) {
591
+ return super.on(event, fn, context);
592
+ }
593
+ };
594
+ function getMemoryText(element) {
595
+ let temp = getMemoryContainer(element);
596
+ return __spreadProps(__spreadValues({}, temp), {
597
+ pixivnId: element.pixivnId,
598
+ anchor: { x: element.anchor.x, y: element.anchor.y },
599
+ text: element.text,
600
+ resolution: element.resolution,
601
+ style: getTextStyle(element.style),
602
+ roundPixels: element.roundPixels,
603
+ onEvents: element.onEvents
604
+ });
605
+ }
606
+ function setMemoryText(element, memory) {
607
+ setMemoryContainer(element, memory);
608
+ if (memory.anchor) {
609
+ if (typeof memory.anchor === "number") {
610
+ element.anchor.set(memory.anchor, memory.anchor);
611
+ } else {
612
+ element.anchor.set(memory.anchor.x, memory.anchor.y);
613
+ }
614
+ }
615
+ memory.text && (element.text = memory.text);
616
+ memory.resolution && (element.resolution = memory.resolution);
617
+ memory.style && (element.style = memory.style);
618
+ memory.roundPixels && (element.roundPixels = memory.roundPixels);
619
+ for (let event in memory.onEvents) {
620
+ let id = memory.onEvents[event];
621
+ let instance = getEventTypeById(id);
622
+ if (instance) {
623
+ element.onEvent(event, instance);
624
+ }
625
+ }
626
+ }
627
+
628
+ // src/decorators/CanvasElementDecorator.ts
629
+ var registeredCanvasElement = {};
630
+ function getCanvasElementInstanceById(canvasId) {
631
+ try {
632
+ let eventType = registeredCanvasElement[canvasId];
633
+ if (!eventType) {
634
+ if (canvasId === CANVAS_CONTAINER_ID) {
635
+ eventType = CanvasContainer;
636
+ } else if (canvasId === CANVAS_IMAGE_ID) {
637
+ eventType = CanvasImage;
638
+ } else if (canvasId === CANVAS_SPRITE_ID) {
639
+ eventType = CanvasSprite;
640
+ } else if (canvasId === CANVAS_TEXT_ID) {
641
+ eventType = CanvasText;
642
+ }
643
+ }
644
+ if (!eventType) {
645
+ console.error(`[Pixi'VN] CanvasElement ${canvasId} not found`);
646
+ return;
647
+ }
648
+ let canvasElement = new eventType();
649
+ return canvasElement;
650
+ } catch (e) {
651
+ console.error(`[Pixi'VN] Error while getting CanvasElement ${canvasId}`, e);
652
+ return;
653
+ }
654
+ }
655
+
656
+ // src/decorators/TickerDecorator.ts
657
+ var registeredTickers = {};
658
+ function tickerDecorator(name) {
659
+ return function(target) {
660
+ if (!name) {
661
+ name = target.name;
662
+ }
663
+ if (registeredTickers[name]) {
664
+ console.info(`[Pixi'VN] Ticker ${name} already exists, it will be overwritten`);
665
+ }
666
+ target.prototype.id = name;
667
+ registeredTickers[name] = target;
668
+ };
669
+ }
670
+ function geTickerInstanceById(tickerId, args, duration, priority) {
671
+ try {
672
+ let ticker = registeredTickers[tickerId];
673
+ if (!ticker) {
674
+ console.error(`[Pixi'VN] Ticker ${tickerId} not found`);
675
+ return;
676
+ }
677
+ return new ticker(args, duration, priority);
678
+ } catch (e) {
679
+ console.error(`[Pixi'VN] Error while getting Ticker ${tickerId}`, e);
680
+ return;
681
+ }
682
+ }
683
+
684
+ // src/types/CloseType.ts
685
+ var Close = "close";
686
+
687
+ // src/classes/ChoiceMenuOption.ts
688
+ var ChoiceMenuOption = class {
689
+ /**
690
+ * @param text Text to be displayed in the menu
691
+ * @param label Label to be opened when the option is selected or the id of the label
692
+ * @param props Properties to be passed to the label and olther parameters that you can use when get all the choice menu options. It be converted to a JSON string, so it cannot contain functions or classes.
693
+ * @param type Type of the label to be opened. @default "call"
694
+ */
695
+ constructor(text, label, props, type = "call") {
696
+ /**
697
+ * Properties to be passed to the label and olther parameters that you can use when get all the choice menu options.
698
+ * @example
699
+ * ```tsx
700
+ * setChoiceMenuOptions([
701
+ * new ChoiceMenuOption("Hello", helloLabel, { disabled: true }),
702
+ * ])
703
+ * return <List>
704
+ * {getChoiceMenuOptions()?.map((item, index) => {
705
+ * return (
706
+ * <ChoiceButton
707
+ * disabled={item.props.disabled}
708
+ * onClick={() => {
709
+ * afterSelectChoice(item)
710
+ * }}
711
+ * >
712
+ * {item.text}
713
+ * </ChoiceButton>
714
+ * )
715
+ * })}
716
+ * </List>
717
+ * ```
718
+ */
719
+ this.props = {};
720
+ this.text = text;
721
+ this._label = label;
722
+ this.type = type;
723
+ if (props) {
724
+ this.props = props;
725
+ }
726
+ }
727
+ /**
728
+ * Label to be opened when the option is selected
729
+ */
730
+ get label() {
731
+ let label = this._label;
732
+ if (typeof label === "string") {
733
+ let res = getLabelById(label);
734
+ if (res) {
735
+ label = res;
736
+ } else {
737
+ console.error(`Label ${label} not found, so it will be closed`);
738
+ label = newCloseLabel();
739
+ }
740
+ }
741
+ return label;
742
+ }
743
+ };
744
+ var ChoiceMenuOptionClose = class {
745
+ /**
746
+ * @param text Text to be displayed in the menu
747
+ * @param closeCurrentLabel If true, the current label will be closed. @default false
748
+ */
749
+ constructor(text, closeCurrentLabel = false) {
750
+ /**
751
+ * Label to be opened when the option is selected
752
+ */
753
+ this.label = newCloseLabel();
754
+ /**
755
+ * Type of the label to be opened
756
+ */
757
+ this.type = Close;
758
+ /**
759
+ * Properties to be passed to the label and olther parameters that you can use when get all the choice menu options.
760
+ * @example
761
+ * ```tsx
762
+ * setChoiceMenuOptions([
763
+ * new ChoiceMenuOption("Hello", helloLabel, { disabled: true }),
764
+ * ])
765
+ * return <List>
766
+ * {getChoiceMenuOptions()?.map((item, index) => {
767
+ * return (
768
+ * <ChoiceButton
769
+ * disabled={item.props.disabled}
770
+ * onClick={() => {
771
+ * afterSelectChoice(item)
772
+ * }}
773
+ * >
774
+ * {item.text}
775
+ * </ChoiceButton>
776
+ * )
777
+ * })}
778
+ * </List>
779
+ * ```
780
+ */
781
+ this.props = {};
782
+ this.text = text;
783
+ this.closeCurrentLabel = closeCurrentLabel;
784
+ }
785
+ };
786
+
787
+ // src/functions/DialogueUtility.ts
788
+ function setDialogue(props) {
789
+ let text = "";
790
+ let character = void 0;
791
+ let dialogue;
792
+ if (typeof props === "string") {
793
+ text = props;
794
+ dialogue = new DialogueBaseModel(text, character);
795
+ } else if (!(props instanceof DialogueBaseModel)) {
796
+ text = props.text;
797
+ if (props.character) {
798
+ if (typeof props.character === "string") {
799
+ character = props.character;
800
+ } else {
801
+ character = props.character.id;
802
+ }
803
+ }
804
+ dialogue = new DialogueBaseModel(text, character);
805
+ } else {
806
+ dialogue = props;
807
+ }
808
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY, dialogue);
809
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY, GameStepManager.lastStepIndex);
810
+ }
811
+ function getDialogue() {
812
+ return GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY);
813
+ }
814
+ function clearDialogue() {
815
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY, void 0);
816
+ }
817
+ function setChoiceMenuOptions(options) {
818
+ let value = options.map((option) => {
819
+ if (option instanceof ChoiceMenuOptionClose) {
820
+ return {
821
+ text: option.text,
822
+ type: Close,
823
+ closeCurrentLabel: option.closeCurrentLabel
824
+ };
825
+ }
826
+ return __spreadProps(__spreadValues({}, option), {
827
+ label: option.label.id
828
+ });
829
+ });
830
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, value);
831
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY, GameStepManager.lastStepIndex);
832
+ }
833
+ function getChoiceMenuOptions() {
834
+ let d = GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY);
835
+ if (d) {
836
+ let options = [];
837
+ d.forEach((option, index) => {
838
+ if (option.type === Close) {
839
+ let itemLabel = newCloseLabel(index);
840
+ let choice = new ChoiceMenuOptionClose(option.text, option.closeCurrentLabel);
841
+ choice.label = itemLabel;
842
+ options.push(choice);
843
+ return;
844
+ }
845
+ let label = getLabelById(option.label);
846
+ if (label) {
847
+ let itemLabel = new Label(label.id, label.steps, {
848
+ onStepStart: label.onStepStart,
849
+ choiseIndex: index
850
+ });
851
+ options.push(new ChoiceMenuOption(option.text, itemLabel, option.props, option.type));
852
+ }
853
+ });
854
+ return options;
855
+ }
856
+ return void 0;
857
+ }
858
+ function clearChoiceMenuOptions() {
859
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, void 0);
860
+ }
861
+
862
+ // src/classes/ticker/TickerBase.ts
863
+ var TickerBase = class {
864
+ /**
865
+ * @param args The arguments that you want to pass to the ticker.
866
+ * @param duration The duration of the ticker in seconds. If is undefined, the step will end only when the animation is finished (if the animation doesn't have a goal to reach then it won't finish). @default undefined
867
+ * @param priority The priority of the ticker. @default UPDATE_PRIORITY.NORMAL
868
+ */
869
+ constructor(args, duration, priority) {
870
+ /**
871
+ * Get the id of the ticker. This variable is used in the system to get the ticker by id, {@link geTickerInstanceById}
872
+ */
873
+ this.id = "ticker_id_not_set";
874
+ this.args = args;
875
+ this.duration = duration;
876
+ this.priority = priority;
877
+ this.id = this.constructor.prototype.id;
878
+ }
879
+ /**
880
+ * The method that will be called every frame.
881
+ * This method should be overridden and you can use GameWindowManager.addCanvasElement() to get the canvas element of the canvas, and edit them.
882
+ * @param _ticker The ticker that is calling this method
883
+ * @param _args The arguments that you passed when you added the ticker
884
+ * @param _tags The tags of the canvas elements that are connected to this ticker
885
+ * @param _tickerId The id of the ticker. You can use this to get the ticker from the {@link GameWindowManager.currentTickers}
886
+ */
887
+ fn(_ticker, _args, _tags, _tickerId) {
888
+ throw new Error("[Pixi'VN] The method TickerBase.fn() must be overridden");
889
+ }
890
+ };
891
+
892
+ // src/classes/ticker/FadeAlphaTicker.ts
893
+ var FadeAlphaTicker = class extends TickerBase {
894
+ fn(ticker, args, tags, tickerId) {
895
+ let type = args.type === void 0 ? "hide" : args.type;
896
+ let duration = args.duration === void 0 ? 1 : args.duration;
897
+ let speed = 1 / (duration * 60);
898
+ let limit = args.limit === void 0 ? type === "hide" ? 0 : 1 : args.limit;
899
+ let tagToRemoveAfter2 = args.tagToRemoveAfter || [];
900
+ if (typeof tagToRemoveAfter2 === "string") {
901
+ tagToRemoveAfter2 = [tagToRemoveAfter2];
902
+ }
903
+ if (type === "hide" && limit < 0) {
904
+ limit = 0;
905
+ }
906
+ if (type === "show" && limit > 1) {
907
+ limit = 1;
908
+ }
909
+ tags.filter((tag) => {
910
+ var _a;
911
+ let element = GameWindowManager.getCanvasElement(tag);
912
+ if (args.startOnlyIfHaveTexture) {
913
+ if (element && element instanceof Sprite && ((_a = element.texture) == null ? void 0 : _a.label) == "EMPTY") {
914
+ return false;
915
+ }
916
+ }
917
+ return true;
918
+ }).forEach((tag) => {
919
+ let element = GameWindowManager.getCanvasElement(tag);
920
+ if (element && element instanceof Container) {
921
+ if (type === "show" && element.alpha < limit) {
922
+ element.alpha += speed * ticker.deltaTime;
923
+ } else if (type === "hide" && element.alpha > limit) {
924
+ element.alpha -= speed * ticker.deltaTime;
925
+ }
926
+ if (type === "show" && element.alpha >= limit) {
927
+ element.alpha = limit;
928
+ GameWindowManager.onEndOfTicker(tag, this, tagToRemoveAfter2, tickerId);
929
+ } else if (type === "hide" && element.alpha <= limit) {
930
+ element.alpha = limit;
931
+ GameWindowManager.onEndOfTicker(tag, this, tagToRemoveAfter2, tickerId);
932
+ }
933
+ }
934
+ });
935
+ }
936
+ };
937
+ FadeAlphaTicker = __decorateClass([
938
+ tickerDecorator()
939
+ ], FadeAlphaTicker);
940
+
941
+ // src/functions/TickerUtility.ts
942
+ function updateTickerProgression(args, propertyName, progression, valueConvert) {
943
+ let limit = valueConvert && progression.limit ? valueConvert(progression.limit) : progression.limit;
944
+ if (args[propertyName] === void 0 || !progression || args[propertyName] === limit) {
945
+ return;
946
+ }
947
+ if (typeof args[propertyName] === "number") {
948
+ if (progression.type === "linear") {
949
+ args[propertyName] = getLinearProgression(args[propertyName], progression);
950
+ } else if (progression.type === "exponential") {
951
+ args[propertyName] = getExponentialProgression(args[propertyName], progression);
952
+ }
953
+ } else if (args[propertyName] !== void 0 && typeof args[propertyName] === "object" && args[propertyName].haveOwnProperty("x") && args[propertyName].haveOwnProperty("y") && typeof args[propertyName].x === "number" && typeof args[propertyName].y === "number") {
954
+ if (progression.type === "linear") {
955
+ args[propertyName].x = getLinearProgression(args[propertyName].x, progression);
956
+ args[propertyName].y = getLinearProgression(args[propertyName].y, progression);
957
+ } else if (progression.type === "exponential") {
958
+ args[propertyName].x = getExponentialProgression(args[propertyName].x, progression);
959
+ args[propertyName].y = getExponentialProgression(args[propertyName].y, progression);
960
+ }
961
+ }
962
+ }
963
+ function getLinearProgression(number, progression, valueConvert) {
964
+ let limit = valueConvert && progression.limit ? valueConvert(progression.limit) : progression.limit;
965
+ let amt = valueConvert ? valueConvert(progression.amt) : progression.amt;
966
+ if (limit !== void 0) {
967
+ if (number > limit && amt > 0) {
968
+ return limit;
969
+ } else if (number < limit && amt < 0) {
970
+ return limit;
971
+ }
972
+ }
973
+ return number + amt;
974
+ }
975
+ function getExponentialProgression(number, progression, valueConvert) {
976
+ let limit = valueConvert && progression.limit ? valueConvert(progression.limit) : progression.limit;
977
+ if (limit !== void 0) {
978
+ if (number > limit && progression.percentage > 0) {
979
+ return limit;
980
+ } else if (number < limit && progression.percentage < 0) {
981
+ return limit;
982
+ }
983
+ }
984
+ return number + number * progression.percentage;
985
+ }
986
+
987
+ // src/classes/ticker/MoveTicker.ts
988
+ var MoveTicker = class extends TickerBase {
989
+ fn(ticker, args, tags, tickerId) {
990
+ let xSpeed = 1;
991
+ let ySpeed = 1;
992
+ if (args.speed) {
993
+ if (typeof args.speed === "number") {
994
+ xSpeed = this.speedConvert(args.speed);
995
+ ySpeed = this.speedConvert(args.speed);
996
+ } else {
997
+ xSpeed = this.speedConvert(args.speed.x);
998
+ ySpeed = this.speedConvert(args.speed.y);
999
+ }
1000
+ }
1001
+ let destination = args.destination;
1002
+ let tagToRemoveAfter2 = args.tagToRemoveAfter || [];
1003
+ if (typeof tagToRemoveAfter2 === "string") {
1004
+ tagToRemoveAfter2 = [tagToRemoveAfter2];
1005
+ }
1006
+ tags.filter((tag) => {
1007
+ var _a;
1008
+ let element = GameWindowManager.getCanvasElement(tag);
1009
+ if (args.startOnlyIfHaveTexture) {
1010
+ if (element && element instanceof Sprite && ((_a = element.texture) == null ? void 0 : _a.label) == "EMPTY") {
1011
+ return false;
1012
+ }
1013
+ }
1014
+ return true;
1015
+ }).forEach((tag) => {
1016
+ let element = GameWindowManager.getCanvasElement(tag);
1017
+ if (element && element instanceof Container) {
1018
+ let xDistance = destination.x - element.x > 0 ? 1 : -1;
1019
+ if (xDistance != 0) {
1020
+ element.x += xDistance * xSpeed * ticker.deltaTime;
1021
+ let newDistance = destination.x - element.x;
1022
+ if (xDistance < 0 && newDistance > 0 || xDistance > 0 && newDistance < 0) {
1023
+ element.x = destination.x;
1024
+ }
1025
+ }
1026
+ let yDistance = destination.y - element.y > 0 ? 1 : -1;
1027
+ if (yDistance != 0) {
1028
+ element.y += yDistance * ySpeed * ticker.deltaTime;
1029
+ let newDistance = destination.y - element.y;
1030
+ if (yDistance < 0 && newDistance > 0 || yDistance > 0 && newDistance < 0) {
1031
+ element.y = destination.y;
1032
+ }
1033
+ }
1034
+ if (element.x == destination.x && element.y == destination.y) {
1035
+ GameWindowManager.onEndOfTicker(tag, this, tagToRemoveAfter2, tickerId);
1036
+ }
1037
+ }
1038
+ });
1039
+ if (args.speedProgression)
1040
+ updateTickerProgression(args, "speed", args.speedProgression, this.speedConvert);
1041
+ }
1042
+ speedConvert(speed) {
1043
+ return speed / 6;
1044
+ }
1045
+ };
1046
+ MoveTicker = __decorateClass([
1047
+ tickerDecorator()
1048
+ ], MoveTicker);
1049
+ var RotateTicker = class extends TickerBase {
1050
+ fn(ticker, args, tags, tickerId) {
1051
+ let speed = this.speedConvert(args.speed === void 0 ? 1 : args.speed);
1052
+ let clockwise = args.clockwise === void 0 ? true : args.clockwise;
1053
+ let tagToRemoveAfter2 = args.tagToRemoveAfter || [];
1054
+ if (typeof tagToRemoveAfter2 === "string") {
1055
+ tagToRemoveAfter2 = [tagToRemoveAfter2];
1056
+ }
1057
+ tags.filter((tag) => {
1058
+ var _a;
1059
+ let element = GameWindowManager.getCanvasElement(tag);
1060
+ if (args.startOnlyIfHaveTexture) {
1061
+ if (element && element instanceof Sprite && ((_a = element.texture) == null ? void 0 : _a.label) == "EMPTY") {
1062
+ return false;
1063
+ }
1064
+ }
1065
+ return true;
1066
+ }).forEach((tag) => {
1067
+ let element = GameWindowManager.getCanvasElement(tag);
1068
+ if (element && element instanceof Container) {
1069
+ if (clockwise)
1070
+ element.rotation += speed * ticker.deltaTime;
1071
+ else
1072
+ element.rotation -= speed * ticker.deltaTime;
1073
+ if (speed < 1e-5 && !(args.speedProgression && args.speedProgression.type == "linear" && args.speedProgression.amt != 0)) {
1074
+ GameWindowManager.onEndOfTicker(tag, this, tagToRemoveAfter2, tickerId);
1075
+ }
1076
+ }
1077
+ });
1078
+ if (args.speedProgression)
1079
+ updateTickerProgression(args, "speed", args.speedProgression, this.speedConvert);
1080
+ }
1081
+ speedConvert(speed) {
1082
+ return speed / 60;
1083
+ }
1084
+ };
1085
+ RotateTicker = __decorateClass([
1086
+ tickerDecorator()
1087
+ ], RotateTicker);
1088
+ var ZoomTicker = class extends TickerBase {
1089
+ fn(ticker, args, tags, tickerId) {
1090
+ let xSpeed = 0.1;
1091
+ let ySpeed = 0.1;
1092
+ if (args.speed) {
1093
+ if (typeof args.speed === "number") {
1094
+ xSpeed = this.speedConvert(args.speed);
1095
+ ySpeed = this.speedConvert(args.speed);
1096
+ } else {
1097
+ xSpeed = this.speedConvert(args.speed.x);
1098
+ ySpeed = this.speedConvert(args.speed.y);
1099
+ }
1100
+ }
1101
+ let tagToRemoveAfter2 = args.tagToRemoveAfter || [];
1102
+ if (typeof tagToRemoveAfter2 === "string") {
1103
+ tagToRemoveAfter2 = [tagToRemoveAfter2];
1104
+ }
1105
+ let type = args.type || "zoom";
1106
+ let xLimit = type === "zoom" ? Infinity : 0;
1107
+ let yLimit = type === "zoom" ? Infinity : 0;
1108
+ if (args.limit) {
1109
+ if (typeof args.limit === "number") {
1110
+ xLimit = args.limit;
1111
+ yLimit = args.limit;
1112
+ } else {
1113
+ xLimit = args.limit.x;
1114
+ yLimit = args.limit.y;
1115
+ }
1116
+ }
1117
+ tags.filter((tag) => {
1118
+ var _a;
1119
+ let element = GameWindowManager.getCanvasElement(tag);
1120
+ if (args.startOnlyIfHaveTexture) {
1121
+ if (element && element instanceof Sprite && ((_a = element.texture) == null ? void 0 : _a.label) == "EMPTY") {
1122
+ return false;
1123
+ }
1124
+ }
1125
+ return true;
1126
+ }).forEach((tag) => {
1127
+ let element = GameWindowManager.getCanvasElement(tag);
1128
+ if (element && element instanceof Container) {
1129
+ if (type === "zoom" && (element.scale.x < xLimit || element.scale.y < yLimit)) {
1130
+ element.scale.x += xSpeed * ticker.deltaTime;
1131
+ element.scale.y += ySpeed * ticker.deltaTime;
1132
+ } else if (type === "unzoom" && (element.scale.x > xLimit || element.scale.y > yLimit)) {
1133
+ element.scale.x -= xSpeed * ticker.deltaTime;
1134
+ element.scale.y -= ySpeed * ticker.deltaTime;
1135
+ }
1136
+ if (type === "zoom") {
1137
+ if (element.scale.x > xLimit) {
1138
+ element.scale.x = xLimit;
1139
+ }
1140
+ if (element.scale.y > yLimit) {
1141
+ element.scale.y = yLimit;
1142
+ }
1143
+ if (element.scale.x >= xLimit && element.scale.y >= yLimit) {
1144
+ element.scale.x = xLimit;
1145
+ element.scale.y = yLimit;
1146
+ this.onEndOfTicker(tag, tickerId, element, tagToRemoveAfter2);
1147
+ }
1148
+ } else if (type === "unzoom") {
1149
+ if (element.scale.x < xLimit) {
1150
+ element.scale.x = xLimit;
1151
+ }
1152
+ if (element.scale.y < yLimit) {
1153
+ element.scale.y = yLimit;
1154
+ }
1155
+ if (element.scale.x <= xLimit && element.scale.y <= yLimit) {
1156
+ element.scale.x = xLimit;
1157
+ element.scale.y = yLimit;
1158
+ this.onEndOfTicker(tag, tickerId, element, tagToRemoveAfter2);
1159
+ }
1160
+ }
1161
+ if (xSpeed < 1e-5 && ySpeed < 1e-5 && !(args.speedProgression && args.speedProgression.type == "linear" && args.speedProgression.amt != 0)) {
1162
+ this.onEndOfTicker(tag, tickerId, element, tagToRemoveAfter2);
1163
+ }
1164
+ }
1165
+ });
1166
+ if (args.speedProgression)
1167
+ updateTickerProgression(args, "speed", args.speedProgression, this.speedConvert);
1168
+ }
1169
+ speedConvert(speed) {
1170
+ return speed / 60;
1171
+ }
1172
+ onEndOfTicker(tag, tickerId, _element, tagToRemoveAfter2) {
1173
+ GameWindowManager.onEndOfTicker(tag, this, tagToRemoveAfter2, tickerId);
1174
+ }
1175
+ };
1176
+ ZoomTicker = __decorateClass([
1177
+ tickerDecorator()
1178
+ ], ZoomTicker);
1179
+
1180
+ // src/constants.ts
1181
+ var Repeat = "repeat";
1182
+
1183
+ // src/functions/ExportUtility.ts
1184
+ function createExportableElement(element) {
1185
+ try {
1186
+ let elementString = JSON.stringify(element);
1187
+ return JSON.parse(elementString);
1188
+ } catch (e) {
1189
+ console.error("[Pixi'VN] Error creating exportable element", e);
1190
+ throw new Error("[Pixi'VN] Error creating exportable element");
1191
+ }
1192
+ }
1193
+
1194
+ // src/functions/DiffUtility.ts
1195
+ function restoreDeepDiffChanges(data, differences) {
1196
+ let result = createExportableElement(data);
1197
+ differences.forEach((diff2) => {
1198
+ let dataToEdit = result;
1199
+ if (diff2.path && diff2.path.length > 0) {
1200
+ diff2.path.forEach((path, index) => {
1201
+ if (diff2.path && index === diff2.path.length - 1) {
1202
+ if (diff2.kind === "E" || diff2.kind === "D") {
1203
+ dataToEdit[path] = diff2.lhs;
1204
+ } else if (diff2.kind === "N") {
1205
+ if (Number.isInteger(path)) {
1206
+ if (Array.isArray(dataToEdit)) {
1207
+ dataToEdit.splice(path, 1);
1208
+ }
1209
+ } else if (typeof path === "string") {
1210
+ delete dataToEdit[path];
1211
+ }
1212
+ } else if (diff2.kind === "A") {
1213
+ let index2 = diff2.index;
1214
+ if (diff2.item.kind === "N") {
1215
+ dataToEdit[path].splice(index2, 1);
1216
+ } else if (diff2.item.kind === "E" || diff2.item.kind === "D") {
1217
+ dataToEdit[path][index2] = diff2.item.lhs;
1218
+ } else if (diff2.item.kind === "A") {
1219
+ console.warn("[Pixi'VN] Nested array found, skipping diff", diff2);
1220
+ } else {
1221
+ console.warn("[Pixi'VN] No array found, skipping diff", diff2);
1222
+ }
1223
+ }
1224
+ } else {
1225
+ dataToEdit = dataToEdit[path];
1226
+ }
1227
+ });
1228
+ } else {
1229
+ console.warn("[Pixi'VN] No path found, skipping diff", diff2);
1230
+ }
1231
+ });
1232
+ return result;
1233
+ }
1234
+
1235
+ // src/managers/StorageManager.ts
1236
+ var _GameStorageManager = class _GameStorageManager {
1237
+ constructor() {
1238
+ }
1239
+ static get keysSystem() {
1240
+ return {
1241
+ CURRENT_DIALOGUE_MEMORY_KEY: "___current_dialogue_memory___",
1242
+ LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY: "___last_dialogue_added_in_step_memory___",
1243
+ CURRENT_MENU_OPTIONS_MEMORY_KEY: "___current_menu_options_memory___",
1244
+ LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY: "___last_menu_options_added_in_step_memory___",
1245
+ CHARACTER_CATEGORY_KEY: "___character___",
1246
+ FLAGS_CATEGORY_KEY: "___flags___"
1247
+ };
1248
+ }
1249
+ /**
1250
+ * Set a variable in the storage
1251
+ * @param key The key of the variable
1252
+ * @param value The value of the variable. If undefined, the variable will be removed
1253
+ * @returns
1254
+ */
1255
+ static setVariable(key, value) {
1256
+ key = key.toLowerCase();
1257
+ if (value === void 0 || value === null) {
1258
+ if (_GameStorageManager.storage.hasOwnProperty(key)) {
1259
+ delete _GameStorageManager.storage[key];
1260
+ }
1261
+ return;
1262
+ }
1263
+ _GameStorageManager.storage[key] = value;
1264
+ }
1265
+ /**
1266
+ * Get a variable from the storage
1267
+ * @param key The key of the variable
1268
+ * @returns The value of the variable. If the variable does not exist, it will return undefined
1269
+ */
1270
+ static getVariable(key) {
1271
+ key = key.toLowerCase();
1272
+ if (_GameStorageManager.storage.hasOwnProperty(key)) {
1273
+ return _GameStorageManager.storage[key];
1274
+ }
1275
+ return void 0;
1276
+ }
1277
+ /**
1278
+ * Remove a variable from the storage
1279
+ * @param key The key of the variable
1280
+ * @returns
1281
+ */
1282
+ static removeVariable(key) {
1283
+ key = key.toLowerCase();
1284
+ if (_GameStorageManager.storage.hasOwnProperty(key)) {
1285
+ delete _GameStorageManager.storage[key];
1286
+ }
1287
+ }
1288
+ /**
1289
+ * Clear the storage and the oidsUsed
1290
+ * @returns
1291
+ */
1292
+ static clear() {
1293
+ _GameStorageManager.storage = {};
1294
+ }
1295
+ static exportJson() {
1296
+ return JSON.stringify(this.export());
1297
+ }
1298
+ static export() {
1299
+ return createExportableElement(_GameStorageManager.storage);
1300
+ }
1301
+ static importJson(dataString) {
1302
+ _GameStorageManager.import(JSON.parse(dataString));
1303
+ }
1304
+ static import(data) {
1305
+ _GameStorageManager.clear();
1306
+ try {
1307
+ if (data) {
1308
+ _GameStorageManager.storage = data;
1309
+ } else {
1310
+ console.warn("[Pixi'VN] No storage data found");
1311
+ }
1312
+ } catch (e) {
1313
+ console.error("[Pixi'VN] Error importing data", e);
1314
+ }
1315
+ }
1316
+ };
1317
+ _GameStorageManager.storage = {};
1318
+ var GameStorageManager = _GameStorageManager;
1319
+
1320
+ // src/functions/EasterEgg.ts
1321
+ function asciiArtLog() {
1322
+ console.info(`
1323
+ ____ _ _ ___ ___ _
1324
+ | _ \\(_)_ _(_| ) \\ / / \\ | |
1325
+ | |_) | \\ \\/ / |/ \\ \\ / /| \\| |
1326
+ | __/| |> <| | \\ V / | |\\ |
1327
+ |_| |_/_/\\_\\_| \\_/ |_| \\_|
1328
+ `);
1329
+ }
1330
+
1331
+ // src/types/ticker/TagToRemoveAfterType.ts
1332
+ var tagToRemoveAfter = "tagToRemoveAfter";
1333
+
1334
+ // src/managers/WindowManager.ts
1335
+ var _GameWindowManager = class _GameWindowManager {
1336
+ constructor() {
1337
+ }
1338
+ /**
1339
+ * The PIXI Application instance.
1340
+ * It not recommended to use this property directly.
1341
+ */
1342
+ static get app() {
1343
+ if (!_GameWindowManager._app) {
1344
+ throw new Error("[Pixi'VN] GameWindowManager.app is undefined");
1345
+ }
1346
+ return _GameWindowManager._app;
1347
+ }
1348
+ /**
1349
+ * If the manager is initialized.
1350
+ */
1351
+ static get isInitialized() {
1352
+ return _GameWindowManager._isInitialized;
1353
+ }
1354
+ static get screen() {
1355
+ return _GameWindowManager.app.screen;
1356
+ }
1357
+ /**
1358
+ * Initialize the PIXI Application and the interface div.
1359
+ * This method should be called before any other method.
1360
+ * @param element The html element where I will put the canvas. Example: document.body
1361
+ * @param width The width of the canvas
1362
+ * @param height The height of the canvas
1363
+ * @param options The options of PIXI Application
1364
+ * @example
1365
+ * ```typescript
1366
+ * const body = document.body
1367
+ * if (!body) {
1368
+ * throw new Error('body element not found')
1369
+ * }
1370
+ * await GameWindowManager.initialize(body, 1920, 1080, {
1371
+ * backgroundColor: "#303030"
1372
+ * })
1373
+ * ```
1374
+ */
1375
+ static initialize(element, width, height, options) {
1376
+ return __async(this, null, function* () {
1377
+ _GameWindowManager.canvasWidth = width;
1378
+ _GameWindowManager.canvasHeight = height;
1379
+ _GameWindowManager._app = new Application();
1380
+ return _GameWindowManager.app.init(__spreadValues({
1381
+ resolution: window.devicePixelRatio || 1,
1382
+ autoDensity: true,
1383
+ width,
1384
+ height
1385
+ }, options)).then(() => {
1386
+ _GameWindowManager._isInitialized = true;
1387
+ this.addCanvasIntoHTMLElement(element);
1388
+ window.addEventListener("resize", _GameWindowManager.resize);
1389
+ _GameWindowManager.resize();
1390
+ asciiArtLog();
1391
+ });
1392
+ });
1393
+ }
1394
+ /**
1395
+ * Add the canvas into a html element.
1396
+ * @param element it is the html element where I will put the canvas. Example: document.body
1397
+ */
1398
+ static addCanvasIntoHTMLElement(element) {
1399
+ if (_GameWindowManager.isInitialized) {
1400
+ element.appendChild(_GameWindowManager.app.canvas);
1401
+ } else {
1402
+ console.error("[Pixi'VN] GameWindowManager is not initialized");
1403
+ }
1404
+ }
1405
+ /**
1406
+ * Initialize the interface div and add it into a html element.
1407
+ * @param element it is the html element where I will put the interface div. Example: document.getElementById('root')
1408
+ * @example
1409
+ * ```tsx
1410
+ * const root = document.getElementById('root')
1411
+ * if (!root) {
1412
+ * throw new Error('root element not found')
1413
+ * }
1414
+ * GameWindowManager.initializeHTMLLayout(root)
1415
+ * const reactRoot = createRoot(GameWindowManager.htmlLayout)
1416
+ * reactRoot.render(
1417
+ * <App />
1418
+ * )
1419
+ * ```
1420
+ */
1421
+ static initializeHTMLLayout(element) {
1422
+ let div = document.createElement("div");
1423
+ div.style.position = "absolute";
1424
+ div.style.pointerEvents = "none";
1425
+ element.appendChild(div);
1426
+ _GameWindowManager.htmlLayout = div;
1427
+ _GameWindowManager.resize();
1428
+ }
1429
+ /* Resize Metods */
1430
+ /**
1431
+ * This method returns the scale of the screen.
1432
+ */
1433
+ static get screenScale() {
1434
+ let screenWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
1435
+ let screenHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
1436
+ return Math.min(screenWidth / _GameWindowManager.canvasWidth, screenHeight / _GameWindowManager.canvasHeight);
1437
+ }
1438
+ /**
1439
+ * This method returns the width of the screen enlarged by the scale.
1440
+ */
1441
+ static get screenWidth() {
1442
+ return Math.floor(_GameWindowManager.screenScale * _GameWindowManager.canvasWidth);
1443
+ }
1444
+ /**
1445
+ * This method returns the height of the screen enlarged by the scale.
1446
+ */
1447
+ static get screenHeight() {
1448
+ return Math.floor(_GameWindowManager.screenScale * _GameWindowManager.canvasHeight);
1449
+ }
1450
+ /**
1451
+ * This method returns the horizontal margin of the screen.
1452
+ */
1453
+ static get horizontalMargin() {
1454
+ let screenWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
1455
+ return (screenWidth - _GameWindowManager.screenWidth) / 2;
1456
+ }
1457
+ /**
1458
+ * This method returns the vertical margin of the screen.
1459
+ */
1460
+ static get verticalMargin() {
1461
+ let screenHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
1462
+ return (screenHeight - _GameWindowManager.screenHeight) / 2;
1463
+ }
1464
+ /**
1465
+ * This method is called when the screen is resized.
1466
+ */
1467
+ static resize() {
1468
+ if (_GameWindowManager.isInitialized) {
1469
+ let style = _GameWindowManager.app.canvas.style;
1470
+ style.width = `${_GameWindowManager.screenWidth}px`;
1471
+ style.height = `${_GameWindowManager.screenHeight}px`;
1472
+ style.marginLeft = `${_GameWindowManager.horizontalMargin}px`;
1473
+ style.marginRight = `${_GameWindowManager.horizontalMargin}px`;
1474
+ style.marginTop = `${_GameWindowManager.verticalMargin}px`;
1475
+ style.marginBottom = `${_GameWindowManager.verticalMargin}px`;
1476
+ }
1477
+ if (_GameWindowManager.htmlLayout) {
1478
+ _GameWindowManager.htmlLayout.style.width = `${_GameWindowManager.screenWidth}px`;
1479
+ _GameWindowManager.htmlLayout.style.height = `${_GameWindowManager.screenHeight}px`;
1480
+ _GameWindowManager.htmlLayout.style.marginLeft = `${_GameWindowManager.horizontalMargin}px`;
1481
+ _GameWindowManager.htmlLayout.style.marginRight = `${_GameWindowManager.horizontalMargin}px`;
1482
+ _GameWindowManager.htmlLayout.style.marginTop = `${_GameWindowManager.verticalMargin}px`;
1483
+ _GameWindowManager.htmlLayout.style.marginBottom = `${_GameWindowManager.verticalMargin}px`;
1484
+ }
1485
+ }
1486
+ /* Edit Canvas Elements Methods */
1487
+ /**
1488
+ * This is a dictionary that contains all Canvas Elements of Canvas, currently.
1489
+ */
1490
+ static get currentCanvasElements() {
1491
+ return _GameWindowManager._children;
1492
+ }
1493
+ /**
1494
+ * Add a canvas element to the canvas.
1495
+ * If there is a canvas element with the same tag, it will be removed.
1496
+ * @param tag The tag of the canvas element.
1497
+ * @param canvasElement The canvas elements to be added.
1498
+ * @example
1499
+ * ```typescript
1500
+ * const texture = await Assets.load('https://pixijs.com/assets/bunny.png');
1501
+ * const sprite = CanvasSprite.from(texture);
1502
+ * GameWindowManager.addCanvasElement("bunny", sprite);
1503
+ * ```
1504
+ */
1505
+ static addCanvasElement(tag, canvasElement) {
1506
+ if (_GameWindowManager._children[tag]) {
1507
+ _GameWindowManager.removeCanvasElement(tag);
1508
+ }
1509
+ _GameWindowManager.app.stage.addChild(canvasElement);
1510
+ _GameWindowManager._children[tag] = canvasElement;
1511
+ _GameWindowManager.childrenTagsOrder.push(tag);
1512
+ }
1513
+ /**
1514
+ * Remove a canvas element from the canvas.
1515
+ * And remove all tickers that are not connected to any canvas element.
1516
+ * @param tags The tag of the canvas element to be removed.
1517
+ * @returns
1518
+ * @example
1519
+ * ```typescript
1520
+ * GameWindowManager.removeCanvasElement("bunny");
1521
+ * ```
1522
+ */
1523
+ static removeCanvasElement(tags) {
1524
+ if (typeof tags === "string") {
1525
+ tags = [tags];
1526
+ }
1527
+ tags.forEach((tag) => {
1528
+ if (_GameWindowManager._children[tag]) {
1529
+ _GameWindowManager.app.stage.removeChild(_GameWindowManager._children[tag]);
1530
+ delete _GameWindowManager._children[tag];
1531
+ _GameWindowManager.removeTickerByCanvasElement(tag);
1532
+ }
1533
+ });
1534
+ _GameWindowManager.childrenTagsOrder = _GameWindowManager.childrenTagsOrder.filter((t) => !tags.includes(t));
1535
+ }
1536
+ /**
1537
+ * Get a canvas element by the tag.
1538
+ * @param tag The tag of the canvas element.
1539
+ * @returns The canvas element.
1540
+ * @example
1541
+ * ```typescript
1542
+ * const sprite = GameWindowManager.getCanvasElement<CanvasSprite>("bunny");
1543
+ * ```
1544
+ */
1545
+ static getCanvasElement(tag) {
1546
+ return _GameWindowManager._children[tag];
1547
+ }
1548
+ /**
1549
+ * Check if a DisplayObject is on the canvas.
1550
+ * @param pixiElement The DisplayObject to be checked.
1551
+ * @returns If the DisplayObject is on the canvas.
1552
+ */
1553
+ static canvasElementIsOnCanvas(pixiElement) {
1554
+ return _GameWindowManager.app.stage.children.includes(pixiElement);
1555
+ }
1556
+ /**
1557
+ * Remove all canvas elements from the canvas.
1558
+ * And remove all tickers that are not connected to any canvas element.
1559
+ */
1560
+ static removeCanvasElements() {
1561
+ _GameWindowManager.app.stage.removeChildren();
1562
+ _GameWindowManager._children = {};
1563
+ _GameWindowManager.childrenTagsOrder = [];
1564
+ _GameWindowManager.removeAllTickers();
1565
+ }
1566
+ /**
1567
+ * Edit the tag of a canvas element.
1568
+ * @param oldTag The old tag of the canvas element.
1569
+ * @param newTag The new tag of the canvas element.
1570
+ */
1571
+ static editCanvasElementTag(oldTag, newTag) {
1572
+ if (_GameWindowManager._children[oldTag]) {
1573
+ _GameWindowManager._children[newTag] = _GameWindowManager._children[oldTag];
1574
+ delete _GameWindowManager._children[oldTag];
1575
+ }
1576
+ if (_GameWindowManager._currentTickersSteps[oldTag]) {
1577
+ _GameWindowManager._currentTickersSteps[newTag] = _GameWindowManager._currentTickersSteps[oldTag];
1578
+ delete _GameWindowManager._currentTickersSteps[oldTag];
1579
+ }
1580
+ for (let id in _GameWindowManager._currentTickers) {
1581
+ let ticker = _GameWindowManager._currentTickers[id];
1582
+ if (ticker.canvasElementTags.includes(oldTag)) {
1583
+ ticker.canvasElementTags = ticker.canvasElementTags.map((t) => t === oldTag ? newTag : t);
1584
+ if (ticker.args.hasOwnProperty(tagToRemoveAfter)) {
1585
+ let tagToRemoveAfter2 = ticker.args.tagToRemoveAfter;
1586
+ if (typeof tagToRemoveAfter2 === "string") {
1587
+ tagToRemoveAfter2 = [tagToRemoveAfter2];
1588
+ }
1589
+ if (Array.isArray(tagToRemoveAfter2)) {
1590
+ ticker.args.tagToRemoveAfter = tagToRemoveAfter2.map((t) => t === oldTag ? newTag : t);
1591
+ }
1592
+ }
1593
+ }
1594
+ }
1595
+ for (let timeout in _GameWindowManager._currentTickersTimeouts) {
1596
+ let TickerTimeout = _GameWindowManager._currentTickersTimeouts[timeout];
1597
+ if (TickerTimeout.tags.includes(oldTag)) {
1598
+ TickerTimeout.tags = TickerTimeout.tags.map((t) => t === oldTag ? newTag : t);
1599
+ }
1600
+ }
1601
+ }
1602
+ /** Edit Tickers Methods */
1603
+ /**
1604
+ * Currently tickers that are running.
1605
+ */
1606
+ static get currentTickers() {
1607
+ return _GameWindowManager._currentTickers;
1608
+ }
1609
+ static get currentTickersList() {
1610
+ return Object.values(_GameWindowManager._currentTickers);
1611
+ }
1612
+ static get currentTickersWithoutCreatedBySteps() {
1613
+ return Object.fromEntries(Object.entries(_GameWindowManager._currentTickers).filter(([_, ticker]) => !ticker.createdByTicketStepsId));
1614
+ }
1615
+ /**
1616
+ * The steps of the tickers
1617
+ */
1618
+ static get currentTickersSteps() {
1619
+ return _GameWindowManager._currentTickersSteps;
1620
+ }
1621
+ static generateTickerId(tickerData) {
1622
+ try {
1623
+ return sha1(JSON.stringify(tickerData)).toString() + "_" + Math.random().toString(36).substring(7);
1624
+ } catch (e) {
1625
+ throw new Error(`[Pixi'VN] Error to generate ticker id: ${e}`);
1626
+ }
1627
+ }
1628
+ /**
1629
+ * Run a ticker. You can run multiple addTicker with the same tag and different tickerClasses.
1630
+ * If you run a ticker with the same tag and tickerClass, the old ticker will be removed.
1631
+ * If already exists a sequence of tickers with the same tag, it will be removed.
1632
+ * @param canvasEslementTag The tag of the canvas element that will use the ticker.
1633
+ * @param ticker The ticker class to be run.
1634
+ * @param args The arguments to be used in the ticker.
1635
+ * @param duration The time to be used in the ticker. This number is in seconds. If it is undefined, the ticker will run forever.
1636
+ * @param priority The priority to be used in the ticker.
1637
+ * @returns
1638
+ * @example
1639
+ * ```typescript
1640
+ * GameWindowManager.addTicker("alien", new RotateTicker({ speed: 0.2 }))
1641
+ * ```
1642
+ */
1643
+ static addTicker(canvasElementTag, ticker) {
1644
+ let tickerId = ticker.id;
1645
+ if (typeof canvasElementTag === "string") {
1646
+ canvasElementTag = [canvasElementTag];
1647
+ }
1648
+ if (!geTickerInstanceById(tickerId, ticker.args, ticker.duration, ticker.priority)) {
1649
+ console.error(`[Pixi'VN] Ticker ${tickerId} not found`);
1650
+ return;
1651
+ }
1652
+ let tickerHistory = {
1653
+ fn: () => {
1654
+ },
1655
+ id: tickerId,
1656
+ args: createExportableElement(ticker.args),
1657
+ canvasElementTags: canvasElementTag,
1658
+ priority: ticker.priority,
1659
+ duration: ticker.duration
1660
+ };
1661
+ let id = _GameWindowManager.generateTickerId(tickerHistory);
1662
+ _GameWindowManager.pushTicker(id, tickerHistory, ticker);
1663
+ if (ticker.duration) {
1664
+ let timeout = setTimeout(() => {
1665
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
1666
+ let tickerTimeoutInfo = _GameWindowManager._currentTickersTimeouts[timeout.toString()];
1667
+ if (tickerTimeoutInfo) {
1668
+ _GameWindowManager.removeTicker(id);
1669
+ }
1670
+ }, ticker.duration * 1e3);
1671
+ _GameWindowManager.addTickerTimeoutInfo(canvasElementTag, tickerId, timeout.toString(), true);
1672
+ }
1673
+ }
1674
+ static pushTicker(id, tickerData, ticker) {
1675
+ _GameWindowManager.removeAssociationBetweenTickerCanvasElement(tickerData.canvasElementTags, ticker);
1676
+ _GameWindowManager._currentTickers[id] = tickerData;
1677
+ tickerData.fn = (t) => {
1678
+ let data = _GameWindowManager._currentTickers[id];
1679
+ if (data) {
1680
+ ticker == null ? void 0 : ticker.fn(t, data.args, data.canvasElementTags, id);
1681
+ }
1682
+ };
1683
+ _GameWindowManager.app.ticker.add(tickerData.fn, void 0, tickerData.priority);
1684
+ }
1685
+ /**
1686
+ * Run a sequence of tickers. If exists a ticker steps with the same tag, it will be removed.
1687
+ * @param tag The tag of canvas element that will use the tickers.
1688
+ * @param steps The steps of the tickers.
1689
+ * @param currentStepNumber The current step number. It is used to continue the sequence of tickers.
1690
+ * @returns
1691
+ * @example
1692
+ * ```typescript
1693
+ * GameWindowManager.addTickersSteps("alien", [
1694
+ * new RotateTicker({ speed: 0.1, clockwise: true }, 2), // 2 seconds
1695
+ * Pause(1), // 1 second
1696
+ * new RotateTicker({ speed: 0.2, clockwise: false }, 2),
1697
+ * Repeat,
1698
+ * ])
1699
+ * ```
1700
+ */
1701
+ static addTickersSteps(tag, steps, currentStepNumber = 0) {
1702
+ if (steps.length == 0) {
1703
+ console.warn("[Pixi'VN] The steps of the tickers is empty");
1704
+ return;
1705
+ }
1706
+ _GameWindowManager.removeTickerStepByCanvasElement(tag);
1707
+ _GameWindowManager._currentTickersSteps[tag] = {
1708
+ currentStepNumber,
1709
+ steps: steps.map((step) => {
1710
+ if (step === Repeat) {
1711
+ return step;
1712
+ }
1713
+ if (step.hasOwnProperty("type") && step.type === "pause") {
1714
+ return step;
1715
+ }
1716
+ let tickerId = step.id;
1717
+ return {
1718
+ ticker: tickerId,
1719
+ args: createExportableElement(step.args),
1720
+ duration: step.duration
1721
+ };
1722
+ })
1723
+ };
1724
+ _GameWindowManager.runTickersSteps(tag);
1725
+ }
1726
+ static restoneTickersSteps(data) {
1727
+ for (let tag in data) {
1728
+ let steps = data[tag];
1729
+ _GameWindowManager._currentTickersSteps[tag] = steps;
1730
+ _GameWindowManager.runTickersSteps(tag);
1731
+ }
1732
+ }
1733
+ static runTickersSteps(tag) {
1734
+ let step = _GameWindowManager._currentTickersSteps[tag].steps[_GameWindowManager._currentTickersSteps[tag].currentStepNumber];
1735
+ if (step === Repeat) {
1736
+ step = _GameWindowManager._currentTickersSteps[tag].steps[0];
1737
+ _GameWindowManager._currentTickersSteps[tag].currentStepNumber = 0;
1738
+ if (step === Repeat) {
1739
+ console.error("[Pixi'VN] TikersSteps has a RepeatType in the first step");
1740
+ return;
1741
+ }
1742
+ }
1743
+ if (step.hasOwnProperty("type") && step.type === "pause") {
1744
+ let timeout = setTimeout(() => {
1745
+ let tickerTimeoutInfo = _GameWindowManager._currentTickersTimeouts[timeout.toString()];
1746
+ if (tickerTimeoutInfo) {
1747
+ tickerTimeoutInfo.tags.forEach((tag2) => {
1748
+ _GameWindowManager.nextTickerStep(tag2);
1749
+ });
1750
+ }
1751
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
1752
+ }, step.duration * 1e3);
1753
+ _GameWindowManager.addTickerTimeoutInfo(tag, "steps", timeout.toString(), false);
1754
+ return;
1755
+ }
1756
+ let ticker = geTickerInstanceById(step.ticker, step.args, step.duration, step.priority);
1757
+ if (!ticker) {
1758
+ console.error(`[Pixi'VN] Ticker ${step.ticker} not found`);
1759
+ return;
1760
+ }
1761
+ let tickerName = ticker.id;
1762
+ let tickerHistory = {
1763
+ fn: () => {
1764
+ },
1765
+ id: tickerName,
1766
+ args: createExportableElement(ticker.args),
1767
+ canvasElementTags: [tag],
1768
+ priority: ticker.priority,
1769
+ duration: ticker.duration,
1770
+ createdByTicketStepsId: tag
1771
+ };
1772
+ let id = _GameWindowManager.generateTickerId(tickerHistory);
1773
+ _GameWindowManager.pushTicker(id, tickerHistory, ticker);
1774
+ if (ticker.duration) {
1775
+ let timeout = setTimeout(() => {
1776
+ let tickerTimeoutInfo = _GameWindowManager._currentTickersTimeouts[timeout.toString()];
1777
+ if (tickerTimeoutInfo) {
1778
+ _GameWindowManager.removeTicker(id);
1779
+ tickerTimeoutInfo.tags.forEach((tag2) => {
1780
+ _GameWindowManager.nextTickerStep(tag2);
1781
+ });
1782
+ }
1783
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
1784
+ }, ticker.duration * 1e3);
1785
+ _GameWindowManager.addTickerTimeoutInfo(tag, tickerName, timeout.toString(), false);
1786
+ }
1787
+ }
1788
+ static nextTickerStep(tag) {
1789
+ if (_GameWindowManager._currentTickersSteps[tag]) {
1790
+ let steps = _GameWindowManager._currentTickersSteps[tag];
1791
+ if (steps.currentStepNumber + 1 < steps.steps.length) {
1792
+ steps.currentStepNumber++;
1793
+ _GameWindowManager._currentTickersSteps[tag] = steps;
1794
+ _GameWindowManager.runTickersSteps(tag);
1795
+ } else {
1796
+ _GameWindowManager.removeTickerStepByCanvasElement(tag);
1797
+ }
1798
+ }
1799
+ }
1800
+ static onEndOfTicker(canvasElementTags, ticker, canvasElementTagsToDelete, tickerId) {
1801
+ let tickerData = _GameWindowManager._currentTickers[tickerId];
1802
+ _GameWindowManager.removeAssociationBetweenTickerCanvasElement(canvasElementTags, ticker);
1803
+ _GameWindowManager.removeCanvasElement(canvasElementTagsToDelete);
1804
+ if (tickerData) {
1805
+ _GameWindowManager.removeTicker(tickerId);
1806
+ if (tickerData.duration == void 0 && tickerData.createdByTicketStepsId) {
1807
+ _GameWindowManager.nextTickerStep(tickerData.createdByTicketStepsId);
1808
+ }
1809
+ }
1810
+ }
1811
+ /**
1812
+ * Remove a connection between a canvas element and a ticker.
1813
+ * And remove the ticker if there is no canvas element connected to it.
1814
+ * @param tags The tag of the canvas element that will use the ticker.
1815
+ * @param ticker The ticker class to be removed.
1816
+ * @example
1817
+ * ```typescript
1818
+ * GameWindowManager.removeAssociationBetweenTickerCanvasElement("alien", RotateTicker)
1819
+ * ```
1820
+ */
1821
+ static removeAssociationBetweenTickerCanvasElement(tags, ticker) {
1822
+ let tickerId;
1823
+ if (typeof ticker === "string") {
1824
+ tickerId = ticker;
1825
+ } else if (ticker instanceof TickerBase) {
1826
+ tickerId = ticker.id;
1827
+ } else {
1828
+ tickerId = ticker.prototype.id;
1829
+ }
1830
+ if (typeof tags === "string") {
1831
+ tags = [tags];
1832
+ }
1833
+ for (let id in _GameWindowManager._currentTickers) {
1834
+ let ticker2 = _GameWindowManager._currentTickers[id];
1835
+ if (ticker2.id === tickerId) {
1836
+ _GameWindowManager._currentTickers[id].canvasElementTags = ticker2.canvasElementTags.filter((e) => !tags.includes(e));
1837
+ }
1838
+ }
1839
+ for (let timeout in _GameWindowManager._currentTickersTimeouts) {
1840
+ let TickerTimeout = _GameWindowManager._currentTickersTimeouts[timeout];
1841
+ if (TickerTimeout.ticker === tickerId && TickerTimeout.canBeDeletedBeforeEnd) {
1842
+ _GameWindowManager._currentTickersTimeouts[timeout].tags = TickerTimeout.tags.filter((t) => !tags.includes(t));
1843
+ }
1844
+ }
1845
+ _GameWindowManager.removeTickersWithoutAssociatedCanvasElement();
1846
+ }
1847
+ /**
1848
+ * Remove all tickers that are not connected to any existing canvas element.
1849
+ */
1850
+ static removeTickersWithoutAssociatedCanvasElement() {
1851
+ for (let id in _GameWindowManager._currentTickers) {
1852
+ let ticker = _GameWindowManager._currentTickers[id];
1853
+ ticker.canvasElementTags = ticker.canvasElementTags.filter((e) => _GameWindowManager._children[e]);
1854
+ if (ticker.canvasElementTags.length === 0) {
1855
+ _GameWindowManager.removeTicker(id);
1856
+ }
1857
+ }
1858
+ for (let tag in _GameWindowManager._currentTickersSteps) {
1859
+ if (_GameWindowManager._children[tag] === void 0) {
1860
+ delete _GameWindowManager._currentTickersSteps[tag];
1861
+ }
1862
+ }
1863
+ Object.entries(_GameWindowManager._currentTickersTimeouts).forEach(([timeout, { tags }]) => {
1864
+ if (tags.length === 0) {
1865
+ _GameWindowManager.removeTickerTimeout(timeout);
1866
+ }
1867
+ });
1868
+ }
1869
+ static addTickerTimeoutInfo(tags, ticker, timeout, canBeDeletedBeforeEnd) {
1870
+ if (typeof tags === "string") {
1871
+ tags = [tags];
1872
+ }
1873
+ _GameWindowManager._currentTickersTimeouts[timeout] = {
1874
+ tags,
1875
+ ticker,
1876
+ canBeDeletedBeforeEnd
1877
+ };
1878
+ }
1879
+ static removeTickerTimeoutInfo(timeout) {
1880
+ if (typeof timeout !== "string") {
1881
+ timeout = timeout.toString();
1882
+ }
1883
+ if (_GameWindowManager._currentTickersTimeouts[timeout]) {
1884
+ delete _GameWindowManager._currentTickersTimeouts[timeout];
1885
+ }
1886
+ }
1887
+ static removeTickerTimeout(timeout) {
1888
+ if (typeof timeout !== "string") {
1889
+ timeout = timeout.toString();
1890
+ }
1891
+ clearTimeout(Number(timeout));
1892
+ _GameWindowManager.removeTickerTimeoutInfo(timeout);
1893
+ }
1894
+ static removeTickerTimeoutsByTag(tag, checkCanBeDeletedBeforeEnd) {
1895
+ for (let timeout in _GameWindowManager._currentTickersTimeouts) {
1896
+ let tagsWithoutTagToRemove = _GameWindowManager._currentTickersTimeouts[timeout].tags.filter((t) => t !== tag);
1897
+ if (tagsWithoutTagToRemove.length === 0) {
1898
+ let canBeDeletedBeforeEnd = _GameWindowManager._currentTickersTimeouts[timeout].canBeDeletedBeforeEnd;
1899
+ if (!checkCanBeDeletedBeforeEnd || canBeDeletedBeforeEnd) {
1900
+ _GameWindowManager.removeTickerTimeout(timeout);
1901
+ }
1902
+ } else {
1903
+ _GameWindowManager._currentTickersTimeouts[timeout].tags = tagsWithoutTagToRemove;
1904
+ }
1905
+ }
1906
+ }
1907
+ /**
1908
+ * Remove all tickers from the canvas.
1909
+ */
1910
+ static removeAllTickers() {
1911
+ _GameWindowManager._currentTickersSteps = {};
1912
+ Object.keys(_GameWindowManager._currentTickers).forEach((id) => {
1913
+ _GameWindowManager.removeTicker(id);
1914
+ });
1915
+ _GameWindowManager._currentTickers = {};
1916
+ for (let timeout in _GameWindowManager._currentTickersTimeouts) {
1917
+ _GameWindowManager.removeTickerTimeout(timeout);
1918
+ }
1919
+ }
1920
+ /**
1921
+ * Remove all tickers from a canvas element.
1922
+ * @param tag The tag of the canvas element that will use the ticker.
1923
+ */
1924
+ static removeTickerByCanvasElement(tag) {
1925
+ if (typeof tag === "string") {
1926
+ tag = [tag];
1927
+ }
1928
+ tag.forEach((tag2) => {
1929
+ for (let id in _GameWindowManager._currentTickers) {
1930
+ let ticker = _GameWindowManager._currentTickers[id];
1931
+ if (ticker.canvasElementTags.includes(tag2)) {
1932
+ _GameWindowManager.removeTicker(id);
1933
+ }
1934
+ }
1935
+ if (_GameWindowManager._currentTickersSteps[tag2]) {
1936
+ delete _GameWindowManager._currentTickersSteps[tag2];
1937
+ }
1938
+ _GameWindowManager.removeTickerTimeoutsByTag(tag2, false);
1939
+ delete _GameWindowManager._currentTickersSteps[tag2];
1940
+ });
1941
+ }
1942
+ static removeTickerStepByCanvasElement(tag) {
1943
+ if (_GameWindowManager._currentTickersSteps[tag]) {
1944
+ delete _GameWindowManager._currentTickersSteps[tag];
1945
+ }
1946
+ for (let id in _GameWindowManager._currentTickers) {
1947
+ let ticker = _GameWindowManager._currentTickers[id];
1948
+ if (ticker.createdByTicketStepsId === tag) {
1949
+ _GameWindowManager.removeTicker(id);
1950
+ }
1951
+ }
1952
+ }
1953
+ static removeTicker(tickerId) {
1954
+ let ticker = _GameWindowManager._currentTickers[tickerId];
1955
+ if (ticker) {
1956
+ if (ticker.args.hasOwnProperty(tagToRemoveAfter)) {
1957
+ let tagToRemoveAfter2 = ticker.args.tagToRemoveAfter;
1958
+ _GameWindowManager.removeCanvasElement(tagToRemoveAfter2);
1959
+ }
1960
+ _GameWindowManager.app.ticker.remove(ticker.fn);
1961
+ delete _GameWindowManager._currentTickers[tickerId];
1962
+ }
1963
+ }
1964
+ /**
1965
+ * Clear the canvas and the tickers.
1966
+ */
1967
+ static clear() {
1968
+ _GameWindowManager.removeCanvasElements();
1969
+ }
1970
+ /* Export and Import Methods */
1971
+ /**
1972
+ * Export the canvas and the tickers to a JSON string.
1973
+ * @returns The JSON string.
1974
+ */
1975
+ static exportJson() {
1976
+ return JSON.stringify(this.export());
1977
+ }
1978
+ /**
1979
+ * Export the canvas and the tickers to an object.
1980
+ * @returns The object.
1981
+ */
1982
+ static export() {
1983
+ let currentElements = {};
1984
+ for (let tag in _GameWindowManager._children) {
1985
+ currentElements[tag] = exportCanvasElement(_GameWindowManager._children[tag]);
1986
+ }
1987
+ return {
1988
+ currentTickers: createExportableElement(_GameWindowManager.currentTickersWithoutCreatedBySteps),
1989
+ currentTickersSteps: createExportableElement(_GameWindowManager._currentTickersSteps),
1990
+ currentElements: createExportableElement(currentElements),
1991
+ childrenTagsOrder: createExportableElement(_GameWindowManager.childrenTagsOrder)
1992
+ };
1993
+ }
1994
+ /**
1995
+ * Import the canvas and the tickers from a JSON string.
1996
+ * @param dataString The JSON string.
1997
+ */
1998
+ static importJson(dataString) {
1999
+ _GameWindowManager.import(JSON.parse(dataString));
2000
+ }
2001
+ /**
2002
+ * Import the canvas and the tickers from an object.
2003
+ * @param data The object.
2004
+ */
2005
+ static import(data) {
2006
+ _GameWindowManager.clear();
2007
+ try {
2008
+ if (data.hasOwnProperty("childrenTagsOrder") && data.hasOwnProperty("currentElements")) {
2009
+ let currentElements = data["currentElements"];
2010
+ let childrenTagsOrder = data["childrenTagsOrder"];
2011
+ childrenTagsOrder.forEach((tag) => {
2012
+ if (currentElements[tag]) {
2013
+ let element = importCanvasElement(currentElements[tag]);
2014
+ _GameWindowManager.addCanvasElement(tag, element);
2015
+ _GameWindowManager.childrenTagsOrder.push(tag);
2016
+ }
2017
+ });
2018
+ } else {
2019
+ console.error("[Pixi'VN] The data does not have the properties childrenTagsOrder and currentElements");
2020
+ return;
2021
+ }
2022
+ if (data.hasOwnProperty("currentTickers")) {
2023
+ let currentTickers = data["currentTickers"];
2024
+ for (let id in currentTickers) {
2025
+ let t = currentTickers[id];
2026
+ let tags = t.canvasElementTags;
2027
+ let ticker = geTickerInstanceById(t.id, t.args, t.duration, t.priority);
2028
+ if (ticker) {
2029
+ _GameWindowManager.addTicker(tags, ticker);
2030
+ } else {
2031
+ console.error(`[Pixi'VN] Ticker ${t.id} not found`);
2032
+ }
2033
+ }
2034
+ }
2035
+ if (data.hasOwnProperty("currentTickersSteps")) {
2036
+ let currentTickersSteps = data["currentTickersSteps"];
2037
+ _GameWindowManager.restoneTickersSteps(currentTickersSteps);
2038
+ }
2039
+ } catch (e) {
2040
+ console.error("[Pixi'VN] Error importing data", e);
2041
+ }
2042
+ }
2043
+ };
2044
+ _GameWindowManager._app = void 0;
2045
+ _GameWindowManager._isInitialized = false;
2046
+ _GameWindowManager._children = {};
2047
+ /**
2048
+ * The order of the children tags.
2049
+ */
2050
+ _GameWindowManager.childrenTagsOrder = [];
2051
+ _GameWindowManager._currentTickers = {};
2052
+ _GameWindowManager._currentTickersSteps = {};
2053
+ _GameWindowManager._currentTickersTimeouts = {};
2054
+ var GameWindowManager = _GameWindowManager;
2055
+
2056
+ // src/managers/StepManager.ts
2057
+ var _GameStepManager = class _GameStepManager {
2058
+ constructor() {
2059
+ }
2060
+ static get stepsHistory() {
2061
+ return _GameStepManager._stepsHistory;
2062
+ }
2063
+ /**
2064
+ * lastStepIndex is the last step index that occurred during the progression of the steps. **Not is the length of the stepsHistory - 1.**
2065
+ */
2066
+ static get lastStepIndex() {
2067
+ return _GameStepManager._lastStepIndex;
2068
+ }
2069
+ /**
2070
+ * Increase the last step index that occurred during the progression of the steps.
2071
+ */
2072
+ static increaseLastStepIndex() {
2073
+ _GameStepManager._lastStepIndex++;
2074
+ }
2075
+ static get openedLabels() {
2076
+ return _GameStepManager._openedLabels;
2077
+ }
2078
+ /**
2079
+ * currentLabelId is the current label id that occurred during the progression of the steps.
2080
+ */
2081
+ static get currentLabelId() {
2082
+ if (_GameStepManager._openedLabels.length > 0) {
2083
+ let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
2084
+ return item.label;
2085
+ }
2086
+ return void 0;
2087
+ }
2088
+ /**
2089
+ * currentLabel is the current label that occurred during the progression of the steps.
2090
+ */
2091
+ static get currentLabel() {
2092
+ if (_GameStepManager.currentLabelId) {
2093
+ return getLabelById(_GameStepManager.currentLabelId);
2094
+ }
2095
+ }
2096
+ static get currentLabelStepIndex() {
2097
+ if (_GameStepManager._openedLabels.length > 0) {
2098
+ let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
2099
+ return item.currentStepIndex;
2100
+ }
2101
+ return null;
2102
+ }
2103
+ /**
2104
+ * lastHistoryStep is the last history step that occurred during the progression of the steps.
2105
+ */
2106
+ static get lastHistoryStep() {
2107
+ if (_GameStepManager._stepsHistory.length > 0) {
2108
+ return _GameStepManager._stepsHistory[_GameStepManager._stepsHistory.length - 1];
2109
+ }
2110
+ return null;
2111
+ }
2112
+ static get originalStepData() {
2113
+ if (!_GameStepManager._originalStepData) {
2114
+ return {
2115
+ path: "",
2116
+ storage: {},
2117
+ canvas: {
2118
+ childrenTagsOrder: [],
2119
+ currentElements: {},
2120
+ currentTickers: {},
2121
+ currentTickersSteps: {}
2122
+ },
2123
+ labelIndex: -1,
2124
+ openedLabels: []
2125
+ };
2126
+ }
2127
+ return createExportableElement(_GameStepManager._originalStepData);
2128
+ }
2129
+ static set originalStepData(value) {
2130
+ _GameStepManager._originalStepData = createExportableElement(value);
2131
+ }
2132
+ static get currentStepData() {
2133
+ let currentStepData = {
2134
+ path: window.location.pathname,
2135
+ storage: GameStorageManager.export(),
2136
+ canvas: GameWindowManager.export(),
2137
+ labelIndex: _GameStepManager.currentLabelStepIndex || 0,
2138
+ openedLabels: createExportableElement(_GameStepManager._openedLabels)
2139
+ };
2140
+ return currentStepData;
2141
+ }
2142
+ /* Edit History Methods */
2143
+ /**
2144
+ * Add a label to the history.
2145
+ * @param label The label to add to the history.
2146
+ */
2147
+ static addStepHistory(step, choiseMade) {
2148
+ let stepHistory = getStepSha1(step);
2149
+ let currentStepData = _GameStepManager.currentStepData;
2150
+ if (_GameStepManager.originalStepData) {
2151
+ if (_GameStepManager.originalStepData.openedLabels.length === currentStepData.openedLabels.length) {
2152
+ try {
2153
+ let lastStepDataOpenedLabelsString = JSON.stringify(_GameStepManager.originalStepData.openedLabels);
2154
+ let historyStepOpenedLabelsString = JSON.stringify(currentStepData.openedLabels);
2155
+ if (lastStepDataOpenedLabelsString === historyStepOpenedLabelsString && _GameStepManager.originalStepData.path === currentStepData.path && _GameStepManager.originalStepData.labelIndex === currentStepData.labelIndex) {
2156
+ return;
2157
+ }
2158
+ } catch (e) {
2159
+ console.error("[Pixi'VN] Error comparing openedLabels", e);
2160
+ }
2161
+ }
2162
+ }
2163
+ let data = diff(_GameStepManager.originalStepData, currentStepData);
2164
+ if (data) {
2165
+ let dialoge = void 0;
2166
+ let requiredChoices = void 0;
2167
+ if (GameStorageManager.getVariable(GameStorageManager.keysSystem.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY) === _GameStepManager.lastStepIndex) {
2168
+ dialoge = getDialogue();
2169
+ }
2170
+ if (GameStorageManager.getVariable(GameStorageManager.keysSystem.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY) === _GameStepManager.lastStepIndex) {
2171
+ requiredChoices = GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY);
2172
+ }
2173
+ _GameStepManager._stepsHistory.push({
2174
+ diff: data,
2175
+ currentLabel: _GameStepManager.currentLabelId,
2176
+ dialoge,
2177
+ choices: requiredChoices,
2178
+ stepSha1: stepHistory,
2179
+ index: _GameStepManager.lastStepIndex,
2180
+ choiceIndexMade: choiseMade
2181
+ });
2182
+ _GameStepManager.originalStepData = currentStepData;
2183
+ }
2184
+ _GameStepManager.increaseLastStepIndex();
2185
+ }
2186
+ /**
2187
+ * Add a label to the history.
2188
+ * @param label The label to add to the history.
2189
+ */
2190
+ static pushNewLabel(label) {
2191
+ let currentLabel = getLabelById(label);
2192
+ if (!currentLabel) {
2193
+ throw new Error(`[Pixi'VN] Label ${label} not found`);
2194
+ }
2195
+ _GameStepManager._openedLabels.push({
2196
+ label,
2197
+ currentStepIndex: 0
2198
+ });
2199
+ }
2200
+ /**
2201
+ * Close the current label and add it to the history.
2202
+ * @returns
2203
+ */
2204
+ static closeCurrentLabel() {
2205
+ if (!_GameStepManager.currentLabelId) {
2206
+ console.warn("[Pixi'VN] No label to close");
2207
+ return;
2208
+ }
2209
+ if (!_GameStepManager.currentLabel) {
2210
+ console.error("[Pixi'VN] currentLabel not found");
2211
+ return;
2212
+ }
2213
+ _GameStepManager._openedLabels.pop();
2214
+ }
2215
+ /**
2216
+ * Close all labels and add them to the history. **Attention: This method can cause an unhandled game ending.**
2217
+ */
2218
+ static closeAllLabels() {
2219
+ while (_GameStepManager._openedLabels.length > 0) {
2220
+ _GameStepManager.closeCurrentLabel();
2221
+ }
2222
+ }
2223
+ /**
2224
+ * Increase the current step index of the current label.
2225
+ */
2226
+ static increaseCurrentStepIndex() {
2227
+ let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
2228
+ _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1] = __spreadProps(__spreadValues({}, item), {
2229
+ currentStepIndex: item.currentStepIndex + 1
2230
+ });
2231
+ }
2232
+ static restorLastLabelList() {
2233
+ _GameStepManager._openedLabels = _GameStepManager.originalStepData.openedLabels;
2234
+ }
2235
+ /* Run Methods */
2236
+ static get canGoNext() {
2237
+ let options = getChoiceMenuOptions();
2238
+ if (options && options.length > 0) {
2239
+ return false;
2240
+ }
2241
+ return true;
2242
+ }
2243
+ /**
2244
+ * Execute the next step and add it to the history.
2245
+ * @param props The props to pass to the step.
2246
+ * @param choiseMade The index of the choise made by the player. (This params is used in the choice menu)
2247
+ * @returns StepLabelResultType or undefined.
2248
+ * @example
2249
+ * ```typescript
2250
+ * function nextOnClick() {
2251
+ * setLoading(true)
2252
+ * GameStepManager.goNext(yourParams)
2253
+ * .then((result) => {
2254
+ * setUpdate((p) => p + 1)
2255
+ * setLoading(false)
2256
+ * if (result) {
2257
+ * // your code
2258
+ * }
2259
+ * })
2260
+ * .catch((e) => {
2261
+ * setLoading(false)
2262
+ * console.error(e)
2263
+ * })
2264
+ * }
2265
+ * ```
2266
+ */
2267
+ static goNext(props, choiseMade) {
2268
+ return __async(this, null, function* () {
2269
+ if (!_GameStepManager.canGoNext) {
2270
+ console.warn("[Pixi'VN] The player must make a choice");
2271
+ return;
2272
+ }
2273
+ if (_GameStepManager.currentLabel && _GameStepManager.currentLabel.onStepEnd) {
2274
+ yield _GameStepManager.currentLabel.onStepEnd(_GameStepManager.currentLabelStepIndex || 0, _GameStepManager.currentLabel);
2275
+ }
2276
+ _GameStepManager.increaseCurrentStepIndex();
2277
+ return yield _GameStepManager.runCurrentStep(props, choiseMade);
2278
+ });
2279
+ }
2280
+ /**
2281
+ * Execute the current step and add it to the history.
2282
+ * @param props The props to pass to the step.
2283
+ * @param choiseMade The choise made by the player.
2284
+ * @returns StepLabelResultType or undefined.
2285
+ */
2286
+ static runCurrentStep(props, choiseMade) {
2287
+ return __async(this, null, function* () {
2288
+ if (_GameStepManager.currentLabelId) {
2289
+ let currentLabelStepIndex = _GameStepManager.currentLabelStepIndex;
2290
+ if (currentLabelStepIndex === null) {
2291
+ console.error("[Pixi'VN] currentLabelStepIndex is null");
2292
+ return;
2293
+ }
2294
+ let currentLabel = _GameStepManager.currentLabel;
2295
+ if (!currentLabel) {
2296
+ console.error("[Pixi'VN] currentLabel not found");
2297
+ return;
2298
+ }
2299
+ if (currentLabel.steps.length > currentLabelStepIndex) {
2300
+ let onStepRun = currentLabel.onStepStart;
2301
+ if (onStepRun) {
2302
+ yield onStepRun(currentLabelStepIndex, currentLabel);
2303
+ }
2304
+ let step = currentLabel.steps[currentLabelStepIndex];
2305
+ let result = yield step(props);
2306
+ _GameStepManager.addStepHistory(step, choiseMade);
2307
+ return result;
2308
+ } else if (_GameStepManager.openedLabels.length > 1) {
2309
+ _GameStepManager.closeCurrentLabel();
2310
+ return yield _GameStepManager.goNext(props, choiseMade);
2311
+ } else {
2312
+ _GameStepManager.restorLastLabelList();
2313
+ console.error("[Pixi'VN] The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.web.app/start/labels.html#how-manage-the-end-of-the-game");
2314
+ return;
2315
+ }
2316
+ }
2317
+ });
2318
+ }
2319
+ /**
2320
+ * Execute the label and add it to the history. (It's similar to Ren'Py's call function)
2321
+ * @param label The label to execute or the id of the label
2322
+ * @param props The props to pass to the label.
2323
+ * @returns StepLabelResultType or undefined.
2324
+ * @example
2325
+ * ```typescript
2326
+ * GameStepManager.callLabel(startLabel, yourParams).then((result) => {
2327
+ * if (result) {
2328
+ * // your code
2329
+ * }
2330
+ * })
2331
+ * ```
2332
+ * @example
2333
+ * ```typescript
2334
+ * // if you use it in a step label you should return the result.
2335
+ * return GameStepManager.callLabel(startLabel).then((result) => {
2336
+ * return result
2337
+ * })
2338
+ * ```
2339
+ */
2340
+ static callLabel(label, props) {
2341
+ return __async(this, null, function* () {
2342
+ let choiseMade = void 0;
2343
+ let labelId;
2344
+ if (typeof label === "string") {
2345
+ labelId = label;
2346
+ } else {
2347
+ labelId = label.id;
2348
+ if (typeof label.choiseIndex === "number") {
2349
+ choiseMade = label.choiseIndex;
2350
+ }
2351
+ }
2352
+ try {
2353
+ if (labelId === CLOSE_LABEL_ID) {
2354
+ let closeCurrentLabel = newCloseLabel(choiseMade);
2355
+ let choice = {
2356
+ label: closeCurrentLabel,
2357
+ text: "",
2358
+ closeCurrentLabel: false,
2359
+ type: "close",
2360
+ props: {}
2361
+ };
2362
+ return _GameStepManager.closeChoiceMenu(choice, props);
2363
+ }
2364
+ let tempLabel = getLabelById(labelId);
2365
+ if (!tempLabel) {
2366
+ throw new Error(`[Pixi'VN] Label ${labelId} not found`);
2367
+ }
2368
+ if (_GameStepManager.currentLabel && _GameStepManager.currentLabel.onStepEnd) {
2369
+ yield _GameStepManager.currentLabel.onStepEnd(_GameStepManager.currentLabelStepIndex || 0, _GameStepManager.currentLabel);
2370
+ }
2371
+ _GameStepManager.pushNewLabel(tempLabel.id);
2372
+ } catch (e) {
2373
+ console.error("[Pixi'VN] Error calling label", e);
2374
+ return;
2375
+ }
2376
+ return yield _GameStepManager.runCurrentStep(props, choiseMade);
2377
+ });
2378
+ }
2379
+ /**
2380
+ * Execute the label, close the current label, execute the new label and add the new label to the history. (It's similar to Ren'Py's jump function)
2381
+ * @param label The label to execute.
2382
+ * @param props The props to pass to the label or the id of the label
2383
+ * @returns StepLabelResultType or undefined.
2384
+ * @example
2385
+ * ```typescript
2386
+ * GameStepManager.jumpLabel(startLabel, yourParams).then((result) => {
2387
+ * if (result) {
2388
+ * // your code
2389
+ * }
2390
+ * })
2391
+ * ```
2392
+ * @example
2393
+ * ```typescript
2394
+ * // if you use it in a step label you should return the result.
2395
+ * return GameStepManager.jumpLabel(startLabel).then((result) => {
2396
+ * return result
2397
+ * })
2398
+ * ```
2399
+ */
2400
+ static jumpLabel(label, props) {
2401
+ return __async(this, null, function* () {
2402
+ _GameStepManager.closeCurrentLabel();
2403
+ let choiseMade = void 0;
2404
+ let labelId;
2405
+ if (typeof label === "string") {
2406
+ labelId = label;
2407
+ } else {
2408
+ labelId = label.id;
2409
+ if (typeof label.choiseIndex === "number") {
2410
+ choiseMade = label.choiseIndex;
2411
+ }
2412
+ }
2413
+ try {
2414
+ if (labelId === CLOSE_LABEL_ID) {
2415
+ let closeCurrentLabel = newCloseLabel(choiseMade);
2416
+ let choice = {
2417
+ label: closeCurrentLabel,
2418
+ text: "",
2419
+ closeCurrentLabel: false,
2420
+ type: "close",
2421
+ props: {}
2422
+ };
2423
+ return _GameStepManager.closeChoiceMenu(choice, props);
2424
+ }
2425
+ let tempLabel = getLabelById(labelId);
2426
+ if (!tempLabel) {
2427
+ throw new Error(`[Pixi'VN] Label ${labelId} not found`);
2428
+ }
2429
+ if (_GameStepManager.currentLabel && _GameStepManager.currentLabel.onStepEnd) {
2430
+ yield _GameStepManager.currentLabel.onStepEnd(_GameStepManager.currentLabelStepIndex || 0, _GameStepManager.currentLabel);
2431
+ }
2432
+ _GameStepManager.pushNewLabel(tempLabel.id);
2433
+ } catch (e) {
2434
+ console.error("[Pixi'VN] Error jumping label", e);
2435
+ return;
2436
+ }
2437
+ return yield _GameStepManager.runCurrentStep(props, choiseMade);
2438
+ });
2439
+ }
2440
+ /**
2441
+ * When the player is in a choice menu, can use this function to exit to the choice menu.
2442
+ * @param choice
2443
+ * @param props
2444
+ * @returns StepLabelResultType or undefined.
2445
+ * @example
2446
+ * ```typescript
2447
+ * GameStepManager.closeChoiceMenu(yourParams).then((result) => {
2448
+ * if (result) {
2449
+ * // your code
2450
+ * }
2451
+ * })
2452
+ * ```
2453
+ */
2454
+ static closeChoiceMenu(choice, props) {
2455
+ return __async(this, null, function* () {
2456
+ let label = choice.label;
2457
+ let choiseMade = void 0;
2458
+ if (typeof label.choiseIndex === "number") {
2459
+ choiseMade = label.choiseIndex;
2460
+ }
2461
+ if (choice.closeCurrentLabel) {
2462
+ _GameStepManager.closeCurrentLabel();
2463
+ }
2464
+ return _GameStepManager.goNext(props, choiseMade);
2465
+ });
2466
+ }
2467
+ /* After Update Methods */
2468
+ // /**
2469
+ // * After the update or code edit, some steps or labels may no longer match.
2470
+ // * - In case of step mismatch, the game will be updated to the last matching step.
2471
+ // * - In case of label mismatch, the game gives an error.
2472
+ // * @returns
2473
+ // */
2474
+ // private static afterUpdate() {
2475
+ // // TODO: implement
2476
+ // if (!GameStepManager.currentLabel) {
2477
+ // // TODO: implement
2478
+ // return
2479
+ // }
2480
+ // let currentLabel = getLabelInstanceByClassName(GameStepManager.currentLabel)
2481
+ // if (!currentLabel) {
2482
+ // console.error("Label not found")
2483
+ // return
2484
+ // }
2485
+ // let oldSteps = GameStepManager.stepsAfterLastHistoryLabel
2486
+ // let currentStepIndex = currentLabel.getCorrespondingStepsNumber(oldSteps)
2487
+ // let stepToRemove = oldSteps.length - currentStepIndex
2488
+ // GameStepManager.removeLastHistoryNodes(stepToRemove)
2489
+ // GameStepManager.loadLastStep()
2490
+ // }
2491
+ // private static loadLastStep() {
2492
+ // // TODO: implement
2493
+ // }
2494
+ // /**
2495
+ // * Remove a number of items from the last of the history.
2496
+ // * @param itemNumber The number of items to remove from the last of the history.
2497
+ // */
2498
+ // private static removeLastHistoryNodes(itemNumber: number) {
2499
+ // // TODO: implement
2500
+ // for (let i = 0; i < itemNumber; i++) {
2501
+ // GameStepManager._stepsHistory.pop()
2502
+ // }
2503
+ // }
2504
+ // /**
2505
+ // * stepsAfterLastHistoryLabel is a list of steps that occurred after the last history label.
2506
+ // */
2507
+ // private static get stepsAfterLastHistoryLabel(): StepHistoryDataType[] {
2508
+ // let length = GameStepManager._stepsHistory.length
2509
+ // let steps: StepHistoryDataType[] = []
2510
+ // for (let i = length - 1; i >= 0; i--) {
2511
+ // let element = GameStepManager._stepsHistory[i]
2512
+ // if (typeof element === "object" && "stepSha1" in element) {
2513
+ // steps.push(element.stepSha1)
2514
+ // }
2515
+ // else {
2516
+ // break
2517
+ // }
2518
+ // }
2519
+ // steps = steps.reverse()
2520
+ // return steps
2521
+ // }
2522
+ /* Go Back & Refresh Methods */
2523
+ /**
2524
+ * Go back to the last step and add it to the history.
2525
+ * @param navigate The navigate function.
2526
+ * @param steps The number of steps to go back.
2527
+ * @returns
2528
+ * @example
2529
+ * ```typescript
2530
+ * export function goBack(navigate: (path: string) => void, afterBack?: () => void) {
2531
+ * GameStepManager.goBack(navigate)
2532
+ * afterBack && afterBack()
2533
+ * }
2534
+ * ```
2535
+ */
2536
+ static goBack(navigate, steps = 1) {
2537
+ return __async(this, null, function* () {
2538
+ if (steps <= 0) {
2539
+ console.warn("[Pixi'VN] Steps must be greater than 0");
2540
+ return;
2541
+ }
2542
+ if (_GameStepManager._stepsHistory.length <= 1) {
2543
+ console.warn("[Pixi'VN] No steps to go back");
2544
+ return;
2545
+ }
2546
+ let restoredStep = _GameStepManager.goBackInternal(steps, _GameStepManager.originalStepData);
2547
+ if (restoredStep) {
2548
+ _GameStepManager._originalStepData = restoredStep;
2549
+ _GameStepManager._openedLabels = createExportableElement(restoredStep.openedLabels);
2550
+ if (_GameStepManager.currentLabel && _GameStepManager.currentLabel.onLoadStep) {
2551
+ yield _GameStepManager.currentLabel.onLoadStep(_GameStepManager.currentLabelStepIndex || 0, _GameStepManager.currentLabel);
2552
+ }
2553
+ GameStorageManager.import(createExportableElement(restoredStep.storage));
2554
+ GameWindowManager.import(createExportableElement(restoredStep.canvas));
2555
+ navigate(restoredStep.path);
2556
+ } else {
2557
+ console.error("[Pixi'VN] Error going back");
2558
+ }
2559
+ });
2560
+ }
2561
+ static goBackInternal(steps, restoredStep) {
2562
+ if (steps <= 0) {
2563
+ return restoredStep;
2564
+ }
2565
+ if (_GameStepManager._stepsHistory.length == 0) {
2566
+ return restoredStep;
2567
+ }
2568
+ let lastHistoryStep = _GameStepManager.lastHistoryStep;
2569
+ if (lastHistoryStep) {
2570
+ try {
2571
+ let result = restoreDeepDiffChanges(restoredStep, lastHistoryStep.diff);
2572
+ _GameStepManager._lastStepIndex = lastHistoryStep.index;
2573
+ _GameStepManager._stepsHistory.pop();
2574
+ return _GameStepManager.goBackInternal(steps - 1, result);
2575
+ } catch (e) {
2576
+ console.error("[Pixi'VN] Error applying diff", e);
2577
+ return restoredStep;
2578
+ }
2579
+ } else {
2580
+ return restoredStep;
2581
+ }
2582
+ }
2583
+ /**
2584
+ * Return true if it is possible to go back.
2585
+ */
2586
+ static get canGoBack() {
2587
+ return _GameStepManager._stepsHistory.length > 1;
2588
+ }
2589
+ /**
2590
+ * Add a label to the history.
2591
+ */
2592
+ static clear() {
2593
+ _GameStepManager._stepsHistory = [];
2594
+ _GameStepManager._openedLabels = [];
2595
+ }
2596
+ /* Export and Import Methods */
2597
+ /**
2598
+ * Export the history to a JSON string.
2599
+ * @returns The history in a JSON string.
2600
+ */
2601
+ static exportJson() {
2602
+ return JSON.stringify(this.export());
2603
+ }
2604
+ /**
2605
+ * Export the history to an object.
2606
+ * @returns The history in an object.
2607
+ */
2608
+ static export() {
2609
+ return {
2610
+ stepsHistory: _GameStepManager._stepsHistory,
2611
+ openedLabels: _GameStepManager._openedLabels,
2612
+ lastStepIndex: _GameStepManager._lastStepIndex,
2613
+ originalStepData: _GameStepManager._originalStepData
2614
+ };
2615
+ }
2616
+ /**
2617
+ * Import the history from a JSON string.
2618
+ * @param dataString The history in a JSON string.
2619
+ */
2620
+ static importJson(dataString) {
2621
+ return __async(this, null, function* () {
2622
+ yield _GameStepManager.import(JSON.parse(dataString));
2623
+ });
2624
+ }
2625
+ /**
2626
+ * Import the history from an object.
2627
+ * @param data The history in an object.
2628
+ */
2629
+ static import(data) {
2630
+ return __async(this, null, function* () {
2631
+ _GameStepManager.clear();
2632
+ try {
2633
+ if (data.hasOwnProperty("stepsHistory")) {
2634
+ _GameStepManager._stepsHistory = data["stepsHistory"];
2635
+ } else {
2636
+ console.warn("[Pixi'VN] Could not import stepsHistory data, so will be ignored");
2637
+ }
2638
+ if (data.hasOwnProperty("openedLabels")) {
2639
+ _GameStepManager._openedLabels = data["openedLabels"];
2640
+ } else {
2641
+ console.warn("[Pixi'VN] Could not import openedLabels data, so will be ignored");
2642
+ }
2643
+ if (data.hasOwnProperty("lastStepIndex")) {
2644
+ _GameStepManager._lastStepIndex = data["lastStepIndex"];
2645
+ } else {
2646
+ console.warn("[Pixi'VN] Could not import lastStepIndex data, so will be ignored");
2647
+ }
2648
+ if (data.hasOwnProperty("originalStepData")) {
2649
+ _GameStepManager._originalStepData = data["originalStepData"];
2650
+ } else {
2651
+ console.warn("[Pixi'VN] Could not import originalStepData data, so will be ignored");
2652
+ }
2653
+ if (_GameStepManager.currentLabel && _GameStepManager.currentLabel.onLoadStep) {
2654
+ yield _GameStepManager.currentLabel.onLoadStep(_GameStepManager.currentLabelStepIndex || 0, _GameStepManager.currentLabel);
2655
+ }
2656
+ } catch (e) {
2657
+ console.error("[Pixi'VN] Error importing data", e);
2658
+ }
2659
+ });
2660
+ }
2661
+ };
2662
+ /**
2663
+ * stepHistory is a list of label events and steps that occurred during the progression of the steps.
2664
+ */
2665
+ _GameStepManager._stepsHistory = [];
2666
+ _GameStepManager._lastStepIndex = 0;
2667
+ _GameStepManager._openedLabels = [];
2668
+ _GameStepManager._originalStepData = void 0;
2669
+ var GameStepManager = _GameStepManager;
2670
+
2671
+ // src/classes/DialogueBaseModel.ts
2672
+ var DialogueBaseModel = class {
2673
+ /**
2674
+ * @param text The text of the dialogue.
2675
+ * @param character The id of the character that is speaking.
2676
+ * @param oltherParams Other parameters that can be stored in the dialogue.
2677
+ */
2678
+ constructor(text, character, oltherParams = {}) {
2679
+ /**
2680
+ * The text of the dialogue.
2681
+ */
2682
+ this.text = "";
2683
+ /**
2684
+ * Other parameters that can be stored in the dialogue.
2685
+ */
2686
+ this.oltherParams = {};
2687
+ if (typeof text === "string") {
2688
+ this.text = text;
2689
+ if (typeof character === "string") {
2690
+ this.character = character;
2691
+ } else {
2692
+ this.character = character == null ? void 0 : character.id;
2693
+ }
2694
+ this.oltherParams = oltherParams;
2695
+ } else {
2696
+ this.text = text.text;
2697
+ if (text.character) {
2698
+ this.character = text.character;
2699
+ }
2700
+ this.oltherParams = text.oltherParams || {};
2701
+ }
2702
+ }
2703
+ /**
2704
+ * Export the dialogue to a DialogueBaseData object.
2705
+ *
2706
+ * @returns The data of the dialogue.
2707
+ */
2708
+ export() {
2709
+ return {
2710
+ text: this.text,
2711
+ character: this.character,
2712
+ oltherParams: this.oltherParams
2713
+ };
2714
+ }
2715
+ };
2716
+
2717
+ // src/classes/LabelJson.ts
2718
+ var LabelJson2 = class extends LabelAbstract {
2719
+ /**
2720
+ * @param id is the id of the label
2721
+ * @param steps is the list of steps that the label will perform
2722
+ * @param props is the properties of the label
2723
+ */
2724
+ constructor(id, steps, props) {
2725
+ super(id, props);
2726
+ this._steps = steps;
2727
+ }
2728
+ /**
2729
+ * Get the steps of the label.
2730
+ */
2731
+ get steps() {
2732
+ if (typeof this._steps === "function") {
2733
+ return this._steps().map(this.stepConverter);
2734
+ }
2735
+ return this._steps.map(this.stepConverter);
2736
+ }
2737
+ stepConverter(step) {
2738
+ return (props) => {
2739
+ if (step.currentChoiceMenuOptions) {
2740
+ setChoiceMenuOptions(step.currentChoiceMenuOptions);
2741
+ } else {
2742
+ clearChoiceMenuOptions();
2743
+ }
2744
+ if (step.dialog) {
2745
+ setDialogue(step.dialog);
2746
+ } else {
2747
+ clearDialogue();
2748
+ }
2749
+ if (step.labelToOpen) {
2750
+ if (step.labelToOpen.type === "jump") {
2751
+ GameStepManager.jumpLabel(step.labelToOpen.labelId, props);
2752
+ } else {
2753
+ GameStepManager.callLabel(step.labelToOpen.labelId, props);
2754
+ }
2755
+ }
2756
+ if (step.end === "game_end") {
2757
+ console.warn("[Pixi'VN] Game end not implemented");
2758
+ } else if (step.end === "label_end") {
2759
+ GameStepManager.closeCurrentLabel();
2760
+ }
2761
+ };
2762
+ }
2763
+ };
2764
+
2765
+ // src/functions/Importer.ts
2766
+ function importPixiVNJson(data) {
2767
+ if (Array.isArray(data)) {
2768
+ data.forEach((label) => {
2769
+ importPixiVNJson(label);
2770
+ });
2771
+ return;
2772
+ }
2773
+ try {
2774
+ if (typeof data === "string") {
2775
+ data = JSON.parse(data);
2776
+ }
2777
+ } catch (e) {
2778
+ console.error("[Pixi'VN] Error parsing imported Pixi'VN JSON", e);
2779
+ return;
2780
+ }
2781
+ if (typeof data !== "object") {
2782
+ console.error("[Pixi'VN] Error parsing imported Pixi'VN JSON: data is not an object");
2783
+ return;
2784
+ }
2785
+ for (const labelId in data) {
2786
+ try {
2787
+ const steps = data[labelId];
2788
+ let label = new LabelJson2(labelId, steps);
2789
+ saveLabel(label);
2790
+ } catch (e) {
2791
+ console.error(`[Pixi'VN] Error creating JSON label ${labelId}`, e);
2792
+ }
2793
+ }
2794
+ }
2795
+
2796
+ export { importPixiVNJson };
2797
+ //# sourceMappingURL=Importer.mjs.map
2798
+ //# sourceMappingURL=Importer.mjs.map