@drincs/pixi-vn-ink
Version:
Pixi'VN gives you the ability to write your own narrative using Ink
2 lines • 3.75 kB
JavaScript
var s="_|_";var p;(t=>(t.log=(i,...l)=>console.log(`[Pixi\u2019VN Ink] ${i}`,...l),t.warn=(i,...l)=>console.warn(`[Pixi\u2019VN Ink] ${i}`,...l),t.error=(i,...l)=>console.error(`[Pixi\u2019VN Ink] ${i}`,...l),t.info=(i,...l)=>console.info(`[Pixi\u2019VN Ink] ${i}`,...l)))(p||={});var y=["+","-","/","*","%","POW","RANDOM"],A=["INT","FLOOR","FLOAT"],V=["==",">","<",">=","<=","!=","CONTAINS"];function g(n,r){if(n.endsWith(".s"))return;if(new RegExp(/.*\.[0-9]+\..*$/).test(n)&&(n=n.split(".").filter(t=>!t.match(/^[0-9]+$/)).join("."),!n.startsWith(".")))return n.replaceAll(".",s);if(!new RegExp(/^\.\^.*$/).test(n)&&n.includes("g-")){let e=n.split("g-");return c(r)+s+"g-"+e[e.length-1]}let o=0;for(;new RegExp(/^\.\^.*$/).test(n);)o++,n=n.substring(2);if(o=o-1,new RegExp(/^\..*$/).test(n)&&r){let e=n.substring(1);return c(r,o)+s+e.replaceAll(".",s)}return n.replaceAll(".",s)||c(r,o).replaceAll(".",s)}function c(n,r=0){let o=n.split(s);for(;o.length>1&&r>0;)o.pop()?.includes("g-")&&r--,r--;return o.join(s)}var x="\xA7DOUBLE_SLASH_CONVERTOR\xA7";function O(n){return n.startsWith("^")&&(n=n.substring(1)),n=n.replaceAll("\\\\",x),n=n.replaceAll("\\n",`
`),n=n.replaceAll("\\t"," "),n=n.replaceAll(" "," "),n=n.replaceAll(x,"\\\\"),n}function N(n,r,o){n=n.map(t=>{if(typeof t=="string"){if(t==="rnd")return "RANDOM";if(t==="?")return "CONTAINS"}return t});let e=[];return n.forEach(t=>{if(typeof t=="object"&&"CNT?"in t)if(new RegExp(/.*\.[0-9]\..*/).test(t["CNT?"])){let i=t["CNT?"].split("."),l=i.pop(),f=i.pop();if(f===void 0||l===void 0){p.error("Error parsing ink file: Conditional statement is not valid",n);return}let T=parseInt(f),a=i.join(".");if(a.includes("^.")){let u=a.split("."),E=u[u.length-1].replaceAll(".",s);u.pop(),a=u.join(".")+"."+E,l.includes("c-")&&(a=a+s+l);}else a=a.replaceAll(".",s);let h=g(a,r);if(!h)return;e.push({type:"compare",leftValue:d(h),operator:">=",rightValue:{type:"value",value:T}});}else {let i=g(t["CNT?"],r);if(!i)return;e.push(d(i));}else if(typeof t=="object"&&"VAR?"in t)e.push(P(t["VAR?"],o));else if(t==="&&"||t==="||"){if(e.length>=2){let i={type:"union",unionType:t==="&&"?"and":"or",conditions:[e[e.length-2],e[e.length-1]]};e.pop(),e.pop(),e.push(i);}}else if(t==="!")if(e.length===0)p.error("Error parsing ink file: Conditional statement is not valid",n);else {let i={type:"union",unionType:"not",condition:e[e.length-1]};e[e.length-1]=i;}else if(t&&typeof t=="string"&&V.includes(t))if(e.length<2)p.error("Error parsing ink file: Conditional statement is not valid",n);else {let i={type:"compare",operator:t,rightValue:e[e.length-1],leftValue:e[e.length-2]};e.pop(),e.pop(),e.push(i);}else if(t&&typeof t=="string"&&y.includes(t))if(e.length<2)p.error("Error parsing ink file: Conditional statement is not valid",n);else {let i={type:"arithmetic",operator:t,rightValue:e[e.length-1],leftValue:e[e.length-2]};e.pop(),e.pop(),e.push(i);}else if(t&&typeof t=="string"&&A.includes(t)){let i={type:"arithmeticsingle",operator:t,leftValue:e[e.length-1]};e.pop(),e.push(i);}else t&&typeof t=="string"?t.startsWith("^")&&e.push(O(t)):typeof t=="object"&&"^->"in t?t["^->"].includes("$r")||e.push(t["^->"]):e.push(t);}),e}function d(n){return {type:"value",storageType:"label",storageOperationType:"get",label:n}}function M(n,r,o){return N(n,r,o)}function P(n,r,o="storage"){let e=r.indexOf(n);return e>=0?{type:"value",storageType:"params",storageOperationType:"get",key:e}:{type:"value",storageOperationType:"get",storageType:o,key:n}}function v(n,r,o,e="storage"){let t=r.indexOf(n);return t>=0?{type:"value",storageType:"params",storageOperationType:"set",key:t,value:o}:{type:"value",storageOperationType:"set",storageType:e,key:n,value:o}}export{M as getParam,v as getSetValue,P as getValue};