@drincs/pixi-vn 0.5.3 → 0.5.5

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 (142) hide show
  1. package/dist/classes/CharacterBaseModel.js +110 -112
  2. package/dist/classes/CharacterBaseModel.js.map +1 -1
  3. package/dist/classes/CharacterBaseModel.mjs +110 -112
  4. package/dist/classes/CharacterBaseModel.mjs.map +1 -1
  5. package/dist/classes/ChoiceMenuOption.d.mts +19 -7
  6. package/dist/classes/ChoiceMenuOption.d.ts +19 -7
  7. package/dist/classes/ChoiceMenuOption.js +1386 -9
  8. package/dist/classes/ChoiceMenuOption.js.map +1 -1
  9. package/dist/classes/ChoiceMenuOption.mjs +1386 -9
  10. package/dist/classes/ChoiceMenuOption.mjs.map +1 -1
  11. package/dist/classes/CloseLabel.d.mts +8 -5
  12. package/dist/classes/CloseLabel.d.ts +8 -5
  13. package/dist/classes/CloseLabel.js +44 -4
  14. package/dist/classes/CloseLabel.js.map +1 -1
  15. package/dist/classes/CloseLabel.mjs +41 -4
  16. package/dist/classes/CloseLabel.mjs.map +1 -1
  17. package/dist/classes/Label.d.mts +47 -21
  18. package/dist/classes/Label.d.ts +47 -21
  19. package/dist/classes/Label.js +36 -1
  20. package/dist/classes/Label.js.map +1 -1
  21. package/dist/classes/Label.mjs +36 -1
  22. package/dist/classes/Label.mjs.map +1 -1
  23. package/dist/classes/StoredClassModel.js +55 -57
  24. package/dist/classes/StoredClassModel.js.map +1 -1
  25. package/dist/classes/StoredClassModel.mjs +55 -57
  26. package/dist/classes/StoredClassModel.mjs.map +1 -1
  27. package/dist/classes/index.d.mts +2 -2
  28. package/dist/classes/index.d.ts +2 -2
  29. package/dist/classes/index.js +125 -73
  30. package/dist/classes/index.js.map +1 -1
  31. package/dist/classes/index.mjs +125 -73
  32. package/dist/classes/index.mjs.map +1 -1
  33. package/dist/classes/ticker/TickerFadeAlpha.js +27 -27
  34. package/dist/classes/ticker/TickerFadeAlpha.js.map +1 -1
  35. package/dist/classes/ticker/TickerFadeAlpha.mjs +27 -27
  36. package/dist/classes/ticker/TickerFadeAlpha.mjs.map +1 -1
  37. package/dist/classes/ticker/TickerMove.js +57 -55
  38. package/dist/classes/ticker/TickerMove.js.map +1 -1
  39. package/dist/classes/ticker/TickerMove.mjs +57 -55
  40. package/dist/classes/ticker/TickerMove.mjs.map +1 -1
  41. package/dist/classes/ticker/TickerRotate.js +57 -55
  42. package/dist/classes/ticker/TickerRotate.js.map +1 -1
  43. package/dist/classes/ticker/TickerRotate.mjs +57 -55
  44. package/dist/classes/ticker/TickerRotate.mjs.map +1 -1
  45. package/dist/classes/ticker/index.js +17 -17
  46. package/dist/classes/ticker/index.js.map +1 -1
  47. package/dist/classes/ticker/index.mjs +17 -17
  48. package/dist/classes/ticker/index.mjs.map +1 -1
  49. package/dist/constants.d.mts +1 -1
  50. package/dist/constants.d.ts +1 -1
  51. package/dist/constants.js +1 -1
  52. package/dist/constants.js.map +1 -1
  53. package/dist/constants.mjs +1 -1
  54. package/dist/constants.mjs.map +1 -1
  55. package/dist/decorators/LabelDecorator.d.mts +13 -20
  56. package/dist/decorators/LabelDecorator.d.ts +13 -20
  57. package/dist/decorators/LabelDecorator.js +1388 -28
  58. package/dist/decorators/LabelDecorator.js.map +1 -1
  59. package/dist/decorators/LabelDecorator.mjs +1388 -25
  60. package/dist/decorators/LabelDecorator.mjs.map +1 -1
  61. package/dist/decorators/index.d.mts +4 -4
  62. package/dist/decorators/index.d.ts +4 -4
  63. package/dist/decorators/index.js +1385 -13
  64. package/dist/decorators/index.js.map +1 -1
  65. package/dist/decorators/index.mjs +1384 -13
  66. package/dist/decorators/index.mjs.map +1 -1
  67. package/dist/functions/DialogueUtility.d.mts +7 -7
  68. package/dist/functions/DialogueUtility.d.ts +7 -7
  69. package/dist/functions/DialogueUtility.js +96 -68
  70. package/dist/functions/DialogueUtility.js.map +1 -1
  71. package/dist/functions/DialogueUtility.mjs +96 -68
  72. package/dist/functions/DialogueUtility.mjs.map +1 -1
  73. package/dist/functions/FlagsUtility.js +55 -57
  74. package/dist/functions/FlagsUtility.js.map +1 -1
  75. package/dist/functions/FlagsUtility.mjs +55 -57
  76. package/dist/functions/FlagsUtility.mjs.map +1 -1
  77. package/dist/functions/GameUtility.js +55 -57
  78. package/dist/functions/GameUtility.js.map +1 -1
  79. package/dist/functions/GameUtility.mjs +55 -57
  80. package/dist/functions/GameUtility.mjs.map +1 -1
  81. package/dist/functions/ImageUtility.js +17 -17
  82. package/dist/functions/ImageUtility.js.map +1 -1
  83. package/dist/functions/ImageUtility.mjs +17 -17
  84. package/dist/functions/ImageUtility.mjs.map +1 -1
  85. package/dist/functions/SavesUtility.d.mts +2 -2
  86. package/dist/functions/SavesUtility.d.ts +2 -2
  87. package/dist/functions/SavesUtility.js +113 -141
  88. package/dist/functions/SavesUtility.js.map +1 -1
  89. package/dist/functions/SavesUtility.mjs +113 -141
  90. package/dist/functions/SavesUtility.mjs.map +1 -1
  91. package/dist/functions/StepLabelUtility.d.mts +0 -1
  92. package/dist/functions/StepLabelUtility.d.ts +0 -1
  93. package/dist/functions/index.d.mts +4 -4
  94. package/dist/functions/index.d.ts +4 -4
  95. package/dist/functions/index.js +97 -69
  96. package/dist/functions/index.js.map +1 -1
  97. package/dist/functions/index.mjs +97 -69
  98. package/dist/functions/index.mjs.map +1 -1
  99. package/dist/index.d.mts +3 -3
  100. package/dist/index.d.ts +3 -3
  101. package/dist/index.js +359 -327
  102. package/dist/index.js.map +1 -1
  103. package/dist/index.mjs +358 -327
  104. package/dist/index.mjs.map +1 -1
  105. package/dist/interface/{IDialogueHistory.d.mts → DialogueHistory.d.mts} +5 -5
  106. package/dist/interface/{IDialogueHistory.d.ts → DialogueHistory.d.ts} +5 -5
  107. package/dist/interface/{IDialogueHistory.js → DialogueHistory.js} +1 -1
  108. package/dist/interface/DialogueHistory.mjs +3 -0
  109. package/dist/interface/IHistoryStep.d.mts +2 -2
  110. package/dist/interface/IHistoryStep.d.ts +2 -2
  111. package/dist/interface/ISaveData.d.mts +2 -2
  112. package/dist/interface/ISaveData.d.ts +2 -2
  113. package/dist/interface/export/ExportedStep.d.mts +2 -2
  114. package/dist/interface/export/ExportedStep.d.ts +2 -2
  115. package/dist/interface/export/index.d.mts +2 -2
  116. package/dist/interface/export/index.d.ts +2 -2
  117. package/dist/interface/index.d.mts +6 -6
  118. package/dist/interface/index.d.ts +6 -6
  119. package/dist/managers/StepManager.d.mts +12 -12
  120. package/dist/managers/StepManager.d.ts +12 -12
  121. package/dist/managers/StepManager.js +53 -79
  122. package/dist/managers/StepManager.js.map +1 -1
  123. package/dist/managers/StepManager.mjs +53 -79
  124. package/dist/managers/StepManager.mjs.map +1 -1
  125. package/dist/managers/WindowManager.d.mts +1 -1
  126. package/dist/managers/WindowManager.d.ts +1 -1
  127. package/dist/managers/index.d.mts +2 -2
  128. package/dist/managers/index.d.ts +2 -2
  129. package/dist/managers/index.js +112 -140
  130. package/dist/managers/index.js.map +1 -1
  131. package/dist/managers/index.mjs +112 -140
  132. package/dist/managers/index.mjs.map +1 -1
  133. package/dist/types/ChoiceMenuOptionsType.d.mts +3 -3
  134. package/dist/types/ChoiceMenuOptionsType.d.ts +3 -3
  135. package/dist/types/StepLabelType.d.mts +2 -3
  136. package/dist/types/StepLabelType.d.ts +2 -3
  137. package/dist/types/index.d.mts +1 -1
  138. package/dist/types/index.d.ts +1 -1
  139. package/package.json +2 -2
  140. package/dist/interface/IDialogueHistory.mjs +0 -3
  141. /package/dist/interface/{IDialogueHistory.js.map → DialogueHistory.js.map} +0 -0
  142. /package/dist/interface/{IDialogueHistory.mjs.map → DialogueHistory.mjs.map} +0 -0
