@drincs/pixi-vn 1.9.2 → 1.9.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/canvas.mjs +1 -1
- package/dist/characters.cjs +1 -1
- package/dist/characters.mjs +1 -1
- package/dist/{chunk-6GLWL3NH.mjs → chunk-7P46CLKX.mjs} +1 -1
- package/dist/chunk-AWU37VV6.mjs +1 -0
- package/dist/chunk-QOBPVPCY.mjs +1 -0
- package/dist/chunk-U5BSF6X3.mjs +1 -0
- package/dist/chunk-YBA63R27.mjs +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.d.cts +4 -4
- package/dist/core.d.ts +4 -4
- package/dist/core.mjs +1 -1
- package/dist/history.cjs +1 -1
- package/dist/history.d.cts +2 -2
- package/dist/history.d.ts +2 -2
- package/dist/history.mjs +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +39 -2
- package/dist/index.d.ts +39 -2
- package/dist/index.mjs +2 -2
- package/dist/narration.cjs +1 -1
- package/dist/narration.d.cts +2 -1
- package/dist/narration.d.ts +2 -1
- package/dist/narration.mjs +1 -1
- package/dist/sound.mjs +1 -1
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.cts +1 -1
- package/dist/storage.d.ts +1 -1
- package/dist/storage.mjs +1 -1
- package/dist/vite.cjs +6 -4
- package/dist/vite.d.cts +64 -0
- package/dist/vite.d.ts +64 -0
- package/dist/vite.mjs +6 -4
- package/dist/worker.cjs +1 -0
- package/dist/worker.d.cts +153 -0
- package/dist/worker.d.ts +153 -0
- package/dist/worker.mjs +1 -0
- package/package.json +7 -1
- package/dist/chunk-HD353M4B.mjs +0 -1
- package/dist/chunk-HQQ5WH6C.mjs +0 -1
- package/dist/chunk-I7DOUH5V.mjs +0 -1
package/dist/narration.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var core=require('@drincs/pixi-vn/core');var yt=Object.create;var We=Object.defineProperty;var St=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Je=s=>{throw TypeError(s)};var Tt=(s,e,t)=>e in s?We(s,e,{enumerable:true,configurable:true,writable:true,value:t}):s[e]=t;var Be=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var Ze=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var _t=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mt(e))!Lt.call(s,i)&&i!==t&&We(s,i,{get:()=>e[i],enumerable:!(n=St(e,i))||n.enumerable});return s};var Ct=(s,e,t)=>(t=s!=null?yt(gt(s)):{},_t(We(t,"default",{value:s,enumerable:true}),s));var z=(s,e,t)=>Tt(s,typeof e!="symbol"?e+"":e,t),je=(s,e,t)=>e.has(s)||Je("Cannot "+t);var r=(s,e,t)=>(je(s,e,"read from private field"),t?t.call(s):e.get(s)),v=(s,e,t)=>e.has(s)?Je("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),S=(s,e,t,n)=>(je(s,e,"write to private field"),e.set(s,t),t),f=(s,e,t)=>(je(s,e,"access private method"),t);var Ue=(s,e,t,n)=>({set _(i){S(s,e,i);},get _(){return r(s,e,n)}});var ut=Ze((ze,ct)=>{(function(s,e){typeof ze=="object"?ct.exports=ze=e():typeof define=="function"&&define.amd?define([],e):s.CryptoJS=e();})(ze,function(){var s=s||(function(e,t){var n;if(typeof window<"u"&&window.crypto&&(n=window.crypto),typeof self<"u"&&self.crypto&&(n=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(n=globalThis.crypto),!n&&typeof window<"u"&&window.msCrypto&&(n=window.msCrypto),!n&&typeof global<"u"&&global.crypto&&(n=global.crypto),!n&&typeof Be=="function")try{n=Be("crypto");}catch{}var i=function(){if(n){if(typeof n.getRandomValues=="function")try{return n.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof n.randomBytes=="function")try{return n.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||(function(){function l(){}return function(d){var E;return l.prototype=d,E=new l,l.prototype=null,E}})(),o={},p=o.lib={},c=p.Base=(function(){return {extend:function(l){var d=a(this);return l&&d.mixIn(l),(!d.hasOwnProperty("init")||this.init===d.init)&&(d.init=function(){d.$super.init.apply(this,arguments);}),d.init.prototype=d,d.$super=this,d},create:function(){var l=this.extend();return l.init.apply(l,arguments),l},init:function(){},mixIn:function(l){for(var d in l)l.hasOwnProperty(d)&&(this[d]=l[d]);l.hasOwnProperty("toString")&&(this.toString=l.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),y=p.WordArray=c.extend({init:function(l,d){l=this.words=l||[],d!=t?this.sigBytes=d:this.sigBytes=l.length*4;},toString:function(l){return (l||g).stringify(this)},concat:function(l){var d=this.words,E=l.words,C=this.sigBytes,R=l.sigBytes;if(this.clamp(),C%4)for(var D=0;D<R;D++){var se=E[D>>>2]>>>24-D%4*8&255;d[C+D>>>2]|=se<<24-(C+D)%4*8;}else for(var G=0;G<R;G+=4)d[C+G>>>2]=E[G>>>2];return this.sigBytes+=R,this},clamp:function(){var l=this.words,d=this.sigBytes;l[d>>>2]&=4294967295<<32-d%4*8,l.length=e.ceil(d/4);},clone:function(){var l=c.clone.call(this);return l.words=this.words.slice(0),l},random:function(l){for(var d=[],E=0;E<l;E+=4)d.push(i());return new y.init(d,l)}}),h=o.enc={},g=h.Hex={stringify:function(l){for(var d=l.words,E=l.sigBytes,C=[],R=0;R<E;R++){var D=d[R>>>2]>>>24-R%4*8&255;C.push((D>>>4).toString(16)),C.push((D&15).toString(16));}return C.join("")},parse:function(l){for(var d=l.length,E=[],C=0;C<d;C+=2)E[C>>>3]|=parseInt(l.substr(C,2),16)<<24-C%8*4;return new y.init(E,d/2)}},M=h.Latin1={stringify:function(l){for(var d=l.words,E=l.sigBytes,C=[],R=0;R<E;R++){var D=d[R>>>2]>>>24-R%4*8&255;C.push(String.fromCharCode(D));}return C.join("")},parse:function(l){for(var d=l.length,E=[],C=0;C<d;C++)E[C>>>2]|=(l.charCodeAt(C)&255)<<24-C%4*8;return new y.init(E,d)}},N=h.Utf8={stringify:function(l){try{return decodeURIComponent(escape(M.stringify(l)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(l){return M.parse(unescape(encodeURIComponent(l)))}},P=p.BufferedBlockAlgorithm=c.extend({reset:function(){this._data=new y.init,this._nDataBytes=0;},_append:function(l){typeof l=="string"&&(l=N.parse(l)),this._data.concat(l),this._nDataBytes+=l.sigBytes;},_process:function(l){var d,E=this._data,C=E.words,R=E.sigBytes,D=this.blockSize,se=D*4,G=R/se;l?G=e.ceil(G):G=e.max((G|0)-this._minBufferSize,0);var Q=G*D,Le=e.min(Q*4,R);if(Q){for(var Ke=0;Ke<Q;Ke+=D)this._doProcessBlock(C,Ke);d=C.splice(0,Q),E.sigBytes-=Le;}return new y.init(d,Le)},clone:function(){var l=c.clone.call(this);return l._data=this._data.clone(),l},_minBufferSize:0});p.Hasher=P.extend({cfg:c.extend(),init:function(l){this.cfg=this.cfg.extend(l),this.reset();},reset:function(){P.reset.call(this),this._doReset();},update:function(l){return this._append(l),this._process(),this},finalize:function(l){l&&this._append(l);var d=this._doFinalize();return d},blockSize:512/32,_createHelper:function(l){return function(d,E){return new l.init(E).finalize(d)}},_createHmacHelper:function(l){return function(d,E){return new _.HMAC.init(l,E).finalize(d)}}});var _=o.algo={};return o})(Math);return s});});var dt=Ze((He,ht)=>{(function(s,e){typeof He=="object"?ht.exports=He=e(ut()):typeof define=="function"&&define.amd?define(["./core"],e):e(s.CryptoJS);})(He,function(s){return (function(){var e=s,t=e.lib,n=t.WordArray,i=t.Hasher,a=e.algo,o=[],p=a.SHA1=i.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(c,y){for(var h=this._hash.words,g=h[0],M=h[1],N=h[2],P=h[3],w=h[4],_=0;_<80;_++){if(_<16)o[_]=c[y+_]|0;else {var l=o[_-3]^o[_-8]^o[_-14]^o[_-16];o[_]=l<<1|l>>>31;}var d=(g<<5|g>>>27)+w+o[_];_<20?d+=(M&N|~M&P)+1518500249:_<40?d+=(M^N^P)+1859775393:_<60?d+=(M&N|M&P|N&P)-1894007588:d+=(M^N^P)-899497514,w=P,P=N,N=M<<30|M>>>2,M=g,g=d;}h[0]=h[0]+g|0,h[1]=h[1]+M|0,h[2]=h[2]+N|0,h[3]=h[3]+P|0,h[4]=h[4]+w|0;},_doFinalize:function(){var c=this._data,y=c.words,h=this._nDataBytes*8,g=c.sigBytes*8;return y[g>>>5]|=128<<24-g%32,y[(g+64>>>9<<4)+14]=Math.floor(h/4294967296),y[(g+64>>>9<<4)+15]=h,c.sigBytes=y.length*4,this._process(),this._hash},clone:function(){var c=i.clone.call(this);return c._hash=this._hash.clone(),c}});e.SHA1=i._createHelper(p),e.HmacSHA1=i._createHmacHelper(p);})(),s.SHA1});});var O="narration";var I={CURRENT_DIALOGUE_MEMORY_KEY:"dialogue",LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY:"dialogue:step_counter",CURRENT_MENU_OPTIONS_MEMORY_KEY:"choice:options",LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY:"choice:step_counter",CURRENT_INPUT_VALUE_MEMORY_KEY:"input:value",LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY:"input:step_counter",CURRENT_INPUT_INFO_MEMORY_KEY:"input:info",CHARACTER_CATEGORY_KEY:"character",ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY:"___glue___",OPENED_LABELS_COUNTER_KEY:"label:opened",ALL_CHOICES_MADE_KEY:"choices:made",CURRENT_STEP_TIMES_COUNTER_KEY:"label:history",LAST_STEP_GLUED:"glue:last_step"};var Et=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,nt=new Set,ke=typeof process=="object"&&process?process:{},it=(s,e,t,n)=>{typeof ke.emitWarning=="function"?ke.emitWarning(s,e,t,n):console.error(`[${t}] ${e}: ${s}`);},Ge=globalThis.AbortController,et=globalThis.AbortSignal;if(typeof Ge>"u"){et=class{onabort;_onabort=[];reason;aborted=false;addEventListener(t,n){this._onabort.push(n);}},Ge=class{constructor(){e();}signal=new et;abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=true;for(let n of this.signal._onabort)n(t);this.signal.onabort?.(t);}}};let s=ke.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{s&&(s=false,it("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e));};}var It=s=>!nt.has(s);var he=s=>s&&s===Math.floor(s)&&s>0&&isFinite(s),at=s=>he(s)?s<=Math.pow(2,8)?Uint8Array:s<=Math.pow(2,16)?Uint16Array:s<=Math.pow(2,32)?Uint32Array:s<=Number.MAX_SAFE_INTEGER?Ye:null:null,Ye=class extends Array{constructor(s){super(s),this.fill(0);}},oe,Te,Rt=(oe=class{heap;length;static create(e){let t=at(e);if(!t)return [];S(oe,Te,true);let n=new oe(e,t);return S(oe,Te,false),n}constructor(e,t){if(!r(oe,Te))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0;}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},Te=new WeakMap,v(oe,Te,false),oe),tt,rt,X,B,J,Se,Z,_e,Ce,ee,Y,te,U,A,T,K,j,H,V,re,F,ne,ie,k,q,ae,ye,W,Ee,u,qe,me,pe,Ae,$,ot,ge,Ie,Me,de,fe,$e,Ve,Fe,x,Xe,xe,be,Qe,Re,st=(Re=class{constructor(e){v(this,u);v(this,X);v(this,B);v(this,J);v(this,Se);v(this,Z);v(this,_e);v(this,Ce);v(this,ee);z(this,"ttl");z(this,"ttlResolution");z(this,"ttlAutopurge");z(this,"updateAgeOnGet");z(this,"updateAgeOnHas");z(this,"allowStale");z(this,"noDisposeOnSet");z(this,"noUpdateTTL");z(this,"maxEntrySize");z(this,"sizeCalculation");z(this,"noDeleteOnFetchRejection");z(this,"noDeleteOnStaleGet");z(this,"allowStaleOnFetchAbort");z(this,"allowStaleOnFetchRejection");z(this,"ignoreFetchAbort");v(this,Y);v(this,te);v(this,U);v(this,A);v(this,T);v(this,K);v(this,j);v(this,H);v(this,V);v(this,re);v(this,F);v(this,ne);v(this,ie);v(this,k);v(this,q);v(this,ae);v(this,ye);v(this,W);v(this,Ee);v(this,me,()=>{});v(this,pe,()=>{});v(this,Ae,()=>{});v(this,$,()=>false);v(this,ge,e=>{});v(this,Ie,(e,t,n)=>{});v(this,Me,(e,t,n,i)=>{if(n||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});z(this,tt,"LRUCache");let{max:t=0,ttl:n,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:o,updateAgeOnHas:p,allowStale:c,dispose:y,onInsert:h,disposeAfter:g,noDisposeOnSet:M,noUpdateTTL:N,maxSize:P=0,maxEntrySize:w=0,sizeCalculation:_,fetchMethod:l,memoMethod:d,noDeleteOnFetchRejection:E,noDeleteOnStaleGet:C,allowStaleOnFetchRejection:R,allowStaleOnFetchAbort:D,ignoreFetchAbort:se,perf:G}=e;if(G!==void 0&&typeof G?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(S(this,ee,G??Et),t!==0&&!he(t))throw new TypeError("max option must be a nonnegative integer");let Q=t?at(t):Array;if(!Q)throw new Error("invalid max value: "+t);if(S(this,X,t),S(this,B,P),this.maxEntrySize=w||r(this,B),this.sizeCalculation=_,this.sizeCalculation){if(!r(this,B)&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(d!==void 0&&typeof d!="function")throw new TypeError("memoMethod must be a function if defined");if(S(this,Ce,d),l!==void 0&&typeof l!="function")throw new TypeError("fetchMethod must be a function if specified");if(S(this,_e,l),S(this,ye,!!l),S(this,U,new Map),S(this,A,new Array(t).fill(void 0)),S(this,T,new Array(t).fill(void 0)),S(this,K,new Q(t)),S(this,j,new Q(t)),S(this,H,0),S(this,V,0),S(this,re,Rt.create(t)),S(this,Y,0),S(this,te,0),typeof y=="function"&&S(this,J,y),typeof h=="function"&&S(this,Se,h),typeof g=="function"?(S(this,Z,g),S(this,F,[])):(S(this,Z,void 0),S(this,F,void 0)),S(this,ae,!!r(this,J)),S(this,Ee,!!r(this,Se)),S(this,W,!!r(this,Z)),this.noDisposeOnSet=!!M,this.noUpdateTTL=!!N,this.noDeleteOnFetchRejection=!!E,this.allowStaleOnFetchRejection=!!R,this.allowStaleOnFetchAbort=!!D,this.ignoreFetchAbort=!!se,this.maxEntrySize!==0){if(r(this,B)!==0&&!he(r(this,B)))throw new TypeError("maxSize must be a positive integer if specified");if(!he(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");f(this,u,ot).call(this);}if(this.allowStale=!!c,this.noDeleteOnStaleGet=!!C,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!p,this.ttlResolution=he(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=n||0,this.ttl){if(!he(this.ttl))throw new TypeError("ttl must be a positive integer if specified");f(this,u,qe).call(this);}if(r(this,X)===0&&this.ttl===0&&r(this,B)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!r(this,X)&&!r(this,B)){let Le="LRU_CACHE_UNBOUNDED";It(Le)&&(nt.add(Le),it("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Le,Re));}}get perf(){return r(this,ee)}static unsafeExposeInternals(e){return {starts:r(e,ie),ttls:r(e,k),autopurgeTimers:r(e,q),sizes:r(e,ne),keyMap:r(e,U),keyList:r(e,A),valList:r(e,T),next:r(e,K),prev:r(e,j),get head(){return r(e,H)},get tail(){return r(e,V)},free:r(e,re),isBackgroundFetch:t=>{var n;return f(n=e,u,x).call(n,t)},backgroundFetch:(t,n,i,a)=>{var o;return f(o=e,u,Fe).call(o,t,n,i,a)},moveToTail:t=>{var n;return f(n=e,u,xe).call(n,t)},indexes:t=>{var n;return f(n=e,u,de).call(n,t)},rindexes:t=>{var n;return f(n=e,u,fe).call(n,t)},isStale:t=>{var n;return r(n=e,$).call(n,t)}}}get max(){return r(this,X)}get maxSize(){return r(this,B)}get calculatedSize(){return r(this,te)}get size(){return r(this,Y)}get fetchMethod(){return r(this,_e)}get memoMethod(){return r(this,Ce)}get dispose(){return r(this,J)}get onInsert(){return r(this,Se)}get disposeAfter(){return r(this,Z)}getRemainingTTL(e){return r(this,U).has(e)?1/0:0}*entries(){for(let e of f(this,u,de).call(this))r(this,T)[e]!==void 0&&r(this,A)[e]!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield [r(this,A)[e],r(this,T)[e]]);}*rentries(){for(let e of f(this,u,fe).call(this))r(this,T)[e]!==void 0&&r(this,A)[e]!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield [r(this,A)[e],r(this,T)[e]]);}*keys(){for(let e of f(this,u,de).call(this)){let t=r(this,A)[e];t!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield t);}}*rkeys(){for(let e of f(this,u,fe).call(this)){let t=r(this,A)[e];t!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield t);}}*values(){for(let e of f(this,u,de).call(this))r(this,T)[e]!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield r(this,T)[e]);}*rvalues(){for(let e of f(this,u,fe).call(this))r(this,T)[e]!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield r(this,T)[e]);}[(rt=Symbol.iterator,tt=Symbol.toStringTag,rt)](){return this.entries()}find(e,t={}){for(let n of f(this,u,de).call(this)){let i=r(this,T)[n],a=f(this,u,x).call(this,i)?i.__staleWhileFetching:i;if(a!==void 0&&e(a,r(this,A)[n],this))return this.get(r(this,A)[n],t)}}forEach(e,t=this){for(let n of f(this,u,de).call(this)){let i=r(this,T)[n],a=f(this,u,x).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,r(this,A)[n],this);}}rforEach(e,t=this){for(let n of f(this,u,fe).call(this)){let i=r(this,T)[n],a=f(this,u,x).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,r(this,A)[n],this);}}purgeStale(){let e=false;for(let t of f(this,u,fe).call(this,{allowStale:true}))r(this,$).call(this,t)&&(f(this,u,be).call(this,r(this,A)[t],"expire"),e=true);return e}info(e){let t=r(this,U).get(e);if(t===void 0)return;let n=r(this,T)[t],i=f(this,u,x).call(this,n)?n.__staleWhileFetching:n;if(i===void 0)return;let a={value:i};if(r(this,k)&&r(this,ie)){let o=r(this,k)[t],p=r(this,ie)[t];if(o&&p){let c=o-(r(this,ee).now()-p);a.ttl=c,a.start=Date.now();}}return r(this,ne)&&(a.size=r(this,ne)[t]),a}dump(){let e=[];for(let t of f(this,u,de).call(this,{allowStale:true})){let n=r(this,A)[t],i=r(this,T)[t],a=f(this,u,x).call(this,i)?i.__staleWhileFetching:i;if(a===void 0||n===void 0)continue;let o={value:a};if(r(this,k)&&r(this,ie)){o.ttl=r(this,k)[t];let p=r(this,ee).now()-r(this,ie)[t];o.start=Math.floor(Date.now()-p);}r(this,ne)&&(o.size=r(this,ne)[t]),e.unshift([n,o]);}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let i=Date.now()-n.start;n.start=r(this,ee).now()-i;}this.set(t,n.value,n);}}set(e,t,n={}){var M,N,P,w;if(t===void 0)return this.delete(e),this;let{ttl:i=this.ttl,start:a,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:p=this.sizeCalculation,status:c}=n,{noUpdateTTL:y=this.noUpdateTTL}=n,h=r(this,Me).call(this,e,t,n.size||0,p);if(this.maxEntrySize&&h>this.maxEntrySize)return c&&(c.set="miss",c.maxEntrySizeExceeded=true),f(this,u,be).call(this,e,"set"),this;let g=r(this,Y)===0?void 0:r(this,U).get(e);if(g===void 0)g=r(this,Y)===0?r(this,V):r(this,re).length!==0?r(this,re).pop():r(this,Y)===r(this,X)?f(this,u,Ve).call(this,false):r(this,Y),r(this,A)[g]=e,r(this,T)[g]=t,r(this,U).set(e,g),r(this,K)[r(this,V)]=g,r(this,j)[g]=r(this,V),S(this,V,g),Ue(this,Y)._++,r(this,Ie).call(this,g,h,c),c&&(c.set="add"),y=false,r(this,Ee)&&((M=r(this,Se))==null||M.call(this,t,e,"add"));else {f(this,u,xe).call(this,g);let _=r(this,T)[g];if(t!==_){if(r(this,ye)&&f(this,u,x).call(this,_)){_.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:l}=_;l!==void 0&&!o&&(r(this,ae)&&((N=r(this,J))==null||N.call(this,l,e,"set")),r(this,W)&&r(this,F)?.push([l,e,"set"]));}else o||(r(this,ae)&&((P=r(this,J))==null||P.call(this,_,e,"set")),r(this,W)&&r(this,F)?.push([_,e,"set"]));if(r(this,ge).call(this,g),r(this,Ie).call(this,g,h,c),r(this,T)[g]=t,c){c.set="replace";let l=_&&f(this,u,x).call(this,_)?_.__staleWhileFetching:_;l!==void 0&&(c.oldValue=l);}}else c&&(c.set="update");r(this,Ee)&&this.onInsert?.(t,e,t===_?"update":"replace");}if(i!==0&&!r(this,k)&&f(this,u,qe).call(this),r(this,k)&&(y||r(this,Ae).call(this,g,i,a),c&&r(this,pe).call(this,c,g)),!o&&r(this,W)&&r(this,F)){let _=r(this,F),l;for(;l=_?.shift();)(w=r(this,Z))==null||w.call(this,...l);}return this}pop(){var e;try{for(;r(this,Y);){let t=r(this,T)[r(this,H)];if(f(this,u,Ve).call(this,!0),f(this,u,x).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(r(this,W)&&r(this,F)){let t=r(this,F),n;for(;n=t?.shift();)(e=r(this,Z))==null||e.call(this,...n);}}}has(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:i}=t,a=r(this,U).get(e);if(a!==void 0){let o=r(this,T)[a];if(f(this,u,x).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(r(this,$).call(this,a))i&&(i.has="stale",r(this,pe).call(this,i,a));else return n&&r(this,me).call(this,a),i&&(i.has="hit",r(this,pe).call(this,i,a)),true}else i&&(i.has="miss");return false}peek(e,t={}){let{allowStale:n=this.allowStale}=t,i=r(this,U).get(e);if(i===void 0||!n&&r(this,$).call(this,i))return;let a=r(this,T)[i];return f(this,u,x).call(this,a)?a.__staleWhileFetching:a}async fetch(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:p=this.noDisposeOnSet,size:c=0,sizeCalculation:y=this.sizeCalculation,noUpdateTTL:h=this.noUpdateTTL,noDeleteOnFetchRejection:g=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:M=this.allowStaleOnFetchRejection,ignoreFetchAbort:N=this.ignoreFetchAbort,allowStaleOnFetchAbort:P=this.allowStaleOnFetchAbort,context:w,forceRefresh:_=false,status:l,signal:d}=t;if(!r(this,ye))return l&&(l.fetch="get"),this.get(e,{allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:l});let E={allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:o,noDisposeOnSet:p,size:c,sizeCalculation:y,noUpdateTTL:h,noDeleteOnFetchRejection:g,allowStaleOnFetchRejection:M,allowStaleOnFetchAbort:P,ignoreFetchAbort:N,status:l,signal:d},C=r(this,U).get(e);if(C===void 0){l&&(l.fetch="miss");let R=f(this,u,Fe).call(this,e,C,E,w);return R.__returned=R}else {let R=r(this,T)[C];if(f(this,u,x).call(this,R)){let Q=n&&R.__staleWhileFetching!==void 0;return l&&(l.fetch="inflight",Q&&(l.returnedStale=true)),Q?R.__staleWhileFetching:R.__returned=R}let D=r(this,$).call(this,C);if(!_&&!D)return l&&(l.fetch="hit"),f(this,u,xe).call(this,C),i&&r(this,me).call(this,C),l&&r(this,pe).call(this,l,C),R;let se=f(this,u,Fe).call(this,e,C,E,w),G=se.__staleWhileFetching!==void 0&&n;return l&&(l.fetch=D?"stale":"refresh",G&&D&&(l.returnedStale=true)),G?se.__staleWhileFetching:se.__returned=se}}async forceFetch(e,t={}){let n=await this.fetch(e,t);if(n===void 0)throw new Error("fetch() returned undefined");return n}memo(e,t={}){let n=r(this,Ce);if(!n)throw new Error("no memoMethod provided to constructor");let{context:i,forceRefresh:a,...o}=t,p=this.get(e,o);if(!a&&p!==void 0)return p;let c=n(e,p,{options:o,context:i});return this.set(e,c,o),c}get(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,status:o}=t,p=r(this,U).get(e);if(p!==void 0){let c=r(this,T)[p],y=f(this,u,x).call(this,c);return o&&r(this,pe).call(this,o,p),r(this,$).call(this,p)?(o&&(o.get="stale"),y?(o&&n&&c.__staleWhileFetching!==void 0&&(o.returnedStale=true),n?c.__staleWhileFetching:void 0):(a||f(this,u,be).call(this,e,"expire"),o&&n&&(o.returnedStale=true),n?c:void 0)):(o&&(o.get="hit"),y?c.__staleWhileFetching:(f(this,u,xe).call(this,p),i&&r(this,me).call(this,p),c))}else o&&(o.get="miss");}delete(e){return f(this,u,be).call(this,e,"delete")}clear(){return f(this,u,Qe).call(this,"delete")}},X=new WeakMap,B=new WeakMap,J=new WeakMap,Se=new WeakMap,Z=new WeakMap,_e=new WeakMap,Ce=new WeakMap,ee=new WeakMap,Y=new WeakMap,te=new WeakMap,U=new WeakMap,A=new WeakMap,T=new WeakMap,K=new WeakMap,j=new WeakMap,H=new WeakMap,V=new WeakMap,re=new WeakMap,F=new WeakMap,ne=new WeakMap,ie=new WeakMap,k=new WeakMap,q=new WeakMap,ae=new WeakMap,ye=new WeakMap,W=new WeakMap,Ee=new WeakMap,u=new WeakSet,qe=function(){let e=new Ye(r(this,X)),t=new Ye(r(this,X));S(this,k,e),S(this,ie,t);let n=this.ttlAutopurge?new Array(r(this,X)):void 0;S(this,q,n),S(this,Ae,(p,c,y=r(this,ee).now())=>{t[p]=c!==0?y:0,e[p]=c,i(p,c);}),S(this,me,p=>{t[p]=e[p]!==0?r(this,ee).now():0,i(p,e[p]);});let i=this.ttlAutopurge?(p,c)=>{if(n?.[p]&&(clearTimeout(n[p]),n[p]=void 0),c&&c!==0&&n){let y=setTimeout(()=>{r(this,$).call(this,p)&&f(this,u,be).call(this,r(this,A)[p],"expire");},c+1);y.unref&&y.unref(),n[p]=y;}}:()=>{};S(this,pe,(p,c)=>{if(e[c]){let y=e[c],h=t[c];if(!y||!h)return;p.ttl=y,p.start=h,p.now=a||o();let g=p.now-h;p.remainingTTL=y-g;}});let a=0,o=()=>{let p=r(this,ee).now();if(this.ttlResolution>0){a=p;let c=setTimeout(()=>a=0,this.ttlResolution);c.unref&&c.unref();}return p};this.getRemainingTTL=p=>{let c=r(this,U).get(p);if(c===void 0)return 0;let y=e[c],h=t[c];if(!y||!h)return 1/0;let g=(a||o())-h;return y-g},S(this,$,p=>{let c=t[p],y=e[p];return !!y&&!!c&&(a||o())-c>y});},me=new WeakMap,pe=new WeakMap,Ae=new WeakMap,$=new WeakMap,ot=function(){let e=new Ye(r(this,X));S(this,te,0),S(this,ne,e),S(this,ge,t=>{S(this,te,r(this,te)-e[t]),e[t]=0;}),S(this,Me,(t,n,i,a)=>{if(f(this,u,x).call(this,n))return 0;if(!he(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(n,t),!he(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return i}),S(this,Ie,(t,n,i)=>{if(e[t]=n,r(this,B)){let a=r(this,B)-e[t];for(;r(this,te)>a;)f(this,u,Ve).call(this,true);}S(this,te,r(this,te)+e[t]),i&&(i.entrySize=n,i.totalCalculatedSize=r(this,te));});},ge=new WeakMap,Ie=new WeakMap,Me=new WeakMap,de=function*({allowStale:e=this.allowStale}={}){if(r(this,Y))for(let t=r(this,V);!(!f(this,u,$e).call(this,t)||((e||!r(this,$).call(this,t))&&(yield t),t===r(this,H)));)t=r(this,j)[t];},fe=function*({allowStale:e=this.allowStale}={}){if(r(this,Y))for(let t=r(this,H);!(!f(this,u,$e).call(this,t)||((e||!r(this,$).call(this,t))&&(yield t),t===r(this,V)));)t=r(this,K)[t];},$e=function(e){return e!==void 0&&r(this,U).get(r(this,A)[e])===e},Ve=function(e){var a;let t=r(this,H),n=r(this,A)[t],i=r(this,T)[t];return r(this,ye)&&f(this,u,x).call(this,i)?i.__abortController.abort(new Error("evicted")):(r(this,ae)||r(this,W))&&(r(this,ae)&&((a=r(this,J))==null||a.call(this,i,n,"evict")),r(this,W)&&r(this,F)?.push([i,n,"evict"])),r(this,ge).call(this,t),r(this,q)?.[t]&&(clearTimeout(r(this,q)[t]),r(this,q)[t]=void 0),e&&(r(this,A)[t]=void 0,r(this,T)[t]=void 0,r(this,re).push(t)),r(this,Y)===1?(S(this,H,S(this,V,0)),r(this,re).length=0):S(this,H,r(this,K)[t]),r(this,U).delete(n),Ue(this,Y)._--,t},Fe=function(e,t,n,i){let a=t===void 0?void 0:r(this,T)[t];if(f(this,u,x).call(this,a))return a;let o=new Ge,{signal:p}=n;p?.addEventListener("abort",()=>o.abort(p.reason),{signal:o.signal});let c={signal:o.signal,options:n,context:i},y=(w,_=false)=>{let{aborted:l}=o.signal,d=n.ignoreFetchAbort&&w!==void 0,E=n.ignoreFetchAbort||!!(n.allowStaleOnFetchAbort&&w!==void 0);if(n.status&&(l&&!_?(n.status.fetchAborted=true,n.status.fetchError=o.signal.reason,d&&(n.status.fetchAbortIgnored=true)):n.status.fetchResolved=true),l&&!d&&!_)return g(o.signal.reason,E);let C=N,R=r(this,T)[t];return (R===N||d&&_&&R===void 0)&&(w===void 0?C.__staleWhileFetching!==void 0?r(this,T)[t]=C.__staleWhileFetching:f(this,u,be).call(this,e,"fetch"):(n.status&&(n.status.fetchUpdated=true),this.set(e,w,c.options))),w},h=w=>(n.status&&(n.status.fetchRejected=true,n.status.fetchError=w),g(w,false)),g=(w,_)=>{let{aborted:l}=o.signal,d=l&&n.allowStaleOnFetchAbort,E=d||n.allowStaleOnFetchRejection,C=E||n.noDeleteOnFetchRejection,R=N;if(r(this,T)[t]===N&&(!C||!_&&R.__staleWhileFetching===void 0?f(this,u,be).call(this,e,"fetch"):d||(r(this,T)[t]=R.__staleWhileFetching)),E)return n.status&&R.__staleWhileFetching!==void 0&&(n.status.returnedStale=true),R.__staleWhileFetching;if(R.__returned===R)throw w},M=(w,_)=>{var d;let l=(d=r(this,_e))==null?void 0:d.call(this,e,a,c);l&&l instanceof Promise&&l.then(E=>w(E===void 0?void 0:E),_),o.signal.addEventListener("abort",()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(w(void 0),n.allowStaleOnFetchAbort&&(w=E=>y(E,true)));});};n.status&&(n.status.fetchDispatched=true);let N=new Promise(M).then(y,h),P=Object.assign(N,{__abortController:o,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,P,{...c.options,status:void 0}),t=r(this,U).get(e)):r(this,T)[t]=P,P},x=function(e){if(!r(this,ye))return false;let t=e;return !!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof Ge},Xe=function(e,t){r(this,j)[t]=e,r(this,K)[e]=t;},xe=function(e){e!==r(this,V)&&(e===r(this,H)?S(this,H,r(this,K)[e]):f(this,u,Xe).call(this,r(this,j)[e],r(this,K)[e]),f(this,u,Xe).call(this,r(this,V),e),S(this,V,e));},be=function(e,t){var i,a;let n=false;if(r(this,Y)!==0){let o=r(this,U).get(e);if(o!==void 0)if(r(this,q)?.[o]&&(clearTimeout(r(this,q)?.[o]),r(this,q)[o]=void 0),n=true,r(this,Y)===1)f(this,u,Qe).call(this,t);else {r(this,ge).call(this,o);let p=r(this,T)[o];if(f(this,u,x).call(this,p)?p.__abortController.abort(new Error("deleted")):(r(this,ae)||r(this,W))&&(r(this,ae)&&((i=r(this,J))==null||i.call(this,p,e,t)),r(this,W)&&r(this,F)?.push([p,e,t])),r(this,U).delete(e),r(this,A)[o]=void 0,r(this,T)[o]=void 0,o===r(this,V))S(this,V,r(this,j)[o]);else if(o===r(this,H))S(this,H,r(this,K)[o]);else {let c=r(this,j)[o];r(this,K)[c]=r(this,K)[o];let y=r(this,K)[o];r(this,j)[y]=r(this,j)[o];}Ue(this,Y)._--,r(this,re).push(o);}}if(r(this,W)&&r(this,F)?.length){let o=r(this,F),p;for(;p=o?.shift();)(a=r(this,Z))==null||a.call(this,...p);}return n},Qe=function(e){var t,n;for(let i of f(this,u,fe).call(this,{allowStale:true})){let a=r(this,T)[i];if(f(this,u,x).call(this,a))a.__abortController.abort(new Error("deleted"));else {let o=r(this,A)[i];r(this,ae)&&((t=r(this,J))==null||t.call(this,a,o,e)),r(this,W)&&r(this,F)?.push([a,o,e]);}}if(r(this,U).clear(),r(this,T).fill(void 0),r(this,A).fill(void 0),r(this,k)&&r(this,ie)){r(this,k).fill(0),r(this,ie).fill(0);for(let i of r(this,q)??[])i!==void 0&&clearTimeout(i);r(this,q)?.fill(void 0);}if(r(this,ne)&&r(this,ne).fill(0),S(this,H,0),S(this,V,0),r(this,re).length=0,S(this,te,0),S(this,Y,0),r(this,W)&&r(this,F)){let i=r(this,F),a;for(;a=i?.shift();)(n=r(this,Z))==null||n.call(this,...a);}},Re);var Ne=class{cache;map=new Map;constructor(e){this.cache=new st({max:e.cacheSize}),this.map=new Map;}get[Symbol.iterator](){return this.map[Symbol.iterator]}get[Symbol.toStringTag](){return this.map[Symbol.toStringTag]}clear(){this.cache.clear(),this.map.clear();}delete(e){let t=this.map.delete(e);return t&&this.cache.delete(e),t}get forEach(){return this.map.forEach}get(e){let t=this.cache.get(e);return t||this.map.get(e)}has(e){return this.map.has(e)}set(e,t){return this.map.set(e,t),this.cache.set(e,t),this}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}};var L;(i=>(i.log=(a,...o)=>console.log(`[Pixi\u2019VN] ${a}`,...o),i.warn=(a,...o)=>console.warn(`[Pixi\u2019VN] ${a}`,...o),i.error=(a,...o)=>console.error(`[Pixi\u2019VN] ${a}`,...o),i.info=(a,...o)=>console.info(`[Pixi\u2019VN] ${a}`,...o)))(L||={});var Oe=new Ne({cacheSize:10}),lt;(o=>{function s(p){let c=Oe.get(p);if(!c){L.error(`Label "${p}" not found`);return}return c}o.get=s;function e(...p){for(let c of p)Oe.set(c.id,c);}o.add=e;function t(){return Array.from(Oe.values())}o.values=t;function n(p){return Oe.has(p)}o.has=n;function i(){return Array.from(Oe.keys())}o.keys=i;function a(){Oe.clear();}o.clear=a;})(lt||={});var le=lt;function ce(s){try{if(typeof s>"u")return s;let e=JSON.stringify(s);return JSON.parse(e)}catch(e){throw L.error("Error creating exportable element",s,e),new core.PixiError("not_json_serializable","Error creating exportable element")}}var b=class s{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return core.GameUnifier.getVariable(O,I.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){core.GameUnifier.setVariable(O,I.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e=""){let t=s.currentLabelStepIndex;if(t===null)return L.error("currentLabelStepIndex is null"),null;let n=`${t}${e}`,i=s.currentLabelId,a=s._currentLabel;if(!i||t===null||!a)return L.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let o=a.getStepSha(t)||"error",p=core.GameUnifier.getVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return p[i]||(p[i]={}),(!p[i][n]||p[i][n].stepSha1!==o)&&(p[i][n]={stepSha1:o}),p[i][n]}static setCurrentStepTimesCounterData(e="",t){let n=s.currentLabelStepIndex,i=n+e,a=s.currentLabelId;if(!a||n===null){L.error("currentLabelId or currentLabelStepIndex is null");return}let o=core.GameUnifier.getVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};o[a]||(o[a]={}),o[a][i]=t,core.GameUnifier.setVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY,o);}static getCurrentStepTimesCounter(e=""){let t=s._stepCounter,n=s.getCurrentStepTimesCounterData(e);if(!n)return L.error("getCurrentStepTimesCounter obj is null"),0;let i=n.stepCounters||[];return i.find(o=>o===t)||(i.push(t),n.stepCounters=i,s.setCurrentStepTimesCounterData(e,n)),i.length}static getRandomNumber(e,t,n={}){let i=n.nestedId||"";if(n.onceOnly||false){let o=s.getCurrentStepTimesCounterData(i);if(!o)return;let p=o.usedRandomNumbers||{},c=Array.from({length:t-e+1},(g,M)=>M+e).filter(g=>!p[`${e}-${t}`]?.includes(g));if(c.length===0)return;let y=Math.floor(Math.random()*c.length),h=c[y];return p[`${e}-${t}`]||(p[`${e}-${t}`]=[]),p[`${e}-${t}`].push(h),o.usedRandomNumbers=p,s.setCurrentStepTimesCounterData(i,o),h}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e=""){let t=s.currentLabelStepIndex,n=t+e,i=s.currentLabelId;if(!i||t===null){L.error("currentLabelId or currentLabelStepIndex is null");return}let a=core.GameUnifier.getVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[i]||(a[i]={}),a[i][n]={stepCounters:[],stepSha1:""},core.GameUnifier.setVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return core.GameUnifier.getVariable(O,I.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){core.GameUnifier.setVariable(O,I.ALL_CHOICES_MADE_KEY,e);}static _stepCounter=0;static increaseStepCounter(){s._stepCounter++;}static _openedLabels=[];static get openedLabels(){return ce(s._openedLabels)}static set openedLabels(e){s._openedLabels=ce(e);}static _originalOpenedLabels=[];static get originalOpenedLabels(){return ce(s._originalOpenedLabels)}static set originalOpenedLabels(e){s._originalOpenedLabels=ce(e);}static get _currentLabel(){if(s.currentLabelId)return le.get(s.currentLabelId)}static get currentLabelId(){if(s._openedLabels.length>0)return s._openedLabels[s._openedLabels.length-1].label}static get currentLabelStepIndex(){return s._openedLabels.length>0?s._openedLabels[s._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let n=s.allOpenedLabels,i=s.allOpenedLabels[e]?.biggestStep||0,a=s.allOpenedLabels[e]?.openCount||0;(!i||i<t)&&(n[e]={biggestStep:t,openCount:a},s.allOpenedLabels=n);}static addChoicesMade(e,t,n,i){let a=s.allChoicesMade,o=a.findIndex(p=>p.labelId===e&&p.stepIndex===t&&p.choiceIndex===i&&p.stepSha1===n);o<0?a.push({labelId:e,stepIndex:t,choiceIndex:i,stepSha1:n,madeTimes:1}):a[o].madeTimes++,s.allChoicesMade=a;}static pushNewLabel(e){if(!le.get(e))throw new core.PixiError("unregistered_element",`Label ${e} not found`);s._openedLabels.push({label:e,currentStepIndex:0});let n=s.allOpenedLabels,i=s.allOpenedLabels[e]?.biggestStep||0,a=s.allOpenedLabels[e]?.openCount||0;n[e]={biggestStep:i,openCount:a+1},s.allOpenedLabels=n;}static increaseCurrentStepIndex(){if(s._openedLabels.length>0){let e=s._openedLabels[s._openedLabels.length-1];s._openedLabels[s._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static _onStepStart;static set onStepStart(e){s._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let n=[];return s.onLoadingLabel&&e===0&&n.push(s.onLoadingLabel(e,t)),s._onStepStart&&n.push(s._onStepStart(e,t)),await Promise.all(n)}}static onLoadingLabel;static onStepEnd;static onLabelStarting;static onLabelClosing};var De=class{get currentStepTimesCounter(){return b.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){b.resetCurrentStepTimesCounter();}getRandomNumber(e,t,n={}){return b.getRandomNumber(e,t,n)}get stepCounter(){return b._stepCounter}get openedLabels(){return b.openedLabels}get currentLabel(){return b._currentLabel}addStepHistory(e,t={}){let{choiceMade:n,ignoreSameStep:i}=t,a,o,p,c=core.GameUnifier.getVariable(O,I.LAST_STEP_GLUED)===this.stepCounter;core.GameUnifier.getVariable(O,I.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=core.GameUnifier.getVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY)),core.GameUnifier.getVariable(O,I.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(o=core.GameUnifier.getVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY)),core.GameUnifier.getVariable(O,I.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(p=core.GameUnifier.getVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY));let y=b.openedLabels,h={currentLabel:b.currentLabelId,dialogue:a,choices:o,stepSha1:e,index:this.stepCounter,labelStepIndex:b.currentLabelStepIndex,choiceIndexMade:n,inputValue:p,...this.isRequiredInput?{isRequiredInput:true}:{},alreadyMadeChoices:this.getAlreadyMadeChoicesForSha(e),isGlued:c,openedLabels:y};b.originalOpenedLabels=y,core.GameUnifier.addHistoryItem(h,{ignoreSameStep:i}),b.lastHistoryStep=h,b.increaseStepCounter();}getAlreadyMadeChoicesForSha(e){let t=b.currentLabelStepIndex,n=this.currentLabel;if(!(t===null||!n))return b.allChoicesMade.filter(i=>i.labelId===n.id&&i.stepIndex===t&&i.stepSha1===e).map(i=>i.choiceIndex)}closeCurrentLabel(){if(!b.currentLabelId){L.warn("No label to close");return}if(!this.currentLabel){L.error("currentLabel not found");return}let e=b.openedLabels;e.pop(),b.openedLabels=e,core.GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;b.openedLabels.length>0;)this.closeCurrentLabel(),core.GameUnifier.onLabelClosing(this.openedLabels.length);}labels={get opened(){return b.openedLabels},get current(){return b._currentLabel},closeCurrent:()=>this.closeCurrentLabel(),closeAll:()=>this.closeAllLabels()};isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let i=b.allOpenedLabels[t]?.biggestStep||0;if(i){let a=le.get(t);if(a)return a.stepCount<=i}return false}get alreadyCurrentStepMadeChoicesObj(){let e=b.currentLabelStepIndex,t=this.currentLabel;if(e===null||!t)return;let n=t.getStepSha(e);return n||(L.warn("stepSha not found, setting to ERROR"),n="error"),b.allChoicesMade.filter(i=>i.labelId===t?.id&&i.stepIndex===e&&i.stepSha1===n)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=b.currentLabelId;if(e){let t=b.allOpenedLabels[e]?.openCount||0;if(b.currentLabelStepIndex&&t>=b.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return b.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}queries=(()=>{let e=this;return {isLabelAlreadyCompleted:t=>e.isLabelAlreadyCompleted(t),get alreadyCurrentStepMadeChoices(){return e.alreadyCurrentStepMadeChoices},get isCurrentStepAlreadyOpened(){return e.isCurrentStepAlreadyOpened},timesLabelOpened:t=>e.getTimesLabelOpened(t),timesChoiceMade:t=>e.getTimesChoiceMade(t)}})();addCurrentStepToHistory(){this.addStepHistory("dev",{ignoreSameStep:true});}getCanContinue(e){let t=e?.showWarn||false,n=this.choicesValue;return n&&n.length>0?(t&&L.warn("The player must make a choice"),false):this.isRequiredInput?(t&&L.warn("The player must enter a value"),false):true}get canContinue(){return core.GameUnifier.runningStepsCount!==0||this.openedLabels.length===0?false:this.getCanContinue()}async onStepStart(e,t){let n=[];return e.onStepStart&&n.push(e.onStepStart(t,e)),b.onStepStart&&n.push(b.onStepStart(t,e)),await Promise.all(n)}async onStepEnd(e,t){let n=[];return e.onStepEnd&&n.push(e.onStepEnd(t,e)),b.onStepEnd&&n.push(b.onStepEnd(t,e)),await Promise.all(n)}async continue(e,t={}){let{runNow:n=false,steps:i=1}=t;if(!Number.isFinite(i)){L.warn(`[continue] The parameter steps must be a valid finite number, received: ${i}`);return}if(i<=0){L.warn(`[continue] The parameter steps must be greater than 0, received: ${i}`);return}if(!n&&!this.getCanContinue({showWarn:true}))return;if(!n&&core.GameUnifier.runningStepsCount!==0){core.GameUnifier.increaseContinueRequest(i);return}i>1&&core.GameUnifier.increaseContinueRequest(i-1),core.GameUnifier.runningStepsCount++;let a;try{core.GameUnifier.runningStepsCount===1&&await core.GameUnifier.onPreContinue(),b.increaseCurrentStepIndex(),a=await this.runCurrentStep(e,t);}catch(o){throw L.error("Error continuing",o),o}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e)||a}async afterRunCurrentStep(e){if(core.GameUnifier.runningStepsCount===0&&core.GameUnifier.continueRequestsCount!==0)return await core.GameUnifier.processNavigationRequests(e);if(this.openedLabels.length===0){if(core.GameUnifier.onEnd)return await core.GameUnifier.onEnd(e,{labelId:"end"});L.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e,t={}){let{choiceMade:n}=t;if(b.currentLabelId){let i=b.currentLabelStepIndex;if(i===null){L.error("currentLabelStepIndex is null");return}let a=b._currentLabel;if(!a){L.error("currentLabel not found");return}if(a.stepCount>i){try{await this.onStepStart(a,i);}catch(h){L.error("Error running onStepStart",h),this.onStepError&&await this.onStepError(h,e);return}let o=a.getStepById(i);if(!o){L.error("step not found");return}let p=a.getStepSha(i);p||(L.warn("stepSha not found, setting to ERROR"),p="error");let c,y;try{c=await o(e,{labelId:a.id});}catch(h){L.error("Error running step",h),y=h;}try{let h=this.choicesValue;if(h?.length===1&&h[0].autoSelect){let g=h[0];c=await this.selectChoice(g,e);}}catch(h){L.error("Error auto-selecting choice",h),y||(y=h);}try{let h=b.lastHistoryStep;n!==void 0&&h&&(p=h.stepSha1,p||(L.warn("stepSha not found, setting to ERROR"),p="error"),b.addChoicesMade(h.currentLabel||"error",typeof h.labelStepIndex=="number"?h.labelStepIndex:-1,h.stepSha1||"error",n),b.choiceMadeTemp=n);}catch(h){L.warn("Error adding choice made to history",h);}try{core.GameUnifier.runningStepsCount===1&&(b.addLabelHistory(a.id,i),this.addStepHistory(p,{...t,choiceMade:b.choiceMadeTemp}),b.choiceMadeTemp=void 0);}catch(h){L.warn("Error adding step to history",h);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,b.currentLabelStepIndex||0);}catch(h){L.warn("Error running onStepEnd",h);}return y&&this.onStepError&&await this.onStepError(y,e),c}else if(this.openedLabels.length>=1)return await this.closeLabel(a.id,e,t)}else {if(this.openedLabels.length===0)return;L.error("currentLabelId not found");}}async closeLabel(e,t,n){let i=async()=>(this.closeCurrentLabel(),await this.continue(t,n));return b.onLabelClosing?await b.onLabelClosing(e,t,i):await i()}async startLabel(e,t,n){let i=async()=>{let{choiceMade:a,closeCurrentLabel:o,type:p}=n;o&&this.openedLabels.length>0&&this.closeCurrentLabel(),core.GameUnifier.runningStepsCount++;let c;try{let y=le.get(e);if(!y)throw new core.PixiError("unregistered_element",`Label ${e} not found`);b.pushNewLabel(y.id),c=await this.runCurrentStep(t,{choiceMade:a});}catch(y){throw L.error(`Error ${p} label`,y),y}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||c};return b.onLabelStarting?await b.onLabelStarting(e,t,n,i):await i()}async call(e,t,n){let{choiceMade:i}=n||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:i,type:"calling"})}async jump(e,t,n){if(this.stepCounter===0)return await this.call(e,t,n);let{choiceMade:i}=n||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:i,closeCurrentLabel:true,type:"jumping to"})}async selectChoice(e,t){this.choicesValue=void 0;let n=e.type;switch(n){case "call":return await this.call(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "jump":return await this.jump(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "close":return await this.closeChoiceMenu(e,{...e.props,...t});default:throw L.error(`Type ${n} not found`),new core.PixiError("invalid_usage",`Type ${n} not found`)}}async closeChoiceMenu(e,t){if(e.type!=="close")throw L.error("For closeChoiceMenu, the type must be close"),new core.PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let n;return typeof e.choiceIndex=="number"&&(n=e.choiceIndex),e.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:n})}get onStepError(){return async(e,t)=>{try{await core.GameUnifier.runOnError(e,t);}catch(n){L.error("Error in onError handler",n);}}}get dialogue(){let e=core.GameUnifier.getVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?core.GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e){if(e===void 0){core.GameUnifier.setVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e=="string"||Array.isArray(e))&&(e={text:e}),this.dialogGlue){let t=core.GameUnifier.getVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let n=[];Array.isArray(t.text)?n=[...t.text]:n=[t.text],Array.isArray(e.text)?n=[...n,...e.text]:n=[...n,e.text],e.text=n,e.character=e.character||t.character;}core.GameUnifier.setVariable(O,I.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{core.GameUnifier.setVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY,ce({...e,character:typeof e.character=="string"?e.character:e.character?.id})),core.GameUnifier.setVariable(O,I.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw L.error("DialogueInterface cannot contain functions or classes"),new core.PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choicesValue(){let e=core.GameUnifier.getVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],n=e.map((a,o)=>({...a,choiceIndex:o})),i=this.alreadyCurrentStepMadeChoices;if(n=n.filter((a,o)=>a.oneTime&&i?.includes(o)?false:a.onlyHaveNoChoice?(t.push(a),false):true),n.length>0)return n;if(t.length>0)return [t[0]]}}set choicesValue(e){if(!e||e.length===0){core.GameUnifier.setVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{core.GameUnifier.setVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY,ce(e)),core.GameUnifier.setVariable(O,I.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw L.error("ChoiceInterface cannot contain functions or classes"),new core.PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}choicesObj=(()=>{let e=this,t={select:(n,i)=>e.selectChoice(n,i)};return Object.defineProperty(t,"list",{get:()=>e.choicesValue,set:n=>{e.choicesValue=n;},enumerable:true}),t})();get choices(){return this.choicesObj}set choices(e){this.choicesValue=e;}get dialogGlue(){return core.GameUnifier.getFlag(I.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){core.GameUnifier.setFlag(I.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return core.GameUnifier.getVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),core.GameUnifier.setVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY,e),core.GameUnifier.setVariable(O,I.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return core.GameUnifier.getVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return core.GameUnifier.getVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e={},t){e.isRequired=true,core.GameUnifier.setVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?core.GameUnifier.setVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY,t):core.GameUnifier.removeVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){core.GameUnifier.removeVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY),core.GameUnifier.removeVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY);}input=(()=>{let e=this;return {get value(){return e.inputValue},set value(t){e.inputValue=t;},get isRequired(){return e.isRequiredInput},get type(){return e.inputType},request:(t,n)=>e.requestInput(t,n),removeRequest:()=>e.removeInputRequest()}})();clear(){b.openedLabels=[],b._stepCounter=0;}export(){return {openedLabels:ce(b.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async n=>{let i=[],a=le.get(n.label);return a&&(a.onLoadingLabel&&i.push(a.onLoadingLabel(e,a)),b.onLoadingLabel&&i.push(b.onLoadingLabel(e,a))),await Promise.all(i)});return await Promise.all(t)}async restore(e,t){this.clear();try{b.lastHistoryStep=t,Object.hasOwn(e,"openedLabels")?(b.openedLabels=e.openedLabels,b.originalOpenedLabels=b.openedLabels):L.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e,"stepCounter")?b._stepCounter=e.stepCounter:L.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(b.currentLabelStepIndex||0);}catch(n){L.error("Error running onLoadingLabel",n);}}catch(n){L.error("Error importing data",n);}}};function xt(s,e,t,n){let i=typeof e=="string"?e:e.id;return {...n,label:i,props:t,text:s,type:n?.type||"call"}}var pt="close";function At(s,e){return {...e,type:pt,text:s}}var ft=Ct(dt());var ve=class{constructor(e,t){this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}id;_onStepStart;get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}_onLoadingLabel;get onLoadingLabel(){return this._onLoadingLabel}_onStepEnd;get onStepEnd(){return this._onStepEnd}};var we=class extends ve{get stepCount(){return this.steps.length}getStepById(e){return this.steps[e]}constructor(e,t,n){super(e,n),this._steps=t;}_steps;get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(e){let t=this.steps;if(e<0||e>=t.length)return typeof this._steps!="function"&&L.warn("stepSha not found, setting to ERROR"),"error";try{return (0,ft.default)(t[e].toString().toLocaleLowerCase()).toString()}catch(n){return L.warn("stepSha not found, setting to ERROR",n),"error"}}};function bt(s,e,t){let n=new we(s,e,t);return le.add(n),n}var Cr=new De;
|
|
1
|
+
'use strict';var core=require('@drincs/pixi-vn/core');var yt=Object.create;var We=Object.defineProperty;var St=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Je=s=>{throw TypeError(s)};var Tt=(s,e,t)=>e in s?We(s,e,{enumerable:true,configurable:true,writable:true,value:t}):s[e]=t;var Be=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var Ze=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var _t=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of mt(e))!Lt.call(s,i)&&i!==t&&We(s,i,{get:()=>e[i],enumerable:!(n=St(e,i))||n.enumerable});return s};var Ct=(s,e,t)=>(t=s!=null?yt(gt(s)):{},_t(We(t,"default",{value:s,enumerable:true}),s));var z=(s,e,t)=>Tt(s,typeof e!="symbol"?e+"":e,t),je=(s,e,t)=>e.has(s)||Je("Cannot "+t);var r=(s,e,t)=>(je(s,e,"read from private field"),t?t.call(s):e.get(s)),v=(s,e,t)=>e.has(s)?Je("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),S=(s,e,t,n)=>(je(s,e,"write to private field"),e.set(s,t),t),f=(s,e,t)=>(je(s,e,"access private method"),t);var Ue=(s,e,t,n)=>({set _(i){S(s,e,i);},get _(){return r(s,e,n)}});var ut=Ze((ze,ct)=>{(function(s,e){typeof ze=="object"?ct.exports=ze=e():typeof define=="function"&&define.amd?define([],e):s.CryptoJS=e();})(ze,function(){var s=s||(function(e,t){var n;if(typeof window<"u"&&window.crypto&&(n=window.crypto),typeof self<"u"&&self.crypto&&(n=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(n=globalThis.crypto),!n&&typeof window<"u"&&window.msCrypto&&(n=window.msCrypto),!n&&typeof global<"u"&&global.crypto&&(n=global.crypto),!n&&typeof Be=="function")try{n=Be("crypto");}catch{}var i=function(){if(n){if(typeof n.getRandomValues=="function")try{return n.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof n.randomBytes=="function")try{return n.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||(function(){function l(){}return function(d){var E;return l.prototype=d,E=new l,l.prototype=null,E}})(),o={},p=o.lib={},c=p.Base=(function(){return {extend:function(l){var d=a(this);return l&&d.mixIn(l),(!d.hasOwnProperty("init")||this.init===d.init)&&(d.init=function(){d.$super.init.apply(this,arguments);}),d.init.prototype=d,d.$super=this,d},create:function(){var l=this.extend();return l.init.apply(l,arguments),l},init:function(){},mixIn:function(l){for(var d in l)l.hasOwnProperty(d)&&(this[d]=l[d]);l.hasOwnProperty("toString")&&(this.toString=l.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),y=p.WordArray=c.extend({init:function(l,d){l=this.words=l||[],d!=t?this.sigBytes=d:this.sigBytes=l.length*4;},toString:function(l){return (l||g).stringify(this)},concat:function(l){var d=this.words,E=l.words,C=this.sigBytes,R=l.sigBytes;if(this.clamp(),C%4)for(var D=0;D<R;D++){var se=E[D>>>2]>>>24-D%4*8&255;d[C+D>>>2]|=se<<24-(C+D)%4*8;}else for(var G=0;G<R;G+=4)d[C+G>>>2]=E[G>>>2];return this.sigBytes+=R,this},clamp:function(){var l=this.words,d=this.sigBytes;l[d>>>2]&=4294967295<<32-d%4*8,l.length=e.ceil(d/4);},clone:function(){var l=c.clone.call(this);return l.words=this.words.slice(0),l},random:function(l){for(var d=[],E=0;E<l;E+=4)d.push(i());return new y.init(d,l)}}),h=o.enc={},g=h.Hex={stringify:function(l){for(var d=l.words,E=l.sigBytes,C=[],R=0;R<E;R++){var D=d[R>>>2]>>>24-R%4*8&255;C.push((D>>>4).toString(16)),C.push((D&15).toString(16));}return C.join("")},parse:function(l){for(var d=l.length,E=[],C=0;C<d;C+=2)E[C>>>3]|=parseInt(l.substr(C,2),16)<<24-C%8*4;return new y.init(E,d/2)}},M=h.Latin1={stringify:function(l){for(var d=l.words,E=l.sigBytes,C=[],R=0;R<E;R++){var D=d[R>>>2]>>>24-R%4*8&255;C.push(String.fromCharCode(D));}return C.join("")},parse:function(l){for(var d=l.length,E=[],C=0;C<d;C++)E[C>>>2]|=(l.charCodeAt(C)&255)<<24-C%4*8;return new y.init(E,d)}},N=h.Utf8={stringify:function(l){try{return decodeURIComponent(escape(M.stringify(l)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(l){return M.parse(unescape(encodeURIComponent(l)))}},P=p.BufferedBlockAlgorithm=c.extend({reset:function(){this._data=new y.init,this._nDataBytes=0;},_append:function(l){typeof l=="string"&&(l=N.parse(l)),this._data.concat(l),this._nDataBytes+=l.sigBytes;},_process:function(l){var d,E=this._data,C=E.words,R=E.sigBytes,D=this.blockSize,se=D*4,G=R/se;l?G=e.ceil(G):G=e.max((G|0)-this._minBufferSize,0);var Q=G*D,Le=e.min(Q*4,R);if(Q){for(var Ke=0;Ke<Q;Ke+=D)this._doProcessBlock(C,Ke);d=C.splice(0,Q),E.sigBytes-=Le;}return new y.init(d,Le)},clone:function(){var l=c.clone.call(this);return l._data=this._data.clone(),l},_minBufferSize:0});p.Hasher=P.extend({cfg:c.extend(),init:function(l){this.cfg=this.cfg.extend(l),this.reset();},reset:function(){P.reset.call(this),this._doReset();},update:function(l){return this._append(l),this._process(),this},finalize:function(l){l&&this._append(l);var d=this._doFinalize();return d},blockSize:512/32,_createHelper:function(l){return function(d,E){return new l.init(E).finalize(d)}},_createHmacHelper:function(l){return function(d,E){return new _.HMAC.init(l,E).finalize(d)}}});var _=o.algo={};return o})(Math);return s});});var dt=Ze((He,ht)=>{(function(s,e){typeof He=="object"?ht.exports=He=e(ut()):typeof define=="function"&&define.amd?define(["./core"],e):e(s.CryptoJS);})(He,function(s){return (function(){var e=s,t=e.lib,n=t.WordArray,i=t.Hasher,a=e.algo,o=[],p=a.SHA1=i.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(c,y){for(var h=this._hash.words,g=h[0],M=h[1],N=h[2],P=h[3],w=h[4],_=0;_<80;_++){if(_<16)o[_]=c[y+_]|0;else {var l=o[_-3]^o[_-8]^o[_-14]^o[_-16];o[_]=l<<1|l>>>31;}var d=(g<<5|g>>>27)+w+o[_];_<20?d+=(M&N|~M&P)+1518500249:_<40?d+=(M^N^P)+1859775393:_<60?d+=(M&N|M&P|N&P)-1894007588:d+=(M^N^P)-899497514,w=P,P=N,N=M<<30|M>>>2,M=g,g=d;}h[0]=h[0]+g|0,h[1]=h[1]+M|0,h[2]=h[2]+N|0,h[3]=h[3]+P|0,h[4]=h[4]+w|0;},_doFinalize:function(){var c=this._data,y=c.words,h=this._nDataBytes*8,g=c.sigBytes*8;return y[g>>>5]|=128<<24-g%32,y[(g+64>>>9<<4)+14]=Math.floor(h/4294967296),y[(g+64>>>9<<4)+15]=h,c.sigBytes=y.length*4,this._process(),this._hash},clone:function(){var c=i.clone.call(this);return c._hash=this._hash.clone(),c}});e.SHA1=i._createHelper(p),e.HmacSHA1=i._createHmacHelper(p);})(),s.SHA1});});var O="narration";var I={CURRENT_DIALOGUE_MEMORY_KEY:"dialogue",LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY:"dialogue:step_counter",CURRENT_MENU_OPTIONS_MEMORY_KEY:"choice:options",LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY:"choice:step_counter",CURRENT_INPUT_VALUE_MEMORY_KEY:"input:value",LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY:"input:step_counter",CURRENT_INPUT_INFO_MEMORY_KEY:"input:info",CHARACTER_CATEGORY_KEY:"character",ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY:"___glue___",OPENED_LABELS_COUNTER_KEY:"label:opened",ALL_CHOICES_MADE_KEY:"choices:made",CURRENT_STEP_TIMES_COUNTER_KEY:"label:history",LAST_STEP_GLUED:"glue:last_step"};var Et=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,nt=new Set,ke=typeof process=="object"&&process?process:{},it=(s,e,t,n)=>{typeof ke.emitWarning=="function"?ke.emitWarning(s,e,t,n):console.error(`[${t}] ${e}: ${s}`);},Ge=globalThis.AbortController,et=globalThis.AbortSignal;if(typeof Ge>"u"){et=class{onabort;_onabort=[];reason;aborted=false;addEventListener(t,n){this._onabort.push(n);}},Ge=class{constructor(){e();}signal=new et;abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=true;for(let n of this.signal._onabort)n(t);this.signal.onabort?.(t);}}};let s=ke.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{s&&(s=false,it("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e));};}var It=s=>!nt.has(s);var he=s=>s&&s===Math.floor(s)&&s>0&&isFinite(s),at=s=>he(s)?s<=Math.pow(2,8)?Uint8Array:s<=Math.pow(2,16)?Uint16Array:s<=Math.pow(2,32)?Uint32Array:s<=Number.MAX_SAFE_INTEGER?Ye:null:null,Ye=class extends Array{constructor(s){super(s),this.fill(0);}},oe,Te,Rt=(oe=class{heap;length;static create(e){let t=at(e);if(!t)return [];S(oe,Te,true);let n=new oe(e,t);return S(oe,Te,false),n}constructor(e,t){if(!r(oe,Te))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0;}push(e){this.heap[this.length++]=e;}pop(){return this.heap[--this.length]}},Te=new WeakMap,v(oe,Te,false),oe),tt,rt,X,B,J,Se,Z,_e,Ce,ee,Y,te,U,A,T,K,j,H,V,re,F,ne,ie,k,q,ae,ye,W,Ee,u,qe,me,pe,Ae,$,ot,ge,Ie,Me,de,fe,$e,Ve,Fe,x,Xe,xe,be,Qe,Re,st=(Re=class{constructor(e){v(this,u);v(this,X);v(this,B);v(this,J);v(this,Se);v(this,Z);v(this,_e);v(this,Ce);v(this,ee);z(this,"ttl");z(this,"ttlResolution");z(this,"ttlAutopurge");z(this,"updateAgeOnGet");z(this,"updateAgeOnHas");z(this,"allowStale");z(this,"noDisposeOnSet");z(this,"noUpdateTTL");z(this,"maxEntrySize");z(this,"sizeCalculation");z(this,"noDeleteOnFetchRejection");z(this,"noDeleteOnStaleGet");z(this,"allowStaleOnFetchAbort");z(this,"allowStaleOnFetchRejection");z(this,"ignoreFetchAbort");v(this,Y);v(this,te);v(this,U);v(this,A);v(this,T);v(this,K);v(this,j);v(this,H);v(this,V);v(this,re);v(this,F);v(this,ne);v(this,ie);v(this,k);v(this,q);v(this,ae);v(this,ye);v(this,W);v(this,Ee);v(this,me,()=>{});v(this,pe,()=>{});v(this,Ae,()=>{});v(this,$,()=>false);v(this,ge,e=>{});v(this,Ie,(e,t,n)=>{});v(this,Me,(e,t,n,i)=>{if(n||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});z(this,tt,"LRUCache");let{max:t=0,ttl:n,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:o,updateAgeOnHas:p,allowStale:c,dispose:y,onInsert:h,disposeAfter:g,noDisposeOnSet:M,noUpdateTTL:N,maxSize:P=0,maxEntrySize:w=0,sizeCalculation:_,fetchMethod:l,memoMethod:d,noDeleteOnFetchRejection:E,noDeleteOnStaleGet:C,allowStaleOnFetchRejection:R,allowStaleOnFetchAbort:D,ignoreFetchAbort:se,perf:G}=e;if(G!==void 0&&typeof G?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(S(this,ee,G??Et),t!==0&&!he(t))throw new TypeError("max option must be a nonnegative integer");let Q=t?at(t):Array;if(!Q)throw new Error("invalid max value: "+t);if(S(this,X,t),S(this,B,P),this.maxEntrySize=w||r(this,B),this.sizeCalculation=_,this.sizeCalculation){if(!r(this,B)&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(d!==void 0&&typeof d!="function")throw new TypeError("memoMethod must be a function if defined");if(S(this,Ce,d),l!==void 0&&typeof l!="function")throw new TypeError("fetchMethod must be a function if specified");if(S(this,_e,l),S(this,ye,!!l),S(this,U,new Map),S(this,A,new Array(t).fill(void 0)),S(this,T,new Array(t).fill(void 0)),S(this,K,new Q(t)),S(this,j,new Q(t)),S(this,H,0),S(this,V,0),S(this,re,Rt.create(t)),S(this,Y,0),S(this,te,0),typeof y=="function"&&S(this,J,y),typeof h=="function"&&S(this,Se,h),typeof g=="function"?(S(this,Z,g),S(this,F,[])):(S(this,Z,void 0),S(this,F,void 0)),S(this,ae,!!r(this,J)),S(this,Ee,!!r(this,Se)),S(this,W,!!r(this,Z)),this.noDisposeOnSet=!!M,this.noUpdateTTL=!!N,this.noDeleteOnFetchRejection=!!E,this.allowStaleOnFetchRejection=!!R,this.allowStaleOnFetchAbort=!!D,this.ignoreFetchAbort=!!se,this.maxEntrySize!==0){if(r(this,B)!==0&&!he(r(this,B)))throw new TypeError("maxSize must be a positive integer if specified");if(!he(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");f(this,u,ot).call(this);}if(this.allowStale=!!c,this.noDeleteOnStaleGet=!!C,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!p,this.ttlResolution=he(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=n||0,this.ttl){if(!he(this.ttl))throw new TypeError("ttl must be a positive integer if specified");f(this,u,qe).call(this);}if(r(this,X)===0&&this.ttl===0&&r(this,B)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!r(this,X)&&!r(this,B)){let Le="LRU_CACHE_UNBOUNDED";It(Le)&&(nt.add(Le),it("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Le,Re));}}get perf(){return r(this,ee)}static unsafeExposeInternals(e){return {starts:r(e,ie),ttls:r(e,k),autopurgeTimers:r(e,q),sizes:r(e,ne),keyMap:r(e,U),keyList:r(e,A),valList:r(e,T),next:r(e,K),prev:r(e,j),get head(){return r(e,H)},get tail(){return r(e,V)},free:r(e,re),isBackgroundFetch:t=>{var n;return f(n=e,u,x).call(n,t)},backgroundFetch:(t,n,i,a)=>{var o;return f(o=e,u,Fe).call(o,t,n,i,a)},moveToTail:t=>{var n;return f(n=e,u,xe).call(n,t)},indexes:t=>{var n;return f(n=e,u,de).call(n,t)},rindexes:t=>{var n;return f(n=e,u,fe).call(n,t)},isStale:t=>{var n;return r(n=e,$).call(n,t)}}}get max(){return r(this,X)}get maxSize(){return r(this,B)}get calculatedSize(){return r(this,te)}get size(){return r(this,Y)}get fetchMethod(){return r(this,_e)}get memoMethod(){return r(this,Ce)}get dispose(){return r(this,J)}get onInsert(){return r(this,Se)}get disposeAfter(){return r(this,Z)}getRemainingTTL(e){return r(this,U).has(e)?1/0:0}*entries(){for(let e of f(this,u,de).call(this))r(this,T)[e]!==void 0&&r(this,A)[e]!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield [r(this,A)[e],r(this,T)[e]]);}*rentries(){for(let e of f(this,u,fe).call(this))r(this,T)[e]!==void 0&&r(this,A)[e]!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield [r(this,A)[e],r(this,T)[e]]);}*keys(){for(let e of f(this,u,de).call(this)){let t=r(this,A)[e];t!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield t);}}*rkeys(){for(let e of f(this,u,fe).call(this)){let t=r(this,A)[e];t!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield t);}}*values(){for(let e of f(this,u,de).call(this))r(this,T)[e]!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield r(this,T)[e]);}*rvalues(){for(let e of f(this,u,fe).call(this))r(this,T)[e]!==void 0&&!f(this,u,x).call(this,r(this,T)[e])&&(yield r(this,T)[e]);}[(rt=Symbol.iterator,tt=Symbol.toStringTag,rt)](){return this.entries()}find(e,t={}){for(let n of f(this,u,de).call(this)){let i=r(this,T)[n],a=f(this,u,x).call(this,i)?i.__staleWhileFetching:i;if(a!==void 0&&e(a,r(this,A)[n],this))return this.get(r(this,A)[n],t)}}forEach(e,t=this){for(let n of f(this,u,de).call(this)){let i=r(this,T)[n],a=f(this,u,x).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,r(this,A)[n],this);}}rforEach(e,t=this){for(let n of f(this,u,fe).call(this)){let i=r(this,T)[n],a=f(this,u,x).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,r(this,A)[n],this);}}purgeStale(){let e=false;for(let t of f(this,u,fe).call(this,{allowStale:true}))r(this,$).call(this,t)&&(f(this,u,be).call(this,r(this,A)[t],"expire"),e=true);return e}info(e){let t=r(this,U).get(e);if(t===void 0)return;let n=r(this,T)[t],i=f(this,u,x).call(this,n)?n.__staleWhileFetching:n;if(i===void 0)return;let a={value:i};if(r(this,k)&&r(this,ie)){let o=r(this,k)[t],p=r(this,ie)[t];if(o&&p){let c=o-(r(this,ee).now()-p);a.ttl=c,a.start=Date.now();}}return r(this,ne)&&(a.size=r(this,ne)[t]),a}dump(){let e=[];for(let t of f(this,u,de).call(this,{allowStale:true})){let n=r(this,A)[t],i=r(this,T)[t],a=f(this,u,x).call(this,i)?i.__staleWhileFetching:i;if(a===void 0||n===void 0)continue;let o={value:a};if(r(this,k)&&r(this,ie)){o.ttl=r(this,k)[t];let p=r(this,ee).now()-r(this,ie)[t];o.start=Math.floor(Date.now()-p);}r(this,ne)&&(o.size=r(this,ne)[t]),e.unshift([n,o]);}return e}load(e){this.clear();for(let[t,n]of e){if(n.start){let i=Date.now()-n.start;n.start=r(this,ee).now()-i;}this.set(t,n.value,n);}}set(e,t,n={}){var M,N,P,w;if(t===void 0)return this.delete(e),this;let{ttl:i=this.ttl,start:a,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:p=this.sizeCalculation,status:c}=n,{noUpdateTTL:y=this.noUpdateTTL}=n,h=r(this,Me).call(this,e,t,n.size||0,p);if(this.maxEntrySize&&h>this.maxEntrySize)return c&&(c.set="miss",c.maxEntrySizeExceeded=true),f(this,u,be).call(this,e,"set"),this;let g=r(this,Y)===0?void 0:r(this,U).get(e);if(g===void 0)g=r(this,Y)===0?r(this,V):r(this,re).length!==0?r(this,re).pop():r(this,Y)===r(this,X)?f(this,u,Ve).call(this,false):r(this,Y),r(this,A)[g]=e,r(this,T)[g]=t,r(this,U).set(e,g),r(this,K)[r(this,V)]=g,r(this,j)[g]=r(this,V),S(this,V,g),Ue(this,Y)._++,r(this,Ie).call(this,g,h,c),c&&(c.set="add"),y=false,r(this,Ee)&&((M=r(this,Se))==null||M.call(this,t,e,"add"));else {f(this,u,xe).call(this,g);let _=r(this,T)[g];if(t!==_){if(r(this,ye)&&f(this,u,x).call(this,_)){_.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:l}=_;l!==void 0&&!o&&(r(this,ae)&&((N=r(this,J))==null||N.call(this,l,e,"set")),r(this,W)&&r(this,F)?.push([l,e,"set"]));}else o||(r(this,ae)&&((P=r(this,J))==null||P.call(this,_,e,"set")),r(this,W)&&r(this,F)?.push([_,e,"set"]));if(r(this,ge).call(this,g),r(this,Ie).call(this,g,h,c),r(this,T)[g]=t,c){c.set="replace";let l=_&&f(this,u,x).call(this,_)?_.__staleWhileFetching:_;l!==void 0&&(c.oldValue=l);}}else c&&(c.set="update");r(this,Ee)&&this.onInsert?.(t,e,t===_?"update":"replace");}if(i!==0&&!r(this,k)&&f(this,u,qe).call(this),r(this,k)&&(y||r(this,Ae).call(this,g,i,a),c&&r(this,pe).call(this,c,g)),!o&&r(this,W)&&r(this,F)){let _=r(this,F),l;for(;l=_?.shift();)(w=r(this,Z))==null||w.call(this,...l);}return this}pop(){var e;try{for(;r(this,Y);){let t=r(this,T)[r(this,H)];if(f(this,u,Ve).call(this,!0),f(this,u,x).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(r(this,W)&&r(this,F)){let t=r(this,F),n;for(;n=t?.shift();)(e=r(this,Z))==null||e.call(this,...n);}}}has(e,t={}){let{updateAgeOnHas:n=this.updateAgeOnHas,status:i}=t,a=r(this,U).get(e);if(a!==void 0){let o=r(this,T)[a];if(f(this,u,x).call(this,o)&&o.__staleWhileFetching===void 0)return false;if(r(this,$).call(this,a))i&&(i.has="stale",r(this,pe).call(this,i,a));else return n&&r(this,me).call(this,a),i&&(i.has="hit",r(this,pe).call(this,i,a)),true}else i&&(i.has="miss");return false}peek(e,t={}){let{allowStale:n=this.allowStale}=t,i=r(this,U).get(e);if(i===void 0||!n&&r(this,$).call(this,i))return;let a=r(this,T)[i];return f(this,u,x).call(this,a)?a.__staleWhileFetching:a}async fetch(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:p=this.noDisposeOnSet,size:c=0,sizeCalculation:y=this.sizeCalculation,noUpdateTTL:h=this.noUpdateTTL,noDeleteOnFetchRejection:g=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:M=this.allowStaleOnFetchRejection,ignoreFetchAbort:N=this.ignoreFetchAbort,allowStaleOnFetchAbort:P=this.allowStaleOnFetchAbort,context:w,forceRefresh:_=false,status:l,signal:d}=t;if(!r(this,ye))return l&&(l.fetch="get"),this.get(e,{allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:l});let E={allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:o,noDisposeOnSet:p,size:c,sizeCalculation:y,noUpdateTTL:h,noDeleteOnFetchRejection:g,allowStaleOnFetchRejection:M,allowStaleOnFetchAbort:P,ignoreFetchAbort:N,status:l,signal:d},C=r(this,U).get(e);if(C===void 0){l&&(l.fetch="miss");let R=f(this,u,Fe).call(this,e,C,E,w);return R.__returned=R}else {let R=r(this,T)[C];if(f(this,u,x).call(this,R)){let Q=n&&R.__staleWhileFetching!==void 0;return l&&(l.fetch="inflight",Q&&(l.returnedStale=true)),Q?R.__staleWhileFetching:R.__returned=R}let D=r(this,$).call(this,C);if(!_&&!D)return l&&(l.fetch="hit"),f(this,u,xe).call(this,C),i&&r(this,me).call(this,C),l&&r(this,pe).call(this,l,C),R;let se=f(this,u,Fe).call(this,e,C,E,w),G=se.__staleWhileFetching!==void 0&&n;return l&&(l.fetch=D?"stale":"refresh",G&&D&&(l.returnedStale=true)),G?se.__staleWhileFetching:se.__returned=se}}async forceFetch(e,t={}){let n=await this.fetch(e,t);if(n===void 0)throw new Error("fetch() returned undefined");return n}memo(e,t={}){let n=r(this,Ce);if(!n)throw new Error("no memoMethod provided to constructor");let{context:i,forceRefresh:a,...o}=t,p=this.get(e,o);if(!a&&p!==void 0)return p;let c=n(e,p,{options:o,context:i});return this.set(e,c,o),c}get(e,t={}){let{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,status:o}=t,p=r(this,U).get(e);if(p!==void 0){let c=r(this,T)[p],y=f(this,u,x).call(this,c);return o&&r(this,pe).call(this,o,p),r(this,$).call(this,p)?(o&&(o.get="stale"),y?(o&&n&&c.__staleWhileFetching!==void 0&&(o.returnedStale=true),n?c.__staleWhileFetching:void 0):(a||f(this,u,be).call(this,e,"expire"),o&&n&&(o.returnedStale=true),n?c:void 0)):(o&&(o.get="hit"),y?c.__staleWhileFetching:(f(this,u,xe).call(this,p),i&&r(this,me).call(this,p),c))}else o&&(o.get="miss");}delete(e){return f(this,u,be).call(this,e,"delete")}clear(){return f(this,u,Qe).call(this,"delete")}},X=new WeakMap,B=new WeakMap,J=new WeakMap,Se=new WeakMap,Z=new WeakMap,_e=new WeakMap,Ce=new WeakMap,ee=new WeakMap,Y=new WeakMap,te=new WeakMap,U=new WeakMap,A=new WeakMap,T=new WeakMap,K=new WeakMap,j=new WeakMap,H=new WeakMap,V=new WeakMap,re=new WeakMap,F=new WeakMap,ne=new WeakMap,ie=new WeakMap,k=new WeakMap,q=new WeakMap,ae=new WeakMap,ye=new WeakMap,W=new WeakMap,Ee=new WeakMap,u=new WeakSet,qe=function(){let e=new Ye(r(this,X)),t=new Ye(r(this,X));S(this,k,e),S(this,ie,t);let n=this.ttlAutopurge?new Array(r(this,X)):void 0;S(this,q,n),S(this,Ae,(p,c,y=r(this,ee).now())=>{t[p]=c!==0?y:0,e[p]=c,i(p,c);}),S(this,me,p=>{t[p]=e[p]!==0?r(this,ee).now():0,i(p,e[p]);});let i=this.ttlAutopurge?(p,c)=>{if(n?.[p]&&(clearTimeout(n[p]),n[p]=void 0),c&&c!==0&&n){let y=setTimeout(()=>{r(this,$).call(this,p)&&f(this,u,be).call(this,r(this,A)[p],"expire");},c+1);y.unref&&y.unref(),n[p]=y;}}:()=>{};S(this,pe,(p,c)=>{if(e[c]){let y=e[c],h=t[c];if(!y||!h)return;p.ttl=y,p.start=h,p.now=a||o();let g=p.now-h;p.remainingTTL=y-g;}});let a=0,o=()=>{let p=r(this,ee).now();if(this.ttlResolution>0){a=p;let c=setTimeout(()=>a=0,this.ttlResolution);c.unref&&c.unref();}return p};this.getRemainingTTL=p=>{let c=r(this,U).get(p);if(c===void 0)return 0;let y=e[c],h=t[c];if(!y||!h)return 1/0;let g=(a||o())-h;return y-g},S(this,$,p=>{let c=t[p],y=e[p];return !!y&&!!c&&(a||o())-c>y});},me=new WeakMap,pe=new WeakMap,Ae=new WeakMap,$=new WeakMap,ot=function(){let e=new Ye(r(this,X));S(this,te,0),S(this,ne,e),S(this,ge,t=>{S(this,te,r(this,te)-e[t]),e[t]=0;}),S(this,Me,(t,n,i,a)=>{if(f(this,u,x).call(this,n))return 0;if(!he(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(n,t),!he(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return i}),S(this,Ie,(t,n,i)=>{if(e[t]=n,r(this,B)){let a=r(this,B)-e[t];for(;r(this,te)>a;)f(this,u,Ve).call(this,true);}S(this,te,r(this,te)+e[t]),i&&(i.entrySize=n,i.totalCalculatedSize=r(this,te));});},ge=new WeakMap,Ie=new WeakMap,Me=new WeakMap,de=function*({allowStale:e=this.allowStale}={}){if(r(this,Y))for(let t=r(this,V);!(!f(this,u,$e).call(this,t)||((e||!r(this,$).call(this,t))&&(yield t),t===r(this,H)));)t=r(this,j)[t];},fe=function*({allowStale:e=this.allowStale}={}){if(r(this,Y))for(let t=r(this,H);!(!f(this,u,$e).call(this,t)||((e||!r(this,$).call(this,t))&&(yield t),t===r(this,V)));)t=r(this,K)[t];},$e=function(e){return e!==void 0&&r(this,U).get(r(this,A)[e])===e},Ve=function(e){var a;let t=r(this,H),n=r(this,A)[t],i=r(this,T)[t];return r(this,ye)&&f(this,u,x).call(this,i)?i.__abortController.abort(new Error("evicted")):(r(this,ae)||r(this,W))&&(r(this,ae)&&((a=r(this,J))==null||a.call(this,i,n,"evict")),r(this,W)&&r(this,F)?.push([i,n,"evict"])),r(this,ge).call(this,t),r(this,q)?.[t]&&(clearTimeout(r(this,q)[t]),r(this,q)[t]=void 0),e&&(r(this,A)[t]=void 0,r(this,T)[t]=void 0,r(this,re).push(t)),r(this,Y)===1?(S(this,H,S(this,V,0)),r(this,re).length=0):S(this,H,r(this,K)[t]),r(this,U).delete(n),Ue(this,Y)._--,t},Fe=function(e,t,n,i){let a=t===void 0?void 0:r(this,T)[t];if(f(this,u,x).call(this,a))return a;let o=new Ge,{signal:p}=n;p?.addEventListener("abort",()=>o.abort(p.reason),{signal:o.signal});let c={signal:o.signal,options:n,context:i},y=(w,_=false)=>{let{aborted:l}=o.signal,d=n.ignoreFetchAbort&&w!==void 0,E=n.ignoreFetchAbort||!!(n.allowStaleOnFetchAbort&&w!==void 0);if(n.status&&(l&&!_?(n.status.fetchAborted=true,n.status.fetchError=o.signal.reason,d&&(n.status.fetchAbortIgnored=true)):n.status.fetchResolved=true),l&&!d&&!_)return g(o.signal.reason,E);let C=N,R=r(this,T)[t];return (R===N||d&&_&&R===void 0)&&(w===void 0?C.__staleWhileFetching!==void 0?r(this,T)[t]=C.__staleWhileFetching:f(this,u,be).call(this,e,"fetch"):(n.status&&(n.status.fetchUpdated=true),this.set(e,w,c.options))),w},h=w=>(n.status&&(n.status.fetchRejected=true,n.status.fetchError=w),g(w,false)),g=(w,_)=>{let{aborted:l}=o.signal,d=l&&n.allowStaleOnFetchAbort,E=d||n.allowStaleOnFetchRejection,C=E||n.noDeleteOnFetchRejection,R=N;if(r(this,T)[t]===N&&(!C||!_&&R.__staleWhileFetching===void 0?f(this,u,be).call(this,e,"fetch"):d||(r(this,T)[t]=R.__staleWhileFetching)),E)return n.status&&R.__staleWhileFetching!==void 0&&(n.status.returnedStale=true),R.__staleWhileFetching;if(R.__returned===R)throw w},M=(w,_)=>{var d;let l=(d=r(this,_e))==null?void 0:d.call(this,e,a,c);l&&l instanceof Promise&&l.then(E=>w(E===void 0?void 0:E),_),o.signal.addEventListener("abort",()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(w(void 0),n.allowStaleOnFetchAbort&&(w=E=>y(E,true)));});};n.status&&(n.status.fetchDispatched=true);let N=new Promise(M).then(y,h),P=Object.assign(N,{__abortController:o,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,P,{...c.options,status:void 0}),t=r(this,U).get(e)):r(this,T)[t]=P,P},x=function(e){if(!r(this,ye))return false;let t=e;return !!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof Ge},Xe=function(e,t){r(this,j)[t]=e,r(this,K)[e]=t;},xe=function(e){e!==r(this,V)&&(e===r(this,H)?S(this,H,r(this,K)[e]):f(this,u,Xe).call(this,r(this,j)[e],r(this,K)[e]),f(this,u,Xe).call(this,r(this,V),e),S(this,V,e));},be=function(e,t){var i,a;let n=false;if(r(this,Y)!==0){let o=r(this,U).get(e);if(o!==void 0)if(r(this,q)?.[o]&&(clearTimeout(r(this,q)?.[o]),r(this,q)[o]=void 0),n=true,r(this,Y)===1)f(this,u,Qe).call(this,t);else {r(this,ge).call(this,o);let p=r(this,T)[o];if(f(this,u,x).call(this,p)?p.__abortController.abort(new Error("deleted")):(r(this,ae)||r(this,W))&&(r(this,ae)&&((i=r(this,J))==null||i.call(this,p,e,t)),r(this,W)&&r(this,F)?.push([p,e,t])),r(this,U).delete(e),r(this,A)[o]=void 0,r(this,T)[o]=void 0,o===r(this,V))S(this,V,r(this,j)[o]);else if(o===r(this,H))S(this,H,r(this,K)[o]);else {let c=r(this,j)[o];r(this,K)[c]=r(this,K)[o];let y=r(this,K)[o];r(this,j)[y]=r(this,j)[o];}Ue(this,Y)._--,r(this,re).push(o);}}if(r(this,W)&&r(this,F)?.length){let o=r(this,F),p;for(;p=o?.shift();)(a=r(this,Z))==null||a.call(this,...p);}return n},Qe=function(e){var t,n;for(let i of f(this,u,fe).call(this,{allowStale:true})){let a=r(this,T)[i];if(f(this,u,x).call(this,a))a.__abortController.abort(new Error("deleted"));else {let o=r(this,A)[i];r(this,ae)&&((t=r(this,J))==null||t.call(this,a,o,e)),r(this,W)&&r(this,F)?.push([a,o,e]);}}if(r(this,U).clear(),r(this,T).fill(void 0),r(this,A).fill(void 0),r(this,k)&&r(this,ie)){r(this,k).fill(0),r(this,ie).fill(0);for(let i of r(this,q)??[])i!==void 0&&clearTimeout(i);r(this,q)?.fill(void 0);}if(r(this,ne)&&r(this,ne).fill(0),S(this,H,0),S(this,V,0),r(this,re).length=0,S(this,te,0),S(this,Y,0),r(this,W)&&r(this,F)){let i=r(this,F),a;for(;a=i?.shift();)(n=r(this,Z))==null||n.call(this,...a);}},Re);var Ne=class{cache;map=new Map;constructor(e){this.cache=new st({max:e.cacheSize}),this.map=new Map;}get[Symbol.iterator](){return this.map[Symbol.iterator]}get[Symbol.toStringTag](){return this.map[Symbol.toStringTag]}clear(){this.cache.clear(),this.map.clear();}delete(e){let t=this.map.delete(e);return t&&this.cache.delete(e),t}get forEach(){return this.map.forEach}get(e){let t=this.cache.get(e);return t||this.map.get(e)}has(e){return this.map.has(e)}set(e,t){return this.map.set(e,t),this.cache.set(e,t),this}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}};var L;(i=>(i.log=(a,...o)=>console.log(`[Pixi\u2019VN] ${a}`,...o),i.warn=(a,...o)=>console.warn(`[Pixi\u2019VN] ${a}`,...o),i.error=(a,...o)=>console.error(`[Pixi\u2019VN] ${a}`,...o),i.info=(a,...o)=>console.info(`[Pixi\u2019VN] ${a}`,...o)))(L||={});var Oe=new Ne({cacheSize:10}),lt;(o=>{function s(p){let c=Oe.get(p);if(!c){L.error(`Label "${p}" not found`);return}return c}o.get=s;function e(...p){for(let c of p)Oe.set(c.id,c);}o.add=e;function t(){return Array.from(Oe.values())}o.values=t;function n(p){return Oe.has(p)}o.has=n;function i(){return Array.from(Oe.keys())}o.keys=i;function a(){Oe.clear();}o.clear=a;})(lt||={});var le=lt;function ce(s){try{if(typeof s>"u")return s;let e=JSON.stringify(s);return JSON.parse(e)}catch(e){throw L.error("Error creating exportable element",s,e),new core.PixiError("not_json_serializable","Error creating exportable element")}}var b=class s{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return core.GameUnifier.getVariable(O,I.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){core.GameUnifier.setVariable(O,I.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e=""){let t=s.currentLabelStepIndex;if(t===null)return L.error("currentLabelStepIndex is null"),null;let n=`${t}${e}`,i=s.currentLabelId,a=s._currentLabel;if(!i||t===null||!a)return L.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let o=a.getStepSha(t)||"error",p=core.GameUnifier.getVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return p[i]||(p[i]={}),(!p[i][n]||p[i][n].stepSha1!==o)&&(p[i][n]={stepSha1:o}),p[i][n]}static setCurrentStepTimesCounterData(e="",t){let n=s.currentLabelStepIndex,i=n+e,a=s.currentLabelId;if(!a||n===null){L.error("currentLabelId or currentLabelStepIndex is null");return}let o=core.GameUnifier.getVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};o[a]||(o[a]={}),o[a][i]=t,core.GameUnifier.setVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY,o);}static getCurrentStepTimesCounter(e=""){let t=s._stepCounter,n=s.getCurrentStepTimesCounterData(e);if(!n)return L.error("getCurrentStepTimesCounter obj is null"),0;let i=n.stepCounters||[];return i.find(o=>o===t)||(i.push(t),n.stepCounters=i,s.setCurrentStepTimesCounterData(e,n)),i.length}static getRandomNumber(e,t,n={}){let i=n.nestedId||"";if(n.onceOnly||false){let o=s.getCurrentStepTimesCounterData(i);if(!o)return;let p=o.usedRandomNumbers||{},c=Array.from({length:t-e+1},(g,M)=>M+e).filter(g=>!p[`${e}-${t}`]?.includes(g));if(c.length===0)return;let y=Math.floor(Math.random()*c.length),h=c[y];return p[`${e}-${t}`]||(p[`${e}-${t}`]=[]),p[`${e}-${t}`].push(h),o.usedRandomNumbers=p,s.setCurrentStepTimesCounterData(i,o),h}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e=""){let t=s.currentLabelStepIndex,n=t+e,i=s.currentLabelId;if(!i||t===null){L.error("currentLabelId or currentLabelStepIndex is null");return}let a=core.GameUnifier.getVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[i]||(a[i]={}),a[i][n]={stepCounters:[],stepSha1:""},core.GameUnifier.setVariable(O,I.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return core.GameUnifier.getVariable(O,I.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){core.GameUnifier.setVariable(O,I.ALL_CHOICES_MADE_KEY,e);}static _stepCounter=0;static increaseStepCounter(){s._stepCounter++;}static _openedLabels=[];static get openedLabels(){return ce(s._openedLabels)}static set openedLabels(e){s._openedLabels=ce(e);}static _originalOpenedLabels=[];static get originalOpenedLabels(){return ce(s._originalOpenedLabels)}static set originalOpenedLabels(e){s._originalOpenedLabels=ce(e);}static get _currentLabel(){if(s.currentLabelId)return le.get(s.currentLabelId)}static get currentLabelId(){if(s._openedLabels.length>0)return s._openedLabels[s._openedLabels.length-1].label}static get currentLabelStepIndex(){return s._openedLabels.length>0?s._openedLabels[s._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let n=s.allOpenedLabels,i=s.allOpenedLabels[e]?.biggestStep||0,a=s.allOpenedLabels[e]?.openCount||0;(!i||i<t)&&(n[e]={biggestStep:t,openCount:a},s.allOpenedLabels=n);}static addChoicesMade(e,t,n,i){let a=s.allChoicesMade,o=a.findIndex(p=>p.labelId===e&&p.stepIndex===t&&p.choiceIndex===i&&p.stepSha1===n);o<0?a.push({labelId:e,stepIndex:t,choiceIndex:i,stepSha1:n,madeTimes:1}):a[o].madeTimes++,s.allChoicesMade=a;}static pushNewLabel(e){if(!le.get(e))throw new core.PixiError("unregistered_element",`Label ${e} not found`);s._openedLabels.push({label:e,currentStepIndex:0});let n=s.allOpenedLabels,i=s.allOpenedLabels[e]?.biggestStep||0,a=s.allOpenedLabels[e]?.openCount||0;n[e]={biggestStep:i,openCount:a+1},s.allOpenedLabels=n;}static increaseCurrentStepIndex(){if(s._openedLabels.length>0){let e=s._openedLabels[s._openedLabels.length-1];s._openedLabels[s._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static _onStepStart;static set onStepStart(e){s._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let n=[];return s.onLoadingLabel&&e===0&&n.push(s.onLoadingLabel(e,t)),s._onStepStart&&n.push(s._onStepStart(e,t)),await Promise.all(n)}}static onLoadingLabel;static onStepEnd;static onLabelStarting;static onLabelClosing};var De=class{get currentStepTimesCounter(){return b.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){b.resetCurrentStepTimesCounter();}getRandomNumber(e,t,n={}){return b.getRandomNumber(e,t,n)}get stepCounter(){return b._stepCounter}get openedLabels(){return b.openedLabels}get currentLabel(){return b._currentLabel}async addStepHistory(e,t={}){let{choiceMade:n,ignoreSameStep:i}=t,a,o,p,c=core.GameUnifier.getVariable(O,I.LAST_STEP_GLUED)===this.stepCounter;core.GameUnifier.getVariable(O,I.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=core.GameUnifier.getVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY)),core.GameUnifier.getVariable(O,I.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(o=core.GameUnifier.getVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY)),core.GameUnifier.getVariable(O,I.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(p=core.GameUnifier.getVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY));let y=b.openedLabels,h={currentLabel:b.currentLabelId,dialogue:a,choices:o,stepSha1:e,index:this.stepCounter,labelStepIndex:b.currentLabelStepIndex,choiceIndexMade:n,inputValue:p,...this.isRequiredInput?{isRequiredInput:true}:{},alreadyMadeChoices:this.getAlreadyMadeChoicesForSha(e),isGlued:c,openedLabels:y};b.originalOpenedLabels=y,await core.GameUnifier.addHistoryItem(h,{ignoreSameStep:i}),b.lastHistoryStep=h,b.increaseStepCounter();}getAlreadyMadeChoicesForSha(e){let t=b.currentLabelStepIndex,n=this.currentLabel;if(!(t===null||!n))return b.allChoicesMade.filter(i=>i.labelId===n.id&&i.stepIndex===t&&i.stepSha1===e).map(i=>i.choiceIndex)}closeCurrentLabel(){if(!b.currentLabelId){L.warn("No label to close");return}if(!this.currentLabel){L.error("currentLabel not found");return}let e=b.openedLabels;e.pop(),b.openedLabels=e,core.GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;b.openedLabels.length>0;)this.closeCurrentLabel(),core.GameUnifier.onLabelClosing(this.openedLabels.length);}labels={get opened(){return b.openedLabels},get current(){return b._currentLabel},closeCurrent:()=>this.closeCurrentLabel(),closeAll:()=>this.closeAllLabels()};isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let i=b.allOpenedLabels[t]?.biggestStep||0;if(i){let a=le.get(t);if(a)return a.stepCount<=i}return false}get alreadyCurrentStepMadeChoicesObj(){let e=b.currentLabelStepIndex,t=this.currentLabel;if(e===null||!t)return;let n=t.getStepSha(e);return n||(L.warn("stepSha not found, setting to ERROR"),n="error"),b.allChoicesMade.filter(i=>i.labelId===t?.id&&i.stepIndex===e&&i.stepSha1===n)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=b.currentLabelId;if(e){let t=b.allOpenedLabels[e]?.openCount||0;if(b.currentLabelStepIndex&&t>=b.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return b.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}queries=(()=>{let e=this;return {isLabelAlreadyCompleted:t=>e.isLabelAlreadyCompleted(t),get alreadyCurrentStepMadeChoices(){return e.alreadyCurrentStepMadeChoices},get isCurrentStepAlreadyOpened(){return e.isCurrentStepAlreadyOpened},timesLabelOpened:t=>e.getTimesLabelOpened(t),timesChoiceMade:t=>e.getTimesChoiceMade(t)}})();addCurrentStepToHistory(){return this.addStepHistory("dev",{ignoreSameStep:true})}getCanContinue(e){let t=e?.showWarn||false,n=this.choicesValue;return n&&n.length>0?(t&&L.warn("The player must make a choice"),false):this.isRequiredInput?(t&&L.warn("The player must enter a value"),false):true}get canContinue(){return core.GameUnifier.runningStepsCount!==0||this.openedLabels.length===0?false:this.getCanContinue()}async onStepStart(e,t){let n=[];return e.onStepStart&&n.push(e.onStepStart(t,e)),b.onStepStart&&n.push(b.onStepStart(t,e)),await Promise.all(n)}async onStepEnd(e,t){let n=[];return e.onStepEnd&&n.push(e.onStepEnd(t,e)),b.onStepEnd&&n.push(b.onStepEnd(t,e)),await Promise.all(n)}async continue(e,t={}){let{runNow:n=false,steps:i=1}=t;if(!Number.isFinite(i)){L.warn(`[continue] The parameter steps must be a valid finite number, received: ${i}`);return}if(i<=0){L.warn(`[continue] The parameter steps must be greater than 0, received: ${i}`);return}if(!n&&!this.getCanContinue({showWarn:true}))return;if(!n&&core.GameUnifier.runningStepsCount!==0){core.GameUnifier.increaseContinueRequest(i);return}i>1&&core.GameUnifier.increaseContinueRequest(i-1),core.GameUnifier.runningStepsCount++;let a;try{core.GameUnifier.runningStepsCount===1&&await core.GameUnifier.onPreContinue(),b.increaseCurrentStepIndex(),a=await this.runCurrentStep(e,t);}catch(o){throw L.error("Error continuing",o),o}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e)||a}async afterRunCurrentStep(e){if(core.GameUnifier.runningStepsCount===0&&core.GameUnifier.continueRequestsCount!==0)return await core.GameUnifier.processNavigationRequests(e);if(this.openedLabels.length===0){if(core.GameUnifier.onEnd)return await core.GameUnifier.onEnd(e,{labelId:"end"});L.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e,t={}){let{choiceMade:n}=t;if(b.currentLabelId){let i=b.currentLabelStepIndex;if(i===null){L.error("currentLabelStepIndex is null");return}let a=b._currentLabel;if(!a){L.error("currentLabel not found");return}if(a.stepCount>i){try{await this.onStepStart(a,i);}catch(h){L.error("Error running onStepStart",h),this.onStepError&&await this.onStepError(h,e);return}let o=a.getStepById(i);if(!o){L.error("step not found");return}let p=a.getStepSha(i);p||(L.warn("stepSha not found, setting to ERROR"),p="error");let c,y;try{c=await o(e,{labelId:a.id});}catch(h){L.error("Error running step",h),y=h;}try{let h=this.choicesValue;if(h?.length===1&&h[0].autoSelect){let g=h[0];c=await this.selectChoice(g,e);}}catch(h){L.error("Error auto-selecting choice",h),y||(y=h);}try{let h=b.lastHistoryStep;n!==void 0&&h&&(p=h.stepSha1,p||(L.warn("stepSha not found, setting to ERROR"),p="error"),b.addChoicesMade(h.currentLabel||"error",typeof h.labelStepIndex=="number"?h.labelStepIndex:-1,h.stepSha1||"error",n),b.choiceMadeTemp=n);}catch(h){L.warn("Error adding choice made to history",h);}try{core.GameUnifier.runningStepsCount===1&&(b.addLabelHistory(a.id,i),await this.addStepHistory(p,{...t,choiceMade:b.choiceMadeTemp}),b.choiceMadeTemp=void 0);}catch(h){L.warn("Error adding step to history",h);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,b.currentLabelStepIndex||0);}catch(h){L.warn("Error running onStepEnd",h);}return y&&this.onStepError&&await this.onStepError(y,e),c}else if(this.openedLabels.length>=1)return await this.closeLabel(a.id,e,t)}else {if(this.openedLabels.length===0)return;L.error("currentLabelId not found");}}async closeLabel(e,t,n){let i=async()=>(this.closeCurrentLabel(),await this.continue(t,n));return b.onLabelClosing?await b.onLabelClosing(e,t,i):await i()}async startLabel(e,t,n){let i=async()=>{let{choiceMade:a,closeCurrentLabel:o,type:p}=n;o&&this.openedLabels.length>0&&this.closeCurrentLabel(),core.GameUnifier.runningStepsCount++;let c;try{let y=le.get(e);if(!y)throw new core.PixiError("unregistered_element",`Label ${e} not found`);b.pushNewLabel(y.id),c=await this.runCurrentStep(t,{choiceMade:a});}catch(y){throw L.error(`Error ${p} label`,y),y}return core.GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||c};return b.onLabelStarting?await b.onLabelStarting(e,t,n,i):await i()}async call(e,t,n){let{choiceMade:i}=n||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:i,type:"calling"})}async jump(e,t,n){if(this.stepCounter===0)return await this.call(e,t,n);let{choiceMade:i}=n||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:i,closeCurrentLabel:true,type:"jumping to"})}async selectChoice(e,t){this.choicesValue=void 0;let n=e.type;switch(n){case "call":return await this.call(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "jump":return await this.jump(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "close":return await this.closeChoiceMenu(e,{...e.props,...t});default:throw L.error(`Type ${n} not found`),new core.PixiError("invalid_usage",`Type ${n} not found`)}}async closeChoiceMenu(e,t){if(e.type!=="close")throw L.error("For closeChoiceMenu, the type must be close"),new core.PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let n;return typeof e.choiceIndex=="number"&&(n=e.choiceIndex),e.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:n})}get onStepError(){return async(e,t)=>{try{await core.GameUnifier.runOnError(e,t);}catch(n){L.error("Error in onError handler",n);}}}get dialogue(){let e=core.GameUnifier.getVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?core.GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e){if(e===void 0){core.GameUnifier.setVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e=="string"||Array.isArray(e))&&(e={text:e}),this.dialogGlue){let t=core.GameUnifier.getVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let n=[];Array.isArray(t.text)?n=[...t.text]:n=[t.text],Array.isArray(e.text)?n=[...n,...e.text]:n=[...n,e.text],e.text=n,e.character=e.character||t.character;}core.GameUnifier.setVariable(O,I.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{core.GameUnifier.setVariable(O,I.CURRENT_DIALOGUE_MEMORY_KEY,ce({...e,character:typeof e.character=="string"?e.character:e.character?.id})),core.GameUnifier.setVariable(O,I.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw L.error("DialogueInterface cannot contain functions or classes"),new core.PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choicesValue(){let e=core.GameUnifier.getVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],n=e.map((a,o)=>({...a,choiceIndex:o})),i=this.alreadyCurrentStepMadeChoices;if(n=n.filter((a,o)=>a.oneTime&&i?.includes(o)?false:a.onlyHaveNoChoice?(t.push(a),false):true),n.length>0)return n;if(t.length>0)return [t[0]]}}set choicesValue(e){if(!e||e.length===0){core.GameUnifier.setVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{core.GameUnifier.setVariable(O,I.CURRENT_MENU_OPTIONS_MEMORY_KEY,ce(e)),core.GameUnifier.setVariable(O,I.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw L.error("ChoiceInterface cannot contain functions or classes"),new core.PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}choicesObj=(()=>{let e=this,t={select:(n,i)=>e.selectChoice(n,i)};return Object.defineProperty(t,"list",{get:()=>e.choicesValue,set:n=>{e.choicesValue=n;},enumerable:true}),t})();get choices(){return this.choicesObj}set choices(e){this.choicesValue=e;}get dialogGlue(){return core.GameUnifier.getFlag(I.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){core.GameUnifier.setFlag(I.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return core.GameUnifier.getVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),core.GameUnifier.setVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY,e),core.GameUnifier.setVariable(O,I.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return core.GameUnifier.getVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return core.GameUnifier.getVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e={},t){e.isRequired=true,core.GameUnifier.setVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?core.GameUnifier.setVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY,t):core.GameUnifier.removeVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){core.GameUnifier.removeVariable(O,I.CURRENT_INPUT_INFO_MEMORY_KEY),core.GameUnifier.removeVariable(O,I.CURRENT_INPUT_VALUE_MEMORY_KEY);}input=(()=>{let e=this;return {get value(){return e.inputValue},set value(t){e.inputValue=t;},get isRequired(){return e.isRequiredInput},get type(){return e.inputType},request:(t,n)=>e.requestInput(t,n),removeRequest:()=>e.removeInputRequest()}})();clear(){b.openedLabels=[],b._stepCounter=0;}export(){return {openedLabels:ce(b.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async n=>{let i=[],a=le.get(n.label);return a&&(a.onLoadingLabel&&i.push(a.onLoadingLabel(e,a)),b.onLoadingLabel&&i.push(b.onLoadingLabel(e,a))),await Promise.all(i)});return await Promise.all(t)}async restore(e,t){this.clear();try{b.lastHistoryStep=t,Object.hasOwn(e,"openedLabels")?(b.openedLabels=e.openedLabels,b.originalOpenedLabels=b.openedLabels):L.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e,"stepCounter")?b._stepCounter=e.stepCounter:L.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(b.currentLabelStepIndex||0);}catch(n){L.error("Error running onLoadingLabel",n);}}catch(n){L.error("Error importing data",n);}}};function xt(s,e,t,n){let i=typeof e=="string"?e:e.id;return {...n,label:i,props:t,text:s,type:n?.type||"call"}}var pt="close";function At(s,e){return {...e,type:pt,text:s}}var ft=Ct(dt());var ve=class{constructor(e,t){this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}id;_onStepStart;get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}_onLoadingLabel;get onLoadingLabel(){return this._onLoadingLabel}_onStepEnd;get onStepEnd(){return this._onStepEnd}};var we=class extends ve{get stepCount(){return this.steps.length}getStepById(e){return this.steps[e]}constructor(e,t,n){super(e,n),this._steps=t;}_steps;get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(e){let t=this.steps;if(e<0||e>=t.length)return typeof this._steps!="function"&&L.warn("stepSha not found, setting to ERROR"),"error";try{return (0,ft.default)(t[e].toString().toLocaleLowerCase()).toString()}catch(n){return L.warn("stepSha not found, setting to ERROR",n),"error"}}};function bt(s,e,t){let n=new we(s,e,t);return le.add(n),n}var Cr=new De;
|
|
2
2
|
exports.Label=we;exports.LabelAbstract=ve;exports.NarrationManagerStatic=b;exports.RegisteredLabels=le;exports.narration=Cr;exports.newChoiceOption=xt;exports.newCloseChoiceOption=At;exports.newLabel=bt;
|
package/dist/narration.d.cts
CHANGED
|
@@ -238,8 +238,9 @@ interface NarrationManagerInterface {
|
|
|
238
238
|
getTimesChoiceMade(index: number): number;
|
|
239
239
|
/**
|
|
240
240
|
* Save the current step to the history.
|
|
241
|
+
* @returns A promise that resolves once the history is saved and the step counter is updated.
|
|
241
242
|
*/
|
|
242
|
-
addCurrentStepToHistory(): void
|
|
243
|
+
addCurrentStepToHistory(): Promise<void>;
|
|
243
244
|
/**
|
|
244
245
|
* Namespace for operations on the input requested to the player.
|
|
245
246
|
*/
|
package/dist/narration.d.ts
CHANGED
|
@@ -238,8 +238,9 @@ interface NarrationManagerInterface {
|
|
|
238
238
|
getTimesChoiceMade(index: number): number;
|
|
239
239
|
/**
|
|
240
240
|
* Save the current step to the history.
|
|
241
|
+
* @returns A promise that resolves once the history is saved and the step counter is updated.
|
|
241
242
|
*/
|
|
242
|
-
addCurrentStepToHistory(): void
|
|
243
|
+
addCurrentStepToHistory(): Promise<void>;
|
|
243
244
|
/**
|
|
244
245
|
* Namespace for operations on the input requested to the player.
|
|
245
246
|
*/
|
package/dist/narration.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a}from'./chunk-6GLWL3NH.mjs';import {k,m}from'./chunk-HD353M4B.mjs';import {d,c,e,f}from'./chunk-HQQ5WH6C.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';var h=new d({cacheSize:10}),_;(d=>{function i(c){let f=h.get(c);if(!f){e.error(`Label "${c}" not found`);return}return f}d.get=i;function e$1(...c){for(let f of c)h.set(f.id,f);}d.add=e$1;function t(){return Array.from(h.values())}d.values=t;function r(c){return h.has(c)}d.has=r;function n(){return Array.from(h.keys())}d.keys=n;function a(){h.clear();}d.clear=a;})(_||={});var y=_;var o=class i{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return GameUnifier.getVariable(k,m.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){GameUnifier.setVariable(k,m.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e$1=""){let t=i.currentLabelStepIndex;if(t===null)return e.error("currentLabelStepIndex is null"),null;let r=`${t}${e$1}`,n=i.currentLabelId,a=i._currentLabel;if(!n||t===null||!a)return e.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let d=a.getStepSha(t)||"error",c=GameUnifier.getVariable(k,m.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return c[n]||(c[n]={}),(!c[n][r]||c[n][r].stepSha1!==d)&&(c[n][r]={stepSha1:d}),c[n][r]}static setCurrentStepTimesCounterData(e$1="",t){let r=i.currentLabelStepIndex,n=r+e$1,a=i.currentLabelId;if(!a||r===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let d=GameUnifier.getVariable(k,m.CURRENT_STEP_TIMES_COUNTER_KEY)||{};d[a]||(d[a]={}),d[a][n]=t,GameUnifier.setVariable(k,m.CURRENT_STEP_TIMES_COUNTER_KEY,d);}static getCurrentStepTimesCounter(e$1=""){let t=i._stepCounter,r=i.getCurrentStepTimesCounterData(e$1);if(!r)return e.error("getCurrentStepTimesCounter obj is null"),0;let n=r.stepCounters||[];return n.find(d=>d===t)||(n.push(t),r.stepCounters=n,i.setCurrentStepTimesCounterData(e$1,r)),n.length}static getRandomNumber(e,t,r={}){let n=r.nestedId||"";if(r.onceOnly||false){let d=i.getCurrentStepTimesCounterData(n);if(!d)return;let c=d.usedRandomNumbers||{},f=Array.from({length:t-e+1},(E,N)=>N+e).filter(E=>!c[`${e}-${t}`]?.includes(E));if(f.length===0)return;let L=Math.floor(Math.random()*f.length),b=f[L];return c[`${e}-${t}`]||(c[`${e}-${t}`]=[]),c[`${e}-${t}`].push(b),d.usedRandomNumbers=c,i.setCurrentStepTimesCounterData(n,d),b}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e$1=""){let t=i.currentLabelStepIndex,r=t+e$1,n=i.currentLabelId;if(!n||t===null){e.error("currentLabelId or currentLabelStepIndex is null");return}let a=GameUnifier.getVariable(k,m.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[n]||(a[n]={}),a[n][r]={stepCounters:[],stepSha1:""},GameUnifier.setVariable(k,m.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return GameUnifier.getVariable(k,m.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){GameUnifier.setVariable(k,m.ALL_CHOICES_MADE_KEY,e);}static _stepCounter=0;static increaseStepCounter(){i._stepCounter++;}static _openedLabels=[];static get openedLabels(){return f(i._openedLabels)}static set openedLabels(e){i._openedLabels=f(e);}static _originalOpenedLabels=[];static get originalOpenedLabels(){return f(i._originalOpenedLabels)}static set originalOpenedLabels(e){i._originalOpenedLabels=f(e);}static get _currentLabel(){if(i.currentLabelId)return y.get(i.currentLabelId)}static get currentLabelId(){if(i._openedLabels.length>0)return i._openedLabels[i._openedLabels.length-1].label}static get currentLabelStepIndex(){return i._openedLabels.length>0?i._openedLabels[i._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;(!n||n<t)&&(r[e]={biggestStep:t,openCount:a},i.allOpenedLabels=r);}static addChoicesMade(e,t,r,n){let a=i.allChoicesMade,d=a.findIndex(c=>c.labelId===e&&c.stepIndex===t&&c.choiceIndex===n&&c.stepSha1===r);d<0?a.push({labelId:e,stepIndex:t,choiceIndex:n,stepSha1:r,madeTimes:1}):a[d].madeTimes++,i.allChoicesMade=a;}static pushNewLabel(e){if(!y.get(e))throw new PixiError("unregistered_element",`Label ${e} not found`);i._openedLabels.push({label:e,currentStepIndex:0});let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;r[e]={biggestStep:n,openCount:a+1},i.allOpenedLabels=r;}static increaseCurrentStepIndex(){if(i._openedLabels.length>0){let e=i._openedLabels[i._openedLabels.length-1];i._openedLabels[i._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static _onStepStart;static set onStepStart(e){i._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let r=[];return i.onLoadingLabel&&e===0&&r.push(i.onLoadingLabel(e,t)),i._onStepStart&&r.push(i._onStepStart(e,t)),await Promise.all(r)}}static onLoadingLabel;static onStepEnd;static onLabelStarting;static onLabelClosing};var g=class{get currentStepTimesCounter(){return o.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){o.resetCurrentStepTimesCounter();}getRandomNumber(e,t,r={}){return o.getRandomNumber(e,t,r)}get stepCounter(){return o._stepCounter}get openedLabels(){return o.openedLabels}get currentLabel(){return o._currentLabel}addStepHistory(e,t={}){let{choiceMade:r,ignoreSameStep:n}=t,a,d,c,f=GameUnifier.getVariable(k,m.LAST_STEP_GLUED)===this.stepCounter;GameUnifier.getVariable(k,m.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=GameUnifier.getVariable(k,m.CURRENT_DIALOGUE_MEMORY_KEY)),GameUnifier.getVariable(k,m.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(d=GameUnifier.getVariable(k,m.CURRENT_MENU_OPTIONS_MEMORY_KEY)),GameUnifier.getVariable(k,m.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(c=GameUnifier.getVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY));let L=o.openedLabels,b={currentLabel:o.currentLabelId,dialogue:a,choices:d,stepSha1:e,index:this.stepCounter,labelStepIndex:o.currentLabelStepIndex,choiceIndexMade:r,inputValue:c,...this.isRequiredInput?{isRequiredInput:true}:{},alreadyMadeChoices:this.getAlreadyMadeChoicesForSha(e),isGlued:f,openedLabels:L};o.originalOpenedLabels=L,GameUnifier.addHistoryItem(b,{ignoreSameStep:n}),o.lastHistoryStep=b,o.increaseStepCounter();}getAlreadyMadeChoicesForSha(e){let t=o.currentLabelStepIndex,r=this.currentLabel;if(!(t===null||!r))return o.allChoicesMade.filter(n=>n.labelId===r.id&&n.stepIndex===t&&n.stepSha1===e).map(n=>n.choiceIndex)}closeCurrentLabel(){if(!o.currentLabelId){e.warn("No label to close");return}if(!this.currentLabel){e.error("currentLabel not found");return}let e$1=o.openedLabels;e$1.pop(),o.openedLabels=e$1,GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;o.openedLabels.length>0;)this.closeCurrentLabel(),GameUnifier.onLabelClosing(this.openedLabels.length);}labels={get opened(){return o.openedLabels},get current(){return o._currentLabel},closeCurrent:()=>this.closeCurrentLabel(),closeAll:()=>this.closeAllLabels()};isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let n=o.allOpenedLabels[t]?.biggestStep||0;if(n){let a=y.get(t);if(a)return a.stepCount<=n}return false}get alreadyCurrentStepMadeChoicesObj(){let e$1=o.currentLabelStepIndex,t=this.currentLabel;if(e$1===null||!t)return;let r=t.getStepSha(e$1);return r||(e.warn("stepSha not found, setting to ERROR"),r="error"),o.allChoicesMade.filter(n=>n.labelId===t?.id&&n.stepIndex===e$1&&n.stepSha1===r)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=o.currentLabelId;if(e){let t=o.allOpenedLabels[e]?.openCount||0;if(o.currentLabelStepIndex&&t>=o.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return o.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}queries=(()=>{let e=this;return {isLabelAlreadyCompleted:t=>e.isLabelAlreadyCompleted(t),get alreadyCurrentStepMadeChoices(){return e.alreadyCurrentStepMadeChoices},get isCurrentStepAlreadyOpened(){return e.isCurrentStepAlreadyOpened},timesLabelOpened:t=>e.getTimesLabelOpened(t),timesChoiceMade:t=>e.getTimesChoiceMade(t)}})();addCurrentStepToHistory(){this.addStepHistory("dev",{ignoreSameStep:true});}getCanContinue(e$1){let t=e$1?.showWarn||false,r=this.choicesValue;return r&&r.length>0?(t&&e.warn("The player must make a choice"),false):this.isRequiredInput?(t&&e.warn("The player must enter a value"),false):true}get canContinue(){return GameUnifier.runningStepsCount!==0||this.openedLabels.length===0?false:this.getCanContinue()}async onStepStart(e,t){let r=[];return e.onStepStart&&r.push(e.onStepStart(t,e)),o.onStepStart&&r.push(o.onStepStart(t,e)),await Promise.all(r)}async onStepEnd(e,t){let r=[];return e.onStepEnd&&r.push(e.onStepEnd(t,e)),o.onStepEnd&&r.push(o.onStepEnd(t,e)),await Promise.all(r)}async continue(e$1,t={}){let{runNow:r=false,steps:n=1}=t;if(!Number.isFinite(n)){e.warn(`[continue] The parameter steps must be a valid finite number, received: ${n}`);return}if(n<=0){e.warn(`[continue] The parameter steps must be greater than 0, received: ${n}`);return}if(!r&&!this.getCanContinue({showWarn:true}))return;if(!r&&GameUnifier.runningStepsCount!==0){GameUnifier.increaseContinueRequest(n);return}n>1&&GameUnifier.increaseContinueRequest(n-1),GameUnifier.runningStepsCount++;let a;try{GameUnifier.runningStepsCount===1&&await GameUnifier.onPreContinue(),o.increaseCurrentStepIndex(),a=await this.runCurrentStep(e$1,t);}catch(d){throw e.error("Error continuing",d),d}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e$1)||a}async afterRunCurrentStep(e$1){if(GameUnifier.runningStepsCount===0&&GameUnifier.continueRequestsCount!==0)return await GameUnifier.processNavigationRequests(e$1);if(this.openedLabels.length===0){if(GameUnifier.onEnd)return await GameUnifier.onEnd(e$1,{labelId:"end"});e.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e$1,t={}){let{choiceMade:r}=t;if(o.currentLabelId){let n=o.currentLabelStepIndex;if(n===null){e.error("currentLabelStepIndex is null");return}let a=o._currentLabel;if(!a){e.error("currentLabel not found");return}if(a.stepCount>n){try{await this.onStepStart(a,n);}catch(b){e.error("Error running onStepStart",b),this.onStepError&&await this.onStepError(b,e$1);return}let d=a.getStepById(n);if(!d){e.error("step not found");return}let c=a.getStepSha(n);c||(e.warn("stepSha not found, setting to ERROR"),c="error");let f,L;try{f=await d(e$1,{labelId:a.id});}catch(b){e.error("Error running step",b),L=b;}try{let b=this.choicesValue;if(b?.length===1&&b[0].autoSelect){let E=b[0];f=await this.selectChoice(E,e$1);}}catch(b){e.error("Error auto-selecting choice",b),L||(L=b);}try{let b=o.lastHistoryStep;r!==void 0&&b&&(c=b.stepSha1,c||(e.warn("stepSha not found, setting to ERROR"),c="error"),o.addChoicesMade(b.currentLabel||"error",typeof b.labelStepIndex=="number"?b.labelStepIndex:-1,b.stepSha1||"error",r),o.choiceMadeTemp=r);}catch(b){e.warn("Error adding choice made to history",b);}try{GameUnifier.runningStepsCount===1&&(o.addLabelHistory(a.id,n),this.addStepHistory(c,{...t,choiceMade:o.choiceMadeTemp}),o.choiceMadeTemp=void 0);}catch(b){e.warn("Error adding step to history",b);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,o.currentLabelStepIndex||0);}catch(b){e.warn("Error running onStepEnd",b);}return L&&this.onStepError&&await this.onStepError(L,e$1),f}else if(this.openedLabels.length>=1)return await this.closeLabel(a.id,e$1,t)}else {if(this.openedLabels.length===0)return;e.error("currentLabelId not found");}}async closeLabel(e,t,r){let n=async()=>(this.closeCurrentLabel(),await this.continue(t,r));return o.onLabelClosing?await o.onLabelClosing(e,t,n):await n()}async startLabel(e$1,t,r){let n=async()=>{let{choiceMade:a,closeCurrentLabel:d,type:c}=r;d&&this.openedLabels.length>0&&this.closeCurrentLabel(),GameUnifier.runningStepsCount++;let f;try{let L=y.get(e$1);if(!L)throw new PixiError("unregistered_element",`Label ${e$1} not found`);o.pushNewLabel(L.id),f=await this.runCurrentStep(t,{choiceMade:a});}catch(L){throw e.error(`Error ${c} label`,L),L}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||f};return o.onLabelStarting?await o.onLabelStarting(e$1,t,r,n):await n()}async call(e,t,r){let{choiceMade:n}=r||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:n,type:"calling"})}async jump(e,t,r){if(this.stepCounter===0)return await this.call(e,t,r);let{choiceMade:n}=r||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:n,closeCurrentLabel:true,type:"jumping to"})}async selectChoice(e$1,t){this.choicesValue=void 0;let r=e$1.type;switch(r){case "call":return await this.call(e$1.label,{...e$1.props,...t},{choiceMade:e$1.choiceIndex});case "jump":return await this.jump(e$1.label,{...e$1.props,...t},{choiceMade:e$1.choiceIndex});case "close":return await this.closeChoiceMenu(e$1,{...e$1.props,...t});default:throw e.error(`Type ${r} not found`),new PixiError("invalid_usage",`Type ${r} not found`)}}async closeChoiceMenu(e$1,t){if(e$1.type!=="close")throw e.error("For closeChoiceMenu, the type must be close"),new PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let r;return typeof e$1.choiceIndex=="number"&&(r=e$1.choiceIndex),e$1.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:r})}get onStepError(){return async(e$1,t)=>{try{await GameUnifier.runOnError(e$1,t);}catch(r){e.error("Error in onError handler",r);}}}get dialogue(){let e=GameUnifier.getVariable(k,m.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e$1){if(e$1===void 0){GameUnifier.setVariable(k,m.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e$1=="string"||Array.isArray(e$1))&&(e$1={text:e$1}),this.dialogGlue){let t=GameUnifier.getVariable(k,m.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let r=[];Array.isArray(t.text)?r=[...t.text]:r=[t.text],Array.isArray(e$1.text)?r=[...r,...e$1.text]:r=[...r,e$1.text],e$1.text=r,e$1.character=e$1.character||t.character;}GameUnifier.setVariable(k,m.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{GameUnifier.setVariable(k,m.CURRENT_DIALOGUE_MEMORY_KEY,f({...e$1,character:typeof e$1.character=="string"?e$1.character:e$1.character?.id})),GameUnifier.setVariable(k,m.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw e.error("DialogueInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choicesValue(){let e=GameUnifier.getVariable(k,m.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],r=e.map((a,d)=>({...a,choiceIndex:d})),n=this.alreadyCurrentStepMadeChoices;if(r=r.filter((a,d)=>a.oneTime&&n?.includes(d)?false:a.onlyHaveNoChoice?(t.push(a),false):true),r.length>0)return r;if(t.length>0)return [t[0]]}}set choicesValue(e$1){if(!e$1||e$1.length===0){GameUnifier.setVariable(k,m.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{GameUnifier.setVariable(k,m.CURRENT_MENU_OPTIONS_MEMORY_KEY,f(e$1)),GameUnifier.setVariable(k,m.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw e.error("ChoiceInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}choicesObj=(()=>{let e=this,t={select:(r,n)=>e.selectChoice(r,n)};return Object.defineProperty(t,"list",{get:()=>e.choicesValue,set:r=>{e.choicesValue=r;},enumerable:true}),t})();get choices(){return this.choicesObj}set choices(e){this.choicesValue=e;}get dialogGlue(){return GameUnifier.getFlag(m.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){GameUnifier.setFlag(m.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return GameUnifier.getVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),GameUnifier.setVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY,e),GameUnifier.setVariable(k,m.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return GameUnifier.getVariable(k,m.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return GameUnifier.getVariable(k,m.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e={},t){e.isRequired=true,GameUnifier.setVariable(k,m.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?GameUnifier.setVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY,t):GameUnifier.removeVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){GameUnifier.removeVariable(k,m.CURRENT_INPUT_INFO_MEMORY_KEY),GameUnifier.removeVariable(k,m.CURRENT_INPUT_VALUE_MEMORY_KEY);}input=(()=>{let e=this;return {get value(){return e.inputValue},set value(t){e.inputValue=t;},get isRequired(){return e.isRequiredInput},get type(){return e.inputType},request:(t,r)=>e.requestInput(t,r),removeRequest:()=>e.removeInputRequest()}})();clear(){o.openedLabels=[],o._stepCounter=0;}export(){return {openedLabels:f(o.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async r=>{let n=[],a=y.get(r.label);return a&&(a.onLoadingLabel&&n.push(a.onLoadingLabel(e,a)),o.onLoadingLabel&&n.push(o.onLoadingLabel(e,a))),await Promise.all(n)});return await Promise.all(t)}async restore(e$1,t){this.clear();try{o.lastHistoryStep=t,Object.hasOwn(e$1,"openedLabels")?(o.openedLabels=e$1.openedLabels,o.originalOpenedLabels=o.openedLabels):e.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e$1,"stepCounter")?o._stepCounter=e$1.stepCounter:e.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(o.currentLabelStepIndex||0);}catch(r){e.error("Error running onLoadingLabel",r);}}catch(r){e.error("Error importing data",r);}}};function D(i,e,t,r){let n=typeof e=="string"?e:e.id;return {...r,label:n,props:t,text:i,type:r?.type||"call"}}var O="close";function U(i,e){return {...e,type:O,text:i}}var M=c(a(),1);var T=class{constructor(e,t){this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}id;_onStepStart;get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}_onLoadingLabel;get onLoadingLabel(){return this._onLoadingLabel}_onStepEnd;get onStepEnd(){return this._onStepEnd}};var I=class extends T{get stepCount(){return this.steps.length}getStepById(e){return this.steps[e]}constructor(e,t,r){super(e,r),this._steps=t;}_steps;get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(e$1){let t=this.steps;if(e$1<0||e$1>=t.length)return typeof this._steps!="function"&&e.warn("stepSha not found, setting to ERROR"),"error";try{return (0,M.default)(t[e$1].toString().toLocaleLowerCase()).toString()}catch(r){return e.warn("stepSha not found, setting to ERROR",r),"error"}}};function x(i,e,t){let r=new I(i,e,t);return y.add(r),r}var fe=new g;
|
|
1
|
+
import {a}from'./chunk-7P46CLKX.mjs';import {a as a$1}from'./chunk-YBA63R27.mjs';import {q,c,r,n,p}from'./chunk-U5BSF6X3.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';var h=new q({cacheSize:10}),_;(d=>{function i(c){let f=h.get(c);if(!f){r.error(`Label "${c}" not found`);return}return f}d.get=i;function e(...c){for(let f of c)h.set(f.id,f);}d.add=e;function t(){return Array.from(h.values())}d.values=t;function r$1(c){return h.has(c)}d.has=r$1;function n(){return Array.from(h.keys())}d.keys=n;function a(){h.clear();}d.clear=a;})(_||={});var y=_;var o=class i{constructor(){}static choiceMadeTemp=void 0;static lastHistoryStep=null;static get allOpenedLabels(){return GameUnifier.getVariable(n,p.OPENED_LABELS_COUNTER_KEY)||{}}static set allOpenedLabels(e){GameUnifier.setVariable(n,p.OPENED_LABELS_COUNTER_KEY,e);}static getCurrentStepTimesCounterData(e=""){let t=i.currentLabelStepIndex;if(t===null)return r.error("currentLabelStepIndex is null"),null;let r$1=`${t}${e}`,n$1=i.currentLabelId,a=i._currentLabel;if(!n$1||t===null||!a)return r.error("currentLabelId or currentLabelStepIndex is null or currentLabel not found"),null;let d=a.getStepSha(t)||"error",c=GameUnifier.getVariable(n,p.CURRENT_STEP_TIMES_COUNTER_KEY)||{};return c[n$1]||(c[n$1]={}),(!c[n$1][r$1]||c[n$1][r$1].stepSha1!==d)&&(c[n$1][r$1]={stepSha1:d}),c[n$1][r$1]}static setCurrentStepTimesCounterData(e="",t){let r$1=i.currentLabelStepIndex,n$1=r$1+e,a=i.currentLabelId;if(!a||r$1===null){r.error("currentLabelId or currentLabelStepIndex is null");return}let d=GameUnifier.getVariable(n,p.CURRENT_STEP_TIMES_COUNTER_KEY)||{};d[a]||(d[a]={}),d[a][n$1]=t,GameUnifier.setVariable(n,p.CURRENT_STEP_TIMES_COUNTER_KEY,d);}static getCurrentStepTimesCounter(e=""){let t=i._stepCounter,r$1=i.getCurrentStepTimesCounterData(e);if(!r$1)return r.error("getCurrentStepTimesCounter obj is null"),0;let n=r$1.stepCounters||[];return n.find(d=>d===t)||(n.push(t),r$1.stepCounters=n,i.setCurrentStepTimesCounterData(e,r$1)),n.length}static getRandomNumber(e,t,r={}){let n=r.nestedId||"";if(r.onceOnly||false){let d=i.getCurrentStepTimesCounterData(n);if(!d)return;let c=d.usedRandomNumbers||{},f=Array.from({length:t-e+1},(E,N)=>N+e).filter(E=>!c[`${e}-${t}`]?.includes(E));if(f.length===0)return;let L=Math.floor(Math.random()*f.length),b=f[L];return c[`${e}-${t}`]||(c[`${e}-${t}`]=[]),c[`${e}-${t}`].push(b),d.usedRandomNumbers=c,i.setCurrentStepTimesCounterData(n,d),b}return Math.floor(Math.random()*(t-e+1))+e}static resetCurrentStepTimesCounter(e=""){let t=i.currentLabelStepIndex,r$1=t+e,n$1=i.currentLabelId;if(!n$1||t===null){r.error("currentLabelId or currentLabelStepIndex is null");return}let a=GameUnifier.getVariable(n,p.CURRENT_STEP_TIMES_COUNTER_KEY)||{};a[n$1]||(a[n$1]={}),a[n$1][r$1]={stepCounters:[],stepSha1:""},GameUnifier.setVariable(n,p.CURRENT_STEP_TIMES_COUNTER_KEY,a);}static get allChoicesMade(){return GameUnifier.getVariable(n,p.ALL_CHOICES_MADE_KEY)||[]}static set allChoicesMade(e){GameUnifier.setVariable(n,p.ALL_CHOICES_MADE_KEY,e);}static _stepCounter=0;static increaseStepCounter(){i._stepCounter++;}static _openedLabels=[];static get openedLabels(){return a$1(i._openedLabels)}static set openedLabels(e){i._openedLabels=a$1(e);}static _originalOpenedLabels=[];static get originalOpenedLabels(){return a$1(i._originalOpenedLabels)}static set originalOpenedLabels(e){i._originalOpenedLabels=a$1(e);}static get _currentLabel(){if(i.currentLabelId)return y.get(i.currentLabelId)}static get currentLabelId(){if(i._openedLabels.length>0)return i._openedLabels[i._openedLabels.length-1].label}static get currentLabelStepIndex(){return i._openedLabels.length>0?i._openedLabels[i._openedLabels.length-1].currentStepIndex:null}static addLabelHistory(e,t){let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;(!n||n<t)&&(r[e]={biggestStep:t,openCount:a},i.allOpenedLabels=r);}static addChoicesMade(e,t,r,n){let a=i.allChoicesMade,d=a.findIndex(c=>c.labelId===e&&c.stepIndex===t&&c.choiceIndex===n&&c.stepSha1===r);d<0?a.push({labelId:e,stepIndex:t,choiceIndex:n,stepSha1:r,madeTimes:1}):a[d].madeTimes++,i.allChoicesMade=a;}static pushNewLabel(e){if(!y.get(e))throw new PixiError("unregistered_element",`Label ${e} not found`);i._openedLabels.push({label:e,currentStepIndex:0});let r=i.allOpenedLabels,n=i.allOpenedLabels[e]?.biggestStep||0,a=i.allOpenedLabels[e]?.openCount||0;r[e]={biggestStep:n,openCount:a+1},i.allOpenedLabels=r;}static increaseCurrentStepIndex(){if(i._openedLabels.length>0){let e=i._openedLabels[i._openedLabels.length-1];i._openedLabels[i._openedLabels.length-1]={...e,currentStepIndex:e.currentStepIndex+1};}}static _onStepStart;static set onStepStart(e){i._onStepStart=e;}static get onStepStart(){return async(e,t)=>{let r=[];return i.onLoadingLabel&&e===0&&r.push(i.onLoadingLabel(e,t)),i._onStepStart&&r.push(i._onStepStart(e,t)),await Promise.all(r)}}static onLoadingLabel;static onStepEnd;static onLabelStarting;static onLabelClosing};var g=class{get currentStepTimesCounter(){return o.getCurrentStepTimesCounter()}set currentStepTimesCounter(e){o.resetCurrentStepTimesCounter();}getRandomNumber(e,t,r={}){return o.getRandomNumber(e,t,r)}get stepCounter(){return o._stepCounter}get openedLabels(){return o.openedLabels}get currentLabel(){return o._currentLabel}async addStepHistory(e,t={}){let{choiceMade:r,ignoreSameStep:n$1}=t,a,d,c,f=GameUnifier.getVariable(n,p.LAST_STEP_GLUED)===this.stepCounter;GameUnifier.getVariable(n,p.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(a=GameUnifier.getVariable(n,p.CURRENT_DIALOGUE_MEMORY_KEY)),GameUnifier.getVariable(n,p.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(d=GameUnifier.getVariable(n,p.CURRENT_MENU_OPTIONS_MEMORY_KEY)),GameUnifier.getVariable(n,p.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY)===this.stepCounter&&(c=GameUnifier.getVariable(n,p.CURRENT_INPUT_VALUE_MEMORY_KEY));let L=o.openedLabels,b={currentLabel:o.currentLabelId,dialogue:a,choices:d,stepSha1:e,index:this.stepCounter,labelStepIndex:o.currentLabelStepIndex,choiceIndexMade:r,inputValue:c,...this.isRequiredInput?{isRequiredInput:true}:{},alreadyMadeChoices:this.getAlreadyMadeChoicesForSha(e),isGlued:f,openedLabels:L};o.originalOpenedLabels=L,await GameUnifier.addHistoryItem(b,{ignoreSameStep:n$1}),o.lastHistoryStep=b,o.increaseStepCounter();}getAlreadyMadeChoicesForSha(e){let t=o.currentLabelStepIndex,r=this.currentLabel;if(!(t===null||!r))return o.allChoicesMade.filter(n=>n.labelId===r.id&&n.stepIndex===t&&n.stepSha1===e).map(n=>n.choiceIndex)}closeCurrentLabel(){if(!o.currentLabelId){r.warn("No label to close");return}if(!this.currentLabel){r.error("currentLabel not found");return}let e=o.openedLabels;e.pop(),o.openedLabels=e,GameUnifier.onLabelClosing(this.openedLabels.length);}closeAllLabels(){for(;o.openedLabels.length>0;)this.closeCurrentLabel(),GameUnifier.onLabelClosing(this.openedLabels.length);}labels={get opened(){return o.openedLabels},get current(){return o._currentLabel},closeCurrent:()=>this.closeCurrentLabel(),closeAll:()=>this.closeAllLabels()};isLabelAlreadyCompleted(e){let t;typeof e=="string"?t=e:t=e.id;let n=o.allOpenedLabels[t]?.biggestStep||0;if(n){let a=y.get(t);if(a)return a.stepCount<=n}return false}get alreadyCurrentStepMadeChoicesObj(){let e=o.currentLabelStepIndex,t=this.currentLabel;if(e===null||!t)return;let r$1=t.getStepSha(e);return r$1||(r.warn("stepSha not found, setting to ERROR"),r$1="error"),o.allChoicesMade.filter(n=>n.labelId===t?.id&&n.stepIndex===e&&n.stepSha1===r$1)}get alreadyCurrentStepMadeChoices(){return this.alreadyCurrentStepMadeChoicesObj?.map(e=>e.choiceIndex)}get isCurrentStepAlreadyOpened(){let e=o.currentLabelId;if(e){let t=o.allOpenedLabels[e]?.openCount||0;if(o.currentLabelStepIndex&&t>=o.currentLabelStepIndex)return true}return false}getTimesLabelOpened(e){return o.allOpenedLabels[e]?.openCount||0}getTimesChoiceMade(e){return this.alreadyCurrentStepMadeChoicesObj?.find(t=>t.choiceIndex===e)?.madeTimes||0}queries=(()=>{let e=this;return {isLabelAlreadyCompleted:t=>e.isLabelAlreadyCompleted(t),get alreadyCurrentStepMadeChoices(){return e.alreadyCurrentStepMadeChoices},get isCurrentStepAlreadyOpened(){return e.isCurrentStepAlreadyOpened},timesLabelOpened:t=>e.getTimesLabelOpened(t),timesChoiceMade:t=>e.getTimesChoiceMade(t)}})();addCurrentStepToHistory(){return this.addStepHistory("dev",{ignoreSameStep:true})}getCanContinue(e){let t=e?.showWarn||false,r$1=this.choicesValue;return r$1&&r$1.length>0?(t&&r.warn("The player must make a choice"),false):this.isRequiredInput?(t&&r.warn("The player must enter a value"),false):true}get canContinue(){return GameUnifier.runningStepsCount!==0||this.openedLabels.length===0?false:this.getCanContinue()}async onStepStart(e,t){let r=[];return e.onStepStart&&r.push(e.onStepStart(t,e)),o.onStepStart&&r.push(o.onStepStart(t,e)),await Promise.all(r)}async onStepEnd(e,t){let r=[];return e.onStepEnd&&r.push(e.onStepEnd(t,e)),o.onStepEnd&&r.push(o.onStepEnd(t,e)),await Promise.all(r)}async continue(e,t={}){let{runNow:r$1=false,steps:n=1}=t;if(!Number.isFinite(n)){r.warn(`[continue] The parameter steps must be a valid finite number, received: ${n}`);return}if(n<=0){r.warn(`[continue] The parameter steps must be greater than 0, received: ${n}`);return}if(!r$1&&!this.getCanContinue({showWarn:true}))return;if(!r$1&&GameUnifier.runningStepsCount!==0){GameUnifier.increaseContinueRequest(n);return}n>1&&GameUnifier.increaseContinueRequest(n-1),GameUnifier.runningStepsCount++;let a;try{GameUnifier.runningStepsCount===1&&await GameUnifier.onPreContinue(),o.increaseCurrentStepIndex(),a=await this.runCurrentStep(e,t);}catch(d){throw r.error("Error continuing",d),d}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(e)||a}async afterRunCurrentStep(e){if(GameUnifier.runningStepsCount===0&&GameUnifier.continueRequestsCount!==0)return await GameUnifier.processNavigationRequests(e);if(this.openedLabels.length===0){if(GameUnifier.onEnd)return await GameUnifier.onEnd(e,{labelId:"end"});r.error("The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.com/start/other-narrative-features.html#how-manage-the-end-of-the-game");}}async runCurrentStep(e,t={}){let{choiceMade:r$1}=t;if(o.currentLabelId){let n=o.currentLabelStepIndex;if(n===null){r.error("currentLabelStepIndex is null");return}let a=o._currentLabel;if(!a){r.error("currentLabel not found");return}if(a.stepCount>n){try{await this.onStepStart(a,n);}catch(b){r.error("Error running onStepStart",b),this.onStepError&&await this.onStepError(b,e);return}let d=a.getStepById(n);if(!d){r.error("step not found");return}let c=a.getStepSha(n);c||(r.warn("stepSha not found, setting to ERROR"),c="error");let f,L;try{f=await d(e,{labelId:a.id});}catch(b){r.error("Error running step",b),L=b;}try{let b=this.choicesValue;if(b?.length===1&&b[0].autoSelect){let E=b[0];f=await this.selectChoice(E,e);}}catch(b){r.error("Error auto-selecting choice",b),L||(L=b);}try{let b=o.lastHistoryStep;r$1!==void 0&&b&&(c=b.stepSha1,c||(r.warn("stepSha not found, setting to ERROR"),c="error"),o.addChoicesMade(b.currentLabel||"error",typeof b.labelStepIndex=="number"?b.labelStepIndex:-1,b.stepSha1||"error",r$1),o.choiceMadeTemp=r$1);}catch(b){r.warn("Error adding choice made to history",b);}try{GameUnifier.runningStepsCount===1&&(o.addLabelHistory(a.id,n),await this.addStepHistory(c,{...t,choiceMade:o.choiceMadeTemp}),o.choiceMadeTemp=void 0);}catch(b){r.warn("Error adding step to history",b);}try{this.currentLabel&&await this.onStepEnd(this.currentLabel,o.currentLabelStepIndex||0);}catch(b){r.warn("Error running onStepEnd",b);}return L&&this.onStepError&&await this.onStepError(L,e),f}else if(this.openedLabels.length>=1)return await this.closeLabel(a.id,e,t)}else {if(this.openedLabels.length===0)return;r.error("currentLabelId not found");}}async closeLabel(e,t,r){let n=async()=>(this.closeCurrentLabel(),await this.continue(t,r));return o.onLabelClosing?await o.onLabelClosing(e,t,n):await n()}async startLabel(e,t,r$1){let n=async()=>{let{choiceMade:a,closeCurrentLabel:d,type:c}=r$1;d&&this.openedLabels.length>0&&this.closeCurrentLabel(),GameUnifier.runningStepsCount++;let f;try{let L=y.get(e);if(!L)throw new PixiError("unregistered_element",`Label ${e} not found`);o.pushNewLabel(L.id),f=await this.runCurrentStep(t,{choiceMade:a});}catch(L){throw r.error(`Error ${c} label`,L),L}return GameUnifier.runningStepsCount--,await this.afterRunCurrentStep(t)||f};return o.onLabelStarting?await o.onLabelStarting(e,t,r$1,n):await n()}async call(e,t,r){let{choiceMade:n}=r||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:n,type:"calling"})}async jump(e,t,r){if(this.stepCounter===0)return await this.call(e,t,r);let{choiceMade:n}=r||{},a;return typeof e=="string"?a=e:a=e.id,await this.startLabel(a,t,{choiceMade:n,closeCurrentLabel:true,type:"jumping to"})}async selectChoice(e,t){this.choicesValue=void 0;let r$1=e.type;switch(r$1){case "call":return await this.call(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "jump":return await this.jump(e.label,{...e.props,...t},{choiceMade:e.choiceIndex});case "close":return await this.closeChoiceMenu(e,{...e.props,...t});default:throw r.error(`Type ${r$1} not found`),new PixiError("invalid_usage",`Type ${r$1} not found`)}}async closeChoiceMenu(e,t){if(e.type!=="close")throw r.error("For closeChoiceMenu, the type must be close"),new PixiError("invalid_usage","For closeChoiceMenu, the type must be close");let r$1;return typeof e.choiceIndex=="number"&&(r$1=e.choiceIndex),e.closeCurrentLabel&&this.closeCurrentLabel(),await this.continue(t,{choiceMade:r$1})}get onStepError(){return async(e,t)=>{try{await GameUnifier.runOnError(e,t);}catch(r$1){r.error("Error in onError handler",r$1);}}}get dialogue(){let e=GameUnifier.getVariable(n,p.CURRENT_DIALOGUE_MEMORY_KEY);if(e)return {...e,character:e.character?GameUnifier.getCharacter(e.character)||e.character:void 0}}set dialogue(e){if(e===void 0){GameUnifier.setVariable(n,p.CURRENT_DIALOGUE_MEMORY_KEY,void 0);return}if((typeof e=="string"||Array.isArray(e))&&(e={text:e}),this.dialogGlue){let t=GameUnifier.getVariable(n,p.CURRENT_DIALOGUE_MEMORY_KEY);if(t){let r=[];Array.isArray(t.text)?r=[...t.text]:r=[t.text],Array.isArray(e.text)?r=[...r,...e.text]:r=[...r,e.text],e.text=r,e.character=e.character||t.character;}GameUnifier.setVariable(n,p.LAST_STEP_GLUED,this.stepCounter),this.dialogGlue=false;}try{GameUnifier.setVariable(n,p.CURRENT_DIALOGUE_MEMORY_KEY,a$1({...e,character:typeof e.character=="string"?e.character:e.character?.id})),GameUnifier.setVariable(n,p.LAST_DIALOGUE_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw r.error("DialogueInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}get choicesValue(){let e=GameUnifier.getVariable(n,p.CURRENT_MENU_OPTIONS_MEMORY_KEY);if(e){let t=[],r=e.map((a,d)=>({...a,choiceIndex:d})),n=this.alreadyCurrentStepMadeChoices;if(r=r.filter((a,d)=>a.oneTime&&n?.includes(d)?false:a.onlyHaveNoChoice?(t.push(a),false):true),r.length>0)return r;if(t.length>0)return [t[0]]}}set choicesValue(e){if(!e||e.length===0){GameUnifier.setVariable(n,p.CURRENT_MENU_OPTIONS_MEMORY_KEY,void 0);return}try{GameUnifier.setVariable(n,p.CURRENT_MENU_OPTIONS_MEMORY_KEY,a$1(e)),GameUnifier.setVariable(n,p.LAST_MENU_OPTIONS_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}catch{throw r.error("ChoiceInterface cannot contain functions or classes"),new PixiError("not_json_serializable","ChoiceInterface cannot contain functions or classes")}}choicesObj=(()=>{let e=this,t={select:(r,n)=>e.selectChoice(r,n)};return Object.defineProperty(t,"list",{get:()=>e.choicesValue,set:r=>{e.choicesValue=r;},enumerable:true}),t})();get choices(){return this.choicesObj}set choices(e){this.choicesValue=e;}get dialogGlue(){return GameUnifier.getFlag(p.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)}set dialogGlue(e){GameUnifier.setFlag(p.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,e);}get inputValue(){return GameUnifier.getVariable(n,p.CURRENT_INPUT_VALUE_MEMORY_KEY)}set inputValue(e){this.removeInputRequest(),GameUnifier.setVariable(n,p.CURRENT_INPUT_VALUE_MEMORY_KEY,e),GameUnifier.setVariable(n,p.LAST_INPUT_ADDED_IN_STEP_MEMORY_KEY,this.stepCounter);}get isRequiredInput(){return GameUnifier.getVariable(n,p.CURRENT_INPUT_INFO_MEMORY_KEY)?.isRequired||false}get inputType(){return GameUnifier.getVariable(n,p.CURRENT_INPUT_INFO_MEMORY_KEY)?.type}requestInput(e={},t){e.isRequired=true,GameUnifier.setVariable(n,p.CURRENT_INPUT_INFO_MEMORY_KEY,e),t!==void 0?GameUnifier.setVariable(n,p.CURRENT_INPUT_VALUE_MEMORY_KEY,t):GameUnifier.removeVariable(n,p.CURRENT_INPUT_VALUE_MEMORY_KEY);}removeInputRequest(){GameUnifier.removeVariable(n,p.CURRENT_INPUT_INFO_MEMORY_KEY),GameUnifier.removeVariable(n,p.CURRENT_INPUT_VALUE_MEMORY_KEY);}input=(()=>{let e=this;return {get value(){return e.inputValue},set value(t){e.inputValue=t;},get isRequired(){return e.isRequiredInput},get type(){return e.inputType},request:(t,r)=>e.requestInput(t,r),removeRequest:()=>e.removeInputRequest()}})();clear(){o.openedLabels=[],o._stepCounter=0;}export(){return {openedLabels:a$1(o.openedLabels),stepCounter:this.stepCounter}}async onLoadingLabel(e){let t=this.openedLabels.map(async r=>{let n=[],a=y.get(r.label);return a&&(a.onLoadingLabel&&n.push(a.onLoadingLabel(e,a)),o.onLoadingLabel&&n.push(o.onLoadingLabel(e,a))),await Promise.all(n)});return await Promise.all(t)}async restore(e,t){this.clear();try{o.lastHistoryStep=t,Object.hasOwn(e,"openedLabels")?(o.openedLabels=e.openedLabels,o.originalOpenedLabels=o.openedLabels):r.warn("Could not import openedLabels data, so will be ignored"),Object.hasOwn(e,"stepCounter")?o._stepCounter=e.stepCounter:r.warn("Could not import stepCounter data, so will be ignored");try{await this.onLoadingLabel(o.currentLabelStepIndex||0);}catch(r$1){r.error("Error running onLoadingLabel",r$1);}}catch(r$1){r.error("Error importing data",r$1);}}};function D(i,e,t,r){let n=typeof e=="string"?e:e.id;return {...r,label:n,props:t,text:i,type:r?.type||"call"}}var O="close";function U(i,e){return {...e,type:O,text:i}}var M=c(a(),1);var T=class{constructor(e,t){this.id=e,this._onStepStart=t?.onStepStart,this._onLoadingLabel=t?.onLoadingLabel,this._onStepEnd=t?.onStepEnd;}id;_onStepStart;get onStepStart(){return async(e,t)=>{if(this._onLoadingLabel&&e===0&&await this._onLoadingLabel(e,t),this._onStepStart)return await this._onStepStart(e,t)}}_onLoadingLabel;get onLoadingLabel(){return this._onLoadingLabel}_onStepEnd;get onStepEnd(){return this._onStepEnd}};var I=class extends T{get stepCount(){return this.steps.length}getStepById(e){return this.steps[e]}constructor(e,t,r){super(e,r),this._steps=t;}_steps;get steps(){return typeof this._steps=="function"?this._steps():this._steps}getStepSha(e){let t=this.steps;if(e<0||e>=t.length)return typeof this._steps!="function"&&r.warn("stepSha not found, setting to ERROR"),"error";try{return (0,M.default)(t[e].toString().toLocaleLowerCase()).toString()}catch(r$1){return r.warn("stepSha not found, setting to ERROR",r$1),"error"}}};function x(i,e,t){let r=new I(i,e,t);return y.add(r),r}var fe=new g;
|
|
2
2
|
export{I as Label,T as LabelAbstract,o as NarrationManagerStatic,y as RegisteredLabels,fe as narration,D as newChoiceOption,U as newCloseChoiceOption,x as newLabel};
|
package/dist/sound.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {h}from'./chunk-HD353M4B.mjs';import {d,e,f as f$1}from'./chunk-HQQ5WH6C.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';import oe from'@drincs/pixi-vn/pixi.js';import*as p from'tone';import {ToneAudioBuffer,Channel,Reverb,Time,PingPongDelay,FeedbackDelay,BitCrusher,Compressor,Delay,Distortion,FeedbackCombFilter,Freeverb,Gate,GreaterThan,GreaterThanZero,Limiter,MidSideCompressor,MultibandCompressor,Panner3D,Phaser,StereoWidener,AutoFilter,Chorus,Tremolo,Vibrato,AutoPanner,BiquadFilter,OnePoleFilter,Filter,Player,now}from'tone';var ie;(s=>(s.mediaInstances=new Map,s.channels=new Map,s.transients=new Set,s.systemPausedAliases=new Set,s.bufferRegistry=new d({cacheSize:10})))(ie||={});var i=ie;function T(a){return a.reduce((t,e)=>{switch(e.filterType){case "ReverbFilter":t.push(new Reverb({decay:e.decay,preDelay:e.preDelay,wet:e.wet}).toDestination());break;case "FeedbackDelayFilter":t.push(new FeedbackDelay({feedback:e.feedback,delayTime:e.delayTime,wet:e.wet}).toDestination());break;case "BitCrusherFilter":t.push(new BitCrusher({bits:e.bits}).toDestination());break;case "CompressorFilter":t.push(new Compressor({attack:e.attack,knee:e.knee,ratio:e.ratio,release:e.release,threshold:e.threshold}).toDestination());break;case "DelayFilter":t.push(new Delay({delayTime:e.delayTime,maxDelay:e.maxDelay}).toDestination());break;case "DistortionFilter":t.push(new Distortion({distortion:e.distortion,oversample:e.oversample,wet:e.wet}).toDestination());break;case "FeedbackCombFilterFilter":t.push(new FeedbackCombFilter({delayTime:e.delayTime,resonance:e.resonance}).toDestination());break;case "FreeverbFilter":t.push(new Freeverb({roomSize:e.roomSize,dampening:e.dampening,wet:e.wet}).toDestination());break;case "GateFilter":t.push(new Gate({threshold:e.threshold,smoothing:e.smoothing}).toDestination());break;case "GreaterThanFilter":t.push(new GreaterThan({value:e.value,convert:e.convert,maxValue:e.maxValue,minValue:e.minValue,units:e.units}).toDestination());break;case "GreaterThanZeroFilter":t.push(new GreaterThanZero);break;case "LimiterFilter":t.push(new Limiter({threshold:e.threshold}).toDestination());break;case "MidSideCompressorFilter":t.push(new MidSideCompressor({mid:e.mid,side:e.side}).toDestination());break;case "MultibandCompressorFilter":t.push(new MultibandCompressor({lowFrequency:e.lowFrequency,highFrequency:e.highFrequency,low:e.low,mid:e.mid,high:e.high}).toDestination());break;case "Panner3DFilter":t.push(new Panner3D({positionX:e.positionX,positionY:e.positionY,positionZ:e.positionZ,orientationX:e.orientationX,orientationY:e.orientationY,orientationZ:e.orientationZ,coneInnerAngle:e.coneInnerAngle,coneOuterAngle:e.coneOuterAngle,coneOuterGain:e.coneOuterGain,distanceModel:e.distanceModel,maxDistance:e.maxDistance,refDistance:e.refDistance,rolloffFactor:e.rolloffFactor,panningModel:e.panningModel}).toDestination());break;case "PhaserFilter":t.push(new Phaser({frequency:e.frequency,octaves:e.octaves,baseFrequency:e.baseFrequency,wet:e.wet,Q:e.Q,stages:e.stages}).toDestination());break;case "StereoWidenerFilter":t.push(new StereoWidener({width:e.width,wet:e.wet}).toDestination());break;case "PingPongDelayFilter":t.push(new PingPongDelay({wet:e.wet,delayTime:e.delayTime,feedback:e.feedback,maxDelay:e.maxDelay}).toDestination());break;case "AutoFilterFilter":t.push(new AutoFilter({frequency:e.frequency,depth:e.depth,baseFrequency:e.baseFrequency,octaves:e.octaves,filter:e.filter,wet:e.wet,type:e.type}).toDestination());break;case "BiquadFilterFilter":t.push(new BiquadFilter({frequency:e.frequency,detune:e.detune,Q:e.Q,type:e.type,gain:e.gain}).toDestination());break;case "OnePoleFilterFilter":t.push(new OnePoleFilter({type:e.type}).toDestination());break;case "CustomFilter":t.push(new Filter({frequency:e.frequency,Q:e.Q,type:e.type,detune:e.detune,gain:e.gain,rolloff:e.rolloff}).toDestination());break;case "ChorusFilter":t.push(new Chorus({frequency:e.frequency,delayTime:e.delayTime,depth:e.depth,type:e.type,spread:e.spread,feedback:e.feedback,wet:e.wet}).toDestination());break;case "TremoloFilter":t.push(new Tremolo({frequency:e.frequency,type:e.type,depth:e.depth,spread:e.spread,wet:e.wet}).toDestination());break;case "VibratoFilter":t.push(new Vibrato({maxDelay:e.maxDelay,frequency:e.frequency,depth:e.depth,type:e.type,wet:e.wet}).toDestination());break;case "AutoPannerFilter":t.push(new AutoPanner({frequency:e.frequency,type:e.type,depth:e.depth,channelCount:e.channelCount,wet:e.wet}).toDestination());break}return t},[])}function se(a){if(a)return Array.from(a).reduce((t,e$1)=>(e$1 instanceof Reverb?t.push({filterType:"ReverbFilter",wet:e$1.wet.value,decay:Time(e$1.decay).toSeconds(),preDelay:Time(e$1.preDelay).toSeconds()}):e$1 instanceof PingPongDelay?t.push({filterType:"PingPongDelayFilter",wet:e$1.wet.value,delayTime:e$1.delayTime.value,feedback:e$1.feedback.value}):e$1 instanceof FeedbackDelay?t.push({filterType:"FeedbackDelayFilter",feedback:e$1.feedback.value,delayTime:e$1.delayTime.value,wet:e$1.wet.value}):e$1 instanceof BitCrusher?t.push({filterType:"BitCrusherFilter",bits:e$1.bits.value,wet:e$1.wet.value}):e$1 instanceof Compressor?t.push({filterType:"CompressorFilter",attack:e$1.attack.value,knee:e$1.knee.value,ratio:e$1.ratio.value,release:e$1.release.value,threshold:e$1.threshold.value}):e$1 instanceof Delay?t.push({filterType:"DelayFilter",delayTime:e$1.delayTime.value,maxDelay:e$1.maxDelay}):e$1 instanceof Distortion?t.push({filterType:"DistortionFilter",distortion:e$1.distortion,oversample:e$1.oversample,wet:e$1.wet.value}):e$1 instanceof FeedbackCombFilter?t.push({filterType:"FeedbackCombFilterFilter",delayTime:e$1.delayTime.value,resonance:e$1.resonance.value}):e$1 instanceof Freeverb?t.push({filterType:"FreeverbFilter",roomSize:e$1.roomSize.value,dampening:e$1.dampening,wet:e$1.wet.value}):e$1 instanceof Gate?t.push({filterType:"GateFilter",threshold:e$1.threshold,smoothing:e$1.smoothing}):e$1 instanceof GreaterThan?t.push({filterType:"GreaterThanFilter",value:e$1.comparator.value,convert:e$1.convert,maxValue:e$1.maxValue,minValue:e$1.minValue}):e$1 instanceof GreaterThanZero?t.push({filterType:"GreaterThanZeroFilter"}):e$1 instanceof Limiter?t.push({filterType:"LimiterFilter",threshold:e$1.threshold.value}):e$1 instanceof MidSideCompressor?t.push({filterType:"MidSideCompressorFilter",mid:{attack:e$1.mid.attack.value,knee:e$1.mid.knee.value,ratio:e$1.mid.ratio.value,release:e$1.mid.release.value,threshold:e$1.mid.threshold.value},side:{attack:e$1.side.attack.value,knee:e$1.side.knee.value,ratio:e$1.side.ratio.value,release:e$1.side.release.value,threshold:e$1.side.threshold.value}}):e$1 instanceof MultibandCompressor?t.push({filterType:"MultibandCompressorFilter",lowFrequency:e$1.lowFrequency.value,highFrequency:e$1.highFrequency.value,low:{attack:e$1.low.attack.value,knee:e$1.low.knee.value,ratio:e$1.low.ratio.value,release:e$1.low.release.value,threshold:e$1.low.threshold.value},mid:{attack:e$1.mid.attack.value,knee:e$1.mid.knee.value,ratio:e$1.mid.ratio.value,release:e$1.mid.release.value,threshold:e$1.mid.threshold.value},high:{attack:e$1.high.attack.value,knee:e$1.high.knee.value,ratio:e$1.high.ratio.value,release:e$1.high.release.value,threshold:e$1.high.threshold.value}}):e$1 instanceof Panner3D?t.push({filterType:"Panner3DFilter",positionX:e$1.positionX.value,positionY:e$1.positionY.value,positionZ:e$1.positionZ.value,orientationX:e$1.orientationX.value,orientationY:e$1.orientationY.value,orientationZ:e$1.orientationZ.value,coneInnerAngle:e$1.coneInnerAngle,coneOuterAngle:e$1.coneOuterAngle,coneOuterGain:e$1.coneOuterGain,distanceModel:e$1.distanceModel,maxDistance:e$1.maxDistance,refDistance:e$1.refDistance,rolloffFactor:e$1.rolloffFactor,panningModel:e$1.panningModel}):e$1 instanceof Phaser?t.push({filterType:"PhaserFilter",frequency:e$1.frequency.value,octaves:e$1.octaves,baseFrequency:e$1.baseFrequency,wet:e$1.wet.value,Q:e$1.Q.value}):e$1 instanceof StereoWidener?t.push({filterType:"StereoWidenerFilter",width:e$1.width.value,wet:e$1.wet.value}):e$1 instanceof AutoFilter?t.push({filterType:"AutoFilterFilter",type:e$1.type,frequency:e$1.frequency.value,depth:e$1.depth.value,baseFrequency:e$1.baseFrequency,octaves:e$1.octaves,filter:{Q:e$1.filter.Q.value,type:e$1.filter.type,rolloff:e$1.filter.rolloff},wet:e$1.wet.value}):e$1 instanceof Chorus?t.push({filterType:"ChorusFilter",type:e$1.type,frequency:e$1.frequency.value,delayTime:e$1.delayTime,depth:e$1.depth,spread:e$1.spread,feedback:e$1.feedback.value,wet:e$1.wet.value}):e$1 instanceof Tremolo?t.push({filterType:"TremoloFilter",type:e$1.type,frequency:e$1.frequency.value,depth:e$1.depth.value,spread:e$1.spread,wet:e$1.wet.value}):e$1 instanceof Vibrato?t.push({filterType:"VibratoFilter",type:e$1.type,frequency:e$1.frequency.value,depth:e$1.depth.value,wet:e$1.wet.value}):e$1 instanceof AutoPanner?t.push({filterType:"AutoPannerFilter",type:e$1.type,frequency:e$1.frequency.value,depth:e$1.depth.value,channelCount:e$1.channelCount,wet:e$1.wet.value}):e$1 instanceof BiquadFilter?t.push({filterType:"BiquadFilterFilter",type:e$1.type,frequency:e$1.frequency.value,detune:e$1.detune.value,Q:e$1.Q.value,gain:e$1.gain.value}):e$1 instanceof OnePoleFilter?t.push({filterType:"OnePoleFilterFilter",type:e$1.type}):e$1 instanceof Filter?t.push({filterType:"CustomFilter",type:e$1.type,frequency:e$1.frequency.value,Q:e$1.Q.value,detune:e$1.detune.value,gain:e$1.gain.value,rolloff:e$1.rolloff}):e.warn(`Unsupported filter type for serialisation: ${e$1?.constructor?.name??e$1}, please report this to the developers if you encounter it.`),t),[])}function H(a){return a instanceof Reverb||a instanceof FeedbackDelay||a instanceof PingPongDelay||a instanceof BitCrusher||a instanceof Compressor||a instanceof Delay||a instanceof Distortion||a instanceof FeedbackCombFilter||a instanceof Freeverb||a instanceof Gate||a instanceof GreaterThan||a instanceof GreaterThanZero||a instanceof Limiter||a instanceof MidSideCompressor||a instanceof MultibandCompressor||a instanceof Panner3D||a instanceof Phaser||a instanceof StereoWidener||a instanceof AutoFilter||a instanceof Chorus||a instanceof Vibrato||a instanceof Tremolo||a instanceof AutoPanner||a instanceof BiquadFilter||a instanceof OnePoleFilter||a instanceof Filter}function m(a){return a<=0?-1/0:20*Math.log10(a)}function f(a){return a<=-1/0?0:10**(a/20)}async function w(a){if(i.bufferRegistry.has(a))return;let t=a;try{let e=oe.Assets.resolver.resolve(a);e?.src&&(t=e.src);}catch{}try{let e=await ToneAudioBuffer.load(t),n=new ToneAudioBuffer(e);i.bufferRegistry.set(a,n);}catch(e$1){e.warn(`Failed to load audio buffer for "${a}" (url: "${t}"): ${e$1 instanceof Error?e$1.message:e$1}`),i.bufferRegistry.set(a,new ToneAudioBuffer);}}var v=class extends Player{constructor(e,n,r,s,o={},l){super(o);this.alias=e;this.channelAlias=n;this.soundAlias=r;this.stepCounter=s;this.delay=l;this.options=o,this.playStartTime=now()+(l??0);}alias;channelAlias;soundAlias;stepCounter;delay;options;filters=new Set;pausedAt=void 0;playStartTime=now();get memory(){let e=Math.max(0,this.pausedAt?this.pausedAt-this.playStartTime:now()-this.playStartTime),n=this.paused;return n&&i.systemPausedAliases.has(this.alias)&&(n=false),{...this.options,fadeIn:this.fadeIn,loop:this.loop,loopEnd:this.loopEnd,loopStart:this.loopStart,mute:this.mute,playbackRate:this.playbackRate,reverse:this.reverse,volume:f(this.volume.value),autostart:!this.paused,elapsed:e,paused:n,delay:this.delay}}set memory(e){this.paused=e.paused,this.loop!==(e.loop||false)&&(this.loop=e.loop||false),this.volume.value!==m(e.volume??1)&&(this.volume.value=m(e.volume??1)),this.mute!==(e.mute||false)&&(this.mute=e.mute||false),this.playbackRate!==(e.playbackRate??1)&&(this.playbackRate=e.playbackRate??1),this.reverse!==(e.reverse||false)&&(this.reverse=e.reverse||false),this.fadeIn!==(e.fadeIn||0)&&(this.fadeIn=e.fadeIn||0),this.loopStart!==(e.loopStart||0)&&(this.loopStart=e.loopStart||0),this.loopEnd!==(e.loopEnd||0)&&(this.loopEnd=e.loopEnd||0);}get paused(){return typeof this.pausedAt=="number"}set paused(e){let n=this.state;if(e)this.pausedAt=now(),n==="started"&&super.stop();else {let r,s=false;typeof this.pausedAt=="number"&&(s=true,r=this.pausedAt-this.playStartTime,this.pausedAt=void 0),s&&n==="stopped"&&(this.delay?this.start(`+${this.delay}`,r):this.start(void 0,r));}}get muted(){return this.mute}set muted(e){this.mute=e;}get speed(){return this.playbackRate}set speed(e){this.playbackRate=e;}stop(e){return i.mediaInstances.delete(this.alias),super.stop(e)}start(e,n,r){let s=now(),o=s;if(typeof e=="number")o=e;else if(typeof e=="string"&&e.startsWith("+")){let c=Number(e.slice(1));Number.isNaN(c)||(o=s+c);}let l=typeof n=="number"?n:0;return this.playStartTime=o-l,super.start(e,n,r)}chain(...e){return e.forEach(n=>{H(n)&&(n.toDestination(),this.filters.add(n));}),super.chain(...e)}disconnect(e){return H(e)&&(e.disconnect(),this.filters.delete(e)),super.disconnect(e)}};var b=class{constructor(t,e={}){this.alias=t;this.background=e.background??false,this.toneChannel=new Channel({volume:m(e.volume??1),mute:e.muted??false,pan:e.pan??0}).toDestination(),e.filters&&this.toneChannel.chain(...e.filters);}alias;toneChannel;get volume(){return f(this.toneChannel.volume.value)}set volume(t){this.toneChannel.volume.value=m(t);}get volumeParam(){return this.toneChannel.volume}get pan(){return this.toneChannel.pan.value}set pan(t){this.toneChannel.pan.value=t;}get panParam(){return this.toneChannel.pan}get muted(){return this.toneChannel.mute}set muted(t){this.toneChannel.mute=t;}pauseAll(){for(let t of i.mediaInstances.values())t.channelAlias===this.alias&&!t.paused&&(t.paused=true);return this}resumeAll(){for(let t of i.mediaInstances.values())t.channelAlias===this.alias&&t.paused&&(t.paused=false);return this}chain(...t){return this.toneChannel.chain(...t),this}background;_createPlayer(t,e$1,n={}){let r=i.bufferRegistry.get(e$1);if(!r)throw new PixiError("unregistered_asset",`Sound buffer for alias "${e$1}" is not loaded. Call sound.load() first.`);let{delay:s,elapsed:o,filters:l=[],muted:c,autostart:h=true,speed:d,volume:P,...y}=n;c!==void 0&&(e.warn(`MediaInstance "${t}" is being created with muted=${c}. This will override the channel's muted state (${this.muted}).`),y.mute=c),d!==void 0&&(e.warn(`MediaInstance "${t}" is being created with speed=${d}. This will override the default playback speed of 1.`),y.playbackRate=d);let I=new v(t,this.alias,e$1,GameUnifier.stepCounter,{...y,volume:P!==void 0?m(P):void 0,url:r},s).chain(...l,this.toneChannel),ee=o!==void 0?Math.max(0,o):void 0;return h&&(s?I.start(`+${s}`,ee):I.start(void 0,ee)),I}async play(t,e,n){let r,s;if(typeof e=="string"?(r=t,s=e):(r=t,s=t,n=e),i.mediaInstances.has(r)){let l=i.mediaInstances.get(r);l&&(l.stop(),n={...l.memory,...n,filters:[...l.filters,...n?.filters||[]]});}await w(s);let o=this._createPlayer(r,s,n);return i.mediaInstances.set(r,o),o}toggleMuteAll(){return this.muted=!this.muted,this.muted}get mediaInstances(){return Array.from(i.mediaInstances.values()).reduce((t,e)=>(e.channelAlias===this.alias&&t.push(e),t),[])}stopAll(){let t=[];for(let[e,n]of i.mediaInstances.entries())n.channelAlias===this.alias&&(n.stop(),t.push(e));return t.forEach(e=>{i.mediaInstances.delete(e);}),this}};var F=class{get volumeAll(){return f(p.getDestination().volume.value)}set volumeAll(t){p.getDestination().volume.value=m(t);}get speedAll(){return this._speedAll}set speedAll(t){this._speedAll=t;for(let e of i.mediaInstances.values())e.speed=t;}_speedAll=1;_defaultChannelAlias=h;get defaultChannelAlias(){return this._defaultChannelAlias}set defaultChannelAlias(t){this._defaultChannelAlias=t;}add(t,e){if(!i.bufferRegistry.has(t)){let n=new p.ToneAudioBuffer(e);i.bufferRegistry.set(t,n);}}pauseAll(){for(let t of i.mediaInstances.values())t.paused||(t.paused=true);return this}resumeAll(){for(let t of i.mediaInstances.values())t.paused&&(t.paused=false);return this}get muted(){return p.getDestination().mute}toggleMuteAll(){let t=!p.getDestination().mute;return p.getDestination().mute=t,t}muteAll(){return p.getDestination().mute=true,this}unmuteAll(){return p.getDestination().mute=false,this}stopAll(){for(let t of i.mediaInstances.values())t.stop();return i.mediaInstances.clear(),this}pauseUnsavedAllInternal(t){for(let[e,n]of i.mediaInstances.entries())t&&n.channelAlias!==t||n.paused||(n.paused=true,i.systemPausedAliases.add(e));if(!t){for(let e of i.transients)e.stop();i.transients.clear();}}resumeUnsavedAllInternal(t){let e=[];for(let n of i.systemPausedAliases){let r=i.mediaInstances.get(n);if(!r){e.push(n);continue}t&&r.channelAlias!==t||(r.paused=false,e.push(n));}for(let n of e)i.systemPausedAliases.delete(n);}stopTransientAllInternal(){for(let t of i.transients)t.stop();i.transients.clear();}async playTransientInternal(t,e){i.bufferRegistry.has(t)||await this.load(t);let n=i.bufferRegistry.get(t);if(!n)throw new PixiError("unregistered_asset",`Sound buffer for alias "${t}" is not loaded. Call sound.load() first.`);let{autostart:r=true,...s}=e??{},o=new p.Player({...s,url:n}).toDestination();return r&&o.start(),i.transients.add(o),o.onstop=()=>{o.dispose(),i.transients.delete(o);},o}unsaved={playTransient:(t,e)=>this.playTransientInternal(t,e),pauseAll:t=>(this.pauseUnsavedAllInternal(t),this.unsaved),resumeAll:t=>(this.resumeUnsavedAllInternal(t),this.unsaved),stopTransientAll:()=>(this.stopTransientAllInternal(),this.unsaved)};pauseUnsavedAll(t){return this.pauseUnsavedAllInternal(t),this}resumeUnsavedAll(t){return this.resumeUnsavedAllInternal(t),this}stopTransientAll(){return this.stopTransientAllInternal(),this}async play(t,e,n){let r,s;typeof e=="string"?(r=t,s=e):(r=t,s=t,n=e),i.bufferRegistry.has(s)||await this.load(s);let{channel:o=this.defaultChannelAlias,...l}=n??{};return await this.findChannelInternal(o).play(r,s,l)}async playTransient(t,e){return this.playTransientInternal(t,e)}find(t){return i.mediaInstances.get(t)}stop(t){let e$1=this.find(t);e$1?(e$1.stop(),i.mediaInstances.delete(t)):e.warn(`No media instance found with alias ${t} to stop.`);}pause(t){let e$1=this.find(t);if(!e$1){e.warn(`No media instance found with alias ${t} to pause.`);return}return e$1.paused=true,e$1}resume(t){let e$1=this.find(t);if(!e$1){e.warn(`No media instance found with alias ${t} to resume.`);return}return e$1.paused=false,e$1}duration(t){return i.bufferRegistry.get(t)?.duration??0}async load(...t){let e=t.map(w);await Promise.all(e);}backgroundLoad(...t){return this.load(...t).catch(e$1=>{e.error("Error background-loading sound",e$1);})}backgroundLoadBundle(t){let e$1=oe.Assets.backgroundLoadBundle(t);return e$1.then(async()=>{try{let n=await oe.Assets.loadBundle(t),r=[];for(let s in n)i.bufferRegistry.has(s)||r.push(this.load(s));await Promise.all(r);}catch(n){e.error("Error loading sound bundle",n);}}).catch(n=>{e.error("Error background-loading sound bundle",n);}),e$1}clear(){this.stopAll();}addChannelInternal(t,e$1={}){if(typeof t!="string"){t.forEach(r=>{let s={...e$1,filters:e$1.filters?[...e$1.filters]:e$1.filters};this.addChannelInternal(r,s);});return}if(i.channels.has(t)){e.warn(`Channel with alias ${t} already exists.`);return}let n=new b(t,e$1);return i.channels.set(t,n),n}findChannelInternal(t){let e=i.channels.get(t);return e||this.addChannelInternal(t)}channels={add:(t,e)=>this.addChannelInternal(t,e),find:t=>this.findChannelInternal(t),get values(){return Array.from(i.channels.values())}};addChannel(t,e={}){return this.channels.add(t,e)}findChannel(t){return this.channels.find(t)}export(){let t=Array.from(i.mediaInstances.entries()).reduce((e,[n,r])=>(e[n]={channelAlias:r.channelAlias,soundAlias:r.soundAlias,stepCounter:r.stepCounter,paused:r.paused,options:{...r.memory,filters:se(r.filters)}},e),{});return {mediaInstances:f$1(t)}}async restore(t){try{if(Object.hasOwn(t,"soundsPlaying")){let e=t.soundsPlaying;if(e){let n=Object.keys(e).map(async r=>{await this.load(r),await this.play(r);});await Promise.all(n);}}if(Object.hasOwn(t,"mediaInstances")){let e$1=t.mediaInstances;if(e$1){let n=new Set,r=Object.values(e$1).map(async({soundAlias:o,channelAlias:l})=>(n.add(l),await this.load(o)));await Promise.all(r),this.channels.values.forEach(o=>{(!o.background||!n.has(o.alias))&&o.stopAll();});let s=Object.keys(e$1).map(async o=>{let l=e$1[o],c=this.findChannelInternal(l.channelAlias),h=l.options.paused??l.paused??!1;if(c.background)if(l.stepCounter===GameUnifier.stepCounter||!this.find(o)){let d=await c.play(o,l.soundAlias,{...l.options,autostart:!h,filters:T(l.options.filters||[]),delay:l.options.delay});d.paused=h;}else {let d=i.mediaInstances.get(o);if(!d){e.warn(`No media instance found with alias ${o} while restoring background state.`);return}d.memory={...l.options,paused:h},[...d.filters].forEach(y=>{d.disconnect(y),y.dispose();}),d.chain(...T(l.options.filters||[]));}else {let d=await c.play(o,l.soundAlias,{...l.options,autostart:!h,filters:T(l.options.filters||[]),delay:l.options.delay});d.paused=h;}});await Promise.all(s);}}}catch(e$1){e.error("Error importing data",e$1);}}};var K=new F;GameUnifier.addOnPreContinue(async()=>{try{i.channels.forEach(a=>{a.background||a.stopAll();});}catch{}});if(typeof document<"u"){let a=false;document.addEventListener("visibilitychange",()=>{document.hidden?K.muted||(K.muteAll(),a=true):a&&(K.unmuteAll(),a=false);});}export{i as SoundRegistry,K as sound};
|
|
1
|
+
import {a}from'./chunk-YBA63R27.mjs';import {q,k,r}from'./chunk-U5BSF6X3.mjs';import {GameUnifier,PixiError}from'@drincs/pixi-vn/core';import oe from'@drincs/pixi-vn/pixi.js';import*as p from'tone';import {ToneAudioBuffer,Channel,Reverb,Time,PingPongDelay,FeedbackDelay,BitCrusher,Compressor,Delay,Distortion,FeedbackCombFilter,Freeverb,Gate,GreaterThan,GreaterThanZero,Limiter,MidSideCompressor,MultibandCompressor,Panner3D,Phaser,StereoWidener,AutoFilter,Chorus,Tremolo,Vibrato,AutoPanner,BiquadFilter,OnePoleFilter,Filter,Player,now}from'tone';var ie;(s=>(s.mediaInstances=new Map,s.channels=new Map,s.transients=new Set,s.systemPausedAliases=new Set,s.bufferRegistry=new q({cacheSize:10})))(ie||={});var i=ie;function T(a){return a.reduce((t,e)=>{switch(e.filterType){case "ReverbFilter":t.push(new Reverb({decay:e.decay,preDelay:e.preDelay,wet:e.wet}).toDestination());break;case "FeedbackDelayFilter":t.push(new FeedbackDelay({feedback:e.feedback,delayTime:e.delayTime,wet:e.wet}).toDestination());break;case "BitCrusherFilter":t.push(new BitCrusher({bits:e.bits}).toDestination());break;case "CompressorFilter":t.push(new Compressor({attack:e.attack,knee:e.knee,ratio:e.ratio,release:e.release,threshold:e.threshold}).toDestination());break;case "DelayFilter":t.push(new Delay({delayTime:e.delayTime,maxDelay:e.maxDelay}).toDestination());break;case "DistortionFilter":t.push(new Distortion({distortion:e.distortion,oversample:e.oversample,wet:e.wet}).toDestination());break;case "FeedbackCombFilterFilter":t.push(new FeedbackCombFilter({delayTime:e.delayTime,resonance:e.resonance}).toDestination());break;case "FreeverbFilter":t.push(new Freeverb({roomSize:e.roomSize,dampening:e.dampening,wet:e.wet}).toDestination());break;case "GateFilter":t.push(new Gate({threshold:e.threshold,smoothing:e.smoothing}).toDestination());break;case "GreaterThanFilter":t.push(new GreaterThan({value:e.value,convert:e.convert,maxValue:e.maxValue,minValue:e.minValue,units:e.units}).toDestination());break;case "GreaterThanZeroFilter":t.push(new GreaterThanZero);break;case "LimiterFilter":t.push(new Limiter({threshold:e.threshold}).toDestination());break;case "MidSideCompressorFilter":t.push(new MidSideCompressor({mid:e.mid,side:e.side}).toDestination());break;case "MultibandCompressorFilter":t.push(new MultibandCompressor({lowFrequency:e.lowFrequency,highFrequency:e.highFrequency,low:e.low,mid:e.mid,high:e.high}).toDestination());break;case "Panner3DFilter":t.push(new Panner3D({positionX:e.positionX,positionY:e.positionY,positionZ:e.positionZ,orientationX:e.orientationX,orientationY:e.orientationY,orientationZ:e.orientationZ,coneInnerAngle:e.coneInnerAngle,coneOuterAngle:e.coneOuterAngle,coneOuterGain:e.coneOuterGain,distanceModel:e.distanceModel,maxDistance:e.maxDistance,refDistance:e.refDistance,rolloffFactor:e.rolloffFactor,panningModel:e.panningModel}).toDestination());break;case "PhaserFilter":t.push(new Phaser({frequency:e.frequency,octaves:e.octaves,baseFrequency:e.baseFrequency,wet:e.wet,Q:e.Q,stages:e.stages}).toDestination());break;case "StereoWidenerFilter":t.push(new StereoWidener({width:e.width,wet:e.wet}).toDestination());break;case "PingPongDelayFilter":t.push(new PingPongDelay({wet:e.wet,delayTime:e.delayTime,feedback:e.feedback,maxDelay:e.maxDelay}).toDestination());break;case "AutoFilterFilter":t.push(new AutoFilter({frequency:e.frequency,depth:e.depth,baseFrequency:e.baseFrequency,octaves:e.octaves,filter:e.filter,wet:e.wet,type:e.type}).toDestination());break;case "BiquadFilterFilter":t.push(new BiquadFilter({frequency:e.frequency,detune:e.detune,Q:e.Q,type:e.type,gain:e.gain}).toDestination());break;case "OnePoleFilterFilter":t.push(new OnePoleFilter({type:e.type}).toDestination());break;case "CustomFilter":t.push(new Filter({frequency:e.frequency,Q:e.Q,type:e.type,detune:e.detune,gain:e.gain,rolloff:e.rolloff}).toDestination());break;case "ChorusFilter":t.push(new Chorus({frequency:e.frequency,delayTime:e.delayTime,depth:e.depth,type:e.type,spread:e.spread,feedback:e.feedback,wet:e.wet}).toDestination());break;case "TremoloFilter":t.push(new Tremolo({frequency:e.frequency,type:e.type,depth:e.depth,spread:e.spread,wet:e.wet}).toDestination());break;case "VibratoFilter":t.push(new Vibrato({maxDelay:e.maxDelay,frequency:e.frequency,depth:e.depth,type:e.type,wet:e.wet}).toDestination());break;case "AutoPannerFilter":t.push(new AutoPanner({frequency:e.frequency,type:e.type,depth:e.depth,channelCount:e.channelCount,wet:e.wet}).toDestination());break}return t},[])}function se(a){if(a)return Array.from(a).reduce((t,e)=>(e instanceof Reverb?t.push({filterType:"ReverbFilter",wet:e.wet.value,decay:Time(e.decay).toSeconds(),preDelay:Time(e.preDelay).toSeconds()}):e instanceof PingPongDelay?t.push({filterType:"PingPongDelayFilter",wet:e.wet.value,delayTime:e.delayTime.value,feedback:e.feedback.value}):e instanceof FeedbackDelay?t.push({filterType:"FeedbackDelayFilter",feedback:e.feedback.value,delayTime:e.delayTime.value,wet:e.wet.value}):e instanceof BitCrusher?t.push({filterType:"BitCrusherFilter",bits:e.bits.value,wet:e.wet.value}):e instanceof Compressor?t.push({filterType:"CompressorFilter",attack:e.attack.value,knee:e.knee.value,ratio:e.ratio.value,release:e.release.value,threshold:e.threshold.value}):e instanceof Delay?t.push({filterType:"DelayFilter",delayTime:e.delayTime.value,maxDelay:e.maxDelay}):e instanceof Distortion?t.push({filterType:"DistortionFilter",distortion:e.distortion,oversample:e.oversample,wet:e.wet.value}):e instanceof FeedbackCombFilter?t.push({filterType:"FeedbackCombFilterFilter",delayTime:e.delayTime.value,resonance:e.resonance.value}):e instanceof Freeverb?t.push({filterType:"FreeverbFilter",roomSize:e.roomSize.value,dampening:e.dampening,wet:e.wet.value}):e instanceof Gate?t.push({filterType:"GateFilter",threshold:e.threshold,smoothing:e.smoothing}):e instanceof GreaterThan?t.push({filterType:"GreaterThanFilter",value:e.comparator.value,convert:e.convert,maxValue:e.maxValue,minValue:e.minValue}):e instanceof GreaterThanZero?t.push({filterType:"GreaterThanZeroFilter"}):e instanceof Limiter?t.push({filterType:"LimiterFilter",threshold:e.threshold.value}):e instanceof MidSideCompressor?t.push({filterType:"MidSideCompressorFilter",mid:{attack:e.mid.attack.value,knee:e.mid.knee.value,ratio:e.mid.ratio.value,release:e.mid.release.value,threshold:e.mid.threshold.value},side:{attack:e.side.attack.value,knee:e.side.knee.value,ratio:e.side.ratio.value,release:e.side.release.value,threshold:e.side.threshold.value}}):e instanceof MultibandCompressor?t.push({filterType:"MultibandCompressorFilter",lowFrequency:e.lowFrequency.value,highFrequency:e.highFrequency.value,low:{attack:e.low.attack.value,knee:e.low.knee.value,ratio:e.low.ratio.value,release:e.low.release.value,threshold:e.low.threshold.value},mid:{attack:e.mid.attack.value,knee:e.mid.knee.value,ratio:e.mid.ratio.value,release:e.mid.release.value,threshold:e.mid.threshold.value},high:{attack:e.high.attack.value,knee:e.high.knee.value,ratio:e.high.ratio.value,release:e.high.release.value,threshold:e.high.threshold.value}}):e instanceof Panner3D?t.push({filterType:"Panner3DFilter",positionX:e.positionX.value,positionY:e.positionY.value,positionZ:e.positionZ.value,orientationX:e.orientationX.value,orientationY:e.orientationY.value,orientationZ:e.orientationZ.value,coneInnerAngle:e.coneInnerAngle,coneOuterAngle:e.coneOuterAngle,coneOuterGain:e.coneOuterGain,distanceModel:e.distanceModel,maxDistance:e.maxDistance,refDistance:e.refDistance,rolloffFactor:e.rolloffFactor,panningModel:e.panningModel}):e instanceof Phaser?t.push({filterType:"PhaserFilter",frequency:e.frequency.value,octaves:e.octaves,baseFrequency:e.baseFrequency,wet:e.wet.value,Q:e.Q.value}):e instanceof StereoWidener?t.push({filterType:"StereoWidenerFilter",width:e.width.value,wet:e.wet.value}):e instanceof AutoFilter?t.push({filterType:"AutoFilterFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,baseFrequency:e.baseFrequency,octaves:e.octaves,filter:{Q:e.filter.Q.value,type:e.filter.type,rolloff:e.filter.rolloff},wet:e.wet.value}):e instanceof Chorus?t.push({filterType:"ChorusFilter",type:e.type,frequency:e.frequency.value,delayTime:e.delayTime,depth:e.depth,spread:e.spread,feedback:e.feedback.value,wet:e.wet.value}):e instanceof Tremolo?t.push({filterType:"TremoloFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,spread:e.spread,wet:e.wet.value}):e instanceof Vibrato?t.push({filterType:"VibratoFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,wet:e.wet.value}):e instanceof AutoPanner?t.push({filterType:"AutoPannerFilter",type:e.type,frequency:e.frequency.value,depth:e.depth.value,channelCount:e.channelCount,wet:e.wet.value}):e instanceof BiquadFilter?t.push({filterType:"BiquadFilterFilter",type:e.type,frequency:e.frequency.value,detune:e.detune.value,Q:e.Q.value,gain:e.gain.value}):e instanceof OnePoleFilter?t.push({filterType:"OnePoleFilterFilter",type:e.type}):e instanceof Filter?t.push({filterType:"CustomFilter",type:e.type,frequency:e.frequency.value,Q:e.Q.value,detune:e.detune.value,gain:e.gain.value,rolloff:e.rolloff}):r.warn(`Unsupported filter type for serialisation: ${e?.constructor?.name??e}, please report this to the developers if you encounter it.`),t),[])}function H(a){return a instanceof Reverb||a instanceof FeedbackDelay||a instanceof PingPongDelay||a instanceof BitCrusher||a instanceof Compressor||a instanceof Delay||a instanceof Distortion||a instanceof FeedbackCombFilter||a instanceof Freeverb||a instanceof Gate||a instanceof GreaterThan||a instanceof GreaterThanZero||a instanceof Limiter||a instanceof MidSideCompressor||a instanceof MultibandCompressor||a instanceof Panner3D||a instanceof Phaser||a instanceof StereoWidener||a instanceof AutoFilter||a instanceof Chorus||a instanceof Vibrato||a instanceof Tremolo||a instanceof AutoPanner||a instanceof BiquadFilter||a instanceof OnePoleFilter||a instanceof Filter}function m(a){return a<=0?-1/0:20*Math.log10(a)}function f(a){return a<=-1/0?0:10**(a/20)}async function w(a){if(i.bufferRegistry.has(a))return;let t=a;try{let e=oe.Assets.resolver.resolve(a);e?.src&&(t=e.src);}catch{}try{let e=await ToneAudioBuffer.load(t),n=new ToneAudioBuffer(e);i.bufferRegistry.set(a,n);}catch(e){r.warn(`Failed to load audio buffer for "${a}" (url: "${t}"): ${e instanceof Error?e.message:e}`),i.bufferRegistry.set(a,new ToneAudioBuffer);}}var v=class extends Player{constructor(e,n,r,s,o={},l){super(o);this.alias=e;this.channelAlias=n;this.soundAlias=r;this.stepCounter=s;this.delay=l;this.options=o,this.playStartTime=now()+(l??0);}alias;channelAlias;soundAlias;stepCounter;delay;options;filters=new Set;pausedAt=void 0;playStartTime=now();get memory(){let e=Math.max(0,this.pausedAt?this.pausedAt-this.playStartTime:now()-this.playStartTime),n=this.paused;return n&&i.systemPausedAliases.has(this.alias)&&(n=false),{...this.options,fadeIn:this.fadeIn,loop:this.loop,loopEnd:this.loopEnd,loopStart:this.loopStart,mute:this.mute,playbackRate:this.playbackRate,reverse:this.reverse,volume:f(this.volume.value),autostart:!this.paused,elapsed:e,paused:n,delay:this.delay}}set memory(e){this.paused=e.paused,this.loop!==(e.loop||false)&&(this.loop=e.loop||false),this.volume.value!==m(e.volume??1)&&(this.volume.value=m(e.volume??1)),this.mute!==(e.mute||false)&&(this.mute=e.mute||false),this.playbackRate!==(e.playbackRate??1)&&(this.playbackRate=e.playbackRate??1),this.reverse!==(e.reverse||false)&&(this.reverse=e.reverse||false),this.fadeIn!==(e.fadeIn||0)&&(this.fadeIn=e.fadeIn||0),this.loopStart!==(e.loopStart||0)&&(this.loopStart=e.loopStart||0),this.loopEnd!==(e.loopEnd||0)&&(this.loopEnd=e.loopEnd||0);}get paused(){return typeof this.pausedAt=="number"}set paused(e){let n=this.state;if(e)this.pausedAt=now(),n==="started"&&super.stop();else {let r,s=false;typeof this.pausedAt=="number"&&(s=true,r=this.pausedAt-this.playStartTime,this.pausedAt=void 0),s&&n==="stopped"&&(this.delay?this.start(`+${this.delay}`,r):this.start(void 0,r));}}get muted(){return this.mute}set muted(e){this.mute=e;}get speed(){return this.playbackRate}set speed(e){this.playbackRate=e;}stop(e){return i.mediaInstances.delete(this.alias),super.stop(e)}start(e,n,r){let s=now(),o=s;if(typeof e=="number")o=e;else if(typeof e=="string"&&e.startsWith("+")){let c=Number(e.slice(1));Number.isNaN(c)||(o=s+c);}let l=typeof n=="number"?n:0;return this.playStartTime=o-l,super.start(e,n,r)}chain(...e){return e.forEach(n=>{H(n)&&(n.toDestination(),this.filters.add(n));}),super.chain(...e)}disconnect(e){return H(e)&&(e.disconnect(),this.filters.delete(e)),super.disconnect(e)}};var b=class{constructor(t,e={}){this.alias=t;this.background=e.background??false,this.toneChannel=new Channel({volume:m(e.volume??1),mute:e.muted??false,pan:e.pan??0}).toDestination(),e.filters&&this.toneChannel.chain(...e.filters);}alias;toneChannel;get volume(){return f(this.toneChannel.volume.value)}set volume(t){this.toneChannel.volume.value=m(t);}get volumeParam(){return this.toneChannel.volume}get pan(){return this.toneChannel.pan.value}set pan(t){this.toneChannel.pan.value=t;}get panParam(){return this.toneChannel.pan}get muted(){return this.toneChannel.mute}set muted(t){this.toneChannel.mute=t;}pauseAll(){for(let t of i.mediaInstances.values())t.channelAlias===this.alias&&!t.paused&&(t.paused=true);return this}resumeAll(){for(let t of i.mediaInstances.values())t.channelAlias===this.alias&&t.paused&&(t.paused=false);return this}chain(...t){return this.toneChannel.chain(...t),this}background;_createPlayer(t,e,n={}){let r$1=i.bufferRegistry.get(e);if(!r$1)throw new PixiError("unregistered_asset",`Sound buffer for alias "${e}" is not loaded. Call sound.load() first.`);let{delay:s,elapsed:o,filters:l=[],muted:c,autostart:h=true,speed:d,volume:P,...y}=n;c!==void 0&&(r.warn(`MediaInstance "${t}" is being created with muted=${c}. This will override the channel's muted state (${this.muted}).`),y.mute=c),d!==void 0&&(r.warn(`MediaInstance "${t}" is being created with speed=${d}. This will override the default playback speed of 1.`),y.playbackRate=d);let I=new v(t,this.alias,e,GameUnifier.stepCounter,{...y,volume:P!==void 0?m(P):void 0,url:r$1},s).chain(...l,this.toneChannel),ee=o!==void 0?Math.max(0,o):void 0;return h&&(s?I.start(`+${s}`,ee):I.start(void 0,ee)),I}async play(t,e,n){let r,s;if(typeof e=="string"?(r=t,s=e):(r=t,s=t,n=e),i.mediaInstances.has(r)){let l=i.mediaInstances.get(r);l&&(l.stop(),n={...l.memory,...n,filters:[...l.filters,...n?.filters||[]]});}await w(s);let o=this._createPlayer(r,s,n);return i.mediaInstances.set(r,o),o}toggleMuteAll(){return this.muted=!this.muted,this.muted}get mediaInstances(){return Array.from(i.mediaInstances.values()).reduce((t,e)=>(e.channelAlias===this.alias&&t.push(e),t),[])}stopAll(){let t=[];for(let[e,n]of i.mediaInstances.entries())n.channelAlias===this.alias&&(n.stop(),t.push(e));return t.forEach(e=>{i.mediaInstances.delete(e);}),this}};var F=class{get volumeAll(){return f(p.getDestination().volume.value)}set volumeAll(t){p.getDestination().volume.value=m(t);}get speedAll(){return this._speedAll}set speedAll(t){this._speedAll=t;for(let e of i.mediaInstances.values())e.speed=t;}_speedAll=1;_defaultChannelAlias=k;get defaultChannelAlias(){return this._defaultChannelAlias}set defaultChannelAlias(t){this._defaultChannelAlias=t;}add(t,e){if(!i.bufferRegistry.has(t)){let n=new p.ToneAudioBuffer(e);i.bufferRegistry.set(t,n);}}pauseAll(){for(let t of i.mediaInstances.values())t.paused||(t.paused=true);return this}resumeAll(){for(let t of i.mediaInstances.values())t.paused&&(t.paused=false);return this}get muted(){return p.getDestination().mute}toggleMuteAll(){let t=!p.getDestination().mute;return p.getDestination().mute=t,t}muteAll(){return p.getDestination().mute=true,this}unmuteAll(){return p.getDestination().mute=false,this}stopAll(){for(let t of i.mediaInstances.values())t.stop();return i.mediaInstances.clear(),this}pauseUnsavedAllInternal(t){for(let[e,n]of i.mediaInstances.entries())t&&n.channelAlias!==t||n.paused||(n.paused=true,i.systemPausedAliases.add(e));if(!t){for(let e of i.transients)e.stop();i.transients.clear();}}resumeUnsavedAllInternal(t){let e=[];for(let n of i.systemPausedAliases){let r=i.mediaInstances.get(n);if(!r){e.push(n);continue}t&&r.channelAlias!==t||(r.paused=false,e.push(n));}for(let n of e)i.systemPausedAliases.delete(n);}stopTransientAllInternal(){for(let t of i.transients)t.stop();i.transients.clear();}async playTransientInternal(t,e){i.bufferRegistry.has(t)||await this.load(t);let n=i.bufferRegistry.get(t);if(!n)throw new PixiError("unregistered_asset",`Sound buffer for alias "${t}" is not loaded. Call sound.load() first.`);let{autostart:r=true,...s}=e??{},o=new p.Player({...s,url:n}).toDestination();return r&&o.start(),i.transients.add(o),o.onstop=()=>{o.dispose(),i.transients.delete(o);},o}unsaved={playTransient:(t,e)=>this.playTransientInternal(t,e),pauseAll:t=>(this.pauseUnsavedAllInternal(t),this.unsaved),resumeAll:t=>(this.resumeUnsavedAllInternal(t),this.unsaved),stopTransientAll:()=>(this.stopTransientAllInternal(),this.unsaved)};pauseUnsavedAll(t){return this.pauseUnsavedAllInternal(t),this}resumeUnsavedAll(t){return this.resumeUnsavedAllInternal(t),this}stopTransientAll(){return this.stopTransientAllInternal(),this}async play(t,e,n){let r,s;typeof e=="string"?(r=t,s=e):(r=t,s=t,n=e),i.bufferRegistry.has(s)||await this.load(s);let{channel:o=this.defaultChannelAlias,...l}=n??{};return await this.findChannelInternal(o).play(r,s,l)}async playTransient(t,e){return this.playTransientInternal(t,e)}find(t){return i.mediaInstances.get(t)}stop(t){let e=this.find(t);e?(e.stop(),i.mediaInstances.delete(t)):r.warn(`No media instance found with alias ${t} to stop.`);}pause(t){let e=this.find(t);if(!e){r.warn(`No media instance found with alias ${t} to pause.`);return}return e.paused=true,e}resume(t){let e=this.find(t);if(!e){r.warn(`No media instance found with alias ${t} to resume.`);return}return e.paused=false,e}duration(t){return i.bufferRegistry.get(t)?.duration??0}async load(...t){let e=t.map(w);await Promise.all(e);}backgroundLoad(...t){return this.load(...t).catch(e=>{r.error("Error background-loading sound",e);})}backgroundLoadBundle(t){let e=oe.Assets.backgroundLoadBundle(t);return e.then(async()=>{try{let n=await oe.Assets.loadBundle(t),r=[];for(let s in n)i.bufferRegistry.has(s)||r.push(this.load(s));await Promise.all(r);}catch(n){r.error("Error loading sound bundle",n);}}).catch(n=>{r.error("Error background-loading sound bundle",n);}),e}clear(){this.stopAll();}addChannelInternal(t,e={}){if(typeof t!="string"){t.forEach(r=>{let s={...e,filters:e.filters?[...e.filters]:e.filters};this.addChannelInternal(r,s);});return}if(i.channels.has(t)){r.warn(`Channel with alias ${t} already exists.`);return}let n=new b(t,e);return i.channels.set(t,n),n}findChannelInternal(t){let e=i.channels.get(t);return e||this.addChannelInternal(t)}channels={add:(t,e)=>this.addChannelInternal(t,e),find:t=>this.findChannelInternal(t),get values(){return Array.from(i.channels.values())}};addChannel(t,e={}){return this.channels.add(t,e)}findChannel(t){return this.channels.find(t)}export(){let t=Array.from(i.mediaInstances.entries()).reduce((e,[n,r])=>(e[n]={channelAlias:r.channelAlias,soundAlias:r.soundAlias,stepCounter:r.stepCounter,paused:r.paused,options:{...r.memory,filters:se(r.filters)}},e),{});return {mediaInstances:a(t)}}async restore(t){try{if(Object.hasOwn(t,"soundsPlaying")){let e=t.soundsPlaying;if(e){let n=Object.keys(e).map(async r=>{await this.load(r),await this.play(r);});await Promise.all(n);}}if(Object.hasOwn(t,"mediaInstances")){let e=t.mediaInstances;if(e){let n=new Set,r$1=Object.values(e).map(async({soundAlias:o,channelAlias:l})=>(n.add(l),await this.load(o)));await Promise.all(r$1),this.channels.values.forEach(o=>{(!o.background||!n.has(o.alias))&&o.stopAll();});let s=Object.keys(e).map(async o=>{let l=e[o],c=this.findChannelInternal(l.channelAlias),h=l.options.paused??l.paused??!1;if(c.background)if(l.stepCounter===GameUnifier.stepCounter||!this.find(o)){let d=await c.play(o,l.soundAlias,{...l.options,autostart:!h,filters:T(l.options.filters||[]),delay:l.options.delay});d.paused=h;}else {let d=i.mediaInstances.get(o);if(!d){r.warn(`No media instance found with alias ${o} while restoring background state.`);return}d.memory={...l.options,paused:h},[...d.filters].forEach(y=>{d.disconnect(y),y.dispose();}),d.chain(...T(l.options.filters||[]));}else {let d=await c.play(o,l.soundAlias,{...l.options,autostart:!h,filters:T(l.options.filters||[]),delay:l.options.delay});d.paused=h;}});await Promise.all(s);}}}catch(e){r.error("Error importing data",e);}}};var K=new F;GameUnifier.addOnPreContinue(async()=>{try{i.channels.forEach(a=>{a.background||a.stopAll();});}catch{}});if(typeof document<"u"){let a=false;document.addEventListener("visibilitychange",()=>{document.hidden?K.muted||(K.muteAll(),a=true):a&&(K.unmuteAll(),a=false);});}export{i as SoundRegistry,K as sound};
|