UNPKG

@drincs/pixi-vn

Version:

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

1 lines 4.31 kB
import {k as k$1,m,j,l,n}from'./chunk-IWAXXFXE.mjs';import {e,g,f as f$1,d}from'./chunk-Z4GZCINS.mjs';import {GameUnifier}from'@drincs/pixi-vn/core';var T;(n=>{n.storage=new e({cacheSize:50}),n.defaultStorage=new e({cacheSize:10}),n.tempStorageDeadlines=new Map;let s;function c(r){n.tempStorageDeadlines.forEach((l,o)=>{l>r&&(n.storage.delete(`${k$1}:${o}`),s?.onClearOldTempVariable?.(o),n.tempStorageDeadlines.delete(o));});}n.clearOldTempVariables=c;function h(r){s=r;}n.setExternalStoreHandler=h;function V(r,l,o){o==null?n.storage.delete(`${r}:${l}`):n.storage.set(`${r}:${l}`,o),s?.onSetVariable?.(l,o);}n.setVariable=V;function O(r,l){let o=n.storage.get(`${r}:${l}`);return g(o)}n.getVariable=O;function M(r,l){n.storage.delete(`${r}:${l}`),s?.onRemoveVariable?.(l);}n.removeVariable=M;function D(r,l){let o=n.storage.get(m)||[];if(l)o.includes(r)||o.push(r);else {let x=o.indexOf(r);x>-1&&o.splice(x,1);}n.storage.set(m,o);}n.setFlag=D;function R(r){return (n.storage.get(m)||[]).includes(r)}n.getFlag=R;})(T||(T={}));var a=T;var S=class{get base(){return a.storage.map}get cache(){return a.storage.cache}get tempStorageDeadlines(){return a.tempStorageDeadlines}set default(t){Object.entries(t).forEach(([e,s])=>{a.defaultStorage.map.set(e,s);});}set(t,e){return a.setVariable(j,t,e)}get(t){let e=a.getVariable(k$1,t);return e===void 0&&(e=a.getVariable(j,t)),e===void 0&&(e=g(a.defaultStorage.get(t))),e}remove(t){return this.removeTempVariable(t),a.removeVariable(j,t)}setTempVariable(t,e){if(e==null){this.removeTempVariable(t);return}else a.setVariable(k$1,t,e),this.tempStorageDeadlines.has(t)||this.tempStorageDeadlines.set(t,GameUnifier.openedLabels);}removeTempVariable(t){a.removeVariable(k$1,t),this.tempStorageDeadlines.has(t)&&this.tempStorageDeadlines.delete(t);}setFlag(t,e){return a.setFlag(t,e)}getFlag(t){return a.getFlag(t)}setStorageHandler(t){a.setExternalStoreHandler(t);}clear(){this.base.clear(),this.cache.clear(),this.tempStorageDeadlines.clear();}export(){let t=[];[...this.base.keys()].forEach(s=>{t.push({key:s,value:this.base.get(s)});});let e=[];return [...a.tempStorageDeadlines.keys()].forEach(s=>{e.push({key:s,value:this.tempStorageDeadlines.get(s)});}),g({main:t,tempDeadlines:e})}restore(t){this.clear();try{t?(t.base?.forEach(e=>{switch(e.key){case "___current_dialogue_memory___":a.setVariable(l,n.CURRENT_DIALOGUE_MEMORY_KEY,e.value);break;case "___last_dialogue_added_in_step_memory___":a.setVariable(l,n.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,e.value);break;case "___current_menu_options_memory___":a.setVariable(l,n.CURRENT_MENU_OPTIONS_MEMORY_KEY,e.value);break;case "___last_menu_options_added_in_step_memory___":a.setVariable(l,n.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,e.value);break;case "_input_value_":a.setVariable(l,n.CURRENT_INPUT_VALUE_MEMORY_KEY,e.value);break;case "___last_input_added_in_step_memory___":a.setVariable(l,n.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,e.value);break;case "___current_input_info_memory___":a.setVariable(l,n.CURRENT_INPUT_INFO_MEMORY_KEY,e.value);break;case "___opened_labels_counter___":a.setVariable(l,n.OPENED_LABELS_COUNTER_KEY,e.value);break;case "___all_choices_made___":a.setVariable(l,n.ALL_CHOICES_MADE_KEY,e.value);break;case "___current_step_times_counter___":a.setVariable(l,n.CURRENT_STEP_TIMES_COUNTER_KEY,e.value);break;case "___last_step_glued___":a.setVariable(l,n.LAST_STEP_GLUED,e.value);break;default:a.setVariable(j,e.key,e.value);}}),t.temp?.forEach(e=>{a.setVariable(k$1,e.key,e.value);}),t.flags?.forEach(e=>{a.setFlag(e,!0);}),t.main?.forEach(e=>{this.base.set(e.key,e.value);}),t.tempDeadlines?.forEach(e=>{this.tempStorageDeadlines.set(e.key,e.value);})):f$1.warn("No storage data found");}catch(e){f$1.error("Error importing data",e);}}};var f=class{constructor(t,e){d(this,"id");d(this,"categoryId");this.categoryId=t,this.id=e,this.migrateOldStorage();}migrateOldStorage(t=this.categoryId){let e=a.getVariable(j,t);e&&(Object.entries(e).forEach(([s,c])=>{typeof c=="object"&&c!==null&&Object.entries(c).forEach(([h,V])=>{a.setVariable(this.categoryId,`${s}:${h}`,V);});}),a.removeVariable(j,t));}setStorageProperty(t,e){a.setVariable(this.categoryId,`${this.id}:${t}`,e);}getStorageProperty(t,e=this.id){return a.getVariable(this.categoryId,`${e}:${t}`)}};var k=new S;export{a,f as b,k as c};