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