@@ -61,13 +61,31 @@ function checkIfStepsIsEqual(step1, step2) {
61
61
 
62
62
  // src/classes/Label.ts
63
63
  var Label = class {
64
+ /**
65
+ * @param id is the id of the label
66
+ * @param steps is the list of steps that the label will perform
67
+ * @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
68
+ * @param choiseIndex is the index of the choice that the label will perform
69
+ */
70
+ constructor(id, steps, onStepRun, choiseIndex) {
71
+ this._id = id;
72
+ this._steps = steps;
73
+ this._onStepRun = onStepRun;
74
+ this._choiseIndex = choiseIndex;
75
+ }
76
+ /**
77
+ * Get the id of the label
78
+ */
79
+ get id() {
80
+ return this._id;
81
+ }
64
82
  /**
65
83
  * Get the steps of the label.
66
84
  * This class should be extended and the steps method should be overridden.
67
85
  * Every time you update this list will also be updated when the other game versions load.
68
86
  */
69
87
  get steps() {
70
- throw new Error("[Pixi'VN] The method Label.steps must be overridden");
88
+ return this._steps;
71
89
  }
72
90
  /**
73
91
  * Get the corresponding steps number
@@ -86,45 +104,40 @@ var Label = class {
86
104
  });
87
105
  return res;
88
106
  }
107
+ /**
108
+ * 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
109
+ * @returns Promise<void> or void
110
+ * @example
111
+ * ```typescript
112
+ * newLabel("id", [], () => {
113
+ * Assets.load('path/to/image1.png')
114
+ * Assets.load('path/to/image2.png')
115
+ * })
116
+ * ```
117
+ */
118
+ get onStepRun() {
119
+ return this._onStepRun;
120
+ }
121
+ get choiseIndex() {
122
+ return this._choiseIndex;
123
+ }
89
124
  };
90
125
 
91
126
  // src/classes/CloseLabel.ts
92
- var CloseLabel = class extends Label {
93
- };
127
+ var CLOSE_LABEL_ID = "__close-label-id__";
128
+ function newCloseLabel(choiseIndex) {
129
+ return new Label(CLOSE_LABEL_ID, [], void 0, choiseIndex);
130
+ }
94
131
 
95
132
  // src/decorators/LabelDecorator.ts
96
133
  var registeredLabels = {};
97
- function getLabelTypeByClassName(labelName) {
98
- try {
99
- let labelType = registeredLabels[labelName];
100
- if (!labelType) {
101
- console.error(`[Pixi'VN] Label ${labelName} not found`);
102
- return;
103
- }
104
- new labelType();
105
- return labelType;
106
- } catch (e) {
107
- console.error(`[Pixi'VN] Error while getting Label ${labelName}`, e);
108
- return;
109
- }
110
- }
111
- function getLabelInstanceByClassName(labelName) {
112
- try {
113
- let labelType = registeredLabels[labelName];
114
- if (!labelType) {
115
- console.error(`[Pixi'VN] Label ${labelName} not found`);
116
- return;
117
- }
118
- let label = new labelType();
119
- let step = label.steps;
120
- if (step.length = 0) {
121
- console.warn(`[Pixi'VN] Label ${labelName} has no steps`);
122
- }
123
- return label;
124
- } catch (e) {
125
- console.error(`[Pixi'VN] Error while getting Label ${labelName}`, e);
134
+ function getLabelById(id) {
135
+ let label = registeredLabels[id];
136
+ if (!label) {
137
+ console.error(`[Pixi'VN] Label ${id} not found`);
126
138
  return;
127
139
  }
140
+ return label;
128
141
  }
129
142
 
130
143
  // src/decorators/CanvasElementDecorator.ts
@@ -1561,7 +1574,7 @@ var _GameStepManager = class _GameStepManager {
1561
1574
  */
1562
1575
  static get currentLabel() {
1563
1576
  if (_GameStepManager.currentLabelId) {
1564
- return getLabelInstanceByClassName(_GameStepManager.currentLabelId);
1577
+ return getLabelById(_GameStepManager.currentLabelId);
1565
1578
  }
1566
1579
  }
1567
1580
  static get currentLabelStepIndex() {
@@ -1582,7 +1595,7 @@ var _GameStepManager = class _GameStepManager {
1582
1595
  return true;
1583
1596
  } else {
1584
1597
  this.openedLabels.forEach((item) => {
1585
- let label = getLabelInstanceByClassName(item.label);
1598
+ let label = getLabelById(item.label);
1586
1599
  if (label && label.steps.length > item.currentStepIndex) {
1587
1600
  return false;
1588
1601
  }
@@ -1675,9 +1688,9 @@ var _GameStepManager = class _GameStepManager {
1675
1688
  * @param label The label to add to the history.
1676
1689
  */
1677
1690
  static pushNewLabel(label) {
1678
- let currentLabel = getLabelInstanceByClassName(label);
1691
+ let currentLabel = getLabelById(label);
1679
1692
  if (!currentLabel) {
1680
- throw new Error("[Pixi'VN] Label not found");
1693
+ throw new Error(`[Pixi'VN] Label ${label} not found`);
1681
1694
  }
1682
1695
  _GameStepManager._openedLabels.push({
1683
1696
  label,
@@ -1694,7 +1707,7 @@ var _GameStepManager = class _GameStepManager {
1694
1707
  return;
1695
1708
  }
1696
1709
  if (!_GameStepManager.currentLabel) {
1697
- console.error("[Pixi'VN] Label not found");
1710
+ console.error("[Pixi'VN] currentLabel not found");
1698
1711
  return;
1699
1712
  }
1700
1713
  _GameStepManager._openedLabels.pop();
@@ -1766,7 +1779,7 @@ var _GameStepManager = class _GameStepManager {
1766
1779
  }
1767
1780
  let currentLabel = _GameStepManager.currentLabel;
1768
1781
  if (!currentLabel) {
1769
- console.error("[Pixi'VN] Label not found");
1782
+ console.error("[Pixi'VN] currentLabel not found");
1770
1783
  return;
1771
1784
  }
1772
1785
  let n = currentLabel.steps.length;
@@ -1787,12 +1800,12 @@ var _GameStepManager = class _GameStepManager {
1787
1800
  /**
1788
1801
  * Execute the label and add it to the history.
1789
1802
  * Is a call function in Ren'Py.
1790
- * @param label The label to execute.
1803
+ * @param label The label to execute or the id of the label
1791
1804
  * @param props The props to pass to the label.
1792
1805
  * @returns StepLabelResultType or undefined.
1793
1806
  * @example
1794
1807
  * ```typescript
1795
- * GameStepManager.callLabel(StartLabel, yourParams).then((result) => {
1808
+ * GameStepManager.callLabel(startLabel, yourParams).then((result) => {
1796
1809
  * if (result) {
1797
1810
  * // your code
1798
1811
  * }
@@ -1801,7 +1814,7 @@ var _GameStepManager = class _GameStepManager {
1801
1814
  * @example
1802
1815
  * ```typescript
1803
1816
  * // if you use it in a step label you should return the result.
1804
- * return GameStepManager.callLabel(StartLabel).then((result) => {
1817
+ * return GameStepManager.callLabel(startLabel).then((result) => {
1805
1818
  * return result
1806
1819
  * })
1807
1820
  * ```
@@ -1809,16 +1822,24 @@ var _GameStepManager = class _GameStepManager {
1809
1822
  static callLabel(label, props) {
1810
1823
  return __async(this, null, function* () {
1811
1824
  let choiseMade = void 0;
1825
+ let labelId;
1826
+ if (typeof label === "string") {
1827
+ labelId = label;
1828
+ } else {
1829
+ labelId = label.id;
1830
+ if (typeof label.choiseIndex === "number") {
1831
+ choiseMade = label.choiseIndex;
1832
+ }
1833
+ }
1812
1834
  try {
1813
- if (label instanceof CloseLabel) {
1835
+ if (labelId === CLOSE_LABEL_ID) {
1814
1836
  return _GameStepManager.runNextStep(props);
1815
1837
  }
1816
- if (label instanceof Label) {
1817
- choiseMade = label.choiseIndex;
1818
- label = label.constructor;
1838
+ let tempLabel = getLabelById(labelId);
1839
+ if (!tempLabel) {
1840
+ throw new Error(`[Pixi'VN] Label ${labelId} not found`);
1819
1841
  }
1820
- let labelName = label.name;
1821
- _GameStepManager.pushNewLabel(labelName);
1842
+ _GameStepManager.pushNewLabel(tempLabel.id);
1822
1843
  } catch (e) {
1823
1844
  console.error("[Pixi'VN] Error calling label", e);
1824
1845
  return;
@@ -1830,11 +1851,11 @@ var _GameStepManager = class _GameStepManager {
1830
1851
  * Execute the label, close all labels and add them to the history.
1831
1852
  * Is a jump function in Ren'Py.
1832
1853
  * @param label The label to execute.
1833
- * @param props The props to pass to the label.
1854
+ * @param props The props to pass to the label or the id of the label
1834
1855
  * @returns StepLabelResultType or undefined.
1835
1856
  * @example
1836
1857
  * ```typescript
1837
- * GameStepManager.jumpLabel(StartLabel, yourParams).then((result) => {
1858
+ * GameStepManager.jumpLabel(startLabel, yourParams).then((result) => {
1838
1859
  * if (result) {
1839
1860
  * // your code
1840
1861
  * }
@@ -1843,7 +1864,7 @@ var _GameStepManager = class _GameStepManager {
1843
1864
  * @example
1844
1865
  * ```typescript
1845
1866
  * // if you use it in a step label you should return the result.
1846
- * return GameStepManager.jumpLabel(StartLabel).then((result) => {
1867
+ * return GameStepManager.jumpLabel(startLabel).then((result) => {
1847
1868
  * return result
1848
1869
  * })
1849
1870
  * ```
@@ -1851,15 +1872,24 @@ var _GameStepManager = class _GameStepManager {
1851
1872
  static jumpLabel(label, props) {
1852
1873
  return __async(this, null, function* () {
1853
1874
  _GameStepManager.closeAllLabels();
1875
+ let labelId;
1876
+ if (typeof label === "string") {
1877
+ labelId = label;
1878
+ } else {
1879
+ labelId = label.id;
1880
+ if (typeof label.choiseIndex === "number") {
1881
+ label.choiseIndex;
1882
+ }
1883
+ }
1854
1884
  try {
1855
- if (label instanceof CloseLabel) {
1885
+ if (labelId === CLOSE_LABEL_ID) {
1856
1886
  return _GameStepManager.runNextStep(props);
1857
1887
  }
1858
- if (label instanceof Label) {
1859
- label = label.constructor;
1888
+ let tempLabel = getLabelById(labelId);
1889
+ if (!tempLabel) {
1890
+ throw new Error(`[Pixi'VN] Label ${labelId} not found`);
1860
1891
  }
1861
- let labelName = label.name;
1862
- _GameStepManager.pushNewLabel(labelName);
1892
+ _GameStepManager.pushNewLabel(tempLabel.id);
1863
1893
  } catch (e) {
1864
1894
  console.error("[Pixi'VN] Error jumping label", e);
1865
1895
  return;
@@ -2089,7 +2119,7 @@ var ChoiceMenuOptionClose = class {
2089
2119
  /**
2090
2120
  * Label to be opened when the option is selected
2091
2121
  */
2092
- this.label = new CloseLabel();
2122
+ this.label = newCloseLabel();
2093
2123
  /**
2094
2124
  * Type of the label to be opened
2095
2125
  */
@@ -2103,7 +2133,7 @@ var ChoiceMenuOptionClose = class {
2103
2133
  };
2104
2134
 
2105
2135
  // src/classes/DialogueBaseModel.ts
2106
- var DialogueBaseModel2 = class {
2136
+ var DialogueBaseModel = class {
2107
2137
  /**
2108
2138
  * @param text The text of the dialogue.
2109
2139
  * @param character The id of the character that is speaking.
@@ -2155,8 +2185,8 @@ function setDialogue(props) {
2155
2185
  let dialogue;
2156
2186
  if (typeof props === "string") {
2157
2187
  text = props;
2158
- dialogue = new DialogueBaseModel2(text, characterId);
2159
- } else if (!(props instanceof DialogueBaseModel2)) {
2188
+ dialogue = new DialogueBaseModel(text, characterId);
2189
+ } else if (!(props instanceof DialogueBaseModel)) {
2160
2190
  text = props.text;
2161
2191
  if (props.character) {
2162
2192
  if (typeof props.character === "string") {
@@ -2165,7 +2195,7 @@ function setDialogue(props) {
2165
2195
  characterId = props.character.id;
2166
2196
  }
2167
2197
  }
2168
- dialogue = new DialogueBaseModel2(text, characterId);
2198
+ dialogue = new DialogueBaseModel(text, characterId);
2169
2199
  } else {
2170
2200
  dialogue = props;
2171
2201
  }
@@ -2187,7 +2217,7 @@ function setChoiceMenuOptions(options) {
2187
2217
  };
2188
2218
  }
2189
2219
  return __spreadProps(__spreadValues({}, option), {
2190
- label: option.label.constructor.name
2220
+ label: option.label.id
2191
2221
  });
2192
2222
  });
2193
2223
  GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, value);
@@ -2199,8 +2229,7 @@ function getChoiceMenuOptions() {
2199
2229
  let options = [];
2200
2230
  d.forEach((option, index) => {
2201
2231
  if (option.type === Close) {
2202
- let itemLabel = new CloseLabel();
2203
- itemLabel.choiseIndex = index;
2232
+ let itemLabel = newCloseLabel(index);
2204
2233
  options.push({
2205
2234
  text: option.text,
2206
2235
  label: itemLabel,
@@ -2209,10 +2238,9 @@ function getChoiceMenuOptions() {
2209
2238
  });
2210
2239
  return;
2211
2240
  }
2212
- let label = getLabelTypeByClassName(option.label);
2241
+ let label = getLabelById(option.label);
2213
2242
  if (label) {
2214
- let itemLabel = new label();
2215
- itemLabel.choiseIndex = index;
2243
+ let itemLabel = new Label(label.id, label.steps, label.onStepRun, index);
2216
2244
  options.push(__spreadProps(__spreadValues({}, option), {
2217
2245
  label: itemLabel
2218
2246
  }));
@@ -2235,7 +2263,7 @@ function getDialogueHistory() {
2235
2263
  if (oldChoices) {
2236
2264
  let choiceMade = false;
2237
2265
  if (step.choiceIndexMade !== void 0 && oldChoices.length > step.choiceIndexMade) {
2238
- oldChoices[step.choiceIndexMade].isMadeChoice = true;
2266
+ oldChoices[step.choiceIndexMade].isResponse = true;
2239
2267
  choiceMade = true;
2240
2268
  }
2241
2269
  list[list.length - 1].playerMadeChoice = choiceMade;
@@ -2247,7 +2275,7 @@ function getDialogueHistory() {
2247
2275
  return {
2248
2276
  text: choice.text,
2249
2277
  type: choice.type,
2250
- isMadeChoice: false
2278
+ isResponse: false
2251
2279
  };
2252
2280
  });
2253
2281
  list.push({