@drincs/pixi-vn-json 1.8.5 → 1.8.6
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/package.json +12 -5
package/dist/importer.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var narration=require('@drincs/pixi-vn/narration'),unifier=require('@drincs/pixi-vn-json/unifier'),translator=require('@drincs/pixi-vn-json/translator'),storage=require('@drincs/pixi-vn/storage');var Q=Object.create;var I=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var re=(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 ee(i))!ie.call(a,n)&&n!==t&&I(a,n,{get:()=>i[n],enumerable:!(o=Z(i,n))||o.enumerable});return a};var oe=(a,i,t)=>(t=a!=null?Q(te(a)):{},ne(I(t,"default",{value:a,enumerable:true}),a));var C=(a,i,t)=>re(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.")},l=Object.create||(function(){function e(){}return function(r){var c;return e.prototype=r,c=new e,e.prototype=null,c}})(),s={},u=s.lib={},d=u.Base=(function(){return {extend:function(e){var r=l(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=d.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 S=0;S<v;S++){var D=c[S>>>2]>>>24-S%4*8&255;r[f+S>>>2]|=D<<24-(f+S)%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=d.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=s.enc={},V=p.Hex={stringify:function(e){for(var r=e.words,c=e.sigBytes,f=[],v=0;v<c;v++){var S=r[v>>>2]>>>24-v%4*8&255;f.push((S>>>4).toString(16)),f.push((S&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 S=r[v>>>2]>>>24-v%4*8&255;f.push(String.fromCharCode(S));}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)))}},g=u.BufferedBlockAlgorithm=d.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,S=this.blockSize,D=S*4,_=v/D;e?_=i.ceil(_):_=i.max((_|0)-this._minBufferSize,0);var T=_*S,j=i.min(T*4,v);if(T){for(var k=0;k<T;k+=S)this._doProcessBlock(f,k);r=f.splice(0,T),c.sigBytes-=j;}return new x.init(r,j)},clone:function(){var e=d.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});u.Hasher=g.extend({cfg:d.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset();},reset:function(){g.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=s.algo={};return s})(Math);return a});});var X=z((E,M)=>{(function(a,i){typeof E=="object"?M.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,l=i.algo,s=[],u=l.SHA1=n.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(d,x){for(var p=this._hash.words,V=p[0],b=p[1],N=p[2],g=p[3],h=p[4],y=0;y<80;y++){if(y<16)s[y]=d[x+y]|0;else {var e=s[y-3]^s[y-8]^s[y-14]^s[y-16];s[y]=e<<1|e>>>31;}var r=(V<<5|V>>>27)+h+s[y];y<20?r+=(b&N|~b&g)+1518500249:y<40?r+=(b^N^g)+1859775393:y<60?r+=(b&N|b&g|N&g)-1894007588:r+=(b^N^g)-899497514,h=g,g=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]+g|0,p[4]=p[4]+h|0;},_doFinalize:function(){var d=this._data,x=d.words,p=this._nDataBytes*8,V=d.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,d.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var d=n.clone.call(this);return d._hash=this._hash.clone(),d}});i.SHA1=n._createHelper(u),i.HmacSHA1=n._createHmacHelper(u);})(),a.SHA1});});var L;(n=>(n.log=(l,...s)=>console.log(`[Pixi\u2019VN Json] ${l}`,...s),n.warn=(l,...s)=>console.warn(`[Pixi\u2019VN Json] ${l}`,...s),n.error=(l,...s)=>console.error(`[Pixi\u2019VN Json] ${l}`,...s),n.info=(l,...s)=>console.info(`[Pixi\u2019VN Json] ${l}`,...s)))(L||(L={}));function W(a){let i="";return a.values.forEach(t=>{if(typeof t=="string")i+=t;else {let o=unifier.JsonUnifier.getLogichValue(t);i+=`${o}`;}}),i}async function R(a,i){let t=unifier.JsonUnifier.getLogichValue(a);if(t)switch(t.type){case "sound":unifier.JsonUnifier.soundOperation(t);break;case "assets":case "bundle":await unifier.JsonUnifier.loadAssets(t);break;case "image":await unifier.JsonUnifier.imageOperation(t);break;case "video":await unifier.JsonUnifier.videoOperation(t);break;case "imagecontainer":await unifier.JsonUnifier.imageContainerOperation(t);break;case "text":await unifier.JsonUnifier.textOperation(t);break;case "canvaselement":await unifier.JsonUnifier.canvasElementOperation(t);break;case "value":unifier.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":unifier.JsonUnifier.narrationOperation(t);break;case "fade":case "move":case "rotate":case "zoom":unifier.JsonUnifier.tickerOperation(t);break;case "shake":await unifier.JsonUnifier.effectOperation(t);break;case "animate":case "animate-sequence":unifier.JsonUnifier.animateOperation(t);break}}function U(a){let i=unifier.JsonUnifier.getLogichValue(a);if(i)switch(i.type){case "value":i.storageOperationType==="set"&&(i.storageType==="storage"||i.storageType==="tempstorage")&&unifier.JsonUnifier.setInitialStorageValue(i);break}}async function le(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 l=>{if(typeof l=="string")try{l=JSON.parse(l);}catch(s){L.error("Error parsing imported Pixi'VN JSON",s),l={};}return l}),n=(await Promise.all(t)).map(async l=>{let s=[];if(l.initialOperations)for(let u of l.initialOperations)U(u);if(l.labels){let u=l.labels;for(let d in u)try{let x=u[d],p=new w(d,x,void 0,i);narration.RegisteredLabels.add(p);}catch(x){L.error(`Error creating JSON label ${d}`,x);}}return Promise.all(s)});await Promise.all(n);}var K=oe(X());var $="___param___";function q(a){try{if(typeof a>"u")return a;let i=JSON.stringify(a);return JSON.parse(i)}catch(i){throw L.error("Error creating exportable element",a,i),new Error("[Pixi\u2019VN] Error creating exportable element")}}var w=class extends narration.LabelAbstract{constructor(t,o,n,l={}){n||(n={}),n.onLoadingLabel=async()=>{for(let s of o){let u;if(typeof s=="function"?u=s():u=s,u=unifier.JsonUnifier.getConditionalStep(u),u.operations){let d=u.operations.map(x=>unifier.JsonUnifier.loadAssets(x));await Promise.all(d);}}};super(t,n);C(this,"_steps");C(this,"operationStringConvert");C(this,"skipEmptyDialogs",false);this._steps=o,this.operationStringConvert=l.operationStringConvert,this.skipEmptyDialogs=l.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, K.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let o="";if(Array.isArray(t)){let n=[];t.forEach(l=>{if(typeof l=="string")n.push(l);else if(l&&typeof l=="object"){let s=unifier.JsonUnifier.getLogichValue(l);s?(s&&!Array.isArray(s)&&typeof s=="object"&&(s=unifier.JsonUnifier.getLogichValue(s)||""),Array.isArray(s)?n=n.map(u=>`${u}`).concat(s):n.push(`${s}`)):n.push(`${l}`);}else n.push(`${l}`);}),o=n;}else {let n=unifier.JsonUnifier.getLogichValue(t)||"";n&&!Array.isArray(n)&&typeof n=="object"&&(n=unifier.JsonUnifier.getLogichValue(n)||""),o=n;}return `${o}`}getDialogue(t){if(t==null)return;let o=unifier.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 unifier.JsonUnifier.getLogichValue(t)?.map(l=>unifier.JsonUnifier.getLogichValue(l)).filter(l=>l!==void 0)}stepConverter(t){return async o=>{let n=typeof t=="function"?t():t;n=q(n),n=unifier.JsonUnifier.getConditionalStep(n);let l=this.operationStringConvert?g=>this.operationStringConvert(g,n,o):void 0,{operations:s=[]}=n;for(let g of s)await R(g,l);let{labelToOpen:u=[]}=n,d=this.getChoices(n.choices),x=unifier.JsonUnifier.getLogichValue(n.glueEnabled),p=this.getDialogue(n.dialogue),V=[];Array.isArray(u)||(u=[u]),u.forEach(g=>{let h=unifier.JsonUnifier.getLogichValue(g);h&&V.push(h);});let b=unifier.JsonUnifier.getLogichValue(n.goNextStep),N=unifier.JsonUnifier.getLogichValue(n.end);if(d){let g=d.map(h=>{let y="";if(Array.isArray(h.text)){let r=[];h.text.forEach(c=>{if(typeof c=="string")r.push(translator.translator.t(c));else if(c&&typeof c=="object"){let f=unifier.JsonUnifier.getLogichValue(c);f&&!Array.isArray(f)&&typeof f=="object"&&(f=unifier.JsonUnifier.getLogichValue(f)||""),f&&(Array.isArray(f)?r=r.concat(translator.translator.t(f)):r.push(translator.translator.t(f)));}}),y=r;}else typeof h.text=="string"&&(y=translator.translator.t(h.text));return {label:h.label,text:y,props:h.props,type:h.type,oneTime:h.oneTime,onlyHaveNoChoice:h.onlyHaveNoChoice,autoSelect:h.autoSelect}});narration.narration.choiceMenuOptions=g;}else narration.narration.choiceMenuOptions=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 g of V){let h=g.label;typeof h=="object"&&(h=unifier.JsonUnifier.getLogichValue(h)||"");let y=g.params?.map(e=>unifier.JsonUnifier.getLogichValue(e));o={...o,...g.props},g.type==="jump"?(narration.narration.openedLabels.length>0&&narration.narration.closeCurrentLabel(),storage.storage.setTempVariable(`${$}${narration.narration.openedLabels.length}`,y),await narration.narration.callLabel(h,o)):(storage.storage.setTempVariable(`${$}${narration.narration.openedLabels.length}`,y),await narration.narration.callLabel(h,o));}N==="game_end"?(narration.narration.closeAllLabels(),await narration.narration.goNext(o,{runNow:true})):N==="label_end"&&narration.narration.closeCurrentLabel(),b&&await narration.narration.goNext(o,{runNow:true});}}};exports.LabelJson=w;exports.importPixiVNJson=le;
|
|
1
|
+
'use strict';var narration=require('@drincs/pixi-vn/narration'),unifier=require('@drincs/pixi-vn-json/unifier'),translator=require('@drincs/pixi-vn-json/translator'),storage=require('@drincs/pixi-vn/storage');var Q=Object.create;var I=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var re=(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 r of ee(i))!ie.call(a,r)&&r!==t&&I(a,r,{get:()=>i[r],enumerable:!(o=Z(i,r))||o.enumerable});return a};var oe=(a,i,t)=>(t=a!=null?Q(te(a)):{},ne(I(t,"default",{value:a,enumerable:true}),a));var C=(a,i,t)=>re(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 r=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(n){var c;return e.prototype=n,c=new e,e.prototype=null,c}})(),l={},u=l.lib={},d=u.Base=(function(){return {extend:function(e){var n=s(this);return e&&n.mixIn(e),(!n.hasOwnProperty("init")||this.init===n.init)&&(n.init=function(){n.$super.init.apply(this,arguments);}),n.init.prototype=n,n.$super=this,n},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var n in e)e.hasOwnProperty(n)&&(this[n]=e[n]);e.hasOwnProperty("toString")&&(this.toString=e.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),x=u.WordArray=d.extend({init:function(e,n){e=this.words=e||[],n!=t?this.sigBytes=n:this.sigBytes=e.length*4;},toString:function(e){return (e||V).stringify(this)},concat:function(e){var n=this.words,c=e.words,f=this.sigBytes,v=e.sigBytes;if(this.clamp(),f%4)for(var S=0;S<v;S++){var D=c[S>>>2]>>>24-S%4*8&255;n[f+S>>>2]|=D<<24-(f+S)%4*8;}else for(var _=0;_<v;_+=4)n[f+_>>>2]=c[_>>>2];return this.sigBytes+=v,this},clamp:function(){var e=this.words,n=this.sigBytes;e[n>>>2]&=4294967295<<32-n%4*8,e.length=i.ceil(n/4);},clone:function(){var e=d.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var n=[],c=0;c<e;c+=4)n.push(r());return new x.init(n,e)}}),p=l.enc={},V=p.Hex={stringify:function(e){for(var n=e.words,c=e.sigBytes,f=[],v=0;v<c;v++){var S=n[v>>>2]>>>24-v%4*8&255;f.push((S>>>4).toString(16)),f.push((S&15).toString(16));}return f.join("")},parse:function(e){for(var n=e.length,c=[],f=0;f<n;f+=2)c[f>>>3]|=parseInt(e.substr(f,2),16)<<24-f%8*4;return new x.init(c,n/2)}},b=p.Latin1={stringify:function(e){for(var n=e.words,c=e.sigBytes,f=[],v=0;v<c;v++){var S=n[v>>>2]>>>24-v%4*8&255;f.push(String.fromCharCode(S));}return f.join("")},parse:function(e){for(var n=e.length,c=[],f=0;f<n;f++)c[f>>>2]|=(e.charCodeAt(f)&255)<<24-f%4*8;return new x.init(c,n)}},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)))}},g=u.BufferedBlockAlgorithm=d.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 n,c=this._data,f=c.words,v=c.sigBytes,S=this.blockSize,D=S*4,_=v/D;e?_=i.ceil(_):_=i.max((_|0)-this._minBufferSize,0);var T=_*S,j=i.min(T*4,v);if(T){for(var k=0;k<T;k+=S)this._doProcessBlock(f,k);n=f.splice(0,T),c.sigBytes-=j;}return new x.init(n,j)},clone:function(){var e=d.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});u.Hasher=g.extend({cfg:d.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset();},reset:function(){g.reset.call(this),this._doReset();},update:function(e){return this._append(e),this._process(),this},finalize:function(e){e&&this._append(e);var n=this._doFinalize();return n},blockSize:512/32,_createHelper:function(e){return function(n,c){return new e.init(c).finalize(n)}},_createHmacHelper:function(e){return function(n,c){return new y.HMAC.init(e,c).finalize(n)}}});var y=l.algo={};return l})(Math);return a});});var X=z((E,M)=>{(function(a,i){typeof E=="object"?M.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,r=t.Hasher,s=i.algo,l=[],u=s.SHA1=r.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(d,x){for(var p=this._hash.words,V=p[0],b=p[1],N=p[2],g=p[3],h=p[4],y=0;y<80;y++){if(y<16)l[y]=d[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 n=(V<<5|V>>>27)+h+l[y];y<20?n+=(b&N|~b&g)+1518500249:y<40?n+=(b^N^g)+1859775393:y<60?n+=(b&N|b&g|N&g)-1894007588:n+=(b^N^g)-899497514,h=g,g=N,N=b<<30|b>>>2,b=V,V=n;}p[0]=p[0]+V|0,p[1]=p[1]+b|0,p[2]=p[2]+N|0,p[3]=p[3]+g|0,p[4]=p[4]+h|0;},_doFinalize:function(){var d=this._data,x=d.words,p=this._nDataBytes*8,V=d.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,d.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var d=r.clone.call(this);return d._hash=this._hash.clone(),d}});i.SHA1=r._createHelper(u),i.HmacSHA1=r._createHmacHelper(u);})(),a.SHA1});});var L;(r=>(r.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),r.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),r.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),r.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=unifier.JsonUnifier.getLogichValue(t);i+=`${o}`;}}),i}async function R(a,i){let t=unifier.JsonUnifier.getLogichValue(a);if(t)switch(t.type){case "sound":unifier.JsonUnifier.soundOperation(t);break;case "assets":case "bundle":await unifier.JsonUnifier.loadAssets(t);break;case "image":await unifier.JsonUnifier.imageOperation(t);break;case "video":await unifier.JsonUnifier.videoOperation(t);break;case "imagecontainer":await unifier.JsonUnifier.imageContainerOperation(t);break;case "text":await unifier.JsonUnifier.textOperation(t);break;case "canvaselement":await unifier.JsonUnifier.canvasElementOperation(t);break;case "value":unifier.JsonUnifier.setStorageValue(t);break;case "operationtoconvert":if(i){let o=W(t),r=await i(o);r&&await R(r,i);}break;case "input":case "dialogue":unifier.JsonUnifier.narrationOperation(t);break;case "fade":case "move":case "rotate":case "zoom":unifier.JsonUnifier.tickerOperation(t);break;case "shake":await unifier.JsonUnifier.effectOperation(t);break;case "animate":case "animate-sequence":unifier.JsonUnifier.animateOperation(t);break}}function U(a){let i=unifier.JsonUnifier.getLogichValue(a);if(i)switch(i.type){case "value":i.storageOperationType==="set"&&(i.storageType==="storage"||i.storageType==="tempstorage")&&unifier.JsonUnifier.setInitialStorageValue(i);break}}async function le(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}),r=(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 d in u)try{let x=u[d],p=new w(d,x,void 0,i);narration.RegisteredLabels.add(p);}catch(x){L.error(`Error creating JSON label ${d}`,x);}}return Promise.all(l)});await Promise.all(r);}var K=oe(X());var $="___param___";function q(a){try{if(typeof a>"u")return a;let i=JSON.stringify(a);return JSON.parse(i)}catch(i){throw L.error("Error creating exportable element",a,i),new Error("[Pixi\u2019VN] Error creating exportable element")}}var w=class extends narration.LabelAbstract{constructor(t,o,r,s={}){r||(r={}),r.onLoadingLabel=async()=>{for(let l of o){let u;if(typeof l=="function"?u=l():u=l,u=unifier.JsonUnifier.getConditionalStep(u),u.operations){let d=u.operations.map(x=>unifier.JsonUnifier.loadAssets(x));await Promise.all(d);}}};super(t,r);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, K.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let o="";if(Array.isArray(t)){let r=[];t.forEach(s=>{if(typeof s=="string")r.push(s);else if(s&&typeof s=="object"){let l=unifier.JsonUnifier.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=unifier.JsonUnifier.getLogichValue(l)||""),Array.isArray(l)?r=r.map(u=>`${u}`).concat(l):r.push(`${l}`)):r.push(`${s}`);}else r.push(`${s}`);}),o=r;}else {let r=unifier.JsonUnifier.getLogichValue(t);r&&!Array.isArray(r)&&typeof r=="object"&&(r=unifier.JsonUnifier.getLogichValue(r)),r&&Array.isArray(r)?o=r.map(s=>`${s}`):o=`${r}`;}return o}getDialogue(t){if(t==null)return;let o=unifier.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 unifier.JsonUnifier.getLogichValue(t)?.map(s=>unifier.JsonUnifier.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(t){return async o=>{let r=typeof t=="function"?t():t;r=q(r),r=unifier.JsonUnifier.getConditionalStep(r);let s=this.operationStringConvert?g=>this.operationStringConvert(g,r,o):void 0,{operations:l=[]}=r;for(let g of l)await R(g,s);let{labelToOpen:u=[]}=r,d=this.getChoices(r.choices),x=unifier.JsonUnifier.getLogichValue(r.glueEnabled),p=this.getDialogue(r.dialogue),V=[];Array.isArray(u)||(u=[u]),u.forEach(g=>{let h=unifier.JsonUnifier.getLogichValue(g);h&&V.push(h);});let b=unifier.JsonUnifier.getLogichValue(r.goNextStep),N=unifier.JsonUnifier.getLogichValue(r.end);if(d){let g=d.map(h=>{let y="";if(Array.isArray(h.text)){let n=[];h.text.forEach(c=>{if(typeof c=="string")n.push(translator.translator.t(c));else if(c&&typeof c=="object"){let f=unifier.JsonUnifier.getLogichValue(c);f&&!Array.isArray(f)&&typeof f=="object"&&(f=unifier.JsonUnifier.getLogichValue(f)||""),f&&(Array.isArray(f)?n=n.concat(translator.translator.t(f)):n.push(translator.translator.t(f)));}}),y=n;}else typeof h.text=="string"&&(y=translator.translator.t(h.text));return {label:h.label,text:y,props:h.props,type:h.type,oneTime:h.oneTime,onlyHaveNoChoice:h.onlyHaveNoChoice,autoSelect:h.autoSelect}});narration.narration.choiceMenuOptions=g;}else narration.narration.choiceMenuOptions=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 g of V){let h=g.label;typeof h=="object"&&(h=unifier.JsonUnifier.getLogichValue(h)||"");let y=g.params?.map(e=>unifier.JsonUnifier.getLogichValue(e));o={...o,...g.props},g.type==="jump"?(narration.narration.openedLabels.length>0&&narration.narration.closeCurrentLabel(),storage.storage.setTempVariable(`${$}${narration.narration.openedLabels.length}`,y),await narration.narration.callLabel(h,o)):(storage.storage.setTempVariable(`${$}${narration.narration.openedLabels.length}`,y),await narration.narration.callLabel(h,o));}N==="game_end"?(narration.narration.closeAllLabels(),await narration.narration.goNext(o,{runNow:true})):N==="label_end"&&narration.narration.closeCurrentLabel(),b&&await narration.narration.goNext(o,{runNow:true});}}};exports.LabelJson=w;exports.importPixiVNJson=le;
|
package/dist/importer.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {RegisteredLabels,LabelAbstract,narration}from'@drincs/pixi-vn/narration';import {JsonUnifier}from'@drincs/pixi-vn-json/unifier';import {translator}from'@drincs/pixi-vn-json/translator';import {storage,SYSTEM_RESERVED_STORAGE_KEYS}from'@drincs/pixi-vn/storage';var Q=Object.create;var I=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var re=(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 ee(i))!ie.call(a,n)&&n!==t&&I(a,n,{get:()=>i[n],enumerable:!(o=Z(i,n))||o.enumerable});return a};var oe=(a,i,t)=>(t=a!=null?Q(te(a)):{},ne(I(t,"default",{value:a,enumerable:true}),a));var C=(a,i,t)=>re(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.")},l=Object.create||(function(){function e(){}return function(r){var c;return e.prototype=r,c=new e,e.prototype=null,c}})(),s={},u=s.lib={},d=u.Base=(function(){return {extend:function(e){var r=l(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=d.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 S=0;S<v;S++){var D=c[S>>>2]>>>24-S%4*8&255;r[f+S>>>2]|=D<<24-(f+S)%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=d.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=s.enc={},V=p.Hex={stringify:function(e){for(var r=e.words,c=e.sigBytes,f=[],v=0;v<c;v++){var S=r[v>>>2]>>>24-v%4*8&255;f.push((S>>>4).toString(16)),f.push((S&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 S=r[v>>>2]>>>24-v%4*8&255;f.push(String.fromCharCode(S));}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)))}},g=u.BufferedBlockAlgorithm=d.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,S=this.blockSize,D=S*4,_=v/D;e?_=i.ceil(_):_=i.max((_|0)-this._minBufferSize,0);var T=_*S,j=i.min(T*4,v);if(T){for(var k=0;k<T;k+=S)this._doProcessBlock(f,k);r=f.splice(0,T),c.sigBytes-=j;}return new x.init(r,j)},clone:function(){var e=d.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});u.Hasher=g.extend({cfg:d.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset();},reset:function(){g.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=s.algo={};return s})(Math);return a});});var X=z((E,M)=>{(function(a,i){typeof E=="object"?M.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,l=i.algo,s=[],u=l.SHA1=n.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(d,x){for(var p=this._hash.words,V=p[0],b=p[1],N=p[2],g=p[3],h=p[4],y=0;y<80;y++){if(y<16)s[y]=d[x+y]|0;else {var e=s[y-3]^s[y-8]^s[y-14]^s[y-16];s[y]=e<<1|e>>>31;}var r=(V<<5|V>>>27)+h+s[y];y<20?r+=(b&N|~b&g)+1518500249:y<40?r+=(b^N^g)+1859775393:y<60?r+=(b&N|b&g|N&g)-1894007588:r+=(b^N^g)-899497514,h=g,g=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]+g|0,p[4]=p[4]+h|0;},_doFinalize:function(){var d=this._data,x=d.words,p=this._nDataBytes*8,V=d.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,d.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var d=n.clone.call(this);return d._hash=this._hash.clone(),d}});i.SHA1=n._createHelper(u),i.HmacSHA1=n._createHmacHelper(u);})(),a.SHA1});});var L;(n=>(n.log=(l,...s)=>console.log(`[Pixi\u2019VN Json] ${l}`,...s),n.warn=(l,...s)=>console.warn(`[Pixi\u2019VN Json] ${l}`,...s),n.error=(l,...s)=>console.error(`[Pixi\u2019VN Json] ${l}`,...s),n.info=(l,...s)=>console.info(`[Pixi\u2019VN Json] ${l}`,...s)))(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 "fade":case "move":case "rotate":case "zoom":JsonUnifier.tickerOperation(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);if(i)switch(i.type){case "value":i.storageOperationType==="set"&&(i.storageType==="storage"||i.storageType==="tempstorage")&&JsonUnifier.setInitialStorageValue(i);break}}async function le(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 l=>{if(typeof l=="string")try{l=JSON.parse(l);}catch(s){L.error("Error parsing imported Pixi'VN JSON",s),l={};}return l}),n=(await Promise.all(t)).map(async l=>{let s=[];if(l.initialOperations)for(let u of l.initialOperations)U(u);if(l.labels){let u=l.labels;for(let d in u)try{let x=u[d],p=new w(d,x,void 0,i);RegisteredLabels.add(p);}catch(x){L.error(`Error creating JSON label ${d}`,x);}}return Promise.all(s)});await Promise.all(n);}var K=oe(X());var $="___param___";function q(a){try{if(typeof a>"u")return a;let i=JSON.stringify(a);return JSON.parse(i)}catch(i){throw L.error("Error creating exportable element",a,i),new Error("[Pixi\u2019VN] Error creating exportable element")}}var w=class extends LabelAbstract{constructor(t,o,n,l={}){n||(n={}),n.onLoadingLabel=async()=>{for(let s of o){let u;if(typeof s=="function"?u=s():u=s,u=JsonUnifier.getConditionalStep(u),u.operations){let d=u.operations.map(x=>JsonUnifier.loadAssets(x));await Promise.all(d);}}};super(t,n);C(this,"_steps");C(this,"operationStringConvert");C(this,"skipEmptyDialogs",false);this._steps=o,this.operationStringConvert=l.operationStringConvert,this.skipEmptyDialogs=l.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, K.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let o="";if(Array.isArray(t)){let n=[];t.forEach(l=>{if(typeof l=="string")n.push(l);else if(l&&typeof l=="object"){let s=JsonUnifier.getLogichValue(l);s?(s&&!Array.isArray(s)&&typeof s=="object"&&(s=JsonUnifier.getLogichValue(s)||""),Array.isArray(s)?n=n.map(u=>`${u}`).concat(s):n.push(`${s}`)):n.push(`${l}`);}else n.push(`${l}`);}),o=n;}else {let n=JsonUnifier.getLogichValue(t)||"";n&&!Array.isArray(n)&&typeof n=="object"&&(n=JsonUnifier.getLogichValue(n)||""),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(l=>JsonUnifier.getLogichValue(l)).filter(l=>l!==void 0)}stepConverter(t){return async o=>{let n=typeof t=="function"?t():t;n=q(n),n=JsonUnifier.getConditionalStep(n);let l=this.operationStringConvert?g=>this.operationStringConvert(g,n,o):void 0,{operations:s=[]}=n;for(let g of s)await R(g,l);let{labelToOpen:u=[]}=n,d=this.getChoices(n.choices),x=JsonUnifier.getLogichValue(n.glueEnabled),p=this.getDialogue(n.dialogue),V=[];Array.isArray(u)||(u=[u]),u.forEach(g=>{let h=JsonUnifier.getLogichValue(g);h&&V.push(h);});let b=JsonUnifier.getLogichValue(n.goNextStep),N=JsonUnifier.getLogichValue(n.end);if(d){let g=d.map(h=>{let y="";if(Array.isArray(h.text)){let r=[];h.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 h.text=="string"&&(y=translator.t(h.text));return {label:h.label,text:y,props:h.props,type:h.type,oneTime:h.oneTime,onlyHaveNoChoice:h.onlyHaveNoChoice,autoSelect:h.autoSelect}});narration.choiceMenuOptions=g;}else narration.choiceMenuOptions=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 g of V){let h=g.label;typeof h=="object"&&(h=JsonUnifier.getLogichValue(h)||"");let y=g.params?.map(e=>JsonUnifier.getLogichValue(e));o={...o,...g.props},g.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${$}${narration.openedLabels.length}`,y),await narration.callLabel(h,o)):(storage.setTempVariable(`${$}${narration.openedLabels.length}`,y),await narration.callLabel(h,o));}N==="game_end"?(narration.closeAllLabels(),await narration.goNext(o,{runNow:true})):N==="label_end"&&narration.closeCurrentLabel(),b&&await narration.goNext(o,{runNow:true});}}};export{w as LabelJson,le as importPixiVNJson};
|
|
1
|
+
import {RegisteredLabels,LabelAbstract,narration}from'@drincs/pixi-vn/narration';import {JsonUnifier}from'@drincs/pixi-vn-json/unifier';import {translator}from'@drincs/pixi-vn-json/translator';import {storage,SYSTEM_RESERVED_STORAGE_KEYS}from'@drincs/pixi-vn/storage';var Q=Object.create;var I=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var re=(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 r of ee(i))!ie.call(a,r)&&r!==t&&I(a,r,{get:()=>i[r],enumerable:!(o=Z(i,r))||o.enumerable});return a};var oe=(a,i,t)=>(t=a!=null?Q(te(a)):{},ne(I(t,"default",{value:a,enumerable:true}),a));var C=(a,i,t)=>re(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 r=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(n){var c;return e.prototype=n,c=new e,e.prototype=null,c}})(),l={},u=l.lib={},d=u.Base=(function(){return {extend:function(e){var n=s(this);return e&&n.mixIn(e),(!n.hasOwnProperty("init")||this.init===n.init)&&(n.init=function(){n.$super.init.apply(this,arguments);}),n.init.prototype=n,n.$super=this,n},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var n in e)e.hasOwnProperty(n)&&(this[n]=e[n]);e.hasOwnProperty("toString")&&(this.toString=e.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),x=u.WordArray=d.extend({init:function(e,n){e=this.words=e||[],n!=t?this.sigBytes=n:this.sigBytes=e.length*4;},toString:function(e){return (e||V).stringify(this)},concat:function(e){var n=this.words,c=e.words,f=this.sigBytes,v=e.sigBytes;if(this.clamp(),f%4)for(var S=0;S<v;S++){var D=c[S>>>2]>>>24-S%4*8&255;n[f+S>>>2]|=D<<24-(f+S)%4*8;}else for(var _=0;_<v;_+=4)n[f+_>>>2]=c[_>>>2];return this.sigBytes+=v,this},clamp:function(){var e=this.words,n=this.sigBytes;e[n>>>2]&=4294967295<<32-n%4*8,e.length=i.ceil(n/4);},clone:function(){var e=d.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var n=[],c=0;c<e;c+=4)n.push(r());return new x.init(n,e)}}),p=l.enc={},V=p.Hex={stringify:function(e){for(var n=e.words,c=e.sigBytes,f=[],v=0;v<c;v++){var S=n[v>>>2]>>>24-v%4*8&255;f.push((S>>>4).toString(16)),f.push((S&15).toString(16));}return f.join("")},parse:function(e){for(var n=e.length,c=[],f=0;f<n;f+=2)c[f>>>3]|=parseInt(e.substr(f,2),16)<<24-f%8*4;return new x.init(c,n/2)}},b=p.Latin1={stringify:function(e){for(var n=e.words,c=e.sigBytes,f=[],v=0;v<c;v++){var S=n[v>>>2]>>>24-v%4*8&255;f.push(String.fromCharCode(S));}return f.join("")},parse:function(e){for(var n=e.length,c=[],f=0;f<n;f++)c[f>>>2]|=(e.charCodeAt(f)&255)<<24-f%4*8;return new x.init(c,n)}},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)))}},g=u.BufferedBlockAlgorithm=d.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 n,c=this._data,f=c.words,v=c.sigBytes,S=this.blockSize,D=S*4,_=v/D;e?_=i.ceil(_):_=i.max((_|0)-this._minBufferSize,0);var T=_*S,j=i.min(T*4,v);if(T){for(var k=0;k<T;k+=S)this._doProcessBlock(f,k);n=f.splice(0,T),c.sigBytes-=j;}return new x.init(n,j)},clone:function(){var e=d.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});u.Hasher=g.extend({cfg:d.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset();},reset:function(){g.reset.call(this),this._doReset();},update:function(e){return this._append(e),this._process(),this},finalize:function(e){e&&this._append(e);var n=this._doFinalize();return n},blockSize:512/32,_createHelper:function(e){return function(n,c){return new e.init(c).finalize(n)}},_createHmacHelper:function(e){return function(n,c){return new y.HMAC.init(e,c).finalize(n)}}});var y=l.algo={};return l})(Math);return a});});var X=z((E,M)=>{(function(a,i){typeof E=="object"?M.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,r=t.Hasher,s=i.algo,l=[],u=s.SHA1=r.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(d,x){for(var p=this._hash.words,V=p[0],b=p[1],N=p[2],g=p[3],h=p[4],y=0;y<80;y++){if(y<16)l[y]=d[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 n=(V<<5|V>>>27)+h+l[y];y<20?n+=(b&N|~b&g)+1518500249:y<40?n+=(b^N^g)+1859775393:y<60?n+=(b&N|b&g|N&g)-1894007588:n+=(b^N^g)-899497514,h=g,g=N,N=b<<30|b>>>2,b=V,V=n;}p[0]=p[0]+V|0,p[1]=p[1]+b|0,p[2]=p[2]+N|0,p[3]=p[3]+g|0,p[4]=p[4]+h|0;},_doFinalize:function(){var d=this._data,x=d.words,p=this._nDataBytes*8,V=d.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,d.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var d=r.clone.call(this);return d._hash=this._hash.clone(),d}});i.SHA1=r._createHelper(u),i.HmacSHA1=r._createHmacHelper(u);})(),a.SHA1});});var L;(r=>(r.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),r.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),r.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),r.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),r=await i(o);r&&await R(r,i);}break;case "input":case "dialogue":JsonUnifier.narrationOperation(t);break;case "fade":case "move":case "rotate":case "zoom":JsonUnifier.tickerOperation(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);if(i)switch(i.type){case "value":i.storageOperationType==="set"&&(i.storageType==="storage"||i.storageType==="tempstorage")&&JsonUnifier.setInitialStorageValue(i);break}}async function le(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}),r=(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 d in u)try{let x=u[d],p=new w(d,x,void 0,i);RegisteredLabels.add(p);}catch(x){L.error(`Error creating JSON label ${d}`,x);}}return Promise.all(l)});await Promise.all(r);}var K=oe(X());var $="___param___";function q(a){try{if(typeof a>"u")return a;let i=JSON.stringify(a);return JSON.parse(i)}catch(i){throw L.error("Error creating exportable element",a,i),new Error("[Pixi\u2019VN] Error creating exportable element")}}var w=class extends LabelAbstract{constructor(t,o,r,s={}){r||(r={}),r.onLoadingLabel=async()=>{for(let l of o){let u;if(typeof l=="function"?u=l():u=l,u=JsonUnifier.getConditionalStep(u),u.operations){let d=u.operations.map(x=>JsonUnifier.loadAssets(x));await Promise.all(d);}}};super(t,r);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, K.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let o="";if(Array.isArray(t)){let r=[];t.forEach(s=>{if(typeof s=="string")r.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)?r=r.map(u=>`${u}`).concat(l):r.push(`${l}`)):r.push(`${s}`);}else r.push(`${s}`);}),o=r;}else {let r=JsonUnifier.getLogichValue(t);r&&!Array.isArray(r)&&typeof r=="object"&&(r=JsonUnifier.getLogichValue(r)),r&&Array.isArray(r)?o=r.map(s=>`${s}`):o=`${r}`;}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 r=typeof t=="function"?t():t;r=q(r),r=JsonUnifier.getConditionalStep(r);let s=this.operationStringConvert?g=>this.operationStringConvert(g,r,o):void 0,{operations:l=[]}=r;for(let g of l)await R(g,s);let{labelToOpen:u=[]}=r,d=this.getChoices(r.choices),x=JsonUnifier.getLogichValue(r.glueEnabled),p=this.getDialogue(r.dialogue),V=[];Array.isArray(u)||(u=[u]),u.forEach(g=>{let h=JsonUnifier.getLogichValue(g);h&&V.push(h);});let b=JsonUnifier.getLogichValue(r.goNextStep),N=JsonUnifier.getLogichValue(r.end);if(d){let g=d.map(h=>{let y="";if(Array.isArray(h.text)){let n=[];h.text.forEach(c=>{if(typeof c=="string")n.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)?n=n.concat(translator.t(f)):n.push(translator.t(f)));}}),y=n;}else typeof h.text=="string"&&(y=translator.t(h.text));return {label:h.label,text:y,props:h.props,type:h.type,oneTime:h.oneTime,onlyHaveNoChoice:h.onlyHaveNoChoice,autoSelect:h.autoSelect}});narration.choiceMenuOptions=g;}else narration.choiceMenuOptions=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 g of V){let h=g.label;typeof h=="object"&&(h=JsonUnifier.getLogichValue(h)||"");let y=g.params?.map(e=>JsonUnifier.getLogichValue(e));o={...o,...g.props},g.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${$}${narration.openedLabels.length}`,y),await narration.callLabel(h,o)):(storage.setTempVariable(`${$}${narration.openedLabels.length}`,y),await narration.callLabel(h,o));}N==="game_end"?(narration.closeAllLabels(),await narration.goNext(o,{runNow:true})):N==="label_end"&&narration.closeCurrentLabel(),b&&await narration.goNext(o,{runNow:true});}}};export{w as LabelJson,le as importPixiVNJson};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drincs/pixi-vn-json",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Pixi'VN can be integrated with JSON files to create a visual novel.",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -45,9 +45,15 @@
|
|
|
45
45
|
},
|
|
46
46
|
"typesVersions": {
|
|
47
47
|
"*": {
|
|
48
|
-
"unifier": [
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
"unifier": [
|
|
49
|
+
"./dist/unifier.d.ts"
|
|
50
|
+
],
|
|
51
|
+
"importer": [
|
|
52
|
+
"./dist/importer.d.ts"
|
|
53
|
+
],
|
|
54
|
+
"translator": [
|
|
55
|
+
"./dist/translator.d.ts"
|
|
56
|
+
]
|
|
51
57
|
}
|
|
52
58
|
},
|
|
53
59
|
"repository": {
|
|
@@ -67,7 +73,8 @@
|
|
|
67
73
|
"jsdom": "^27.0.0",
|
|
68
74
|
"ts-node": "^10.9.2",
|
|
69
75
|
"tsup": "^8.5.0",
|
|
70
|
-
"typescript": "^5.9.3"
|
|
76
|
+
"typescript": "^5.9.3",
|
|
77
|
+
"vite-tsconfig-paths": "^5.1.4"
|
|
71
78
|
},
|
|
72
79
|
"peerDependencies": {
|
|
73
80
|
"@drincs/pixi-vn": ">=1.3.31"
|