@drincs/pixi-vn-json 1.7.3 → 1.7.4

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/importer.cjs CHANGED
@@ -1,3 +1 @@
1
- 'use strict';var narration=require('@drincs/pixi-vn/narration'),storage=require('@drincs/pixi-vn/storage');var ae=Object.create;var W=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var fe=(i,e,t)=>e in i?W(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var X=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var Q=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var ue=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of le(e))!pe.call(i,o)&&o!==t&&W(i,o,{get:()=>e[o],enumerable:!(r=se(e,o))||r.enumerable});return i};var de=(i,e,t)=>(t=i!=null?ae(ce(i)):{},ue(W(t,"default",{value:i,enumerable:true}),i));var S=(i,e,t)=>fe(i,typeof e!="symbol"?e+"":e,t);var te=Q((H,ee)=>{(function(i,e){typeof H=="object"?ee.exports=H=e():typeof define=="function"&&define.amd?define([],e):i.CryptoJS=e();})(H,function(){var i=i||(function(e,t){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 X=="function")try{r=X("crypto");}catch{}var o=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.")},s=Object.create||(function(){function n(){}return function(a){var p;return n.prototype=a,p=new n,n.prototype=null,p}})(),l={},c=l.lib={},u=c.Base=(function(){return {extend:function(n){var a=s(this);return n&&a.mixIn(n),(!a.hasOwnProperty("init")||this.init===a.init)&&(a.init=function(){a.$super.init.apply(this,arguments);}),a.init.prototype=a,a.$super=this,a},create:function(){var n=this.extend();return n.init.apply(n,arguments),n},init:function(){},mixIn:function(n){for(var a in n)n.hasOwnProperty(a)&&(this[a]=n[a]);n.hasOwnProperty("toString")&&(this.toString=n.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),x=c.WordArray=u.extend({init:function(n,a){n=this.words=n||[],a!=t?this.sigBytes=a:this.sigBytes=n.length*4;},toString:function(n){return (n||V).stringify(this)},concat:function(n){var a=this.words,p=n.words,h=this.sigBytes,C=n.sigBytes;if(this.clamp(),h%4)for(var E=0;E<C;E++){var M=p[E>>>2]>>>24-E%4*8&255;a[h+E>>>2]|=M<<24-(h+E)%4*8;}else for(var L=0;L<C;L+=4)a[h+L>>>2]=p[L>>>2];return this.sigBytes+=C,this},clamp:function(){var n=this.words,a=this.sigBytes;n[a>>>2]&=4294967295<<32-a%4*8,n.length=e.ceil(a/4);},clone:function(){var n=u.clone.call(this);return n.words=this.words.slice(0),n},random:function(n){for(var a=[],p=0;p<n;p+=4)a.push(o());return new x.init(a,n)}}),d=l.enc={},V=d.Hex={stringify:function(n){for(var a=n.words,p=n.sigBytes,h=[],C=0;C<p;C++){var E=a[C>>>2]>>>24-C%4*8&255;h.push((E>>>4).toString(16)),h.push((E&15).toString(16));}return h.join("")},parse:function(n){for(var a=n.length,p=[],h=0;h<a;h+=2)p[h>>>3]|=parseInt(n.substr(h,2),16)<<24-h%8*4;return new x.init(p,a/2)}},y=d.Latin1={stringify:function(n){for(var a=n.words,p=n.sigBytes,h=[],C=0;C<p;C++){var E=a[C>>>2]>>>24-C%4*8&255;h.push(String.fromCharCode(E));}return h.join("")},parse:function(n){for(var a=n.length,p=[],h=0;h<a;h++)p[h>>>2]|=(n.charCodeAt(h)&255)<<24-h%4*8;return new x.init(p,a)}},v=d.Utf8={stringify:function(n){try{return decodeURIComponent(escape(y.stringify(n)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(n){return y.parse(unescape(encodeURIComponent(n)))}},N=c.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new x.init,this._nDataBytes=0;},_append:function(n){typeof n=="string"&&(n=v.parse(n)),this._data.concat(n),this._nDataBytes+=n.sigBytes;},_process:function(n){var a,p=this._data,h=p.words,C=p.sigBytes,E=this.blockSize,M=E*4,L=C/M;n?L=e.ceil(L):L=e.max((L|0)-this._minBufferSize,0);var B=L*E,U=e.min(B*4,C);if(B){for(var K=0;K<B;K+=E)this._doProcessBlock(h,K);a=h.splice(0,B),p.sigBytes-=U;}return new x.init(a,U)},clone:function(){var n=u.clone.call(this);return n._data=this._data.clone(),n},_minBufferSize:0});c.Hasher=N.extend({cfg:u.extend(),init:function(n){this.cfg=this.cfg.extend(n),this.reset();},reset:function(){N.reset.call(this),this._doReset();},update:function(n){return this._append(n),this._process(),this},finalize:function(n){n&&this._append(n);var a=this._doFinalize();return a},blockSize:512/32,_createHelper:function(n){return function(a,p){return new n.init(p).finalize(a)}},_createHmacHelper:function(n){return function(a,p){return new b.HMAC.init(n,p).finalize(a)}}});var b=l.algo={};return l})(Math);return i});});var ne=Q(($,ie)=>{(function(i,e){typeof $=="object"?ie.exports=$=e(te()):typeof define=="function"&&define.amd?define(["./core"],e):e(i.CryptoJS);})($,function(i){return (function(){var e=i,t=e.lib,r=t.WordArray,o=t.Hasher,s=e.algo,l=[],c=s.SHA1=o.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(u,x){for(var d=this._hash.words,V=d[0],y=d[1],v=d[2],N=d[3],T=d[4],b=0;b<80;b++){if(b<16)l[b]=u[x+b]|0;else {var n=l[b-3]^l[b-8]^l[b-14]^l[b-16];l[b]=n<<1|n>>>31;}var a=(V<<5|V>>>27)+T+l[b];b<20?a+=(y&v|~y&N)+1518500249:b<40?a+=(y^v^N)+1859775393:b<60?a+=(y&v|y&N|v&N)-1894007588:a+=(y^v^N)-899497514,T=N,N=v,v=y<<30|y>>>2,y=V,V=a;}d[0]=d[0]+V|0,d[1]=d[1]+y|0,d[2]=d[2]+v|0,d[3]=d[3]+N|0,d[4]=d[4]+T|0;},_doFinalize:function(){var u=this._data,x=u.words,d=this._nDataBytes*8,V=u.sigBytes*8;return x[V>>>5]|=128<<24-V%32,x[(V+64>>>9<<4)+14]=Math.floor(d/4294967296),x[(V+64>>>9<<4)+15]=d,u.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var u=o.clone.call(this);return u._hash=this._hash.clone(),u}});e.SHA1=o._createHelper(c),e.HmacSHA1=o._createHmacHelper(c);})(),i.SHA1});});var J;(o=>(o.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),o.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),o.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),o.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(J||(J={}));var f=class f{static t(e){return Array.isArray(e)?e.map(t=>f.translate(`${t}`)):f.translate(`${e}`)}static set beforeToTranslate(e){f._beforeToTranslate=e;}static set translate(e){f._translate=e;}static get translate(){return e=>{let t=e;return f._beforeToTranslate&&(t=f._beforeToTranslate(t)),t=f._translate(t),f._afterToTranslate&&(t=f._afterToTranslate(t)),t}}static set afterToTranslate(e){f._afterToTranslate=e;}static addKey(e,t,r){let o=r.defaultValue||"empty_string";typeof t=="string"&&(t=[t]),Array.isArray(t)&&t.forEach(s=>{e[s]===void 0&&(o==="empty_string"?e[s]="":o==="copy_key"&&(f._beforeToTranslate?e[s]=f._beforeToTranslate(s):e[s]=s));});}static getConditionalsThenElse(e,t=[]){if(typeof e=="object"&&e&&"type"in e)if(e.type==="ifelse")e.then&&f.getConditionalsThenElse(e.then,t),e.else&&f.getConditionalsThenElse(e.else,t);else if(e.type==="stepswitch"){if(e.elements)if(Array.isArray(e.elements))e.elements.forEach(r=>{f.getConditionalsThenElse(r,t);});else if(e.elements.type==="ifelse"){let r=[];f.getConditionalsThenElse(e.elements,r),r.forEach(o=>{t.push(...o);});}else if(e.elements.type==="stepswitch"){let r=[];f.getConditionalsThenElse(e.elements,r),r.forEach(o=>{t.push(...o);});}else f.getConditionalsThenElse(e.elements,t);}else e.type==="resulttocombine"?(e.firstItem&&f.getConditionalsThenElse(e.firstItem,t),e.secondConditionalItem&&e.secondConditionalItem.forEach(r=>{f.getConditionalsThenElse(r,t);})):t.push(e);else e&&t.push(e);return t}static generateJsonTranslation(e,t={},r={}){let{defaultValue:o="copy_key"}=r;return e.forEach(s=>{if(s.choices){let l=[];Array.isArray(s.choices)?l=[s.choices]:l=f.getConditionalsThenElse(s.choices),l.forEach(c=>c.forEach(u=>{if("type"in u){let x=[];u.type==="ifelse"||u.type==="stepswitch"?f.getConditionalsThenElse(u,x):x=[u],x.map(V=>f.getConditionalsThenElse(V.text)).forEach(V=>{Array.isArray(V)&&V.forEach(y=>{Array.isArray(y)?y.forEach(v=>{typeof v=="string"?f.addKey(t,v,{defaultValue:o}):f.getConditionalsThenElse(v).forEach(N=>{Array.isArray(N)?N.forEach(T=>{typeof T=="string"&&f.addKey(t,T,{defaultValue:o});}):typeof N=="string"&&f.addKey(t,N,{defaultValue:o});});}):typeof y=="string"&&f.addKey(t,y,{defaultValue:o});});});}}));}if(s.dialogue){let l=[];Array.isArray(s.dialogue)?l=[s.dialogue]:l=f.getConditionalsThenElse(s.dialogue),l.forEach(c=>{if(typeof c=="string")f.addKey(t,c,{defaultValue:o});else if("text"in c){let u=f.getConditionalsThenElse(c.text);typeof u=="string"&&(u=[u]),u.forEach(x=>{typeof x=="string"?f.addKey(t,x,{defaultValue:o}):f.getConditionalsThenElse(x).forEach(V=>{typeof V=="string"?f.addKey(t,V,{defaultValue:o}):Array.isArray(V)&&V.forEach(y=>{typeof y=="string"?f.addKey(t,y,{defaultValue:o}):f.getConditionalsThenElse(y).forEach(v=>{typeof v=="string"&&f.addKey(t,v,{defaultValue:o});});});});});}});}s.conditionalStep&&f.getConditionalsThenElse(s.conditionalStep).forEach(c=>{Array.isArray(c)?f.generateJsonTranslation(c,t,r):f.generateJsonTranslation([c],t,r);});}),t}};S(f,"_beforeToTranslate"),S(f,"_translate",e=>e),S(f,"_afterToTranslate");var D=f;var w=D;var _="___param___";function G(i){try{if(typeof i>"u")return i;let e=JSON.stringify(i);return JSON.parse(e)}catch(e){throw J.error("Error creating exportable element",i,e),new Error("[Pixi\u2019VN] Error creating exportable element")}}function Z(i){let e=P(i.value),t;switch(e&&typeof e=="object"&&"type"in e?t=P(e):t=e,i.storageType){case "flagStorage":storage.storage.setFlag(i.key,i.value);break;case "storage":storage.storage.setVariable(i.key,t);break;case "tempstorage":storage.storage.setTempVariable(i.key,t);break;case "params":let r=storage.storage.getVariable(`${_}${narration.narration.openedLabels.length-1}`)||[];r&&r.length-1>=i.key&&(r[i.key]=t),storage.storage.setTempVariable(`${_}${narration.narration.openedLabels.length-1}`,r);break}}function P(i){let e=ye(i);if(e&&typeof e=="object"&&"type"in e)switch(e.type){case "value":return he(e);case "arithmetic":case "arithmeticsingle":return ge(e);case "compare":case "valueCondition":case "union":return xe(e)}return e}function ge(i){let e=P(i.leftValue);switch(i.type){case "arithmetic":let t=P(i.rightValue);switch(i.operator){case "*":return e*t;case "/":return e/t;case "+":return e+t;case "-":return e-t;case "%":return e%t;case "POW":return Math.pow(e,t);case "RANDOM":return narration.narration.getRandomNumber(e,t)}case "arithmeticsingle":switch(i.operator){case "INT":return parseInt(e);case "FLOOR":return Math.floor(e);case "FLOAT":return parseFloat(e)}break}}function he(i){if(i&&typeof i=="object"&&"type"in i&&i.type==="value"&&i.storageOperationType==="get")switch(i.storageType){case "storage":case "tempstorage":return storage.storage.getVariable(i.key);case "flagStorage":return storage.storage.getFlag(i.key);case "label":return narration.narration.getTimesLabelOpened(i.label);case "choice":return narration.narration.getTimesChoiceMade(i.index);case "logic":return P(i.operation);case "params":let e=storage.storage.getVariable(`${_}${narration.narration.openedLabels.length-1}`)||[];if(e&&e.length>i.key)return e[i.key];J.warn("getValue params not found");return}return i}function xe(i){if(!i)return false;if(typeof i!="object"||!("type"in i))return !!i;switch(i.type){case "compare":let e=P(i.leftValue),t=P(i.rightValue);switch(i.operator){case "==":return e===t;case "!=":return e!==t;case "<":return e<t;case "<=":return e<=t;case ">":return e>t;case ">=":return e>=t;case "CONTAINS":return e.toString().includes(t.toString())}break;case "valueCondition":return !!P(i.value);case "union":return me(i)}return !!i}function me(i){if(i.unionType==="not")return !P(i.condition);let e=i.unionType==="and";for(let t=0;t<i.conditions.length;t++)if(e=P(i.conditions[t])||false,i.unionType==="and"){if(!e)return false}else if(e)return true;return e}function Ve(i,e){return Math.floor(Math.random()*(e-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 Pe(i);case "ifelse":return P(i.condition)?P(i.then):P(i.else);case "stepswitch":let t=P(i.elements)||[];if(t.length===0){J.error("getValueFromConditionalStatements elements.length === 0");return}switch(i.choiceType){case "random":let r=Ve(0,t.length-1);return P(t[r]);case "loop":let o=narration.NarrationManagerStatic.getCurrentStepTimesCounter(i.nestedId)-1;return o>t.length-1&&(o=o%t.length),P(t[o]);case "sequential":let s,l=narration.NarrationManagerStatic.getCurrentStepTimesCounter(i.nestedId)-1;return i.end=="lastItem"&&(s=P(t[t.length-1])),l>t.length-1?s:P(t[l]);case "sequentialrandom":let c=narration.NarrationManagerStatic.getRandomNumber(0,t.length-1,{nestedId:i.nestedId,onceOnly:true});if(c==null&&i.end=="lastItem"){let u=narration.NarrationManagerStatic.getCurrentStepTimesCounterData(i.nestedId);if(!u||!u?.usedRandomNumbers){J.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}let x=u.usedRandomNumbers[`0-${t.length-1}`];return P(t[x[x.length-1]])}if(c==null){J.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}return P(t[c])}}return i}function z(i){if(i.conditionalStep){let e=G(P(i.conditionalStep));if(e?.glueEnabled===void 0&&delete e?.glueEnabled,e?.goNextStep===void 0&&delete e?.goNextStep,e?.end===void 0&&delete e?.end,e?.choices===void 0&&delete e?.choices,e?.dialogue===void 0&&delete e?.dialogue,e?.labelToOpen===void 0&&delete e?.labelToOpen,e?.operations===void 0&&delete e?.operations,e){let t={...i,conditionalStep:void 0,...e};return z(t)}else storage.storage.getFlag(storage.SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)&&storage.storage.setFlag(storage.SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,false);}return i}function Pe(i){let e=i.firstItem,t=[];i.secondConditionalItem?.forEach(o=>{if(Array.isArray(o))o.forEach(s=>{let l=P(s);t.push(l);});else {let s=P(o);t.push(s);}});let r=e?[e,...t]:t;if(r.length===0){J.warn("combinateResult toCheck.length === 0");return}if(typeof r[0]=="string")return w.t(r);if(typeof r[0]=="object"){let o=r,s,l=o.map((n,a)=>{n=z(n);let p=P(n.dialogue)||"";return a===0?(s=P(n.glueEnabled)||false,p):(typeof p=="object"&&"text"in p&&(p=p.character+": "+p.text),s===false&&(p=`
2
-
3
- `+p),s=P(n.glueEnabled)||false,p)}),c=P(l[0]),u=typeof c=="object"&&"character"in c?c.character:void 0,x=l.flatMap(n=>{let a;n&&typeof n=="object"&&"text"in n?a=n.text:a=n;let p;return Array.isArray(a)?p=a.map(h=>{let C=P(h);return w.t(`${C}`)}):p=P(a)||"",w.t(p)}),d=o.find(n=>n.end),V=o.find(n=>n.choices),y=false,v=false;o.length>0&&(o[0].glueEnabled&&o[0].goNextStep&&o[0].dialogue===void 0&&storage.storage.setFlag(storage.SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true),y=o[o.length-1].glueEnabled,v=o.reverse().find(n=>!(n.operations&&(!n.dialogue||!n.choices)))?.goNextStep);let N=o.find(n=>n.labelToOpen),T=[];return o.forEach(n=>{n.operations&&T.forEach(a=>{T.push(a);});}),{dialogue:u?{character:u,text:x}:x,end:d?.end,choices:V?.choices,glueEnabled:y,goNextStep:v,labelToOpen:N?.labelToOpen,operations:T}}}var g=class g{static init(e){g._loadAssets=e.loadAssets,g._soundOperation=e.soundOperation,g._imageOperation=e.imageOperation,g._videoOperation=e.videoOperation,g._imageContainerOperation=e.imageContainerOperation,g._canvasElementOperation=e.canvasElementOperation,g._setStorageValue=e.setStorageValue,g._inputOperation=e.inputOperation,g._tickerOperation=e.tickerOperation,g._effectOperation=e.effectOperation,g._animateOperation=e.animateOperation,g._getLogichValue=e.getLogichValue,g._getConditionalStep=e.getConditionalStep;}static get loadAssets(){return g._loadAssets}static get soundOperation(){return g._soundOperation}static get imageOperation(){return g._imageOperation}static get videoOperation(){return g._videoOperation}static get imageContainerOperation(){return g._imageContainerOperation}static get canvasElementOperation(){return g._canvasElementOperation}static get setStorageValue(){return g._setStorageValue}static get inputOperation(){return g._inputOperation}static get tickerOperation(){return g._tickerOperation}static get effectOperation(){return g._effectOperation}static get animateOperation(){return g._animateOperation}static get getLogichValue(){return g._getLogichValue}static get getConditionalStep(){return g._getConditionalStep}};S(g,"_loadAssets",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_soundOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_imageOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_videoOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_imageContainerOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_canvasElementOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_setStorageValue",Z),S(g,"_inputOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_tickerOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_effectOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_animateOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_getLogichValue",P),S(g,"_getConditionalStep",z);var m=g;async function R(i,e){let t=m.getLogichValue(i);if(t)switch(t.type){case "sound":m.soundOperation(t);break;case "assets":case "bundle":await m.loadAssets(t);break;case "image":await m.imageOperation(t);break;case "video":await m.videoOperation(t);break;case "imagecontainer":await m.imageContainerOperation(t);break;case "canvaselement":await m.canvasElementOperation(t);break;case "value":m.setStorageValue(t);break;case "operationtoconvert":if(e){let r="";t.values.forEach(s=>{if(typeof s=="string")r+=s;else {let l=m.getLogichValue(s);r+=`${l}`;}});let o=await e(r);o&&await R(o,e);}break;case "input":m.inputOperation(t);break;case "fade":case "move":case "rotate":case "zoom":m.tickerOperation(t);break;case "shake":await m.effectOperation(t);break;case "animate":case "animate-sequence":m.animateOperation(t);break}}async function Te(i,e={}){let{operationStringConvert:t,skipEmptyDialogs:r}=e;if(!Array.isArray(i))if(typeof i=="object"||typeof i=="string")i=[i];else {J.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let o=i.map(async c=>{if(typeof c=="string")try{c=JSON.parse(c);}catch(u){J.error("Error parsing imported Pixi'VN JSON",u),c={};}return c}),l=(await Promise.all(o)).map(async c=>{let u=[];if(c.initialOperations){c.initialOperations.forEach(d=>{let V=R(d,t?y=>t(y,{},{}):void 0);u.push(V);});let x={};[...storage.storage.storage.keys()].forEach((d,V)=>{x[d]=storage.storage.storage.get(d);}),storage.storage.startingStorage=x;}if(c.labels){let x=c.labels;for(let d in x)try{let V=x[d],y=new k(d,V,void 0,e);narration.RegisteredLabels.add(y);}catch(V){J.error(`Error creating JSON label ${d}`,V);}}return Promise.all(u)});await Promise.all(l);}var re=de(ne());var k=class extends narration.LabelAbstract{constructor(t,r,o,s={}){o||(o={}),o.onLoadingLabel=async()=>{for(let l of r){let c;if(typeof l=="function"?c=l():c=l,c=m.getConditionalStep(c),c.operations){let u=c.operations.map(x=>m.loadAssets(x));await Promise.all(u);}}};super(t,o);S(this,"_steps");S(this,"operationStringConvert");S(this,"skipEmptyDialogs",false);this._steps=r,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}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 r=this._steps[t];return this.stepConverter(r)}getStepSha(t){if(t<0||t>=this.steps.length)return;let r=this._steps[t];return (0, re.default)(r.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let r="";if(Array.isArray(t)){let o=[];t.forEach(s=>{if(typeof s=="string")o.push(s);else if(s&&typeof s=="object"){let l=m.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=m.getLogichValue(l)||""),Array.isArray(l)?o=o.concat(l):o.push(`${l}`)):o.push(`${s}`);}}),r=o;}else {let o=m.getLogichValue(t)||"";o&&!Array.isArray(o)&&typeof o=="object"&&(o=m.getLogichValue(o)||""),r=o;}return `${r}`}getDialogue(t){if(t==null)return;let r=m.getLogichValue(t);return r==null?"":typeof r=="object"&&"character"in r&&"text"in r?{character:r.character,text:w.t(this.getDialogueText(r.text))}:w.t(this.getDialogueText(r))}getChoices(t){return m.getLogichValue(t)?.map(s=>m.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(t){return async r=>{let o=typeof t=="function"?t():t;o=G(o),o=m.getConditionalStep(o);let s=this.operationStringConvert?N=>this.operationStringConvert(N,o,r):void 0,{operations:l=[]}=o;for(let N of l)await R(N,s);let{labelToOpen:c=[]}=o,u=this.getChoices(o.choices),x=m.getLogichValue(o.glueEnabled),d=this.getDialogue(o.dialogue),V=[];Array.isArray(c)||(c=[c]),c.forEach(N=>{let T=m.getLogichValue(N);T&&V.push(T);});let y=m.getLogichValue(o.goNextStep),v=m.getLogichValue(o.end);if(u){let N=u.map(T=>{let b="";if(Array.isArray(T.text)){let a=[];T.text.forEach(p=>{if(typeof p=="string")a.push(w.t(p));else if(p&&typeof p=="object"){let h=m.getLogichValue(p);h&&!Array.isArray(h)&&typeof h=="object"&&(h=m.getLogichValue(h)||""),h&&(Array.isArray(h)?a=a.concat(w.t(h)):a.push(w.t(h)));}}),b=a;}else typeof T.text=="string"&&(b=w.t(T.text));return {label:T.label,text:b,props:T.props,type:T.type,oneTime:T.oneTime,onlyHaveNoChoice:T.onlyHaveNoChoice,autoSelect:T.autoSelect}});narration.narration.choiceMenuOptions=N;}else narration.narration.choiceMenuOptions=void 0;d!==void 0&&(narration.narration.dialogue=d,this.skipEmptyDialogs&&typeof d=="string"&&(d===""||RegExp(/^\s+$/).test(d))&&(y=true)),x?storage.storage.setFlag(storage.SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true):x===false&&storage.storage.setFlag(storage.SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,false);for(let N of V){let T=N.label;typeof T=="object"&&(T=m.getLogichValue(T)||"");let b=N.params?.map(n=>m.getLogichValue(n));r={...r,...N.props},N.type==="jump"?(narration.narration.openedLabels.length>0&&narration.narration.closeCurrentLabel(),storage.storage.setTempVariable(`${_}${narration.narration.openedLabels.length}`,b),await narration.narration.callLabel(T,r)):(storage.storage.setTempVariable(`${_}${narration.narration.openedLabels.length}`,b),await narration.narration.callLabel(T,r));}v==="game_end"?(narration.narration.closeAllLabels(),await narration.narration.goNext(r,{runNow:true})):v==="label_end"&&narration.narration.closeCurrentLabel(),y&&await narration.narration.goNext(r,{runNow:true});}}};exports.LabelJson=k;exports.importPixiVNJson=Te;
1
+ 'use strict';var narration=require('@drincs/pixi-vn/narration'),storage=require('@drincs/pixi-vn/storage'),unifier=require('@drincs/pixi-vn-json/unifier');var Z=Object.create;var $=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var re=(a,t,e)=>t in a?$(a,t,{enumerable:true,configurable:true,writable:true,value:e}):a[t]=e;var K=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var F=(a,t)=>()=>(t||a((t={exports:{}}).exports,t),t.exports);var oe=(a,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of te(t))!ne.call(a,n)&&n!==e&&$(a,n,{get:()=>t[n],enumerable:!(r=ee(t,n))||r.enumerable});return a};var se=(a,t,e)=>(e=a!=null?Z(ie(a)):{},oe($(e,"default",{value:a,enumerable:true}),a));var C=(a,t,e)=>re(a,typeof t!="symbol"?t+"":t,e);var X=F((B,G)=>{(function(a,t){typeof B=="object"?G.exports=B=t():typeof define=="function"&&define.amd?define([],t):a.CryptoJS=t();})(B,function(){var a=a||(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 K=="function")try{r=K("crypto");}catch{}var n=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.")},s=Object.create||(function(){function i(){}return function(o){var y;return i.prototype=o,y=new i,i.prototype=null,y}})(),l={},c=l.lib={},u=c.Base=(function(){return {extend:function(i){var o=s(this);return i&&o.mixIn(i),(!o.hasOwnProperty("init")||this.init===o.init)&&(o.init=function(){o.$super.init.apply(this,arguments);}),o.init.prototype=o,o.$super=this,o},create:function(){var i=this.extend();return i.init.apply(i,arguments),i},init:function(){},mixIn:function(i){for(var o in i)i.hasOwnProperty(o)&&(this[o]=i[o]);i.hasOwnProperty("toString")&&(this.toString=i.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),d=c.WordArray=u.extend({init:function(i,o){i=this.words=i||[],o!=e?this.sigBytes=o:this.sigBytes=i.length*4;},toString:function(i){return (i||h).stringify(this)},concat:function(i){var o=this.words,y=i.words,g=this.sigBytes,P=i.sigBytes;if(this.clamp(),g%4)for(var N=0;N<P;N++){var R=y[N>>>2]>>>24-N%4*8&255;o[g+N>>>2]|=R<<24-(g+N)%4*8;}else for(var E=0;E<P;E+=4)o[g+E>>>2]=y[E>>>2];return this.sigBytes+=P,this},clamp:function(){var i=this.words,o=this.sigBytes;i[o>>>2]&=4294967295<<32-o%4*8,i.length=t.ceil(o/4);},clone:function(){var i=u.clone.call(this);return i.words=this.words.slice(0),i},random:function(i){for(var o=[],y=0;y<i;y+=4)o.push(n());return new d.init(o,i)}}),p=l.enc={},h=p.Hex={stringify:function(i){for(var o=i.words,y=i.sigBytes,g=[],P=0;P<y;P++){var N=o[P>>>2]>>>24-P%4*8&255;g.push((N>>>4).toString(16)),g.push((N&15).toString(16));}return g.join("")},parse:function(i){for(var o=i.length,y=[],g=0;g<o;g+=2)y[g>>>3]|=parseInt(i.substr(g,2),16)<<24-g%8*4;return new d.init(y,o/2)}},m=p.Latin1={stringify:function(i){for(var o=i.words,y=i.sigBytes,g=[],P=0;P<y;P++){var N=o[P>>>2]>>>24-P%4*8&255;g.push(String.fromCharCode(N));}return g.join("")},parse:function(i){for(var o=i.length,y=[],g=0;g<o;g++)y[g>>>2]|=(i.charCodeAt(g)&255)<<24-g%4*8;return new d.init(y,o)}},v=p.Utf8={stringify:function(i){try{return decodeURIComponent(escape(m.stringify(i)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(i){return m.parse(unescape(encodeURIComponent(i)))}},x=c.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new d.init,this._nDataBytes=0;},_append:function(i){typeof i=="string"&&(i=v.parse(i)),this._data.concat(i),this._nDataBytes+=i.sigBytes;},_process:function(i){var o,y=this._data,g=y.words,P=y.sigBytes,N=this.blockSize,R=N*4,E=P/R;i?E=t.ceil(E):E=t.max((E|0)-this._minBufferSize,0);var D=E*N,U=t.min(D*4,P);if(D){for(var H=0;H<D;H+=N)this._doProcessBlock(g,H);o=g.splice(0,D),y.sigBytes-=U;}return new d.init(o,U)},clone:function(){var i=u.clone.call(this);return i._data=this._data.clone(),i},_minBufferSize:0});c.Hasher=x.extend({cfg:u.extend(),init:function(i){this.cfg=this.cfg.extend(i),this.reset();},reset:function(){x.reset.call(this),this._doReset();},update:function(i){return this._append(i),this._process(),this},finalize:function(i){i&&this._append(i);var o=this._doFinalize();return o},blockSize:512/32,_createHelper:function(i){return function(o,y){return new i.init(y).finalize(o)}},_createHmacHelper:function(i){return function(o,y){return new T.HMAC.init(i,y).finalize(o)}}});var T=l.algo={};return l})(Math);return a});});var Y=F((k,q)=>{(function(a,t){typeof k=="object"?q.exports=k=t(X()):typeof define=="function"&&define.amd?define(["./core"],t):t(a.CryptoJS);})(k,function(a){return (function(){var t=a,e=t.lib,r=e.WordArray,n=e.Hasher,s=t.algo,l=[],c=s.SHA1=n.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(u,d){for(var p=this._hash.words,h=p[0],m=p[1],v=p[2],x=p[3],b=p[4],T=0;T<80;T++){if(T<16)l[T]=u[d+T]|0;else {var i=l[T-3]^l[T-8]^l[T-14]^l[T-16];l[T]=i<<1|i>>>31;}var o=(h<<5|h>>>27)+b+l[T];T<20?o+=(m&v|~m&x)+1518500249:T<40?o+=(m^v^x)+1859775393:T<60?o+=(m&v|m&x|v&x)-1894007588:o+=(m^v^x)-899497514,b=x,x=v,v=m<<30|m>>>2,m=h,h=o;}p[0]=p[0]+h|0,p[1]=p[1]+m|0,p[2]=p[2]+v|0,p[3]=p[3]+x|0,p[4]=p[4]+b|0;},_doFinalize:function(){var u=this._data,d=u.words,p=this._nDataBytes*8,h=u.sigBytes*8;return d[h>>>5]|=128<<24-h%32,d[(h+64>>>9<<4)+14]=Math.floor(p/4294967296),d[(h+64>>>9<<4)+15]=p,u.sigBytes=d.length*4,this._process(),this._hash},clone:function(){var u=n.clone.call(this);return u._hash=this._hash.clone(),u}});t.SHA1=n._createHelper(c),t.HmacSHA1=n._createHmacHelper(c);})(),a.SHA1});});var L;(n=>(n.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),n.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),n.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),n.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(L||(L={}));async function O(a,t){let e=unifier.JsonUnifier.getLogichValue(a);if(e)switch(e.type){case "sound":unifier.JsonUnifier.soundOperation(e);break;case "assets":case "bundle":await unifier.JsonUnifier.loadAssets(e);break;case "image":await unifier.JsonUnifier.imageOperation(e);break;case "video":await unifier.JsonUnifier.videoOperation(e);break;case "imagecontainer":await unifier.JsonUnifier.imageContainerOperation(e);break;case "canvaselement":await unifier.JsonUnifier.canvasElementOperation(e);break;case "value":unifier.JsonUnifier.setStorageValue(e);break;case "operationtoconvert":if(t){let r="";e.values.forEach(s=>{if(typeof s=="string")r+=s;else {let l=unifier.JsonUnifier.getLogichValue(s);r+=`${l}`;}});let n=await t(r);n&&await O(n,t);}break;case "input":unifier.JsonUnifier.inputOperation(e);break;case "fade":case "move":case "rotate":case "zoom":unifier.JsonUnifier.tickerOperation(e);break;case "shake":await unifier.JsonUnifier.effectOperation(e);break;case "animate":case "animate-sequence":unifier.JsonUnifier.animateOperation(e);break}}async function le(a,t={}){let{operationStringConvert:e,skipEmptyDialogs:r}=t;if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {L.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let n=a.map(async c=>{if(typeof c=="string")try{c=JSON.parse(c);}catch(u){L.error("Error parsing imported Pixi'VN JSON",u),c={};}return c}),l=(await Promise.all(n)).map(async c=>{let u=[];if(c.initialOperations){c.initialOperations.forEach(p=>{let h=O(p,e?m=>e(m,{},{}):void 0);u.push(h);});let d={};[...storage.storage.storage.keys()].forEach((p,h)=>{d[p]=storage.storage.storage.get(p);}),storage.storage.startingStorage=d;}if(c.labels){let d=c.labels;for(let p in d)try{let h=d[p],m=new A(p,h,void 0,t);narration.RegisteredLabels.add(m);}catch(h){L.error(`Error creating JSON label ${p}`,h);}}return Promise.all(u)});await Promise.all(l);}var f=class f{static t(t){return Array.isArray(t)?t.map(e=>f.translate(`${e}`)):f.translate(`${t}`)}static set beforeToTranslate(t){f._beforeToTranslate=t;}static set translate(t){f._translate=t;}static get translate(){return t=>{let e=t;return f._beforeToTranslate&&(e=f._beforeToTranslate(e)),e=f._translate(e),f._afterToTranslate&&(e=f._afterToTranslate(e)),e}}static set afterToTranslate(t){f._afterToTranslate=t;}static addKey(t,e,r){let n=r.defaultValue||"empty_string";typeof e=="string"&&(e=[e]),Array.isArray(e)&&e.forEach(s=>{t[s]===void 0&&(n==="empty_string"?t[s]="":n==="copy_key"&&(f._beforeToTranslate?t[s]=f._beforeToTranslate(s):t[s]=s));});}static getConditionalsThenElse(t,e=[]){if(typeof t=="object"&&t&&"type"in t)if(t.type==="ifelse")t.then&&f.getConditionalsThenElse(t.then,e),t.else&&f.getConditionalsThenElse(t.else,e);else if(t.type==="stepswitch"){if(t.elements)if(Array.isArray(t.elements))t.elements.forEach(r=>{f.getConditionalsThenElse(r,e);});else if(t.elements.type==="ifelse"){let r=[];f.getConditionalsThenElse(t.elements,r),r.forEach(n=>{e.push(...n);});}else if(t.elements.type==="stepswitch"){let r=[];f.getConditionalsThenElse(t.elements,r),r.forEach(n=>{e.push(...n);});}else f.getConditionalsThenElse(t.elements,e);}else t.type==="resulttocombine"?(t.firstItem&&f.getConditionalsThenElse(t.firstItem,e),t.secondConditionalItem&&t.secondConditionalItem.forEach(r=>{f.getConditionalsThenElse(r,e);})):e.push(t);else t&&e.push(t);return e}static generateJsonTranslation(t,e={},r={}){let{defaultValue:n="copy_key"}=r;return t.forEach(s=>{if(s.choices){let l=[];Array.isArray(s.choices)?l=[s.choices]:l=f.getConditionalsThenElse(s.choices),l.forEach(c=>c.forEach(u=>{if("type"in u){let d=[];u.type==="ifelse"||u.type==="stepswitch"?f.getConditionalsThenElse(u,d):d=[u],d.map(h=>f.getConditionalsThenElse(h.text)).forEach(h=>{Array.isArray(h)&&h.forEach(m=>{Array.isArray(m)?m.forEach(v=>{typeof v=="string"?f.addKey(e,v,{defaultValue:n}):f.getConditionalsThenElse(v).forEach(x=>{Array.isArray(x)?x.forEach(b=>{typeof b=="string"&&f.addKey(e,b,{defaultValue:n});}):typeof x=="string"&&f.addKey(e,x,{defaultValue:n});});}):typeof m=="string"&&f.addKey(e,m,{defaultValue:n});});});}}));}if(s.dialogue){let l=[];Array.isArray(s.dialogue)?l=[s.dialogue]:l=f.getConditionalsThenElse(s.dialogue),l.forEach(c=>{if(typeof c=="string")f.addKey(e,c,{defaultValue:n});else if("text"in c){let u=f.getConditionalsThenElse(c.text);typeof u=="string"&&(u=[u]),u.forEach(d=>{typeof d=="string"?f.addKey(e,d,{defaultValue:n}):f.getConditionalsThenElse(d).forEach(h=>{typeof h=="string"?f.addKey(e,h,{defaultValue:n}):Array.isArray(h)&&h.forEach(m=>{typeof m=="string"?f.addKey(e,m,{defaultValue:n}):f.getConditionalsThenElse(m).forEach(v=>{typeof v=="string"&&f.addKey(e,v,{defaultValue:n});});});});});}});}s.conditionalStep&&f.getConditionalsThenElse(s.conditionalStep).forEach(c=>{Array.isArray(c)?f.generateJsonTranslation(c,e,r):f.generateJsonTranslation([c],e,r);});}),e}};C(f,"_beforeToTranslate"),C(f,"_translate",t=>t),C(f,"_afterToTranslate");var _=f;var w=_;var Q=se(Y());var W="___param___";function j(a){try{if(typeof a>"u")return a;let t=JSON.stringify(a);return JSON.parse(t)}catch(t){throw L.error("Error creating exportable element",a,t),new Error("[Pixi\u2019VN] Error creating exportable element")}}var A=class extends narration.LabelAbstract{constructor(e,r,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let l of r){let c;if(typeof l=="function"?c=l():c=l,c=unifier.JsonUnifier.getConditionalStep(c),c.operations){let u=c.operations.map(d=>unifier.JsonUnifier.loadAssets(d));await Promise.all(u);}}};super(e,n);C(this,"_steps");C(this,"operationStringConvert");C(this,"skipEmptyDialogs",false);this._steps=r,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(e=>this.stepConverter(e))}get stepCount(){return this._steps.length}getStepById(e){if(e<0||e>=this._steps.length)return;let r=this._steps[e];return this.stepConverter(r)}getStepSha(e){if(e<0||e>=this.steps.length)return;let r=this._steps[e];return (0, Q.default)(r.toString().toLocaleLowerCase()).toString()}getDialogueText(e){let r="";if(Array.isArray(e)){let n=[];e.forEach(s=>{if(typeof s=="string")n.push(s);else if(s&&typeof s=="object"){let l=unifier.JsonUnifier.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=unifier.JsonUnifier.getLogichValue(l)||""),Array.isArray(l)?n=n.concat(l):n.push(`${l}`)):n.push(`${s}`);}}),r=n;}else {let n=unifier.JsonUnifier.getLogichValue(e)||"";n&&!Array.isArray(n)&&typeof n=="object"&&(n=unifier.JsonUnifier.getLogichValue(n)||""),r=n;}return `${r}`}getDialogue(e){if(e==null)return;let r=unifier.JsonUnifier.getLogichValue(e);return r==null?"":typeof r=="object"&&"character"in r&&"text"in r?{character:r.character,text:w.t(this.getDialogueText(r.text))}:w.t(this.getDialogueText(r))}getChoices(e){return unifier.JsonUnifier.getLogichValue(e)?.map(s=>unifier.JsonUnifier.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(e){return async r=>{let n=typeof e=="function"?e():e;n=j(n),n=unifier.JsonUnifier.getConditionalStep(n);let s=this.operationStringConvert?x=>this.operationStringConvert(x,n,r):void 0,{operations:l=[]}=n;for(let x of l)await O(x,s);let{labelToOpen:c=[]}=n,u=this.getChoices(n.choices),d=unifier.JsonUnifier.getLogichValue(n.glueEnabled),p=this.getDialogue(n.dialogue),h=[];Array.isArray(c)||(c=[c]),c.forEach(x=>{let b=unifier.JsonUnifier.getLogichValue(x);b&&h.push(b);});let m=unifier.JsonUnifier.getLogichValue(n.goNextStep),v=unifier.JsonUnifier.getLogichValue(n.end);if(u){let x=u.map(b=>{let T="";if(Array.isArray(b.text)){let o=[];b.text.forEach(y=>{if(typeof y=="string")o.push(w.t(y));else if(y&&typeof y=="object"){let g=unifier.JsonUnifier.getLogichValue(y);g&&!Array.isArray(g)&&typeof g=="object"&&(g=unifier.JsonUnifier.getLogichValue(g)||""),g&&(Array.isArray(g)?o=o.concat(w.t(g)):o.push(w.t(g)));}}),T=o;}else typeof b.text=="string"&&(T=w.t(b.text));return {label:b.label,text:T,props:b.props,type:b.type,oneTime:b.oneTime,onlyHaveNoChoice:b.onlyHaveNoChoice,autoSelect:b.autoSelect}});narration.narration.choiceMenuOptions=x;}else narration.narration.choiceMenuOptions=void 0;p!==void 0&&(narration.narration.dialogue=p,this.skipEmptyDialogs&&typeof p=="string"&&(p===""||RegExp(/^\s+$/).test(p))&&(m=true)),d?storage.storage.setFlag(storage.SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true):d===false&&storage.storage.setFlag(storage.SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,false);for(let x of h){let b=x.label;typeof b=="object"&&(b=unifier.JsonUnifier.getLogichValue(b)||"");let T=x.params?.map(i=>unifier.JsonUnifier.getLogichValue(i));r={...r,...x.props},x.type==="jump"?(narration.narration.openedLabels.length>0&&narration.narration.closeCurrentLabel(),storage.storage.setTempVariable(`${W}${narration.narration.openedLabels.length}`,T),await narration.narration.callLabel(b,r)):(storage.storage.setTempVariable(`${W}${narration.narration.openedLabels.length}`,T),await narration.narration.callLabel(b,r));}v==="game_end"?(narration.narration.closeAllLabels(),await narration.narration.goNext(r,{runNow:true})):v==="label_end"&&narration.narration.closeCurrentLabel(),m&&await narration.narration.goNext(r,{runNow:true});}}};exports.LabelJson=A;exports.importPixiVNJson=le;
package/dist/importer.mjs CHANGED
@@ -1,3 +1 @@
1
- import {RegisteredLabels,LabelAbstract,narration,NarrationManagerStatic}from'@drincs/pixi-vn/narration';import {storage,SYSTEM_RESERVED_STORAGE_KEYS}from'@drincs/pixi-vn/storage';var ae=Object.create;var W=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var fe=(i,e,t)=>e in i?W(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var X=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var Q=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var ue=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of le(e))!pe.call(i,o)&&o!==t&&W(i,o,{get:()=>e[o],enumerable:!(r=se(e,o))||r.enumerable});return i};var de=(i,e,t)=>(t=i!=null?ae(ce(i)):{},ue(W(t,"default",{value:i,enumerable:true}),i));var S=(i,e,t)=>fe(i,typeof e!="symbol"?e+"":e,t);var te=Q((H,ee)=>{(function(i,e){typeof H=="object"?ee.exports=H=e():typeof define=="function"&&define.amd?define([],e):i.CryptoJS=e();})(H,function(){var i=i||(function(e,t){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 X=="function")try{r=X("crypto");}catch{}var o=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.")},s=Object.create||(function(){function n(){}return function(a){var p;return n.prototype=a,p=new n,n.prototype=null,p}})(),l={},c=l.lib={},u=c.Base=(function(){return {extend:function(n){var a=s(this);return n&&a.mixIn(n),(!a.hasOwnProperty("init")||this.init===a.init)&&(a.init=function(){a.$super.init.apply(this,arguments);}),a.init.prototype=a,a.$super=this,a},create:function(){var n=this.extend();return n.init.apply(n,arguments),n},init:function(){},mixIn:function(n){for(var a in n)n.hasOwnProperty(a)&&(this[a]=n[a]);n.hasOwnProperty("toString")&&(this.toString=n.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),x=c.WordArray=u.extend({init:function(n,a){n=this.words=n||[],a!=t?this.sigBytes=a:this.sigBytes=n.length*4;},toString:function(n){return (n||V).stringify(this)},concat:function(n){var a=this.words,p=n.words,h=this.sigBytes,C=n.sigBytes;if(this.clamp(),h%4)for(var E=0;E<C;E++){var M=p[E>>>2]>>>24-E%4*8&255;a[h+E>>>2]|=M<<24-(h+E)%4*8;}else for(var L=0;L<C;L+=4)a[h+L>>>2]=p[L>>>2];return this.sigBytes+=C,this},clamp:function(){var n=this.words,a=this.sigBytes;n[a>>>2]&=4294967295<<32-a%4*8,n.length=e.ceil(a/4);},clone:function(){var n=u.clone.call(this);return n.words=this.words.slice(0),n},random:function(n){for(var a=[],p=0;p<n;p+=4)a.push(o());return new x.init(a,n)}}),d=l.enc={},V=d.Hex={stringify:function(n){for(var a=n.words,p=n.sigBytes,h=[],C=0;C<p;C++){var E=a[C>>>2]>>>24-C%4*8&255;h.push((E>>>4).toString(16)),h.push((E&15).toString(16));}return h.join("")},parse:function(n){for(var a=n.length,p=[],h=0;h<a;h+=2)p[h>>>3]|=parseInt(n.substr(h,2),16)<<24-h%8*4;return new x.init(p,a/2)}},y=d.Latin1={stringify:function(n){for(var a=n.words,p=n.sigBytes,h=[],C=0;C<p;C++){var E=a[C>>>2]>>>24-C%4*8&255;h.push(String.fromCharCode(E));}return h.join("")},parse:function(n){for(var a=n.length,p=[],h=0;h<a;h++)p[h>>>2]|=(n.charCodeAt(h)&255)<<24-h%4*8;return new x.init(p,a)}},v=d.Utf8={stringify:function(n){try{return decodeURIComponent(escape(y.stringify(n)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(n){return y.parse(unescape(encodeURIComponent(n)))}},N=c.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new x.init,this._nDataBytes=0;},_append:function(n){typeof n=="string"&&(n=v.parse(n)),this._data.concat(n),this._nDataBytes+=n.sigBytes;},_process:function(n){var a,p=this._data,h=p.words,C=p.sigBytes,E=this.blockSize,M=E*4,L=C/M;n?L=e.ceil(L):L=e.max((L|0)-this._minBufferSize,0);var B=L*E,U=e.min(B*4,C);if(B){for(var K=0;K<B;K+=E)this._doProcessBlock(h,K);a=h.splice(0,B),p.sigBytes-=U;}return new x.init(a,U)},clone:function(){var n=u.clone.call(this);return n._data=this._data.clone(),n},_minBufferSize:0});c.Hasher=N.extend({cfg:u.extend(),init:function(n){this.cfg=this.cfg.extend(n),this.reset();},reset:function(){N.reset.call(this),this._doReset();},update:function(n){return this._append(n),this._process(),this},finalize:function(n){n&&this._append(n);var a=this._doFinalize();return a},blockSize:512/32,_createHelper:function(n){return function(a,p){return new n.init(p).finalize(a)}},_createHmacHelper:function(n){return function(a,p){return new b.HMAC.init(n,p).finalize(a)}}});var b=l.algo={};return l})(Math);return i});});var ne=Q(($,ie)=>{(function(i,e){typeof $=="object"?ie.exports=$=e(te()):typeof define=="function"&&define.amd?define(["./core"],e):e(i.CryptoJS);})($,function(i){return (function(){var e=i,t=e.lib,r=t.WordArray,o=t.Hasher,s=e.algo,l=[],c=s.SHA1=o.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(u,x){for(var d=this._hash.words,V=d[0],y=d[1],v=d[2],N=d[3],T=d[4],b=0;b<80;b++){if(b<16)l[b]=u[x+b]|0;else {var n=l[b-3]^l[b-8]^l[b-14]^l[b-16];l[b]=n<<1|n>>>31;}var a=(V<<5|V>>>27)+T+l[b];b<20?a+=(y&v|~y&N)+1518500249:b<40?a+=(y^v^N)+1859775393:b<60?a+=(y&v|y&N|v&N)-1894007588:a+=(y^v^N)-899497514,T=N,N=v,v=y<<30|y>>>2,y=V,V=a;}d[0]=d[0]+V|0,d[1]=d[1]+y|0,d[2]=d[2]+v|0,d[3]=d[3]+N|0,d[4]=d[4]+T|0;},_doFinalize:function(){var u=this._data,x=u.words,d=this._nDataBytes*8,V=u.sigBytes*8;return x[V>>>5]|=128<<24-V%32,x[(V+64>>>9<<4)+14]=Math.floor(d/4294967296),x[(V+64>>>9<<4)+15]=d,u.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var u=o.clone.call(this);return u._hash=this._hash.clone(),u}});e.SHA1=o._createHelper(c),e.HmacSHA1=o._createHmacHelper(c);})(),i.SHA1});});var J;(o=>(o.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),o.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),o.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),o.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(J||(J={}));var f=class f{static t(e){return Array.isArray(e)?e.map(t=>f.translate(`${t}`)):f.translate(`${e}`)}static set beforeToTranslate(e){f._beforeToTranslate=e;}static set translate(e){f._translate=e;}static get translate(){return e=>{let t=e;return f._beforeToTranslate&&(t=f._beforeToTranslate(t)),t=f._translate(t),f._afterToTranslate&&(t=f._afterToTranslate(t)),t}}static set afterToTranslate(e){f._afterToTranslate=e;}static addKey(e,t,r){let o=r.defaultValue||"empty_string";typeof t=="string"&&(t=[t]),Array.isArray(t)&&t.forEach(s=>{e[s]===void 0&&(o==="empty_string"?e[s]="":o==="copy_key"&&(f._beforeToTranslate?e[s]=f._beforeToTranslate(s):e[s]=s));});}static getConditionalsThenElse(e,t=[]){if(typeof e=="object"&&e&&"type"in e)if(e.type==="ifelse")e.then&&f.getConditionalsThenElse(e.then,t),e.else&&f.getConditionalsThenElse(e.else,t);else if(e.type==="stepswitch"){if(e.elements)if(Array.isArray(e.elements))e.elements.forEach(r=>{f.getConditionalsThenElse(r,t);});else if(e.elements.type==="ifelse"){let r=[];f.getConditionalsThenElse(e.elements,r),r.forEach(o=>{t.push(...o);});}else if(e.elements.type==="stepswitch"){let r=[];f.getConditionalsThenElse(e.elements,r),r.forEach(o=>{t.push(...o);});}else f.getConditionalsThenElse(e.elements,t);}else e.type==="resulttocombine"?(e.firstItem&&f.getConditionalsThenElse(e.firstItem,t),e.secondConditionalItem&&e.secondConditionalItem.forEach(r=>{f.getConditionalsThenElse(r,t);})):t.push(e);else e&&t.push(e);return t}static generateJsonTranslation(e,t={},r={}){let{defaultValue:o="copy_key"}=r;return e.forEach(s=>{if(s.choices){let l=[];Array.isArray(s.choices)?l=[s.choices]:l=f.getConditionalsThenElse(s.choices),l.forEach(c=>c.forEach(u=>{if("type"in u){let x=[];u.type==="ifelse"||u.type==="stepswitch"?f.getConditionalsThenElse(u,x):x=[u],x.map(V=>f.getConditionalsThenElse(V.text)).forEach(V=>{Array.isArray(V)&&V.forEach(y=>{Array.isArray(y)?y.forEach(v=>{typeof v=="string"?f.addKey(t,v,{defaultValue:o}):f.getConditionalsThenElse(v).forEach(N=>{Array.isArray(N)?N.forEach(T=>{typeof T=="string"&&f.addKey(t,T,{defaultValue:o});}):typeof N=="string"&&f.addKey(t,N,{defaultValue:o});});}):typeof y=="string"&&f.addKey(t,y,{defaultValue:o});});});}}));}if(s.dialogue){let l=[];Array.isArray(s.dialogue)?l=[s.dialogue]:l=f.getConditionalsThenElse(s.dialogue),l.forEach(c=>{if(typeof c=="string")f.addKey(t,c,{defaultValue:o});else if("text"in c){let u=f.getConditionalsThenElse(c.text);typeof u=="string"&&(u=[u]),u.forEach(x=>{typeof x=="string"?f.addKey(t,x,{defaultValue:o}):f.getConditionalsThenElse(x).forEach(V=>{typeof V=="string"?f.addKey(t,V,{defaultValue:o}):Array.isArray(V)&&V.forEach(y=>{typeof y=="string"?f.addKey(t,y,{defaultValue:o}):f.getConditionalsThenElse(y).forEach(v=>{typeof v=="string"&&f.addKey(t,v,{defaultValue:o});});});});});}});}s.conditionalStep&&f.getConditionalsThenElse(s.conditionalStep).forEach(c=>{Array.isArray(c)?f.generateJsonTranslation(c,t,r):f.generateJsonTranslation([c],t,r);});}),t}};S(f,"_beforeToTranslate"),S(f,"_translate",e=>e),S(f,"_afterToTranslate");var D=f;var w=D;var _="___param___";function G(i){try{if(typeof i>"u")return i;let e=JSON.stringify(i);return JSON.parse(e)}catch(e){throw J.error("Error creating exportable element",i,e),new Error("[Pixi\u2019VN] Error creating exportable element")}}function Z(i){let e=P(i.value),t;switch(e&&typeof e=="object"&&"type"in e?t=P(e):t=e,i.storageType){case "flagStorage":storage.setFlag(i.key,i.value);break;case "storage":storage.setVariable(i.key,t);break;case "tempstorage":storage.setTempVariable(i.key,t);break;case "params":let r=storage.getVariable(`${_}${narration.openedLabels.length-1}`)||[];r&&r.length-1>=i.key&&(r[i.key]=t),storage.setTempVariable(`${_}${narration.openedLabels.length-1}`,r);break}}function P(i){let e=ye(i);if(e&&typeof e=="object"&&"type"in e)switch(e.type){case "value":return he(e);case "arithmetic":case "arithmeticsingle":return ge(e);case "compare":case "valueCondition":case "union":return xe(e)}return e}function ge(i){let e=P(i.leftValue);switch(i.type){case "arithmetic":let t=P(i.rightValue);switch(i.operator){case "*":return e*t;case "/":return e/t;case "+":return e+t;case "-":return e-t;case "%":return e%t;case "POW":return Math.pow(e,t);case "RANDOM":return narration.getRandomNumber(e,t)}case "arithmeticsingle":switch(i.operator){case "INT":return parseInt(e);case "FLOOR":return Math.floor(e);case "FLOAT":return parseFloat(e)}break}}function he(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 P(i.operation);case "params":let e=storage.getVariable(`${_}${narration.openedLabels.length-1}`)||[];if(e&&e.length>i.key)return e[i.key];J.warn("getValue params not found");return}return i}function xe(i){if(!i)return false;if(typeof i!="object"||!("type"in i))return !!i;switch(i.type){case "compare":let e=P(i.leftValue),t=P(i.rightValue);switch(i.operator){case "==":return e===t;case "!=":return e!==t;case "<":return e<t;case "<=":return e<=t;case ">":return e>t;case ">=":return e>=t;case "CONTAINS":return e.toString().includes(t.toString())}break;case "valueCondition":return !!P(i.value);case "union":return me(i)}return !!i}function me(i){if(i.unionType==="not")return !P(i.condition);let e=i.unionType==="and";for(let t=0;t<i.conditions.length;t++)if(e=P(i.conditions[t])||false,i.unionType==="and"){if(!e)return false}else if(e)return true;return e}function Ve(i,e){return Math.floor(Math.random()*(e-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 Pe(i);case "ifelse":return P(i.condition)?P(i.then):P(i.else);case "stepswitch":let t=P(i.elements)||[];if(t.length===0){J.error("getValueFromConditionalStatements elements.length === 0");return}switch(i.choiceType){case "random":let r=Ve(0,t.length-1);return P(t[r]);case "loop":let o=NarrationManagerStatic.getCurrentStepTimesCounter(i.nestedId)-1;return o>t.length-1&&(o=o%t.length),P(t[o]);case "sequential":let s,l=NarrationManagerStatic.getCurrentStepTimesCounter(i.nestedId)-1;return i.end=="lastItem"&&(s=P(t[t.length-1])),l>t.length-1?s:P(t[l]);case "sequentialrandom":let c=NarrationManagerStatic.getRandomNumber(0,t.length-1,{nestedId:i.nestedId,onceOnly:true});if(c==null&&i.end=="lastItem"){let u=NarrationManagerStatic.getCurrentStepTimesCounterData(i.nestedId);if(!u||!u?.usedRandomNumbers){J.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}let x=u.usedRandomNumbers[`0-${t.length-1}`];return P(t[x[x.length-1]])}if(c==null){J.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}return P(t[c])}}return i}function z(i){if(i.conditionalStep){let e=G(P(i.conditionalStep));if(e?.glueEnabled===void 0&&delete e?.glueEnabled,e?.goNextStep===void 0&&delete e?.goNextStep,e?.end===void 0&&delete e?.end,e?.choices===void 0&&delete e?.choices,e?.dialogue===void 0&&delete e?.dialogue,e?.labelToOpen===void 0&&delete e?.labelToOpen,e?.operations===void 0&&delete e?.operations,e){let t={...i,conditionalStep:void 0,...e};return z(t)}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 Pe(i){let e=i.firstItem,t=[];i.secondConditionalItem?.forEach(o=>{if(Array.isArray(o))o.forEach(s=>{let l=P(s);t.push(l);});else {let s=P(o);t.push(s);}});let r=e?[e,...t]:t;if(r.length===0){J.warn("combinateResult toCheck.length === 0");return}if(typeof r[0]=="string")return w.t(r);if(typeof r[0]=="object"){let o=r,s,l=o.map((n,a)=>{n=z(n);let p=P(n.dialogue)||"";return a===0?(s=P(n.glueEnabled)||false,p):(typeof p=="object"&&"text"in p&&(p=p.character+": "+p.text),s===false&&(p=`
2
-
3
- `+p),s=P(n.glueEnabled)||false,p)}),c=P(l[0]),u=typeof c=="object"&&"character"in c?c.character:void 0,x=l.flatMap(n=>{let a;n&&typeof n=="object"&&"text"in n?a=n.text:a=n;let p;return Array.isArray(a)?p=a.map(h=>{let C=P(h);return w.t(`${C}`)}):p=P(a)||"",w.t(p)}),d=o.find(n=>n.end),V=o.find(n=>n.choices),y=false,v=false;o.length>0&&(o[0].glueEnabled&&o[0].goNextStep&&o[0].dialogue===void 0&&storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true),y=o[o.length-1].glueEnabled,v=o.reverse().find(n=>!(n.operations&&(!n.dialogue||!n.choices)))?.goNextStep);let N=o.find(n=>n.labelToOpen),T=[];return o.forEach(n=>{n.operations&&T.forEach(a=>{T.push(a);});}),{dialogue:u?{character:u,text:x}:x,end:d?.end,choices:V?.choices,glueEnabled:y,goNextStep:v,labelToOpen:N?.labelToOpen,operations:T}}}var g=class g{static init(e){g._loadAssets=e.loadAssets,g._soundOperation=e.soundOperation,g._imageOperation=e.imageOperation,g._videoOperation=e.videoOperation,g._imageContainerOperation=e.imageContainerOperation,g._canvasElementOperation=e.canvasElementOperation,g._setStorageValue=e.setStorageValue,g._inputOperation=e.inputOperation,g._tickerOperation=e.tickerOperation,g._effectOperation=e.effectOperation,g._animateOperation=e.animateOperation,g._getLogichValue=e.getLogichValue,g._getConditionalStep=e.getConditionalStep;}static get loadAssets(){return g._loadAssets}static get soundOperation(){return g._soundOperation}static get imageOperation(){return g._imageOperation}static get videoOperation(){return g._videoOperation}static get imageContainerOperation(){return g._imageContainerOperation}static get canvasElementOperation(){return g._canvasElementOperation}static get setStorageValue(){return g._setStorageValue}static get inputOperation(){return g._inputOperation}static get tickerOperation(){return g._tickerOperation}static get effectOperation(){return g._effectOperation}static get animateOperation(){return g._animateOperation}static get getLogichValue(){return g._getLogichValue}static get getConditionalStep(){return g._getConditionalStep}};S(g,"_loadAssets",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_soundOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_imageOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_videoOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_imageContainerOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_canvasElementOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_setStorageValue",Z),S(g,"_inputOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_tickerOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_effectOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_animateOperation",()=>{throw J.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),S(g,"_getLogichValue",P),S(g,"_getConditionalStep",z);var m=g;async function R(i,e){let t=m.getLogichValue(i);if(t)switch(t.type){case "sound":m.soundOperation(t);break;case "assets":case "bundle":await m.loadAssets(t);break;case "image":await m.imageOperation(t);break;case "video":await m.videoOperation(t);break;case "imagecontainer":await m.imageContainerOperation(t);break;case "canvaselement":await m.canvasElementOperation(t);break;case "value":m.setStorageValue(t);break;case "operationtoconvert":if(e){let r="";t.values.forEach(s=>{if(typeof s=="string")r+=s;else {let l=m.getLogichValue(s);r+=`${l}`;}});let o=await e(r);o&&await R(o,e);}break;case "input":m.inputOperation(t);break;case "fade":case "move":case "rotate":case "zoom":m.tickerOperation(t);break;case "shake":await m.effectOperation(t);break;case "animate":case "animate-sequence":m.animateOperation(t);break}}async function Te(i,e={}){let{operationStringConvert:t,skipEmptyDialogs:r}=e;if(!Array.isArray(i))if(typeof i=="object"||typeof i=="string")i=[i];else {J.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let o=i.map(async c=>{if(typeof c=="string")try{c=JSON.parse(c);}catch(u){J.error("Error parsing imported Pixi'VN JSON",u),c={};}return c}),l=(await Promise.all(o)).map(async c=>{let u=[];if(c.initialOperations){c.initialOperations.forEach(d=>{let V=R(d,t?y=>t(y,{},{}):void 0);u.push(V);});let x={};[...storage.storage.keys()].forEach((d,V)=>{x[d]=storage.storage.get(d);}),storage.startingStorage=x;}if(c.labels){let x=c.labels;for(let d in x)try{let V=x[d],y=new k(d,V,void 0,e);RegisteredLabels.add(y);}catch(V){J.error(`Error creating JSON label ${d}`,V);}}return Promise.all(u)});await Promise.all(l);}var re=de(ne());var k=class extends LabelAbstract{constructor(t,r,o,s={}){o||(o={}),o.onLoadingLabel=async()=>{for(let l of r){let c;if(typeof l=="function"?c=l():c=l,c=m.getConditionalStep(c),c.operations){let u=c.operations.map(x=>m.loadAssets(x));await Promise.all(u);}}};super(t,o);S(this,"_steps");S(this,"operationStringConvert");S(this,"skipEmptyDialogs",false);this._steps=r,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}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 r=this._steps[t];return this.stepConverter(r)}getStepSha(t){if(t<0||t>=this.steps.length)return;let r=this._steps[t];return (0, re.default)(r.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let r="";if(Array.isArray(t)){let o=[];t.forEach(s=>{if(typeof s=="string")o.push(s);else if(s&&typeof s=="object"){let l=m.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=m.getLogichValue(l)||""),Array.isArray(l)?o=o.concat(l):o.push(`${l}`)):o.push(`${s}`);}}),r=o;}else {let o=m.getLogichValue(t)||"";o&&!Array.isArray(o)&&typeof o=="object"&&(o=m.getLogichValue(o)||""),r=o;}return `${r}`}getDialogue(t){if(t==null)return;let r=m.getLogichValue(t);return r==null?"":typeof r=="object"&&"character"in r&&"text"in r?{character:r.character,text:w.t(this.getDialogueText(r.text))}:w.t(this.getDialogueText(r))}getChoices(t){return m.getLogichValue(t)?.map(s=>m.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(t){return async r=>{let o=typeof t=="function"?t():t;o=G(o),o=m.getConditionalStep(o);let s=this.operationStringConvert?N=>this.operationStringConvert(N,o,r):void 0,{operations:l=[]}=o;for(let N of l)await R(N,s);let{labelToOpen:c=[]}=o,u=this.getChoices(o.choices),x=m.getLogichValue(o.glueEnabled),d=this.getDialogue(o.dialogue),V=[];Array.isArray(c)||(c=[c]),c.forEach(N=>{let T=m.getLogichValue(N);T&&V.push(T);});let y=m.getLogichValue(o.goNextStep),v=m.getLogichValue(o.end);if(u){let N=u.map(T=>{let b="";if(Array.isArray(T.text)){let a=[];T.text.forEach(p=>{if(typeof p=="string")a.push(w.t(p));else if(p&&typeof p=="object"){let h=m.getLogichValue(p);h&&!Array.isArray(h)&&typeof h=="object"&&(h=m.getLogichValue(h)||""),h&&(Array.isArray(h)?a=a.concat(w.t(h)):a.push(w.t(h)));}}),b=a;}else typeof T.text=="string"&&(b=w.t(T.text));return {label:T.label,text:b,props:T.props,type:T.type,oneTime:T.oneTime,onlyHaveNoChoice:T.onlyHaveNoChoice,autoSelect:T.autoSelect}});narration.choiceMenuOptions=N;}else narration.choiceMenuOptions=void 0;d!==void 0&&(narration.dialogue=d,this.skipEmptyDialogs&&typeof d=="string"&&(d===""||RegExp(/^\s+$/).test(d))&&(y=true)),x?storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true):x===false&&storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,false);for(let N of V){let T=N.label;typeof T=="object"&&(T=m.getLogichValue(T)||"");let b=N.params?.map(n=>m.getLogichValue(n));r={...r,...N.props},N.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${_}${narration.openedLabels.length}`,b),await narration.callLabel(T,r)):(storage.setTempVariable(`${_}${narration.openedLabels.length}`,b),await narration.callLabel(T,r));}v==="game_end"?(narration.closeAllLabels(),await narration.goNext(r,{runNow:true})):v==="label_end"&&narration.closeCurrentLabel(),y&&await narration.goNext(r,{runNow:true});}}};export{k as LabelJson,Te as importPixiVNJson};
1
+ import {RegisteredLabels,LabelAbstract,narration}from'@drincs/pixi-vn/narration';import {storage,SYSTEM_RESERVED_STORAGE_KEYS}from'@drincs/pixi-vn/storage';import {JsonUnifier}from'@drincs/pixi-vn-json/unifier';var Z=Object.create;var $=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var re=(a,t,e)=>t in a?$(a,t,{enumerable:true,configurable:true,writable:true,value:e}):a[t]=e;var K=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var F=(a,t)=>()=>(t||a((t={exports:{}}).exports,t),t.exports);var oe=(a,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of te(t))!ne.call(a,n)&&n!==e&&$(a,n,{get:()=>t[n],enumerable:!(r=ee(t,n))||r.enumerable});return a};var se=(a,t,e)=>(e=a!=null?Z(ie(a)):{},oe($(e,"default",{value:a,enumerable:true}),a));var C=(a,t,e)=>re(a,typeof t!="symbol"?t+"":t,e);var X=F((B,G)=>{(function(a,t){typeof B=="object"?G.exports=B=t():typeof define=="function"&&define.amd?define([],t):a.CryptoJS=t();})(B,function(){var a=a||(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 K=="function")try{r=K("crypto");}catch{}var n=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.")},s=Object.create||(function(){function i(){}return function(o){var y;return i.prototype=o,y=new i,i.prototype=null,y}})(),l={},c=l.lib={},u=c.Base=(function(){return {extend:function(i){var o=s(this);return i&&o.mixIn(i),(!o.hasOwnProperty("init")||this.init===o.init)&&(o.init=function(){o.$super.init.apply(this,arguments);}),o.init.prototype=o,o.$super=this,o},create:function(){var i=this.extend();return i.init.apply(i,arguments),i},init:function(){},mixIn:function(i){for(var o in i)i.hasOwnProperty(o)&&(this[o]=i[o]);i.hasOwnProperty("toString")&&(this.toString=i.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),d=c.WordArray=u.extend({init:function(i,o){i=this.words=i||[],o!=e?this.sigBytes=o:this.sigBytes=i.length*4;},toString:function(i){return (i||h).stringify(this)},concat:function(i){var o=this.words,y=i.words,g=this.sigBytes,P=i.sigBytes;if(this.clamp(),g%4)for(var N=0;N<P;N++){var R=y[N>>>2]>>>24-N%4*8&255;o[g+N>>>2]|=R<<24-(g+N)%4*8;}else for(var E=0;E<P;E+=4)o[g+E>>>2]=y[E>>>2];return this.sigBytes+=P,this},clamp:function(){var i=this.words,o=this.sigBytes;i[o>>>2]&=4294967295<<32-o%4*8,i.length=t.ceil(o/4);},clone:function(){var i=u.clone.call(this);return i.words=this.words.slice(0),i},random:function(i){for(var o=[],y=0;y<i;y+=4)o.push(n());return new d.init(o,i)}}),p=l.enc={},h=p.Hex={stringify:function(i){for(var o=i.words,y=i.sigBytes,g=[],P=0;P<y;P++){var N=o[P>>>2]>>>24-P%4*8&255;g.push((N>>>4).toString(16)),g.push((N&15).toString(16));}return g.join("")},parse:function(i){for(var o=i.length,y=[],g=0;g<o;g+=2)y[g>>>3]|=parseInt(i.substr(g,2),16)<<24-g%8*4;return new d.init(y,o/2)}},m=p.Latin1={stringify:function(i){for(var o=i.words,y=i.sigBytes,g=[],P=0;P<y;P++){var N=o[P>>>2]>>>24-P%4*8&255;g.push(String.fromCharCode(N));}return g.join("")},parse:function(i){for(var o=i.length,y=[],g=0;g<o;g++)y[g>>>2]|=(i.charCodeAt(g)&255)<<24-g%4*8;return new d.init(y,o)}},v=p.Utf8={stringify:function(i){try{return decodeURIComponent(escape(m.stringify(i)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(i){return m.parse(unescape(encodeURIComponent(i)))}},x=c.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new d.init,this._nDataBytes=0;},_append:function(i){typeof i=="string"&&(i=v.parse(i)),this._data.concat(i),this._nDataBytes+=i.sigBytes;},_process:function(i){var o,y=this._data,g=y.words,P=y.sigBytes,N=this.blockSize,R=N*4,E=P/R;i?E=t.ceil(E):E=t.max((E|0)-this._minBufferSize,0);var D=E*N,U=t.min(D*4,P);if(D){for(var H=0;H<D;H+=N)this._doProcessBlock(g,H);o=g.splice(0,D),y.sigBytes-=U;}return new d.init(o,U)},clone:function(){var i=u.clone.call(this);return i._data=this._data.clone(),i},_minBufferSize:0});c.Hasher=x.extend({cfg:u.extend(),init:function(i){this.cfg=this.cfg.extend(i),this.reset();},reset:function(){x.reset.call(this),this._doReset();},update:function(i){return this._append(i),this._process(),this},finalize:function(i){i&&this._append(i);var o=this._doFinalize();return o},blockSize:512/32,_createHelper:function(i){return function(o,y){return new i.init(y).finalize(o)}},_createHmacHelper:function(i){return function(o,y){return new T.HMAC.init(i,y).finalize(o)}}});var T=l.algo={};return l})(Math);return a});});var Y=F((k,q)=>{(function(a,t){typeof k=="object"?q.exports=k=t(X()):typeof define=="function"&&define.amd?define(["./core"],t):t(a.CryptoJS);})(k,function(a){return (function(){var t=a,e=t.lib,r=e.WordArray,n=e.Hasher,s=t.algo,l=[],c=s.SHA1=n.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(u,d){for(var p=this._hash.words,h=p[0],m=p[1],v=p[2],x=p[3],b=p[4],T=0;T<80;T++){if(T<16)l[T]=u[d+T]|0;else {var i=l[T-3]^l[T-8]^l[T-14]^l[T-16];l[T]=i<<1|i>>>31;}var o=(h<<5|h>>>27)+b+l[T];T<20?o+=(m&v|~m&x)+1518500249:T<40?o+=(m^v^x)+1859775393:T<60?o+=(m&v|m&x|v&x)-1894007588:o+=(m^v^x)-899497514,b=x,x=v,v=m<<30|m>>>2,m=h,h=o;}p[0]=p[0]+h|0,p[1]=p[1]+m|0,p[2]=p[2]+v|0,p[3]=p[3]+x|0,p[4]=p[4]+b|0;},_doFinalize:function(){var u=this._data,d=u.words,p=this._nDataBytes*8,h=u.sigBytes*8;return d[h>>>5]|=128<<24-h%32,d[(h+64>>>9<<4)+14]=Math.floor(p/4294967296),d[(h+64>>>9<<4)+15]=p,u.sigBytes=d.length*4,this._process(),this._hash},clone:function(){var u=n.clone.call(this);return u._hash=this._hash.clone(),u}});t.SHA1=n._createHelper(c),t.HmacSHA1=n._createHmacHelper(c);})(),a.SHA1});});var L;(n=>(n.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),n.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),n.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),n.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(L||(L={}));async function O(a,t){let e=JsonUnifier.getLogichValue(a);if(e)switch(e.type){case "sound":JsonUnifier.soundOperation(e);break;case "assets":case "bundle":await JsonUnifier.loadAssets(e);break;case "image":await JsonUnifier.imageOperation(e);break;case "video":await JsonUnifier.videoOperation(e);break;case "imagecontainer":await JsonUnifier.imageContainerOperation(e);break;case "canvaselement":await JsonUnifier.canvasElementOperation(e);break;case "value":JsonUnifier.setStorageValue(e);break;case "operationtoconvert":if(t){let r="";e.values.forEach(s=>{if(typeof s=="string")r+=s;else {let l=JsonUnifier.getLogichValue(s);r+=`${l}`;}});let n=await t(r);n&&await O(n,t);}break;case "input":JsonUnifier.inputOperation(e);break;case "fade":case "move":case "rotate":case "zoom":JsonUnifier.tickerOperation(e);break;case "shake":await JsonUnifier.effectOperation(e);break;case "animate":case "animate-sequence":JsonUnifier.animateOperation(e);break}}async function le(a,t={}){let{operationStringConvert:e,skipEmptyDialogs:r}=t;if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {L.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let n=a.map(async c=>{if(typeof c=="string")try{c=JSON.parse(c);}catch(u){L.error("Error parsing imported Pixi'VN JSON",u),c={};}return c}),l=(await Promise.all(n)).map(async c=>{let u=[];if(c.initialOperations){c.initialOperations.forEach(p=>{let h=O(p,e?m=>e(m,{},{}):void 0);u.push(h);});let d={};[...storage.storage.keys()].forEach((p,h)=>{d[p]=storage.storage.get(p);}),storage.startingStorage=d;}if(c.labels){let d=c.labels;for(let p in d)try{let h=d[p],m=new A(p,h,void 0,t);RegisteredLabels.add(m);}catch(h){L.error(`Error creating JSON label ${p}`,h);}}return Promise.all(u)});await Promise.all(l);}var f=class f{static t(t){return Array.isArray(t)?t.map(e=>f.translate(`${e}`)):f.translate(`${t}`)}static set beforeToTranslate(t){f._beforeToTranslate=t;}static set translate(t){f._translate=t;}static get translate(){return t=>{let e=t;return f._beforeToTranslate&&(e=f._beforeToTranslate(e)),e=f._translate(e),f._afterToTranslate&&(e=f._afterToTranslate(e)),e}}static set afterToTranslate(t){f._afterToTranslate=t;}static addKey(t,e,r){let n=r.defaultValue||"empty_string";typeof e=="string"&&(e=[e]),Array.isArray(e)&&e.forEach(s=>{t[s]===void 0&&(n==="empty_string"?t[s]="":n==="copy_key"&&(f._beforeToTranslate?t[s]=f._beforeToTranslate(s):t[s]=s));});}static getConditionalsThenElse(t,e=[]){if(typeof t=="object"&&t&&"type"in t)if(t.type==="ifelse")t.then&&f.getConditionalsThenElse(t.then,e),t.else&&f.getConditionalsThenElse(t.else,e);else if(t.type==="stepswitch"){if(t.elements)if(Array.isArray(t.elements))t.elements.forEach(r=>{f.getConditionalsThenElse(r,e);});else if(t.elements.type==="ifelse"){let r=[];f.getConditionalsThenElse(t.elements,r),r.forEach(n=>{e.push(...n);});}else if(t.elements.type==="stepswitch"){let r=[];f.getConditionalsThenElse(t.elements,r),r.forEach(n=>{e.push(...n);});}else f.getConditionalsThenElse(t.elements,e);}else t.type==="resulttocombine"?(t.firstItem&&f.getConditionalsThenElse(t.firstItem,e),t.secondConditionalItem&&t.secondConditionalItem.forEach(r=>{f.getConditionalsThenElse(r,e);})):e.push(t);else t&&e.push(t);return e}static generateJsonTranslation(t,e={},r={}){let{defaultValue:n="copy_key"}=r;return t.forEach(s=>{if(s.choices){let l=[];Array.isArray(s.choices)?l=[s.choices]:l=f.getConditionalsThenElse(s.choices),l.forEach(c=>c.forEach(u=>{if("type"in u){let d=[];u.type==="ifelse"||u.type==="stepswitch"?f.getConditionalsThenElse(u,d):d=[u],d.map(h=>f.getConditionalsThenElse(h.text)).forEach(h=>{Array.isArray(h)&&h.forEach(m=>{Array.isArray(m)?m.forEach(v=>{typeof v=="string"?f.addKey(e,v,{defaultValue:n}):f.getConditionalsThenElse(v).forEach(x=>{Array.isArray(x)?x.forEach(b=>{typeof b=="string"&&f.addKey(e,b,{defaultValue:n});}):typeof x=="string"&&f.addKey(e,x,{defaultValue:n});});}):typeof m=="string"&&f.addKey(e,m,{defaultValue:n});});});}}));}if(s.dialogue){let l=[];Array.isArray(s.dialogue)?l=[s.dialogue]:l=f.getConditionalsThenElse(s.dialogue),l.forEach(c=>{if(typeof c=="string")f.addKey(e,c,{defaultValue:n});else if("text"in c){let u=f.getConditionalsThenElse(c.text);typeof u=="string"&&(u=[u]),u.forEach(d=>{typeof d=="string"?f.addKey(e,d,{defaultValue:n}):f.getConditionalsThenElse(d).forEach(h=>{typeof h=="string"?f.addKey(e,h,{defaultValue:n}):Array.isArray(h)&&h.forEach(m=>{typeof m=="string"?f.addKey(e,m,{defaultValue:n}):f.getConditionalsThenElse(m).forEach(v=>{typeof v=="string"&&f.addKey(e,v,{defaultValue:n});});});});});}});}s.conditionalStep&&f.getConditionalsThenElse(s.conditionalStep).forEach(c=>{Array.isArray(c)?f.generateJsonTranslation(c,e,r):f.generateJsonTranslation([c],e,r);});}),e}};C(f,"_beforeToTranslate"),C(f,"_translate",t=>t),C(f,"_afterToTranslate");var _=f;var w=_;var Q=se(Y());var W="___param___";function j(a){try{if(typeof a>"u")return a;let t=JSON.stringify(a);return JSON.parse(t)}catch(t){throw L.error("Error creating exportable element",a,t),new Error("[Pixi\u2019VN] Error creating exportable element")}}var A=class extends LabelAbstract{constructor(e,r,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let l of r){let c;if(typeof l=="function"?c=l():c=l,c=JsonUnifier.getConditionalStep(c),c.operations){let u=c.operations.map(d=>JsonUnifier.loadAssets(d));await Promise.all(u);}}};super(e,n);C(this,"_steps");C(this,"operationStringConvert");C(this,"skipEmptyDialogs",false);this._steps=r,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(e=>this.stepConverter(e))}get stepCount(){return this._steps.length}getStepById(e){if(e<0||e>=this._steps.length)return;let r=this._steps[e];return this.stepConverter(r)}getStepSha(e){if(e<0||e>=this.steps.length)return;let r=this._steps[e];return (0, Q.default)(r.toString().toLocaleLowerCase()).toString()}getDialogueText(e){let r="";if(Array.isArray(e)){let n=[];e.forEach(s=>{if(typeof s=="string")n.push(s);else if(s&&typeof s=="object"){let l=JsonUnifier.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=JsonUnifier.getLogichValue(l)||""),Array.isArray(l)?n=n.concat(l):n.push(`${l}`)):n.push(`${s}`);}}),r=n;}else {let n=JsonUnifier.getLogichValue(e)||"";n&&!Array.isArray(n)&&typeof n=="object"&&(n=JsonUnifier.getLogichValue(n)||""),r=n;}return `${r}`}getDialogue(e){if(e==null)return;let r=JsonUnifier.getLogichValue(e);return r==null?"":typeof r=="object"&&"character"in r&&"text"in r?{character:r.character,text:w.t(this.getDialogueText(r.text))}:w.t(this.getDialogueText(r))}getChoices(e){return JsonUnifier.getLogichValue(e)?.map(s=>JsonUnifier.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(e){return async r=>{let n=typeof e=="function"?e():e;n=j(n),n=JsonUnifier.getConditionalStep(n);let s=this.operationStringConvert?x=>this.operationStringConvert(x,n,r):void 0,{operations:l=[]}=n;for(let x of l)await O(x,s);let{labelToOpen:c=[]}=n,u=this.getChoices(n.choices),d=JsonUnifier.getLogichValue(n.glueEnabled),p=this.getDialogue(n.dialogue),h=[];Array.isArray(c)||(c=[c]),c.forEach(x=>{let b=JsonUnifier.getLogichValue(x);b&&h.push(b);});let m=JsonUnifier.getLogichValue(n.goNextStep),v=JsonUnifier.getLogichValue(n.end);if(u){let x=u.map(b=>{let T="";if(Array.isArray(b.text)){let o=[];b.text.forEach(y=>{if(typeof y=="string")o.push(w.t(y));else if(y&&typeof y=="object"){let g=JsonUnifier.getLogichValue(y);g&&!Array.isArray(g)&&typeof g=="object"&&(g=JsonUnifier.getLogichValue(g)||""),g&&(Array.isArray(g)?o=o.concat(w.t(g)):o.push(w.t(g)));}}),T=o;}else typeof b.text=="string"&&(T=w.t(b.text));return {label:b.label,text:T,props:b.props,type:b.type,oneTime:b.oneTime,onlyHaveNoChoice:b.onlyHaveNoChoice,autoSelect:b.autoSelect}});narration.choiceMenuOptions=x;}else narration.choiceMenuOptions=void 0;p!==void 0&&(narration.dialogue=p,this.skipEmptyDialogs&&typeof p=="string"&&(p===""||RegExp(/^\s+$/).test(p))&&(m=true)),d?storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true):d===false&&storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,false);for(let x of h){let b=x.label;typeof b=="object"&&(b=JsonUnifier.getLogichValue(b)||"");let T=x.params?.map(i=>JsonUnifier.getLogichValue(i));r={...r,...x.props},x.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${W}${narration.openedLabels.length}`,T),await narration.callLabel(b,r)):(storage.setTempVariable(`${W}${narration.openedLabels.length}`,T),await narration.callLabel(b,r));}v==="game_end"?(narration.closeAllLabels(),await narration.goNext(r,{runNow:true})):v==="label_end"&&narration.closeCurrentLabel(),m&&await narration.goNext(r,{runNow:true});}}};export{A as LabelJson,le as importPixiVNJson};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drincs/pixi-vn-json",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "type": "module",
5
5
  "description": "Pixi'VN can be integrated with JSON files to create a visual novel.",
6
6
  "main": "./dist/index.cjs",