@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
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- require('deep-diff');
3
+ var deepDiff = require('deep-diff');
4
4
  var sha1 = require('crypto-js/sha1');
5
5
  var pixi_js = require('pixi.js');
6
6
 
@@ -70,23 +70,26 @@ var CanvasEvent = class {
70
70
  throw new Error("[Pixi'VN] The method CanvasEvent.fn() must be overridden");
71
71
  }
72
72
  };
73
+ function getStepSha1(step) {
74
+ let sha1String = sha1__default.default(step.toString().toLocaleLowerCase());
75
+ return sha1String.toString();
76
+ }
73
77
  function checkIfStepsIsEqual(step1, step2) {
74
78
  return step1 === step2;
75
79
  }
76
80
 
77
- // src/classes/Label.ts
78
- var Label = class {
81
+ // src/classes/LabelAbstract.ts
82
+ var LabelAbstract = class {
79
83
  /**
80
84
  * @param id is the id of the label
81
- * @param steps is the list of steps that the label will perform
82
- * @param onStepRun is a function that will be executed before any step is executed, is useful for example to make sure all images used have been cached
83
- * @param choiseIndex is the index of the choice that the label will perform
85
+ * @param props is the properties of the label
84
86
  */
85
- constructor(id, steps, onStepRun, choiseIndex) {
87
+ constructor(id, props) {
86
88
  this._id = id;
87
- this._steps = steps;
88
- this._onStepRun = onStepRun;
89
- this._choiseIndex = choiseIndex;
89
+ this._onStepStart = props == null ? void 0 : props.onStepStart;
90
+ this._onLoadStep = props == null ? void 0 : props.onLoadStep;
91
+ this._onStepEnd = props == null ? void 0 : props.onStepEnd;
92
+ this._choiseIndex = props == null ? void 0 : props.choiseIndex;
90
93
  }
91
94
  /**
92
95
  * Get the id of the label. This variable is used in the system to get the label by id, {@link getLabelById}
@@ -94,17 +97,6 @@ var Label = class {
94
97
  get id() {
95
98
  return this._id;
96
99
  }
97
- /**
98
- * Get the steps of the label.
99
- * This class should be extended and the steps method should be overridden.
100
- * Every time you update this list will also be updated when the other game versions load.
101
- */
102
- get steps() {
103
- if (typeof this._steps === "function") {
104
- return this._steps();
105
- }
106
- return this._steps;
107
- }
108
100
  /**
109
101
  * Get the corresponding steps number
110
102
  * @param externalSteps
@@ -123,28 +115,66 @@ var Label = class {
123
115
  return res;
124
116
  }
125
117
  /**
126
- * Get the function that will be executed before any step is executed, is useful for example to make sure all images used have been cached
118
+ * 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.
119
+ * @returns Promise<void> or void
120
+ */
121
+ get onStepStart() {
122
+ return (stepIndex, label) => __async(this, null, function* () {
123
+ if (this._onLoadStep) {
124
+ yield this._onLoadStep(stepIndex, label);
125
+ }
126
+ if (this._onStepStart) {
127
+ return yield this._onStepStart(stepIndex, label);
128
+ }
129
+ });
130
+ }
131
+ /**
132
+ * 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.
127
133
  * @returns Promise<void> or void
128
- * @example
129
- * ```typescript
130
- * newLabel("id", [], () => {
131
- * Assets.load('path/to/image1.png')
132
- * Assets.load('path/to/image2.png')
133
- * })
134
- * ```
135
134
  */
136
- get onStepRun() {
137
- return this._onStepRun;
135
+ get onLoadStep() {
136
+ return this._onLoadStep;
137
+ }
138
+ /**
139
+ * Is a function that will be executed when the step ends.
140
+ * @returns Promise<void> or void
141
+ */
142
+ get onStepEnd() {
143
+ return this._onStepEnd;
138
144
  }
139
145
  get choiseIndex() {
140
146
  return this._choiseIndex;
141
147
  }
142
148
  };
143
149
 
150
+ // src/classes/Label.ts
151
+ var Label = class extends LabelAbstract {
152
+ /**
153
+ * @param id is the id of the label
154
+ * @param steps is the list of steps that the label will perform
155
+ * @param props is the properties of the label
156
+ */
157
+ constructor(id, steps, props) {
158
+ super(id, props);
159
+ this._steps = steps;
160
+ }
161
+ /**
162
+ * Get the steps of the label.
163
+ */
164
+ get steps() {
165
+ if (typeof this._steps === "function") {
166
+ return this._steps();
167
+ }
168
+ return this._steps;
169
+ }
170
+ };
171
+
144
172
  // src/classes/CloseLabel.ts
145
173
  var CLOSE_LABEL_ID = "__close-label-id__";
146
174
  function newCloseLabel(choiseIndex) {
147
- return new Label(CLOSE_LABEL_ID, [], void 0, choiseIndex);
175
+ return new Label(CLOSE_LABEL_ID, [], {
176
+ choiseIndex
177
+ });
148
178
  }
149
179
 
150
180
  // src/decorators/LabelDecorator.ts
@@ -234,8 +264,6 @@ function getMemoryContainer(element) {
234
264
  };
235
265
  }
236
266
  function setMemoryContainer(element, memory) {
237
- memory.width && (element.width = memory.width);
238
- memory.height && (element.height = memory.height);
239
267
  memory.isRenderGroup && (element.isRenderGroup = memory.isRenderGroup);
240
268
  memory.blendMode && (element.blendMode = memory.blendMode);
241
269
  memory.tint && (element.tint = memory.tint);
@@ -268,6 +296,8 @@ function setMemoryContainer(element, memory) {
268
296
  memory.interactive && (element.interactive = memory.interactive);
269
297
  memory.interactiveChildren && (element.interactiveChildren = memory.interactiveChildren);
270
298
  memory.hitArea && (element.hitArea = memory.hitArea);
299
+ memory.width && (element.width = memory.width);
300
+ memory.height && (element.height = memory.height);
271
301
  }
272
302
  function getTexture(imageUrl) {
273
303
  return __async(this, null, function* () {
@@ -676,29 +706,57 @@ var ChoiceMenuOption = class {
676
706
  /**
677
707
  * @param text Text to be displayed in the menu
678
708
  * @param label Label to be opened when the option is selected or the id of the label
709
+ * @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.
679
710
  * @param type Type of the label to be opened. @default "call"
680
- * @param props Properties to be passed to the label, when the label is called. it cannot contain functions or classes. @default {}
681
711
  */
682
- constructor(text, label, type = "call", props) {
712
+ constructor(text, label, props, type = "call") {
683
713
  /**
684
- * Properties to be passed to the label
714
+ * Properties to be passed to the label and olther parameters that you can use when get all the choice menu options.
715
+ * @example
716
+ * ```tsx
717
+ * setChoiceMenuOptions([
718
+ * new ChoiceMenuOption("Hello", helloLabel, { disabled: true }),
719
+ * ])
720
+ * return <List>
721
+ * {getChoiceMenuOptions()?.map((item, index) => {
722
+ * return (
723
+ * <ChoiceButton
724
+ * disabled={item.props.disabled}
725
+ * onClick={() => {
726
+ * afterSelectChoice(item)
727
+ * }}
728
+ * >
729
+ * {item.text}
730
+ * </ChoiceButton>
731
+ * )
732
+ * })}
733
+ * </List>
734
+ * ```
685
735
  */
686
736
  this.props = {};
687
- if (typeof label === "string") {
688
- let tLabel = getLabelById(label);
689
- if (!tLabel) {
690
- throw new Error(`[Pixi'VN] Label ${label} not found`);
691
- } else {
692
- label = tLabel;
693
- }
694
- }
695
737
  this.text = text;
696
- this.label = label;
738
+ this._label = label;
697
739
  this.type = type;
698
740
  if (props) {
699
741
  this.props = props;
700
742
  }
701
743
  }
744
+ /**
745
+ * Label to be opened when the option is selected
746
+ */
747
+ get label() {
748
+ let label = this._label;
749
+ if (typeof label === "string") {
750
+ let res = getLabelById(label);
751
+ if (res) {
752
+ label = res;
753
+ } else {
754
+ console.error(`Label ${label} not found, so it will be closed`);
755
+ label = newCloseLabel();
756
+ }
757
+ }
758
+ return label;
759
+ }
702
760
  };
703
761
  var ChoiceMenuOptionClose = class {
704
762
  /**
@@ -715,7 +773,27 @@ var ChoiceMenuOptionClose = class {
715
773
  */
716
774
  this.type = Close;
717
775
  /**
718
- * Properties to be passed to the label
776
+ * Properties to be passed to the label and olther parameters that you can use when get all the choice menu options.
777
+ * @example
778
+ * ```tsx
779
+ * setChoiceMenuOptions([
780
+ * new ChoiceMenuOption("Hello", helloLabel, { disabled: true }),
781
+ * ])
782
+ * return <List>
783
+ * {getChoiceMenuOptions()?.map((item, index) => {
784
+ * return (
785
+ * <ChoiceButton
786
+ * disabled={item.props.disabled}
787
+ * onClick={() => {
788
+ * afterSelectChoice(item)
789
+ * }}
790
+ * >
791
+ * {item.text}
792
+ * </ChoiceButton>
793
+ * )
794
+ * })}
795
+ * </List>
796
+ * ```
719
797
  */
720
798
  this.props = {};
721
799
  this.text = text;
@@ -723,6 +801,81 @@ var ChoiceMenuOptionClose = class {
723
801
  }
724
802
  };
725
803
 
804
+ // src/functions/DialogueUtility.ts
805
+ function setDialogue(props) {
806
+ let text = "";
807
+ let character = void 0;
808
+ let dialogue;
809
+ if (typeof props === "string") {
810
+ text = props;
811
+ dialogue = new DialogueBaseModel(text, character);
812
+ } else if (!(props instanceof DialogueBaseModel)) {
813
+ text = props.text;
814
+ if (props.character) {
815
+ if (typeof props.character === "string") {
816
+ character = props.character;
817
+ } else {
818
+ character = props.character.id;
819
+ }
820
+ }
821
+ dialogue = new DialogueBaseModel(text, character);
822
+ } else {
823
+ dialogue = props;
824
+ }
825
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY, dialogue);
826
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY, GameStepManager.lastStepIndex);
827
+ }
828
+ function getDialogue() {
829
+ return GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY);
830
+ }
831
+ function clearDialogue() {
832
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_DIALOGUE_MEMORY_KEY, void 0);
833
+ }
834
+ function setChoiceMenuOptions(options) {
835
+ let value = options.map((option) => {
836
+ if (option instanceof ChoiceMenuOptionClose) {
837
+ return {
838
+ text: option.text,
839
+ type: Close,
840
+ closeCurrentLabel: option.closeCurrentLabel
841
+ };
842
+ }
843
+ return __spreadProps(__spreadValues({}, option), {
844
+ label: option.label.id
845
+ });
846
+ });
847
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, value);
848
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY, GameStepManager.lastStepIndex);
849
+ }
850
+ function getChoiceMenuOptions() {
851
+ let d = GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY);
852
+ if (d) {
853
+ let options = [];
854
+ d.forEach((option, index) => {
855
+ if (option.type === Close) {
856
+ let itemLabel = newCloseLabel(index);
857
+ let choice = new ChoiceMenuOptionClose(option.text, option.closeCurrentLabel);
858
+ choice.label = itemLabel;
859
+ options.push(choice);
860
+ return;
861
+ }
862
+ let label = getLabelById(option.label);
863
+ if (label) {
864
+ let itemLabel = new Label(label.id, label.steps, {
865
+ onStepStart: label.onStepStart,
866
+ choiseIndex: index
867
+ });
868
+ options.push(new ChoiceMenuOption(option.text, itemLabel, option.props, option.type));
869
+ }
870
+ });
871
+ return options;
872
+ }
873
+ return void 0;
874
+ }
875
+ function clearChoiceMenuOptions() {
876
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, void 0);
877
+ }
878
+
726
879
  // src/classes/ticker/TickerBase.ts
