@drincs/pixi-vn 0.5.7 → 0.5.9

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 (61) hide show
  1. package/dist/classes/CharacterBaseModel.js.map +1 -1
  2. package/dist/classes/CharacterBaseModel.mjs.map +1 -1
  3. package/dist/classes/ChoiceMenuOption.js.map +1 -1
  4. package/dist/classes/ChoiceMenuOption.mjs.map +1 -1
  5. package/dist/classes/StoredClassModel.js.map +1 -1
  6. package/dist/classes/StoredClassModel.mjs.map +1 -1
  7. package/dist/classes/index.js.map +1 -1
  8. package/dist/classes/index.mjs.map +1 -1
  9. package/dist/classes/ticker/TickerFadeAlpha.js.map +1 -1
  10. package/dist/classes/ticker/TickerFadeAlpha.mjs.map +1 -1
  11. package/dist/classes/ticker/TickerMove.js.map +1 -1
  12. package/dist/classes/ticker/TickerMove.mjs.map +1 -1
  13. package/dist/classes/ticker/TickerRotate.js.map +1 -1
  14. package/dist/classes/ticker/TickerRotate.mjs.map +1 -1
  15. package/dist/classes/ticker/index.js.map +1 -1
  16. package/dist/classes/ticker/index.mjs.map +1 -1
  17. package/dist/constants.d.mts +1 -1
  18. package/dist/constants.d.ts +1 -1
  19. package/dist/constants.js +1 -1
  20. package/dist/constants.js.map +1 -1
  21. package/dist/constants.mjs +1 -1
  22. package/dist/constants.mjs.map +1 -1
  23. package/dist/decorators/LabelDecorator.js.map +1 -1
  24. package/dist/decorators/LabelDecorator.mjs.map +1 -1
  25. package/dist/decorators/index.js.map +1 -1
  26. package/dist/decorators/index.mjs.map +1 -1
  27. package/dist/functions/DialogueUtility.d.mts +4 -2
  28. package/dist/functions/DialogueUtility.d.ts +4 -2
  29. package/dist/functions/DialogueUtility.js +21 -12
  30. package/dist/functions/DialogueUtility.js.map +1 -1
  31. package/dist/functions/DialogueUtility.mjs +21 -12
  32. package/dist/functions/DialogueUtility.mjs.map +1 -1
  33. package/dist/functions/FlagsUtility.js.map +1 -1
  34. package/dist/functions/FlagsUtility.mjs.map +1 -1
  35. package/dist/functions/GameUtility.js.map +1 -1
  36. package/dist/functions/GameUtility.mjs.map +1 -1
  37. package/dist/functions/ImageUtility.js.map +1 -1
  38. package/dist/functions/ImageUtility.mjs.map +1 -1
  39. package/dist/functions/SavesUtility.js +92 -13
  40. package/dist/functions/SavesUtility.js.map +1 -1
  41. package/dist/functions/SavesUtility.mjs +92 -13
  42. package/dist/functions/SavesUtility.mjs.map +1 -1
  43. package/dist/functions/index.js +22 -13
  44. package/dist/functions/index.js.map +1 -1
  45. package/dist/functions/index.mjs +22 -13
  46. package/dist/functions/index.mjs.map +1 -1
  47. package/dist/index.js +22 -13
  48. package/dist/index.js.map +1 -1
  49. package/dist/index.mjs +22 -13
  50. package/dist/index.mjs.map +1 -1
  51. package/dist/managers/StepManager.d.mts +1 -1
  52. package/dist/managers/StepManager.d.ts +1 -1
  53. package/dist/managers/StepManager.js +91 -12
  54. package/dist/managers/StepManager.js.map +1 -1
  55. package/dist/managers/StepManager.mjs +91 -12
  56. package/dist/managers/StepManager.mjs.map +1 -1
  57. package/dist/managers/index.js +91 -12
  58. package/dist/managers/index.js.map +1 -1
  59. package/dist/managers/index.mjs +91 -12
  60. package/dist/managers/index.mjs.map +1 -1
  61. package/package.json +2 -2
@@ -61,9 +61,79 @@ function getStepSha1(step) {
61
61
  let sha1String = sha1__default.default(step.toString().toLocaleLowerCase());
62
62
  return sha1String.toString();
63
63
  }
64
+ function checkIfStepsIsEqual(step1, step2) {
65
+ return step1 === step2;
66
+ }
67
+
68
+ // src/classes/Label.ts
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
+ }
88
+ /**
89
+ * Get the steps of the label.
90
+ * This class should be extended and the steps method should be overridden.
91
+ * Every time you update this list will also be updated when the other game versions load.
92
+ */
93
+ get steps() {
94
+ return this._steps;
95
+ }
96
+ /**
97
+ * Get the corresponding steps number
98
+ * @param externalSteps
99
+ * @returns Numer of corresponding steps, for example, if externalSteps is [ABC, DEF, GHI] and the steps of the label is [ABC, GHT], the result will be 1
100
+ */
101
+ getCorrespondingStepsNumber(externalSteps) {
102
+ if (externalSteps.length === 0) {
103
+ return 0;
104
+ }
105
+ let res = 0;
106
+ externalSteps.forEach((step, index) => {
107
+ if (checkIfStepsIsEqual(step, this.steps[index])) {
108
+ res = index;
109
+ }
110
+ });
111
+ return res;
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
+ }
130
+ };
64
131
 
