@drincs/pixi-vn-json 1.12.0 → 1.13.0

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/index.cjs CHANGED
@@ -1,3 +1,2 @@
1
- 'use strict';var core=require('@drincs/pixi-vn-json/core'),importer=require('@drincs/pixi-vn-json/importer'),translator=require('@drincs/pixi-vn-json/translator'),canvas=require('@drincs/pixi-vn/canvas'),narration=require('@drincs/pixi-vn/narration'),sound=require('@drincs/pixi-vn/sound'),pixiVn=require('@drincs/pixi-vn'),storage=require('@drincs/pixi-vn/storage');var V="___param___";async function E(e){let a=core.JsonUnifier.getLogichValue(e);if(a)switch(a.type){case "assets":switch(a.operationType){case "load":await canvas.Assets.load(a.aliases);break;case "lazyload":canvas.Assets.backgroundLoad(a.aliases);break}break;case "bundle":switch(a.operationType){case "load":await canvas.Assets.loadBundle(a.aliases);break;case "lazyload":canvas.Assets.backgroundLoadBundle(a.aliases);break}break}}var r;(t=>(t.log=(l,...u)=>console.log(`[Pixi\u2019VN Json] ${l}`,...u),t.warn=(l,...u)=>console.warn(`[Pixi\u2019VN Json] ${l}`,...u),t.error=(l,...u)=>console.error(`[Pixi\u2019VN Json] ${l}`,...u),t.info=(l,...u)=>console.info(`[Pixi\u2019VN Json] ${l}`,...u)))(r||(r={}));async function b(e,a,i){switch(i.type){case "fade":await canvas.showWithFade(a.alias,e,i.props,i.priority);break;case "dissolve":await canvas.showWithDissolve(a.alias,e,i.props,i.priority);break;case "movein":case "moveout":await canvas.moveIn(a.alias,e,i.props,i.priority);break;case "zoomin":case "zoomout":await canvas.zoomIn(a.alias,e,i.props,i.priority);break;case "pushin":case "pushout":await canvas.pushIn(a.alias,e,i.props,i.priority);break}}function h(e){if(e.transition)switch(e.transition.type){case "fade":canvas.removeWithFade(e.alias,e.transition.props,e.transition.priority);break;case "dissolve":canvas.removeWithDissolve(e.alias,e.transition.props,e.transition.priority);break;case "movein":case "moveout":canvas.moveOut(e.alias,e.transition.props,e.transition.priority);break;case "zoomin":case "zoomout":canvas.zoomOut(e.alias,e.transition.props,e.transition.priority);break;case "pushin":case "pushout":canvas.pushOut(e.alias,e.transition.props,e.transition.priority);break}else canvas.canvas.remove(e.alias);}async function L(e){switch(e.operationType){case "show":if(e.transition){let a=new canvas.ImageSprite(e.props,e.url||e.alias);await b(a,e,e.transition);}else await canvas.showImage(e.alias,e.url,e.props);break;case "edit":{let a=canvas.canvas.find(e.alias);a?e.props&&await a.setMemory({...a.memory,...e.props}):r.error(`Image with alias ${e.alias} not found.`);break}case "remove":h(e);break}}async function A(e){switch(e.operationType){case "show":if(e.transition){let a=new canvas.VideoSprite(e.props,e.url||e.alias);await b(a,e,e.transition);}else await canvas.showVideo(e.alias,e.url,e.props);break;case "edit":{let a=canvas.canvas.find(e.alias);a?e.props&&await a.setMemory({...a.memory,...e.props}):r.error(`Video with alias ${e.alias} not found.`);break}case "remove":h(e);break;case "pause":{let a=canvas.canvas.find(e.alias);a?a.paused=true:r.error(`Video with alias ${e.alias} not found.`);break}case "resume":{let a=canvas.canvas.find(e.alias);a?a.paused=false:r.error(`Video with alias ${e.alias} not found.`);break}}}async function R(e){switch(e.operationType){case "show":if(e.transition){let a=new canvas.ImageContainer(e.props,e.urls);await b(a,e,e.transition);}else await canvas.showImageContainer(e.alias,e.urls,e.props);break;case "edit":{let a=canvas.canvas.find(e.alias);a?e.props&&await a.setMemory({...a.memory,...e.props}):r.error(`ImageContainer with alias ${e.alias} not found.`);break}case "remove":h(e);break}}async function M(e){switch(e.operationType){case "show":if(e.props=e.props||{},e.props.text=translator.translator.t(e.text),e.transition){let a=new canvas.Text(e.props);await b(a,e,e.transition);}else canvas.showText(e.alias,e.text,e.props);break;case "edit":{let a=canvas.canvas.find(e.alias);a?e.props&&await a.setMemory({...a.memory,...e.props}):r.error(`Text with alias ${e.alias} not found.`);break}case "remove":h(e);break}}async function $(e){switch(e.operationType){case "edit":try{let a=canvas.canvas.find(e.alias);a?e.props&&a.setMemory({...a.memory,...e.props}):r.error(`Canvas Element with alias ${e.alias} not found.`);}catch(a){r.error(`There was an error while trying to edit the canvas element with alias ${e.alias}.`,a);}break;case "remove":h(e);break}}async function G(e){e.type==="shake"&&await canvas.shakeEffect(e.alias,e.props,e.priority);}function D(e){switch(e.type){case "animate":canvas.canvas.animate(e.alias,e.keyframes,e.options,e.priority);break;case "animate-sequence":canvas.canvas.animate(e.alias,e.sequence,e.options,e.priority);break}}function j(e){switch(e.type){case "input":narration.narration.requestInput({type:e.valueType},e.defaultValue);break;case "dialogue":narration.narration.dialogue=void 0;break}}function F(e){switch(e.operationType){case "play":e.url?sound.sound.play(e.alias,e.url,e.props):sound.sound.play(e.alias,e.props);break;case "stop":switch(e.type){case "sound":sound.sound.stop(e.alias);break;case "all":sound.sound.stopAll();break}break;case "pause":switch(e.type){case "sound":sound.sound.pause(e.alias);break;case "channel":sound.sound.findChannel(e.alias).pauseAll();break;case "all":sound.sound.pauseAll();break}break;case "resume":switch(e.type){case "sound":sound.sound.resume(e.alias);break;case "channel":sound.sound.findChannel(e.alias).resumeAll();break;case "all":sound.sound.resumeAll();break}break;case "edit":Object.entries(e.props).forEach(([a,i])=>{let o=sound.sound.find(e.alias);o&&(a==="volume"?o.volume.value=i:o.paused=i);});break}}function U(e){let a=core.JsonUnifier.getLogichValue(e.value),i;switch(a&&typeof a=="object"&&"type"in a?i=core.JsonUnifier.getLogichValue(a):i=a,e.storageType){case "flagStorage":storage.storage.setFlag(e.key,e.value);break;case "storage":storage.storage.set(e.key,i);break;case "tempstorage":storage.storage.setTempVariable(e.key,i);break;case "params":{let o=storage.storage.get(`${V}${narration.narration.openedLabels.length-1}`)||[];o&&o.length-1>=e.key&&(o[e.key]=i),storage.storage.setTempVariable(`${V}${narration.narration.openedLabels.length-1}`,o);break}}}function z(e){let a=core.JsonUnifier.getLogichValue(e.value),i;switch(a&&typeof a=="object"&&"type"in a?i=core.JsonUnifier.getLogichValue(a):i=a,e.storageType){case "storage":case "tempstorage":storage.storage.default={[e.key]:i};break}}function y(e){let a=S(e);if(a&&typeof a=="object"&&"type"in a)switch(a.type){case "value":return xe(a);case "arithmetic":case "arithmeticsingle":return ye(a);case "compare":case "valueCondition":case "union":return be(a)}return a}function ye(e){let a=core.JsonUnifier.getLogichValue(e.leftValue);switch(e.type){case "arithmetic":{let i=core.JsonUnifier.getLogichValue(e.rightValue);switch(e.operator){case "*":return a*i;case "/":return a/i;case "+":return a+i;case "-":return a-i;case "%":return a%i;case "POW":return a**i;case "RANDOM":return narration.narration.getRandomNumber(a,i)}}case "arithmeticsingle":switch(e.operator){case "INT":return parseInt(a);case "FLOOR":return Math.floor(a);}break}}function xe(e){if(e&&typeof e=="object"&&"type"in e&&e.type==="value"&&e.storageOperationType==="get")switch(e.storageType){case "storage":case "tempstorage":return e.key==="_input_value_"?narration.narration.inputValue:storage.storage.get(e.key);case "flagStorage":return storage.storage.getFlag(e.key);case "label":return narration.narration.getTimesLabelOpened(e.label);case "choice":return narration.narration.getTimesChoiceMade(e.index);case "logic":return core.JsonUnifier.getLogichValue(e.operation);case "params":{let a=storage.storage.get(`${V}${narration.narration.openedLabels.length-1}`)||[];if(a&&a.length>e.key)return a[e.key];r.warn("getValue params not found");return}}return e}function be(e){if(!e)return false;if(typeof e!="object"||!("type"in e))return !!e;switch(e.type){case "compare":{let a=core.JsonUnifier.getLogichValue(e.leftValue),i=core.JsonUnifier.getLogichValue(e.rightValue);switch(e.operator){case "==":return a===i;case "!=":return a!==i;case "<":return a<i;case "<=":return a<=i;case ">":return a>i;case ">=":return a>=i;case "CONTAINS":return a.toString().includes(i.toString())}break}case "valueCondition":return !!core.JsonUnifier.getLogichValue(e.value);case "union":return Ne(e)}return !!e}function Ne(e){if(e.unionType==="not")return !y(e.condition);let a=e.unionType==="and";for(let i=0;i<e.conditions.length;i++)if(a=core.JsonUnifier.getLogichValue(e.conditions[i])||false,e.unionType==="and"){if(!a)return false}else if(a)return true;return a}function Te(e,a){return Math.floor(Math.random()*(a-e+1)+e)}function S(e){if(Array.isArray(e)||!e)return e;if(e&&typeof e=="object"&&"type"in e)switch(e.type){case "resulttocombine":return Pe(e);case "ifelse":return core.JsonUnifier.getLogichValue(e.condition)?core.JsonUnifier.getLogichValue(e.then):core.JsonUnifier.getLogichValue(e.else);case "stepswitch":{let a=core.JsonUnifier.getLogichValue(e.elements)||[];if(a.length===0){r.error("getValueFromConditionalStatements elements.length === 0");return}switch(e.choiceType){case "random":{let i=Te(0,a.length-1);return core.JsonUnifier.getLogichValue(a[i])}case "loop":{let i=narration.NarrationManagerStatic.getCurrentStepTimesCounter(e.nestedId)-1;return i>a.length-1?(i=i%a.length,core.JsonUnifier.getLogichValue(a[i])):core.JsonUnifier.getLogichValue(a[i])}case "sequential":{let i,o=narration.NarrationManagerStatic.getCurrentStepTimesCounter(e.nestedId)-1;return e.end=="lastItem"&&(i=core.JsonUnifier.getLogichValue(a[a.length-1])),o>a.length-1?i:core.JsonUnifier.getLogichValue(a[o])}case "sequentialrandom":{let i=narration.NarrationManagerStatic.getRandomNumber(0,a.length-1,{nestedId:e.nestedId,onceOnly:true});if(i==null&&e.end=="lastItem"){let o=narration.NarrationManagerStatic.getCurrentStepTimesCounterData(e.nestedId);if(!o||!o?.usedRandomNumbers){r.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}let t=o.usedRandomNumbers[`0-${a.length-1}`];return core.JsonUnifier.getLogichValue(a[t[t.length-1]])}if(i==null){r.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}return core.JsonUnifier.getLogichValue(a[i])}}}}return e}function T(e){if(e.conditionalStep){let a=pixiVn.createExportableElement(core.JsonUnifier.getLogichValue(e.conditionalStep));if(a?.glueEnabled===void 0&&delete a?.glueEnabled,a?.goNextStep===void 0&&delete a?.goNextStep,a?.end===void 0&&delete a?.end,a?.choices===void 0&&delete a?.choices,a?.dialogue===void 0&&delete a?.dialogue,a?.labelToOpen===void 0&&delete a?.labelToOpen,a?.operations===void 0&&delete a?.operations,a){let i={...e,conditionalStep:void 0,...a};return T(i)}else narration.narration.dialogGlue&&(narration.narration.dialogGlue=false);}return e}function Pe(e){let a=e.firstItem,i=[];e.secondConditionalItem?.forEach(t=>{if(Array.isArray(t))t.forEach(l=>{let u=core.JsonUnifier.getLogichValue(l);i.push(u);});else {let l=core.JsonUnifier.getLogichValue(t);i.push(l);}});let o=a?[a,...i]:i;if(o.length===0){r.warn("combinateResult toCheck.length === 0");return}if(typeof o[0]=="string")return translator.translator.t(o);if(typeof o[0]=="object"){let t=o,l,u=false,C=t.map((s,g)=>{s=T(s);let c=core.JsonUnifier.getLogichValue(s.dialogue)||"";return g===0?(l=core.JsonUnifier.getLogichValue(s.glueEnabled)||false,c):(typeof c=="object"&&"text"in c&&(c=c.character+": "+c.text),l===false&&u&&(c=`
2
-
3
- `+c),c&&(u=true),l=core.JsonUnifier.getLogichValue(s.glueEnabled)||false,c)}),P=core.JsonUnifier.getLogichValue(C[0]),k=typeof P=="object"&&"character"in P?P.character:void 0,O=C.flatMap(s=>{let g;s&&typeof s=="object"&&"text"in s?g=s.text:g=s;let c;return Array.isArray(g)?c=g.map(B=>{let H=core.JsonUnifier.getLogichValue(B);return translator.translator.t(`${H}`)}):c=core.JsonUnifier.getLogichValue(g)||"",translator.translator.t(c)}),W=t.find(s=>s.end),q=t.find(s=>s.choices),v=false,I=false;t.length>0&&(t[0].glueEnabled&&t[0].goNextStep&&t[0].dialogue===void 0&&(narration.narration.dialogGlue=true),v=t[t.length-1].glueEnabled,I=t.reverse().find(s=>!(s.operations&&(!s.dialogue||!s.choices)))?.goNextStep);let X=t.find(s=>s.labelToOpen),J=[];return t.forEach(s=>{s.operations&&(J=[...J,...s.operations]);}),{dialogue:k?{character:k,text:O}:O,end:W?.end,choices:q?.choices,glueEnabled:v,goNextStep:I,labelToOpen:X?.labelToOpen,operations:J}}}function Ze({getLogichValue:e=y}){core.JsonUnifier.init({animateOperation:D,canvasElementOperation:$,effectOperation:G,imageContainerOperation:R,imageOperation:L,textOperation:M,narrationOperation:j,loadAssets:E,soundOperation:F,videoOperation:A,setStorageValue:U,setInitialStorageValue:z,getLogichValue:a=>e?e(S(a),y):y(a),getConditionalStep:T});}exports.PIXIVNJSON_PARAM_ID=V;exports.init=Ze;Object.keys(core).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return core[k]}})});Object.keys(importer).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return importer[k]}})});Object.keys(translator).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return translator[k]}})});
1
+ 'use strict';var actions=require('@drincs/pixi-vn-json/actions'),core=require('@drincs/pixi-vn-json/core'),interpreter=require('@drincs/pixi-vn-json/interpreter'),translator=require('@drincs/pixi-vn-json/translator');exports.VariableGetter=void 0;(A=>{let e=new Set;function L(i){e.add(i);}A.add=L;function J(){e.clear();}A.clear=J;function w(i,o={}){let n=r=>actions.getLogichValue(r,o)??void 0,a=actions.getValueFromConditionalStatements(i,o);if(e.size===0)return n(a);let s=n;for(let r of e){let d=s;s=c=>r(c,d)??void 0;}return s(a)}A.getLogichValue=w;})(exports.VariableGetter||(exports.VariableGetter={}));var p={version:"1.13.0"};var f="___param___",x=`https://pixi-vn.web.app/schemas/${p.version}/schema.json`,h=["==","!=","<","<=",">",">=","CONTAINS"];function X(){core.JsonUnifier.init({animateOperation:actions.animateOperation,canvasElementOperation:actions.canvasElementOperation,effectOperation:actions.effectOperation,imageContainerOperation:actions.imageContainerOperation,imageOperation:actions.imageOperation,textOperation:actions.textOperation,narrationOperation:actions.narrationOperation,loadAssets:actions.loadAssets,soundOperation:actions.soundOperation,videoOperation:actions.videoOperation,setStorageValue:actions.setStorageValue,setInitialStorageValue:actions.setInitialStorageValue,getLogichValue:exports.VariableGetter.getLogichValue,getConditionalStep:actions.getConditionalStep});}
2
+ exports.PIXIVNJSON_PARAM_ID=f;exports.PIXIVNJSON_SCHEMA_URL=x;exports.PixiVNJsonComparationOperators=h;exports.init=X;Object.keys(core).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return core[k]}})});Object.keys(interpreter).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return interpreter[k]}})});Object.keys(translator).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return translator[k]}})});