@drincs/pixi-vn 0.1.5 → 0.2.0

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.
package/dist/index.mjs CHANGED
@@ -181,6 +181,26 @@ function getDialogueHistory() {
181
181
  return list;
182
182
  }
183
183
 
184
+ // src/functions/FlagsUtility.ts
185
+ function setFlag(name, value) {
186
+ let flags = GameStorageManager.getVariable(GameStorageManager.keysSystem.FLAGS_CATEGORY_KEY) || [];
187
+ if (value) {
188
+ if (!flags.includes(name)) {
189
+ flags.push(name);
190
+ }
191
+ } else {
192
+ let index = flags.indexOf(name);
193
+ if (index > -1) {
194
+ flags.splice(index, 1);
195
+ }
196
+ }
197
+ GameStorageManager.setVariable(GameStorageManager.keysSystem.FLAGS_CATEGORY_KEY, flags);
198
+ }
199
+ function getFlag(name) {
200
+ let flags = GameStorageManager.getVariable(GameStorageManager.keysSystem.FLAGS_CATEGORY_KEY) || [];
201
+ return flags.includes(name);
202
+ }
203
+
184
204
  // src/functions/GameUtility.ts
185
205
  function clearAllGameDatas() {
186
206
  GameStorageManager.clear();
@@ -1053,7 +1073,8 @@ var _GameStorageManager = class _GameStorageManager {
1053
1073
  LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY: "___last_dialogue_added_in_step_memory_key___",
1054
1074
  CURRENT_MENU_OPTIONS_MEMORY_KEY: "___current_menu_options_memory_key___",
1055
1075
  LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY: "___last_menu_options_added_in_step_memory_key___",
1056
- CHARACTER_PREKEY: "___character___"
1076
+ CHARACTER_CATEGORY_KEY: "___character___",
1077
+ FLAGS_CATEGORY_KEY: "___flags___"
1057
1078
  };
1058
1079
  }
1059
1080
  /**
@@ -1064,7 +1085,7 @@ var _GameStorageManager = class _GameStorageManager {
1064
1085
  */
1065
1086
  static setVariable(key, value) {
1066
1087
  key = key.toLowerCase();
1067
- if (value === void 0) {
1088
+ if (value === void 0 || value === null) {
1068
1089
  if (_GameStorageManager.storage.hasOwnProperty(key)) {
1069
1090
  delete _GameStorageManager.storage[key];
1070
1091
  }
@@ -1130,6 +1151,17 @@ var GameStorageManager = _GameStorageManager;
1130
1151
  // src/managers/WindowManager.ts
1131
1152
  import { Application } from "pixi.js";
1132
1153
 
1154
+ // src/functions/EasterEgg.ts
1155
+ function asciiArtLog() {
1156
+ console.log(`
1157
+ ____ _ _ ___ ___ _
1158
+ | _ (_)_ _(_| ) / / | |
1159
+ | |_) | / / |/ / /| | |
1160
+ | __/| |> <| | V / | | |
1161
+ |_| |_/_/__| _/ |_| _|
1162
+ `);
1163
+ }
1164
+
1133
1165
  // src/types/PauseType.ts
1134
1166
  var PauseValueType = "Pause";
1135
1167
  function Pause(duration) {
@@ -1198,6 +1230,7 @@ var _GameWindowManager = class _GameWindowManager {
1198
1230
  this.addCanvasIntoElement(element);
1199
1231
  window.addEventListener("resize", _GameWindowManager.resize);
1200
1232
  _GameWindowManager.resize();
1233
+ asciiArtLog();
1201
1234
  });
1202
1235
  });
1203
1236
  }
@@ -1730,9 +1763,9 @@ var _GameStepManager = class _GameStepManager {
1730
1763
  return _GameStepManager._openedLabels;
1731
1764
  }
1732
1765
  /**
1733
- * currentLabel is the current label that occurred during the progression of the steps.
1766
+ * currentLabelId is the current label id that occurred during the progression of the steps.
1734
1767
  */