727
880
  var TickerBase = class {
728
881
  /**
@@ -803,8 +956,9 @@ FadeAlphaTicker = __decorateClass([
803
956
  ], FadeAlphaTicker);
804
957
 
805
958
  // src/functions/TickerUtility.ts
806
- function updateTickerProgression(args, propertyName, progression) {
807
- if (args[propertyName] === void 0 || !progression || args[propertyName] === progression.limit) {
959
+ function updateTickerProgression(args, propertyName, progression, valueConvert) {
960
+ let limit = valueConvert && progression.limit ? valueConvert(progression.limit) : progression.limit;
961
+ if (args[propertyName] === void 0 || !progression || args[propertyName] === limit) {
808
962
  return;
809
963
  }
810
964
  if (typeof args[propertyName] === "number") {
@@ -823,22 +977,25 @@ function updateTickerProgression(args, propertyName, progression) {
823
977
  }
824
978
  }
825
979
  }
826
- function getLinearProgression(number, progression) {
827
- if (progression.limit !== void 0) {
828
- if (number > progression.limit && progression.amt > 0) {
829
- return progression.limit;
830
- } else if (number < progression.limit && progression.amt < 0) {
831
- return progression.limit;
980
+ function getLinearProgression(number, progression, valueConvert) {
981
+ let limit = valueConvert && progression.limit ? valueConvert(progression.limit) : progression.limit;
982
+ let amt = valueConvert ? valueConvert(progression.amt) : progression.amt;
983
+ if (limit !== void 0) {
984
+ if (number > limit && amt > 0) {
985
+ return limit;
986
+ } else if (number < limit && amt < 0) {
987
+ return limit;
832
988
  }
833
989
  }
834
- return number + progression.amt / 60;
990
+ return number + amt;
835
991
  }
836
- function getExponentialProgression(number, progression) {
837
- if (progression.limit !== void 0) {
838
- if (number > progression.limit && progression.percentage > 0) {
839
- return progression.limit;
840
- } else if (number < progression.limit && progression.percentage < 0) {
841
- return progression.limit;
992
+ function getExponentialProgression(number, progression, valueConvert) {
993
+ let limit = valueConvert && progression.limit ? valueConvert(progression.limit) : progression.limit;
994
+ if (limit !== void 0) {
995
+ if (number > limit && progression.percentage > 0) {
996
+ return limit;
997
+ } else if (number < limit && progression.percentage < 0) {
998
+ return limit;
842
999
  }
843
1000
  }
844
1001
  return number + number * progression.percentage;
@@ -851,15 +1008,13 @@ var MoveTicker = class extends TickerBase {
851
1008
  let ySpeed = 1;
852
1009
  if (args.speed) {
853
1010
  if (typeof args.speed === "number") {
854
- xSpeed = args.speed;
855
- ySpeed = args.speed;
1011
+ xSpeed = this.speedConvert(args.speed);
1012
+ ySpeed = this.speedConvert(args.speed);
856
1013
  } else {
857
- xSpeed = args.speed.x;
858
- ySpeed = args.speed.y;
1014
+ xSpeed = this.speedConvert(args.speed.x);
1015
+ ySpeed = this.speedConvert(args.speed.y);
859
1016
  }
860
1017
  }
861
- xSpeed /= 60;
862
- ySpeed /= 60;
863
1018
  let destination = args.destination;
864
1019
  let tagToRemoveAfter2 = args.tagToRemoveAfter || [];
865
1020
  if (typeof tagToRemoveAfter2 === "string") {
@@ -899,7 +1054,10 @@ var MoveTicker = class extends TickerBase {
899
1054
  }
900
1055
  });
901
1056
  if (args.speedProgression)
902
- updateTickerProgression(args, "speed", args.speedProgression);
1057
+ updateTickerProgression(args, "speed", args.speedProgression, this.speedConvert);
1058
+ }
1059
+ speedConvert(speed) {
1060
+ return speed / 6;
903
1061
  }
904
1062
  };
905
1063
  MoveTicker = __decorateClass([
@@ -907,7 +1065,7 @@ MoveTicker = __decorateClass([
907
1065
  ], MoveTicker);
908
1066
  var RotateTicker = class extends TickerBase {
909
1067
  fn(ticker, args, tags, tickerId) {
910
- let speed = (args.speed === void 0 ? 1 : args.speed) / 60;
1068
+ let speed = this.speedConvert(args.speed === void 0 ? 1 : args.speed);
911
1069
  let clockwise = args.clockwise === void 0 ? true : args.clockwise;
912
1070
  let tagToRemoveAfter2 = args.tagToRemoveAfter || [];
913
1071
  if (typeof tagToRemoveAfter2 === "string") {
@@ -935,7 +1093,10 @@ var RotateTicker = class extends TickerBase {
935
1093
  }
936
1094
  });
937
1095
  if (args.speedProgression)
938
- updateTickerProgression(args, "speed", args.speedProgression);
1096
+ updateTickerProgression(args, "speed", args.speedProgression, this.speedConvert);
1097
+ }
1098
+ speedConvert(speed) {
1099
+ return speed / 60;
939
1100
  }
940
1101
  };
941
1102
  RotateTicker = __decorateClass([
@@ -947,15 +1108,13 @@ var ZoomTicker = class extends TickerBase {
947
1108
  let ySpeed = 0.1;
948
1109
  if (args.speed) {
949
1110
  if (typeof args.speed === "number") {
950
- xSpeed = args.speed;
951
- ySpeed = args.speed;
1111
+ xSpeed = this.speedConvert(args.speed);
1112
+ ySpeed = this.speedConvert(args.speed);
952
1113
  } else {
953
- xSpeed = args.speed.x;
954
- ySpeed = args.speed.y;
1114
+ xSpeed = this.speedConvert(args.speed.x);
1115
+ ySpeed = this.speedConvert(args.speed.y);
955
1116
  }
956
1117
  }
957
- xSpeed /= 60;
958
- ySpeed /= 60;
959
1118
  let tagToRemoveAfter2 = args.tagToRemoveAfter || [];
960
1119
  if (typeof tagToRemoveAfter2 === "string") {
961
1120
  tagToRemoveAfter2 = [tagToRemoveAfter2];
@@ -1022,7 +1181,10 @@ var ZoomTicker = class extends TickerBase {
1022
1181
  }
1023
1182
  });
1024
1183
  if (args.speedProgression)
1025
- updateTickerProgression(args, "speed", args.speedProgression);
1184
+ updateTickerProgression(args, "speed", args.speedProgression, this.speedConvert);
1185
+ }
1186
+ speedConvert(speed) {
1187
+ return speed / 60;
1026
1188
  }
1027
1189
  onEndOfTicker(tag, tickerId, _element, tagToRemoveAfter2) {
1028
1190
  GameWindowManager.onEndOfTicker(tag, this, tagToRemoveAfter2, tickerId);
@@ -1046,6 +1208,47 @@ function createExportableElement(element) {
1046
1208
  }
1047
1209
  }
1048
1210
 
1211
+ // src/functions/DiffUtility.ts
1212
+ function restoreDeepDiffChanges(data, differences) {
1213
+ let result = createExportableElement(data);
1214
+ differences.forEach((diff2) => {
1215
+ let dataToEdit = result;
1216
+ if (diff2.path && diff2.path.length > 0) {
1217
+ diff2.path.forEach((path, index) => {
1218
+ if (diff2.path && index === diff2.path.length - 1) {
1219
+ if (diff2.kind === "E" || diff2.kind === "D") {
1220
+ dataToEdit[path] = diff2.lhs;
1221
+ } else if (diff2.kind === "N") {
1222
+ if (Number.isInteger(path)) {
1223
+ if (Array.isArray(dataToEdit)) {
1224
+ dataToEdit.splice(path, 1);
1225
+ }
1226
+ } else if (typeof path === "string") {
1227
+ delete dataToEdit[path];
1228
+ }
1229
+ } else if (diff2.kind === "A") {
1230
+ let index2 = diff2.index;
1231
+ if (diff2.item.kind === "N") {
1232
+ dataToEdit[path].splice(index2, 1);
1233
+ } else if (diff2.item.kind === "E" || diff2.item.kind === "D") {
1234
+ dataToEdit[path][index2] = diff2.item.lhs;
1235
+ } else if (diff2.item.kind === "A") {
1236
+ console.warn("[Pixi'VN] Nested array found, skipping diff", diff2);
1237
+ } else {
1238
+ console.warn("[Pixi'VN] No array found, skipping diff", diff2);
1239
+ }
1240
+ }
1241
+ } else {
1242
+ dataToEdit = dataToEdit[path];
1243
+ }
1244
+ });
1245
+ } else {
1246
+ console.warn("[Pixi'VN] No path found, skipping diff", diff2);
1247
+ }
1248
+ });
1249
+ return result;
1250
+ }
1251
+
1049
1252
  // src/managers/StorageManager.ts
1050
1253
  var _GameStorageManager = class _GameStorageManager {
1051
1254
  constructor() {
@@ -1867,6 +2070,621 @@ _GameWindowManager._currentTickersSteps = {};
1867
2070
  _GameWindowManager._currentTickersTimeouts = {};
1868
2071
  var GameWindowManager = _GameWindowManager;
1869
2072
 
2073
+ // src/managers/StepManager.ts
2074
+ var _GameStepManager = class _GameStepManager {
2075
+ constructor() {
2076
+ }
2077
+ static get stepsHistory() {
2078
+ return _GameStepManager._stepsHistory;
2079
+ }
2080
+ /**
2081
+ * lastStepIndex is the last step index that occurred during the progression of the steps. **Not is the length of the stepsHistory - 1.**
2082
+ */
2083
+ static get lastStepIndex() {
2084
+ return _GameStepManager._lastStepIndex;
2085
+ }
2086
+ /**
2087
+ * Increase the last step index that occurred during the progression of the steps.
2088
+ */
2089
+ static increaseLastStepIndex() {
2090
+ _GameStepManager._lastStepIndex++;
2091
+ }
2092
+ static get openedLabels() {
2093
+ return _GameStepManager._openedLabels;
2094
+ }
2095
+ /**
2096
+ * currentLabelId is the current label id that occurred during the progression of the steps.
2097
+ */
2098
+ static get currentLabelId() {
2099
+ if (_GameStepManager._openedLabels.length > 0) {
2100
+ let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
2101
+ return item.label;
2102
+ }
2103
+ return void 0;
2104
+ }
2105
+ /**
2106
+ * currentLabel is the current label that occurred during the progression of the steps.
2107
+ */
2108
+ static get currentLabel() {
2109
+ if (_GameStepManager.currentLabelId) {
2110
+ return getLabelById(_GameStepManager.currentLabelId);
2111
+ }
2112
+ }
2113
+ static get currentLabelStepIndex() {
2114
+ if (_GameStepManager._openedLabels.length > 0) {
2115
+ let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
2116
+ return item.currentStepIndex;
2117
+ }
2118
+ return null;
2119
+ }
2120
+ /**
2121
+ * lastHistoryStep is the last history step that occurred during the progression of the steps.
2122
+ */
2123
+ static get lastHistoryStep() {
2124
+ if (_GameStepManager._stepsHistory.length > 0) {
2125
+ return _GameStepManager._stepsHistory[_GameStepManager._stepsHistory.length - 1];
2126
+ }
2127
+ return null;
2128
+ }
2129
+ static get originalStepData() {
2130
+ if (!_GameStepManager._originalStepData) {
2131
+ return {
2132
+ path: "",
2133
+ storage: {},
2134
+ canvas: {
2135
+ childrenTagsOrder: [],
2136
+ currentElements: {},
2137
+ currentTickers: {},
2138
+ currentTickersSteps: {}
2139
+ },
2140
+ labelIndex: -1,
2141
+ openedLabels: []
2142
+ };
2143
+ }
2144
+ return createExportableElement(_GameStepManager._originalStepData);
2145
+ }
2146
+ static set originalStepData(value) {
2147
+ _GameStepManager._originalStepData = createExportableElement(value);
2148
+ }
2149
+ static get currentStepData() {
2150
+ let currentStepData = {
2151
+ path: window.location.pathname,
2152
+ storage: GameStorageManager.export(),
2153
+ canvas: GameWindowManager.export(),
2154
+ labelIndex: _GameStepManager.currentLabelStepIndex || 0,
2155
+ openedLabels: createExportableElement(_GameStepManager._openedLabels)
2156
+ };
2157
+ return currentStepData;
2158
+ }
2159
+ /* Edit History Methods */
2160
+ /**
2161
+ * Add a label to the history.
2162
+ * @param label The label to add to the history.
2163
+ */
2164
+ static addStepHistory(step, choiseMade) {
2165
+ let stepHistory = getStepSha1(step);
2166
+ let currentStepData = _GameStepManager.currentStepData;
2167
+ if (_GameStepManager.originalStepData) {
2168
+ if (_GameStepManager.originalStepData.openedLabels.length === currentStepData.openedLabels.length) {
2169
+ try {
2170
+ let lastStepDataOpenedLabelsString = JSON.stringify(_GameStepManager.originalStepData.openedLabels);
2171
+ let historyStepOpenedLabelsString = JSON.stringify(currentStepData.openedLabels);
2172
+ if (lastStepDataOpenedLabelsString === historyStepOpenedLabelsString && _GameStepManager.originalStepData.path === currentStepData.path && _GameStepManager.originalStepData.labelIndex === currentStepData.labelIndex) {
2173
+ return;
2174
+ }
2175
+ } catch (e) {
2176
+ console.error("[Pixi'VN] Error comparing openedLabels", e);
2177
+ }
2178
+ }
2179
+ }
2180
+ let data = deepDiff.diff(_GameStepManager.originalStepData, currentStepData);
2181
+ if (data) {
2182
+ let dialoge = void 0;
2183
+ let requiredChoices = void 0;
2184
+ if (GameStorageManager.getVariable(GameStorageManager.keysSystem.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY) === _GameStepManager.lastStepIndex) {
2185
+ dialoge = getDialogue();
2186
+ }
2187
+ if (GameStorageManager.getVariable(GameStorageManager.keysSystem.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY) === _GameStepManager.lastStepIndex) {
2188
+ requiredChoices = GameStorageManager.getVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY);
2189
+ }
2190
+ _GameStepManager._stepsHistory.push({
2191
+ diff: data,
2192
+ currentLabel: _GameStepManager.currentLabelId,
2193
+ dialoge,
2194
+ choices: requiredChoices,
2195
+ stepSha1: stepHistory,
2196
+ index: _GameStepManager.lastStepIndex,
2197
+ choiceIndexMade: choiseMade
2198
+ });
2199
+ _GameStepManager.originalStepData = currentStepData;
2200
+ }
2201
+ _GameStepManager.increaseLastStepIndex();
2202
+ }
2203
+ /**
2204
+ * Add a label to the history.
2205
+ * @param label The label to add to the history.
2206
+ */
2207
+ static pushNewLabel(label) {
2208
+ let currentLabel = getLabelById(label);
2209
+ if (!currentLabel) {
2210
+ throw new Error(`[Pixi'VN] Label ${label} not found`);
2211
+ }
2212
+ _GameStepManager._openedLabels.push({
2213
+ label,
2214
+ currentStepIndex: 0
2215
+ });
2216
+ }
2217
+ /**
2218
+ * Close the current label and add it to the history.
2219
+ * @returns
2220
+ */
2221
+ static closeCurrentLabel() {
2222
+ if (!_GameStepManager.currentLabelId) {
2223
+ console.warn("[Pixi'VN] No label to close");
2224
+ return;
2225
+ }
2226
+ if (!_GameStepManager.currentLabel) {
2227
+ console.error("[Pixi'VN] currentLabel not found");
2228
+ return;
2229
+ }
2230
+ _GameStepManager._openedLabels.pop();
2231
+ }
2232
+ /**
2233
+ * Close all labels and add them to the history. **Attention: This method can cause an unhandled game ending.**
2234
+ */
2235
+ static closeAllLabels() {
2236
+ while (_GameStepManager._openedLabels.length > 0) {
2237
+ _GameStepManager.closeCurrentLabel();
2238
+ }
2239
+ }
2240
+ /**
2241
+ * Increase the current step index of the current label.
2242
+ */
2243
+ static increaseCurrentStepIndex() {
2244
+ let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
2245
+ _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1] = __spreadProps(__spreadValues({}, item), {
2246
+ currentStepIndex: item.currentStepIndex + 1
2247
+ });
2248
+ }
2249
+ static restorLastLabelList() {
2250
+ _GameStepManager._openedLabels = _GameStepManager.originalStepData.openedLabels;
2251
+ }
2252
+ /* Run Methods */
2253
+ static get canGoNext() {
2254
+ let options = getChoiceMenuOptions();
2255
+ if (options && options.length > 0) {
2256
+ return false;
2257
+ }
2258
+ return true;
2259
+ }
2260
+ /**
2261
+ * Execute the next step and add it to the history.
2262
+ * @param props The props to pass to the step.
2263
+ * @param choiseMade The index of the choise made by the player. (This params is used in the choice menu)
2264
+ * @returns StepLabelResultType or undefined.
2265
+ * @example
2266
+ * ```typescript
2267
+ * function nextOnClick() {
2268
+ * setLoading(true)
2269
+ * GameStepManager.goNext(yourParams)
2270
+ * .then((result) => {
2271
+ * setUpdate((p) => p + 1)
2272
+ * setLoading(false)
2273
+ * if (result) {
2274
+ * // your code
2275
+ * }
2276
+ * })
2277
+ * .catch((e) => {
2278
+ * setLoading(false)
2279
+ * console.error(e)
2280
+ * })
2281
+ * }
2282
+ * ```
2283
+ */
2284
+ static goNext(props, choiseMade) {
2285
+ return __async(this, null, function* () {
2286
+ if (!_GameStepManager.canGoNext) {
2287
+ console.warn("[Pixi'VN] The player must make a choice");
2288
+ return;
2289
+ }
2290
+ if (_GameStepManager.currentLabel && _GameStepManager.currentLabel.onStepEnd) {
2291
+ yield _GameStepManager.currentLabel.onStepEnd(_GameStepManager.currentLabelStepIndex || 0, _GameStepManager.currentLabel);
2292
+ }
2293
+ _GameStepManager.increaseCurrentStepIndex();
2294
+ return yield _GameStepManager.runCurrentStep(props, choiseMade);
2295
+ });
2296
+ }
2297
+ /**
2298
+ * Execute the current step and add it to the history.
2299
+ * @param props The props to pass to the step.
2300
+ * @param choiseMade The choise made by the player.
2301
+ * @returns StepLabelResultType or undefined.
2302
+ */
2303
+ static runCurrentStep(props, choiseMade) {
2304
+ return __async(this, null, function* () {
2305
+ if (_GameStepManager.currentLabelId) {
2306
+ let currentLabelStepIndex = _GameStepManager.currentLabelStepIndex;
2307
+ if (currentLabelStepIndex === null) {
2308
+ console.error("[Pixi'VN] currentLabelStepIndex is null");
2309
+ return;
2310
+ }
2311
+ let currentLabel = _GameStepManager.currentLabel;
2312
+ if (!currentLabel) {
2313
+ console.error("[Pixi'VN] currentLabel not found");
2314
+ return;
2315
+ }
2316
+ if (currentLabel.steps.length > currentLabelStepIndex) {
2317
+ let onStepRun = currentLabel.onStepStart;
2318
+ if (onStepRun) {
2319
+ yield onStepRun(currentLabelStepIndex, currentLabel);
2320
+ }
2321
+ let step = currentLabel.steps[currentLabelStepIndex];
2322
+ let result = yield step(props);
2323
+ _GameStepManager.addStepHistory(step, choiseMade);
2324
+ return result;
2325
+ } else if (_GameStepManager.openedLabels.length > 1) {
2326
+ _GameStepManager.closeCurrentLabel();
2327
+ return yield _GameStepManager.goNext(props, choiseMade);
2328
+ } else {
2329
+ _GameStepManager.restorLastLabelList();
2330
+ 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");
2331
+ return;
2332
+ }
2333
+ }
2334
+ });
2335
+ }
2336
+ /**
2337
+ * Execute the label and add it to the history. (It's similar to Ren'Py's call function)
2338
+ * @param label The label to execute or the id of the label
2339
+ * @param props The props to pass to the label.
2340
+ * @returns StepLabelResultType or undefined.
2341
+ * @example
2342
+ * ```typescript
2343
+ * GameStepManager.callLabel(startLabel, yourParams).then((result) => {
2344
+ * if (result) {
2345
+ * // your code
2346
+ * }
2347
+ * })
2348
+ * ```
2349
+ * @example
2350
+ * ```typescript
2351
+ * // if you use it in a step label you should return the result.
2352
+ * return GameStepManager.callLabel(startLabel).then((result) => {
2353
+ * return result
2354
+ * })
2355
+ * ```
2356
+ */
2357
+ static callLabel(label, props) {
2358
+ return __async(this, null, function* () {
2359
+ let choiseMade = void 0;
2360
+ let labelId;
2361
+ if (typeof label === "string") {
2362
+ labelId = label;
2363
+ } else {
2364
+ labelId = label.id;
2365
+ if (typeof label.choiseIndex === "number") {
2366
+ choiseMade = label.choiseIndex;
2367
+ }
2368
+ }
2369
+ try {
2370
+ if (labelId === CLOSE_LABEL_ID) {
2371
+ let closeCurrentLabel = newCloseLabel(choiseMade);
2372
+ let choice = {
2373
+ label: closeCurrentLabel,
2374
+ text: "",
2375
+ closeCurrentLabel: false,
2376
+ type: "close",
2377
+ props: {}
2378
+ };
2379
+ return _GameStepManager.closeChoiceMenu(choice, props);
2380
+ }
2381
+ let tempLabel = getLabelById(labelId);
2382
+ if (!tempLabel) {
2383
+ throw new Error(`[Pixi'VN] Label ${labelId} not found`);
2384
+ }
2385
+ if (_GameStepManager.currentLabel && _GameStepManager.currentLabel.onStepEnd) {
2386
+ yield _GameStepManager.currentLabel.onStepEnd(_GameStepManager.currentLabelStepIndex || 0, _GameStepManager.currentLabel);
2387
+ }
2388
+ _GameStepManager.pushNewLabel(tempLabel.id);
2389
+ } catch (e) {
2390
+ console.error("[Pixi'VN] Error calling label", e);
2391
+ return;
2392
+ }
2393
+ return yield _GameStepManager.runCurrentStep(props, choiseMade);
2394
+ });
2395
+ }
2396
+ /**
2397
+ * 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)
2398
+ * @param label The label to execute.
2399
+ * @param props The props to pass to the label or the id of the label
2400
+ * @returns StepLabelResultType or undefined.
2401
+ * @example
2402
+ * ```typescript
2403
+ * GameStepManager.jumpLabel(startLabel, yourParams).then((result) => {
2404
+ * if (result) {
2405
+ * // your code
2406
+ * }
2407
+ * })
2408
+ * ```
2409
+ * @example
2410
+ * ```typescript
2411
+ * // if you use it in a step label you should return the result.
2412
+ * return GameStepManager.jumpLabel(startLabel).then((result) => {
2413
+ * return result
2414
+ * })
2415
+ * ```
2416
+ */
2417
+ static jumpLabel(label, props) {
2418
+ return __async(this, null, function* () {
2419
+ _GameStepManager.closeCurrentLabel();
2420
+ let choiseMade = void 0;
2421
+ let labelId;
2422
+ if (typeof label === "string") {
2423
+ labelId = label;
2424
+ } else {
2425
+ labelId = label.id;
2426
+ if (typeof label.choiseIndex === "number") {
2427
+ choiseMade = label.choiseIndex;
2428
+ }
2429
+ }
2430
+ try {
2431
+ if (labelId === CLOSE_LABEL_ID) {
2432
+ let closeCurrentLabel = newCloseLabel(choiseMade);
2433
+ let choice = {
2434
+ label: closeCurrentLabel,
2435
+ text: "",
2436
+ closeCurrentLabel: false,
2437
+ type: "close",
2438
+ props: {}
2439
+ };
2440
+ return _GameStepManager.closeChoiceMenu(choice, props);
2441
+ }
2442
+ let tempLabel = getLabelById(labelId);
2443
+ if (!tempLabel) {
2444
+ throw new Error(`[Pixi'VN] Label ${labelId} not found`);
2445
+ }
2446
+ if (_GameStepManager.currentLabel && _GameStepManager.currentLabel.onStepEnd) {
2447
+ yield _GameStepManager.currentLabel.onStepEnd(_GameStepManager.currentLabelStepIndex || 0, _GameStepManager.currentLabel);
2448
+ }
2449
+ _GameStepManager.pushNewLabel(tempLabel.id);
2450
+ } catch (e) {
2451
+ console.error("[Pixi'VN] Error jumping label", e);
2452
+ return;
2453
+ }
2454
+ return yield _GameStepManager.runCurrentStep(props, choiseMade);
2455
+ });
2456
+ }
2457
+ /**
2458
+ * When the player is in a choice menu, can use this function to exit to the choice menu.
2459
+ * @param choice
2460
+ * @param props
2461
+ * @returns StepLabelResultType or undefined.
2462
+ * @example
2463
+ * ```typescript
2464
+ * GameStepManager.closeChoiceMenu(yourParams).then((result) => {
2465
+ * if (result) {
2466
+ * // your code
2467
+ * }
2468
+ * })
2469
+ * ```
2470
+ */
2471
+ static closeChoiceMenu(choice, props) {
2472
+ return __async(this, null, function* () {
2473
+ let label = choice.label;
2474
+ let choiseMade = void 0;
2475
+ if (typeof label.choiseIndex === "number") {
2476
+ choiseMade = label.choiseIndex;
2477
+ }
2478
+ if (choice.closeCurrentLabel) {
2479
+ _GameStepManager.closeCurrentLabel();
2480
+ }
2481
+ return _GameStepManager.goNext(props, choiseMade);
2482
+ });
2483
+ }
2484
+ /* After Update Methods */
2485
+ // /**
2486
+ // * After the update or code edit, some steps or labels may no longer match.
2487
+ // * - In case of step mismatch, the game will be updated to the last matching step.
2488
+ // * - In case of label mismatch, the game gives an error.
2489
+ // * @returns
2490
+ // */
2491
+ // private static afterUpdate() {
2492
+ // // TODO: implement
2493
+ // if (!GameStepManager.currentLabel) {
2494
+ // // TODO: implement
2495
+ // return
2496
+ // }
2497
+ // let currentLabel = getLabelInstanceByClassName(GameStepManager.currentLabel)
2498
+ // if (!currentLabel) {
2499
+ // console.error("Label not found")
2500
+ // return
2501
+ // }
2502
+ // let oldSteps = GameStepManager.stepsAfterLastHistoryLabel
2503
+ // let currentStepIndex = currentLabel.getCorrespondingStepsNumber(oldSteps)
2504
+ // let stepToRemove = oldSteps.length - currentStepIndex
2505
+ // GameStepManager.removeLastHistoryNodes(stepToRemove)
2506
+ // GameStepManager.loadLastStep()
2507
+ // }
2508
+ // private static loadLastStep() {
2509
+ // // TODO: implement
2510
+ // }
2511
+ // /**
2512
+ // * Remove a number of items from the last of the history.
2513
+ // * @param itemNumber The number of items to remove from the last of the history.
2514
+ // */
2515
+ // private static removeLastHistoryNodes(itemNumber: number) {
2516
+ // // TODO: implement
2517
+ // for (let i = 0; i < itemNumber; i++) {
2518
+ // GameStepManager._stepsHistory.pop()
2519
+ // }
2520
+ // }
2521
+ // /**
2522
+ // * stepsAfterLastHistoryLabel is a list of steps that occurred after the last history label.
2523
+ // */
2524
+ // private static get stepsAfterLastHistoryLabel(): StepHistoryDataType[] {
2525
+ // let length = GameStepManager._stepsHistory.length
2526
+ // let steps: StepHistoryDataType[] = []
2527
+ // for (let i = length - 1; i >= 0; i--) {
2528
+ // let element = GameStepManager._stepsHistory[i]
2529
+ // if (typeof element === "object" && "stepSha1" in element) {
2530
+ // steps.push(element.stepSha1)
2531
+ // }
2532
+ // else {
2533
+ // break
2534
+ // }
2535
+ // }
2536
+ // steps = steps.reverse()
2537
+ // return steps
2538
+ // }
2539
+ /* Go Back & Refresh Methods */
2540
+ /**
2541
+ * Go back to the last step and add it to the history.
2542
+ * @param navigate The navigate function.
2543
+ * @param steps The number of steps to go back.
2544
+ * @returns
2545
+ * @example
2546
+ * ```typescript
2547
+ * export function goBack(navigate: (path: string) => void, afterBack?: () => void) {
2548
+ * GameStepManager.goBack(navigate)
2549
+ * afterBack && afterBack()
2550
+ * }
2551
+ * ```
2552
+ */
2553
+ static goBack(navigate, steps = 1) {
2554
+ return __async(this, null, function* () {
2555
+ if (steps <= 0) {
2556
+ console.warn("[Pixi'VN] Steps must be greater than 0");
2557
+ return;
2558
+ }
2559
+ if (_GameStepManager._stepsHistory.length <= 1) {
2560
+ console.warn("[Pixi'VN] No steps to go back");
2561
+ return;
2562
+ }
2563
+ let restoredStep = _GameStepManager.goBackInternal(steps, _GameStepManager.originalStepData);
2564
+ if (restoredStep) {
2565
+ _GameStepManager._originalStepData = restoredStep;
2566
+ _GameStepManager._openedLabels = createExportableElement(restoredStep.openedLabels);
2567
+ if (_GameStepManager.currentLabel && _GameStepManager.currentLabel.onLoadStep) {
2568
+ yield _GameStepManager.currentLabel.onLoadStep(_GameStepManager.currentLabelStepIndex || 0, _GameStepManager.currentLabel);
2569
+ }
2570
+ GameStorageManager.import(createExportableElement(restoredStep.storage));
2571
+ GameWindowManager.import(createExportableElement(restoredStep.canvas));
2572
+ navigate(restoredStep.path);
2573
+ } else {
2574
+ console.error("[Pixi'VN] Error going back");
2575
+ }
2576
+ });
2577
+ }
2578
+ static goBackInternal(steps, restoredStep) {
2579
+ if (steps <= 0) {
2580
+ return restoredStep;
2581
+ }
2582
+ if (_GameStepManager._stepsHistory.length == 0) {
2583
+ return restoredStep;
2584
+ }
2585
+ let lastHistoryStep = _GameStepManager.lastHistoryStep;
2586
+ if (lastHistoryStep) {
2587
+ try {
2588
+ let result = restoreDeepDiffChanges(restoredStep, lastHistoryStep.diff);
2589
+ _GameStepManager._lastStepIndex = lastHistoryStep.index;
2590
+ _GameStepManager._stepsHistory.pop();
2591
+ return _GameStepManager.goBackInternal(steps - 1, result);
2592
+ } catch (e) {
2593
+ console.error("[Pixi'VN] Error applying diff", e);
2594
+ return restoredStep;
2595
+ }
2596
+ } else {
2597
+ return restoredStep;
2598
+ }
2599
+ }
2600
+ /**
2601
+ * Return true if it is possible to go back.
2602
+ */
2603
+ static get canGoBack() {
2604
+ return _GameStepManager._stepsHistory.length > 1;
2605
+ }
2606
+ /**
2607
+ * Add a label to the history.
2608
+ */
2609
+ static clear() {
2610
+ _GameStepManager._stepsHistory = [];
2611
+ _GameStepManager._openedLabels = [];
2612
+ }
2613
+ /* Export and Import Methods */
2614
+ /**
2615
+ * Export the history to a JSON string.
2616
+ * @returns The history in a JSON string.
2617
+ */
2618
+ static exportJson() {
2619
+ return JSON.stringify(this.export());
2620
+ }
2621
+ /**
2622
+ * Export the history to an object.
2623
+ * @returns The history in an object.
2624
+ */
2625
+ static export() {
2626
+ return {
2627
+ stepsHistory: _GameStepManager._stepsHistory,
2628
+ openedLabels: _GameStepManager._openedLabels,
2629
+ lastStepIndex: _GameStepManager._lastStepIndex,
2630
+ originalStepData: _GameStepManager._originalStepData
2631
+ };
2632
+ }
2633
+ /**
2634
+ * Import the history from a JSON string.
2635
+ * @param dataString The history in a JSON string.
2636
+ */
2637
+ static importJson(dataString) {
2638
+ return __async(this, null, function* () {
2639
+ yield _GameStepManager.import(JSON.parse(dataString));
2640
+ });
2641
+ }
2642
+ /**
2643
+ * Import the history from an object.
2644
+ * @param data The history in an object.
2645
+ */
2646
+ static import(data) {
2647
+ return __async(this, null, function* () {
2648
+ _GameStepManager.clear();
2649
+ try {
2650
+ if (data.hasOwnProperty("stepsHistory")) {
2651
+ _GameStepManager._stepsHistory = data["stepsHistory"];
2652
+ } else {
2653
+ console.warn("[Pixi'VN] Could not import stepsHistory data, so will be ignored");
2654
+ }
2655
+ if (data.hasOwnProperty("openedLabels")) {
2656
+ _GameStepManager._openedLabels = data["openedLabels"];
2657
+ } else {
2658
+ console.warn("[Pixi'VN] Could not import openedLabels data, so will be ignored");
2659
+ }
2660
+ if (data.hasOwnProperty("lastStepIndex")) {
2661
+ _GameStepManager._lastStepIndex = data["lastStepIndex"];
2662
+ } else {
2663
+ console.warn("[Pixi'VN] Could not import lastStepIndex data, so will be ignored");
2664
+ }
2665
+ if (data.hasOwnProperty("originalStepData")) {
2666
+ _GameStepManager._originalStepData = data["originalStepData"];
2667
+ } else {
2668
+ console.warn("[Pixi'VN] Could not import originalStepData data, so will be ignored");
2669
+ }
2670
+ if (_GameStepManager.currentLabel && _GameStepManager.currentLabel.onLoadStep) {
2671
+ yield _GameStepManager.currentLabel.onLoadStep(_GameStepManager.currentLabelStepIndex || 0, _GameStepManager.currentLabel);
2672
+ }
2673
+ } catch (e) {
2674
+ console.error("[Pixi'VN] Error importing data", e);
2675
+ }
2676
+ });
2677
+ }
2678
+ };
2679
+ /**
2680
+ * stepHistory is a list of label events and steps that occurred during the progression of the steps.
2681
+ */
2682
+ _GameStepManager._stepsHistory = [];
2683
+ _GameStepManager._lastStepIndex = 0;
2684
+ _GameStepManager._openedLabels = [];
2685
+ _GameStepManager._originalStepData = void 0;
2686
+ var GameStepManager = _GameStepManager;
2687
+
1870
2688
  // src/classes/StoredClassModel.ts
