@drincs/pixi-vn-json
Version:
Pixi'VN can be integrated with JSON files to create a visual novel.
3 lines (2 loc) • 23.5 kB
JavaScript
import {storage,narration,LabelAbstract,SYSTEM_RESERVED_STORAGE_KEYS,RegisteredLabels,NarrationManagerStatic,createExportableElement,Assets,shakeEffect,ZoomTicker,canvas,RotateTicker,MoveTicker,FadeAlphaTicker,ImageContainer,VideoSprite,ImageSprite,sound,pushOut,zoomOut,moveOut,removeWithDissolve,removeWithFade,pushIn,zoomIn,moveIn,showWithDissolve,showWithFade}from'@drincs/pixi-vn';var oe=Object.create;var Q=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var j=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var ee=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports);var ue=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of fe(t))!pe.call(i,a)&&a!==e&&Q(i,a,{get:()=>t[a],enumerable:!(r=le(t,a))||r.enumerable});return i};var de=(i,t,e)=>(e=i!=null?oe(ce(i)):{},ue(Q(e,"default",{value:i,enumerable:true}),i));var ie=ee((R,te)=>{(function(i,t){typeof R=="object"?te.exports=R=t():typeof define=="function"&&define.amd?define([],t):i.CryptoJS=t();})(R,function(){var i=i||function(t,e){var r;if(typeof window<"u"&&window.crypto&&(r=window.crypto),typeof self<"u"&&self.crypto&&(r=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(r=globalThis.crypto),!r&&typeof window<"u"&&window.msCrypto&&(r=window.msCrypto),!r&&typeof global<"u"&&global.crypto&&(r=global.crypto),!r&&typeof j=="function")try{r=j("crypto");}catch{}var a=function(){if(r){if(typeof r.getRandomValues=="function")try{return r.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof r.randomBytes=="function")try{return r.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},o=Object.create||function(){function n(){}return function(s){var d;return n.prototype=s,d=new n,n.prototype=null,d}}(),f={},l=f.lib={},p=l.Base=function(){return {extend:function(n){var s=o(this);return n&&s.mixIn(n),(!s.hasOwnProperty("init")||this.init===s.init)&&(s.init=function(){s.$super.init.apply(this,arguments);}),s.init.prototype=s,s.$super=this,s},create:function(){var n=this.extend();return n.init.apply(n,arguments),n},init:function(){},mixIn:function(n){for(var s in n)n.hasOwnProperty(s)&&(this[s]=n[s]);n.hasOwnProperty("toString")&&(this.toString=n.toString);},clone:function(){return this.init.prototype.extend(this)}}}(),g=l.WordArray=p.extend({init:function(n,s){n=this.words=n||[],s!=e?this.sigBytes=s:this.sigBytes=n.length*4;},toString:function(n){return (n||y).stringify(this)},concat:function(n){var s=this.words,d=n.words,x=this.sigBytes,N=n.sigBytes;if(this.clamp(),x%4)for(var S=0;S<N;S++){var W=d[S>>>2]>>>24-S%4*8&255;s[x+S>>>2]|=W<<24-(x+S)%4*8;}else for(var E=0;E<N;E+=4)s[x+E>>>2]=d[E>>>2];return this.sigBytes+=N,this},clamp:function(){var n=this.words,s=this.sigBytes;n[s>>>2]&=4294967295<<32-s%4*8,n.length=t.ceil(s/4);},clone:function(){var n=p.clone.call(this);return n.words=this.words.slice(0),n},random:function(n){for(var s=[],d=0;d<n;d+=4)s.push(a());return new g.init(s,n)}}),u=f.enc={},y=u.Hex={stringify:function(n){for(var s=n.words,d=n.sigBytes,x=[],N=0;N<d;N++){var S=s[N>>>2]>>>24-N%4*8&255;x.push((S>>>4).toString(16)),x.push((S&15).toString(16));}return x.join("")},parse:function(n){for(var s=n.length,d=[],x=0;x<s;x+=2)d[x>>>3]|=parseInt(n.substr(x,2),16)<<24-x%8*4;return new g.init(d,s/2)}},T=u.Latin1={stringify:function(n){for(var s=n.words,d=n.sigBytes,x=[],N=0;N<d;N++){var S=s[N>>>2]>>>24-N%4*8&255;x.push(String.fromCharCode(S));}return x.join("")},parse:function(n){for(var s=n.length,d=[],x=0;x<s;x++)d[x>>>2]|=(n.charCodeAt(x)&255)<<24-x%4*8;return new g.init(d,s)}},m=u.Utf8={stringify:function(n){try{return decodeURIComponent(escape(T.stringify(n)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(n){return T.parse(unescape(encodeURIComponent(n)))}},h=l.BufferedBlockAlgorithm=p.extend({reset:function(){this._data=new g.init,this._nDataBytes=0;},_append:function(n){typeof n=="string"&&(n=m.parse(n)),this._data.concat(n),this._nDataBytes+=n.sigBytes;},_process:function(n){var s,d=this._data,x=d.words,N=d.sigBytes,S=this.blockSize,W=S*4,E=N/W;n?E=t.ceil(E):E=t.max((E|0)-this._minBufferSize,0);var D=E*S,Z=t.min(D*4,N);if(D){for(var K=0;K<D;K+=S)this._doProcessBlock(x,K);s=x.splice(0,D),d.sigBytes-=Z;}return new g.init(s,Z)},clone:function(){var n=p.clone.call(this);return n._data=this._data.clone(),n},_minBufferSize:0});l.Hasher=h.extend({cfg:p.extend(),init:function(n){this.cfg=this.cfg.extend(n),this.reset();},reset:function(){h.reset.call(this),this._doReset();},update:function(n){return this._append(n),this._process(),this},finalize:function(n){n&&this._append(n);var s=this._doFinalize();return s},blockSize:512/32,_createHelper:function(n){return function(s,d){return new n.init(d).finalize(s)}},_createHmacHelper:function(n){return function(s,d){return new b.HMAC.init(n,d).finalize(s)}}});var b=f.algo={};return f}(Math);return i});});var re=ee((B,ne)=>{(function(i,t){typeof B=="object"?ne.exports=B=t(ie()):typeof define=="function"&&define.amd?define(["./core"],t):t(i.CryptoJS);})(B,function(i){return function(){var t=i,e=t.lib,r=e.WordArray,a=e.Hasher,o=t.algo,f=[],l=o.SHA1=a.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(p,g){for(var u=this._hash.words,y=u[0],T=u[1],m=u[2],h=u[3],P=u[4],b=0;b<80;b++){if(b<16)f[b]=p[g+b]|0;else {var n=f[b-3]^f[b-8]^f[b-14]^f[b-16];f[b]=n<<1|n>>>31;}var s=(y<<5|y>>>27)+P+f[b];b<20?s+=(T&m|~T&h)+1518500249:b<40?s+=(T^m^h)+1859775393:b<60?s+=(T&m|T&h|m&h)-1894007588:s+=(T^m^h)-899497514,P=h,h=m,m=T<<30|T>>>2,T=y,y=s;}u[0]=u[0]+y|0,u[1]=u[1]+T|0,u[2]=u[2]+m|0,u[3]=u[3]+h|0,u[4]=u[4]+P|0;},_doFinalize:function(){var p=this._data,g=p.words,u=this._nDataBytes*8,y=p.sigBytes*8;return g[y>>>5]|=128<<24-y%32,g[(y+64>>>9<<4)+14]=Math.floor(u/4294967296),g[(y+64>>>9<<4)+15]=u,p.sigBytes=g.length*4,this._process(),this._hash},clone:function(){var p=a.clone.call(this);return p._hash=this._hash.clone(),p}});t.SHA1=a._createHelper(l),t.HmacSHA1=a._createHmacHelper(l);}(),i.SHA1});});var se=de(re());var k="___param___";var J=class i{static _beforeToTranslate=void 0;static _translate=t=>t;static _afterToTranslate=void 0;static t(t){return Array.isArray(t)?t.map(e=>i.translate(`${e}`)):i.translate(`${t}`)}static set beforeToTranslate(t){i._beforeToTranslate=t;}static set translate(t){i._translate=t;}static get translate(){return t=>{let e=t;return i._beforeToTranslate&&(e=i._beforeToTranslate(e)),e=i._translate(e),i._afterToTranslate&&(e=i._afterToTranslate(e)),e}}static set afterToTranslate(t){i._afterToTranslate=t;}static addKey(t,e,r){let a=r.defaultValue||"empty_string";typeof e=="string"&&(e=[e]),Array.isArray(e)&&e.forEach(o=>{t[o]===void 0&&(a==="empty_string"?t[o]="":a==="copy_key"&&(i._beforeToTranslate?t[o]=i._beforeToTranslate(o):t[o]=o));});}static getConditionalsThenElse(t,e=[]){if(typeof t=="object"&&t&&"type"in t)if(t.type==="ifelse")t.then&&i.getConditionalsThenElse(t.then,e),t.else&&i.getConditionalsThenElse(t.else,e);else if(t.type==="stepswitch"){if(t.elements)if(Array.isArray(t.elements))t.elements.forEach(r=>{i.getConditionalsThenElse(r,e);});else if(t.elements.type==="ifelse"){let r=[];i.getConditionalsThenElse(t.elements,r),r.forEach(a=>{e.push(...a);});}else if(t.elements.type==="stepswitch"){let r=[];i.getConditionalsThenElse(t.elements,r),r.forEach(a=>{e.push(...a);});}else i.getConditionalsThenElse(t.elements,e);}else t.type==="resulttocombine"?(t.firstItem&&i.getConditionalsThenElse(t.firstItem,e),t.secondConditionalItem&&t.secondConditionalItem.forEach(r=>{i.getConditionalsThenElse(r,e);})):e.push(t);else t&&e.push(t);return e}static generateJsonTranslation(t,e={},r={}){return t.forEach(a=>{if(a.choices){let o=[];Array.isArray(a.choices)?o=[a.choices]:o=i.getConditionalsThenElse(a.choices),o.forEach(f=>f.forEach(l=>{if("type"in l){let p=[];l.type==="ifelse"||l.type==="stepswitch"?i.getConditionalsThenElse(l,p):p=[l],p.map(u=>i.getConditionalsThenElse(u.text)).forEach(u=>{Array.isArray(u)&&u.forEach(y=>{Array.isArray(y)?y.forEach(T=>{typeof T=="string"?i.addKey(e,T,r):i.getConditionalsThenElse(T).forEach(m=>{Array.isArray(m)?m.forEach(h=>{typeof h=="string"&&i.addKey(e,h,r);}):typeof m=="string"&&i.addKey(e,m,r);});}):typeof y=="string"&&i.addKey(e,y,r);});});}}));}if(a.dialogue){let o=[];Array.isArray(a.dialogue)?o=[a.dialogue]:o=i.getConditionalsThenElse(a.dialogue),o.forEach(f=>{typeof f=="string"?i.addKey(e,f,r):"text"in f&&Array.isArray(f.text)&&f.text.forEach(l=>{typeof l=="string"?i.addKey(e,l,r):i.getConditionalsThenElse(l).forEach(g=>{typeof g=="string"?i.addKey(e,g,r):Array.isArray(g)&&g.forEach(u=>{typeof u=="string"?i.addKey(e,u,r):i.getConditionalsThenElse(u).forEach(y=>{typeof y=="string"&&i.addKey(e,y,r);});});});});});}a.conditionalStep&&i.getConditionalsThenElse(a.conditionalStep).forEach(f=>{Array.isArray(f)?i.generateJsonTranslation(f,e,r):i.generateJsonTranslation([f],e,r);});}),e}};var $=J;var V;(a=>(a.log=(o,...f)=>console.log(`[Pixi\u2019VN Json] ${o}`,...f),a.warn=(o,...f)=>console.warn(`[Pixi\u2019VN Json] ${o}`,...f),a.error=(o,...f)=>console.error(`[Pixi\u2019VN Json] ${o}`,...f),a.info=(o,...f)=>console.info(`[Pixi\u2019VN Json] ${o}`,...f)))(V||={});function he(i,t){return Math.floor(Math.random()*(t-i+1)+i)}function ye(i){if(Array.isArray(i)||!i)return i;if(i&&typeof i=="object"&&"type"in i)switch(i.type){case "resulttocombine":return me(i);case "ifelse":return c(i.condition)?c(i.then):c(i.else);case "stepswitch":let e=c(i.elements)||[];if(e.length===0){V.error("getValueFromConditionalStatements elements.length === 0");return}switch(i.choiceType){case "random":let r=he(0,e.length-1);return c(e[r]);case "loop":let a=NarrationManagerStatic.getCurrentStepTimesCounter(i.nestedId)-1;return a>e.length-1&&(a=a%e.length),c(e[a]);case "sequential":let o,f=NarrationManagerStatic.getCurrentStepTimesCounter(i.nestedId)-1;return i.end=="lastItem"&&(o=c(e[e.length-1])),f>e.length-1?o:c(e[f]);case "sequentialrandom":let l=NarrationManagerStatic.getRandomNumber(0,e.length-1,{nestedId:i.nestedId,onceOnly:true});if(l==null&&i.end=="lastItem"){let p=NarrationManagerStatic.getCurrentStepTimesCounterData(i.nestedId);if(!p||!p?.usedRandomNumbers){V.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}let g=p.usedRandomNumbers[`0-${e.length-1}`];return c(e[g[g.length-1]])}if(l==null){V.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}return c(e[l])}}return i}function L(i){if(i.conditionalStep){let t=createExportableElement(c(i.conditionalStep));if(t?.glueEnabled===void 0&&delete t?.glueEnabled,t?.goNextStep===void 0&&delete t?.goNextStep,t?.end===void 0&&delete t?.end,t?.choices===void 0&&delete t?.choices,t?.dialogue===void 0&&delete t?.dialogue,t?.labelToOpen===void 0&&delete t?.labelToOpen,t?.operations===void 0&&delete t?.operations,t){let e={...i,conditionalStep:void 0,...t};return L(e)}else storage.getFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)&&storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,false);}return i}function me(i){let t=i.firstItem,e=[];i.secondConditionalItem?.forEach(a=>{if(Array.isArray(a))a.forEach(o=>{let f=c(o);e.push(f);});else {let o=c(a);e.push(o);}});let r=t?[t,...e]:e;if(r.length===0){V.warn("combinateResult toCheck.length === 0");return}if(typeof r[0]=="string")return $.t(r);if(typeof r[0]=="object"){let a=r,o,f=a.map((n,s)=>{n=L(n);let d=c(n.dialogue)||"";return s===0?(o=c(n.glueEnabled)||false,d):(typeof d=="object"&&"text"in d&&(d=d.character+": "+d.text),o===false&&(d=`
`+d),o=c(n.glueEnabled)||false,d)}),l=c(f[0]),p=typeof l=="object"&&"character"in l?l.character:void 0,g=f.flatMap(n=>{let s;n&&typeof n=="object"&&"text"in n?s=n.text:s=n;let d;return Array.isArray(s)?d=s.map(x=>{let N=c(x);return $.t(`${N}`)}):d=c(s)||"",$.t(d)}),u=a.find(n=>n.end),y=a.find(n=>n.choices),T=false,m=false;a.length>0&&(a[0].glueEnabled&&a[0].goNextStep&&a[0].dialogue===void 0&&storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true),T=a[a.length-1].glueEnabled,m=a.reverse().find(n=>!(n.operations&&(!n.dialogue||!n.choices)))?.goNextStep);let h=a.find(n=>n.labelToOpen),P=[];return a.forEach(n=>{n.operations&&P.forEach(s=>{P.push(s);});}),{dialogue:p?{character:p,text:g}:g,end:u?.end,choices:y?.choices,glueEnabled:T,goNextStep:m,labelToOpen:h?.labelToOpen,operations:P}}}function xe(i){if(!i)return false;if(typeof i!="object"||!("type"in i))return !!i;switch(i.type){case "compare":let t=c(i.leftValue),e=c(i.rightValue);switch(i.operator){case "==":return t===e;case "!=":return t!==e;case "<":return t<e;case "<=":return t<=e;case ">":return t>e;case ">=":return t>=e;case "CONTAINS":return t.toString().includes(e.toString())}break;case "valueCondition":return !!c(i.value);case "union":return be(i)}return !!i}function Te(i){if(i&&typeof i=="object"&&"type"in i&&i.type==="value"&&i.storageOperationType==="get")switch(i.storageType){case "storage":case "tempstorage":return storage.getVariable(i.key);case "flagStorage":return storage.getFlag(i.key);case "label":return narration.getTimesLabelOpened(i.label);case "choice":return narration.getTimesChoiceMade(i.index);case "logic":return c(i.operation);case "params":let t=storage.getVariable(`${k}${narration.openedLabels.length-1}`)||[];if(t&&t.length>i.key)return t[i.key];V.warn("getValue params not found");return}return i}function be(i){if(i.unionType==="not")return !c(i.condition);let t=i.unionType==="and";for(let e=0;e<i.conditions.length;e++)if(t=c(i.conditions[e])||false,i.unionType==="and"){if(!t)return false}else if(t)return true;return t}function X(i){let t=c(i.value),e;switch(t&&typeof t=="object"&&"type"in t?e=c(t):e=t,i.storageType){case "flagStorage":storage.setFlag(i.key,i.value);break;case "storage":storage.setVariable(i.key,e);break;case "tempstorage":storage.setTempVariable(i.key,e);break;case "params":let r=storage.getVariable(`${k}${narration.openedLabels.length-1}`)||[];r&&r.length-1>=i.key&&(r[i.key]=e),storage.setTempVariable(`${k}${narration.openedLabels.length-1}`,r);break}}function c(i){let t=ye(i);if(t&&typeof t=="object"&&"type"in t)switch(t.type){case "value":return Te(t);case "arithmetic":case "arithmeticsingle":return Ve(t);case "compare":case "valueCondition":case "union":return xe(t)}return t}function Ve(i){let t=c(i.leftValue);switch(i.type){case "arithmetic":let e=c(i.rightValue);switch(i.operator){case "*":return t*e;case "/":return t/e;case "+":return t+e;case "-":return t-e;case "%":return t%e;case "POW":return Math.pow(t,e);case "RANDOM":return narration.getRandomNumber(t,e)}case "arithmeticsingle":switch(i.operator){case "INT":return parseInt(t);case "FLOOR":return Math.floor(t);case "FLOAT":return parseFloat(t)}break}}async function H(i){let t=c(i);if(t)switch(t.type){case "assets":switch(t.operationType){case "load":await Assets.load(t.aliases);break;case "lazyload":Assets.backgroundLoad(t.aliases);break}break;case "bundle":switch(t.operationType){case "load":await Assets.loadBundle(t.aliases);break;case "lazyload":Assets.backgroundLoadBundle(t.aliases);break}break}}async function I(i,t){let e=c(i);if(e)switch(e.type){case "sound":switch(e.operationType){case "play":sound.play(e.alias,e.props);break;case "stop":sound.stop(e.alias);break;case "pause":sound.pause(e.alias);break;case "resume":sound.resume(e.alias);break;case "volume":sound.volume(e.alias,e.value);break}break;case "assets":case "bundle":await H(e);break;case "image":switch(e.operationType){case "show":let l=new ImageSprite(e.props,e.url||e.alias);await Y(l,e);break;case "edit":let p=canvas.find(e.alias);p?e.props&&await p.setMemory({...p.memory,...e.props}):V.error(`Image with alias ${e.alias} not found.`);break;case "remove":M(e);break}break;case "video":switch(e.operationType){case "show":let l=new VideoSprite(e.props,e.url||e.alias);await Y(l,e);break;case "edit":let p=canvas.find(e.alias);p?e.props&&await p.setMemory({...p.memory,...e.props}):V.error(`Video with alias ${e.alias} not found.`);break;case "remove":M(e);break;case "pause":let g=canvas.find(e.alias);g?g.paused=true:V.error(`Video with alias ${e.alias} not found.`);break;case "resume":let u=canvas.find(e.alias);u?u.paused=false:V.error(`Video with alias ${e.alias} not found.`);break}break;case "imagecontainer":switch(e.operationType){case "show":let l=new ImageContainer(e.props,e.urls);await Y(l,e);break;case "edit":let p=canvas.find(e.alias);p?e.props&&await p.setMemory({...p.memory,...e.props}):V.error(`ImageContainer with alias ${e.alias} not found.`);break;case "remove":M(e);break}break;case "canvaselement":switch(e.operationType){case "edit":try{let l=canvas.find(e.alias);l?e.props&&(l.memory={...l.memory,...e.props}):V.error(`Canvas Element with alias ${e.alias} not found.`);}catch(l){V.error(`There was an error while trying to edit the canvas element with alias ${e.alias}.`,l);}break;case "remove":M(e);break}break;case "value":X(e);break;case "operationtoconvert":if(t){let l="";e.values.forEach(g=>{if(typeof g=="string")l+=g;else {let u=c(g);l+=`${u}`;}});let p=await t(l);p&&await I(p,t);}break;case "input":switch(e.operationType){case "request":narration.requestInput({type:e.valueType},e.defaultValue);break}break;case "fade":let r=new FadeAlphaTicker(e.props,e.duration,e.priority);canvas.addTicker(e.alias,r);break;case "move":let a=new MoveTicker(e.props,e.duration,e.priority);canvas.addTicker(e.alias,a);break;case "rotate":let o=new RotateTicker(e.props,e.duration,e.priority);canvas.addTicker(e.alias,o);break;case "zoom":let f=new ZoomTicker(e.props,e.duration,e.priority);canvas.addTicker(e.alias,f);break;case "shake":await shakeEffect(e.alias,e.props,e.priority);break}}async function Y(i,t){if(t.transition)switch(t.transition.type){case "fade":await showWithFade(t.alias,i,t.transition.props,t.transition.priority);break;case "dissolve":await showWithDissolve(t.alias,i,t.transition.props,t.transition.priority);break;case "movein":case "moveout":await moveIn(t.alias,i,t.transition.props,t.transition.priority);break;case "zoomin":case "zoomout":await zoomIn(t.alias,i,t.transition.props,t.transition.priority);break;case "pushin":case "pushout":await pushIn(t.alias,i,t.transition.props,t.transition.priority);break}else await i.load(),canvas.add(t.alias,i);}function M(i){if(i.transition)switch(i.transition.type){case "fade":removeWithFade(i.alias,i.transition.props,i.transition.priority);break;case "dissolve":removeWithDissolve(i.alias,i.transition.props,i.transition.priority);break;case "movein":case "moveout":moveOut(i.alias,i.transition.props,i.transition.priority);break;case "zoomin":case "zoomout":zoomOut(i.alias,i.transition.props,i.transition.priority);break;case "pushin":case "pushout":pushOut(i.alias,i.transition.props,i.transition.priority);break}else canvas.remove(i.alias);}var _=class extends LabelAbstract{constructor(t,e,r,a={}){r||(r={}),r.onLoadingLabel=async()=>{for(let o of e){let f;if(typeof o=="function"?f=o():f=o,f=L(f),f.operations){let l=f.operations.map(p=>H(p));await Promise.all(l);}}},super(t,r),this._steps=e,this.operationStringConvert=a.operationStringConvert,this.skipEmptyDialogs=a.skipEmptyDialogs||false;}_steps;get steps(){return this._steps.map(t=>this.stepConverter(t))}get stepCount(){return this._steps.length}getStepById(t){if(t<0||t>=this._steps.length)return;let e=this._steps[t];return this.stepConverter(e)}operationStringConvert;skipEmptyDialogs=false;getStepSha(t){if(t<0||t>=this.steps.length)return;let e=this._steps[t];return (0, se.default)(e.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let e="";if(Array.isArray(t)){let r=[];t.forEach(a=>{if(typeof a=="string")r.push(a);else if(a&&typeof a=="object"){let o=c(a);o?(o&&!Array.isArray(o)&&typeof o=="object"&&(o=c(o)||""),Array.isArray(o)?r=r.concat(o):r.push(`${o}`)):r.push(`${a}`);}}),e=r;}else {let r=c(t)||"";r&&!Array.isArray(r)&&typeof r=="object"&&(r=c(r)||""),e=r;}return `${e}`}getDialogue(t){if(t==null)return;let e=c(t);return e==null?"":typeof e=="object"&&"character"in e&&"text"in e?{character:e.character,text:J.t(this.getDialogueText(e.text))}:J.t(this.getDialogueText(e))}getChoices(t){return c(t)?.map(a=>c(a)).filter(a=>a!==void 0)}stepConverter(t){return async e=>{let r=typeof t=="function"?t():t;r=L(r);let a=this.operationStringConvert?m=>this.operationStringConvert(m,r,e):void 0,{operations:o=[]}=r,{labelToOpen:f=[]}=r;for(let m of o)await I(m,a);let l=this.getChoices(r.choices),p=c(r.glueEnabled),g=this.getDialogue(r.dialogue),u=[];Array.isArray(f)||(f=[f]),f.forEach(m=>{let h=c(m);h&&u.push(h);});let y=c(r.goNextStep),T=c(r.end);if(l){let m=l.map(h=>{let P="";if(Array.isArray(h.text)){let n=[];h.text.forEach(s=>{if(typeof s=="string")n.push(J.t(s));else if(s&&typeof s=="object"){let d=c(s);d&&!Array.isArray(d)&&typeof d=="object"&&(d=c(d)||""),d&&(Array.isArray(d)?n=n.concat(J.t(d)):n.push(J.t(d)));}}),P=n;}else typeof h.text=="string"&&(P=J.t(h.text));return {label:h.label,text:P,props:h.props,type:h.type,oneTime:h.oneTime,onlyHaveNoChoice:h.onlyHaveNoChoice,autoSelect:h.autoSelect}});narration.choiceMenuOptions=m;}else narration.choiceMenuOptions=void 0;g!==void 0&&(narration.dialogue=g,this.skipEmptyDialogs&&typeof g=="string"&&(g===""||RegExp(/^\s+$/).test(g))&&(y=true)),p?storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true):p===false&&storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,false);for(let m of u){let h=m.label;typeof h=="object"&&(h=c(h)||"");let P=m.params?.map(b=>c(b));e={...e,...m.props},m.type==="jump"?(narration.closeCurrentLabel(),storage.setTempVariable(`${k}${narration.openedLabels.length}`,P),await narration.callLabel(h,e)):(storage.setTempVariable(`${k}${narration.openedLabels.length}`,P),await narration.callLabel(h,e));}T==="game_end"?(narration.closeAllLabels(),await narration.goNext(e,{runNow:true})):T==="label_end"&&narration.closeCurrentLabel(),y&&await narration.goNext(e,{runNow:true});}}};async function Me(i,t={}){let{operationStringConvert:e,skipEmptyDialogs:r}=t;if(!Array.isArray(i))if(typeof i=="object"||typeof i=="string")i=[i];else {V.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let a=i.map(async l=>{if(typeof l=="string")try{l=JSON.parse(l);}catch(p){V.error("Error parsing imported Pixi'VN JSON",p),l={};}return l}),f=(await Promise.all(a)).map(async l=>{let p=[];if(l.initialOperations){l.initialOperations.forEach(u=>{let y=I(u,e?T=>e(T,{},{}):void 0);p.push(y);});let g={};[...storage.storage.keys()].forEach((u,y)=>{g[u]=storage.storage.get(u);}),storage.startingStorage=g;}if(l.labels){let g=l.labels;for(let u in g)try{let y=g[u],T=new _(u,y,void 0,t);RegisteredLabels.add(T);}catch(y){V.error(`Error creating JSON label ${u}`,y);}}return Promise.all(p)});await Promise.all(f);}export{_ as LabelJson,k as PIXIVNJSON_PARAM_ID,c as getLogichValue,Me as importPixiVNJson,X as setStorageJson,$ as translator};