@drincs/pixi-vn-ink 0.4.1 → 0.4.2
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/functions/hashtag-script.cjs +1 -1
- package/dist/functions/hashtag-script.js +1 -1
- package/dist/functions/importer.cjs +2 -2
- package/dist/functions/importer.js +2 -2
- package/dist/functions/index.cjs +26 -26
- package/dist/functions/index.js +26 -26
- package/dist/functions/ink-to-pixivn.cjs +1 -1
- package/dist/functions/ink-to-pixivn.js +1 -1
- package/dist/functions/replace.cjs +1 -1
- package/dist/functions/replace.js +1 -1
- package/dist/functions/story-info-converter.cjs +1 -1
- package/dist/functions/story-info-converter.js +1 -1
- package/dist/index.cjs +26 -26
- package/dist/index.js +26 -26
- package/dist/managers/HashtagScriptManager.cjs +1 -1
- package/dist/managers/HashtagScriptManager.js +1 -1
- package/dist/parser/adding-elements.cjs +1 -1
- package/dist/parser/adding-elements.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';function
|
|
1
|
+
'use strict';function T(s){}exports.onInkHashtagScript=T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function T(s){}export{T as onInkHashtagScript};
|
|
@@ -43,6 +43,6 @@ Error:${h}`);}return u!=null&&(l=new s(u,r,this._externalErrorHandler,this._root
|
|
|
43
43
|
\r`),this.ParseNewline(),We.ParseSuccess),this.Line=r=>()=>{let o=this.ParseObject(r);return o===null?null:(this.Expect(this.EndOfLine,"end of line",this.SkipToNextLine),o)},this.StartTag=()=>{if(this.Whitespace(),this.ParseString("#")===null)return null;this.parsingStringExpression&&this.Error("Tags aren't allowed inside of strings. Please use \\# if you want a hash symbol.");let r=null;if(this.tagActive){let o=new he.ContentList;o.AddContent(new Rt.Tag(!1)),o.AddContent(new Rt.Tag(!0)),r=o;}else r=new Rt.Tag(!0);return this.tagActive=!0,this.Whitespace(),r},this._inlineWhitespaceChars=new X.CharacterSet(" "),this.EndOfLine=()=>this.OneOf([this.Newline,this.EndOfFile]),this.Newline=()=>(this.Whitespace(),this.ParseNewline()!==null?We.ParseSuccess:null),this.EndOfFile=()=>(this.Whitespace(),this.endOfInput?We.ParseSuccess:null),this.MultilineWhitespace=()=>{let r=this.OneOrMore(this.Newline);return r===null?null:r.length>=1?We.ParseSuccess:null},this.Whitespace=()=>this.ParseCharactersFromCharSet(this._inlineWhitespaceChars)!==null?We.ParseSuccess:null,this.Spaced=r=>()=>{this.Whitespace();let o=this.ParseObject(r);return o===null?null:(this.Whitespace(),o)},this.AnyWhitespace=()=>{let r=!1;for(;this.OneOf([this.Whitespace,this.MultilineWhitespace])!==null;)r=!0;return r?We.ParseSuccess:null},this.MultiSpaced=r=>()=>{this.AnyWhitespace();let o=this.ParseObject(r);return o===null?null:(this.AnyWhitespace(),o)},this._filename=null,this._externalErrorHandler=null,this._fileHandler=null,this._filename=t,this.RegisterExpressionOperators(),this.GenerateStatementLevelRules(),this.errorHandler=this.OnStringParserError,this._externalErrorHandler=n,a===null?this._fileHandler=new Ag.DefaultFileHandler:this._fileHandler=a,i===null){if(this._rootParser=this,this._openFilenames=[],this._filename!==null){let r=this.fileHandler.ResolveInkFilename(this._filename);this._openFilenames.push(r);}}else this._rootParser=i;}PreProcessInputString(e){return new fg.CommentEliminator(e).Process()}get parsingStringExpression(){return this.GetFlag(Number(Qr.CustomFlags.ParsingString))}set parsingStringExpression(e){this.SetFlag(Number(Qr.CustomFlags.ParsingString),e);}get tagActive(){return this.GetFlag(Number(Qr.CustomFlags.TagActive))}set tagActive(e){this.SetFlag(Number(Qr.CustomFlags.TagActive),e);}get identifierCharSet(){return this._identifierCharSet===null&&((this._identifierCharSet=new X.CharacterSet).AddRange("A","Z").AddRange("a","z").AddRange("0","9").Add("_"),this.ExtendIdentifierCharacterRanges(this._identifierCharSet)),this._identifierCharSet}EndTagIfNecessary(e){this.tagActive&&(e!=null&&(e instanceof he.ContentList?e.AddContent(new Rt.Tag(!1)):e.push(new Rt.Tag(!1))),this.tagActive=!1);}};ts.InkParser=D;D.LatinBasic=Te.CharacterRange.Define("A","z",new X.CharacterSet().AddRange("[","`"));D.LatinExtendedA=Te.CharacterRange.Define("\u0100","\u017F");D.LatinExtendedB=Te.CharacterRange.Define("\u0180","\u024F");D.Greek=Te.CharacterRange.Define("\u0370","\u03FF",new X.CharacterSet().AddRange("\u0378","\u0385").AddCharacters("\u0374\u0375\u0378\u0387\u038B\u038D\u03A2"));D.Cyrillic=Te.CharacterRange.Define("\u0400","\u04FF",new X.CharacterSet().AddRange("\u0482","\u0489"));D.Armenian=Te.CharacterRange.Define("\u0530","\u058F",new X.CharacterSet().AddCharacters("\u0530").AddRange("\u0557","\u0560").AddRange("\u0588","\u058E"));D.Hebrew=Te.CharacterRange.Define("\u0590","\u05FF",new X.CharacterSet);D.Arabic=Te.CharacterRange.Define("\u0600","\u06FF",new X.CharacterSet);D.Korean=Te.CharacterRange.Define("\uAC00","\uD7AF",new X.CharacterSet);D.Latin1Supplement=Te.CharacterRange.Define("\x80","\xFF",new X.CharacterSet);D.Chinese=Te.CharacterRange.Define("\u4E00","\u9FFF",new X.CharacterSet);D.ListAllCharacterRanges=()=>[D.LatinBasic,D.LatinExtendedA,D.LatinExtendedB,D.Arabic,D.Armenian,D.Cyrillic,D.Greek,D.Hebrew,D.Korean,D.Latin1Supplement,D.Chinese];});var Bu=C(ns=>{Object.defineProperty(ns,"__esModule",{value:!0});ns.GenerateStoryStats=void 0;var Ig=_t(),Fg=xt(),Vg=ln(),kg=Ga(),Rg=za(),Dg=Je();function Lg(s){let e=s.FindAll(Dg.Text)(),t=0;for(let l of e){let u=0,h=!0;for(let c of l.text)c==" "||c==" "||c==`
|
|
44
44
|
`||c=="\r"?h=!0:h&&(u++,h=!1);t+=u;}let n=s.FindAll(kg.Knot)(),i=s.FindAll(Rg.Stitch)(),a=s.FindAll(Ig.Choice)(),r=s.FindAll(Vg.Gather)(l=>l.debugMetadata!=null),o=s.FindAll(Fg.Divert)();return {words:t,knots:n.length,functions:n.filter(l=>l.isFunction).length,stitches:i.length,gathers:r.length,diverts:o.length-1,choices:a.length}}ns.GenerateStoryStats=Lg;});var Gu=C(is=>{Object.defineProperty(is,"__esModule",{value:!0});is.JsonFileHandler=void 0;var Oo=class{constructor(e){this.fileHierarchy=e,this.ResolveInkFilename=t=>{if(Object.keys(this.fileHierarchy).includes(t))return t;throw new Error(`Cannot locate ${t}. Are you trying a relative import ? This is not yet implemented.`)},this.LoadInkFileContents=t=>{if(Object.keys(this.fileHierarchy).includes(t))return this.fileHierarchy[t];throw new Error(`Cannot open ${t}.`)};}};is.JsonFileHandler=Oo;});var $u=C(ne=>{Object.defineProperty(ne,"__esModule",{value:!0});ne.Compiler=ne.Story=ne.InkList=ne.JsonFileHandler=ne.StatementLevel=ne.InkParser=ne.CompilerOptions=void 0;var Wg=cs(),qg=Zo(),No=Wn(),jg=Po(),Mg=j(),Bg=k(),Gg=Bu(),Jg=cs();Object.defineProperty(ne,"CompilerOptions",{enumerable:!0,get:function(){return Jg.CompilerOptions}});var $g=Po();Object.defineProperty(ne,"InkParser",{enumerable:!0,get:function(){return $g.InkParser}});var Ug=Ha();Object.defineProperty(ne,"StatementLevel",{enumerable:!0,get:function(){return Ug.StatementLevel}});var Hg=Gu();Object.defineProperty(ne,"JsonFileHandler",{enumerable:!0,get:function(){return Hg.JsonFileHandler}});var Ju=vn();Object.defineProperty(ne,"InkList",{enumerable:!0,get:function(){return Ju.InkList}});Object.defineProperty(ne,"Story",{enumerable:!0,get:function(){return Ju.Story}});var Ao=class{get errors(){return this._errors}get warnings(){return this._warnings}get authorMessages(){return this._authorMessages}get inputString(){return this._inputString}get options(){return this._options}get parsedStory(){if(!this._parsedStory)throw new Error;return this._parsedStory}get runtimeStory(){if(!this._runtimeStory)throw new Error("Compilation failed.");return this._runtimeStory}get parser(){if(!this._parser)throw new Error;return this._parser}get debugSourceRanges(){return this._debugSourceRanges}constructor(e,t=null){this._errors=[],this._warnings=[],this._authorMessages=[],this._parsedStory=null,this._runtimeStory=null,this._parser=null,this._debugSourceRanges=[],this.Compile=()=>(this._parser=new jg.InkParser(this.inputString,this.options.sourceFilename||null,this.OnError,null,this.options.fileHandler),this._parsedStory=this.parser.ParseStory(),this.errors.length===0?(this.parsedStory.countAllVisits=this.options.countAllVisits,this._runtimeStory=this.parsedStory.ExportRuntime(this.OnError)):this._runtimeStory=null,this.runtimeStory),this.RetrieveDebugSourceForLatestContent=()=>{var n;for(let i of this.runtimeStory.state.outputStream){let a=(0, Bg.asOrNull)(i,Mg.StringValue);if(a!==null){let r=new qg.DebugSourceRange(((n=a.value)===null||n===void 0?void 0:n.length)||0,a.debugMetadata,a.value||"unknown");this.debugSourceRanges.push(r);}}},this.GenerateStats=()=>this._parsedStory===null?null:(0, Gg.GenerateStoryStats)(this._parsedStory),this.DebugMetadataForContentAtOffset=n=>{let i=0,a=null;for(let r of this.debugSourceRanges){if(r.debugMetadata!==null&&(a=r.debugMetadata),n>=i&&n<i+r.length)return a;i+=r.length;}return null},this.OnError=(n,i)=>{switch(i){case No.ErrorType.Author:this._authorMessages.push(n);break;case No.ErrorType.Warning:this._warnings.push(n);break;case No.ErrorType.Error:this._errors.push(n);break}this.options.errorHandler!==null&&this.options.errorHandler(n,i);},this._inputString=e,this._options=t||new Wg.CompilerOptions;}};ne.Compiler=Ao;});var Lh=Object.create,Jo=Object.defineProperty,Wh=Object.getOwnPropertyDescriptor,qh=Object.getOwnPropertyNames,jh=Object.getPrototypeOf,Mh=Object.prototype.hasOwnProperty,Mo=(s=>typeof Qe<"u"?Qe:typeof Proxy<"u"?new Proxy(s,{get:(e,t)=>(typeof Qe<"u"?Qe:e)[t]}):s)(function(s){if(typeof Qe<"u")return Qe.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')}),$o=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),Bh=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of qh(e))!Mh.call(s,i)&&i!==t&&Jo(s,i,{get:()=>e[i],enumerable:!(n=Wh(e,i))||n.enumerable});return s},Gh=(s,e,t)=>(t=s!=null?Lh(jh(s)):{},Bh(Jo(t,"default",{value:s,enumerable:!0}),s)),Jh=$o((s,e)=>{(function(t,n){typeof s=="object"?e.exports=s=n():typeof define=="function"&&define.amd?define([],n):t.CryptoJS=n();})(s,function(){var t=t||function(n,i){var a;if(typeof window<"u"&&window.crypto&&(a=window.crypto),typeof self<"u"&&self.crypto&&(a=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(a=globalThis.crypto),!a&&typeof window<"u"&&window.msCrypto&&(a=window.msCrypto),!a&&typeof global<"u"&&global.crypto&&(a=global.crypto),!a&&typeof Mo=="function")try{a=Mo("crypto");}catch{}var r=function(){if(a){if(typeof a.getRandomValues=="function")try{return a.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof a.randomBytes=="function")try{return a.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},o=Object.create||function(){function d(){}return function(y){var v;return d.prototype=y,v=new d,d.prototype=null,v}}(),l={},u=l.lib={},h=u.Base=function(){return {extend:function(d){var y=o(this);return d&&y.mixIn(d),(!y.hasOwnProperty("init")||this.init===y.init)&&(y.init=function(){y.$super.init.apply(this,arguments);}),y.init.prototype=y,y.$super=this,y},create:function(){var d=this.extend();return d.init.apply(d,arguments),d},init:function(){},mixIn:function(d){for(var y in d)d.hasOwnProperty(y)&&(this[y]=d[y]);d.hasOwnProperty("toString")&&(this.toString=d.toString);},clone:function(){return this.init.prototype.extend(this)}}}(),c=u.WordArray=h.extend({init:function(d,y){d=this.words=d||[],y!=i?this.sigBytes=y:this.sigBytes=d.length*4;},toString:function(d){return (d||p).stringify(this)},concat:function(d){var y=this.words,v=d.words,g=this.sigBytes,_=d.sigBytes;if(this.clamp(),g%4)for(var I=0;I<_;I++){var fe=v[I>>>2]>>>24-I%4*8&255;y[g+I>>>2]|=fe<<24-(g+I)%4*8;}else for(var R=0;R<_;R+=4)y[g+R>>>2]=v[R>>>2];return this.sigBytes+=_,this},clamp:function(){var d=this.words,y=this.sigBytes;d[y>>>2]&=4294967295<<32-y%4*8,d.length=n.ceil(y/4);},clone:function(){var d=h.clone.call(this);return d.words=this.words.slice(0),d},random:function(d){for(var y=[],v=0;v<d;v+=4)y.push(r());return new c.init(y,d)}}),f=l.enc={},p=f.Hex={stringify:function(d){for(var y=d.words,v=d.sigBytes,g=[],_=0;_<v;_++){var I=y[_>>>2]>>>24-_%4*8&255;g.push((I>>>4).toString(16)),g.push((I&15).toString(16));}return g.join("")},parse:function(d){for(var y=d.length,v=[],g=0;g<y;g+=2)v[g>>>3]|=parseInt(d.substr(g,2),16)<<24-g%8*4;return new c.init(v,y/2)}},m=f.Latin1={stringify:function(d){for(var y=d.words,v=d.sigBytes,g=[],_=0;_<v;_++){var I=y[_>>>2]>>>24-_%4*8&255;g.push(String.fromCharCode(I));}return g.join("")},parse:function(d){for(var y=d.length,v=[],g=0;g<y;g++)v[g>>>2]|=(d.charCodeAt(g)&255)<<24-g%4*8;return new c.init(v,y)}},S=f.Utf8={stringify:function(d){try{return decodeURIComponent(escape(m.stringify(d)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(d){return m.parse(unescape(encodeURIComponent(d)))}},b=u.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new c.init,this._nDataBytes=0;},_append:function(d){typeof d=="string"&&(d=S.parse(d)),this._data.concat(d),this._nDataBytes+=d.sigBytes;},_process:function(d){var y,v=this._data,g=v.words,_=v.sigBytes,I=this.blockSize,fe=I*4,R=_/fe;d?R=n.ceil(R):R=n.max((R|0)-this._minBufferSize,0);var B=R*I,pe=n.min(B*4,_);if(B){for(var dt=0;dt<B;dt+=I)this._doProcessBlock(g,dt);y=g.splice(0,B),v.sigBytes-=pe;}return new c.init(y,pe)},clone:function(){var d=h.clone.call(this);return d._data=this._data.clone(),d},_minBufferSize:0});u.Hasher=b.extend({cfg:h.extend(),init:function(d){this.cfg=this.cfg.extend(d),this.reset();},reset:function(){b.reset.call(this),this._doReset();},update:function(d){return this._append(d),this._process(),this},finalize:function(d){d&&this._append(d);var y=this._doFinalize();return y},blockSize:16,_createHelper:function(d){return function(y,v){return new d.init(v).finalize(y)}},_createHmacHelper:function(d){return function(y,v){return new x.HMAC.init(d,v).finalize(y)}}});var x=l.algo={};return l}(Math);return t});}),$h=$o((s,e)=>{(function(t,n){typeof s=="object"?e.exports=s=n(Jh()):typeof define=="function"&&define.amd?define(["./core"],n):n(t.CryptoJS);})(s,function(t){return function(){var n=t,i=n.lib,a=i.WordArray,r=i.Hasher,o=n.algo,l=[],u=o.SHA1=r.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(h,c){for(var f=this._hash.words,p=f[0],m=f[1],S=f[2],b=f[3],x=f[4],d=0;d<80;d++){if(d<16)l[d]=h[c+d]|0;else {var y=l[d-3]^l[d-8]^l[d-14]^l[d-16];l[d]=y<<1|y>>>31;}var v=(p<<5|p>>>27)+x+l[d];d<20?v+=(m&S|~m&b)+1518500249:d<40?v+=(m^S^b)+1859775393:d<60?v+=(m&S|m&b|S&b)-1894007588:v+=(m^S^b)-899497514,x=b,b=S,S=m<<30|m>>>2,m=p,p=v;}f[0]=f[0]+p|0,f[1]=f[1]+m|0,f[2]=f[2]+S|0,f[3]=f[3]+b|0,f[4]=f[4]+x|0;},_doFinalize:function(){var h=this._data,c=h.words,f=this._nDataBytes*8,p=h.sigBytes*8;return c[p>>>5]|=128<<24-p%32,c[(p+64>>>9<<4)+14]=Math.floor(f/4294967296),c[(p+64>>>9<<4)+15]=f,h.sigBytes=c.length*4,this._process(),this._hash},clone:function(){var h=r.clone.call(this);return h._hash=this._hash.clone(),h}});n.SHA1=r._createHelper(u),n.HmacSHA1=r._createHmacHelper(u);}(),t.SHA1});}),Uh=Gh($h()),Gt="___param___",Ze=class P{static _beforeToTranslate=void 0;static _translate=e=>e;static _afterToTranslate=void 0;static t(e){return Array.isArray(e)?e.map(t=>P.translate(`${t}`)):P.translate(`${e}`)}static set beforeToTranslate(e){P._beforeToTranslate=e;}static set translate(e){P._translate=e;}static get translate(){return e=>{let t=e;return P._beforeToTranslate&&(t=P._beforeToTranslate(t)),t=P._translate(t),P._afterToTranslate&&(t=P._afterToTranslate(t)),t}}static set afterToTranslate(e){P._afterToTranslate=e;}static addKey(e,t,n){let i=n.defaultValue||"empty_string";typeof t=="string"&&(t=[t]),Array.isArray(t)&&t.forEach(a=>{e[a]===void 0&&(i==="empty_string"?e[a]="":i==="copy_key"&&(P._beforeToTranslate?e[a]=P._beforeToTranslate(a):e[a]=a));});}static getConditionalsThenElse(e,t=[]){if(typeof e=="object"&&e&&"type"in e)if(e.type==="ifelse")e.then&&P.getConditionalsThenElse(e.then,t),e.else&&P.getConditionalsThenElse(e.else,t);else if(e.type==="stepswitch"){if(e.elements)if(Array.isArray(e.elements))e.elements.forEach(n=>{P.getConditionalsThenElse(n,t);});else if(e.elements.type==="ifelse"){let n=[];P.getConditionalsThenElse(e.elements,n),n.forEach(i=>{t.push(...i);});}else if(e.elements.type==="stepswitch"){let n=[];P.getConditionalsThenElse(e.elements,n),n.forEach(i=>{t.push(...i);});}else P.getConditionalsThenElse(e.elements,t);}else e.type==="resulttocombine"?(e.firstItem&&P.getConditionalsThenElse(e.firstItem,t),e.secondConditionalItem&&e.secondConditionalItem.forEach(n=>{P.getConditionalsThenElse(n,t);})):t.push(e);else e&&t.push(e);return t}static generateJsonTranslation(e,t={},n={}){return e.forEach(i=>{if(i.choices){let a=[];Array.isArray(i.choices)?a=[i.choices]:a=P.getConditionalsThenElse(i.choices),a.forEach(r=>r.forEach(o=>{if("type"in o){let l=[];o.type==="ifelse"||o.type==="stepswitch"?P.getConditionalsThenElse(o,l):l=[o],l.map(u=>P.getConditionalsThenElse(u.text)).forEach(u=>{Array.isArray(u)&&u.forEach(h=>{Array.isArray(h)?h.forEach(c=>{typeof c=="string"?P.addKey(t,c,n):P.getConditionalsThenElse(c).forEach(f=>{Array.isArray(f)?f.forEach(p=>{typeof p=="string"&&P.addKey(t,p,n);}):typeof f=="string"&&P.addKey(t,f,n);});}):typeof h=="string"&&P.addKey(t,h,n);});});}}));}if(i.dialogue){let a=[];Array.isArray(i.dialogue)?a=[i.dialogue]:a=P.getConditionalsThenElse(i.dialogue),a.forEach(r=>{typeof r=="string"?P.addKey(t,r,n):"text"in r&&Array.isArray(r.text)&&r.text.forEach(o=>{typeof o=="string"?P.addKey(t,o,n):P.getConditionalsThenElse(o).forEach(l=>{typeof l=="string"?P.addKey(t,l,n):Array.isArray(l)&&l.forEach(u=>{typeof u=="string"?P.addKey(t,u,n):P.getConditionalsThenElse(u).forEach(h=>{typeof h=="string"&&P.addKey(t,h,n);});});});});});}i.conditionalStep&&P.getConditionalsThenElse(i.conditionalStep).forEach(a=>{Array.isArray(a)?P.generateJsonTranslation(a,t,n):P.generateJsonTranslation([a],t,n);});}),t}},os=Ze;function Hh(s,e){return Math.floor(Math.random()*(e-s+1)+s)}function Kh(s){if(Array.isArray(s)||!s)return s;if(s&&typeof s=="object"&&"type"in s)switch(s.type){case"resulttocombine":return zh(s);case"ifelse":return w(s.condition)?w(s.then):w(s.else);case"stepswitch":let e=w(s.elements)||[];if(e.length===0){console.error("[Pixi\u2019VN Json] getValueFromConditionalStatements elements.length === 0");return}switch(s.choiceType){case"random":let t=Hh(0,e.length-1);return w(e[t]);case"loop":let n=pixiVn.NarrationManagerStatic.getCurrentStepTimesCounter(s.nestedId)-1;return n>e.length-1&&(n=n%e.length),w(e[n]);case"sequential":let i,a=pixiVn.NarrationManagerStatic.getCurrentStepTimesCounter(s.nestedId)-1;return s.end=="lastItem"&&(i=w(e[e.length-1])),a>e.length-1?i:w(e[a]);case"sequentialrandom":let r=pixiVn.NarrationManagerStatic.getRandomNumber(0,e.length-1,{nestedId:s.nestedId,onceOnly:!0});if(r==null&&s.end=="lastItem"){let o=pixiVn.NarrationManagerStatic.getCurrentStepTimesCounterData(s.nestedId);if(!o||!o?.usedRandomNumbers){console.warn("[Pixi\u2019VN Json] getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}let l=o.usedRandomNumbers[`0-${e.length-1}`];return w(e[l[l.length-1]])}if(r==null){console.warn("[Pixi\u2019VN Json] getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}return w(e[r])}}return s}function kn(s){if(s.conditionalStep){let e=pixiVn.createExportableElement(w(s.conditionalStep));if(e?.glueEnabled===void 0&&delete e?.glueEnabled,e?.goNextStep===void 0&&delete e?.goNextStep,e?.end===void 0&&delete e?.end,e?.choices===void 0&&delete e?.choices,e?.dialogue===void 0&&delete e?.dialogue,e?.labelToOpen===void 0&&delete e?.labelToOpen,e?.operations===void 0&&delete e?.operations,e){let t={...s,conditionalStep:void 0,...e};return kn(t)}else pixiVn.getFlag(pixiVn.storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)&&pixiVn.setFlag(pixiVn.storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!1);}return s}function zh(s){let e=s.firstItem,t=[];s.secondConditionalItem?.forEach(i=>{if(Array.isArray(i))i.forEach(a=>{let r=w(a);t.push(r);});else {let a=w(i);t.push(a);}});let n=e?[e,...t]:t;if(n.length===0){console.warn("[Pixi\u2019VN Json] combinateResult toCheck.length === 0");return}if(typeof n[0]=="string")return os.t(n).join("");if(typeof n[0]=="object"){let i=n,a,r=i.map((b,x)=>{b=kn(b);let d=w(b.dialogue)||"";return x===0?(a=w(b.glueEnabled)||!1,d):(typeof d=="object"&&"text"in d&&(d=d.character+": "+d.text),a===!1&&(d=`
|
|
45
45
|
|
|
46
|
-
`+d),a=w(b.glueEnabled)||!1,d)}),o=w(r[0]),l=typeof o=="object"&&"character"in o?o.character:void 0,u=r.map(b=>{let x;b&&typeof b=="object"&&"text"in b?x=b.text:x=b;let d;return Array.isArray(x)?d=x.map(y=>{let v=w(y);return os.t(`${v}`)}).join(""):d=w(x)||"",os.t(d)}).join(""),h=i.find(b=>b.end),c=i.find(b=>b.choices),f=!1,p=!1;i.length>0&&(i[0].glueEnabled&&i[0].goNextStep&&i[0].dialogue===void 0&&pixiVn.setFlag(pixiVn.storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!0),f=i[i.length-1].glueEnabled,p=i.reverse().find(b=>!(b.operations&&(!b.dialogue||!b.choices)))?.goNextStep);let m=i.find(b=>b.labelToOpen),S=[];return i.forEach(b=>{b.operations&&S.forEach(x=>{S.push(x);});}),{dialogue:l?{character:l,text:u}:u,end:h?.end,choices:c?.choices,glueEnabled:f,goNextStep:p,labelToOpen:m?.labelToOpen,operations:S}}}function Xh(s){if(!s)return !1;if(typeof s!="object"||!("type"in s))return !!s;switch(s.type){case"compare":let e=w(s.leftValue),t=w(s.rightValue);switch(s.operator){case"==":return e===t;case"!=":return e!==t;case"<":return e<t;case"<=":return e<=t;case">":return e>t;case">=":return e>=t;case"CONTAINS":return e.toString().includes(t.toString())}break;case"valueCondition":return !!w(s.value);case"union":return Qh(s)}return !!s}function Yh(s){if(s&&typeof s=="object"&&"type"in s&&s.type==="value"&&s.storageOperationType==="get")switch(s.storageType){case"storage":case"tempstorage":return pixiVn.storage.getVariable(s.key);case"flagStorage":return pixiVn.getFlag(s.key);case"label":return pixiVn.narration.getTimesLabelOpened(s.label);case"choice":return pixiVn.narration.getTimesChoiceMade(s.index);case"logic":return w(s.operation);case"params":let e=pixiVn.storage.getVariable(`${Gt}${pixiVn.narration.openedLabels.length-1}`)||[];if(e&&e.length>s.key)return e[s.key];console.warn("[Pixi\u2019VN Json] getValue params not found");return}return s}function Qh(s){if(s.unionType==="not")return !w(s.condition);let e=s.unionType==="and";for(let t=0;t<s.conditions.length;t++)if(e=w(s.conditions[t])||!1,s.unionType==="and"){if(!e)return !1}else if(e)return !0;return e}function Zh(s){let e=w(s.value),t;switch(e&&typeof e=="object"&&"type"in e?t=w(e):t=e,s.storageType){case"flagStorage":pixiVn.setFlag(s.key,s.value);break;case"storage":pixiVn.storage.setVariable(s.key,t);break;case"tempstorage":pixiVn.storage.setTempVariable(s.key,t);break;case"params":let n=pixiVn.storage.getVariable(`${Gt}${pixiVn.narration.openedLabels.length-1}`)||[];n&&n.length-1>=s.key&&(n[s.key]=t),pixiVn.storage.setTempVariable(`${Gt}${pixiVn.narration.openedLabels.length-1}`,n);break}}function w(s){let e=Kh(s);if(e&&typeof e=="object"&&"type"in e)switch(e.type){case"value":return Yh(e);case"arithmetic":case"arithmeticsingle":return ec(e);case"compare":case"valueCondition":case"union":return Xh(e)}return e}function ec(s){let e=w(s.leftValue);switch(s.type){case"arithmetic":let t=w(s.rightValue);switch(s.operator){case"*":return e*t;case"/":return e/t;case"+":return e+t;case"-":return e-t;case"%":return e%t;case"POW":return Math.pow(e,t);case"RANDOM":return pixiVn.narration.getRandomNumber(e,t)}case"arithmeticsingle":switch(s.operator){case"INT":return parseInt(e);case"FLOOR":return Math.floor(e);case"FLOAT":return parseFloat(e)}break}}async function tc(s){let e=w(s);if(e)switch(e.type){case"assets":switch(e.operationType){case"load":await pixiVn.Assets.load(e.assets);break}break}}async function us(s,e){let t=w(s);if(t)switch(t.type){case"sound":switch(t.operationType){case"play":pixiVn.sound.play(t.alias,t.props);break;case"stop":pixiVn.sound.stop(t.alias);break;case"pause":pixiVn.sound.pause(t.alias);break;case"resume":pixiVn.sound.resume(t.alias);break;case"volume":pixiVn.sound.volume(t.alias,t.value);break}break;case"assets":switch(t.operationType){case"load":let o=t.assets.map(l=>pixiVn.Assets.load(l));await Promise.all(o);break}break;case"image":switch(t.operationType){case"show":let o=new pixiVn.ImageSprite(t.props,t.url||t.alias);await ls(o,t);break;case"edit":let l=pixiVn.canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Image with alias ${t.alias} not found.`);break;case"remove":Vn(t);break}break;case"video":switch(t.operationType){case"show":let o=new pixiVn.VideoSprite(t.props,t.url||t.alias);await ls(o,t);break;case"edit":let l=pixiVn.canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break;case"remove":Vn(t);break;case"pause":let u=pixiVn.canvas.find(t.alias);u?u.paused=!0:console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break;case"resume":let h=pixiVn.canvas.find(t.alias);h?h.paused=!1:console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break}break;case"imagecontainer":switch(t.operationType){case"show":let o=new pixiVn.ImageContainer(t.props,t.urls);await ls(o,t);break;case"edit":let l=pixiVn.canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] ImageContainer with alias ${t.alias} not found.`);break;case"remove":Vn(t);break}break;case"canvaselement":switch(t.operationType){case"edit":try{let o=pixiVn.canvas.find(t.alias);o?t.props&&(o.memory={...o.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Canvas Element with alias ${t.alias} not found.`);}catch(o){console.error(`[Pixi\u2019VN Json] There was an error while trying to edit the canvas element with alias ${t.alias}.`,o);}break;case"remove":Vn(t);break}break;case"value":Zh(t);break;case"operationtoconvert":if(e){let o="";t.values.forEach(u=>{if(typeof u=="string")o+=u;else {let h=w(u);o+=`${h}`;}});let l=await e(o);l&&await us(l,e);}break;case"input":switch(t.operationType){case"request":pixiVn.narration.requestInput({type:t.valueType},t.defaultValue);break}break;case"fade":let n=new pixiVn.FadeAlphaTicker(t.props,t.duration,t.priority);pixiVn.canvas.addTicker(t.alias,n);break;case"move":let i=new pixiVn.MoveTicker(t.props,t.duration,t.priority);pixiVn.canvas.addTicker(t.alias,i);break;case"rotate":let a=new pixiVn.RotateTicker(t.props,t.duration,t.priority);pixiVn.canvas.addTicker(t.alias,a);break;case"zoom":let r=new pixiVn.ZoomTicker(t.props,t.duration,t.priority);pixiVn.canvas.addTicker(t.alias,r);break;case"shake":await pixiVn.shakeEffect(t.alias,t.props,t.priority);break}}async function ls(s,e){if(e.transition)switch(e.transition.type){case"fade":await pixiVn.showWithFadeTransition(e.alias,s,e.transition.props,e.transition.priority);break;case"dissolve":await pixiVn.showWithDissolveTransition(e.alias,s,e.transition.props,e.transition.priority);break;case"movein":case"moveout":await pixiVn.moveIn(e.alias,s,e.transition.props,e.transition.priority);break;case"zoomin":case"zoomout":await pixiVn.zoomIn(e.alias,s,e.transition.props,e.transition.priority);break;case"pushin":case"pushout":await pixiVn.pushIn(e.alias,s,e.transition.props,e.transition.priority);break}else pixiVn.canvas.add(e.alias,s),await s.load();}function Vn(s){if(s.transition)switch(s.transition.type){case"fade":pixiVn.removeWithFadeTransition(s.alias,s.transition.props,s.transition.priority);break;case"dissolve":pixiVn.removeWithDissolveTransition(s.alias,s.transition.props,s.transition.priority);break;case"movein":case"moveout":pixiVn.moveOut(s.alias,s.transition.props,s.transition.priority);break;case"zoomin":case"zoomout":pixiVn.zoomOut(s.alias,s.transition.props,s.transition.priority);break;case"pushin":case"pushout":pixiVn.pushOut(s.alias,s.transition.props,s.transition.priority);break}else pixiVn.canvas.remove(s.alias);}var nc=class extends pixiVn.LabelAbstract{constructor(s,e,t,n={}){t||(t={}),t.onLoadingLabel=async()=>{for(let i of e){let a;if(typeof i=="function"?a=i():a=i,a=kn(a),a.operations){let r=a.operations.map(o=>tc(o));await Promise.all(r);}}},super(s,t),this._steps=e,this.operationStringConvert=n.operationStringConvert,this.skipEmptyDialogs=n.skipEmptyDialogs||!1;}_steps;get steps(){return this._steps.map(s=>this.stepConverter(s))}operationStringConvert;skipEmptyDialogs=!1;getStepSha1(s){if(s<0||s>=this.steps.length)return;let e=this._steps[s];return (0, Uh.default)(e.toString().toLocaleLowerCase()).toString()}getDialogueText(s){let e="";if(Array.isArray(s)){let t=[];s.forEach(n=>{if(typeof n=="string")t.push(n);else if(n&&typeof n=="object"){let i=w(n);i?(i&&!Array.isArray(i)&&typeof i=="object"&&(i=w(i)||""),Array.isArray(i)?t=t.concat(i):t.push(`${i}`)):t.push(`${n}`);}}),e=t;}else {let t=w(s)||"";t&&!Array.isArray(t)&&typeof t=="object"&&(t=w(t)||""),e=t;}return `${e}`}getDialogue(s){if(s==null)return;let e=w(s);return e==null?"":typeof e=="object"&&"character"in e&&"text"in e?{character:e.character,text:Ze.t(this.getDialogueText(e.text))}:Ze.t(this.getDialogueText(e))}getChoices(s){return w(s)?.map(e=>w(e)).filter(e=>e!==void 0)}stepConverter(s){return async e=>{let t;if(typeof s=="function"?t=s():t=s,t=kn(t),t.operations)for(let u of t.operations)await us(u,this.operationStringConvert?h=>this.operationStringConvert(h,t,e):void 0);let n=this.getChoices(t.choices),i=w(t.glueEnabled),a=this.getDialogue(t.dialogue),r=[];t.labelToOpen&&(Array.isArray(t.labelToOpen)||(t.labelToOpen=[t.labelToOpen]),t.labelToOpen.forEach(u=>{let h=w(u);h&&r.push(h);}));let o=w(t.goNextStep),l=w(t.end);if(n){let u=n.map(h=>{let c="";if(Array.isArray(h.text)){let f=[];h.text.forEach(p=>{if(typeof p=="string")f.push(Ze.t(p));else if(p&&typeof p=="object"){let m=w(p);m&&!Array.isArray(m)&&typeof m=="object"&&(m=w(m)||""),m&&(Array.isArray(m)?f=f.concat(Ze.t(m)):f.push(Ze.t(m)));}}),c=f.join();}else typeof h.text=="string"&&(c=Ze.t(h.text));return new pixiVn.ChoiceMenuOption(c,h.label,h.props,{type:h.type,oneTime:h.oneTime,onlyHaveNoChoice:h.onlyHaveNoChoice,autoSelect:h.autoSelect})});pixiVn.narration.choiceMenuOptions=u;}else pixiVn.narration.choiceMenuOptions=void 0;a!==void 0&&(pixiVn.narration.dialogue=a,this.skipEmptyDialogs&&typeof a=="string"&&(a===""||RegExp(/^\s+$/).test(a))&&(o=!0)),i?pixiVn.setFlag(pixiVn.storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!0):i===!1&&pixiVn.setFlag(pixiVn.storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!1);for(let u of r){let h=u.label;typeof h=="object"&&(h=w(h)||"");let c=u.params?.map(f=>w(f));e={...e,...u.props},u.type==="jump"?(pixiVn.narration.closeCurrentLabel(),pixiVn.storage.setTempVariable(`${Gt}${pixiVn.narration.openedLabels.length}`,c),await pixiVn.narration.callLabel(h,e)):(pixiVn.storage.setTempVariable(`${Gt}${pixiVn.narration.openedLabels.length}`,c),await pixiVn.narration.callLabel(h,e));}l==="game_end"?(pixiVn.narration.closeAllLabels(),await pixiVn.narration.goNext(e)):l==="label_end"&&pixiVn.narration.closeCurrentLabel(),o&&await pixiVn.narration.goNext(e);}}};function Uo(s,e={}){let t=e?.operationStringConvert;try{typeof s=="string"&&(s=JSON.parse(s));}catch(n){console.error("[Pixi\u2019VN Json] Error parsing imported Pixi'VN JSON",n);return}if(typeof s!="object"){console.error("[Pixi\u2019VN Json] Error parsing imported Pixi'VN JSON: data is not an object");return}if(s.initialOperations){for(let n of s.initialOperations)us(n,t?i=>t(i,{},{}):void 0);pixiVn.StorageManagerStatic.saveStorageAsBasicStorage();}if(s.labels){let n=s.labels;for(let i in n)try{let a=n[i],r=new nc(i,a,void 0,e);pixiVn.saveLabel(r);}catch(a){console.error(`[Pixi\u2019VN Json] Error creating JSON label ${i}`,a);}}}var Ho="\xA7SPACE\xA7",Ko="\xA7DOUBLE_QUOTES\xA7",zo="\xA7QUOTES\xA7",Xo="SPECIAL_\xA7QUOTES\xA7",Yo="\xA7CURLY_BRACKETS1\xA7",Qo="\xA7CURLY_BRACKETS2\xA7",ic=["add","play","pause","resume","remove","volume"],Jt=class s{static _customHashtagScript=e=>!1;static runCustomHashtagScript(e,t){return s._customHashtagScript(e,t,s.convertListStringToObj)}static set customHashtagScript(e){s._customHashtagScript=e;}static async generateOrRunOperationFromHashtagScript(e,t,n){try{e=e.replaceAll('\\"',Ko),e=e.replaceAll("\\'",zo),e=e.replaceAll("\\`",Xo),e=e.replaceAll("\\{",Yo),e=e.replaceAll("\\}",Qo),e=e.replaceAll("{"," { "),e=e.replaceAll("}"," } "),e=e.replaceAll(Yo,"{"),e=e.replaceAll(Qo,"}");let i=[],a,r="";for(let u=0;u<e.length;u++){let h=e[u];h==='"'||h==="'"||h==="`"?a===void 0?(i.push(r),r="",a=h,r+=h):a===h?(a=void 0,r+=h,i.push(r),r=""):r+=h:r+=h;}if(r!==""&&i.push(r),i.forEach((u,h)=>{h%2===1&&(i[h]=u.replaceAll(" ",Ho));}),e=i.join(""),i=e.split(" ").filter(u=>u!==""),i=i.map(u=>u.replaceAll(Ho," ").replaceAll(Ko,'"').replaceAll(zo,"'").replaceAll(Xo,"`")),s.runCustomHashtagScript(i,n))return;let o=i.length>1?s.removeExtraDoubleQuotes(i[1]):"",l=i.length>0?s.removeExtraDoubleQuotes(i[0]):"";switch(o){case"image":case"imagecontainer":case"canvaselement":case"video":return o==="video"&&(l==="pause"||l==="resume")?{type:"video",operationType:l,alias:s.removeExtraDoubleQuotes(i[2])}:s.getCanvasOperationFromComment(i,o);case"sound":return s.getSoundOperationFromComment(i);case"input":if(l==="request"){let u={type:"input",operationType:"request"};if(i.length>2)try{let h=i.slice(2),c=s.convertListStringToObj(h);"type"in c&&typeof c.type=="string"&&(u.valueType=c.type),"default"in c&&(u.defaultValue=c.default);}catch{}return u}case"assets":if(l==="load")return {type:"assets",operationType:"load",assets:i.slice(2)};default:if(o)switch(l){case"call":case"jump":t.labelToOpen={label:o,type:l},t.goNextStep=void 0;break;case"fade":case"move":case"rotate":case"zoom":case"shake":let u={};if(i.length>2)try{u=s.convertListStringToObj(i.slice(2));}catch{}if(l=="move"&&!("destination"in u)&&(!("x"in u)||!("y"in u))){console.error("[Pixi\u2019VN Ink] The move operation must have a x and y or destination property",e);return}else l=="move"&&"x"in u&&"y"in u&&(u.destination={x:u.x,y:u.y},delete u.x,delete u.y);return {alias:o,type:l,props:u}}else switch(l){case"pause":"dialogue"in t&&delete t.dialogue,"goNextStep"in t&&delete t.goNextStep;break}}}catch(i){throw console.error("[Pixi\u2019VN Ink] Error parsing ink hashtag-script",e),i}}static getCanvasOperationFromComment(e,t){let n=s.removeExtraDoubleQuotes(e[0]),i=s.removeExtraDoubleQuotes(e[2]),a=s.convertListStringToPropList(e.slice(3));switch(n){case"show":switch(t){case"image":case"video":return s.getImageOperationFromComment(t,i,a);case"imagecontainer":return s.getContainerOperationFromComment(t,i,a);case"canvaselement":default:console.error("[Pixi\u2019VN Ink] This show operation is not valid for this type of element",t);}case"edit":return {type:t,operationType:"edit",alias:i,props:s.convertPropListStringToObj(a)};case"remove":let o={type:t,operationType:"remove",alias:i};if(a.length>1&&a[0]==="with"){let l=e[e.indexOf("with")+1],u=e.slice(e.indexOf("with")+2),h=s.getTransition(l,u);h!==void 0&&(o.transition=h);}return o;default:console.error("[Pixi\u2019VN Ink] The operation type is not valid",n);}}static getImageOperationFromComment(e,t,n){let i,a;n.length%2===0?(i=t,a=n):(i=s.removeExtraDoubleQuotes(n[0]),a=s.convertListStringToPropList(n.slice(1)));let r={type:e,operationType:"show",alias:t,url:i};return s.setShowProps(r,a)}static getContainerOperationFromComment(e,t,n){let i=[],a=n.findIndex(u=>u.startsWith("[")),r=n.findIndex(u=>u.endsWith("]"));if(a===-1||r===-1){console.error("[Pixi\u2019VN Ink] show imagecontainer must have a list of image ulrs",n);return}if(i=n.slice(a,r+1),i.length<2){console.error("[Pixi\u2019VN Ink] show imagecontainer must have a list of image ulrs",n);return}i[0]==="["?i.shift():i[0]=i[0].substring(1),i[i.length-1]==="]"?i.pop():i[i.length-1]=i[i.length-1].substring(0,i[i.length-1].length-1);let o={type:e,operationType:"show",alias:t,urls:i.map(u=>s.removeExtraDoubleQuotes(u))},l=s.convertListStringToPropList(n.slice(r+1));return s.setShowProps(o,l)}static getSoundOperationFromComment(e){let t=s.removeExtraDoubleQuotes(e[0]);if(!ic.includes(t))return;let n=s.removeExtraDoubleQuotes(e[2]);switch(t){case"play":let i={type:"sound",operationType:"play",alias:n};if(e.length>3){let u=s.getSoundPlayOptions(e.slice(3));u!==void 0&&(i.props=u);}return i;case"pause":case"resume":return {type:"sound",operationType:t,alias:n};case"stop":case"remove":return {type:"sound",operationType:"stop",alias:n};case"volume":let o=parseFloat(e[3]);return {type:"sound",operationType:"volume",alias:n,value:o}}}static setShowProps(e,t){if(t.length>0){if(t.includes("with")&&t.length>t.indexOf("with")+1){let n=t[t.indexOf("with")+1],i=t.slice(t.indexOf("with")+2);t=t.slice(0,t.indexOf("with"));let a=s.getTransition(n,i);a!==void 0&&(e.transition=a);}if(t.length>0){let n=s.convertListStringToObj(t);e.props=n;}}return e}static getTransition(e,t){switch(e){case"dissolve":case"fade":case"movein":case"moveout":case"zoomin":case"zoomout":case"pushin":case"pushout":break;default:return}let n={type:e};if(t.length>0)try{let i=s.convertPropListStringToObj(t);n.props=i;}catch{}return n}static getSoundOption(e){try{return s.convertListStringToObj(e)}catch{return}}static getSoundPlayOptions(e){try{return s.convertListStringToObj(e)}catch{return}}static convertListStringToObj(e){let t=s.convertListStringToPropList(e);return s.convertPropListStringToObj(t)}static convertListStringToPropList(e){let t=[],n=0,i="";for(let a=0;a<e.length;a++){let r=e[a];r.startsWith("{")?(n++,i+=r):r.endsWith("}")&&n>0?(n--,i+=r,n===0&&(t.push(i),i="")):n>0?i+=r:t.push(r);}return t}static convertPropListStringToObj(e){if(e.length%2!==0)throw console.error("[Pixi\u2019VN Ink] The props list must have a pair number of elements",e),new Error("[Pixi\u2019VN Ink] The props list must have a pair number of elements");let t="{";e.forEach((n,i)=>{if(i%2===0)t+=`"${n}": `;else {switch(n){case"null":case"undefined":case"true":case"false":t+=`${n}`;break;default:s.containExtraDoubleQuotes(n)?(n=s.removeExtraDoubleQuotes(n),t+=`"${n}"`):n.startsWith("{")&&n.endsWith("}")?t+=`${n}`:n.startsWith('"')&&n.endsWith('"')?t+=`${n}`:isNaN(parseFloat(n))?t+=`"${n}"`:t+=`${n}`;}i<e.length-1&&(t+=", ");}}),t+="}";try{return JSON.parse(t)}catch(n){throw console.error("[Pixi\u2019VN Ink] Error parsing ink json",t),n}}static removeExtraDoubleQuotes(e){return e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")||e.startsWith("`")&&e.endsWith("`")?e.substring(1,e.length-1):e}static containExtraDoubleQuotes(e){return !!(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")||e.startsWith("`")&&e.endsWith("`"))}};var sh=fh($u());var L="_|_",rs="global decl",Xe="___external_value___";function An(s,e){if(new RegExp(/.*\.[0-9]+\..*$/).test(s)&&(s=s.split(".").filter(i=>!i.match(/^[0-9]+$/)).join("."),!s.startsWith(".")))return s.replaceAll(".",L);if(!new RegExp(/^\.\^.*$/).test(s)&&s.includes("g-")){let n=s.split("g-");return Io(e)+L+"g-"+n[n.length-1]}let t=0;for(;new RegExp(/^\.\^.*$/).test(s);)t++,s=s.substring(2);if(t=t-1,new RegExp(/^\..*$/).test(s)&&e){let n=s.substring(1);return Io(e,t)+L+n.replaceAll(".",L)}return s.replaceAll(".",L)||Io(e,t).replaceAll(".",L)}function Io(s,e=0){let t=s.split(L);for(;t.length>1&&e>0;)t.pop()?.includes("g-")&&e--,e--;return t.join(L)}var Uu="\xA7DOUBLE_SLASH_CONVERTOR\xA7";function Re(s){return s.startsWith("^")&&(s=s.substring(1)),s=s.replaceAll("\\\\",Uu),s=s.replaceAll("\\n",`
|
|
47
|
-
`),s=s.replaceAll("\\t"," "),s=s.replaceAll(" "," "),s=s.replaceAll(Uu,"\\\\"),s}var Hu=["+","-","/","*","%","_","==",">","<",">=","<=","!=","!","&&","||","MIN","MAX"],Ku=["+","-","/","*","%","POW","RANDOM"],zu=["INT","FLOOR","FLOAT"],Xu=["==",">","<",">=","<=","!=","CONTAINS"];function Lt(s,e,t){s=s.map(i=>{if(typeof i=="string"){if(i==="rnd")return "RANDOM";if(i==="?")return "CONTAINS"}return i});let n=[];return s.forEach(i=>{if(typeof i=="object"&&"CNT?"in i)if(new RegExp(/.*\.[0-9]\..*/).test(i["CNT?"])){let a=i["CNT?"].split("."),r=a.pop(),o=a.pop();if(o===void 0||r===void 0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);return}let l=parseInt(o),u=a.join(".");if(u.includes("^.")){let h=u.split("."),c=h[h.length-1].replaceAll(".",L);h.pop(),u=h.join(".")+"."+c,r.includes("c-")&&(u=u+L+r);}else u=u.replaceAll(".",L);n.push({type:"compare",leftValue:Yu(An(u,e)),operator:">=",rightValue:{type:"value",value:l}});}else n.push(Yu(An(i["CNT?"],e)));else if(typeof i=="object"&&"VAR?"in i)n.push(Wt(i["VAR?"],t));else if(i==="&&"||i==="||"){if(n.length>=2){let a={type:"union",unionType:i==="&&"?"and":"or",conditions:[n[n.length-2],n[n.length-1]]};n.pop(),n.pop(),n.push(a);}}else if(i==="!")if(n.length===0)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"union",unionType:"not",condition:n[n.length-1]};n[n.length-1]=a;}else if(i&&typeof i=="string"&&Xu.includes(i))if(n.length<2)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"compare",operator:i,rightValue:n[n.length-1],leftValue:n[n.length-2]};n.pop(),n.pop(),n.push(a);}else if(i&&typeof i=="string"&&Ku.includes(i))if(n.length<2)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"arithmetic",operator:i,rightValue:n[n.length-1],leftValue:n[n.length-2]};n.pop(),n.pop(),n.push(a);}else if(i&&typeof i=="string"&&zu.includes(i)){let a={type:"arithmeticsingle",operator:i,leftValue:n[n.length-1]};n.pop(),n.push(a);}else i&&typeof i=="string"?i.startsWith("^")&&n.push(Re(i)):typeof i=="object"&&"^->"in i?i["^->"].includes("$r")||n.push(i["^->"]):n.push(i);}),n}function Yu(s){return {type:"value",storageType:"label",storageOperationType:"get",label:s}}function Qu(s,e,t){return Lt(s,e,t)}function Wt(s,e,t="storage"){let n=e.indexOf(s);return n>=0?{type:"value",storageType:"params",storageOperationType:"get",key:n}:{type:"value",storageOperationType:"get",storageType:t,key:s}}function Fo(s,e,t,n="storage"){let i=e.indexOf(s);return i>=0?{type:"value",storageType:"params",storageOperationType:"set",key:i,value:t}:{type:"value",storageOperationType:"set",storageType:n,key:s,value:t}}function ss(s,e){e&&(typeof e=="string"?e.startsWith("^")&&s.push(Re(e)):typeof e=="object"&&"type"in e&&e.type!=="value"&&s.push(e));}function Vo(s,e,t,n,i=!0,a=!1){return zg(s,e,t,n,i,a)}function zg(s,e,t,n,i,a=!1){if(e){if(a)Array.isArray(e)&&e.length>0&&s.push({operations:[{type:"operationtoconvert",values:e}],goNextStep:!0});else if(typeof e=="string"&&e.startsWith("^")||e&&typeof e=="object"&&"type"in e&&e.type=="value"&&e.storageOperationType==="get"){if(!i&&s.length>0){let r=s[s.length-1];!r.glueEnabled&&!r.operations&&(r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0)),s[s.length-1]=r;}typeof e=="string"?s.push(Xg(Re(e))):s.push({dialogue:e});}else if(typeof e=="string"){if(e==="end")s.push({end:"game_end"});else if(e==="done")s.push({end:"label_end",goNextStep:!0});else if(e=="<>")if(s.length>0){let r=s[s.length-1];r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0),s[s.length-1]=r;}else s.push({glueEnabled:!0,goNextStep:!0});}else if(typeof e=="object"){if("type"in e&&e.type!=="value"){if(!i&&s.length>0){let r=s[s.length-1];!r.glueEnabled&&!r.operations&&(r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0)),s[s.length-1]=r;}s.push({conditionalStep:e});}else if("->"in e){let r=i?void 0:!0;if(!i&&s.length>0){let o=s[s.length-1];o.labelToOpen||(o.goNextStep=!0),s[s.length-1]=o;}if(e.params&&e.params.length===0&&(e.params=void 0),e.var)s.push({labelToOpen:{label:Wt(e["->"],n),type:"jump",params:e.params},glueEnabled:r});else {let o=An(e["->"],t);s.push({labelToOpen:{label:o,type:"jump",params:e.params},glueEnabled:r});}}"type"in e&&e.type=="value"&&e.storageOperationType==="set"&&(typeof e.value=="string"&&e.value.startsWith("^")&&(e.value=Re(e.value)),s.push({goNextStep:!0,operations:[e]}));}}}function Xg(s){let e;if(s.includes(": ")){let t=s.split(": "),n=t[0],i=t[1];pixiVn.getCharacterById(n)&&(e=n,s=i);}return e?{dialogue:{character:e,text:s}}:{dialogue:s}}function ko(s,e,t,n=!0,i=!1){return Yg(s,e,t,n,i)}function Yg(s,e,t,n,i=!1){e&&(typeof e=="string"&&e.startsWith("^")||e&&typeof e=="object"&&"type"in e&&e.type=="value"&&e.storageOperationType==="get"?typeof e=="string"?s.push(Re(e)):s.push(e):typeof e=="object"&&"type"in e&&s.push(e));}function as(s,e,t){if(s.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Arithmetic statement is not valid",s);return}let n=Lt(s,e,t);if(n.length===1){let i=n[0];return i&&typeof i=="object"&&"type"in i?{type:"value",storageType:"logic",storageOperationType:"get",operation:i}:i}}function qt(s,e,t,n="",i,a,r=void 0){let o=[],l="sequential",u=!1,h=!0;s.forEach(p=>{p==="%"&&(l="loop"),p==="seq"&&(l="random"),p==="MIN"&&(u=!0);});let c=s[s.length-1];return Object.keys(c).forEach(p=>{let m=c[p];if(Array.isArray(m)&&m.length>3){m=m.slice(1,m.length-2);let S=[];Ye(m,n,i,S,e,e,t,jt,r,!0,a),S.length===1?o.push(S[0]):o.push({type:"resulttocombine",combine:"cross",secondConditionalItem:S});}else Array.isArray(m)&&m.length===3&&(h=!1);}),l==="sequential"?{type:"stepswitch",elements:o,choiceType:l,end:h?"lastItem":void 0,nestedId:r}:u&&l==="random"?{type:"stepswitch",elements:o,choiceType:"sequentialrandom",end:h?"lastItem":void 0,nestedId:r}:{type:"stepswitch",elements:o,choiceType:l}}function Ro(s="",e=""){let t=Array.isArray(s)?s:[s],n=Array.isArray(e)?e:[e];return [...new Set([...t,...n])]}function jt(s,e,t,n,i){if(s.length>0){let a={};Zu(s,a,i);for(let[r,o]of Object.entries(a)){let l=t+L+r,u={text:o.text.length===1?o.text[0]:o.text,label:l,props:{},type:"jump",oneTime:o.onetime};o.text.length===0&&(u.onlyHaveNoChoice=!0,u.autoSelect=!0),u.oneTime===!1&&delete u.oneTime;let h=Do(u,o.conditions,i,t)||u,c=e[e.length-1];if(typeof c=="object"&&c&&"type"in c&&(c={conditionalStep:c}),e.length>0&&typeof c=="object"&&c&&"choices"in c&&c.choices){let f=c.choices;f&&Array.isArray(f)?f.push(h):console.error("[Pixi\u2019VN Ink] Unhandled case: choices is PixiVNJsonConditionalStatements<PixiVNJsonChoices> | undefined",o,f),c.choices=f.sort((p,m)=>{try{let S=p.label.split("."),b=S[S.length-1].replaceAll(".",L),x=m.label.split("."),d=x[x.length-1].replaceAll(".",L);if(b.includes("c-")&&d.includes("c-")){let y=b.split("c-")[1],v=parseInt(y),g=d.split("c-")[1],_=parseInt(g);return v-_}}catch{}return 0});}else e.push({choices:[h]});o.preDialog&&(n.preDialog[l]={...o.preDialog});}}}function Zu(s,e,t,n){let i=[],a="",r="",o=!1,l=[];for(let u=0;u<s.length;u++){let h=s[u];if(typeof h=="string")h.startsWith("^")?i.push(Re(h)):Hu.includes(h)&&l.push(h);else if(Array.isArray(h)&&h.includes("visit")){let c=qt(h,ss,(f,p,m)=>{},n,{preDialog:{}},t);i.push(c);}else if(h&&typeof h=="object")if("*"in h&&typeof h["*"]&&typeof h["*"]=="string")h["*"].includes("c")&&(a="c"+h["*"].split("c")[1],h.flg&16&&(o=!0));else if("s"in h&&h.s instanceof Array){let c=eh(h.s),f=h.s.includes("<>");c&&(n&&e[n]?(e[n].preDialog={text:c,glue:f},e[n].text=Ro(c,e[n].text)):(i.push(c),r=c));}else "CNT?"in h&&l.push(h);else l.push(h);if(a){e[a]?e[a].text=Ro(i,e[a].text):e[a]={text:i,onetime:o,conditions:l},r&&(e[a].preDialog={text:r,glue:!1});let c=s.slice(u+1);Zu(c,e,t,a);return}}}function eh(s){for(let e of s)if(typeof e=="string"){if(e.startsWith("^"))return Re(e)}else if(e instanceof Array){let t=eh(e);if(t)return t}}function Do(s,e,t,n,i){if(e.length===0)return;let a=Lt(e,n,t);if(a.length===1){let r={type:"ifelse",condition:a[0],then:s,else:i};return r.else||delete r.else,r}else if(a.length>1){let r={type:"ifelse",condition:{type:"union",unionType:"and",conditions:a},then:s,else:i};return r.else||delete r.else,r}}function th(s,e,t,n,i,a,r=void 0){if(s.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);return}let o=[],l=[];if(s.forEach(c=>{Array.isArray(c)?l.push(c):typeof c=="string"&&c==="du"?i.du?o.push(i.du):i.du=o[o.length-1]:(typeof c!="string"||c!=="/ev")&&o.push(c);}),l.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",l);return}let u=Lo(l[0],e,t,n+L+"then",i,a,`${r||""}then`),h;return l.length===2?h=Lo(l[1],e,t,n+L+"else",i,a,`${r||""}else`):l.length>2&&(l.shift(),l.push("nop"),l=[{b:l}],h=Lo(l,e,t,n+L+"else",i,a,`${r||""}else`)),i.du=void 0,Do(u,o,a,n,h)}function Lo(s,e,t,n,i,a,r=void 0){let o=[];for(let u of s)typeof u=="object"&&"b"in u&&(u.b=u.b.filter(h=>h!==null&&!(typeof h=="object"&&"->"in h&&new RegExp(/.*\.[0-9]/).test(h["->"]))),Ye(u.b,n,i,o,e,e,t,jt,r,!0,a));return o.length===1?o[0]:{type:"resulttocombine",combine:"cross",secondConditionalItem:o}}function Ye(s,e,t,n=[],i,a,r,o,l=void 0,u=!0,h=[]){let c=!1,f=[],p=!1,m=!1,S=[],b=[];if(t.preDialog[e]&&(u=!1,i(n,"^"+t.preDialog[e].text,e,h,u,m),t.preDialog[e].glue&&i(n,"<>",e,h,u,m),delete t.preDialog[e]),s.includes("visit")){let d=qt(s,a,r,e,t,h,l);d&&(!u&&n.length>0&&i(n,"<>",e,h,u,m),i(n,d,e,h,u,m));return}let x=s[0];if(x&&typeof x=="object"&&"temp="in x){for(;s[0]&&typeof s[0]=="object"&&"temp="in s[0];)h.push(s[0]["temp="]),s.shift();h=h.reverse();}if(s.forEach((d,y)=>{if(m){if(typeof d=="string"&&d=="/#"){let v=[];Ye(b,e,t,v,ko,ko,r,o,l,u),i(n,v,e,h,u,m),m=!1,b=[];}else b.push(d);return}else if(c)if(Array.isArray(d))f.push(d);else if(d&&typeof d=="object")if("CNT?"in d)y>0&&s[y-1]=="ev"?(p=!0,S.push(d)):p?S.push(d):(f.push(d),u=!1);else if("VAR="in d||"temp="in d){let v=Fo("VAR="in d?d["VAR="]:d["temp="],h,s[y-1],"VAR="in d?"storage":"tempstorage");if(v.value&&typeof v.value=="string"&&v.value=="/str"&&(v.value=s[y-2]),v.value&&typeof v.value=="object"&&"^->"in v.value&&(v.value=v.value["^->"]),f.length>1){let g=as(f,e,h);f=[],g&&typeof g=="object"&&"type"in g&&g.type=="value"&&"storageType"in g&&g.storageType=="logic"&&(v.value=g.operation);}(typeof v.key!="string"||!v.key.includes("$r"))&&(i(n,v,e,h,u,m),u=!0);}else "VAR?"in d?f.push(d):"^->"in d&&(d["^->"].includes("$r")||f.push(d));else if(typeof d=="string"&&d=="/ev")p&&S.push(d),c=!1,f.push(d);else if(typeof d=="string"&&d=="out"){if(f.length>0){let v=f[f.length-1];if(v&&typeof v=="object"&&"VAR?"in v){f.pop();let g=Wt(v["VAR?"],h,"storage");i(n,g,e,h,u,m);}else {let g=[];for(;f.length>0&&f[f.length-1]!="/ev";)g.push(f.pop());g=g.reverse();let _=as(g,e,h);f=[],_&&typeof _=="object"&&"type"in _&&_.type=="value"&&"storageType"in _&&_.storageType=="logic"?i(n,{storageOperationType:"get",storageType:"logic",operation:_.operation,type:"value"},e,h,u,m):(i(n,"<>",e,h,u,m),_=`^${_}`,i(n,_,e,h,u,m));}u=!1;}}else f.push(d);else if(typeof d=="string")if(d.startsWith("^"))i(n,d,e,h,u,m),u=!1;else if(d=="ev")c=!0;else if(d==`
|
|
46
|
+
`+d),a=w(b.glueEnabled)||!1,d)}),o=w(r[0]),l=typeof o=="object"&&"character"in o?o.character:void 0,u=r.map(b=>{let x;b&&typeof b=="object"&&"text"in b?x=b.text:x=b;let d;return Array.isArray(x)?d=x.map(y=>{let v=w(y);return os.t(`${v}`)}).join(""):d=w(x)||"",os.t(d)}).join(""),h=i.find(b=>b.end),c=i.find(b=>b.choices),f=!1,p=!1;i.length>0&&(i[0].glueEnabled&&i[0].goNextStep&&i[0].dialogue===void 0&&pixiVn.setFlag(pixiVn.storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!0),f=i[i.length-1].glueEnabled,p=i.reverse().find(b=>!(b.operations&&(!b.dialogue||!b.choices)))?.goNextStep);let m=i.find(b=>b.labelToOpen),S=[];return i.forEach(b=>{b.operations&&S.forEach(x=>{S.push(x);});}),{dialogue:l?{character:l,text:u}:u,end:h?.end,choices:c?.choices,glueEnabled:f,goNextStep:p,labelToOpen:m?.labelToOpen,operations:S}}}function Xh(s){if(!s)return !1;if(typeof s!="object"||!("type"in s))return !!s;switch(s.type){case"compare":let e=w(s.leftValue),t=w(s.rightValue);switch(s.operator){case"==":return e===t;case"!=":return e!==t;case"<":return e<t;case"<=":return e<=t;case">":return e>t;case">=":return e>=t;case"CONTAINS":return e.toString().includes(t.toString())}break;case"valueCondition":return !!w(s.value);case"union":return Qh(s)}return !!s}function Yh(s){if(s&&typeof s=="object"&&"type"in s&&s.type==="value"&&s.storageOperationType==="get")switch(s.storageType){case"storage":case"tempstorage":return pixiVn.storage.getVariable(s.key);case"flagStorage":return pixiVn.getFlag(s.key);case"label":return pixiVn.narration.getTimesLabelOpened(s.label);case"choice":return pixiVn.narration.getTimesChoiceMade(s.index);case"logic":return w(s.operation);case"params":let e=pixiVn.storage.getVariable(`${Gt}${pixiVn.narration.openedLabels.length-1}`)||[];if(e&&e.length>s.key)return e[s.key];console.warn("[Pixi\u2019VN Json] getValue params not found");return}return s}function Qh(s){if(s.unionType==="not")return !w(s.condition);let e=s.unionType==="and";for(let t=0;t<s.conditions.length;t++)if(e=w(s.conditions[t])||!1,s.unionType==="and"){if(!e)return !1}else if(e)return !0;return e}function Zh(s){let e=w(s.value),t;switch(e&&typeof e=="object"&&"type"in e?t=w(e):t=e,s.storageType){case"flagStorage":pixiVn.setFlag(s.key,s.value);break;case"storage":pixiVn.storage.setVariable(s.key,t);break;case"tempstorage":pixiVn.storage.setTempVariable(s.key,t);break;case"params":let n=pixiVn.storage.getVariable(`${Gt}${pixiVn.narration.openedLabels.length-1}`)||[];n&&n.length-1>=s.key&&(n[s.key]=t),pixiVn.storage.setTempVariable(`${Gt}${pixiVn.narration.openedLabels.length-1}`,n);break}}function w(s){let e=Kh(s);if(e&&typeof e=="object"&&"type"in e)switch(e.type){case"value":return Yh(e);case"arithmetic":case"arithmeticsingle":return ec(e);case"compare":case"valueCondition":case"union":return Xh(e)}return e}function ec(s){let e=w(s.leftValue);switch(s.type){case"arithmetic":let t=w(s.rightValue);switch(s.operator){case"*":return e*t;case"/":return e/t;case"+":return e+t;case"-":return e-t;case"%":return e%t;case"POW":return Math.pow(e,t);case"RANDOM":return pixiVn.narration.getRandomNumber(e,t)}case"arithmeticsingle":switch(s.operator){case"INT":return parseInt(e);case"FLOOR":return Math.floor(e);case"FLOAT":return parseFloat(e)}break}}async function tc(s){let e=w(s);if(e)switch(e.type){case"assets":switch(e.operationType){case"load":await pixiVn.Assets.load(e.assets);break}break}}async function us(s,e){let t=w(s);if(t)switch(t.type){case"sound":switch(t.operationType){case"play":pixiVn.sound.play(t.alias,t.props);break;case"stop":pixiVn.sound.stop(t.alias);break;case"pause":pixiVn.sound.pause(t.alias);break;case"resume":pixiVn.sound.resume(t.alias);break;case"volume":pixiVn.sound.volume(t.alias,t.value);break}break;case"assets":switch(t.operationType){case"load":let o=t.assets.map(l=>pixiVn.Assets.load(l));await Promise.all(o);break}break;case"image":switch(t.operationType){case"show":let o=new pixiVn.ImageSprite(t.props,t.url||t.alias);await ls(o,t);break;case"edit":let l=pixiVn.canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Image with alias ${t.alias} not found.`);break;case"remove":Vn(t);break}break;case"video":switch(t.operationType){case"show":let o=new pixiVn.VideoSprite(t.props,t.url||t.alias);await ls(o,t);break;case"edit":let l=pixiVn.canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break;case"remove":Vn(t);break;case"pause":let u=pixiVn.canvas.find(t.alias);u?u.paused=!0:console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break;case"resume":let h=pixiVn.canvas.find(t.alias);h?h.paused=!1:console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break}break;case"imagecontainer":switch(t.operationType){case"show":let o=new pixiVn.ImageContainer(t.props,t.urls);await ls(o,t);break;case"edit":let l=pixiVn.canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] ImageContainer with alias ${t.alias} not found.`);break;case"remove":Vn(t);break}break;case"canvaselement":switch(t.operationType){case"edit":try{let o=pixiVn.canvas.find(t.alias);o?t.props&&(o.memory={...o.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Canvas Element with alias ${t.alias} not found.`);}catch(o){console.error(`[Pixi\u2019VN Json] There was an error while trying to edit the canvas element with alias ${t.alias}.`,o);}break;case"remove":Vn(t);break}break;case"value":Zh(t);break;case"operationtoconvert":if(e){let o="";t.values.forEach(u=>{if(typeof u=="string")o+=u;else {let h=w(u);o+=`${h}`;}});let l=await e(o);l&&await us(l,e);}break;case"input":switch(t.operationType){case"request":pixiVn.narration.requestInput({type:t.valueType},t.defaultValue);break}break;case"fade":let n=new pixiVn.FadeAlphaTicker(t.props,t.duration,t.priority);pixiVn.canvas.addTicker(t.alias,n);break;case"move":let i=new pixiVn.MoveTicker(t.props,t.duration,t.priority);pixiVn.canvas.addTicker(t.alias,i);break;case"rotate":let a=new pixiVn.RotateTicker(t.props,t.duration,t.priority);pixiVn.canvas.addTicker(t.alias,a);break;case"zoom":let r=new pixiVn.ZoomTicker(t.props,t.duration,t.priority);pixiVn.canvas.addTicker(t.alias,r);break;case"shake":await pixiVn.shakeEffect(t.alias,t.props,t.priority);break}}async function ls(s,e){if(e.transition)switch(e.transition.type){case"fade":await pixiVn.showWithFadeTransition(e.alias,s,e.transition.props,e.transition.priority);break;case"dissolve":await pixiVn.showWithDissolveTransition(e.alias,s,e.transition.props,e.transition.priority);break;case"movein":case"moveout":await pixiVn.moveIn(e.alias,s,e.transition.props,e.transition.priority);break;case"zoomin":case"zoomout":await pixiVn.zoomIn(e.alias,s,e.transition.props,e.transition.priority);break;case"pushin":case"pushout":await pixiVn.pushIn(e.alias,s,e.transition.props,e.transition.priority);break}else pixiVn.canvas.add(e.alias,s),await s.load();}function Vn(s){if(s.transition)switch(s.transition.type){case"fade":pixiVn.removeWithFadeTransition(s.alias,s.transition.props,s.transition.priority);break;case"dissolve":pixiVn.removeWithDissolveTransition(s.alias,s.transition.props,s.transition.priority);break;case"movein":case"moveout":pixiVn.moveOut(s.alias,s.transition.props,s.transition.priority);break;case"zoomin":case"zoomout":pixiVn.zoomOut(s.alias,s.transition.props,s.transition.priority);break;case"pushin":case"pushout":pixiVn.pushOut(s.alias,s.transition.props,s.transition.priority);break}else pixiVn.canvas.remove(s.alias);}var nc=class extends pixiVn.LabelAbstract{constructor(s,e,t,n={}){t||(t={}),t.onLoadingLabel=async()=>{for(let i of e){let a;if(typeof i=="function"?a=i():a=i,a=kn(a),a.operations){let r=a.operations.map(o=>tc(o));await Promise.all(r);}}},super(s,t),this._steps=e,this.operationStringConvert=n.operationStringConvert,this.skipEmptyDialogs=n.skipEmptyDialogs||!1;}_steps;get steps(){return this._steps.map(s=>this.stepConverter(s))}operationStringConvert;skipEmptyDialogs=!1;getStepSha1(s){if(s<0||s>=this.steps.length)return;let e=this._steps[s];return (0, Uh.default)(e.toString().toLocaleLowerCase()).toString()}getDialogueText(s){let e="";if(Array.isArray(s)){let t=[];s.forEach(n=>{if(typeof n=="string")t.push(n);else if(n&&typeof n=="object"){let i=w(n);i?(i&&!Array.isArray(i)&&typeof i=="object"&&(i=w(i)||""),Array.isArray(i)?t=t.concat(i):t.push(`${i}`)):t.push(`${n}`);}}),e=t;}else {let t=w(s)||"";t&&!Array.isArray(t)&&typeof t=="object"&&(t=w(t)||""),e=t;}return `${e}`}getDialogue(s){if(s==null)return;let e=w(s);return e==null?"":typeof e=="object"&&"character"in e&&"text"in e?{character:e.character,text:Ze.t(this.getDialogueText(e.text))}:Ze.t(this.getDialogueText(e))}getChoices(s){return w(s)?.map(e=>w(e)).filter(e=>e!==void 0)}stepConverter(s){return async e=>{let t;if(typeof s=="function"?t=s():t=s,t=kn(t),t.operations)for(let u of t.operations)await us(u,this.operationStringConvert?h=>this.operationStringConvert(h,t,e):void 0);let n=this.getChoices(t.choices),i=w(t.glueEnabled),a=this.getDialogue(t.dialogue),r=[];t.labelToOpen&&(Array.isArray(t.labelToOpen)||(t.labelToOpen=[t.labelToOpen]),t.labelToOpen.forEach(u=>{let h=w(u);h&&r.push(h);}));let o=w(t.goNextStep),l=w(t.end);if(n){let u=n.map(h=>{let c="";if(Array.isArray(h.text)){let f=[];h.text.forEach(p=>{if(typeof p=="string")f.push(Ze.t(p));else if(p&&typeof p=="object"){let m=w(p);m&&!Array.isArray(m)&&typeof m=="object"&&(m=w(m)||""),m&&(Array.isArray(m)?f=f.concat(Ze.t(m)):f.push(Ze.t(m)));}}),c=f.join();}else typeof h.text=="string"&&(c=Ze.t(h.text));return new pixiVn.ChoiceMenuOption(c,h.label,h.props,{type:h.type,oneTime:h.oneTime,onlyHaveNoChoice:h.onlyHaveNoChoice,autoSelect:h.autoSelect})});pixiVn.narration.choiceMenuOptions=u;}else pixiVn.narration.choiceMenuOptions=void 0;a!==void 0&&(pixiVn.narration.dialogue=a,this.skipEmptyDialogs&&typeof a=="string"&&(a===""||RegExp(/^\s+$/).test(a))&&(o=!0)),i?pixiVn.setFlag(pixiVn.storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!0):i===!1&&pixiVn.setFlag(pixiVn.storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!1);for(let u of r){let h=u.label;typeof h=="object"&&(h=w(h)||"");let c=u.params?.map(f=>w(f));e={...e,...u.props},u.type==="jump"?(pixiVn.narration.closeCurrentLabel(),pixiVn.storage.setTempVariable(`${Gt}${pixiVn.narration.openedLabels.length}`,c),await pixiVn.narration.callLabel(h,e)):(pixiVn.storage.setTempVariable(`${Gt}${pixiVn.narration.openedLabels.length}`,c),await pixiVn.narration.callLabel(h,e));}l==="game_end"?(pixiVn.narration.closeAllLabels(),await pixiVn.narration.goNext(e)):l==="label_end"&&pixiVn.narration.closeCurrentLabel(),o&&await pixiVn.narration.goNext(e);}}};function Uo(s,e={}){let t=e?.operationStringConvert;try{typeof s=="string"&&(s=JSON.parse(s));}catch(n){console.error("[Pixi\u2019VN Json] Error parsing imported Pixi'VN JSON",n);return}if(typeof s!="object"){console.error("[Pixi\u2019VN Json] Error parsing imported Pixi'VN JSON: data is not an object");return}if(s.initialOperations){for(let n of s.initialOperations)us(n,t?i=>t(i,{},{}):void 0);pixiVn.StorageManagerStatic.saveStorageAsBasicStorage();}if(s.labels){let n=s.labels;for(let i in n)try{let a=n[i],r=new nc(i,a,void 0,e);pixiVn.saveLabel(r);}catch(a){console.error(`[Pixi\u2019VN Json] Error creating JSON label ${i}`,a);}}}var Ho="\xA7SPACE\xA7",Ko="\xA7DOUBLE_QUOTES\xA7",zo="\xA7QUOTES\xA7",Xo="SPECIAL_\xA7QUOTES\xA7",Yo="\xA7CURLY_BRACKETS1\xA7",Qo="\xA7CURLY_BRACKETS2\xA7",ic=["add","play","pause","resume","remove","volume"],Jt=class s{static _customHashtagScript=e=>!1;static runCustomHashtagScript(e,t){return s._customHashtagScript(e,t,s.convertListStringToObj)}static set customHashtagScript(e){s._customHashtagScript=e;}static async generateOrRunOperationFromHashtagScript(e,t,n){try{e=e.replaceAll('\\"',Ko),e=e.replaceAll("\\'",zo),e=e.replaceAll("\\`",Xo),e=e.replaceAll("\\{",Yo),e=e.replaceAll("\\}",Qo),e=e.replaceAll("{"," { "),e=e.replaceAll("}"," } "),e=e.replaceAll(Yo,"{"),e=e.replaceAll(Qo,"}");let i=[],a,r="";for(let u=0;u<e.length;u++){let h=e[u];h==='"'||h==="'"||h==="`"?a===void 0?(i.push(r),r="",a=h,r+=h):a===h?(a=void 0,r+=h,i.push(r),r=""):r+=h:r+=h;}if(r!==""&&i.push(r),i.forEach((u,h)=>{h%2===1&&(i[h]=u.replaceAll(" ",Ho));}),e=i.join(""),i=e.split(" ").filter(u=>u!==""),i=i.map(u=>u.replaceAll(Ho," ").replaceAll(Ko,'"').replaceAll(zo,"'").replaceAll(Xo,"`")),s.runCustomHashtagScript(i,n))return;let o=i.length>1?s.removeExtraDoubleQuotes(i[1]):"",l=i.length>0?s.removeExtraDoubleQuotes(i[0]):"";switch(o){case"image":case"imagecontainer":case"canvaselement":case"video":return o==="video"&&(l==="pause"||l==="resume")?{type:"video",operationType:l,alias:s.removeExtraDoubleQuotes(i[2])}:s.getCanvasOperationFromComment(i,o);case"sound":return s.getSoundOperationFromComment(i);case"input":if(l==="request"){let u={type:"input",operationType:"request"};if(i.length>2)try{let h=i.slice(2),c=s.convertListStringToObj(h);"type"in c&&typeof c.type=="string"&&(u.valueType=c.type),"default"in c&&(u.defaultValue=c.default);}catch{}return u}case"assets":if(l==="load")return {type:"assets",operationType:"load",assets:i.slice(2)};default:if(o)switch(l){case"call":case"jump":t.labelToOpen={label:o,type:l},t.goNextStep=void 0;break;case"fade":case"move":case"rotate":case"zoom":case"shake":let u={};if(i.length>2)try{u=s.convertListStringToObj(i.slice(2));}catch{}if(l=="move"&&"x"in u&&"y"in u&&(u.destination={x:u.x,y:u.y,type:"pixel"},delete u.x,delete u.y),l=="move"&&"xAlign"in u&&"yAlign"in u&&(u.destination={x:u.xAlign,y:u.yAlign,type:"align"},delete u.xAlign,delete u.yAlign),l=="move"&&"xPercentage"in u&&"yPercentage"in u&&(u.destination={x:u.xPercentage,y:u.yPercentage,type:"percentage"},delete u.xPercentage,delete u.yPercentage),l=="move"&&!("destination"in u)){console.error("[Pixi\u2019VN Ink] The move operation don't have a destination or destination is not valid",u);return}return {alias:o,type:l,props:u}}else switch(l){case"pause":"dialogue"in t&&delete t.dialogue,"goNextStep"in t&&delete t.goNextStep;break}}}catch(i){throw console.error("[Pixi\u2019VN Ink] Error parsing ink hashtag-script",e),i}}static getCanvasOperationFromComment(e,t){let n=s.removeExtraDoubleQuotes(e[0]),i=s.removeExtraDoubleQuotes(e[2]),a=s.convertListStringToPropList(e.slice(3));switch(n){case"show":switch(t){case"image":case"video":return s.getImageOperationFromComment(t,i,a);case"imagecontainer":return s.getContainerOperationFromComment(t,i,a);case"canvaselement":default:console.error("[Pixi\u2019VN Ink] This show operation is not valid for this type of element",t);}case"edit":return {type:t,operationType:"edit",alias:i,props:s.convertPropListStringToObj(a)};case"remove":let o={type:t,operationType:"remove",alias:i};if(a.length>1&&a[0]==="with"){let l=e[e.indexOf("with")+1],u=e.slice(e.indexOf("with")+2),h=s.getTransition(l,u);h!==void 0&&(o.transition=h);}return o;default:console.error("[Pixi\u2019VN Ink] The operation type is not valid",n);}}static getImageOperationFromComment(e,t,n){let i,a;n.length%2===0?(i=t,a=n):(i=s.removeExtraDoubleQuotes(n[0]),a=s.convertListStringToPropList(n.slice(1)));let r={type:e,operationType:"show",alias:t,url:i};return s.setShowProps(r,a)}static getContainerOperationFromComment(e,t,n){let i=[],a=n.findIndex(u=>u.startsWith("[")),r=n.findIndex(u=>u.endsWith("]"));if(a===-1||r===-1){console.error("[Pixi\u2019VN Ink] show imagecontainer must have a list of image ulrs",n);return}if(i=n.slice(a,r+1),i.length<2){console.error("[Pixi\u2019VN Ink] show imagecontainer must have a list of image ulrs",n);return}i[0]==="["?i.shift():i[0]=i[0].substring(1),i[i.length-1]==="]"?i.pop():i[i.length-1]=i[i.length-1].substring(0,i[i.length-1].length-1);let o={type:e,operationType:"show",alias:t,urls:i.map(u=>s.removeExtraDoubleQuotes(u))},l=s.convertListStringToPropList(n.slice(r+1));return s.setShowProps(o,l)}static getSoundOperationFromComment(e){let t=s.removeExtraDoubleQuotes(e[0]);if(!ic.includes(t))return;let n=s.removeExtraDoubleQuotes(e[2]);switch(t){case"play":let i={type:"sound",operationType:"play",alias:n};if(e.length>3){let u=s.getSoundPlayOptions(e.slice(3));u!==void 0&&(i.props=u);}return i;case"pause":case"resume":return {type:"sound",operationType:t,alias:n};case"stop":case"remove":return {type:"sound",operationType:"stop",alias:n};case"volume":let o=parseFloat(e[3]);return {type:"sound",operationType:"volume",alias:n,value:o}}}static setShowProps(e,t){if(t.length>0){if(t.includes("with")&&t.length>t.indexOf("with")+1){let n=t[t.indexOf("with")+1],i=t.slice(t.indexOf("with")+2);t=t.slice(0,t.indexOf("with"));let a=s.getTransition(n,i);a!==void 0&&(e.transition=a);}if(t.length>0){let n=s.convertListStringToObj(t);e.props=n;}}return e}static getTransition(e,t){switch(e){case"dissolve":case"fade":case"movein":case"moveout":case"zoomin":case"zoomout":case"pushin":case"pushout":break;default:return}let n={type:e};if(t.length>0)try{let i=s.convertPropListStringToObj(t);n.props=i;}catch{}return n}static getSoundOption(e){try{return s.convertListStringToObj(e)}catch{return}}static getSoundPlayOptions(e){try{return s.convertListStringToObj(e)}catch{return}}static convertListStringToObj(e){let t=s.convertListStringToPropList(e);return s.convertPropListStringToObj(t)}static convertListStringToPropList(e){let t=[],n=0,i="";for(let a=0;a<e.length;a++){let r=e[a];r.startsWith("{")?(n++,i+=r):r.endsWith("}")&&n>0?(n--,i+=r,n===0&&(t.push(i),i="")):n>0?i+=r:t.push(r);}return t}static convertPropListStringToObj(e){if(e.length%2!==0)throw console.error("[Pixi\u2019VN Ink] The props list must have a pair number of elements",e),new Error("[Pixi\u2019VN Ink] The props list must have a pair number of elements");let t="{";e.forEach((n,i)=>{if(i%2===0)t+=`"${n}": `;else {switch(n){case"null":case"undefined":case"true":case"false":t+=`${n}`;break;default:s.containExtraDoubleQuotes(n)?(n=s.removeExtraDoubleQuotes(n),t+=`"${n}"`):n.startsWith("{")&&n.endsWith("}")?t+=`${n}`:n.startsWith('"')&&n.endsWith('"')?t+=`${n}`:isNaN(parseFloat(n))?t+=`"${n}"`:t+=`${n}`;}i<e.length-1&&(t+=", ");}}),t+="}";try{return JSON.parse(t)}catch(n){throw console.error("[Pixi\u2019VN Ink] Error parsing ink json",t),n}}static removeExtraDoubleQuotes(e){return e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")||e.startsWith("`")&&e.endsWith("`")?e.substring(1,e.length-1):e}static containExtraDoubleQuotes(e){return !!(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")||e.startsWith("`")&&e.endsWith("`"))}};var sh=fh($u());var L="_|_",rs="global decl",Xe="___external_value___";function An(s,e){if(new RegExp(/.*\.[0-9]+\..*$/).test(s)&&(s=s.split(".").filter(i=>!i.match(/^[0-9]+$/)).join("."),!s.startsWith(".")))return s.replaceAll(".",L);if(!new RegExp(/^\.\^.*$/).test(s)&&s.includes("g-")){let n=s.split("g-");return Io(e)+L+"g-"+n[n.length-1]}let t=0;for(;new RegExp(/^\.\^.*$/).test(s);)t++,s=s.substring(2);if(t=t-1,new RegExp(/^\..*$/).test(s)&&e){let n=s.substring(1);return Io(e,t)+L+n.replaceAll(".",L)}return s.replaceAll(".",L)||Io(e,t).replaceAll(".",L)}function Io(s,e=0){let t=s.split(L);for(;t.length>1&&e>0;)t.pop()?.includes("g-")&&e--,e--;return t.join(L)}var Uu="\xA7DOUBLE_SLASH_CONVERTOR\xA7";function Re(s){return s.startsWith("^")&&(s=s.substring(1)),s=s.replaceAll("\\\\",Uu),s=s.replaceAll("\\n",`
|
|
47
|
+
`),s=s.replaceAll("\\t"," "),s=s.replaceAll(" "," "),s=s.replaceAll(Uu,"\\\\"),s}var Hu=["+","-","/","*","%","_","==",">","<",">=","<=","!=","!","&&","||","MIN","MAX"],Ku=["+","-","/","*","%","POW","RANDOM"],zu=["INT","FLOOR","FLOAT"],Xu=["==",">","<",">=","<=","!=","CONTAINS"];function Lt(s,e,t){s=s.map(i=>{if(typeof i=="string"){if(i==="rnd")return "RANDOM";if(i==="?")return "CONTAINS"}return i});let n=[];return s.forEach(i=>{if(typeof i=="object"&&"CNT?"in i)if(new RegExp(/.*\.[0-9]\..*/).test(i["CNT?"])){let a=i["CNT?"].split("."),r=a.pop(),o=a.pop();if(o===void 0||r===void 0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);return}let l=parseInt(o),u=a.join(".");if(u.includes("^.")){let h=u.split("."),c=h[h.length-1].replaceAll(".",L);h.pop(),u=h.join(".")+"."+c,r.includes("c-")&&(u=u+L+r);}else u=u.replaceAll(".",L);n.push({type:"compare",leftValue:Yu(An(u,e)),operator:">=",rightValue:{type:"value",value:l}});}else n.push(Yu(An(i["CNT?"],e)));else if(typeof i=="object"&&"VAR?"in i)n.push(Wt(i["VAR?"],t));else if(i==="&&"||i==="||"){if(n.length>=2){let a={type:"union",unionType:i==="&&"?"and":"or",conditions:[n[n.length-2],n[n.length-1]]};n.pop(),n.pop(),n.push(a);}}else if(i==="!")if(n.length===0)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"union",unionType:"not",condition:n[n.length-1]};n[n.length-1]=a;}else if(i&&typeof i=="string"&&Xu.includes(i))if(n.length<2)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"compare",operator:i,rightValue:n[n.length-1],leftValue:n[n.length-2]};n.pop(),n.pop(),n.push(a);}else if(i&&typeof i=="string"&&Ku.includes(i))if(n.length<2)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"arithmetic",operator:i,rightValue:n[n.length-1],leftValue:n[n.length-2]};n.pop(),n.pop(),n.push(a);}else if(i&&typeof i=="string"&&zu.includes(i)){let a={type:"arithmeticsingle",operator:i,leftValue:n[n.length-1]};n.pop(),n.push(a);}else i&&typeof i=="string"?i.startsWith("^")&&n.push(Re(i)):typeof i=="object"&&"^->"in i?i["^->"].includes("$r")||n.push(i["^->"]):n.push(i);}),n}function Yu(s){return {type:"value",storageType:"label",storageOperationType:"get",label:s}}function Qu(s,e,t){return Lt(s,e,t)}function Wt(s,e,t="storage"){let n=e.indexOf(s);return n>=0?{type:"value",storageType:"params",storageOperationType:"get",key:n}:{type:"value",storageOperationType:"get",storageType:t,key:s}}function Fo(s,e,t,n="storage"){let i=e.indexOf(s);return i>=0?{type:"value",storageType:"params",storageOperationType:"set",key:i,value:t}:{type:"value",storageOperationType:"set",storageType:n,key:s,value:t}}function ss(s,e){e&&(typeof e=="string"?e.startsWith("^")&&s.push(Re(e)):typeof e=="object"&&"type"in e&&e.type!=="value"&&s.push(e));}function Vo(s,e,t,n,i=!0,a=!1){return zg(s,e,t,n,i,a)}function zg(s,e,t,n,i,a=!1){if(e){if(a)Array.isArray(e)&&e.length>0&&s.push({operations:[{type:"operationtoconvert",values:e}],goNextStep:!0});else if(typeof e=="string"&&e.startsWith("^")||e&&typeof e=="object"&&"type"in e&&e.type=="value"&&e.storageOperationType==="get"){if(!i&&s.length>0){let r=s[s.length-1];!r.glueEnabled&&!r.operations&&(r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0)),s[s.length-1]=r;}typeof e=="string"?s.push(Xg(Re(e))):s.push({dialogue:e});}else if(typeof e=="string"){if(e==="end")s.push({end:"game_end"});else if(e==="done")s.push({end:"label_end",goNextStep:!0});else if(e=="<>")if(s.length>0){let r=s[s.length-1];r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0),s[s.length-1]=r;}else s.push({glueEnabled:!0,goNextStep:!1});}else if(typeof e=="object"){if("type"in e&&e.type!=="value"){if(!i&&s.length>0){let r=s[s.length-1];!r.glueEnabled&&!r.operations&&(r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0)),s[s.length-1]=r;}s.push({conditionalStep:e});}else if("->"in e){let r=i?void 0:!0;if(!i&&s.length>0){let o=s[s.length-1];o.labelToOpen||(o.goNextStep=!0),s[s.length-1]=o;}if(e.params&&e.params.length===0&&(e.params=void 0),e.var)s.push({labelToOpen:{label:Wt(e["->"],n),type:"jump",params:e.params},glueEnabled:r});else {let o=An(e["->"],t);s.push({labelToOpen:{label:o,type:"jump",params:e.params},glueEnabled:r});}}"type"in e&&e.type=="value"&&e.storageOperationType==="set"&&(typeof e.value=="string"&&e.value.startsWith("^")&&(e.value=Re(e.value)),s.push({goNextStep:!0,operations:[e]}));}}}function Xg(s){let e;if(s.includes(": ")){let t=s.split(": "),n=t[0],i=t.slice(1).join(": ");pixiVn.getCharacterById(n)&&(e=n,s=i);}return e?{dialogue:{character:e,text:s}}:{dialogue:s}}function ko(s,e,t,n=!0,i=!1){return Yg(s,e,t,n,i)}function Yg(s,e,t,n,i=!1){e&&(typeof e=="string"&&e.startsWith("^")||e&&typeof e=="object"&&"type"in e&&e.type=="value"&&e.storageOperationType==="get"?typeof e=="string"?s.push(Re(e)):s.push(e):typeof e=="object"&&"type"in e&&s.push(e));}function as(s,e,t){if(s.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Arithmetic statement is not valid",s);return}let n=Lt(s,e,t);if(n.length===1){let i=n[0];return i&&typeof i=="object"&&"type"in i?{type:"value",storageType:"logic",storageOperationType:"get",operation:i}:i}}function qt(s,e,t,n="",i,a,r=void 0){let o=[],l="sequential",u=!1,h=!0;s.forEach(p=>{p==="%"&&(l="loop"),p==="seq"&&(l="random"),p==="MIN"&&(u=!0);});let c=s[s.length-1];return Object.keys(c).forEach(p=>{let m=c[p];if(Array.isArray(m)&&m.length>3){m=m.slice(1,m.length-2);let S=[];Ye(m,n,i,S,e,e,t,jt,r,!0,a),S.length===1?o.push(S[0]):o.push({type:"resulttocombine",combine:"cross",secondConditionalItem:S});}else Array.isArray(m)&&m.length===3&&(h=!1);}),l==="sequential"?{type:"stepswitch",elements:o,choiceType:l,end:h?"lastItem":void 0,nestedId:r}:u&&l==="random"?{type:"stepswitch",elements:o,choiceType:"sequentialrandom",end:h?"lastItem":void 0,nestedId:r}:{type:"stepswitch",elements:o,choiceType:l}}function Ro(s="",e=""){let t=Array.isArray(s)?s:[s],n=Array.isArray(e)?e:[e];return [...new Set([...t,...n])]}function jt(s,e,t,n,i){if(s.length>0){let a={};Zu(s,a,i);for(let[r,o]of Object.entries(a)){let l=t+L+r,u={text:o.text.length===1?o.text[0]:o.text,label:l,props:{},type:"jump",oneTime:o.onetime};o.text.length===0&&(u.onlyHaveNoChoice=!0,u.autoSelect=!0),u.oneTime===!1&&delete u.oneTime;let h=Do(u,o.conditions,i,t)||u,c=e[e.length-1];if(typeof c=="object"&&c&&"type"in c&&(c={conditionalStep:c}),e.length>0&&typeof c=="object"&&c&&"choices"in c&&c.choices){let f=c.choices;f&&Array.isArray(f)?f.push(h):console.error("[Pixi\u2019VN Ink] Unhandled case: choices is PixiVNJsonConditionalStatements<PixiVNJsonChoices> | undefined",o,f),c.choices=f.sort((p,m)=>{try{let S=p.label.split("."),b=S[S.length-1].replaceAll(".",L),x=m.label.split("."),d=x[x.length-1].replaceAll(".",L);if(b.includes("c-")&&d.includes("c-")){let y=b.split("c-")[1],v=parseInt(y),g=d.split("c-")[1],_=parseInt(g);return v-_}}catch{}return 0});}else e.push({choices:[h]});o.preDialog&&(n.preDialog[l]={...o.preDialog});}}}function Zu(s,e,t,n){let i=[],a="",r="",o=!1,l=[];for(let u=0;u<s.length;u++){let h=s[u];if(typeof h=="string")h.startsWith("^")?i.push(Re(h)):Hu.includes(h)&&l.push(h);else if(Array.isArray(h)&&h.includes("visit")){let c=qt(h,ss,(f,p,m)=>{},n,{preDialog:{}},t);i.push(c);}else if(h&&typeof h=="object")if("*"in h&&typeof h["*"]&&typeof h["*"]=="string")h["*"].includes("c")&&(a="c"+h["*"].split("c")[1],h.flg&16&&(o=!0));else if("s"in h&&h.s instanceof Array){let c=eh(h.s),f=h.s.includes("<>");c&&(n&&e[n]?(e[n].preDialog={text:c,glue:f},e[n].text=Ro(c,e[n].text)):(i.push(c),r=c));}else "CNT?"in h&&l.push(h);else l.push(h);if(a){e[a]?e[a].text=Ro(i,e[a].text):e[a]={text:i,onetime:o,conditions:l},r&&(e[a].preDialog={text:r,glue:!1});let c=s.slice(u+1);Zu(c,e,t,a);return}}}function eh(s){for(let e of s)if(typeof e=="string"){if(e.startsWith("^"))return Re(e)}else if(e instanceof Array){let t=eh(e);if(t)return t}}function Do(s,e,t,n,i){if(e.length===0)return;let a=Lt(e,n,t);if(a.length===1){let r={type:"ifelse",condition:a[0],then:s,else:i};return r.else||delete r.else,r}else if(a.length>1){let r={type:"ifelse",condition:{type:"union",unionType:"and",conditions:a},then:s,else:i};return r.else||delete r.else,r}}function th(s,e,t,n,i,a,r=void 0){if(s.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);return}let o=[],l=[];if(s.forEach(c=>{Array.isArray(c)?l.push(c):typeof c=="string"&&c==="du"?i.du?o.push(i.du):i.du=o[o.length-1]:(typeof c!="string"||c!=="/ev")&&o.push(c);}),l.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",l);return}let u=Lo(l[0],e,t,n+L+"then",i,a,`${r||""}then`),h;return l.length===2?h=Lo(l[1],e,t,n+L+"else",i,a,`${r||""}else`):l.length>2&&(l.shift(),l.push("nop"),l=[{b:l}],h=Lo(l,e,t,n+L+"else",i,a,`${r||""}else`)),i.du=void 0,Do(u,o,a,n,h)}function Lo(s,e,t,n,i,a,r=void 0){let o=[];for(let u of s)typeof u=="object"&&"b"in u&&(u.b=u.b.filter(h=>h!==null&&!(typeof h=="object"&&"->"in h&&new RegExp(/.*\.[0-9]/).test(h["->"]))),Ye(u.b,n,i,o,e,e,t,jt,r,!0,a));return o.length===1?o[0]:{type:"resulttocombine",combine:"cross",secondConditionalItem:o}}function Ye(s,e,t,n=[],i,a,r,o,l=void 0,u=!0,h=[]){let c=!1,f=[],p=!1,m=!1,S=[],b=[];if(t.preDialog[e]&&(u=!1,i(n,"^"+t.preDialog[e].text,e,h,u,m),t.preDialog[e].glue&&i(n,"<>",e,h,u,m),delete t.preDialog[e]),s.includes("visit")){let d=qt(s,a,r,e,t,h,l);d&&(!u&&n.length>0&&i(n,"<>",e,h,u,m),i(n,d,e,h,u,m));return}let x=s[0];if(x&&typeof x=="object"&&"temp="in x){for(;s[0]&&typeof s[0]=="object"&&"temp="in s[0];)h.push(s[0]["temp="]),s.shift();h=h.reverse();}if(s.forEach((d,y)=>{if(m){if(typeof d=="string"&&d=="/#"){let v=[];Ye(b,e,t,v,ko,ko,r,o,l,u),i(n,v,e,h,u,m),m=!1,b=[];}else b.push(d);return}else if(c)if(Array.isArray(d))f.push(d);else if(d&&typeof d=="object")if("CNT?"in d)y>0&&s[y-1]=="ev"?(p=!0,S.push(d)):p?S.push(d):(f.push(d),u=!1);else if("VAR="in d||"temp="in d){let v=Fo("VAR="in d?d["VAR="]:d["temp="],h,s[y-1],"VAR="in d?"storage":"tempstorage");if(v.value&&typeof v.value=="string"&&v.value=="/str"&&(v.value=s[y-2]),v.value&&typeof v.value=="object"&&"^->"in v.value&&(v.value=v.value["^->"]),f.length>1){let g=as(f,e,h);f=[],g&&typeof g=="object"&&"type"in g&&g.type=="value"&&"storageType"in g&&g.storageType=="logic"&&(v.value=g.operation);}(typeof v.key!="string"||!v.key.includes("$r"))&&(i(n,v,e,h,u,m),u=!0);}else "VAR?"in d?f.push(d):"^->"in d&&(d["^->"].includes("$r")||f.push(d));else if(typeof d=="string"&&d=="/ev")p&&S.push(d),c=!1,f.push(d);else if(typeof d=="string"&&d=="out"){if(f.length>0){let v=f[f.length-1];if(v&&typeof v=="object"&&"VAR?"in v){f.pop();let g=Wt(v["VAR?"],h,"storage");i(n,g,e,h,u,m);}else {let g=[];for(;f.length>0&&f[f.length-1]!="/ev";)g.push(f.pop());g=g.reverse();let _=as(g,e,h);f=[],_&&typeof _=="object"&&"type"in _&&_.type=="value"&&"storageType"in _&&_.storageType=="logic"?i(n,{storageOperationType:"get",storageType:"logic",operation:_.operation,type:"value"},e,h,u,m):(i(n,"<>",e,h,u,m),_=`^${_}`,i(n,_,e,h,u,m));}u=!1;}}else f.push(d);else if(typeof d=="string")if(d.startsWith("^"))i(n,d,e,h,u,m),u=!1;else if(d=="ev")c=!0;else if(d==`
|
|
48
48
|
`)u=!0;else if(d=="done"||d=="end")i(n,d,e,h,u,m),u=!1;else if(d=="<>")i(n,d,e,h,u,m),u=!1;else if(d=="nop"&&p){let v=th(S,a,r,e,t,h,l);v&&i(n,v,e,h,u,m),p=!1,S=[];}else d=="#"&&(m=!0);else if(d instanceof Array)if(p)S.push(d);else if(d.length>1&&typeof d[d.length-2]=="object"&&d[d.length-2]&&"c"in d[d.length-2]&&typeof d[d.length-1]=="object"&&d[d.length-1]&&"b"in d[d.length-1]){f.pop();let v=[],g=[];for(;f.length>0&&f[f.length-1]!="/ev";)v.push(f.pop());S=[...S,...v.reverse()],p=!0,g.push(d.pop()),g.push(d.pop()),S=[...S,...d],S.push(g);}else if(d.length>1&&typeof d[d.length-1]=="object"&&d[d.length-1]&&"#n"in d[d.length-1]){let v=d.pop();if(!v){console.error("[Pixi\u2019VN Ink] Error parsing ink file: el is undefined");return}let g=v["#n"];delete v["#n"],d.push(v),i(n,{"->":e?e+L+g:g},e,h,u,m),r({[g]:d},e,t);}else Ye(d,e,t,n,i,a,r,o,l,u);else if(d&&typeof d=="object")if("->"in d&&typeof d["->"]=="string"&&!new RegExp(/^\.\^\.\^\.\d\.s$/).test(d["->"])){let v=[];f.length>0&&(v=Qu(["ev",...f],e,h)),d.params=v,i(n,d,e,h,u,m),u=!1;}else if("*"in d&&typeof d["*"]=="string")d["*"].includes("c")&&(f.push(d),u=!1);else if("s"in d&&d.s instanceof Array)f.push(d),u=!1;else if("CNT?"in d)f.push(d),u=!1;else if("VAR="in d||"temp="in d){let v=[],g=Fo("VAR="in d?d["VAR="]:d["temp="],h,void 0,"VAR="in d?"storage":"tempstorage");if(g.key!=="$r"){for(f.pop(),f[f.length-1]=="/ev"&&f.pop();f.length>0&&f[f.length-1]!="/ev";)v.push(f.pop());v=v.reverse(),g.value=as(v,e,h),f=[],(g.value!==void 0||g.value!==null)&&i(n,g,e,h,u,m),u=!1;}}else r(d,e,t);}),o(f,n,e,t,h),e.includes(L)&&n.length==2){let d=n[0],y=n[1];d&&y&&typeof d=="object"&&"dialogue"in d&&typeof y=="object"&&"labelToOpen"in y&&d.dialogue==" "&&y.labelToOpen&&(n.shift(),delete y.glueEnabled,n[0]=y);}}function nh(s){try{let e={};return ih(s,e),e}catch(e){console.error("[Pixi\u2019VN Ink] Error parsing ink file",e);}}function ih(s,e,t={externalSwitch:void 0}){for(let n of s)if(n)if(n instanceof Array)if(n.includes("visit")){let i=qt(n,ss,(a,r,o)=>{},"",{preDialog:{}},[]);i&&(t.externalSwitch=i);}else ih(n,e,t);else typeof n=="object"&&(n&&"VAR="in n&&t.externalSwitch&&(e[Xe]||(e[Xe]=[]),e[Xe].push({operations:[{type:"value",value:t.externalSwitch,key:n["VAR="],storageType:"storage",storageOperationType:"set"}]})),rh(n,e));}function rh(s,e,t="",n={preDialog:{}}){if(s!==null){for(let[i,a]of Object.entries(s))if(a instanceof Array){let r=[],o={},l=(t?t+L:"")+i;Ye(a,l,n,r,Vo,Vo,(u,h,c)=>{rh(u,o,h,c);},jt);for(let[u,h]of Object.entries(o))e[u]=h;r.length>0&&(e[l]=r);}}}function ah(s){let e={},t=Qg(s),n;try{n=JSON.parse(t);}catch{console.error("[Pixi\u2019VN Ink] Error parsing ink file");return}if(e.labels=nh(n.root),e.labels&&rs in e.labels){let i=e.labels[rs];delete e.labels[rs],i.forEach(a=>{a.operations&&(e.initialOperations=e.initialOperations?[...e.initialOperations,...a.operations]:[...a.operations]);});}if(e.labels&&Xe in e.labels){let i=e.labels[Xe];delete e.labels[Xe],i.forEach(a=>{a.operations&&(e.initialOperations=e.initialOperations?[...e.initialOperations,...a.operations]:[...a.operations]);});}return e}function Qg(s){try{return new sh.Compiler(s).Compile().ToJson()||""}catch(e){return console.error("[Pixi\u2019VN Ink] Error compiling ink file",e),""}}async function Zg(s){let e=[];if(Array.isArray(s)){for(let n of s){let i=await Zg(n);e.concat(i);}return e}let t=ah(s);return t&&(Uo(t,{operationStringConvert:Jt.generateOrRunOperationFromHashtagScript,skipEmptyDialogs:!0}),e.push(t)),e}exports.importInkText=Zg;
|
|
@@ -43,6 +43,6 @@ Error:${h}`);}return u!=null&&(l=new s(u,r,this._externalErrorHandler,this._root
|
|
|
43
43
|
\r`),this.ParseNewline(),We.ParseSuccess),this.Line=r=>()=>{let o=this.ParseObject(r);return o===null?null:(this.Expect(this.EndOfLine,"end of line",this.SkipToNextLine),o)},this.StartTag=()=>{if(this.Whitespace(),this.ParseString("#")===null)return null;this.parsingStringExpression&&this.Error("Tags aren't allowed inside of strings. Please use \\# if you want a hash symbol.");let r=null;if(this.tagActive){let o=new he.ContentList;o.AddContent(new Rt.Tag(!1)),o.AddContent(new Rt.Tag(!0)),r=o;}else r=new Rt.Tag(!0);return this.tagActive=!0,this.Whitespace(),r},this._inlineWhitespaceChars=new X.CharacterSet(" "),this.EndOfLine=()=>this.OneOf([this.Newline,this.EndOfFile]),this.Newline=()=>(this.Whitespace(),this.ParseNewline()!==null?We.ParseSuccess:null),this.EndOfFile=()=>(this.Whitespace(),this.endOfInput?We.ParseSuccess:null),this.MultilineWhitespace=()=>{let r=this.OneOrMore(this.Newline);return r===null?null:r.length>=1?We.ParseSuccess:null},this.Whitespace=()=>this.ParseCharactersFromCharSet(this._inlineWhitespaceChars)!==null?We.ParseSuccess:null,this.Spaced=r=>()=>{this.Whitespace();let o=this.ParseObject(r);return o===null?null:(this.Whitespace(),o)},this.AnyWhitespace=()=>{let r=!1;for(;this.OneOf([this.Whitespace,this.MultilineWhitespace])!==null;)r=!0;return r?We.ParseSuccess:null},this.MultiSpaced=r=>()=>{this.AnyWhitespace();let o=this.ParseObject(r);return o===null?null:(this.AnyWhitespace(),o)},this._filename=null,this._externalErrorHandler=null,this._fileHandler=null,this._filename=t,this.RegisterExpressionOperators(),this.GenerateStatementLevelRules(),this.errorHandler=this.OnStringParserError,this._externalErrorHandler=n,a===null?this._fileHandler=new Ag.DefaultFileHandler:this._fileHandler=a,i===null){if(this._rootParser=this,this._openFilenames=[],this._filename!==null){let r=this.fileHandler.ResolveInkFilename(this._filename);this._openFilenames.push(r);}}else this._rootParser=i;}PreProcessInputString(e){return new fg.CommentEliminator(e).Process()}get parsingStringExpression(){return this.GetFlag(Number(Qr.CustomFlags.ParsingString))}set parsingStringExpression(e){this.SetFlag(Number(Qr.CustomFlags.ParsingString),e);}get tagActive(){return this.GetFlag(Number(Qr.CustomFlags.TagActive))}set tagActive(e){this.SetFlag(Number(Qr.CustomFlags.TagActive),e);}get identifierCharSet(){return this._identifierCharSet===null&&((this._identifierCharSet=new X.CharacterSet).AddRange("A","Z").AddRange("a","z").AddRange("0","9").Add("_"),this.ExtendIdentifierCharacterRanges(this._identifierCharSet)),this._identifierCharSet}EndTagIfNecessary(e){this.tagActive&&(e!=null&&(e instanceof he.ContentList?e.AddContent(new Rt.Tag(!1)):e.push(new Rt.Tag(!1))),this.tagActive=!1);}};ts.InkParser=D;D.LatinBasic=Te.CharacterRange.Define("A","z",new X.CharacterSet().AddRange("[","`"));D.LatinExtendedA=Te.CharacterRange.Define("\u0100","\u017F");D.LatinExtendedB=Te.CharacterRange.Define("\u0180","\u024F");D.Greek=Te.CharacterRange.Define("\u0370","\u03FF",new X.CharacterSet().AddRange("\u0378","\u0385").AddCharacters("\u0374\u0375\u0378\u0387\u038B\u038D\u03A2"));D.Cyrillic=Te.CharacterRange.Define("\u0400","\u04FF",new X.CharacterSet().AddRange("\u0482","\u0489"));D.Armenian=Te.CharacterRange.Define("\u0530","\u058F",new X.CharacterSet().AddCharacters("\u0530").AddRange("\u0557","\u0560").AddRange("\u0588","\u058E"));D.Hebrew=Te.CharacterRange.Define("\u0590","\u05FF",new X.CharacterSet);D.Arabic=Te.CharacterRange.Define("\u0600","\u06FF",new X.CharacterSet);D.Korean=Te.CharacterRange.Define("\uAC00","\uD7AF",new X.CharacterSet);D.Latin1Supplement=Te.CharacterRange.Define("\x80","\xFF",new X.CharacterSet);D.Chinese=Te.CharacterRange.Define("\u4E00","\u9FFF",new X.CharacterSet);D.ListAllCharacterRanges=()=>[D.LatinBasic,D.LatinExtendedA,D.LatinExtendedB,D.Arabic,D.Armenian,D.Cyrillic,D.Greek,D.Hebrew,D.Korean,D.Latin1Supplement,D.Chinese];});var Bu=C(ns=>{Object.defineProperty(ns,"__esModule",{value:!0});ns.GenerateStoryStats=void 0;var Ig=_t(),Fg=xt(),Vg=ln(),kg=Ga(),Rg=za(),Dg=Je();function Lg(s){let e=s.FindAll(Dg.Text)(),t=0;for(let l of e){let u=0,h=!0;for(let c of l.text)c==" "||c==" "||c==`
|
|
44
44
|
`||c=="\r"?h=!0:h&&(u++,h=!1);t+=u;}let n=s.FindAll(kg.Knot)(),i=s.FindAll(Rg.Stitch)(),a=s.FindAll(Ig.Choice)(),r=s.FindAll(Vg.Gather)(l=>l.debugMetadata!=null),o=s.FindAll(Fg.Divert)();return {words:t,knots:n.length,functions:n.filter(l=>l.isFunction).length,stitches:i.length,gathers:r.length,diverts:o.length-1,choices:a.length}}ns.GenerateStoryStats=Lg;});var Gu=C(is=>{Object.defineProperty(is,"__esModule",{value:!0});is.JsonFileHandler=void 0;var Oo=class{constructor(e){this.fileHierarchy=e,this.ResolveInkFilename=t=>{if(Object.keys(this.fileHierarchy).includes(t))return t;throw new Error(`Cannot locate ${t}. Are you trying a relative import ? This is not yet implemented.`)},this.LoadInkFileContents=t=>{if(Object.keys(this.fileHierarchy).includes(t))return this.fileHierarchy[t];throw new Error(`Cannot open ${t}.`)};}};is.JsonFileHandler=Oo;});var $u=C(ne=>{Object.defineProperty(ne,"__esModule",{value:!0});ne.Compiler=ne.Story=ne.InkList=ne.JsonFileHandler=ne.StatementLevel=ne.InkParser=ne.CompilerOptions=void 0;var Wg=cs(),qg=Zo(),No=Wn(),jg=Po(),Mg=j(),Bg=k(),Gg=Bu(),Jg=cs();Object.defineProperty(ne,"CompilerOptions",{enumerable:!0,get:function(){return Jg.CompilerOptions}});var $g=Po();Object.defineProperty(ne,"InkParser",{enumerable:!0,get:function(){return $g.InkParser}});var Ug=Ha();Object.defineProperty(ne,"StatementLevel",{enumerable:!0,get:function(){return Ug.StatementLevel}});var Hg=Gu();Object.defineProperty(ne,"JsonFileHandler",{enumerable:!0,get:function(){return Hg.JsonFileHandler}});var Ju=vn();Object.defineProperty(ne,"InkList",{enumerable:!0,get:function(){return Ju.InkList}});Object.defineProperty(ne,"Story",{enumerable:!0,get:function(){return Ju.Story}});var Ao=class{get errors(){return this._errors}get warnings(){return this._warnings}get authorMessages(){return this._authorMessages}get inputString(){return this._inputString}get options(){return this._options}get parsedStory(){if(!this._parsedStory)throw new Error;return this._parsedStory}get runtimeStory(){if(!this._runtimeStory)throw new Error("Compilation failed.");return this._runtimeStory}get parser(){if(!this._parser)throw new Error;return this._parser}get debugSourceRanges(){return this._debugSourceRanges}constructor(e,t=null){this._errors=[],this._warnings=[],this._authorMessages=[],this._parsedStory=null,this._runtimeStory=null,this._parser=null,this._debugSourceRanges=[],this.Compile=()=>(this._parser=new jg.InkParser(this.inputString,this.options.sourceFilename||null,this.OnError,null,this.options.fileHandler),this._parsedStory=this.parser.ParseStory(),this.errors.length===0?(this.parsedStory.countAllVisits=this.options.countAllVisits,this._runtimeStory=this.parsedStory.ExportRuntime(this.OnError)):this._runtimeStory=null,this.runtimeStory),this.RetrieveDebugSourceForLatestContent=()=>{var n;for(let i of this.runtimeStory.state.outputStream){let a=(0, Bg.asOrNull)(i,Mg.StringValue);if(a!==null){let r=new qg.DebugSourceRange(((n=a.value)===null||n===void 0?void 0:n.length)||0,a.debugMetadata,a.value||"unknown");this.debugSourceRanges.push(r);}}},this.GenerateStats=()=>this._parsedStory===null?null:(0, Gg.GenerateStoryStats)(this._parsedStory),this.DebugMetadataForContentAtOffset=n=>{let i=0,a=null;for(let r of this.debugSourceRanges){if(r.debugMetadata!==null&&(a=r.debugMetadata),n>=i&&n<i+r.length)return a;i+=r.length;}return null},this.OnError=(n,i)=>{switch(i){case No.ErrorType.Author:this._authorMessages.push(n);break;case No.ErrorType.Warning:this._warnings.push(n);break;case No.ErrorType.Error:this._errors.push(n);break}this.options.errorHandler!==null&&this.options.errorHandler(n,i);},this._inputString=e,this._options=t||new Wg.CompilerOptions;}};ne.Compiler=Ao;});var Lh=Object.create,Jo=Object.defineProperty,Wh=Object.getOwnPropertyDescriptor,qh=Object.getOwnPropertyNames,jh=Object.getPrototypeOf,Mh=Object.prototype.hasOwnProperty,Mo=(s=>typeof Qe<"u"?Qe:typeof Proxy<"u"?new Proxy(s,{get:(e,t)=>(typeof Qe<"u"?Qe:e)[t]}):s)(function(s){if(typeof Qe<"u")return Qe.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')}),$o=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),Bh=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of qh(e))!Mh.call(s,i)&&i!==t&&Jo(s,i,{get:()=>e[i],enumerable:!(n=Wh(e,i))||n.enumerable});return s},Gh=(s,e,t)=>(t=s!=null?Lh(jh(s)):{},Bh(Jo(t,"default",{value:s,enumerable:!0}),s)),Jh=$o((s,e)=>{(function(t,n){typeof s=="object"?e.exports=s=n():typeof define=="function"&&define.amd?define([],n):t.CryptoJS=n();})(s,function(){var t=t||function(n,i){var a;if(typeof window<"u"&&window.crypto&&(a=window.crypto),typeof self<"u"&&self.crypto&&(a=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(a=globalThis.crypto),!a&&typeof window<"u"&&window.msCrypto&&(a=window.msCrypto),!a&&typeof global<"u"&&global.crypto&&(a=global.crypto),!a&&typeof Mo=="function")try{a=Mo("crypto");}catch{}var r=function(){if(a){if(typeof a.getRandomValues=="function")try{return a.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof a.randomBytes=="function")try{return a.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},o=Object.create||function(){function d(){}return function(y){var v;return d.prototype=y,v=new d,d.prototype=null,v}}(),l={},u=l.lib={},h=u.Base=function(){return {extend:function(d){var y=o(this);return d&&y.mixIn(d),(!y.hasOwnProperty("init")||this.init===y.init)&&(y.init=function(){y.$super.init.apply(this,arguments);}),y.init.prototype=y,y.$super=this,y},create:function(){var d=this.extend();return d.init.apply(d,arguments),d},init:function(){},mixIn:function(d){for(var y in d)d.hasOwnProperty(y)&&(this[y]=d[y]);d.hasOwnProperty("toString")&&(this.toString=d.toString);},clone:function(){return this.init.prototype.extend(this)}}}(),c=u.WordArray=h.extend({init:function(d,y){d=this.words=d||[],y!=i?this.sigBytes=y:this.sigBytes=d.length*4;},toString:function(d){return (d||p).stringify(this)},concat:function(d){var y=this.words,v=d.words,g=this.sigBytes,_=d.sigBytes;if(this.clamp(),g%4)for(var I=0;I<_;I++){var fe=v[I>>>2]>>>24-I%4*8&255;y[g+I>>>2]|=fe<<24-(g+I)%4*8;}else for(var R=0;R<_;R+=4)y[g+R>>>2]=v[R>>>2];return this.sigBytes+=_,this},clamp:function(){var d=this.words,y=this.sigBytes;d[y>>>2]&=4294967295<<32-y%4*8,d.length=n.ceil(y/4);},clone:function(){var d=h.clone.call(this);return d.words=this.words.slice(0),d},random:function(d){for(var y=[],v=0;v<d;v+=4)y.push(r());return new c.init(y,d)}}),f=l.enc={},p=f.Hex={stringify:function(d){for(var y=d.words,v=d.sigBytes,g=[],_=0;_<v;_++){var I=y[_>>>2]>>>24-_%4*8&255;g.push((I>>>4).toString(16)),g.push((I&15).toString(16));}return g.join("")},parse:function(d){for(var y=d.length,v=[],g=0;g<y;g+=2)v[g>>>3]|=parseInt(d.substr(g,2),16)<<24-g%8*4;return new c.init(v,y/2)}},m=f.Latin1={stringify:function(d){for(var y=d.words,v=d.sigBytes,g=[],_=0;_<v;_++){var I=y[_>>>2]>>>24-_%4*8&255;g.push(String.fromCharCode(I));}return g.join("")},parse:function(d){for(var y=d.length,v=[],g=0;g<y;g++)v[g>>>2]|=(d.charCodeAt(g)&255)<<24-g%4*8;return new c.init(v,y)}},S=f.Utf8={stringify:function(d){try{return decodeURIComponent(escape(m.stringify(d)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(d){return m.parse(unescape(encodeURIComponent(d)))}},b=u.BufferedBlockAlgorithm=h.extend({reset:function(){this._data=new c.init,this._nDataBytes=0;},_append:function(d){typeof d=="string"&&(d=S.parse(d)),this._data.concat(d),this._nDataBytes+=d.sigBytes;},_process:function(d){var y,v=this._data,g=v.words,_=v.sigBytes,I=this.blockSize,fe=I*4,R=_/fe;d?R=n.ceil(R):R=n.max((R|0)-this._minBufferSize,0);var B=R*I,pe=n.min(B*4,_);if(B){for(var dt=0;dt<B;dt+=I)this._doProcessBlock(g,dt);y=g.splice(0,B),v.sigBytes-=pe;}return new c.init(y,pe)},clone:function(){var d=h.clone.call(this);return d._data=this._data.clone(),d},_minBufferSize:0});u.Hasher=b.extend({cfg:h.extend(),init:function(d){this.cfg=this.cfg.extend(d),this.reset();},reset:function(){b.reset.call(this),this._doReset();},update:function(d){return this._append(d),this._process(),this},finalize:function(d){d&&this._append(d);var y=this._doFinalize();return y},blockSize:16,_createHelper:function(d){return function(y,v){return new d.init(v).finalize(y)}},_createHmacHelper:function(d){return function(y,v){return new x.HMAC.init(d,v).finalize(y)}}});var x=l.algo={};return l}(Math);return t});}),$h=$o((s,e)=>{(function(t,n){typeof s=="object"?e.exports=s=n(Jh()):typeof define=="function"&&define.amd?define(["./core"],n):n(t.CryptoJS);})(s,function(t){return function(){var n=t,i=n.lib,a=i.WordArray,r=i.Hasher,o=n.algo,l=[],u=o.SHA1=r.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(h,c){for(var f=this._hash.words,p=f[0],m=f[1],S=f[2],b=f[3],x=f[4],d=0;d<80;d++){if(d<16)l[d]=h[c+d]|0;else {var y=l[d-3]^l[d-8]^l[d-14]^l[d-16];l[d]=y<<1|y>>>31;}var v=(p<<5|p>>>27)+x+l[d];d<20?v+=(m&S|~m&b)+1518500249:d<40?v+=(m^S^b)+1859775393:d<60?v+=(m&S|m&b|S&b)-1894007588:v+=(m^S^b)-899497514,x=b,b=S,S=m<<30|m>>>2,m=p,p=v;}f[0]=f[0]+p|0,f[1]=f[1]+m|0,f[2]=f[2]+S|0,f[3]=f[3]+b|0,f[4]=f[4]+x|0;},_doFinalize:function(){var h=this._data,c=h.words,f=this._nDataBytes*8,p=h.sigBytes*8;return c[p>>>5]|=128<<24-p%32,c[(p+64>>>9<<4)+14]=Math.floor(f/4294967296),c[(p+64>>>9<<4)+15]=f,h.sigBytes=c.length*4,this._process(),this._hash},clone:function(){var h=r.clone.call(this);return h._hash=this._hash.clone(),h}});n.SHA1=r._createHelper(u),n.HmacSHA1=r._createHmacHelper(u);}(),t.SHA1});}),Uh=Gh($h()),Gt="___param___",Ze=class P{static _beforeToTranslate=void 0;static _translate=e=>e;static _afterToTranslate=void 0;static t(e){return Array.isArray(e)?e.map(t=>P.translate(`${t}`)):P.translate(`${e}`)}static set beforeToTranslate(e){P._beforeToTranslate=e;}static set translate(e){P._translate=e;}static get translate(){return e=>{let t=e;return P._beforeToTranslate&&(t=P._beforeToTranslate(t)),t=P._translate(t),P._afterToTranslate&&(t=P._afterToTranslate(t)),t}}static set afterToTranslate(e){P._afterToTranslate=e;}static addKey(e,t,n){let i=n.defaultValue||"empty_string";typeof t=="string"&&(t=[t]),Array.isArray(t)&&t.forEach(a=>{e[a]===void 0&&(i==="empty_string"?e[a]="":i==="copy_key"&&(P._beforeToTranslate?e[a]=P._beforeToTranslate(a):e[a]=a));});}static getConditionalsThenElse(e,t=[]){if(typeof e=="object"&&e&&"type"in e)if(e.type==="ifelse")e.then&&P.getConditionalsThenElse(e.then,t),e.else&&P.getConditionalsThenElse(e.else,t);else if(e.type==="stepswitch"){if(e.elements)if(Array.isArray(e.elements))e.elements.forEach(n=>{P.getConditionalsThenElse(n,t);});else if(e.elements.type==="ifelse"){let n=[];P.getConditionalsThenElse(e.elements,n),n.forEach(i=>{t.push(...i);});}else if(e.elements.type==="stepswitch"){let n=[];P.getConditionalsThenElse(e.elements,n),n.forEach(i=>{t.push(...i);});}else P.getConditionalsThenElse(e.elements,t);}else e.type==="resulttocombine"?(e.firstItem&&P.getConditionalsThenElse(e.firstItem,t),e.secondConditionalItem&&e.secondConditionalItem.forEach(n=>{P.getConditionalsThenElse(n,t);})):t.push(e);else e&&t.push(e);return t}static generateJsonTranslation(e,t={},n={}){return e.forEach(i=>{if(i.choices){let a=[];Array.isArray(i.choices)?a=[i.choices]:a=P.getConditionalsThenElse(i.choices),a.forEach(r=>r.forEach(o=>{if("type"in o){let l=[];o.type==="ifelse"||o.type==="stepswitch"?P.getConditionalsThenElse(o,l):l=[o],l.map(u=>P.getConditionalsThenElse(u.text)).forEach(u=>{Array.isArray(u)&&u.forEach(h=>{Array.isArray(h)?h.forEach(c=>{typeof c=="string"?P.addKey(t,c,n):P.getConditionalsThenElse(c).forEach(f=>{Array.isArray(f)?f.forEach(p=>{typeof p=="string"&&P.addKey(t,p,n);}):typeof f=="string"&&P.addKey(t,f,n);});}):typeof h=="string"&&P.addKey(t,h,n);});});}}));}if(i.dialogue){let a=[];Array.isArray(i.dialogue)?a=[i.dialogue]:a=P.getConditionalsThenElse(i.dialogue),a.forEach(r=>{typeof r=="string"?P.addKey(t,r,n):"text"in r&&Array.isArray(r.text)&&r.text.forEach(o=>{typeof o=="string"?P.addKey(t,o,n):P.getConditionalsThenElse(o).forEach(l=>{typeof l=="string"?P.addKey(t,l,n):Array.isArray(l)&&l.forEach(u=>{typeof u=="string"?P.addKey(t,u,n):P.getConditionalsThenElse(u).forEach(h=>{typeof h=="string"&&P.addKey(t,h,n);});});});});});}i.conditionalStep&&P.getConditionalsThenElse(i.conditionalStep).forEach(a=>{Array.isArray(a)?P.generateJsonTranslation(a,t,n):P.generateJsonTranslation([a],t,n);});}),t}},os=Ze;function Hh(s,e){return Math.floor(Math.random()*(e-s+1)+s)}function Kh(s){if(Array.isArray(s)||!s)return s;if(s&&typeof s=="object"&&"type"in s)switch(s.type){case"resulttocombine":return zh(s);case"ifelse":return w(s.condition)?w(s.then):w(s.else);case"stepswitch":let e=w(s.elements)||[];if(e.length===0){console.error("[Pixi\u2019VN Json] getValueFromConditionalStatements elements.length === 0");return}switch(s.choiceType){case"random":let t=Hh(0,e.length-1);return w(e[t]);case"loop":let n=NarrationManagerStatic.getCurrentStepTimesCounter(s.nestedId)-1;return n>e.length-1&&(n=n%e.length),w(e[n]);case"sequential":let i,a=NarrationManagerStatic.getCurrentStepTimesCounter(s.nestedId)-1;return s.end=="lastItem"&&(i=w(e[e.length-1])),a>e.length-1?i:w(e[a]);case"sequentialrandom":let r=NarrationManagerStatic.getRandomNumber(0,e.length-1,{nestedId:s.nestedId,onceOnly:!0});if(r==null&&s.end=="lastItem"){let o=NarrationManagerStatic.getCurrentStepTimesCounterData(s.nestedId);if(!o||!o?.usedRandomNumbers){console.warn("[Pixi\u2019VN Json] getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}let l=o.usedRandomNumbers[`0-${e.length-1}`];return w(e[l[l.length-1]])}if(r==null){console.warn("[Pixi\u2019VN Json] getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}return w(e[r])}}return s}function kn(s){if(s.conditionalStep){let e=createExportableElement(w(s.conditionalStep));if(e?.glueEnabled===void 0&&delete e?.glueEnabled,e?.goNextStep===void 0&&delete e?.goNextStep,e?.end===void 0&&delete e?.end,e?.choices===void 0&&delete e?.choices,e?.dialogue===void 0&&delete e?.dialogue,e?.labelToOpen===void 0&&delete e?.labelToOpen,e?.operations===void 0&&delete e?.operations,e){let t={...s,conditionalStep:void 0,...e};return kn(t)}else getFlag(storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)&&setFlag(storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!1);}return s}function zh(s){let e=s.firstItem,t=[];s.secondConditionalItem?.forEach(i=>{if(Array.isArray(i))i.forEach(a=>{let r=w(a);t.push(r);});else {let a=w(i);t.push(a);}});let n=e?[e,...t]:t;if(n.length===0){console.warn("[Pixi\u2019VN Json] combinateResult toCheck.length === 0");return}if(typeof n[0]=="string")return os.t(n).join("");if(typeof n[0]=="object"){let i=n,a,r=i.map((b,x)=>{b=kn(b);let d=w(b.dialogue)||"";return x===0?(a=w(b.glueEnabled)||!1,d):(typeof d=="object"&&"text"in d&&(d=d.character+": "+d.text),a===!1&&(d=`
|
|
45
45
|
|
|
46
|
-
`+d),a=w(b.glueEnabled)||!1,d)}),o=w(r[0]),l=typeof o=="object"&&"character"in o?o.character:void 0,u=r.map(b=>{let x;b&&typeof b=="object"&&"text"in b?x=b.text:x=b;let d;return Array.isArray(x)?d=x.map(y=>{let v=w(y);return os.t(`${v}`)}).join(""):d=w(x)||"",os.t(d)}).join(""),h=i.find(b=>b.end),c=i.find(b=>b.choices),f=!1,p=!1;i.length>0&&(i[0].glueEnabled&&i[0].goNextStep&&i[0].dialogue===void 0&&setFlag(storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!0),f=i[i.length-1].glueEnabled,p=i.reverse().find(b=>!(b.operations&&(!b.dialogue||!b.choices)))?.goNextStep);let m=i.find(b=>b.labelToOpen),S=[];return i.forEach(b=>{b.operations&&S.forEach(x=>{S.push(x);});}),{dialogue:l?{character:l,text:u}:u,end:h?.end,choices:c?.choices,glueEnabled:f,goNextStep:p,labelToOpen:m?.labelToOpen,operations:S}}}function Xh(s){if(!s)return !1;if(typeof s!="object"||!("type"in s))return !!s;switch(s.type){case"compare":let e=w(s.leftValue),t=w(s.rightValue);switch(s.operator){case"==":return e===t;case"!=":return e!==t;case"<":return e<t;case"<=":return e<=t;case">":return e>t;case">=":return e>=t;case"CONTAINS":return e.toString().includes(t.toString())}break;case"valueCondition":return !!w(s.value);case"union":return Qh(s)}return !!s}function Yh(s){if(s&&typeof s=="object"&&"type"in s&&s.type==="value"&&s.storageOperationType==="get")switch(s.storageType){case"storage":case"tempstorage":return storage.getVariable(s.key);case"flagStorage":return getFlag(s.key);case"label":return narration.getTimesLabelOpened(s.label);case"choice":return narration.getTimesChoiceMade(s.index);case"logic":return w(s.operation);case"params":let e=storage.getVariable(`${Gt}${narration.openedLabels.length-1}`)||[];if(e&&e.length>s.key)return e[s.key];console.warn("[Pixi\u2019VN Json] getValue params not found");return}return s}function Qh(s){if(s.unionType==="not")return !w(s.condition);let e=s.unionType==="and";for(let t=0;t<s.conditions.length;t++)if(e=w(s.conditions[t])||!1,s.unionType==="and"){if(!e)return !1}else if(e)return !0;return e}function Zh(s){let e=w(s.value),t;switch(e&&typeof e=="object"&&"type"in e?t=w(e):t=e,s.storageType){case"flagStorage":setFlag(s.key,s.value);break;case"storage":storage.setVariable(s.key,t);break;case"tempstorage":storage.setTempVariable(s.key,t);break;case"params":let n=storage.getVariable(`${Gt}${narration.openedLabels.length-1}`)||[];n&&n.length-1>=s.key&&(n[s.key]=t),storage.setTempVariable(`${Gt}${narration.openedLabels.length-1}`,n);break}}function w(s){let e=Kh(s);if(e&&typeof e=="object"&&"type"in e)switch(e.type){case"value":return Yh(e);case"arithmetic":case"arithmeticsingle":return ec(e);case"compare":case"valueCondition":case"union":return Xh(e)}return e}function ec(s){let e=w(s.leftValue);switch(s.type){case"arithmetic":let t=w(s.rightValue);switch(s.operator){case"*":return e*t;case"/":return e/t;case"+":return e+t;case"-":return e-t;case"%":return e%t;case"POW":return Math.pow(e,t);case"RANDOM":return narration.getRandomNumber(e,t)}case"arithmeticsingle":switch(s.operator){case"INT":return parseInt(e);case"FLOOR":return Math.floor(e);case"FLOAT":return parseFloat(e)}break}}async function tc(s){let e=w(s);if(e)switch(e.type){case"assets":switch(e.operationType){case"load":await Assets.load(e.assets);break}break}}async function us(s,e){let t=w(s);if(t)switch(t.type){case"sound":switch(t.operationType){case"play":sound.play(t.alias,t.props);break;case"stop":sound.stop(t.alias);break;case"pause":sound.pause(t.alias);break;case"resume":sound.resume(t.alias);break;case"volume":sound.volume(t.alias,t.value);break}break;case"assets":switch(t.operationType){case"load":let o=t.assets.map(l=>Assets.load(l));await Promise.all(o);break}break;case"image":switch(t.operationType){case"show":let o=new ImageSprite(t.props,t.url||t.alias);await ls(o,t);break;case"edit":let l=canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Image with alias ${t.alias} not found.`);break;case"remove":Vn(t);break}break;case"video":switch(t.operationType){case"show":let o=new VideoSprite(t.props,t.url||t.alias);await ls(o,t);break;case"edit":let l=canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break;case"remove":Vn(t);break;case"pause":let u=canvas.find(t.alias);u?u.paused=!0:console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break;case"resume":let h=canvas.find(t.alias);h?h.paused=!1:console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break}break;case"imagecontainer":switch(t.operationType){case"show":let o=new ImageContainer(t.props,t.urls);await ls(o,t);break;case"edit":let l=canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] ImageContainer with alias ${t.alias} not found.`);break;case"remove":Vn(t);break}break;case"canvaselement":switch(t.operationType){case"edit":try{let o=canvas.find(t.alias);o?t.props&&(o.memory={...o.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Canvas Element with alias ${t.alias} not found.`);}catch(o){console.error(`[Pixi\u2019VN Json] There was an error while trying to edit the canvas element with alias ${t.alias}.`,o);}break;case"remove":Vn(t);break}break;case"value":Zh(t);break;case"operationtoconvert":if(e){let o="";t.values.forEach(u=>{if(typeof u=="string")o+=u;else {let h=w(u);o+=`${h}`;}});let l=await e(o);l&&await us(l,e);}break;case"input":switch(t.operationType){case"request":narration.requestInput({type:t.valueType},t.defaultValue);break}break;case"fade":let n=new FadeAlphaTicker(t.props,t.duration,t.priority);canvas.addTicker(t.alias,n);break;case"move":let i=new MoveTicker(t.props,t.duration,t.priority);canvas.addTicker(t.alias,i);break;case"rotate":let a=new RotateTicker(t.props,t.duration,t.priority);canvas.addTicker(t.alias,a);break;case"zoom":let r=new ZoomTicker(t.props,t.duration,t.priority);canvas.addTicker(t.alias,r);break;case"shake":await shakeEffect(t.alias,t.props,t.priority);break}}async function ls(s,e){if(e.transition)switch(e.transition.type){case"fade":await showWithFadeTransition(e.alias,s,e.transition.props,e.transition.priority);break;case"dissolve":await showWithDissolveTransition(e.alias,s,e.transition.props,e.transition.priority);break;case"movein":case"moveout":await moveIn(e.alias,s,e.transition.props,e.transition.priority);break;case"zoomin":case"zoomout":await zoomIn(e.alias,s,e.transition.props,e.transition.priority);break;case"pushin":case"pushout":await pushIn(e.alias,s,e.transition.props,e.transition.priority);break}else canvas.add(e.alias,s),await s.load();}function Vn(s){if(s.transition)switch(s.transition.type){case"fade":removeWithFadeTransition(s.alias,s.transition.props,s.transition.priority);break;case"dissolve":removeWithDissolveTransition(s.alias,s.transition.props,s.transition.priority);break;case"movein":case"moveout":moveOut(s.alias,s.transition.props,s.transition.priority);break;case"zoomin":case"zoomout":zoomOut(s.alias,s.transition.props,s.transition.priority);break;case"pushin":case"pushout":pushOut(s.alias,s.transition.props,s.transition.priority);break}else canvas.remove(s.alias);}var nc=class extends LabelAbstract{constructor(s,e,t,n={}){t||(t={}),t.onLoadingLabel=async()=>{for(let i of e){let a;if(typeof i=="function"?a=i():a=i,a=kn(a),a.operations){let r=a.operations.map(o=>tc(o));await Promise.all(r);}}},super(s,t),this._steps=e,this.operationStringConvert=n.operationStringConvert,this.skipEmptyDialogs=n.skipEmptyDialogs||!1;}_steps;get steps(){return this._steps.map(s=>this.stepConverter(s))}operationStringConvert;skipEmptyDialogs=!1;getStepSha1(s){if(s<0||s>=this.steps.length)return;let e=this._steps[s];return (0, Uh.default)(e.toString().toLocaleLowerCase()).toString()}getDialogueText(s){let e="";if(Array.isArray(s)){let t=[];s.forEach(n=>{if(typeof n=="string")t.push(n);else if(n&&typeof n=="object"){let i=w(n);i?(i&&!Array.isArray(i)&&typeof i=="object"&&(i=w(i)||""),Array.isArray(i)?t=t.concat(i):t.push(`${i}`)):t.push(`${n}`);}}),e=t;}else {let t=w(s)||"";t&&!Array.isArray(t)&&typeof t=="object"&&(t=w(t)||""),e=t;}return `${e}`}getDialogue(s){if(s==null)return;let e=w(s);return e==null?"":typeof e=="object"&&"character"in e&&"text"in e?{character:e.character,text:Ze.t(this.getDialogueText(e.text))}:Ze.t(this.getDialogueText(e))}getChoices(s){return w(s)?.map(e=>w(e)).filter(e=>e!==void 0)}stepConverter(s){return async e=>{let t;if(typeof s=="function"?t=s():t=s,t=kn(t),t.operations)for(let u of t.operations)await us(u,this.operationStringConvert?h=>this.operationStringConvert(h,t,e):void 0);let n=this.getChoices(t.choices),i=w(t.glueEnabled),a=this.getDialogue(t.dialogue),r=[];t.labelToOpen&&(Array.isArray(t.labelToOpen)||(t.labelToOpen=[t.labelToOpen]),t.labelToOpen.forEach(u=>{let h=w(u);h&&r.push(h);}));let o=w(t.goNextStep),l=w(t.end);if(n){let u=n.map(h=>{let c="";if(Array.isArray(h.text)){let f=[];h.text.forEach(p=>{if(typeof p=="string")f.push(Ze.t(p));else if(p&&typeof p=="object"){let m=w(p);m&&!Array.isArray(m)&&typeof m=="object"&&(m=w(m)||""),m&&(Array.isArray(m)?f=f.concat(Ze.t(m)):f.push(Ze.t(m)));}}),c=f.join();}else typeof h.text=="string"&&(c=Ze.t(h.text));return new ChoiceMenuOption(c,h.label,h.props,{type:h.type,oneTime:h.oneTime,onlyHaveNoChoice:h.onlyHaveNoChoice,autoSelect:h.autoSelect})});narration.choiceMenuOptions=u;}else narration.choiceMenuOptions=void 0;a!==void 0&&(narration.dialogue=a,this.skipEmptyDialogs&&typeof a=="string"&&(a===""||RegExp(/^\s+$/).test(a))&&(o=!0)),i?setFlag(storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!0):i===!1&&setFlag(storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!1);for(let u of r){let h=u.label;typeof h=="object"&&(h=w(h)||"");let c=u.params?.map(f=>w(f));e={...e,...u.props},u.type==="jump"?(narration.closeCurrentLabel(),storage.setTempVariable(`${Gt}${narration.openedLabels.length}`,c),await narration.callLabel(h,e)):(storage.setTempVariable(`${Gt}${narration.openedLabels.length}`,c),await narration.callLabel(h,e));}l==="game_end"?(narration.closeAllLabels(),await narration.goNext(e)):l==="label_end"&&narration.closeCurrentLabel(),o&&await narration.goNext(e);}}};function Uo(s,e={}){let t=e?.operationStringConvert;try{typeof s=="string"&&(s=JSON.parse(s));}catch(n){console.error("[Pixi\u2019VN Json] Error parsing imported Pixi'VN JSON",n);return}if(typeof s!="object"){console.error("[Pixi\u2019VN Json] Error parsing imported Pixi'VN JSON: data is not an object");return}if(s.initialOperations){for(let n of s.initialOperations)us(n,t?i=>t(i,{},{}):void 0);StorageManagerStatic.saveStorageAsBasicStorage();}if(s.labels){let n=s.labels;for(let i in n)try{let a=n[i],r=new nc(i,a,void 0,e);saveLabel(r);}catch(a){console.error(`[Pixi\u2019VN Json] Error creating JSON label ${i}`,a);}}}var Ho="\xA7SPACE\xA7",Ko="\xA7DOUBLE_QUOTES\xA7",zo="\xA7QUOTES\xA7",Xo="SPECIAL_\xA7QUOTES\xA7",Yo="\xA7CURLY_BRACKETS1\xA7",Qo="\xA7CURLY_BRACKETS2\xA7",ic=["add","play","pause","resume","remove","volume"],Jt=class s{static _customHashtagScript=e=>!1;static runCustomHashtagScript(e,t){return s._customHashtagScript(e,t,s.convertListStringToObj)}static set customHashtagScript(e){s._customHashtagScript=e;}static async generateOrRunOperationFromHashtagScript(e,t,n){try{e=e.replaceAll('\\"',Ko),e=e.replaceAll("\\'",zo),e=e.replaceAll("\\`",Xo),e=e.replaceAll("\\{",Yo),e=e.replaceAll("\\}",Qo),e=e.replaceAll("{"," { "),e=e.replaceAll("}"," } "),e=e.replaceAll(Yo,"{"),e=e.replaceAll(Qo,"}");let i=[],a,r="";for(let u=0;u<e.length;u++){let h=e[u];h==='"'||h==="'"||h==="`"?a===void 0?(i.push(r),r="",a=h,r+=h):a===h?(a=void 0,r+=h,i.push(r),r=""):r+=h:r+=h;}if(r!==""&&i.push(r),i.forEach((u,h)=>{h%2===1&&(i[h]=u.replaceAll(" ",Ho));}),e=i.join(""),i=e.split(" ").filter(u=>u!==""),i=i.map(u=>u.replaceAll(Ho," ").replaceAll(Ko,'"').replaceAll(zo,"'").replaceAll(Xo,"`")),s.runCustomHashtagScript(i,n))return;let o=i.length>1?s.removeExtraDoubleQuotes(i[1]):"",l=i.length>0?s.removeExtraDoubleQuotes(i[0]):"";switch(o){case"image":case"imagecontainer":case"canvaselement":case"video":return o==="video"&&(l==="pause"||l==="resume")?{type:"video",operationType:l,alias:s.removeExtraDoubleQuotes(i[2])}:s.getCanvasOperationFromComment(i,o);case"sound":return s.getSoundOperationFromComment(i);case"input":if(l==="request"){let u={type:"input",operationType:"request"};if(i.length>2)try{let h=i.slice(2),c=s.convertListStringToObj(h);"type"in c&&typeof c.type=="string"&&(u.valueType=c.type),"default"in c&&(u.defaultValue=c.default);}catch{}return u}case"assets":if(l==="load")return {type:"assets",operationType:"load",assets:i.slice(2)};default:if(o)switch(l){case"call":case"jump":t.labelToOpen={label:o,type:l},t.goNextStep=void 0;break;case"fade":case"move":case"rotate":case"zoom":case"shake":let u={};if(i.length>2)try{u=s.convertListStringToObj(i.slice(2));}catch{}if(l=="move"&&!("destination"in u)&&(!("x"in u)||!("y"in u))){console.error("[Pixi\u2019VN Ink] The move operation must have a x and y or destination property",e);return}else l=="move"&&"x"in u&&"y"in u&&(u.destination={x:u.x,y:u.y},delete u.x,delete u.y);return {alias:o,type:l,props:u}}else switch(l){case"pause":"dialogue"in t&&delete t.dialogue,"goNextStep"in t&&delete t.goNextStep;break}}}catch(i){throw console.error("[Pixi\u2019VN Ink] Error parsing ink hashtag-script",e),i}}static getCanvasOperationFromComment(e,t){let n=s.removeExtraDoubleQuotes(e[0]),i=s.removeExtraDoubleQuotes(e[2]),a=s.convertListStringToPropList(e.slice(3));switch(n){case"show":switch(t){case"image":case"video":return s.getImageOperationFromComment(t,i,a);case"imagecontainer":return s.getContainerOperationFromComment(t,i,a);case"canvaselement":default:console.error("[Pixi\u2019VN Ink] This show operation is not valid for this type of element",t);}case"edit":return {type:t,operationType:"edit",alias:i,props:s.convertPropListStringToObj(a)};case"remove":let o={type:t,operationType:"remove",alias:i};if(a.length>1&&a[0]==="with"){let l=e[e.indexOf("with")+1],u=e.slice(e.indexOf("with")+2),h=s.getTransition(l,u);h!==void 0&&(o.transition=h);}return o;default:console.error("[Pixi\u2019VN Ink] The operation type is not valid",n);}}static getImageOperationFromComment(e,t,n){let i,a;n.length%2===0?(i=t,a=n):(i=s.removeExtraDoubleQuotes(n[0]),a=s.convertListStringToPropList(n.slice(1)));let r={type:e,operationType:"show",alias:t,url:i};return s.setShowProps(r,a)}static getContainerOperationFromComment(e,t,n){let i=[],a=n.findIndex(u=>u.startsWith("[")),r=n.findIndex(u=>u.endsWith("]"));if(a===-1||r===-1){console.error("[Pixi\u2019VN Ink] show imagecontainer must have a list of image ulrs",n);return}if(i=n.slice(a,r+1),i.length<2){console.error("[Pixi\u2019VN Ink] show imagecontainer must have a list of image ulrs",n);return}i[0]==="["?i.shift():i[0]=i[0].substring(1),i[i.length-1]==="]"?i.pop():i[i.length-1]=i[i.length-1].substring(0,i[i.length-1].length-1);let o={type:e,operationType:"show",alias:t,urls:i.map(u=>s.removeExtraDoubleQuotes(u))},l=s.convertListStringToPropList(n.slice(r+1));return s.setShowProps(o,l)}static getSoundOperationFromComment(e){let t=s.removeExtraDoubleQuotes(e[0]);if(!ic.includes(t))return;let n=s.removeExtraDoubleQuotes(e[2]);switch(t){case"play":let i={type:"sound",operationType:"play",alias:n};if(e.length>3){let u=s.getSoundPlayOptions(e.slice(3));u!==void 0&&(i.props=u);}return i;case"pause":case"resume":return {type:"sound",operationType:t,alias:n};case"stop":case"remove":return {type:"sound",operationType:"stop",alias:n};case"volume":let o=parseFloat(e[3]);return {type:"sound",operationType:"volume",alias:n,value:o}}}static setShowProps(e,t){if(t.length>0){if(t.includes("with")&&t.length>t.indexOf("with")+1){let n=t[t.indexOf("with")+1],i=t.slice(t.indexOf("with")+2);t=t.slice(0,t.indexOf("with"));let a=s.getTransition(n,i);a!==void 0&&(e.transition=a);}if(t.length>0){let n=s.convertListStringToObj(t);e.props=n;}}return e}static getTransition(e,t){switch(e){case"dissolve":case"fade":case"movein":case"moveout":case"zoomin":case"zoomout":case"pushin":case"pushout":break;default:return}let n={type:e};if(t.length>0)try{let i=s.convertPropListStringToObj(t);n.props=i;}catch{}return n}static getSoundOption(e){try{return s.convertListStringToObj(e)}catch{return}}static getSoundPlayOptions(e){try{return s.convertListStringToObj(e)}catch{return}}static convertListStringToObj(e){let t=s.convertListStringToPropList(e);return s.convertPropListStringToObj(t)}static convertListStringToPropList(e){let t=[],n=0,i="";for(let a=0;a<e.length;a++){let r=e[a];r.startsWith("{")?(n++,i+=r):r.endsWith("}")&&n>0?(n--,i+=r,n===0&&(t.push(i),i="")):n>0?i+=r:t.push(r);}return t}static convertPropListStringToObj(e){if(e.length%2!==0)throw console.error("[Pixi\u2019VN Ink] The props list must have a pair number of elements",e),new Error("[Pixi\u2019VN Ink] The props list must have a pair number of elements");let t="{";e.forEach((n,i)=>{if(i%2===0)t+=`"${n}": `;else {switch(n){case"null":case"undefined":case"true":case"false":t+=`${n}`;break;default:s.containExtraDoubleQuotes(n)?(n=s.removeExtraDoubleQuotes(n),t+=`"${n}"`):n.startsWith("{")&&n.endsWith("}")?t+=`${n}`:n.startsWith('"')&&n.endsWith('"')?t+=`${n}`:isNaN(parseFloat(n))?t+=`"${n}"`:t+=`${n}`;}i<e.length-1&&(t+=", ");}}),t+="}";try{return JSON.parse(t)}catch(n){throw console.error("[Pixi\u2019VN Ink] Error parsing ink json",t),n}}static removeExtraDoubleQuotes(e){return e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")||e.startsWith("`")&&e.endsWith("`")?e.substring(1,e.length-1):e}static containExtraDoubleQuotes(e){return !!(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")||e.startsWith("`")&&e.endsWith("`"))}};var sh=fh($u());var L="_|_",rs="global decl",Xe="___external_value___";function An(s,e){if(new RegExp(/.*\.[0-9]+\..*$/).test(s)&&(s=s.split(".").filter(i=>!i.match(/^[0-9]+$/)).join("."),!s.startsWith(".")))return s.replaceAll(".",L);if(!new RegExp(/^\.\^.*$/).test(s)&&s.includes("g-")){let n=s.split("g-");return Io(e)+L+"g-"+n[n.length-1]}let t=0;for(;new RegExp(/^\.\^.*$/).test(s);)t++,s=s.substring(2);if(t=t-1,new RegExp(/^\..*$/).test(s)&&e){let n=s.substring(1);return Io(e,t)+L+n.replaceAll(".",L)}return s.replaceAll(".",L)||Io(e,t).replaceAll(".",L)}function Io(s,e=0){let t=s.split(L);for(;t.length>1&&e>0;)t.pop()?.includes("g-")&&e--,e--;return t.join(L)}var Uu="\xA7DOUBLE_SLASH_CONVERTOR\xA7";function Re(s){return s.startsWith("^")&&(s=s.substring(1)),s=s.replaceAll("\\\\",Uu),s=s.replaceAll("\\n",`
|
|
47
|
-
`),s=s.replaceAll("\\t"," "),s=s.replaceAll(" "," "),s=s.replaceAll(Uu,"\\\\"),s}var Hu=["+","-","/","*","%","_","==",">","<",">=","<=","!=","!","&&","||","MIN","MAX"],Ku=["+","-","/","*","%","POW","RANDOM"],zu=["INT","FLOOR","FLOAT"],Xu=["==",">","<",">=","<=","!=","CONTAINS"];function Lt(s,e,t){s=s.map(i=>{if(typeof i=="string"){if(i==="rnd")return "RANDOM";if(i==="?")return "CONTAINS"}return i});let n=[];return s.forEach(i=>{if(typeof i=="object"&&"CNT?"in i)if(new RegExp(/.*\.[0-9]\..*/).test(i["CNT?"])){let a=i["CNT?"].split("."),r=a.pop(),o=a.pop();if(o===void 0||r===void 0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);return}let l=parseInt(o),u=a.join(".");if(u.includes("^.")){let h=u.split("."),c=h[h.length-1].replaceAll(".",L);h.pop(),u=h.join(".")+"."+c,r.includes("c-")&&(u=u+L+r);}else u=u.replaceAll(".",L);n.push({type:"compare",leftValue:Yu(An(u,e)),operator:">=",rightValue:{type:"value",value:l}});}else n.push(Yu(An(i["CNT?"],e)));else if(typeof i=="object"&&"VAR?"in i)n.push(Wt(i["VAR?"],t));else if(i==="&&"||i==="||"){if(n.length>=2){let a={type:"union",unionType:i==="&&"?"and":"or",conditions:[n[n.length-2],n[n.length-1]]};n.pop(),n.pop(),n.push(a);}}else if(i==="!")if(n.length===0)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"union",unionType:"not",condition:n[n.length-1]};n[n.length-1]=a;}else if(i&&typeof i=="string"&&Xu.includes(i))if(n.length<2)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"compare",operator:i,rightValue:n[n.length-1],leftValue:n[n.length-2]};n.pop(),n.pop(),n.push(a);}else if(i&&typeof i=="string"&&Ku.includes(i))if(n.length<2)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"arithmetic",operator:i,rightValue:n[n.length-1],leftValue:n[n.length-2]};n.pop(),n.pop(),n.push(a);}else if(i&&typeof i=="string"&&zu.includes(i)){let a={type:"arithmeticsingle",operator:i,leftValue:n[n.length-1]};n.pop(),n.push(a);}else i&&typeof i=="string"?i.startsWith("^")&&n.push(Re(i)):typeof i=="object"&&"^->"in i?i["^->"].includes("$r")||n.push(i["^->"]):n.push(i);}),n}function Yu(s){return {type:"value",storageType:"label",storageOperationType:"get",label:s}}function Qu(s,e,t){return Lt(s,e,t)}function Wt(s,e,t="storage"){let n=e.indexOf(s);return n>=0?{type:"value",storageType:"params",storageOperationType:"get",key:n}:{type:"value",storageOperationType:"get",storageType:t,key:s}}function Fo(s,e,t,n="storage"){let i=e.indexOf(s);return i>=0?{type:"value",storageType:"params",storageOperationType:"set",key:i,value:t}:{type:"value",storageOperationType:"set",storageType:n,key:s,value:t}}function ss(s,e){e&&(typeof e=="string"?e.startsWith("^")&&s.push(Re(e)):typeof e=="object"&&"type"in e&&e.type!=="value"&&s.push(e));}function Vo(s,e,t,n,i=!0,a=!1){return zg(s,e,t,n,i,a)}function zg(s,e,t,n,i,a=!1){if(e){if(a)Array.isArray(e)&&e.length>0&&s.push({operations:[{type:"operationtoconvert",values:e}],goNextStep:!0});else if(typeof e=="string"&&e.startsWith("^")||e&&typeof e=="object"&&"type"in e&&e.type=="value"&&e.storageOperationType==="get"){if(!i&&s.length>0){let r=s[s.length-1];!r.glueEnabled&&!r.operations&&(r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0)),s[s.length-1]=r;}typeof e=="string"?s.push(Xg(Re(e))):s.push({dialogue:e});}else if(typeof e=="string"){if(e==="end")s.push({end:"game_end"});else if(e==="done")s.push({end:"label_end",goNextStep:!0});else if(e=="<>")if(s.length>0){let r=s[s.length-1];r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0),s[s.length-1]=r;}else s.push({glueEnabled:!0,goNextStep:!0});}else if(typeof e=="object"){if("type"in e&&e.type!=="value"){if(!i&&s.length>0){let r=s[s.length-1];!r.glueEnabled&&!r.operations&&(r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0)),s[s.length-1]=r;}s.push({conditionalStep:e});}else if("->"in e){let r=i?void 0:!0;if(!i&&s.length>0){let o=s[s.length-1];o.labelToOpen||(o.goNextStep=!0),s[s.length-1]=o;}if(e.params&&e.params.length===0&&(e.params=void 0),e.var)s.push({labelToOpen:{label:Wt(e["->"],n),type:"jump",params:e.params},glueEnabled:r});else {let o=An(e["->"],t);s.push({labelToOpen:{label:o,type:"jump",params:e.params},glueEnabled:r});}}"type"in e&&e.type=="value"&&e.storageOperationType==="set"&&(typeof e.value=="string"&&e.value.startsWith("^")&&(e.value=Re(e.value)),s.push({goNextStep:!0,operations:[e]}));}}}function Xg(s){let e;if(s.includes(": ")){let t=s.split(": "),n=t[0],i=t[1];getCharacterById(n)&&(e=n,s=i);}return e?{dialogue:{character:e,text:s}}:{dialogue:s}}function ko(s,e,t,n=!0,i=!1){return Yg(s,e,t,n,i)}function Yg(s,e,t,n,i=!1){e&&(typeof e=="string"&&e.startsWith("^")||e&&typeof e=="object"&&"type"in e&&e.type=="value"&&e.storageOperationType==="get"?typeof e=="string"?s.push(Re(e)):s.push(e):typeof e=="object"&&"type"in e&&s.push(e));}function as(s,e,t){if(s.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Arithmetic statement is not valid",s);return}let n=Lt(s,e,t);if(n.length===1){let i=n[0];return i&&typeof i=="object"&&"type"in i?{type:"value",storageType:"logic",storageOperationType:"get",operation:i}:i}}function qt(s,e,t,n="",i,a,r=void 0){let o=[],l="sequential",u=!1,h=!0;s.forEach(p=>{p==="%"&&(l="loop"),p==="seq"&&(l="random"),p==="MIN"&&(u=!0);});let c=s[s.length-1];return Object.keys(c).forEach(p=>{let m=c[p];if(Array.isArray(m)&&m.length>3){m=m.slice(1,m.length-2);let S=[];Ye(m,n,i,S,e,e,t,jt,r,!0,a),S.length===1?o.push(S[0]):o.push({type:"resulttocombine",combine:"cross",secondConditionalItem:S});}else Array.isArray(m)&&m.length===3&&(h=!1);}),l==="sequential"?{type:"stepswitch",elements:o,choiceType:l,end:h?"lastItem":void 0,nestedId:r}:u&&l==="random"?{type:"stepswitch",elements:o,choiceType:"sequentialrandom",end:h?"lastItem":void 0,nestedId:r}:{type:"stepswitch",elements:o,choiceType:l}}function Ro(s="",e=""){let t=Array.isArray(s)?s:[s],n=Array.isArray(e)?e:[e];return [...new Set([...t,...n])]}function jt(s,e,t,n,i){if(s.length>0){let a={};Zu(s,a,i);for(let[r,o]of Object.entries(a)){let l=t+L+r,u={text:o.text.length===1?o.text[0]:o.text,label:l,props:{},type:"jump",oneTime:o.onetime};o.text.length===0&&(u.onlyHaveNoChoice=!0,u.autoSelect=!0),u.oneTime===!1&&delete u.oneTime;let h=Do(u,o.conditions,i,t)||u,c=e[e.length-1];if(typeof c=="object"&&c&&"type"in c&&(c={conditionalStep:c}),e.length>0&&typeof c=="object"&&c&&"choices"in c&&c.choices){let f=c.choices;f&&Array.isArray(f)?f.push(h):console.error("[Pixi\u2019VN Ink] Unhandled case: choices is PixiVNJsonConditionalStatements<PixiVNJsonChoices> | undefined",o,f),c.choices=f.sort((p,m)=>{try{let S=p.label.split("."),b=S[S.length-1].replaceAll(".",L),x=m.label.split("."),d=x[x.length-1].replaceAll(".",L);if(b.includes("c-")&&d.includes("c-")){let y=b.split("c-")[1],v=parseInt(y),g=d.split("c-")[1],_=parseInt(g);return v-_}}catch{}return 0});}else e.push({choices:[h]});o.preDialog&&(n.preDialog[l]={...o.preDialog});}}}function Zu(s,e,t,n){let i=[],a="",r="",o=!1,l=[];for(let u=0;u<s.length;u++){let h=s[u];if(typeof h=="string")h.startsWith("^")?i.push(Re(h)):Hu.includes(h)&&l.push(h);else if(Array.isArray(h)&&h.includes("visit")){let c=qt(h,ss,(f,p,m)=>{},n,{preDialog:{}},t);i.push(c);}else if(h&&typeof h=="object")if("*"in h&&typeof h["*"]&&typeof h["*"]=="string")h["*"].includes("c")&&(a="c"+h["*"].split("c")[1],h.flg&16&&(o=!0));else if("s"in h&&h.s instanceof Array){let c=eh(h.s),f=h.s.includes("<>");c&&(n&&e[n]?(e[n].preDialog={text:c,glue:f},e[n].text=Ro(c,e[n].text)):(i.push(c),r=c));}else "CNT?"in h&&l.push(h);else l.push(h);if(a){e[a]?e[a].text=Ro(i,e[a].text):e[a]={text:i,onetime:o,conditions:l},r&&(e[a].preDialog={text:r,glue:!1});let c=s.slice(u+1);Zu(c,e,t,a);return}}}function eh(s){for(let e of s)if(typeof e=="string"){if(e.startsWith("^"))return Re(e)}else if(e instanceof Array){let t=eh(e);if(t)return t}}function Do(s,e,t,n,i){if(e.length===0)return;let a=Lt(e,n,t);if(a.length===1){let r={type:"ifelse",condition:a[0],then:s,else:i};return r.else||delete r.else,r}else if(a.length>1){let r={type:"ifelse",condition:{type:"union",unionType:"and",conditions:a},then:s,else:i};return r.else||delete r.else,r}}function th(s,e,t,n,i,a,r=void 0){if(s.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);return}let o=[],l=[];if(s.forEach(c=>{Array.isArray(c)?l.push(c):typeof c=="string"&&c==="du"?i.du?o.push(i.du):i.du=o[o.length-1]:(typeof c!="string"||c!=="/ev")&&o.push(c);}),l.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",l);return}let u=Lo(l[0],e,t,n+L+"then",i,a,`${r||""}then`),h;return l.length===2?h=Lo(l[1],e,t,n+L+"else",i,a,`${r||""}else`):l.length>2&&(l.shift(),l.push("nop"),l=[{b:l}],h=Lo(l,e,t,n+L+"else",i,a,`${r||""}else`)),i.du=void 0,Do(u,o,a,n,h)}function Lo(s,e,t,n,i,a,r=void 0){let o=[];for(let u of s)typeof u=="object"&&"b"in u&&(u.b=u.b.filter(h=>h!==null&&!(typeof h=="object"&&"->"in h&&new RegExp(/.*\.[0-9]/).test(h["->"]))),Ye(u.b,n,i,o,e,e,t,jt,r,!0,a));return o.length===1?o[0]:{type:"resulttocombine",combine:"cross",secondConditionalItem:o}}function Ye(s,e,t,n=[],i,a,r,o,l=void 0,u=!0,h=[]){let c=!1,f=[],p=!1,m=!1,S=[],b=[];if(t.preDialog[e]&&(u=!1,i(n,"^"+t.preDialog[e].text,e,h,u,m),t.preDialog[e].glue&&i(n,"<>",e,h,u,m),delete t.preDialog[e]),s.includes("visit")){let d=qt(s,a,r,e,t,h,l);d&&(!u&&n.length>0&&i(n,"<>",e,h,u,m),i(n,d,e,h,u,m));return}let x=s[0];if(x&&typeof x=="object"&&"temp="in x){for(;s[0]&&typeof s[0]=="object"&&"temp="in s[0];)h.push(s[0]["temp="]),s.shift();h=h.reverse();}if(s.forEach((d,y)=>{if(m){if(typeof d=="string"&&d=="/#"){let v=[];Ye(b,e,t,v,ko,ko,r,o,l,u),i(n,v,e,h,u,m),m=!1,b=[];}else b.push(d);return}else if(c)if(Array.isArray(d))f.push(d);else if(d&&typeof d=="object")if("CNT?"in d)y>0&&s[y-1]=="ev"?(p=!0,S.push(d)):p?S.push(d):(f.push(d),u=!1);else if("VAR="in d||"temp="in d){let v=Fo("VAR="in d?d["VAR="]:d["temp="],h,s[y-1],"VAR="in d?"storage":"tempstorage");if(v.value&&typeof v.value=="string"&&v.value=="/str"&&(v.value=s[y-2]),v.value&&typeof v.value=="object"&&"^->"in v.value&&(v.value=v.value["^->"]),f.length>1){let g=as(f,e,h);f=[],g&&typeof g=="object"&&"type"in g&&g.type=="value"&&"storageType"in g&&g.storageType=="logic"&&(v.value=g.operation);}(typeof v.key!="string"||!v.key.includes("$r"))&&(i(n,v,e,h,u,m),u=!0);}else "VAR?"in d?f.push(d):"^->"in d&&(d["^->"].includes("$r")||f.push(d));else if(typeof d=="string"&&d=="/ev")p&&S.push(d),c=!1,f.push(d);else if(typeof d=="string"&&d=="out"){if(f.length>0){let v=f[f.length-1];if(v&&typeof v=="object"&&"VAR?"in v){f.pop();let g=Wt(v["VAR?"],h,"storage");i(n,g,e,h,u,m);}else {let g=[];for(;f.length>0&&f[f.length-1]!="/ev";)g.push(f.pop());g=g.reverse();let _=as(g,e,h);f=[],_&&typeof _=="object"&&"type"in _&&_.type=="value"&&"storageType"in _&&_.storageType=="logic"?i(n,{storageOperationType:"get",storageType:"logic",operation:_.operation,type:"value"},e,h,u,m):(i(n,"<>",e,h,u,m),_=`^${_}`,i(n,_,e,h,u,m));}u=!1;}}else f.push(d);else if(typeof d=="string")if(d.startsWith("^"))i(n,d,e,h,u,m),u=!1;else if(d=="ev")c=!0;else if(d==`
|
|
46
|
+
`+d),a=w(b.glueEnabled)||!1,d)}),o=w(r[0]),l=typeof o=="object"&&"character"in o?o.character:void 0,u=r.map(b=>{let x;b&&typeof b=="object"&&"text"in b?x=b.text:x=b;let d;return Array.isArray(x)?d=x.map(y=>{let v=w(y);return os.t(`${v}`)}).join(""):d=w(x)||"",os.t(d)}).join(""),h=i.find(b=>b.end),c=i.find(b=>b.choices),f=!1,p=!1;i.length>0&&(i[0].glueEnabled&&i[0].goNextStep&&i[0].dialogue===void 0&&setFlag(storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!0),f=i[i.length-1].glueEnabled,p=i.reverse().find(b=>!(b.operations&&(!b.dialogue||!b.choices)))?.goNextStep);let m=i.find(b=>b.labelToOpen),S=[];return i.forEach(b=>{b.operations&&S.forEach(x=>{S.push(x);});}),{dialogue:l?{character:l,text:u}:u,end:h?.end,choices:c?.choices,glueEnabled:f,goNextStep:p,labelToOpen:m?.labelToOpen,operations:S}}}function Xh(s){if(!s)return !1;if(typeof s!="object"||!("type"in s))return !!s;switch(s.type){case"compare":let e=w(s.leftValue),t=w(s.rightValue);switch(s.operator){case"==":return e===t;case"!=":return e!==t;case"<":return e<t;case"<=":return e<=t;case">":return e>t;case">=":return e>=t;case"CONTAINS":return e.toString().includes(t.toString())}break;case"valueCondition":return !!w(s.value);case"union":return Qh(s)}return !!s}function Yh(s){if(s&&typeof s=="object"&&"type"in s&&s.type==="value"&&s.storageOperationType==="get")switch(s.storageType){case"storage":case"tempstorage":return storage.getVariable(s.key);case"flagStorage":return getFlag(s.key);case"label":return narration.getTimesLabelOpened(s.label);case"choice":return narration.getTimesChoiceMade(s.index);case"logic":return w(s.operation);case"params":let e=storage.getVariable(`${Gt}${narration.openedLabels.length-1}`)||[];if(e&&e.length>s.key)return e[s.key];console.warn("[Pixi\u2019VN Json] getValue params not found");return}return s}function Qh(s){if(s.unionType==="not")return !w(s.condition);let e=s.unionType==="and";for(let t=0;t<s.conditions.length;t++)if(e=w(s.conditions[t])||!1,s.unionType==="and"){if(!e)return !1}else if(e)return !0;return e}function Zh(s){let e=w(s.value),t;switch(e&&typeof e=="object"&&"type"in e?t=w(e):t=e,s.storageType){case"flagStorage":setFlag(s.key,s.value);break;case"storage":storage.setVariable(s.key,t);break;case"tempstorage":storage.setTempVariable(s.key,t);break;case"params":let n=storage.getVariable(`${Gt}${narration.openedLabels.length-1}`)||[];n&&n.length-1>=s.key&&(n[s.key]=t),storage.setTempVariable(`${Gt}${narration.openedLabels.length-1}`,n);break}}function w(s){let e=Kh(s);if(e&&typeof e=="object"&&"type"in e)switch(e.type){case"value":return Yh(e);case"arithmetic":case"arithmeticsingle":return ec(e);case"compare":case"valueCondition":case"union":return Xh(e)}return e}function ec(s){let e=w(s.leftValue);switch(s.type){case"arithmetic":let t=w(s.rightValue);switch(s.operator){case"*":return e*t;case"/":return e/t;case"+":return e+t;case"-":return e-t;case"%":return e%t;case"POW":return Math.pow(e,t);case"RANDOM":return narration.getRandomNumber(e,t)}case"arithmeticsingle":switch(s.operator){case"INT":return parseInt(e);case"FLOOR":return Math.floor(e);case"FLOAT":return parseFloat(e)}break}}async function tc(s){let e=w(s);if(e)switch(e.type){case"assets":switch(e.operationType){case"load":await Assets.load(e.assets);break}break}}async function us(s,e){let t=w(s);if(t)switch(t.type){case"sound":switch(t.operationType){case"play":sound.play(t.alias,t.props);break;case"stop":sound.stop(t.alias);break;case"pause":sound.pause(t.alias);break;case"resume":sound.resume(t.alias);break;case"volume":sound.volume(t.alias,t.value);break}break;case"assets":switch(t.operationType){case"load":let o=t.assets.map(l=>Assets.load(l));await Promise.all(o);break}break;case"image":switch(t.operationType){case"show":let o=new ImageSprite(t.props,t.url||t.alias);await ls(o,t);break;case"edit":let l=canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Image with alias ${t.alias} not found.`);break;case"remove":Vn(t);break}break;case"video":switch(t.operationType){case"show":let o=new VideoSprite(t.props,t.url||t.alias);await ls(o,t);break;case"edit":let l=canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break;case"remove":Vn(t);break;case"pause":let u=canvas.find(t.alias);u?u.paused=!0:console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break;case"resume":let h=canvas.find(t.alias);h?h.paused=!1:console.error(`[Pixi\u2019VN Json] Video with alias ${t.alias} not found.`);break}break;case"imagecontainer":switch(t.operationType){case"show":let o=new ImageContainer(t.props,t.urls);await ls(o,t);break;case"edit":let l=canvas.find(t.alias);l?t.props&&await l.setMemory({...l.memory,...t.props}):console.error(`[Pixi\u2019VN Json] ImageContainer with alias ${t.alias} not found.`);break;case"remove":Vn(t);break}break;case"canvaselement":switch(t.operationType){case"edit":try{let o=canvas.find(t.alias);o?t.props&&(o.memory={...o.memory,...t.props}):console.error(`[Pixi\u2019VN Json] Canvas Element with alias ${t.alias} not found.`);}catch(o){console.error(`[Pixi\u2019VN Json] There was an error while trying to edit the canvas element with alias ${t.alias}.`,o);}break;case"remove":Vn(t);break}break;case"value":Zh(t);break;case"operationtoconvert":if(e){let o="";t.values.forEach(u=>{if(typeof u=="string")o+=u;else {let h=w(u);o+=`${h}`;}});let l=await e(o);l&&await us(l,e);}break;case"input":switch(t.operationType){case"request":narration.requestInput({type:t.valueType},t.defaultValue);break}break;case"fade":let n=new FadeAlphaTicker(t.props,t.duration,t.priority);canvas.addTicker(t.alias,n);break;case"move":let i=new MoveTicker(t.props,t.duration,t.priority);canvas.addTicker(t.alias,i);break;case"rotate":let a=new RotateTicker(t.props,t.duration,t.priority);canvas.addTicker(t.alias,a);break;case"zoom":let r=new ZoomTicker(t.props,t.duration,t.priority);canvas.addTicker(t.alias,r);break;case"shake":await shakeEffect(t.alias,t.props,t.priority);break}}async function ls(s,e){if(e.transition)switch(e.transition.type){case"fade":await showWithFadeTransition(e.alias,s,e.transition.props,e.transition.priority);break;case"dissolve":await showWithDissolveTransition(e.alias,s,e.transition.props,e.transition.priority);break;case"movein":case"moveout":await moveIn(e.alias,s,e.transition.props,e.transition.priority);break;case"zoomin":case"zoomout":await zoomIn(e.alias,s,e.transition.props,e.transition.priority);break;case"pushin":case"pushout":await pushIn(e.alias,s,e.transition.props,e.transition.priority);break}else canvas.add(e.alias,s),await s.load();}function Vn(s){if(s.transition)switch(s.transition.type){case"fade":removeWithFadeTransition(s.alias,s.transition.props,s.transition.priority);break;case"dissolve":removeWithDissolveTransition(s.alias,s.transition.props,s.transition.priority);break;case"movein":case"moveout":moveOut(s.alias,s.transition.props,s.transition.priority);break;case"zoomin":case"zoomout":zoomOut(s.alias,s.transition.props,s.transition.priority);break;case"pushin":case"pushout":pushOut(s.alias,s.transition.props,s.transition.priority);break}else canvas.remove(s.alias);}var nc=class extends LabelAbstract{constructor(s,e,t,n={}){t||(t={}),t.onLoadingLabel=async()=>{for(let i of e){let a;if(typeof i=="function"?a=i():a=i,a=kn(a),a.operations){let r=a.operations.map(o=>tc(o));await Promise.all(r);}}},super(s,t),this._steps=e,this.operationStringConvert=n.operationStringConvert,this.skipEmptyDialogs=n.skipEmptyDialogs||!1;}_steps;get steps(){return this._steps.map(s=>this.stepConverter(s))}operationStringConvert;skipEmptyDialogs=!1;getStepSha1(s){if(s<0||s>=this.steps.length)return;let e=this._steps[s];return (0, Uh.default)(e.toString().toLocaleLowerCase()).toString()}getDialogueText(s){let e="";if(Array.isArray(s)){let t=[];s.forEach(n=>{if(typeof n=="string")t.push(n);else if(n&&typeof n=="object"){let i=w(n);i?(i&&!Array.isArray(i)&&typeof i=="object"&&(i=w(i)||""),Array.isArray(i)?t=t.concat(i):t.push(`${i}`)):t.push(`${n}`);}}),e=t;}else {let t=w(s)||"";t&&!Array.isArray(t)&&typeof t=="object"&&(t=w(t)||""),e=t;}return `${e}`}getDialogue(s){if(s==null)return;let e=w(s);return e==null?"":typeof e=="object"&&"character"in e&&"text"in e?{character:e.character,text:Ze.t(this.getDialogueText(e.text))}:Ze.t(this.getDialogueText(e))}getChoices(s){return w(s)?.map(e=>w(e)).filter(e=>e!==void 0)}stepConverter(s){return async e=>{let t;if(typeof s=="function"?t=s():t=s,t=kn(t),t.operations)for(let u of t.operations)await us(u,this.operationStringConvert?h=>this.operationStringConvert(h,t,e):void 0);let n=this.getChoices(t.choices),i=w(t.glueEnabled),a=this.getDialogue(t.dialogue),r=[];t.labelToOpen&&(Array.isArray(t.labelToOpen)||(t.labelToOpen=[t.labelToOpen]),t.labelToOpen.forEach(u=>{let h=w(u);h&&r.push(h);}));let o=w(t.goNextStep),l=w(t.end);if(n){let u=n.map(h=>{let c="";if(Array.isArray(h.text)){let f=[];h.text.forEach(p=>{if(typeof p=="string")f.push(Ze.t(p));else if(p&&typeof p=="object"){let m=w(p);m&&!Array.isArray(m)&&typeof m=="object"&&(m=w(m)||""),m&&(Array.isArray(m)?f=f.concat(Ze.t(m)):f.push(Ze.t(m)));}}),c=f.join();}else typeof h.text=="string"&&(c=Ze.t(h.text));return new ChoiceMenuOption(c,h.label,h.props,{type:h.type,oneTime:h.oneTime,onlyHaveNoChoice:h.onlyHaveNoChoice,autoSelect:h.autoSelect})});narration.choiceMenuOptions=u;}else narration.choiceMenuOptions=void 0;a!==void 0&&(narration.dialogue=a,this.skipEmptyDialogs&&typeof a=="string"&&(a===""||RegExp(/^\s+$/).test(a))&&(o=!0)),i?setFlag(storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!0):i===!1&&setFlag(storage.keysSystem.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,!1);for(let u of r){let h=u.label;typeof h=="object"&&(h=w(h)||"");let c=u.params?.map(f=>w(f));e={...e,...u.props},u.type==="jump"?(narration.closeCurrentLabel(),storage.setTempVariable(`${Gt}${narration.openedLabels.length}`,c),await narration.callLabel(h,e)):(storage.setTempVariable(`${Gt}${narration.openedLabels.length}`,c),await narration.callLabel(h,e));}l==="game_end"?(narration.closeAllLabels(),await narration.goNext(e)):l==="label_end"&&narration.closeCurrentLabel(),o&&await narration.goNext(e);}}};function Uo(s,e={}){let t=e?.operationStringConvert;try{typeof s=="string"&&(s=JSON.parse(s));}catch(n){console.error("[Pixi\u2019VN Json] Error parsing imported Pixi'VN JSON",n);return}if(typeof s!="object"){console.error("[Pixi\u2019VN Json] Error parsing imported Pixi'VN JSON: data is not an object");return}if(s.initialOperations){for(let n of s.initialOperations)us(n,t?i=>t(i,{},{}):void 0);StorageManagerStatic.saveStorageAsBasicStorage();}if(s.labels){let n=s.labels;for(let i in n)try{let a=n[i],r=new nc(i,a,void 0,e);saveLabel(r);}catch(a){console.error(`[Pixi\u2019VN Json] Error creating JSON label ${i}`,a);}}}var Ho="\xA7SPACE\xA7",Ko="\xA7DOUBLE_QUOTES\xA7",zo="\xA7QUOTES\xA7",Xo="SPECIAL_\xA7QUOTES\xA7",Yo="\xA7CURLY_BRACKETS1\xA7",Qo="\xA7CURLY_BRACKETS2\xA7",ic=["add","play","pause","resume","remove","volume"],Jt=class s{static _customHashtagScript=e=>!1;static runCustomHashtagScript(e,t){return s._customHashtagScript(e,t,s.convertListStringToObj)}static set customHashtagScript(e){s._customHashtagScript=e;}static async generateOrRunOperationFromHashtagScript(e,t,n){try{e=e.replaceAll('\\"',Ko),e=e.replaceAll("\\'",zo),e=e.replaceAll("\\`",Xo),e=e.replaceAll("\\{",Yo),e=e.replaceAll("\\}",Qo),e=e.replaceAll("{"," { "),e=e.replaceAll("}"," } "),e=e.replaceAll(Yo,"{"),e=e.replaceAll(Qo,"}");let i=[],a,r="";for(let u=0;u<e.length;u++){let h=e[u];h==='"'||h==="'"||h==="`"?a===void 0?(i.push(r),r="",a=h,r+=h):a===h?(a=void 0,r+=h,i.push(r),r=""):r+=h:r+=h;}if(r!==""&&i.push(r),i.forEach((u,h)=>{h%2===1&&(i[h]=u.replaceAll(" ",Ho));}),e=i.join(""),i=e.split(" ").filter(u=>u!==""),i=i.map(u=>u.replaceAll(Ho," ").replaceAll(Ko,'"').replaceAll(zo,"'").replaceAll(Xo,"`")),s.runCustomHashtagScript(i,n))return;let o=i.length>1?s.removeExtraDoubleQuotes(i[1]):"",l=i.length>0?s.removeExtraDoubleQuotes(i[0]):"";switch(o){case"image":case"imagecontainer":case"canvaselement":case"video":return o==="video"&&(l==="pause"||l==="resume")?{type:"video",operationType:l,alias:s.removeExtraDoubleQuotes(i[2])}:s.getCanvasOperationFromComment(i,o);case"sound":return s.getSoundOperationFromComment(i);case"input":if(l==="request"){let u={type:"input",operationType:"request"};if(i.length>2)try{let h=i.slice(2),c=s.convertListStringToObj(h);"type"in c&&typeof c.type=="string"&&(u.valueType=c.type),"default"in c&&(u.defaultValue=c.default);}catch{}return u}case"assets":if(l==="load")return {type:"assets",operationType:"load",assets:i.slice(2)};default:if(o)switch(l){case"call":case"jump":t.labelToOpen={label:o,type:l},t.goNextStep=void 0;break;case"fade":case"move":case"rotate":case"zoom":case"shake":let u={};if(i.length>2)try{u=s.convertListStringToObj(i.slice(2));}catch{}if(l=="move"&&"x"in u&&"y"in u&&(u.destination={x:u.x,y:u.y,type:"pixel"},delete u.x,delete u.y),l=="move"&&"xAlign"in u&&"yAlign"in u&&(u.destination={x:u.xAlign,y:u.yAlign,type:"align"},delete u.xAlign,delete u.yAlign),l=="move"&&"xPercentage"in u&&"yPercentage"in u&&(u.destination={x:u.xPercentage,y:u.yPercentage,type:"percentage"},delete u.xPercentage,delete u.yPercentage),l=="move"&&!("destination"in u)){console.error("[Pixi\u2019VN Ink] The move operation don't have a destination or destination is not valid",u);return}return {alias:o,type:l,props:u}}else switch(l){case"pause":"dialogue"in t&&delete t.dialogue,"goNextStep"in t&&delete t.goNextStep;break}}}catch(i){throw console.error("[Pixi\u2019VN Ink] Error parsing ink hashtag-script",e),i}}static getCanvasOperationFromComment(e,t){let n=s.removeExtraDoubleQuotes(e[0]),i=s.removeExtraDoubleQuotes(e[2]),a=s.convertListStringToPropList(e.slice(3));switch(n){case"show":switch(t){case"image":case"video":return s.getImageOperationFromComment(t,i,a);case"imagecontainer":return s.getContainerOperationFromComment(t,i,a);case"canvaselement":default:console.error("[Pixi\u2019VN Ink] This show operation is not valid for this type of element",t);}case"edit":return {type:t,operationType:"edit",alias:i,props:s.convertPropListStringToObj(a)};case"remove":let o={type:t,operationType:"remove",alias:i};if(a.length>1&&a[0]==="with"){let l=e[e.indexOf("with")+1],u=e.slice(e.indexOf("with")+2),h=s.getTransition(l,u);h!==void 0&&(o.transition=h);}return o;default:console.error("[Pixi\u2019VN Ink] The operation type is not valid",n);}}static getImageOperationFromComment(e,t,n){let i,a;n.length%2===0?(i=t,a=n):(i=s.removeExtraDoubleQuotes(n[0]),a=s.convertListStringToPropList(n.slice(1)));let r={type:e,operationType:"show",alias:t,url:i};return s.setShowProps(r,a)}static getContainerOperationFromComment(e,t,n){let i=[],a=n.findIndex(u=>u.startsWith("[")),r=n.findIndex(u=>u.endsWith("]"));if(a===-1||r===-1){console.error("[Pixi\u2019VN Ink] show imagecontainer must have a list of image ulrs",n);return}if(i=n.slice(a,r+1),i.length<2){console.error("[Pixi\u2019VN Ink] show imagecontainer must have a list of image ulrs",n);return}i[0]==="["?i.shift():i[0]=i[0].substring(1),i[i.length-1]==="]"?i.pop():i[i.length-1]=i[i.length-1].substring(0,i[i.length-1].length-1);let o={type:e,operationType:"show",alias:t,urls:i.map(u=>s.removeExtraDoubleQuotes(u))},l=s.convertListStringToPropList(n.slice(r+1));return s.setShowProps(o,l)}static getSoundOperationFromComment(e){let t=s.removeExtraDoubleQuotes(e[0]);if(!ic.includes(t))return;let n=s.removeExtraDoubleQuotes(e[2]);switch(t){case"play":let i={type:"sound",operationType:"play",alias:n};if(e.length>3){let u=s.getSoundPlayOptions(e.slice(3));u!==void 0&&(i.props=u);}return i;case"pause":case"resume":return {type:"sound",operationType:t,alias:n};case"stop":case"remove":return {type:"sound",operationType:"stop",alias:n};case"volume":let o=parseFloat(e[3]);return {type:"sound",operationType:"volume",alias:n,value:o}}}static setShowProps(e,t){if(t.length>0){if(t.includes("with")&&t.length>t.indexOf("with")+1){let n=t[t.indexOf("with")+1],i=t.slice(t.indexOf("with")+2);t=t.slice(0,t.indexOf("with"));let a=s.getTransition(n,i);a!==void 0&&(e.transition=a);}if(t.length>0){let n=s.convertListStringToObj(t);e.props=n;}}return e}static getTransition(e,t){switch(e){case"dissolve":case"fade":case"movein":case"moveout":case"zoomin":case"zoomout":case"pushin":case"pushout":break;default:return}let n={type:e};if(t.length>0)try{let i=s.convertPropListStringToObj(t);n.props=i;}catch{}return n}static getSoundOption(e){try{return s.convertListStringToObj(e)}catch{return}}static getSoundPlayOptions(e){try{return s.convertListStringToObj(e)}catch{return}}static convertListStringToObj(e){let t=s.convertListStringToPropList(e);return s.convertPropListStringToObj(t)}static convertListStringToPropList(e){let t=[],n=0,i="";for(let a=0;a<e.length;a++){let r=e[a];r.startsWith("{")?(n++,i+=r):r.endsWith("}")&&n>0?(n--,i+=r,n===0&&(t.push(i),i="")):n>0?i+=r:t.push(r);}return t}static convertPropListStringToObj(e){if(e.length%2!==0)throw console.error("[Pixi\u2019VN Ink] The props list must have a pair number of elements",e),new Error("[Pixi\u2019VN Ink] The props list must have a pair number of elements");let t="{";e.forEach((n,i)=>{if(i%2===0)t+=`"${n}": `;else {switch(n){case"null":case"undefined":case"true":case"false":t+=`${n}`;break;default:s.containExtraDoubleQuotes(n)?(n=s.removeExtraDoubleQuotes(n),t+=`"${n}"`):n.startsWith("{")&&n.endsWith("}")?t+=`${n}`:n.startsWith('"')&&n.endsWith('"')?t+=`${n}`:isNaN(parseFloat(n))?t+=`"${n}"`:t+=`${n}`;}i<e.length-1&&(t+=", ");}}),t+="}";try{return JSON.parse(t)}catch(n){throw console.error("[Pixi\u2019VN Ink] Error parsing ink json",t),n}}static removeExtraDoubleQuotes(e){return e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")||e.startsWith("`")&&e.endsWith("`")?e.substring(1,e.length-1):e}static containExtraDoubleQuotes(e){return !!(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")||e.startsWith("`")&&e.endsWith("`"))}};var sh=fh($u());var L="_|_",rs="global decl",Xe="___external_value___";function An(s,e){if(new RegExp(/.*\.[0-9]+\..*$/).test(s)&&(s=s.split(".").filter(i=>!i.match(/^[0-9]+$/)).join("."),!s.startsWith(".")))return s.replaceAll(".",L);if(!new RegExp(/^\.\^.*$/).test(s)&&s.includes("g-")){let n=s.split("g-");return Io(e)+L+"g-"+n[n.length-1]}let t=0;for(;new RegExp(/^\.\^.*$/).test(s);)t++,s=s.substring(2);if(t=t-1,new RegExp(/^\..*$/).test(s)&&e){let n=s.substring(1);return Io(e,t)+L+n.replaceAll(".",L)}return s.replaceAll(".",L)||Io(e,t).replaceAll(".",L)}function Io(s,e=0){let t=s.split(L);for(;t.length>1&&e>0;)t.pop()?.includes("g-")&&e--,e--;return t.join(L)}var Uu="\xA7DOUBLE_SLASH_CONVERTOR\xA7";function Re(s){return s.startsWith("^")&&(s=s.substring(1)),s=s.replaceAll("\\\\",Uu),s=s.replaceAll("\\n",`
|
|
47
|
+
`),s=s.replaceAll("\\t"," "),s=s.replaceAll(" "," "),s=s.replaceAll(Uu,"\\\\"),s}var Hu=["+","-","/","*","%","_","==",">","<",">=","<=","!=","!","&&","||","MIN","MAX"],Ku=["+","-","/","*","%","POW","RANDOM"],zu=["INT","FLOOR","FLOAT"],Xu=["==",">","<",">=","<=","!=","CONTAINS"];function Lt(s,e,t){s=s.map(i=>{if(typeof i=="string"){if(i==="rnd")return "RANDOM";if(i==="?")return "CONTAINS"}return i});let n=[];return s.forEach(i=>{if(typeof i=="object"&&"CNT?"in i)if(new RegExp(/.*\.[0-9]\..*/).test(i["CNT?"])){let a=i["CNT?"].split("."),r=a.pop(),o=a.pop();if(o===void 0||r===void 0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);return}let l=parseInt(o),u=a.join(".");if(u.includes("^.")){let h=u.split("."),c=h[h.length-1].replaceAll(".",L);h.pop(),u=h.join(".")+"."+c,r.includes("c-")&&(u=u+L+r);}else u=u.replaceAll(".",L);n.push({type:"compare",leftValue:Yu(An(u,e)),operator:">=",rightValue:{type:"value",value:l}});}else n.push(Yu(An(i["CNT?"],e)));else if(typeof i=="object"&&"VAR?"in i)n.push(Wt(i["VAR?"],t));else if(i==="&&"||i==="||"){if(n.length>=2){let a={type:"union",unionType:i==="&&"?"and":"or",conditions:[n[n.length-2],n[n.length-1]]};n.pop(),n.pop(),n.push(a);}}else if(i==="!")if(n.length===0)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"union",unionType:"not",condition:n[n.length-1]};n[n.length-1]=a;}else if(i&&typeof i=="string"&&Xu.includes(i))if(n.length<2)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"compare",operator:i,rightValue:n[n.length-1],leftValue:n[n.length-2]};n.pop(),n.pop(),n.push(a);}else if(i&&typeof i=="string"&&Ku.includes(i))if(n.length<2)console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);else {let a={type:"arithmetic",operator:i,rightValue:n[n.length-1],leftValue:n[n.length-2]};n.pop(),n.pop(),n.push(a);}else if(i&&typeof i=="string"&&zu.includes(i)){let a={type:"arithmeticsingle",operator:i,leftValue:n[n.length-1]};n.pop(),n.push(a);}else i&&typeof i=="string"?i.startsWith("^")&&n.push(Re(i)):typeof i=="object"&&"^->"in i?i["^->"].includes("$r")||n.push(i["^->"]):n.push(i);}),n}function Yu(s){return {type:"value",storageType:"label",storageOperationType:"get",label:s}}function Qu(s,e,t){return Lt(s,e,t)}function Wt(s,e,t="storage"){let n=e.indexOf(s);return n>=0?{type:"value",storageType:"params",storageOperationType:"get",key:n}:{type:"value",storageOperationType:"get",storageType:t,key:s}}function Fo(s,e,t,n="storage"){let i=e.indexOf(s);return i>=0?{type:"value",storageType:"params",storageOperationType:"set",key:i,value:t}:{type:"value",storageOperationType:"set",storageType:n,key:s,value:t}}function ss(s,e){e&&(typeof e=="string"?e.startsWith("^")&&s.push(Re(e)):typeof e=="object"&&"type"in e&&e.type!=="value"&&s.push(e));}function Vo(s,e,t,n,i=!0,a=!1){return zg(s,e,t,n,i,a)}function zg(s,e,t,n,i,a=!1){if(e){if(a)Array.isArray(e)&&e.length>0&&s.push({operations:[{type:"operationtoconvert",values:e}],goNextStep:!0});else if(typeof e=="string"&&e.startsWith("^")||e&&typeof e=="object"&&"type"in e&&e.type=="value"&&e.storageOperationType==="get"){if(!i&&s.length>0){let r=s[s.length-1];!r.glueEnabled&&!r.operations&&(r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0)),s[s.length-1]=r;}typeof e=="string"?s.push(Xg(Re(e))):s.push({dialogue:e});}else if(typeof e=="string"){if(e==="end")s.push({end:"game_end"});else if(e==="done")s.push({end:"label_end",goNextStep:!0});else if(e=="<>")if(s.length>0){let r=s[s.length-1];r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0),s[s.length-1]=r;}else s.push({glueEnabled:!0,goNextStep:!1});}else if(typeof e=="object"){if("type"in e&&e.type!=="value"){if(!i&&s.length>0){let r=s[s.length-1];!r.glueEnabled&&!r.operations&&(r.glueEnabled=!0,r.labelToOpen||(r.goNextStep=!0)),s[s.length-1]=r;}s.push({conditionalStep:e});}else if("->"in e){let r=i?void 0:!0;if(!i&&s.length>0){let o=s[s.length-1];o.labelToOpen||(o.goNextStep=!0),s[s.length-1]=o;}if(e.params&&e.params.length===0&&(e.params=void 0),e.var)s.push({labelToOpen:{label:Wt(e["->"],n),type:"jump",params:e.params},glueEnabled:r});else {let o=An(e["->"],t);s.push({labelToOpen:{label:o,type:"jump",params:e.params},glueEnabled:r});}}"type"in e&&e.type=="value"&&e.storageOperationType==="set"&&(typeof e.value=="string"&&e.value.startsWith("^")&&(e.value=Re(e.value)),s.push({goNextStep:!0,operations:[e]}));}}}function Xg(s){let e;if(s.includes(": ")){let t=s.split(": "),n=t[0],i=t.slice(1).join(": ");getCharacterById(n)&&(e=n,s=i);}return e?{dialogue:{character:e,text:s}}:{dialogue:s}}function ko(s,e,t,n=!0,i=!1){return Yg(s,e,t,n,i)}function Yg(s,e,t,n,i=!1){e&&(typeof e=="string"&&e.startsWith("^")||e&&typeof e=="object"&&"type"in e&&e.type=="value"&&e.storageOperationType==="get"?typeof e=="string"?s.push(Re(e)):s.push(e):typeof e=="object"&&"type"in e&&s.push(e));}function as(s,e,t){if(s.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Arithmetic statement is not valid",s);return}let n=Lt(s,e,t);if(n.length===1){let i=n[0];return i&&typeof i=="object"&&"type"in i?{type:"value",storageType:"logic",storageOperationType:"get",operation:i}:i}}function qt(s,e,t,n="",i,a,r=void 0){let o=[],l="sequential",u=!1,h=!0;s.forEach(p=>{p==="%"&&(l="loop"),p==="seq"&&(l="random"),p==="MIN"&&(u=!0);});let c=s[s.length-1];return Object.keys(c).forEach(p=>{let m=c[p];if(Array.isArray(m)&&m.length>3){m=m.slice(1,m.length-2);let S=[];Ye(m,n,i,S,e,e,t,jt,r,!0,a),S.length===1?o.push(S[0]):o.push({type:"resulttocombine",combine:"cross",secondConditionalItem:S});}else Array.isArray(m)&&m.length===3&&(h=!1);}),l==="sequential"?{type:"stepswitch",elements:o,choiceType:l,end:h?"lastItem":void 0,nestedId:r}:u&&l==="random"?{type:"stepswitch",elements:o,choiceType:"sequentialrandom",end:h?"lastItem":void 0,nestedId:r}:{type:"stepswitch",elements:o,choiceType:l}}function Ro(s="",e=""){let t=Array.isArray(s)?s:[s],n=Array.isArray(e)?e:[e];return [...new Set([...t,...n])]}function jt(s,e,t,n,i){if(s.length>0){let a={};Zu(s,a,i);for(let[r,o]of Object.entries(a)){let l=t+L+r,u={text:o.text.length===1?o.text[0]:o.text,label:l,props:{},type:"jump",oneTime:o.onetime};o.text.length===0&&(u.onlyHaveNoChoice=!0,u.autoSelect=!0),u.oneTime===!1&&delete u.oneTime;let h=Do(u,o.conditions,i,t)||u,c=e[e.length-1];if(typeof c=="object"&&c&&"type"in c&&(c={conditionalStep:c}),e.length>0&&typeof c=="object"&&c&&"choices"in c&&c.choices){let f=c.choices;f&&Array.isArray(f)?f.push(h):console.error("[Pixi\u2019VN Ink] Unhandled case: choices is PixiVNJsonConditionalStatements<PixiVNJsonChoices> | undefined",o,f),c.choices=f.sort((p,m)=>{try{let S=p.label.split("."),b=S[S.length-1].replaceAll(".",L),x=m.label.split("."),d=x[x.length-1].replaceAll(".",L);if(b.includes("c-")&&d.includes("c-")){let y=b.split("c-")[1],v=parseInt(y),g=d.split("c-")[1],_=parseInt(g);return v-_}}catch{}return 0});}else e.push({choices:[h]});o.preDialog&&(n.preDialog[l]={...o.preDialog});}}}function Zu(s,e,t,n){let i=[],a="",r="",o=!1,l=[];for(let u=0;u<s.length;u++){let h=s[u];if(typeof h=="string")h.startsWith("^")?i.push(Re(h)):Hu.includes(h)&&l.push(h);else if(Array.isArray(h)&&h.includes("visit")){let c=qt(h,ss,(f,p,m)=>{},n,{preDialog:{}},t);i.push(c);}else if(h&&typeof h=="object")if("*"in h&&typeof h["*"]&&typeof h["*"]=="string")h["*"].includes("c")&&(a="c"+h["*"].split("c")[1],h.flg&16&&(o=!0));else if("s"in h&&h.s instanceof Array){let c=eh(h.s),f=h.s.includes("<>");c&&(n&&e[n]?(e[n].preDialog={text:c,glue:f},e[n].text=Ro(c,e[n].text)):(i.push(c),r=c));}else "CNT?"in h&&l.push(h);else l.push(h);if(a){e[a]?e[a].text=Ro(i,e[a].text):e[a]={text:i,onetime:o,conditions:l},r&&(e[a].preDialog={text:r,glue:!1});let c=s.slice(u+1);Zu(c,e,t,a);return}}}function eh(s){for(let e of s)if(typeof e=="string"){if(e.startsWith("^"))return Re(e)}else if(e instanceof Array){let t=eh(e);if(t)return t}}function Do(s,e,t,n,i){if(e.length===0)return;let a=Lt(e,n,t);if(a.length===1){let r={type:"ifelse",condition:a[0],then:s,else:i};return r.else||delete r.else,r}else if(a.length>1){let r={type:"ifelse",condition:{type:"union",unionType:"and",conditions:a},then:s,else:i};return r.else||delete r.else,r}}function th(s,e,t,n,i,a,r=void 0){if(s.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",s);return}let o=[],l=[];if(s.forEach(c=>{Array.isArray(c)?l.push(c):typeof c=="string"&&c==="du"?i.du?o.push(i.du):i.du=o[o.length-1]:(typeof c!="string"||c!=="/ev")&&o.push(c);}),l.length===0){console.error("[Pixi\u2019VN Ink] Error parsing ink file: Conditional statement is not valid",l);return}let u=Lo(l[0],e,t,n+L+"then",i,a,`${r||""}then`),h;return l.length===2?h=Lo(l[1],e,t,n+L+"else",i,a,`${r||""}else`):l.length>2&&(l.shift(),l.push("nop"),l=[{b:l}],h=Lo(l,e,t,n+L+"else",i,a,`${r||""}else`)),i.du=void 0,Do(u,o,a,n,h)}function Lo(s,e,t,n,i,a,r=void 0){let o=[];for(let u of s)typeof u=="object"&&"b"in u&&(u.b=u.b.filter(h=>h!==null&&!(typeof h=="object"&&"->"in h&&new RegExp(/.*\.[0-9]/).test(h["->"]))),Ye(u.b,n,i,o,e,e,t,jt,r,!0,a));return o.length===1?o[0]:{type:"resulttocombine",combine:"cross",secondConditionalItem:o}}function Ye(s,e,t,n=[],i,a,r,o,l=void 0,u=!0,h=[]){let c=!1,f=[],p=!1,m=!1,S=[],b=[];if(t.preDialog[e]&&(u=!1,i(n,"^"+t.preDialog[e].text,e,h,u,m),t.preDialog[e].glue&&i(n,"<>",e,h,u,m),delete t.preDialog[e]),s.includes("visit")){let d=qt(s,a,r,e,t,h,l);d&&(!u&&n.length>0&&i(n,"<>",e,h,u,m),i(n,d,e,h,u,m));return}let x=s[0];if(x&&typeof x=="object"&&"temp="in x){for(;s[0]&&typeof s[0]=="object"&&"temp="in s[0];)h.push(s[0]["temp="]),s.shift();h=h.reverse();}if(s.forEach((d,y)=>{if(m){if(typeof d=="string"&&d=="/#"){let v=[];Ye(b,e,t,v,ko,ko,r,o,l,u),i(n,v,e,h,u,m),m=!1,b=[];}else b.push(d);return}else if(c)if(Array.isArray(d))f.push(d);else if(d&&typeof d=="object")if("CNT?"in d)y>0&&s[y-1]=="ev"?(p=!0,S.push(d)):p?S.push(d):(f.push(d),u=!1);else if("VAR="in d||"temp="in d){let v=Fo("VAR="in d?d["VAR="]:d["temp="],h,s[y-1],"VAR="in d?"storage":"tempstorage");if(v.value&&typeof v.value=="string"&&v.value=="/str"&&(v.value=s[y-2]),v.value&&typeof v.value=="object"&&"^->"in v.value&&(v.value=v.value["^->"]),f.length>1){let g=as(f,e,h);f=[],g&&typeof g=="object"&&"type"in g&&g.type=="value"&&"storageType"in g&&g.storageType=="logic"&&(v.value=g.operation);}(typeof v.key!="string"||!v.key.includes("$r"))&&(i(n,v,e,h,u,m),u=!0);}else "VAR?"in d?f.push(d):"^->"in d&&(d["^->"].includes("$r")||f.push(d));else if(typeof d=="string"&&d=="/ev")p&&S.push(d),c=!1,f.push(d);else if(typeof d=="string"&&d=="out"){if(f.length>0){let v=f[f.length-1];if(v&&typeof v=="object"&&"VAR?"in v){f.pop();let g=Wt(v["VAR?"],h,"storage");i(n,g,e,h,u,m);}else {let g=[];for(;f.length>0&&f[f.length-1]!="/ev";)g.push(f.pop());g=g.reverse();let _=as(g,e,h);f=[],_&&typeof _=="object"&&"type"in _&&_.type=="value"&&"storageType"in _&&_.storageType=="logic"?i(n,{storageOperationType:"get",storageType:"logic",operation:_.operation,type:"value"},e,h,u,m):(i(n,"<>",e,h,u,m),_=`^${_}`,i(n,_,e,h,u,m));}u=!1;}}else f.push(d);else if(typeof d=="string")if(d.startsWith("^"))i(n,d,e,h,u,m),u=!1;else if(d=="ev")c=!0;else if(d==`
|
|
48
48
|
`)u=!0;else if(d=="done"||d=="end")i(n,d,e,h,u,m),u=!1;else if(d=="<>")i(n,d,e,h,u,m),u=!1;else if(d=="nop"&&p){let v=th(S,a,r,e,t,h,l);v&&i(n,v,e,h,u,m),p=!1,S=[];}else d=="#"&&(m=!0);else if(d instanceof Array)if(p)S.push(d);else if(d.length>1&&typeof d[d.length-2]=="object"&&d[d.length-2]&&"c"in d[d.length-2]&&typeof d[d.length-1]=="object"&&d[d.length-1]&&"b"in d[d.length-1]){f.pop();let v=[],g=[];for(;f.length>0&&f[f.length-1]!="/ev";)v.push(f.pop());S=[...S,...v.reverse()],p=!0,g.push(d.pop()),g.push(d.pop()),S=[...S,...d],S.push(g);}else if(d.length>1&&typeof d[d.length-1]=="object"&&d[d.length-1]&&"#n"in d[d.length-1]){let v=d.pop();if(!v){console.error("[Pixi\u2019VN Ink] Error parsing ink file: el is undefined");return}let g=v["#n"];delete v["#n"],d.push(v),i(n,{"->":e?e+L+g:g},e,h,u,m),r({[g]:d},e,t);}else Ye(d,e,t,n,i,a,r,o,l,u);else if(d&&typeof d=="object")if("->"in d&&typeof d["->"]=="string"&&!new RegExp(/^\.\^\.\^\.\d\.s$/).test(d["->"])){let v=[];f.length>0&&(v=Qu(["ev",...f],e,h)),d.params=v,i(n,d,e,h,u,m),u=!1;}else if("*"in d&&typeof d["*"]=="string")d["*"].includes("c")&&(f.push(d),u=!1);else if("s"in d&&d.s instanceof Array)f.push(d),u=!1;else if("CNT?"in d)f.push(d),u=!1;else if("VAR="in d||"temp="in d){let v=[],g=Fo("VAR="in d?d["VAR="]:d["temp="],h,void 0,"VAR="in d?"storage":"tempstorage");if(g.key!=="$r"){for(f.pop(),f[f.length-1]=="/ev"&&f.pop();f.length>0&&f[f.length-1]!="/ev";)v.push(f.pop());v=v.reverse(),g.value=as(v,e,h),f=[],(g.value!==void 0||g.value!==null)&&i(n,g,e,h,u,m),u=!1;}}else r(d,e,t);}),o(f,n,e,t,h),e.includes(L)&&n.length==2){let d=n[0],y=n[1];d&&y&&typeof d=="object"&&"dialogue"in d&&typeof y=="object"&&"labelToOpen"in y&&d.dialogue==" "&&y.labelToOpen&&(n.shift(),delete y.glueEnabled,n[0]=y);}}function nh(s){try{let e={};return ih(s,e),e}catch(e){console.error("[Pixi\u2019VN Ink] Error parsing ink file",e);}}function ih(s,e,t={externalSwitch:void 0}){for(let n of s)if(n)if(n instanceof Array)if(n.includes("visit")){let i=qt(n,ss,(a,r,o)=>{},"",{preDialog:{}},[]);i&&(t.externalSwitch=i);}else ih(n,e,t);else typeof n=="object"&&(n&&"VAR="in n&&t.externalSwitch&&(e[Xe]||(e[Xe]=[]),e[Xe].push({operations:[{type:"value",value:t.externalSwitch,key:n["VAR="],storageType:"storage",storageOperationType:"set"}]})),rh(n,e));}function rh(s,e,t="",n={preDialog:{}}){if(s!==null){for(let[i,a]of Object.entries(s))if(a instanceof Array){let r=[],o={},l=(t?t+L:"")+i;Ye(a,l,n,r,Vo,Vo,(u,h,c)=>{rh(u,o,h,c);},jt);for(let[u,h]of Object.entries(o))e[u]=h;r.length>0&&(e[l]=r);}}}function ah(s){let e={},t=Qg(s),n;try{n=JSON.parse(t);}catch{console.error("[Pixi\u2019VN Ink] Error parsing ink file");return}if(e.labels=nh(n.root),e.labels&&rs in e.labels){let i=e.labels[rs];delete e.labels[rs],i.forEach(a=>{a.operations&&(e.initialOperations=e.initialOperations?[...e.initialOperations,...a.operations]:[...a.operations]);});}if(e.labels&&Xe in e.labels){let i=e.labels[Xe];delete e.labels[Xe],i.forEach(a=>{a.operations&&(e.initialOperations=e.initialOperations?[...e.initialOperations,...a.operations]:[...a.operations]);});}return e}function Qg(s){try{return new sh.Compiler(s).Compile().ToJson()||""}catch(e){return console.error("[Pixi\u2019VN Ink] Error compiling ink file",e),""}}async function Zg(s){let e=[];if(Array.isArray(s)){for(let n of s){let i=await Zg(n);e.concat(i);}return e}let t=ah(s);return t&&(Uo(t,{operationStringConvert:Jt.generateOrRunOperationFromHashtagScript,skipEmptyDialogs:!0}),e.push(t)),e}export{Zg as importInkText};
|