@drincs/pixi-vn-json 1.7.2 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/unifier.mjs CHANGED
@@ -1 +1,3 @@
1
- var c=Object.defineProperty;var P=(n,i,s)=>i in n?c(n,i,{enumerable:true,configurable:true,writable:true,value:s}):n[i]=s;var o=(n,i,s)=>P(n,typeof i!="symbol"?i+"":i,s);var t;(p=>(p.log=(r,...a)=>console.log(`[Pixi\u2019VN Json] ${r}`,...a),p.warn=(r,...a)=>console.warn(`[Pixi\u2019VN Json] ${r}`,...a),p.error=(r,...a)=>console.error(`[Pixi\u2019VN Json] ${r}`,...a),p.info=(r,...a)=>console.info(`[Pixi\u2019VN Json] ${r}`,...a)))(t||(t={}));var e=class{static init(i){this._loadAssets=i.loadAssets,this._soundOperation=i.soundOperation,this._imageOperation=i.imageOperation,this._videoOperation=i.videoOperation,this._imageContainerOperation=i.imageContainerOperation,this._canvasElementOperation=i.canvasElementOperation,this._setStorageValue=i.setStorageValue,this._inputOperation=i.inputOperation,this._tickerOperation=i.tickerOperation,this._effectOperation=i.effectOperation,this._animateOperation=i.animateOperation,this._getLogichValue=i.getLogichValue,this._getConditionalStep=i.getConditionalStep;}static get loadAssets(){return this._loadAssets}static get soundOperation(){return this._soundOperation}static get imageOperation(){return this._imageOperation}static get videoOperation(){return this._videoOperation}static get imageContainerOperation(){return this._imageContainerOperation}static get canvasElementOperation(){return this._canvasElementOperation}static get setStorageValue(){return this._setStorageValue}static get inputOperation(){return this._inputOperation}static get tickerOperation(){return this._tickerOperation}static get effectOperation(){return this._effectOperation}static get animateOperation(){return this._animateOperation}static get getLogichValue(){return this._getLogichValue}static get getConditionalStep(){return this._getConditionalStep}};o(e,"_loadAssets",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_soundOperation",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_imageOperation",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_videoOperation",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_imageContainerOperation",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_canvasElementOperation",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_setStorageValue",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_inputOperation",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_tickerOperation",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_effectOperation",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_animateOperation",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_getLogichValue",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),o(e,"_getConditionalStep",()=>{throw t.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")});export{e as JsonUnifier};
1
+ import {narration,NarrationManagerStatic}from'@drincs/pixi-vn/narration';import {storage,SYSTEM_RESERVED_STORAGE_KEYS}from'@drincs/pixi-vn/storage';var G=Object.defineProperty;var j=(t,e,i)=>e in t?G(t,e,{enumerable:true,configurable:true,writable:true,value:i}):t[e]=i;var f=(t,e,i)=>j(t,typeof e!="symbol"?e+"":e,i);var n=class n{static t(e){return Array.isArray(e)?e.map(i=>n.translate(`${i}`)):n.translate(`${e}`)}static set beforeToTranslate(e){n._beforeToTranslate=e;}static set translate(e){n._translate=e;}static get translate(){return e=>{let i=e;return n._beforeToTranslate&&(i=n._beforeToTranslate(i)),i=n._translate(i),n._afterToTranslate&&(i=n._afterToTranslate(i)),i}}static set afterToTranslate(e){n._afterToTranslate=e;}static addKey(e,i,l){let o=l.defaultValue||"empty_string";typeof i=="string"&&(i=[i]),Array.isArray(i)&&i.forEach(r=>{e[r]===void 0&&(o==="empty_string"?e[r]="":o==="copy_key"&&(n._beforeToTranslate?e[r]=n._beforeToTranslate(r):e[r]=r));});}static getConditionalsThenElse(e,i=[]){if(typeof e=="object"&&e&&"type"in e)if(e.type==="ifelse")e.then&&n.getConditionalsThenElse(e.then,i),e.else&&n.getConditionalsThenElse(e.else,i);else if(e.type==="stepswitch"){if(e.elements)if(Array.isArray(e.elements))e.elements.forEach(l=>{n.getConditionalsThenElse(l,i);});else if(e.elements.type==="ifelse"){let l=[];n.getConditionalsThenElse(e.elements,l),l.forEach(o=>{i.push(...o);});}else if(e.elements.type==="stepswitch"){let l=[];n.getConditionalsThenElse(e.elements,l),l.forEach(o=>{i.push(...o);});}else n.getConditionalsThenElse(e.elements,i);}else e.type==="resulttocombine"?(e.firstItem&&n.getConditionalsThenElse(e.firstItem,i),e.secondConditionalItem&&e.secondConditionalItem.forEach(l=>{n.getConditionalsThenElse(l,i);})):i.push(e);else e&&i.push(e);return i}static generateJsonTranslation(e,i={},l={}){let{defaultValue:o="copy_key"}=l;return e.forEach(r=>{if(r.choices){let c=[];Array.isArray(r.choices)?c=[r.choices]:c=n.getConditionalsThenElse(r.choices),c.forEach(d=>d.forEach(g=>{if("type"in g){let V=[];g.type==="ifelse"||g.type==="stepswitch"?n.getConditionalsThenElse(g,V):V=[g],V.map(m=>n.getConditionalsThenElse(m.text)).forEach(m=>{Array.isArray(m)&&m.forEach(P=>{Array.isArray(P)?P.forEach(h=>{typeof h=="string"?n.addKey(i,h,{defaultValue:o}):n.getConditionalsThenElse(h).forEach(y=>{Array.isArray(y)?y.forEach(J=>{typeof J=="string"&&n.addKey(i,J,{defaultValue:o});}):typeof y=="string"&&n.addKey(i,y,{defaultValue:o});});}):typeof P=="string"&&n.addKey(i,P,{defaultValue:o});});});}}));}if(r.dialogue){let c=[];Array.isArray(r.dialogue)?c=[r.dialogue]:c=n.getConditionalsThenElse(r.dialogue),c.forEach(d=>{if(typeof d=="string")n.addKey(i,d,{defaultValue:o});else if("text"in d){let g=n.getConditionalsThenElse(d.text);typeof g=="string"&&(g=[g]),g.forEach(V=>{typeof V=="string"?n.addKey(i,V,{defaultValue:o}):n.getConditionalsThenElse(V).forEach(m=>{typeof m=="string"?n.addKey(i,m,{defaultValue:o}):Array.isArray(m)&&m.forEach(P=>{typeof P=="string"?n.addKey(i,P,{defaultValue:o}):n.getConditionalsThenElse(P).forEach(h=>{typeof h=="string"&&n.addKey(i,h,{defaultValue:o});});});});});}});}r.conditionalStep&&n.getConditionalsThenElse(r.conditionalStep).forEach(d=>{Array.isArray(d)?n.generateJsonTranslation(d,i,l):n.generateJsonTranslation([d],i,l);});}),i}};f(n,"_beforeToTranslate"),f(n,"_translate",e=>e),f(n,"_afterToTranslate");var E=n;var S=E;var O="___param___";var u;(o=>(o.log=(r,...c)=>console.log(`[Pixi\u2019VN Json] ${r}`,...c),o.warn=(r,...c)=>console.warn(`[Pixi\u2019VN Json] ${r}`,...c),o.error=(r,...c)=>console.error(`[Pixi\u2019VN Json] ${r}`,...c),o.info=(r,...c)=>console.info(`[Pixi\u2019VN Json] ${r}`,...c)))(u||(u={}));function R(t){try{if(typeof t>"u")return t;let e=JSON.stringify(t);return JSON.parse(e)}catch(e){throw u.error("Error creating exportable element",t,e),new Error("[Pixi\u2019VN] Error creating exportable element")}}function L(t){let e=s(t.value),i;switch(e&&typeof e=="object"&&"type"in e?i=s(e):i=e,t.storageType){case "flagStorage":storage.setFlag(t.key,t.value);break;case "storage":storage.setVariable(t.key,i);break;case "tempstorage":storage.setTempVariable(t.key,i);break;case "params":let l=storage.getVariable(`${O}${narration.openedLabels.length-1}`)||[];l&&l.length-1>=t.key&&(l[t.key]=i),storage.setTempVariable(`${O}${narration.openedLabels.length-1}`,l);break}}function s(t){let e=K(t);if(e&&typeof e=="object"&&"type"in e)switch(e.type){case "value":return _(e);case "arithmetic":case "arithmeticsingle":return z(e);case "compare":case "valueCondition":case "union":return F(e)}return e}function z(t){let e=s(t.leftValue);switch(t.type){case "arithmetic":let i=s(t.rightValue);switch(t.operator){case "*":return e*i;case "/":return e/i;case "+":return e+i;case "-":return e-i;case "%":return e%i;case "POW":return Math.pow(e,i);case "RANDOM":return narration.getRandomNumber(e,i)}case "arithmeticsingle":switch(t.operator){case "INT":return parseInt(e);case "FLOOR":return Math.floor(e);case "FLOAT":return parseFloat(e)}break}}function _(t){if(t&&typeof t=="object"&&"type"in t&&t.type==="value"&&t.storageOperationType==="get")switch(t.storageType){case "storage":case "tempstorage":return storage.getVariable(t.key);case "flagStorage":return storage.getFlag(t.key);case "label":return narration.getTimesLabelOpened(t.label);case "choice":return narration.getTimesChoiceMade(t.index);case "logic":return s(t.operation);case "params":let e=storage.getVariable(`${O}${narration.openedLabels.length-1}`)||[];if(e&&e.length>t.key)return e[t.key];u.warn("getValue params not found");return}return t}function F(t){if(!t)return false;if(typeof t!="object"||!("type"in t))return !!t;switch(t.type){case "compare":let e=s(t.leftValue),i=s(t.rightValue);switch(t.operator){case "==":return e===i;case "!=":return e!==i;case "<":return e<i;case "<=":return e<=i;case ">":return e>i;case ">=":return e>=i;case "CONTAINS":return e.toString().includes(i.toString())}break;case "valueCondition":return !!s(t.value);case "union":return M(t)}return !!t}function M(t){if(t.unionType==="not")return !s(t.condition);let e=t.unionType==="and";for(let i=0;i<t.conditions.length;i++)if(e=s(t.conditions[i])||false,t.unionType==="and"){if(!e)return false}else if(e)return true;return e}function $(t,e){return Math.floor(Math.random()*(e-t+1)+t)}function K(t){if(Array.isArray(t)||!t)return t;if(t&&typeof t=="object"&&"type"in t)switch(t.type){case "resulttocombine":return X(t);case "ifelse":return s(t.condition)?s(t.then):s(t.else);case "stepswitch":let i=s(t.elements)||[];if(i.length===0){u.error("getValueFromConditionalStatements elements.length === 0");return}switch(t.choiceType){case "random":let l=$(0,i.length-1);return s(i[l]);case "loop":let o=NarrationManagerStatic.getCurrentStepTimesCounter(t.nestedId)-1;return o>i.length-1&&(o=o%i.length),s(i[o]);case "sequential":let r,c=NarrationManagerStatic.getCurrentStepTimesCounter(t.nestedId)-1;return t.end=="lastItem"&&(r=s(i[i.length-1])),c>i.length-1?r:s(i[c]);case "sequentialrandom":let d=NarrationManagerStatic.getRandomNumber(0,i.length-1,{nestedId:t.nestedId,onceOnly:true});if(d==null&&t.end=="lastItem"){let g=NarrationManagerStatic.getCurrentStepTimesCounterData(t.nestedId);if(!g||!g?.usedRandomNumbers){u.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}let V=g.usedRandomNumbers[`0-${i.length-1}`];return s(i[V[V.length-1]])}if(d==null){u.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}return s(i[d])}}return t}function b(t){if(t.conditionalStep){let e=R(s(t.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 i={...t,conditionalStep:void 0,...e};return b(i)}else storage.getFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY)&&storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,false);}return t}function X(t){let e=t.firstItem,i=[];t.secondConditionalItem?.forEach(o=>{if(Array.isArray(o))o.forEach(r=>{let c=s(r);i.push(c);});else {let r=s(o);i.push(r);}});let l=e?[e,...i]:i;if(l.length===0){u.warn("combinateResult toCheck.length === 0");return}if(typeof l[0]=="string")return S.t(l);if(typeof l[0]=="object"){let o=l,r,c=o.map((p,T)=>{p=b(p);let x=s(p.dialogue)||"";return T===0?(r=s(p.glueEnabled)||false,x):(typeof x=="object"&&"text"in x&&(x=x.character+": "+x.text),r===false&&(x=`
2
+
3
+ `+x),r=s(p.glueEnabled)||false,x)}),d=s(c[0]),g=typeof d=="object"&&"character"in d?d.character:void 0,V=c.flatMap(p=>{let T;p&&typeof p=="object"&&"text"in p?T=p.text:T=p;let x;return Array.isArray(T)?x=T.map(k=>{let D=s(k);return S.t(`${D}`)}):x=s(T)||"",S.t(x)}),w=o.find(p=>p.end),m=o.find(p=>p.choices),P=false,h=false;o.length>0&&(o[0].glueEnabled&&o[0].goNextStep&&o[0].dialogue===void 0&&storage.setFlag(SYSTEM_RESERVED_STORAGE_KEYS.ADD_NEXT_DIALOG_TEXT_INTO_THE_CURRENT_DIALOG_FLAG_KEY,true),P=o[o.length-1].glueEnabled,h=o.reverse().find(p=>!(p.operations&&(!p.dialogue||!p.choices)))?.goNextStep);let y=o.find(p=>p.labelToOpen),J=[];return o.forEach(p=>{p.operations&&J.forEach(T=>{J.push(T);});}),{dialogue:g?{character:g,text:V}:V,end:w?.end,choices:m?.choices,glueEnabled:P,goNextStep:h,labelToOpen:y?.labelToOpen,operations:J}}}var a=class a{static init(e){a._loadAssets=e.loadAssets,a._soundOperation=e.soundOperation,a._imageOperation=e.imageOperation,a._videoOperation=e.videoOperation,a._imageContainerOperation=e.imageContainerOperation,a._canvasElementOperation=e.canvasElementOperation,a._setStorageValue=e.setStorageValue,a._inputOperation=e.inputOperation,a._tickerOperation=e.tickerOperation,a._effectOperation=e.effectOperation,a._animateOperation=e.animateOperation,a._getLogichValue=e.getLogichValue,a._getConditionalStep=e.getConditionalStep;}static get loadAssets(){return a._loadAssets}static get soundOperation(){return a._soundOperation}static get imageOperation(){return a._imageOperation}static get videoOperation(){return a._videoOperation}static get imageContainerOperation(){return a._imageContainerOperation}static get canvasElementOperation(){return a._canvasElementOperation}static get setStorageValue(){return a._setStorageValue}static get inputOperation(){return a._inputOperation}static get tickerOperation(){return a._tickerOperation}static get effectOperation(){return a._effectOperation}static get animateOperation(){return a._animateOperation}static get getLogichValue(){return a._getLogichValue}static get getConditionalStep(){return a._getConditionalStep}};f(a,"_loadAssets",()=>{throw u.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),f(a,"_soundOperation",()=>{throw u.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),f(a,"_imageOperation",()=>{throw u.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),f(a,"_videoOperation",()=>{throw u.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),f(a,"_imageContainerOperation",()=>{throw u.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),f(a,"_canvasElementOperation",()=>{throw u.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),f(a,"_setStorageValue",L),f(a,"_inputOperation",()=>{throw u.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),f(a,"_tickerOperation",()=>{throw u.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),f(a,"_effectOperation",()=>{throw u.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),f(a,"_animateOperation",()=>{throw u.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new Error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),f(a,"_getLogichValue",s),f(a,"_getConditionalStep",b);var A=a;export{A as JsonUnifier};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drincs/pixi-vn-json",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "type": "module",
5
5
  "description": "Pixi'VN can be integrated with JSON files to create a visual novel.",
6
6
  "main": "./dist/index.cjs",
@@ -11,9 +11,9 @@
11
11
  ],
12
12
  "scripts": {
13
13
  "build:unifier": "tsup --config tsup.unifier.config.ts",
14
- "build:importer": "tsup --config tsup.importer.config.ts",
14
+ "build:submodules": "tsup --config tsup.submodules.config.ts",
15
15
  "build:index": "tsup --config tsup.config.ts",
16
- "build": "npm run build:unifier && npm run build:importer && npm run build:index",
16
+ "build": "npm run build:unifier && npm run build:submodules && npm run build:index",
17
17
  "test": "vitest"
18
18
  },
19
19
  "exports": {
@@ -34,12 +34,19 @@
34
34
  "import": "./dist/importer.mjs",
35
35
  "require": "./dist/importer.cjs",
36
36
  "default": "./dist/importer.mjs"
37
+ },
38
+ "./translator": {
39
+ "types": "./dist/translator.d.ts",
40
+ "import": "./dist/translator.mjs",
41
+ "require": "./dist/translator.cjs",
42
+ "default": "./dist/translator.mjs"
37
43
  }
38
44
  },
39
45
  "typesVersions": {
40
46
  "*": {
41
47
  "unifier": ["./dist/unifier.d.ts"],
42
- "importer": ["./dist/importer.d.ts"]
48
+ "importer": ["./dist/importer.d.ts"],
49
+ "translator": ["./dist/translator.d.ts"]
43
50
  }
44
51
  },
45
52
  "repository": {