1735
- static get currentLabel() {
1768
+ static get currentLabelId() {
1736
1769
  if (_GameStepManager._openedLabels.length > 0) {
1737
1770
  let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
1738
1771
  return item.label;
@@ -1740,8 +1773,13 @@ var _GameStepManager = class _GameStepManager {
1740
1773
  return void 0;
1741
1774
  }
1742
1775
  /**
1743
- * is the current step index of the current label that occurred during the progression of the steps.
1776
+ * currentLabel is the current label that occurred during the progression of the steps.
1744
1777
  */
1778
+ static get currentLabel() {
1779
+ if (_GameStepManager.currentLabelId) {
1780
+ return getLabelInstanceByClassName(_GameStepManager.currentLabelId);
1781
+ }
1782
+ }
1745
1783
  static get currentLabelStepIndex() {
1746
1784
  if (_GameStepManager._openedLabels.length > 0) {
1747
1785
  let item = _GameStepManager._openedLabels[_GameStepManager._openedLabels.length - 1];
@@ -1749,6 +1787,17 @@ var _GameStepManager = class _GameStepManager {
1749
1787
  }
1750
1788
  return null;
1751
1789
  }
1790
+ /**
1791
+ * currentLabelStep is the current step that occurred during the progression of the steps. It can used to determine the game end.
1792
+ */
1793
+ static get isLastGameStep() {
1794
+ var _a;
1795
+ let stepLabel = (_a = _GameStepManager.currentLabel) == null ? void 0 : _a.steps;
1796
+ if (stepLabel) {
1797
+ return _GameStepManager.currentLabelStepIndex === stepLabel.length;
1798
+ }
1799
+ return false;
1800
+ }
1752
1801
  /**
1753
1802
  * lastHistoryStep is the last history step that occurred during the progression of the steps.
1754
1803
  */
@@ -1816,7 +1865,7 @@ var _GameStepManager = class _GameStepManager {
1816
1865
  }
1817
1866
  _GameStepManager._stepsHistory.push({
1818
1867
  diff: data,
1819
- currentLabel: _GameStepManager.currentLabel,
1868
+ currentLabel: _GameStepManager.currentLabelId,
1820
1869
  dialoge,
1821
1870
  choices: requiredChoices,
1822
1871
  stepSha1: stepHistory,
@@ -1845,12 +1894,11 @@ var _GameStepManager = class _GameStepManager {
1845
1894
  * @returns
1846
1895
  */
1847
1896
  static closeCurrentLabel() {
1848
- if (!_GameStepManager.currentLabel) {
1897
+ if (!_GameStepManager.currentLabelId) {
1849
1898
  console.warn("[Pixi'VN] No label to close");
1850
1899
  return;
1851
1900
  }
1852
- let currentLabel = getLabelInstanceByClassName(_GameStepManager.currentLabel);
1853
- if (!currentLabel) {
1901
+ if (!_GameStepManager.currentLabel) {
1854
1902
  console.error("[Pixi'VN] Label not found");
1855
1903
  return;
1856
1904
  }
@@ -1909,13 +1957,13 @@ var _GameStepManager = class _GameStepManager {
1909
1957
  */
1910
1958
  static runCurrentStep() {
1911
1959
  return __async(this, null, function* () {
1912
- if (_GameStepManager.currentLabel) {
1960
+ if (_GameStepManager.currentLabelId) {
1913
1961
  let lasteStepsLength = _GameStepManager.currentLabelStepIndex;
1914
1962
  if (lasteStepsLength === null) {
1915
1963
  console.error("[Pixi'VN] currentLabelStepIndex is null");
1916
1964
  return;
1917
1965
  }
1918
- let currentLabel = getLabelInstanceByClassName(_GameStepManager.currentLabel);
1966
+ let currentLabel = _GameStepManager.currentLabel;
1919
1967
  if (!currentLabel) {
1920
1968
  console.error("[Pixi'VN] Label not found");
1921
1969
  return;
@@ -2179,27 +2227,54 @@ var GameStepManager = _GameStepManager;
2179
2227
 
2180
2228
  // src/classes/StoredClassModel.ts
2181
2229
  var StoredClassModel = class {
2182
- constructor(id) {
2183
- this.id = id;
2230
+ /**
2231
+ * @param categoryId The id of the category. For example if you are storing a character class, you can use "characters" as categoryId. so all instances of the character class will be stored in the "characters" category.
2232
+ * @param id The id of instance of the class. This id must be unique for the category.
2233
+ */
2234
+ constructor(categoryId, id) {
2235
+ this.categoryId = categoryId;
2236
+ this._id = id;
2184
2237
  }
2185
- get nameClass() {
2186
- return this.constructor.name + "Storage";
2238
+ /**
2239
+ * Is id of the stored class. is unique for this class.
2240
+ */
2241
+ get id() {
2242
+ return this._id;
2187
2243
  }
2188
- updateStorageProperty(key, value) {
2189
- let storage = GameStorageManager.getVariable(this.nameClass);
2244
+ /**
2245
+ * Update a property in the storage.
2246
+ * @param propertyName The name of the property to set.
2247
+ * @param value The value to set. If is undefined, the property will be removed from the storage.
2248
+ */
2249
+ setStorageProperty(propertyName, value) {
2250
+ let storage = GameStorageManager.getVariable(this.categoryId);
2190
2251
  if (!storage) {
2191
2252
  storage = {};
2192
2253
  }
2193
- storage[this.id] = __spreadProps(__spreadValues({}, storage[this.id]), { [key]: value });
2194
- GameStorageManager.setVariable(this.nameClass, storage);
2195
- }
2196
- getStorageProperty(key) {
2197
- let storage = GameStorageManager.getVariable(this.nameClass);
2198
- if (!storage) {
2199
- return void 0;
2254
+ if (!storage.hasOwnProperty(this.id)) {
2255
+ storage[this.id] = {};
2256
+ }
2257
+ if (value === void 0 || value === null) {
2258
+ if (storage[this.id].hasOwnProperty(propertyName)) {
2259
+ delete storage[this.id][propertyName];
2260
+ }
2261
+ } else {
2262
+ storage[this.id] = __spreadProps(__spreadValues({}, storage[this.id]), { [propertyName]: value });
2200
2263
  }
2201
- if (storage[this.id].hasOwnProperty(key)) {
2202
- return storage[this.id][key];
2264
+ if (Object.keys(storage[this.id]).length === 0) {
2265
+ delete storage[this.id];
2266
+ }
2267
+ GameStorageManager.setVariable(this.categoryId, storage);
2268
+ }
2269
+ /**
2270
+ * Get a property from the storage.
2271
+ * @param propertyName The name of the property to get.
2272
+ * @returns The value of the property. If the property is not found, returns undefined.
2273
+ */
2274
+ getStorageProperty(propertyName) {
2275
+ let storage = GameStorageManager.getVariable(this.categoryId);
2276
+ if (storage && storage.hasOwnProperty(this.id) && storage[this.id].hasOwnProperty(propertyName)) {
2277
+ return storage[this.id][propertyName];
2203
2278
  }
2204
2279
  return void 0;
2205
2280
  }
@@ -2208,7 +2283,7 @@ var StoredClassModel = class {
2208
2283
  // src/classes/CharacterModelBase.ts
2209
2284
  var CharacterModelBase2 = class extends StoredClassModel {
2210
2285
  constructor(id, props) {
2211
- super(GameStorageManager.keysSystem.CHARACTER_PREKEY + id);
2286
+ super(GameStorageManager.keysSystem.CHARACTER_CATEGORY_KEY, id);
2212
2287
  this.defaultName = "";
2213
2288
  this.defaultName = props.name;
2214
2289
  this.defaultSurname = props.surname;
@@ -2220,19 +2295,19 @@ var CharacterModelBase2 = class extends StoredClassModel {
2220
2295
  return this.getStorageProperty("name") || this.defaultName;
2221
2296
  }
2222
2297
  set name(value) {
2223
- this.updateStorageProperty("name", value);
2298
+ this.setStorageProperty("name", value);
2224
2299
  }
2225
2300
  get surname() {
2226
2301
  return this.getStorageProperty("surname") || this.defaultSurname;
2227
2302
  }
2228
2303
  set surname(value) {
2229
- this.updateStorageProperty("surname", value);
2304
+ this.setStorageProperty("surname", value);
2230
2305
  }
2231
2306
  get age() {
2232
2307
  return this.getStorageProperty("age") || this.defaultAge;
2233
2308
  }
2234
2309
  set age(value) {
2235
- this.updateStorageProperty("age", value);
2310
+ this.setStorageProperty("age", value);
2236
2311
  }
2237
2312
  get icon() {
2238
2313
  return this._icon;
@@ -2335,6 +2410,7 @@ export {
2335
2410
  getChoiceMenuOptions,
2336
2411
  getDialogue,
2337
2412
  getDialogueHistory,
2413
+ getFlag,
2338
2414
  getSaveData,
2339
2415
  getSaveJson,
2340
2416
  getTexture,
@@ -2345,6 +2421,7 @@ export {
2345
2421
  saveCharacter,
2346
2422
  setChoiceMenuOptions,
2347
2423
  setDialogue,
2424
+ setFlag,
2348
2425
  showCanvasImages,
2349
2426
  showImageWithDissolveTransition,
2350
2427
  tickerDecorator