1871
2689
  var StoredClassModel = class {
1872
2690
  /**
@@ -2027,12 +2845,61 @@ var DialogueBaseModel = class {
2027
2845
  }
2028
2846
  };
2029
2847
 
2848
+ // src/classes/LabelJson.ts
2849
+ var LabelJson2 = class extends LabelAbstract {
2850
+ /**
2851
+ * @param id is the id of the label
2852
+ * @param steps is the list of steps that the label will perform
2853
+ * @param props is the properties of the label
2854
+ */
2855
+ constructor(id, steps, props) {
2856
+ super(id, props);
2857
+ this._steps = steps;
2858
+ }
2859
+ /**
2860
+ * Get the steps of the label.
2861
+ */
2862
+ get steps() {
2863
+ if (typeof this._steps === "function") {
2864
+ return this._steps().map(this.stepConverter);
2865
+ }
2866
+ return this._steps.map(this.stepConverter);
2867
+ }
2868
+ stepConverter(step) {
2869
+ return (props) => {
2870
+ if (step.currentChoiceMenuOptions) {
2871
+ setChoiceMenuOptions(step.currentChoiceMenuOptions);
2872
+ } else {
2873
+ clearChoiceMenuOptions();
2874
+ }
2875
+ if (step.dialog) {
2876
+ setDialogue(step.dialog);
2877
+ } else {
2878
+ clearDialogue();
2879
+ }
2880
+ if (step.labelToOpen) {
2881
+ if (step.labelToOpen.type === "jump") {
2882
+ GameStepManager.jumpLabel(step.labelToOpen.labelId, props);
2883
+ } else {
2884
+ GameStepManager.callLabel(step.labelToOpen.labelId, props);
2885
+ }
2886
+ }
2887
+ if (step.end === "game_end") {
2888
+ console.warn("[Pixi'VN] Game end not implemented");
2889
+ } else if (step.end === "label_end") {
2890
+ GameStepManager.closeCurrentLabel();
2891
+ }
2892
+ };
2893
+ }
2894
+ };
2895
+
2030
2896
  exports.CanvasEvent = CanvasEvent;
2031
2897
  exports.CharacterBaseModel = CharacterBaseModel2;
2032
2898
  exports.ChoiceMenuOption = ChoiceMenuOption;
2033
2899
  exports.ChoiceMenuOptionClose = ChoiceMenuOptionClose;
2034
2900
  exports.DialogueBaseModel = DialogueBaseModel;
2035
2901
  exports.Label = Label;
2902
+ exports.LabelJson = LabelJson2;
2036
2903
  exports.StoredClassModel = StoredClassModel;
2037
2904
  //# sourceMappingURL=index.js.map
2038
2905
  //# sourceMappingURL=index.js.map