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