@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
@@ -55,9 +55,79 @@ function getStepSha1(step) {
55
55
  let sha1String = sha1(step.toString().toLocaleLowerCase());
56
56
  return sha1String.toString();
57
57
  }
58
+ function checkIfStepsIsEqual(step1, step2) {
59
+ return step1 === step2;
60
+ }
61
+
62
+ // src/classes/Label.ts
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
+ }
82
+ /**
83
+ * Get the steps of the label.
84
+ * This class should be extended and the steps method should be overridden.
85
+ * Every time you update this list will also be updated when the other game versions load.
86
+ */
87
+ get steps() {
88
+ return this._steps;
89
+ }
90
+ /**
91
+ * Get the corresponding steps number
92
+ * @param externalSteps
93
+ * @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
94
+ */
95
+ getCorrespondingStepsNumber(externalSteps) {
96
+ if (externalSteps.length === 0) {
97
+ return 0;
98
+ }
99
+ let res = 0;
100
+ externalSteps.forEach((step, index) => {
101
+ if (checkIfStepsIsEqual(step, this.steps[index])) {
102
+ res = index;
103
+ }
104
+ });
105
+ return res;
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
+ }
124
+ };
58
125
 
59
126
  // src/classes/CloseLabel.ts
60
127
  var CLOSE_LABEL_ID = "__close-label-id__";
128
+ function newCloseLabel(choiseIndex) {
129
+ return new Label(CLOSE_LABEL_ID, [], void 0, choiseIndex);
130
+ }
61
131
 
62
132
  // src/functions/ExportUtility.ts
63
133
  function createExportableElement(element) {
@@ -1703,8 +1773,8 @@ var _GameStepManager = class _GameStepManager {
1703
1773
  static runCurrentStep(props, choiseMade) {
1704
1774
  return __async(this, null, function* () {
1705
1775
  if (_GameStepManager.currentLabelId) {
1706
- let lasteStepsLength = _GameStepManager.currentLabelStepIndex;
1707
- if (lasteStepsLength === null) {
1776
+ let lastStepsLength = _GameStepManager.currentLabelStepIndex;
1777
+ if (lastStepsLength === null) {
1708
1778
  console.error("[Pixi'VN] currentLabelStepIndex is null");
1709
1779
  return;
1710
1780
  }
@@ -1714,12 +1784,12 @@ var _GameStepManager = class _GameStepManager {
1714
1784
  return;
1715
1785
  }
1716
1786
  let n = currentLabel.steps.length;
1717
- if (n > lasteStepsLength) {
1718
- let nextStep = currentLabel.steps[lasteStepsLength];
1719
- let result = yield nextStep(props);
1720
- _GameStepManager.addStepHistory(nextStep, choiseMade);
1787
+ if (n > lastStepsLength) {
1788
+ let step = currentLabel.steps[lastStepsLength];
1789
+ let result = yield step(props);
1790
+ _GameStepManager.addStepHistory(step, choiseMade);
1721
1791
  return result;
1722
- } else if (n === lasteStepsLength) {
1792
+ } else if (n === lastStepsLength) {
1723
1793
  _GameStepManager.closeCurrentLabel();
1724
1794
  return yield _GameStepManager.runNextStep(props);
1725
1795
  } else {
@@ -1764,7 +1834,8 @@ var _GameStepManager = class _GameStepManager {
1764
1834
  }
1765
1835
  try {
1766
1836
  if (labelId === CLOSE_LABEL_ID) {
1767
- return _GameStepManager.runNextStep(props);
1837
+ let closeLabel = newCloseLabel(choiseMade);
1838
+ return _GameStepManager.closeChoiceMenu(closeLabel, props);
1768
1839
  }
1769
1840
  let tempLabel = getLabelById(labelId);
1770
1841
  if (!tempLabel) {
@@ -1803,18 +1874,20 @@ var _GameStepManager = class _GameStepManager {
1803
1874
  static jumpLabel(label, props) {
1804
1875
  return __async(this, null, function* () {
1805
1876
  _GameStepManager.closeAllLabels();
1877
+ let choiseMade = void 0;
1806
1878
  let labelId;
1807
1879
  if (typeof label === "string") {
1808
1880
  labelId = label;
1809
1881
  } else {
1810
1882
  labelId = label.id;
1811
1883
  if (typeof label.choiseIndex === "number") {
1812
- label.choiseIndex;
1884
+ choiseMade = label.choiseIndex;
1813
1885
  }
1814
1886
  }
1815
1887
  try {
1816
1888
  if (labelId === CLOSE_LABEL_ID) {
1817
- return _GameStepManager.runNextStep(props);
1889
+ let closeLabel = newCloseLabel(choiseMade);
1890
+ return _GameStepManager.closeChoiceMenu(closeLabel, props);
1818
1891
  }
1819
1892
  let tempLabel = getLabelById(labelId);
1820
1893
  if (!tempLabel) {
@@ -1825,7 +1898,7 @@ var _GameStepManager = class _GameStepManager {
1825
1898
  console.error("[Pixi'VN] Error jumping label", e);
1826
1899
  return;
1827
1900
  }
1828
- return yield _GameStepManager.runCurrentStep(props);
1901
+ return yield _GameStepManager.runCurrentStep(props, choiseMade);
1829
1902
  });
1830
1903
  }
1831
1904
  /**
@@ -1841,8 +1914,14 @@ var _GameStepManager = class _GameStepManager {
1841
1914
  * })
1842
1915
  * ```
1843
1916
  */
1844
- static closeChoiceMenu(props) {
1917
+ static closeChoiceMenu(label, props) {
1845
1918
  return __async(this, null, function* () {
1919
+ let choiseMade = void 0;
1920
+ if (typeof label.choiseIndex === "number") {
1921
+ choiseMade = label.choiseIndex;
1922
+ }
1923
+ _GameStepManager.addStepHistory(() => {
1924
+ }, choiseMade);
1846
1925
  return _GameStepManager.runNextStep(props);
1847
1926
  });
1848
1927
  }