@drincs/pixi-vn-json
Version:
Pixi'VN can be integrated with JSON files to create a visual novel.
1 lines • 2.89 kB
JavaScript
var h=class t{static _beforeToTranslate=void 0;static _translate=e=>e;static _afterToTranslate=void 0;static t(e){return Array.isArray(e)?e.map(i=>t.translate(`${i}`)):t.translate(`${e}`)}static set beforeToTranslate(e){t._beforeToTranslate=e;}static set translate(e){t._translate=e;}static get translate(){return e=>{let i=e;return t._beforeToTranslate&&(i=t._beforeToTranslate(i)),i=t._translate(i),t._afterToTranslate&&(i=t._afterToTranslate(i)),i}}static set afterToTranslate(e){t._afterToTranslate=e;}static addKey(e,i,s){let n=s.defaultValue||"empty_string";typeof i=="string"&&(i=[i]),Array.isArray(i)&&i.forEach(r=>{e[r]===void 0&&(n==="empty_string"?e[r]="":n==="copy_key"&&(t._beforeToTranslate?e[r]=t._beforeToTranslate(r):e[r]=r));});}static getConditionalsThenElse(e,i=[]){if(typeof e=="object"&&e&&"type"in e)if(e.type==="ifelse")e.then&&t.getConditionalsThenElse(e.then,i),e.else&&t.getConditionalsThenElse(e.else,i);else if(e.type==="stepswitch"){if(e.elements)if(Array.isArray(e.elements))e.elements.forEach(s=>{t.getConditionalsThenElse(s,i);});else if(e.elements.type==="ifelse"){let s=[];t.getConditionalsThenElse(e.elements,s),s.forEach(n=>{i.push(...n);});}else if(e.elements.type==="stepswitch"){let s=[];t.getConditionalsThenElse(e.elements,s),s.forEach(n=>{i.push(...n);});}else t.getConditionalsThenElse(e.elements,i);}else e.type==="resulttocombine"?(e.firstItem&&t.getConditionalsThenElse(e.firstItem,i),e.secondConditionalItem&&e.secondConditionalItem.forEach(s=>{t.getConditionalsThenElse(s,i);})):i.push(e);else e&&i.push(e);return i}static generateJsonTranslation(e,i={},s={}){return e.forEach(n=>{if(n.choices){let r=[];Array.isArray(n.choices)?r=[n.choices]:r=t.getConditionalsThenElse(n.choices),r.forEach(l=>l.forEach(o=>{if("type"in o){let g=[];o.type==="ifelse"||o.type==="stepswitch"?t.getConditionalsThenElse(o,g):g=[o],g.map(a=>t.getConditionalsThenElse(a.text)).forEach(a=>{Array.isArray(a)&&a.forEach(f=>{Array.isArray(f)?f.forEach(c=>{typeof c=="string"?t.addKey(i,c,s):t.getConditionalsThenElse(c).forEach(T=>{Array.isArray(T)?T.forEach(d=>{typeof d=="string"&&t.addKey(i,d,s);}):typeof T=="string"&&t.addKey(i,T,s);});}):typeof f=="string"&&t.addKey(i,f,s);});});}}));}if(n.dialogue){let r=[];Array.isArray(n.dialogue)?r=[n.dialogue]:r=t.getConditionalsThenElse(n.dialogue),r.forEach(l=>{typeof l=="string"?t.addKey(i,l,s):"text"in l&&Array.isArray(l.text)&&l.text.forEach(o=>{typeof o=="string"?t.addKey(i,o,s):t.getConditionalsThenElse(o).forEach(y=>{typeof y=="string"?t.addKey(i,y,s):Array.isArray(y)&&y.forEach(a=>{typeof a=="string"?t.addKey(i,a,s):t.getConditionalsThenElse(a).forEach(f=>{typeof f=="string"&&t.addKey(i,f,s);});});});});});}n.conditionalStep&&t.getConditionalsThenElse(n.conditionalStep).forEach(l=>{Array.isArray(l)?t.generateJsonTranslation(l,i,s):t.generateJsonTranslation([l],i,s);});}),i}};export{h as default};