65
132
  // src/classes/CloseLabel.ts
66
133
  var CLOSE_LABEL_ID = "__close-label-id__";
134
+ function newCloseLabel(choiseIndex) {
135
+ return new Label(CLOSE_LABEL_ID, [], void 0, choiseIndex);
136
+ }
67
137
 
68
138
  // src/functions/CanvasUtility.ts
69
139
  function getTextureMemory(texture) {
@@ -1711,8 +1781,8 @@ var _GameStepManager = class _GameStepManager {
1711
1781
  static runCurrentStep(props, choiseMade) {
1712
1782
  return __async(this, null, function* () {
1713
1783
  if (_GameStepManager.currentLabelId) {
1714
- let lasteStepsLength = _GameStepManager.currentLabelStepIndex;
1715
- if (lasteStepsLength === null) {
1784
+ let lastStepsLength = _GameStepManager.currentLabelStepIndex;
1785
+ if (lastStepsLength === null) {
1716
1786
  console.error("[Pixi'VN] currentLabelStepIndex is null");
1717
1787
  return;
1718
1788
  }
@@ -1722,12 +1792,12 @@ var _GameStepManager = class _GameStepManager {
1722
1792
  return;
1723
1793
  }
1724
1794
  let n = currentLabel.steps.length;
1725
- if (n > lasteStepsLength) {
1726
- let nextStep = currentLabel.steps[lasteStepsLength];
1727
- let result = yield nextStep(props);
1728
- _GameStepManager.addStepHistory(nextStep, choiseMade);
1795
+ if (n > lastStepsLength) {
1796
+ let step = currentLabel.steps[lastStepsLength];
1797
+ let result = yield step(props);
1798
+ _GameStepManager.addStepHistory(step, choiseMade);
1729
1799
  return result;
1730
- } else if (n === lasteStepsLength) {
1800
+ } else if (n === lastStepsLength) {
1731
1801
  _GameStepManager.closeCurrentLabel();
1732
1802
  return yield _GameStepManager.runNextStep(props);
1733
1803
  } else {
@@ -1772,7 +1842,8 @@ var _GameStepManager = class _GameStepManager {
1772
1842
  }
1773
1843
  try {
1774
1844
  if (labelId === CLOSE_LABEL_ID) {
1775
- return _GameStepManager.runNextStep(props);
1845
+ let closeLabel = newCloseLabel(choiseMade);
1846
+ return _GameStepManager.closeChoiceMenu(closeLabel, props);
1776
1847
  }
1777
1848
  let tempLabel = getLabelById(labelId);
1778
1849
  if (!tempLabel) {
@@ -1811,18 +1882,20 @@ var _GameStepManager = class _GameStepManager {
1811
1882
  static jumpLabel(label, props) {
1812
1883
  return __async(this, null, function* () {
1813
1884
  _GameStepManager.closeAllLabels();
1885
+ let choiseMade = void 0;
1814
1886
  let labelId;
1815
1887
  if (typeof label === "string") {
1816
1888
  labelId = label;
1817
1889
  } else {
1818
1890
  labelId = label.id;
1819
1891
  if (typeof label.choiseIndex === "number") {
1820
- label.choiseIndex;
1892
+ choiseMade = label.choiseIndex;
1821
1893
  }
1822
1894
  }
1823
1895
  try {
1824
1896
  if (labelId === CLOSE_LABEL_ID) {
1825
- return _GameStepManager.runNextStep(props);
1897
+ let closeLabel = newCloseLabel(choiseMade);
1898
+ return _GameStepManager.closeChoiceMenu(closeLabel, props);
1826
1899
  }
1827
1900
  let tempLabel = getLabelById(labelId);
1828
1901
  if (!tempLabel) {
@@ -1833,7 +1906,7 @@ var _GameStepManager = class _GameStepManager {
1833
1906
  console.error("[Pixi'VN] Error jumping label", e);
1834
1907
  return;
1835
1908
  }
1836
- return yield _GameStepManager.runCurrentStep(props);
1909
+ return yield _GameStepManager.runCurrentStep(props, choiseMade);
1837
1910
  });
1838
1911
  }
1839
1912
  /**
@@ -1849,8 +1922,14 @@ var _GameStepManager = class _GameStepManager {
1849
1922
  * })
1850
1923
  * ```
1851
1924
  */
1852
- static closeChoiceMenu(props) {
1925
+ static closeChoiceMenu(label, props) {
1853
1926
  return __async(this, null, function* () {
1927
+ let choiseMade = void 0;
1928
+ if (typeof label.choiseIndex === "number") {
1929
+ choiseMade = label.choiseIndex;
1930
+ }
1931
+ _GameStepManager.addStepHistory(() => {
1932
+ }, choiseMade);
1854
1933
  return _GameStepManager.runNextStep(props);
1855
1934
  });
1856
1935
  }