UNPKG

@drincs/pixi-vn

Version:

Pixi'VN is a npm package that provides various features for creating visual novels.

122 lines (120 loc) 3.71 kB
// src/functions/ExportUtility.ts function createExportableElement(element) { try { let elementString = JSON.stringify(element); return JSON.parse(elementString); } catch (e) { console.error("[Pixi'VN] Error creating exportable element", e); throw new Error("[Pixi'VN] Error creating exportable element"); } } // src/managers/StorageManager.ts var _GameStorageManager = class _GameStorageManager { constructor() { } static get keysSystem() { return { /** * The key of the current dialogue memory */ CURRENT_DIALOGUE_MEMORY_KEY: "___current_dialogue_memory___", /** * The key of the last dialogue added in the step memory */ LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY: "___last_dialogue_added_in_step_memory___", /** * The key of the current menu options memory */ CURRENT_MENU_OPTIONS_MEMORY_KEY: "___current_menu_options_memory___", /** * The key of the last menu options added in the step memory */ LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY: "___last_menu_options_added_in_step_memory___", /** * The key of the characters memory */ CHARACTER_CATEGORY_KEY: "___character___", /** * The key of the flags memory */ FLAGS_CATEGORY_KEY: "___flags___", /** * This variable is used to add the next dialog text into the current dialog memory. * This value was added to introduce Ink Glue functionality https://github.com/inkle/ink/blob/master/Documentation/WritingWithInk.md#glue */ ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY: "___glue___" }; } /** * Set a variable in the storage * @param key The key of the variable * @param value The value of the variable. If undefined, the variable will be removed * @returns */ static setVariable(key, value) { key = key.toLowerCase(); if (value === void 0 || value === null) { if (_GameStorageManager.storage.hasOwnProperty(key)) { delete _GameStorageManager.storage[key]; } return; } _GameStorageManager.storage[key] = value; } /** * Get a variable from the storage * @param key The key of the variable * @returns The value of the variable. If the variable does not exist, it will return undefined */ static getVariable(key) { key = key.toLowerCase(); if (_GameStorageManager.storage.hasOwnProperty(key)) { return _GameStorageManager.storage[key]; } return void 0; } /** * Remove a variable from the storage * @param key The key of the variable * @returns */ static removeVariable(key) { key = key.toLowerCase(); if (_GameStorageManager.storage.hasOwnProperty(key)) { delete _GameStorageManager.storage[key]; } } /** * Clear the storage and the oidsUsed * @returns */ static clear() { _GameStorageManager.storage = {}; } static exportJson() { return JSON.stringify(this.export()); } static export() { return createExportableElement(_GameStorageManager.storage); } static importJson(dataString) { _GameStorageManager.import(JSON.parse(dataString)); } static import(data) { _GameStorageManager.clear(); try { if (data) { _GameStorageManager.storage = data; } else { console.warn("[Pixi'VN] No storage data found"); } } catch (e) { console.error("[Pixi'VN] Error importing data", e); } } }; _GameStorageManager.storage = {}; var GameStorageManager = _GameStorageManager; export { GameStorageManager as default }; //# sourceMappingURL=StorageManager.mjs.map //# sourceMappingURL=StorageManager.mjs.map