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