@drincs/pixi-vn-ink
Version:
Pixi'VN gives you the ability to write your own narrative using Ink
2 lines • 3.7 kB
JavaScript
;var pixiVn=require('@drincs/pixi-vn');var s="_|_";function g(e,n){if(e.endsWith(".s"))return;if(new RegExp(/.*\.[0-9]+\..*$/).test(e)&&(e=e.split(".").filter(r=>!r.match(/^[0-9]+$/)).join("."),!e.startsWith(".")))return e.replaceAll(".",s);if(!new RegExp(/^\.\^.*$/).test(e)&&e.includes("g-")){let o=e.split("g-");return u(n)+s+"g-"+o[o.length-1]}let i=0;for(;new RegExp(/^\.\^.*$/).test(e);)i++,e=e.substring(2);if(i=i-1,new RegExp(/^\..*$/).test(e)&&n){let o=e.substring(1);return u(n,i)+s+o.replaceAll(".",s)}return e.replaceAll(".",s)||u(n,i).replaceAll(".",s)}function u(e,n=0){let i=e.split(s);for(;i.length>1&&n>0;)i.pop()?.includes("g-")&&n--,n--;return i.join(s)}var c="\xA7DOUBLE_SLASH_CONVERTOR\xA7";function p(e){return e.startsWith("^")&&(e=e.substring(1)),e=e.replaceAll("\\\\",c),e=e.replaceAll("\\n",`
`),e=e.replaceAll("\\t"," "),e=e.replaceAll(" "," "),e=e.replaceAll(c,"\\\\"),e}var y;(r=>(r.log=(a,...t)=>console.log(`[Pixi\u2019VN Ink] ${a}`,...t),r.warn=(a,...t)=>console.warn(`[Pixi\u2019VN Ink] ${a}`,...t),r.error=(a,...t)=>console.error(`[Pixi\u2019VN Ink] ${a}`,...t),r.info=(a,...t)=>console.info(`[Pixi\u2019VN Ink] ${a}`,...t)))(y||={});function f(e,n,i="storage"){let o=n.indexOf(e);return o>=0?{type:"value",storageType:"params",storageOperationType:"get",key:o}:{type:"value",storageOperationType:"get",storageType:i,key:e}}function H(e,n){n&&(typeof n=="string"?n.startsWith("^")&&e.push(p(n)):typeof n=="object"&&"type"in n&&n.type!=="value"&&e.push(n));}function X(e,n,i,o,r=true,a=false){return d(e,n,i,o,r,a)}function d(e,n,i,o,r,a=false){if(n){if(a)Array.isArray(n)&&n.length>0&&e.push({operations:[{type:"operationtoconvert",values:n}],goNextStep:true});else if(typeof n=="string"&&n.startsWith("^")||n&&typeof n=="object"&&"type"in n&&n.type=="value"&&n.storageOperationType==="get"){if(!r&&e.length>0){let t=e[e.length-1];!t.glueEnabled&&!t.operations&&(t.glueEnabled=true,t.labelToOpen||(t.goNextStep=true)),e[e.length-1]=t;}typeof n=="string"?e.push(V(p(n))):e.push({dialogue:n});}else if(typeof n=="string"){if(n==="end")e.push({end:"game_end"});else if(n==="done")e.push({end:"label_end",goNextStep:true});else if(n=="<>")if(e.length>0){let t=e[e.length-1];t.glueEnabled=true,t.labelToOpen||(t.goNextStep=true),e[e.length-1]=t;}else e.push({glueEnabled:true,goNextStep:false});}else if(typeof n=="object"){if("type"in n&&n.type!=="value"){if(!r&&e.length>0){let t=e[e.length-1];!t.glueEnabled&&!t.operations&&(t.glueEnabled=true,t.labelToOpen||(t.goNextStep=true)),e[e.length-1]=t;}e.push({conditionalStep:n});}else if("->"in n){let t=r?void 0:true;if(!r&&e.length>0){let l=e[e.length-1];l.labelToOpen||(l.goNextStep=true),e[e.length-1]=l;}if(n.params&&n.params.length===0&&(n.params=void 0),n.var)e.push({labelToOpen:{label:f(n["->"],o),type:"jump",params:n.params},glueEnabled:t});else {let l=g(n["->"],i);if(!l)return;e.push({labelToOpen:{label:l,type:"jump",params:n.params},glueEnabled:t});}}"type"in n&&n.type=="value"&&n.storageOperationType==="set"&&(typeof n.value=="string"&&n.value.startsWith("^")&&(n.value=p(n.value)),e.push({goNextStep:true,operations:[n]}));}}}function V(e){let n;if(e.includes(": ")){let i=e.split(": "),o=i[0],r=i.slice(1).join(": ");pixiVn.getCharacterById(o)&&(n=o,e=r);}return n?{dialogue:{character:n,text:e}}:{dialogue:e}}function Y(e,n,i,o=true,r=false){return x(e,n,i,o,r)}function x(e,n,i,o,r=false){n&&(typeof n=="string"&&n.startsWith("^")||n&&typeof n=="object"&&"type"in n&&n.type=="value"&&n.storageOperationType==="get"?typeof n=="string"?e.push(p(n)):e.push(n):typeof n=="object"&&"type"in n&&e.push(n));}exports.addSwitchComment=Y;exports.addSwitchElemenStep=X;exports.addSwitchElemenText=H;