@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
@@ -67,13 +67,31 @@ function checkIfStepsIsEqual(step1, step2) {
67
67
 
68
68
  // src/classes/Label.ts
69
69
  var Label = class {
70
+ /**
71
+ * @param id is the id of the label
72
+ * @param steps is the list of steps that the label will perform
73
+ * @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
74
+ * @param choiseIndex is the index of the choice that the label will perform
75
+ */
76
+ constructor(id, steps, onStepRun, choiseIndex) {
77
+ this._id = id;
78
+ this._steps = steps;
79
+ this._onStepRun = onStepRun;
80
+ this._choiseIndex = choiseIndex;
81
+ }
82
+ /**
83
+ * Get the id of the label
84
+ */
85
+ get id() {
86
+ return this._id;
87
+ }
70
88
  /**
71
89
  * Get the steps of the label.
72
90
  * This class should be extended and the steps method should be overridden.
73
91
  * Every time you update this list will also be updated when the other game versions load.
74
92
  */
75
93
  get steps() {
76
- throw new Error("[Pixi'VN] The method Label.steps must be overridden");
94
+ return this._steps;
77
95
  }
78
96
  /**
79
97
  * Get the corresponding steps number
@@ -92,45 +110,40 @@ var Label = class {
92
110
  });
93
111
  return res;
94
112
  }
113
+ /**
114
+ * 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
115
+ * @returns Promise<void> or void
116
+ * @example
117
+ * ```typescript
118
+ * newLabel("id", [], () => {
119
+ * Assets.load('path/to/image1.png')
120
+ * Assets.load('path/to/image2.png')
121
+ * })
122
+ * ```
123
+ */
124
+ get onStepRun() {
125
+ return this._onStepRun;
126
+ }
127
+ get choiseIndex() {
128
+ return this._choiseIndex;
129
+ }
95
130
  };
96
131
 
97
132
  // src/classes/CloseLabel.ts
98
- var CloseLabel = class extends Label {
99
- };
133
+ var CLOSE_LABEL_ID = "__close-label-id__";
134
+ function newCloseLabel(choiseIndex) {
135
+ return new Label(CLOSE_LABEL_ID, [], void 0, choiseIndex);
136
+ }
100
137
 
101
138
  // src/decorators/LabelDecorator.ts
102
139
  var registeredLabels = {};
103
- function getLabelTypeByClassName(labelName) {
104
- try {
105
- let labelType = registeredLabels[labelName];
106
- if (!labelType) {
107
- console.error(`[Pixi'VN] Label ${labelName} not found`);
108
- return;
109
- }
110
- new labelType();
111
- return labelType;
112
- } catch (e) {
113
- console.error(`[Pixi'VN] Error while getting Label ${labelName}`, e);
114
- return;
115
- }
116
- }
117
- function getLabelInstanceByClassName(labelName) {
118
- try {
119
- let labelType = registeredLabels[labelName];
120
- if (!labelType) {
121
- console.error(`[Pixi'VN] Label ${labelName} not found`);
122
- return;
123
- }
124
- let label = new labelType();
125
- let step = label.steps;
126
- if (step.length = 0) {
127
- console.warn(`[Pixi'VN] Label ${labelName} has no steps`);
128
- }
129
- return label;
130
- } catch (e) {
131
- console.error(`[Pixi'VN] Error while getting Label ${labelName}`, e);
140
+ function getLabelById(id) {
141
+ let label = registeredLabels[id];
142
+ if (!label) {
143
+ console.error(`[Pixi'VN] Label ${id} not found`);
132
144
  return;
133
145
  }
146
+ return label;
134
147
  }
135
148
 
136
149
  // src/decorators/CanvasElementDecorator.ts
@@ -1567,7 +1580,7 @@ var _GameStepManager = class _GameStepManager {
1567
1580
  */
1568
1581
  static get currentLabel() {
1569
1582
  if (_GameStepManager.currentLabelId) {
1570
- return getLabelInstanceByClassName(_GameStepManager.currentLabelId);
1583
+ return getLabelById(_GameStepManager.currentLabelId);
1571
1584
  }
1572
1585
  }
1573
1586
  static get currentLabelStepIndex() {
@@ -1588,7 +1601,7 @@ var _GameStepManager = class _GameStepManager {
1588
1601
  return true;
1589
1602
  } else {
1590
1603
  this.openedLabels.forEach((item) => {
1591
- let label = getLabelInstanceByClassName(item.label);
1604
+ let label = getLabelById(item.label);
1592
1605
  if (label && label.steps.length > item.currentStepIndex) {
1593
1606
  return false;
1594
1607
  }
@@ -1681,9 +1694,9 @@ var _GameStepManager = class _GameStepManager {
1681
1694
  * @param label The label to add to the history.
1682
1695
  */
1683
1696
  static pushNewLabel(label) {
1684
- let currentLabel = getLabelInstanceByClassName(label);
1697
+ let currentLabel = getLabelById(label);
1685
1698
  if (!currentLabel) {
1686
- throw new Error("[Pixi'VN] Label not found");
1699
+ throw new Error(`[Pixi'VN] Label ${label} not found`);
1687
1700
  }
1688
1701
  _GameStepManager._openedLabels.push({
1689
1702
  label,
@@ -1700,7 +1713,7 @@ var _GameStepManager = class _GameStepManager {
1700
1713
  return;
1701
1714
  }
1702
1715
  if (!_GameStepManager.currentLabel) {
1703
- console.error("[Pixi'VN] Label not found");
1716
+ console.error("[Pixi'VN] currentLabel not found");
1704
1717
  return;
1705
1718
  }
1706
1719
  _GameStepManager._openedLabels.pop();
@@ -1772,7 +1785,7 @@ var _GameStepManager = class _GameStepManager {
1772
1785
  }
1773
1786
  let currentLabel = _GameStepManager.currentLabel;
1774
1787
  if (!currentLabel) {
1775
- console.error("[Pixi'VN] Label not found");
1788
+ console.error("[Pixi'VN] currentLabel not found");
1776
1789
  return;
1777
1790
  }
1778
1791
  let n = currentLabel.steps.length;
@@ -1793,12 +1806,12 @@ var _GameStepManager = class _GameStepManager {
1793
1806
  /**
1794
1807
  * Execute the label and add it to the history.
1795
1808
  * Is a call function in Ren'Py.
1796
- * @param label The label to execute.
1809
+ * @param label The label to execute or the id of the label
1797
1810
  * @param props The props to pass to the label.
1798
1811
  * @returns StepLabelResultType or undefined.
1799
1812
  * @example
1800
1813
  * ```typescript
1801
- * GameStepManager.callLabel(StartLabel, yourParams).then((result) => {
1814
+ * GameStepManager.callLabel(startLabel, yourParams).then((result) => {
1802
1815
  * if (result) {
1803
1816
  * // your code
1804
1817
  * }
@@ -1807,7 +1820,7 @@ var _GameStepManager = class _GameStepManager {
1807
1820
  * @example
1808
1821
  * ```typescript
1809
1822
  * // if you use it in a step label you should return the result.
1810
- * return GameStepManager.callLabel(StartLabel).then((result) => {
1823
+ * return GameStepManager.callLabel(startLabel).then((result) => {
1811
1824
  * return result
1812
1825
  * })
1813
1826
  * ```
@@ -1815,16 +1828,24 @@ var _GameStepManager = class _GameStepManager {
1815
1828
  static callLabel(label, props) {
1816
1829
  return __async(this, null, function* () {
1817
1830
  let choiseMade = void 0;
1831
+ let labelId;
1832
+ if (typeof label === "string") {
1833
+ labelId = label;
1834
+ } else {
1835
+ labelId = label.id;
1836
+ if (typeof label.choiseIndex === "number") {
1837
+ choiseMade = label.choiseIndex;
1838
+ }
1839
+ }
1818
1840
  try {
1819
- if (label instanceof CloseLabel) {
1841
+ if (labelId === CLOSE_LABEL_ID) {
1820
1842
  return _GameStepManager.runNextStep(props);
1821
1843
  }
1822
- if (label instanceof Label) {
1823
- choiseMade = label.choiseIndex;
1824
- label = label.constructor;
1844
+ let tempLabel = getLabelById(labelId);
1845
+ if (!tempLabel) {
1846
+ throw new Error(`[Pixi'VN] Label ${labelId} not found`);
1825
1847
  }
1826
- let labelName = label.name;
1827
- _GameStepManager.pushNewLabel(labelName);
1848
+ _GameStepManager.pushNewLabel(tempLabel.id);
1828
1849
  } catch (e) {
1829
1850
  console.error("[Pixi'VN] Error calling label", e);
1830
1851
  return;
@@ -1836,11 +1857,11 @@ var _GameStepManager = class _GameStepManager {
1836
1857
  * Execute the label, close all labels and add them to the history.
1837
1858
  * Is a jump function in Ren'Py.
1838
1859
  * @param label The label to execute.
1839
- * @param props The props to pass to the label.
1860
+ * @param props The props to pass to the label or the id of the label
1840
1861
  * @returns StepLabelResultType or undefined.
1841
1862
  * @example
1842
1863
  * ```typescript
1843
- * GameStepManager.jumpLabel(StartLabel, yourParams).then((result) => {
1864
+ * GameStepManager.jumpLabel(startLabel, yourParams).then((result) => {
1844
1865
  * if (result) {
1845
1866
  * // your code
1846
1867
  * }
@@ -1849,7 +1870,7 @@ var _GameStepManager = class _GameStepManager {
1849
1870
  * @example
1850
1871
  * ```typescript
1851
1872
  * // if you use it in a step label you should return the result.
1852
- * return GameStepManager.jumpLabel(StartLabel).then((result) => {
1873
+ * return GameStepManager.jumpLabel(startLabel).then((result) => {
1853
1874
  * return result
1854
1875
  * })
1855
1876
  * ```
@@ -1857,15 +1878,24 @@ var _GameStepManager = class _GameStepManager {
1857
1878
  static jumpLabel(label, props) {
1858
1879
  return __async(this, null, function* () {
1859
1880
  _GameStepManager.closeAllLabels();
1881
+ let labelId;
1882
+ if (typeof label === "string") {
1883
+ labelId = label;
1884
+ } else {
1885
+ labelId = label.id;
1886
+ if (typeof label.choiseIndex === "number") {
1887
+ label.choiseIndex;
1888
+ }
1889
+ }
1860
1890
  try {
1861
- if (label instanceof CloseLabel) {
1891
+ if (labelId === CLOSE_LABEL_ID) {
1862
1892
  return _GameStepManager.runNextStep(props);
1863
1893
  }
1864
- if (label instanceof Label) {
1865
- label = label.constructor;
1894
+ let tempLabel = getLabelById(labelId);
1895
+ if (!tempLabel) {
1896
+ throw new Error(`[Pixi'VN] Label ${labelId} not found`);
1866
1897
  }
1867
- let labelName = label.name;
1868
- _GameStepManager.pushNewLabel(labelName);
1898
+ _GameStepManager.pushNewLabel(tempLabel.id);
1869
1899
  } catch (e) {
1870
1900
  console.error("[Pixi'VN] Error jumping label", e);
1871
1901
  return;
@@ -2095,7 +2125,7 @@ var ChoiceMenuOptionClose = class {
2095
2125
  /**
2096
2126
  * Label to be opened when the option is selected
2097
2127
  */
2098
- this.label = new CloseLabel();
2128
+ this.label = newCloseLabel();
2099
2129
  /**
2100
2130
  * Type of the label to be opened
2101
2131
  */
@@ -2109,7 +2139,7 @@ var ChoiceMenuOptionClose = class {
2109
2139
  };
2110
2140
 
2111
2141
  // src/classes/DialogueBaseModel.ts
2112
- var DialogueBaseModel2 = class {
2142
+ var DialogueBaseModel = class {
2113
2143
  /**
2114
2144
  * @param text The text of the dialogue.
2115
2145
  * @param character The id of the character that is speaking.
@@ -2161,8 +2191,8 @@ function setDialogue(props) {
2161
2191
  let dialogue;
2162
2192
  if (typeof props === "string") {
2163
2193
  text = props;
2164
- dialogue = new DialogueBaseModel2(text, characterId);
2165
- } else if (!(props instanceof DialogueBaseModel2)) {
2194
+ dialogue = new DialogueBaseModel(text, characterId);
2195
+ } else if (!(props instanceof DialogueBaseModel)) {
2166
2196
  text = props.text;
2167
2197
  if (props.character) {
2168
2198
  if (typeof props.character === "string") {
@@ -2171,7 +2201,7 @@ function setDialogue(props) {
2171
2201
  characterId = props.character.id;
2172
2202
  }
2173
2203
  }
2174
- dialogue = new DialogueBaseModel2(text, characterId);
2204
+ dialogue = new DialogueBaseModel(text, characterId);
2175
2205
  } else {
2176
2206
  dialogue = props;
2177
2207
  }
@@ -2193,7 +2223,7 @@ function setChoiceMenuOptions(options) {
2193
2223
  };
2194
2224
  }
2195
2225
  return __spreadProps(__spreadValues({}, option), {
2196
- label: option.label.constructor.name
2226
+ label: option.label.id
2197
2227
  });
2198
2228
  });
2199
2229
  GameStorageManager.setVariable(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY, value);
@@ -2205,8 +2235,7 @@ function getChoiceMenuOptions() {
2205
2235
  let options = [];
2206
2236
  d.forEach((option, index) => {
2207
2237
  if (option.type === Close) {
2208
- let itemLabel = new CloseLabel();
2209
- itemLabel.choiseIndex = index;
2238
+ let itemLabel = newCloseLabel(index);
2210
2239
  options.push({
2211
2240
  text: option.text,
2212
2241
  label: itemLabel,
@@ -2215,10 +2244,9 @@ function getChoiceMenuOptions() {
2215
2244
  });
2216
2245
  return;
2217
2246
  }
2218
- let label = getLabelTypeByClassName(option.label);
2247
+ let label = getLabelById(option.label);
2219
2248
  if (label) {
2220
- let itemLabel = new label();
2221
- itemLabel.choiseIndex = index;
2249
+ let itemLabel = new Label(label.id, label.steps, label.onStepRun, index);
2222
2250
  options.push(__spreadProps(__spreadValues({}, option), {
2223
2251
  label: itemLabel
2224
2252
  }));
@@ -2241,7 +2269,7 @@ function getDialogueHistory() {
2241
2269
  if (oldChoices) {
2242
2270
  let choiceMade = false;
2243
2271
  if (step.choiceIndexMade !== void 0 && oldChoices.length > step.choiceIndexMade) {
2244
- oldChoices[step.choiceIndexMade].isMadeChoice = true;
2272
+ oldChoices[step.choiceIndexMade].isResponse = true;
2245
2273
  choiceMade = true;
2246
2274
  }
2247
2275
  list[list.length - 1].playerMadeChoice = choiceMade;
@@ -2253,7 +2281,7 @@ function getDialogueHistory() {
2253
2281
  return {
2254
2282
  text: choice.text,
2255
2283
  type: choice.type,
2256
- isMadeChoice: false
2284
+ isResponse: false
2257
2285
  };
2258
2286
  });
2259
2287
  list.push({