@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/README.md +40 -29
- package/dist/{importer.d.cts → PixiVNJsonLabelStep-DgN7qF7j.d.cts} +477 -78
- package/dist/{importer.d.ts → PixiVNJsonLabelStep-DgN7qF7j.d.ts} +477 -78
- package/dist/PixiVNJsonLabelStep-dVwPLFMT.d.cts +991 -0
- package/dist/PixiVNJsonLabelStep-dVwPLFMT.d.ts +991 -0
- package/dist/actions.cjs +3 -0
- package/dist/actions.d.cts +127 -0
- package/dist/actions.d.ts +127 -0
- package/dist/actions.mjs +3 -0
- package/dist/core.cjs +1 -1
- package/dist/core.d.cts +33 -536
- package/dist/core.d.ts +33 -536
- package/dist/core.mjs +1 -1
- package/dist/index.cjs +2 -3
- package/dist/index.d.cts +556 -23
- package/dist/index.d.ts +556 -23
- package/dist/index.mjs +2 -3
- package/dist/interpreter.cjs +1 -0
- package/dist/interpreter.d.cts +96 -0
- package/dist/interpreter.d.ts +96 -0
- package/dist/interpreter.mjs +1 -0
- package/dist/schema.cjs +1 -0
- package/dist/schema.d.cts +41 -0
- package/dist/schema.d.ts +41 -0
- package/dist/schema.mjs +0 -0
- package/dist/translator.cjs +1 -1
- package/dist/translator.d.cts +512 -15
- package/dist/translator.d.ts +512 -15
- package/dist/translator.mjs +1 -1
- package/package.json +34 -4
- package/dist/importer.cjs +0 -1
- package/dist/importer.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {JsonUnifier}from'@drincs/pixi-vn-json/core';export*from'@drincs/pixi-vn-json/core';export*from'@drincs/pixi-vn-json/importer';import {translator as translator$1}from'@drincs/pixi-vn-json/translator';export*from'@drincs/pixi-vn-json/translator';import {canvas,VideoSprite,showVideo,Assets,Text,showText,ImageSprite,showImage,ImageContainer,showImageContainer,shakeEffect,pushOut,zoomOut,moveOut,removeWithDissolve,removeWithFade,pushIn,zoomIn,moveIn,showWithDissolve,showWithFade}from'@drincs/pixi-vn/canvas';import {narration,NarrationManagerStatic}from'@drincs/pixi-vn/narration';import {sound}from'@drincs/pixi-vn/sound';import {createExportableElement}from'@drincs/pixi-vn';import {storage}from'@drincs/pixi-vn/storage';var V="___param___";async function E(e){let a=JsonUnifier.getLogichValue(e);if(a)switch(a.type){case "assets":switch(a.operationType){case "load":await Assets.load(a.aliases);break;case "lazyload":Assets.backgroundLoad(a.aliases);break}break;case "bundle":switch(a.operationType){case "load":await Assets.loadBundle(a.aliases);break;case "lazyload":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 showWithFade(a.alias,e,i.props,i.priority);break;case "dissolve":await showWithDissolve(a.alias,e,i.props,i.priority);break;case "movein":case "moveout":await moveIn(a.alias,e,i.props,i.priority);break;case "zoomin":case "zoomout":await zoomIn(a.alias,e,i.props,i.priority);break;case "pushin":case "pushout":await pushIn(a.alias,e,i.props,i.priority);break}}function h(e){if(e.transition)switch(e.transition.type){case "fade":removeWithFade(e.alias,e.transition.props,e.transition.priority);break;case "dissolve":removeWithDissolve(e.alias,e.transition.props,e.transition.priority);break;case "movein":case "moveout":moveOut(e.alias,e.transition.props,e.transition.priority);break;case "zoomin":case "zoomout":zoomOut(e.alias,e.transition.props,e.transition.priority);break;case "pushin":case "pushout":pushOut(e.alias,e.transition.props,e.transition.priority);break}else canvas.remove(e.alias);}async function L(e){switch(e.operationType){case "show":if(e.transition){let a=new ImageSprite(e.props,e.url||e.alias);await b(a,e,e.transition);}else await showImage(e.alias,e.url,e.props);break;case "edit":{let a=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 VideoSprite(e.props,e.url||e.alias);await b(a,e,e.transition);}else await showVideo(e.alias,e.url,e.props);break;case "edit":{let a=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.find(e.alias);a?a.paused=true:r.error(`Video with alias ${e.alias} not found.`);break}case "resume":{let a=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 ImageContainer(e.props,e.urls);await b(a,e,e.transition);}else await showImageContainer(e.alias,e.urls,e.props);break;case "edit":{let a=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$1.t(e.text),e.transition){let a=new Text(e.props);await b(a,e,e.transition);}else showText(e.alias,e.text,e.props);break;case "edit":{let a=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.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 shakeEffect(e.alias,e.props,e.priority);}function D(e){switch(e.type){case "animate":canvas.animate(e.alias,e.keyframes,e.options,e.priority);break;case "animate-sequence":canvas.animate(e.alias,e.sequence,e.options,e.priority);break}}function j(e){switch(e.type){case "input":narration.requestInput({type:e.valueType},e.defaultValue);break;case "dialogue":narration.dialogue=void 0;break}}function F(e){switch(e.operationType){case "play":e.url?sound.play(e.alias,e.url,e.props):sound.play(e.alias,e.props);break;case "stop":switch(e.type){case "sound":sound.stop(e.alias);break;case "all":sound.stopAll();break}break;case "pause":switch(e.type){case "sound":sound.pause(e.alias);break;case "channel":sound.findChannel(e.alias).pauseAll();break;case "all":sound.pauseAll();break}break;case "resume":switch(e.type){case "sound":sound.resume(e.alias);break;case "channel":sound.findChannel(e.alias).resumeAll();break;case "all":sound.resumeAll();break}break;case "edit":Object.entries(e.props).forEach(([a,i])=>{let o=sound.find(e.alias);o&&(a==="volume"?o.volume.value=i:o.paused=i);});break}}function U(e){let a=JsonUnifier.getLogichValue(e.value),i;switch(a&&typeof a=="object"&&"type"in a?i=JsonUnifier.getLogichValue(a):i=a,e.storageType){case "flagStorage":storage.setFlag(e.key,e.value);break;case "storage":storage.set(e.key,i);break;case "tempstorage":storage.setTempVariable(e.key,i);break;case "params":{let o=storage.get(`${V}${narration.openedLabels.length-1}`)||[];o&&o.length-1>=e.key&&(o[e.key]=i),storage.setTempVariable(`${V}${narration.openedLabels.length-1}`,o);break}}}function z(e){let a=JsonUnifier.getLogichValue(e.value),i;switch(a&&typeof a=="object"&&"type"in a?i=JsonUnifier.getLogichValue(a):i=a,e.storageType){case "storage":case "tempstorage":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=JsonUnifier.getLogichValue(e.leftValue);switch(e.type){case "arithmetic":{let i=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.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.inputValue:storage.get(e.key);case "flagStorage":return storage.getFlag(e.key);case "label":return narration.getTimesLabelOpened(e.label);case "choice":return narration.getTimesChoiceMade(e.index);case "logic":return JsonUnifier.getLogichValue(e.operation);case "params":{let a=storage.get(`${V}${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=JsonUnifier.getLogichValue(e.leftValue),i=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 !!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=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 JsonUnifier.getLogichValue(e.condition)?JsonUnifier.getLogichValue(e.then):JsonUnifier.getLogichValue(e.else);case "stepswitch":{let a=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 JsonUnifier.getLogichValue(a[i])}case "loop":{let i=NarrationManagerStatic.getCurrentStepTimesCounter(e.nestedId)-1;return i>a.length-1?(i=i%a.length,JsonUnifier.getLogichValue(a[i])):JsonUnifier.getLogichValue(a[i])}case "sequential":{let i,o=NarrationManagerStatic.getCurrentStepTimesCounter(e.nestedId)-1;return e.end=="lastItem"&&(i=JsonUnifier.getLogichValue(a[a.length-1])),o>a.length-1?i:JsonUnifier.getLogichValue(a[o])}case "sequentialrandom":{let i=NarrationManagerStatic.getRandomNumber(0,a.length-1,{nestedId:e.nestedId,onceOnly:true});if(i==null&&e.end=="lastItem"){let o=NarrationManagerStatic.getCurrentStepTimesCounterData(e.nestedId);if(!o||!o?.usedRandomNumbers){r.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}let t=o.usedRandomNumbers[`0-${a.length-1}`];return JsonUnifier.getLogichValue(a[t[t.length-1]])}if(i==null){r.warn("getValueFromConditionalStatements randomIndexWhitExclude == undefined");return}return JsonUnifier.getLogichValue(a[i])}}}}return e}function T(e){if(e.conditionalStep){let a=createExportableElement(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.dialogGlue&&(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=JsonUnifier.getLogichValue(l);i.push(u);});else {let l=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$1.t(o);if(typeof o[0]=="object"){let t=o,l,u=false,C=t.map((s,g)=>{s=T(s);let c=JsonUnifier.getLogichValue(s.dialogue)||"";return g===0?(l=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=JsonUnifier.getLogichValue(s.glueEnabled)||false,c)}),P=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=JsonUnifier.getLogichValue(B);return translator$1.t(`${H}`)}):c=JsonUnifier.getLogichValue(g)||"",translator$1.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.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}){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});}export{V as PIXIVNJSON_PARAM_ID,Ze as init};
|
|
1
|
+
import {getValueFromConditionalStatements,getLogichValue,getConditionalStep,setInitialStorageValue,setStorageValue,videoOperation,soundOperation,loadAssets,narrationOperation,textOperation,imageOperation,imageContainerOperation,effectOperation,canvasElementOperation,animateOperation}from'@drincs/pixi-vn-json/actions';import {JsonUnifier}from'@drincs/pixi-vn-json/core';export*from'@drincs/pixi-vn-json/core';export*from'@drincs/pixi-vn-json/interpreter';export*from'@drincs/pixi-vn-json/translator';var t;(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=>getLogichValue(r,o)??void 0,a=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;})(t||(t={}));var p={version:"1.13.0"};var f="___param___",x=`https://pixi-vn.web.app/schemas/${p.version}/schema.json`,h=["==","!=","<","<=",">",">=","CONTAINS"];function X(){JsonUnifier.init({animateOperation:animateOperation,canvasElementOperation:canvasElementOperation,effectOperation:effectOperation,imageContainerOperation:imageContainerOperation,imageOperation:imageOperation,textOperation:textOperation,narrationOperation:narrationOperation,loadAssets:loadAssets,soundOperation:soundOperation,videoOperation:videoOperation,setStorageValue:setStorageValue,setInitialStorageValue:setInitialStorageValue,getLogichValue:t.getLogichValue,getConditionalStep:getConditionalStep});}
|
|
2
|
+
export{f as PIXIVNJSON_PARAM_ID,x as PIXIVNJSON_SCHEMA_URL,h as PixiVNJsonComparationOperators,t as VariableGetter,X as init};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var pixiVn=require('@drincs/pixi-vn'),core=require('@drincs/pixi-vn-json/core'),translator=require('@drincs/pixi-vn-json/translator'),narration=require('@drincs/pixi-vn/narration'),storage=require('@drincs/pixi-vn/storage');var te=Object.create;var R=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var ae=(a,e,r)=>e in a?R(a,e,{enumerable:true,configurable:true,writable:true,value:r}):a[e]=r;var D=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var q=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports);var se=(a,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ne(e))!re.call(a,n)&&n!==r&&R(a,n,{get:()=>e[n],enumerable:!(t=ie(e,n))||t.enumerable});return a};var pe=(a,e,r)=>(r=a!=null?te(oe(a)):{},se(R(r,"default",{value:a,enumerable:true}),a));var V=(a,e,r)=>ae(a,typeof e!="symbol"?e+"":e,r);var Q=q((I,K)=>{(function(a,e){typeof I=="object"?K.exports=I=e():typeof define=="function"&&define.amd?define([],e):a.CryptoJS=e();})(I,function(){var a=a||(function(e,r){var t;if(typeof window<"u"&&window.crypto&&(t=window.crypto),typeof self<"u"&&self.crypto&&(t=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(t=globalThis.crypto),!t&&typeof window<"u"&&window.msCrypto&&(t=window.msCrypto),!t&&typeof global<"u"&&global.crypto&&(t=global.crypto),!t&&typeof D=="function")try{t=D("crypto");}catch{}var n=function(){if(t){if(typeof t.getRandomValues=="function")try{return t.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof t.randomBytes=="function")try{return t.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function i(){}return function(o){var u;return i.prototype=o,u=new i,i.prototype=null,u}})(),p={},d=p.lib={},g=d.Base=(function(){return {extend:function(i){var o=s(this);return i&&o.mixIn(i),(!o.hasOwnProperty("init")||this.init===o.init)&&(o.init=function(){o.$super.init.apply(this,arguments);}),o.init.prototype=o,o.$super=this,o},create:function(){var i=this.extend();return i.init.apply(i,arguments),i},init:function(){},mixIn:function(i){for(var o in i)i.hasOwnProperty(o)&&(this[o]=i[o]);i.hasOwnProperty("toString")&&(this.toString=i.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),y=d.WordArray=g.extend({init:function(i,o){i=this.words=i||[],o!=r?this.sigBytes=o:this.sigBytes=i.length*4;},toString:function(i){return (i||J).stringify(this)},concat:function(i){var o=this.words,u=i.words,l=this.sigBytes,S=i.sigBytes;if(this.clamp(),l%4)for(var b=0;b<S;b++){var k=u[b>>>2]>>>24-b%4*8&255;o[l+b>>>2]|=k<<24-(l+b)%4*8;}else for(var j=0;j<S;j+=4)o[l+j>>>2]=u[j>>>2];return this.sigBytes+=S,this},clamp:function(){var i=this.words,o=this.sigBytes;i[o>>>2]&=4294967295<<32-o%4*8,i.length=e.ceil(o/4);},clone:function(){var i=g.clone.call(this);return i.words=this.words.slice(0),i},random:function(i){for(var o=[],u=0;u<i;u+=4)o.push(n());return new y.init(o,i)}}),f=p.enc={},J=f.Hex={stringify:function(i){for(var o=i.words,u=i.sigBytes,l=[],S=0;S<u;S++){var b=o[S>>>2]>>>24-S%4*8&255;l.push((b>>>4).toString(16)),l.push((b&15).toString(16));}return l.join("")},parse:function(i){for(var o=i.length,u=[],l=0;l<o;l+=2)u[l>>>3]|=parseInt(i.substr(l,2),16)<<24-l%8*4;return new y.init(u,o/2)}},N=f.Latin1={stringify:function(i){for(var o=i.words,u=i.sigBytes,l=[],S=0;S<u;S++){var b=o[S>>>2]>>>24-S%4*8&255;l.push(String.fromCharCode(b));}return l.join("")},parse:function(i){for(var o=i.length,u=[],l=0;l<o;l++)u[l>>>2]|=(i.charCodeAt(l)&255)<<24-l%4*8;return new y.init(u,o)}},C=f.Utf8={stringify:function(i){try{return decodeURIComponent(escape(N.stringify(i)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(i){return N.parse(unescape(encodeURIComponent(i)))}},m=d.BufferedBlockAlgorithm=g.extend({reset:function(){this._data=new y.init,this._nDataBytes=0;},_append:function(i){typeof i=="string"&&(i=C.parse(i)),this._data.concat(i),this._nDataBytes+=i.sigBytes;},_process:function(i){var o,u=this._data,l=u.words,S=u.sigBytes,b=this.blockSize,k=b*4,j=S/k;i?j=e.ceil(j):j=e.max((j|0)-this._minBufferSize,0);var E=j*b,M=e.min(E*4,S);if(E){for(var z=0;z<E;z+=b)this._doProcessBlock(l,z);o=l.splice(0,E),u.sigBytes-=M;}return new y.init(o,M)},clone:function(){var i=g.clone.call(this);return i._data=this._data.clone(),i},_minBufferSize:0});d.Hasher=m.extend({cfg:g.extend(),init:function(i){this.cfg=this.cfg.extend(i),this.reset();},reset:function(){m.reset.call(this),this._doReset();},update:function(i){return this._append(i),this._process(),this},finalize:function(i){i&&this._append(i);var o=this._doFinalize();return o},blockSize:512/32,_createHelper:function(i){return function(o,u){return new i.init(u).finalize(o)}},_createHmacHelper:function(i){return function(o,u){return new P.HMAC.init(i,u).finalize(o)}}});var P=p.algo={};return p})(Math);return a});});var Z=q((B,Y)=>{(function(a,e){typeof B=="object"?Y.exports=B=e(Q()):typeof define=="function"&&define.amd?define(["./core"],e):e(a.CryptoJS);})(B,function(a){return (function(){var e=a,r=e.lib,t=r.WordArray,n=r.Hasher,s=e.algo,p=[],d=s.SHA1=n.extend({_doReset:function(){this._hash=new t.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(g,y){for(var f=this._hash.words,J=f[0],N=f[1],C=f[2],m=f[3],x=f[4],P=0;P<80;P++){if(P<16)p[P]=g[y+P]|0;else {var i=p[P-3]^p[P-8]^p[P-14]^p[P-16];p[P]=i<<1|i>>>31;}var o=(J<<5|J>>>27)+x+p[P];P<20?o+=(N&C|~N&m)+1518500249:P<40?o+=(N^C^m)+1859775393:P<60?o+=(N&C|N&m|C&m)-1894007588:o+=(N^C^m)-899497514,x=m,m=C,C=N<<30|N>>>2,N=J,J=o;}f[0]=f[0]+J|0,f[1]=f[1]+N|0,f[2]=f[2]+C|0,f[3]=f[3]+m|0,f[4]=f[4]+x|0;},_doFinalize:function(){var g=this._data,y=g.words,f=this._nDataBytes*8,J=g.sigBytes*8;return y[J>>>5]|=128<<24-J%32,y[(J+64>>>9<<4)+14]=Math.floor(f/4294967296),y[(J+64>>>9<<4)+15]=f,g.sigBytes=y.length*4,this._process(),this._hash},clone:function(){var g=n.clone.call(this);return g._hash=this._hash.clone(),g}});e.SHA1=n._createHelper(d),e.HmacSHA1=n._createHmacHelper(d);})(),a.SHA1});});var H="___param___";var h;(n=>(n.log=(s,...p)=>console.log(`[Pixi\u2019VN Json] ${s}`,...p),n.warn=(s,...p)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...p),n.error=(s,...p)=>console.error(`[Pixi\u2019VN Json] ${s}`,...p),n.info=(s,...p)=>console.info(`[Pixi\u2019VN Json] ${s}`,...p)))(h||(h={}));var c=class c{static init(e){e.loadAssets&&(c._loadAssets=e.loadAssets),e.soundOperation&&(c._soundOperation=e.soundOperation),e.imageOperation&&(c._imageOperation=e.imageOperation),e.videoOperation&&(c._videoOperation=e.videoOperation),e.imageContainerOperation&&(c._imageContainerOperation=e.imageContainerOperation),e.textOperation&&(c._textOperation=e.textOperation),e.canvasElementOperation&&(c._canvasElementOperation=e.canvasElementOperation),e.setStorageValue&&(c._setStorageValue=e.setStorageValue),e.setInitialStorageValue&&(c._setInitialStorageValue=e.setInitialStorageValue),e.narrationOperation&&(c._narrationOperation=e.narrationOperation),e.effectOperation&&(c._effectOperation=e.effectOperation),e.animateOperation&&(c._animateOperation=e.animateOperation),e.getLogichValue&&(c._getLogichValue=e.getLogichValue),e.getConditionalStep&&(c._getConditionalStep=e.getConditionalStep);}static get loadAssets(){return c._loadAssets}static get soundOperation(){return c._soundOperation}static get imageOperation(){return c._imageOperation}static get videoOperation(){return c._videoOperation}static get imageContainerOperation(){return c._imageContainerOperation}static get textOperation(){return c._textOperation}static get canvasElementOperation(){return c._canvasElementOperation}static get setStorageValue(){return c._setStorageValue}static get setInitialStorageValue(){return c._setInitialStorageValue}static get narrationOperation(){return c._narrationOperation}static get effectOperation(){return c._effectOperation}static get animateOperation(){return c._animateOperation}static get getLogichValue(){return c._getLogichValue}static get getConditionalStep(){return c._getConditionalStep}};V(c,"_loadAssets",()=>{}),V(c,"_soundOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_imageOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_videoOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_imageContainerOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_textOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_canvasElementOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_setStorageValue",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_setInitialStorageValue",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_narrationOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_effectOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_animateOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_getLogichValue",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_getConditionalStep",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new pixiVn.PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")});var T=c;function G(a,e){if(e&&typeof e=="object"&&typeof a.functionName=="string"&&a.functionName in e){let r=e[a.functionName];if(typeof r=="function"){let t=a.args.map(n=>T.getLogichValue(n,e));return r(...t)}else h.warn(`getLogichValue function ${a.functionName} not found in props`);}}function F(a,e={}){let r="";return a.values.forEach(t=>{if(typeof t=="string")r+=t;else {let n=core.JsonUnifier.getLogichValue(t,e);r+=`${n}`;}}),r}async function $(a,e,r){let t=core.JsonUnifier.getLogichValue(a,e);if(t)switch(t.type){case "sound":core.JsonUnifier.soundOperation(t);break;case "assets":case "bundle":await core.JsonUnifier.loadAssets(t);break;case "image":await core.JsonUnifier.imageOperation(t);break;case "video":await core.JsonUnifier.videoOperation(t);break;case "imagecontainer":await core.JsonUnifier.imageContainerOperation(t);break;case "text":await core.JsonUnifier.textOperation(t);break;case "canvaselement":await core.JsonUnifier.canvasElementOperation(t);break;case "value":core.JsonUnifier.setStorageValue(t,e);break;case "operationtoconvert":if(r){let n=F(t,e),s=await r(n);s&&await $(s,e,r);}break;case "input":case "dialogue":core.JsonUnifier.narrationOperation(t);break;case "shake":await core.JsonUnifier.effectOperation(t);break;case "animate":case "animate-sequence":core.JsonUnifier.animateOperation(t);break;case "function":await G(t,e);break}}function X(a){let e=core.JsonUnifier.getLogichValue(a,{});e&&e.type==="value"&&e.storageOperationType==="set"&&(e.storageType==="storage"||e.storageType==="tempstorage")&&core.JsonUnifier.setInitialStorageValue(e);}var ee=pe(Z());var _=class extends narration.LabelAbstract{constructor(r,t,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let p of t){let d;if(typeof p=="function"?d=p():d=p,d=core.JsonUnifier.getConditionalStep(d),d.operations)try{let g=d.operations.map(y=>core.JsonUnifier.loadAssets(y));await Promise.all(g);}catch(g){h.error("The operation in the onLoadingLabel function of the label has an error:",g);}}};super(r,n);V(this,"_steps");V(this,"operationStringConvert");V(this,"skipEmptyDialogs",false);this._steps=t,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(r=>this.stepConverter(r))}get stepCount(){return this._steps.length}getStepById(r){if(r<0||r>=this._steps.length)return;let t=this._steps[r];return this.stepConverter(t)}getStepSha(r){if(r<0||r>=this.steps.length)return;let t=this._steps[r];return (0, ee.default)(t.toString().toLocaleLowerCase()).toString()}getDialogueText(r,t){let n="";if(Array.isArray(r)){let s=[];r.forEach(p=>{if(typeof p=="string")s.push(p);else if(p&&typeof p=="object"){let d=core.JsonUnifier.getLogichValue(p,t);d?(d&&!Array.isArray(d)&&typeof d=="object"&&(d=core.JsonUnifier.getLogichValue(d,t)||""),Array.isArray(d)?s=s.map(g=>`${g}`).concat(d):s.push(`${d}`)):s.push(`${p}`);}else s.push(`${p}`);}),n=s;}else {let s=core.JsonUnifier.getLogichValue(r,t);s&&!Array.isArray(s)&&typeof s=="object"&&(s=core.JsonUnifier.getLogichValue(s,t)),s&&Array.isArray(s)?n=s.map(p=>`${p}`):n=`${s}`;}return n}getDialogue(r,t){if(r==null)return;let n=core.JsonUnifier.getLogichValue(r,t);return n==null?`${n}`:typeof n=="object"&&"character"in n&&"text"in n?{character:n.character,text:translator.translator.t(this.getDialogueText(n.text,t))}:translator.translator.t(this.getDialogueText(n,t))}getChoices(r,t){return core.JsonUnifier.getLogichValue(r,t)?.map(p=>core.JsonUnifier.getLogichValue(p,t)).filter(p=>p!==void 0)}stepConverter(r){return async t=>{let n=typeof r=="function"?r():r;n=pixiVn.createExportableElement(n),n=core.JsonUnifier.getConditionalStep(n,t);let s=this.operationStringConvert?m=>this.operationStringConvert(m,n,t):void 0,{operations:p=[]}=n;for(let m of p)await $(m,t,s);let{labelToOpen:d=[]}=n,g=this.getChoices(n.choices,t),y=core.JsonUnifier.getLogichValue(n.glueEnabled,t),f=this.getDialogue(n.dialogue,t),J=[];Array.isArray(d)||(d=[d]),d.forEach(m=>{let x=core.JsonUnifier.getLogichValue(m,t);x&&J.push(x);});let N=core.JsonUnifier.getLogichValue(n.goNextStep,t),C=core.JsonUnifier.getLogichValue(n.end,t);if(g){let m=g.map(x=>{let P="";if(Array.isArray(x.text)){let o=[];x.text.forEach(u=>{if(typeof u=="string")o.push(translator.translator.t(u));else if(u&&typeof u=="object"){let l=core.JsonUnifier.getLogichValue(u,t);l&&!Array.isArray(l)&&typeof l=="object"&&(l=core.JsonUnifier.getLogichValue(l,t)||""),l&&(Array.isArray(l)?o=o.concat(translator.translator.t(l)):o.push(translator.translator.t(l)));}}),P=o;}else typeof x.text=="string"&&(P=translator.translator.t(x.text));return {label:x.label,text:P,props:x.props,type:x.type,oneTime:x.oneTime,onlyHaveNoChoice:x.onlyHaveNoChoice,autoSelect:x.autoSelect}});narration.narration.choices=m;}else narration.narration.choices=void 0;f!==void 0&&(narration.narration.dialogue=f,this.skipEmptyDialogs&&typeof f=="string"&&(f===""||RegExp(/^\s+$/).test(f))&&(N=true)),y?narration.narration.dialogGlue=true:y===false&&(narration.narration.dialogGlue=false);for(let m of J){let x=m.label;typeof x=="object"&&(x=core.JsonUnifier.getLogichValue(x,t)||"");let P=m.params?.map(i=>core.JsonUnifier.getLogichValue(i,t));t={...t,...m.props},m.type==="jump"?(narration.narration.openedLabels.length>0&&narration.narration.closeCurrentLabel(),storage.storage.setTempVariable(`${H}${narration.narration.openedLabels.length}`,P),await narration.narration.call(x,t)):(storage.storage.setTempVariable(`${H}${narration.narration.openedLabels.length}`,P),await narration.narration.call(x,t));}C==="game_end"?(narration.narration.closeAllLabels(),await narration.narration.continue(t,{runNow:true})):C==="label_end"&&narration.narration.closeCurrentLabel(),N&&await narration.narration.continue(t,{runNow:true});}}};async function ge(a,e={}){if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {h.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let t=a.map(n=>{if(typeof n=="string")try{return JSON.parse(n)}catch(s){return h.error("Error parsing imported Pixi'VN JSON",s),{}}return n}).map(async n=>{if(n.initialOperations)for(let s of n.initialOperations)X(s);if(n.labels){let s=n.labels;for(let p in s)try{let d=s[p],g=new _(p,d,void 0,e);narration.RegisteredLabels.add(g);}catch(d){h.error(`Error creating JSON label ${p}`,d);}}});await Promise.all(t);}exports.LabelJson=_;exports.importPixiVNJson=ge;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { P as PixiVNJsonLabelStep, a as PixiVNJsonValueSet, b as PixiVNJsonIfElse, c as PixiVNJsonOperation } from './PixiVNJsonLabelStep-DgN7qF7j.cjs';
|
|
2
|
+
import { LabelAbstract, LabelProps, StepLabelPropsType, StepLabelType } from '@drincs/pixi-vn/narration';
|
|
3
|
+
import '@drincs/pixi-vn';
|
|
4
|
+
import '@drincs/pixi-vn/motion';
|
|
5
|
+
import 'pixi.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Collection of labels to be used in the narrative.
|
|
9
|
+
*/
|
|
10
|
+
type PixiVNJsonLabels = {
|
|
11
|
+
[labelId: string]: PixiVNJsonLabelStep[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* PixiVNJson It can be defined as a programming language to write a narrative written in json.
|
|
16
|
+
*/
|
|
17
|
+
interface PixiVNJson {
|
|
18
|
+
/**
|
|
19
|
+
* The URI of the JSON Schema that describes and validates this document.
|
|
20
|
+
*
|
|
21
|
+
* You can point to a specific version of the schema, for example:
|
|
22
|
+
* - `"https://pixi-vn.web.app/schemas/1.13.0/schema.json"` — pin to a specific version
|
|
23
|
+
* - `"https://pixi-vn.web.app/schemas/latest/schema.json"` — always use the latest version
|
|
24
|
+
*
|
|
25
|
+
* Most editors (VS Code, WebStorm, etc.) use this field to provide
|
|
26
|
+
* auto-completion, hover documentation, and validation for the document.
|
|
27
|
+
*/
|
|
28
|
+
$schema?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The operations to be executed before the narrative starts.
|
|
31
|
+
* For the set storage: They will be set only if there are no variables with the same key already.
|
|
32
|
+
* For the det tempstorage: if there are variables with the same key already, they will be overwritten.
|
|
33
|
+
*/
|
|
34
|
+
initialOperations?: (PixiVNJsonValueSet | PixiVNJsonIfElse<PixiVNJsonValueSet>)[];
|
|
35
|
+
/**
|
|
36
|
+
* The labels to be used in the narrative. They will be added to the system
|
|
37
|
+
*/
|
|
38
|
+
labels?: PixiVNJsonLabels;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type LabelJsonOptions = {
|
|
42
|
+
/**
|
|
43
|
+
* Function that converts a string to a {@link PixiVNJsonOperation}.
|
|
44
|
+
* If is a special operation you can return undefined and can run the operation.
|
|
45
|
+
*/
|
|
46
|
+
operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType | object) => Promise<PixiVNJsonOperation | undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* If true and a dialog is empty or has only spaces, {@link PixiVNJsonLabelStep.goNextStep} will be set to true.
|
|
49
|
+
*/
|
|
50
|
+
skipEmptyDialogs?: boolean;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* A label whose steps are defined by a plain JSON structure ({@link PixiVNJsonLabelStep}[]).
|
|
54
|
+
*
|
|
55
|
+
* `LabelJson` bridges pixi-vn's label system and the JSON script format: each step is
|
|
56
|
+
* lazily converted to a {@link StepLabelType} closure that resolves dialogues, choices,
|
|
57
|
+
* operations, and conditional overrides at runtime via {@link JsonUnifier}.
|
|
58
|
+
*
|
|
59
|
+
* @template T - The type of the props object passed between steps.
|
|
60
|
+
*/
|
|
61
|
+
declare class LabelJson<T extends {} = object> extends LabelAbstract<LabelJson<T>, T> {
|
|
62
|
+
/**
|
|
63
|
+
* @param id is the id of the label
|
|
64
|
+
* @param steps is the list of steps that the label will perform
|
|
65
|
+
* @param props is the properties of the label
|
|
66
|
+
*/
|
|
67
|
+
constructor(id: string, steps: (PixiVNJsonLabelStep | (() => PixiVNJsonLabelStep))[], props?: LabelProps<LabelJson<T>>, options?: LabelJsonOptions);
|
|
68
|
+
private _steps;
|
|
69
|
+
get steps(): StepLabelType<T>[];
|
|
70
|
+
get stepCount(): number;
|
|
71
|
+
getStepById(stepId: number): StepLabelType<T> | undefined;
|
|
72
|
+
private operationStringConvert?;
|
|
73
|
+
private skipEmptyDialogs;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the SHA-1 hash of the raw step at the given index.
|
|
76
|
+
* Can be used to detect step changes across label reloads.
|
|
77
|
+
*
|
|
78
|
+
* @param index - Zero-based index of the step.
|
|
79
|
+
* @returns The hex SHA-1 string, or `undefined` if the index is out of range.
|
|
80
|
+
*/
|
|
81
|
+
getStepSha(index: number): string | undefined;
|
|
82
|
+
private getDialogueText;
|
|
83
|
+
private getDialogue;
|
|
84
|
+
private getChoices;
|
|
85
|
+
private stepConverter;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Import a Pixi'VN JSON to the system.
|
|
90
|
+
* This feature was created to give other developers the ability to create tools that can generate Pixi'VN labels or that generate Pixi'VN after extracting information from a programming language designed for writing narratives.
|
|
91
|
+
* @param values The Pixi'VN JSON to be imported
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
declare function importPixiVNJson(values: PixiVNJson | string | (PixiVNJson | string)[], options?: LabelJsonOptions): Promise<void>;
|
|
95
|
+
|
|
96
|
+
export { LabelJson, importPixiVNJson };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { P as PixiVNJsonLabelStep, a as PixiVNJsonValueSet, b as PixiVNJsonIfElse, c as PixiVNJsonOperation } from './PixiVNJsonLabelStep-DgN7qF7j.js';
|
|
2
|
+
import { LabelAbstract, LabelProps, StepLabelPropsType, StepLabelType } from '@drincs/pixi-vn/narration';
|
|
3
|
+
import '@drincs/pixi-vn';
|
|
4
|
+
import '@drincs/pixi-vn/motion';
|
|
5
|
+
import 'pixi.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Collection of labels to be used in the narrative.
|
|
9
|
+
*/
|
|
10
|
+
type PixiVNJsonLabels = {
|
|
11
|
+
[labelId: string]: PixiVNJsonLabelStep[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* PixiVNJson It can be defined as a programming language to write a narrative written in json.
|
|
16
|
+
*/
|
|
17
|
+
interface PixiVNJson {
|
|
18
|
+
/**
|
|
19
|
+
* The URI of the JSON Schema that describes and validates this document.
|
|
20
|
+
*
|
|
21
|
+
* You can point to a specific version of the schema, for example:
|
|
22
|
+
* - `"https://pixi-vn.web.app/schemas/1.13.0/schema.json"` — pin to a specific version
|
|
23
|
+
* - `"https://pixi-vn.web.app/schemas/latest/schema.json"` — always use the latest version
|
|
24
|
+
*
|
|
25
|
+
* Most editors (VS Code, WebStorm, etc.) use this field to provide
|
|
26
|
+
* auto-completion, hover documentation, and validation for the document.
|
|
27
|
+
*/
|
|
28
|
+
$schema?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The operations to be executed before the narrative starts.
|
|
31
|
+
* For the set storage: They will be set only if there are no variables with the same key already.
|
|
32
|
+
* For the det tempstorage: if there are variables with the same key already, they will be overwritten.
|
|
33
|
+
*/
|
|
34
|
+
initialOperations?: (PixiVNJsonValueSet | PixiVNJsonIfElse<PixiVNJsonValueSet>)[];
|
|
35
|
+
/**
|
|
36
|
+
* The labels to be used in the narrative. They will be added to the system
|
|
37
|
+
*/
|
|
38
|
+
labels?: PixiVNJsonLabels;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type LabelJsonOptions = {
|
|
42
|
+
/**
|
|
43
|
+
* Function that converts a string to a {@link PixiVNJsonOperation}.
|
|
44
|
+
* If is a special operation you can return undefined and can run the operation.
|
|
45
|
+
*/
|
|
46
|
+
operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType | object) => Promise<PixiVNJsonOperation | undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* If true and a dialog is empty or has only spaces, {@link PixiVNJsonLabelStep.goNextStep} will be set to true.
|
|
49
|
+
*/
|
|
50
|
+
skipEmptyDialogs?: boolean;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* A label whose steps are defined by a plain JSON structure ({@link PixiVNJsonLabelStep}[]).
|
|
54
|
+
*
|
|
55
|
+
* `LabelJson` bridges pixi-vn's label system and the JSON script format: each step is
|
|
56
|
+
* lazily converted to a {@link StepLabelType} closure that resolves dialogues, choices,
|
|
57
|
+
* operations, and conditional overrides at runtime via {@link JsonUnifier}.
|
|
58
|
+
*
|
|
59
|
+
* @template T - The type of the props object passed between steps.
|
|
60
|
+
*/
|
|
61
|
+
declare class LabelJson<T extends {} = object> extends LabelAbstract<LabelJson<T>, T> {
|
|
62
|
+
/**
|
|
63
|
+
* @param id is the id of the label
|
|
64
|
+
* @param steps is the list of steps that the label will perform
|
|
65
|
+
* @param props is the properties of the label
|
|
66
|
+
*/
|
|
67
|
+
constructor(id: string, steps: (PixiVNJsonLabelStep | (() => PixiVNJsonLabelStep))[], props?: LabelProps<LabelJson<T>>, options?: LabelJsonOptions);
|
|
68
|
+
private _steps;
|
|
69
|
+
get steps(): StepLabelType<T>[];
|
|
70
|
+
get stepCount(): number;
|
|
71
|
+
getStepById(stepId: number): StepLabelType<T> | undefined;
|
|
72
|
+
private operationStringConvert?;
|
|
73
|
+
private skipEmptyDialogs;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the SHA-1 hash of the raw step at the given index.
|
|
76
|
+
* Can be used to detect step changes across label reloads.
|
|
77
|
+
*
|
|
78
|
+
* @param index - Zero-based index of the step.
|
|
79
|
+
* @returns The hex SHA-1 string, or `undefined` if the index is out of range.
|
|
80
|
+
*/
|
|
81
|
+
getStepSha(index: number): string | undefined;
|
|
82
|
+
private getDialogueText;
|
|
83
|
+
private getDialogue;
|
|
84
|
+
private getChoices;
|
|
85
|
+
private stepConverter;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Import a Pixi'VN JSON to the system.
|
|
90
|
+
* This feature was created to give other developers the ability to create tools that can generate Pixi'VN labels or that generate Pixi'VN after extracting information from a programming language designed for writing narratives.
|
|
91
|
+
* @param values The Pixi'VN JSON to be imported
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
declare function importPixiVNJson(values: PixiVNJson | string | (PixiVNJson | string)[], options?: LabelJsonOptions): Promise<void>;
|
|
95
|
+
|
|
96
|
+
export { LabelJson, importPixiVNJson };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {PixiError,createExportableElement}from'@drincs/pixi-vn';import {JsonUnifier}from'@drincs/pixi-vn-json/core';import {translator}from'@drincs/pixi-vn-json/translator';import {LabelAbstract,narration,RegisteredLabels}from'@drincs/pixi-vn/narration';import {storage}from'@drincs/pixi-vn/storage';var te=Object.create;var R=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var ae=(a,e,r)=>e in a?R(a,e,{enumerable:true,configurable:true,writable:true,value:r}):a[e]=r;var D=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var q=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports);var se=(a,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ne(e))!re.call(a,n)&&n!==r&&R(a,n,{get:()=>e[n],enumerable:!(t=ie(e,n))||t.enumerable});return a};var pe=(a,e,r)=>(r=a!=null?te(oe(a)):{},se(R(r,"default",{value:a,enumerable:true}),a));var V=(a,e,r)=>ae(a,typeof e!="symbol"?e+"":e,r);var Q=q((I,K)=>{(function(a,e){typeof I=="object"?K.exports=I=e():typeof define=="function"&&define.amd?define([],e):a.CryptoJS=e();})(I,function(){var a=a||(function(e,r){var t;if(typeof window<"u"&&window.crypto&&(t=window.crypto),typeof self<"u"&&self.crypto&&(t=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(t=globalThis.crypto),!t&&typeof window<"u"&&window.msCrypto&&(t=window.msCrypto),!t&&typeof global<"u"&&global.crypto&&(t=global.crypto),!t&&typeof D=="function")try{t=D("crypto");}catch{}var n=function(){if(t){if(typeof t.getRandomValues=="function")try{return t.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof t.randomBytes=="function")try{return t.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function i(){}return function(o){var u;return i.prototype=o,u=new i,i.prototype=null,u}})(),p={},d=p.lib={},g=d.Base=(function(){return {extend:function(i){var o=s(this);return i&&o.mixIn(i),(!o.hasOwnProperty("init")||this.init===o.init)&&(o.init=function(){o.$super.init.apply(this,arguments);}),o.init.prototype=o,o.$super=this,o},create:function(){var i=this.extend();return i.init.apply(i,arguments),i},init:function(){},mixIn:function(i){for(var o in i)i.hasOwnProperty(o)&&(this[o]=i[o]);i.hasOwnProperty("toString")&&(this.toString=i.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),y=d.WordArray=g.extend({init:function(i,o){i=this.words=i||[],o!=r?this.sigBytes=o:this.sigBytes=i.length*4;},toString:function(i){return (i||J).stringify(this)},concat:function(i){var o=this.words,u=i.words,l=this.sigBytes,S=i.sigBytes;if(this.clamp(),l%4)for(var b=0;b<S;b++){var k=u[b>>>2]>>>24-b%4*8&255;o[l+b>>>2]|=k<<24-(l+b)%4*8;}else for(var j=0;j<S;j+=4)o[l+j>>>2]=u[j>>>2];return this.sigBytes+=S,this},clamp:function(){var i=this.words,o=this.sigBytes;i[o>>>2]&=4294967295<<32-o%4*8,i.length=e.ceil(o/4);},clone:function(){var i=g.clone.call(this);return i.words=this.words.slice(0),i},random:function(i){for(var o=[],u=0;u<i;u+=4)o.push(n());return new y.init(o,i)}}),f=p.enc={},J=f.Hex={stringify:function(i){for(var o=i.words,u=i.sigBytes,l=[],S=0;S<u;S++){var b=o[S>>>2]>>>24-S%4*8&255;l.push((b>>>4).toString(16)),l.push((b&15).toString(16));}return l.join("")},parse:function(i){for(var o=i.length,u=[],l=0;l<o;l+=2)u[l>>>3]|=parseInt(i.substr(l,2),16)<<24-l%8*4;return new y.init(u,o/2)}},N=f.Latin1={stringify:function(i){for(var o=i.words,u=i.sigBytes,l=[],S=0;S<u;S++){var b=o[S>>>2]>>>24-S%4*8&255;l.push(String.fromCharCode(b));}return l.join("")},parse:function(i){for(var o=i.length,u=[],l=0;l<o;l++)u[l>>>2]|=(i.charCodeAt(l)&255)<<24-l%4*8;return new y.init(u,o)}},C=f.Utf8={stringify:function(i){try{return decodeURIComponent(escape(N.stringify(i)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(i){return N.parse(unescape(encodeURIComponent(i)))}},m=d.BufferedBlockAlgorithm=g.extend({reset:function(){this._data=new y.init,this._nDataBytes=0;},_append:function(i){typeof i=="string"&&(i=C.parse(i)),this._data.concat(i),this._nDataBytes+=i.sigBytes;},_process:function(i){var o,u=this._data,l=u.words,S=u.sigBytes,b=this.blockSize,k=b*4,j=S/k;i?j=e.ceil(j):j=e.max((j|0)-this._minBufferSize,0);var E=j*b,M=e.min(E*4,S);if(E){for(var z=0;z<E;z+=b)this._doProcessBlock(l,z);o=l.splice(0,E),u.sigBytes-=M;}return new y.init(o,M)},clone:function(){var i=g.clone.call(this);return i._data=this._data.clone(),i},_minBufferSize:0});d.Hasher=m.extend({cfg:g.extend(),init:function(i){this.cfg=this.cfg.extend(i),this.reset();},reset:function(){m.reset.call(this),this._doReset();},update:function(i){return this._append(i),this._process(),this},finalize:function(i){i&&this._append(i);var o=this._doFinalize();return o},blockSize:512/32,_createHelper:function(i){return function(o,u){return new i.init(u).finalize(o)}},_createHmacHelper:function(i){return function(o,u){return new P.HMAC.init(i,u).finalize(o)}}});var P=p.algo={};return p})(Math);return a});});var Z=q((B,Y)=>{(function(a,e){typeof B=="object"?Y.exports=B=e(Q()):typeof define=="function"&&define.amd?define(["./core"],e):e(a.CryptoJS);})(B,function(a){return (function(){var e=a,r=e.lib,t=r.WordArray,n=r.Hasher,s=e.algo,p=[],d=s.SHA1=n.extend({_doReset:function(){this._hash=new t.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(g,y){for(var f=this._hash.words,J=f[0],N=f[1],C=f[2],m=f[3],x=f[4],P=0;P<80;P++){if(P<16)p[P]=g[y+P]|0;else {var i=p[P-3]^p[P-8]^p[P-14]^p[P-16];p[P]=i<<1|i>>>31;}var o=(J<<5|J>>>27)+x+p[P];P<20?o+=(N&C|~N&m)+1518500249:P<40?o+=(N^C^m)+1859775393:P<60?o+=(N&C|N&m|C&m)-1894007588:o+=(N^C^m)-899497514,x=m,m=C,C=N<<30|N>>>2,N=J,J=o;}f[0]=f[0]+J|0,f[1]=f[1]+N|0,f[2]=f[2]+C|0,f[3]=f[3]+m|0,f[4]=f[4]+x|0;},_doFinalize:function(){var g=this._data,y=g.words,f=this._nDataBytes*8,J=g.sigBytes*8;return y[J>>>5]|=128<<24-J%32,y[(J+64>>>9<<4)+14]=Math.floor(f/4294967296),y[(J+64>>>9<<4)+15]=f,g.sigBytes=y.length*4,this._process(),this._hash},clone:function(){var g=n.clone.call(this);return g._hash=this._hash.clone(),g}});e.SHA1=n._createHelper(d),e.HmacSHA1=n._createHmacHelper(d);})(),a.SHA1});});var H="___param___";var h;(n=>(n.log=(s,...p)=>console.log(`[Pixi\u2019VN Json] ${s}`,...p),n.warn=(s,...p)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...p),n.error=(s,...p)=>console.error(`[Pixi\u2019VN Json] ${s}`,...p),n.info=(s,...p)=>console.info(`[Pixi\u2019VN Json] ${s}`,...p)))(h||(h={}));var c=class c{static init(e){e.loadAssets&&(c._loadAssets=e.loadAssets),e.soundOperation&&(c._soundOperation=e.soundOperation),e.imageOperation&&(c._imageOperation=e.imageOperation),e.videoOperation&&(c._videoOperation=e.videoOperation),e.imageContainerOperation&&(c._imageContainerOperation=e.imageContainerOperation),e.textOperation&&(c._textOperation=e.textOperation),e.canvasElementOperation&&(c._canvasElementOperation=e.canvasElementOperation),e.setStorageValue&&(c._setStorageValue=e.setStorageValue),e.setInitialStorageValue&&(c._setInitialStorageValue=e.setInitialStorageValue),e.narrationOperation&&(c._narrationOperation=e.narrationOperation),e.effectOperation&&(c._effectOperation=e.effectOperation),e.animateOperation&&(c._animateOperation=e.animateOperation),e.getLogichValue&&(c._getLogichValue=e.getLogichValue),e.getConditionalStep&&(c._getConditionalStep=e.getConditionalStep);}static get loadAssets(){return c._loadAssets}static get soundOperation(){return c._soundOperation}static get imageOperation(){return c._imageOperation}static get videoOperation(){return c._videoOperation}static get imageContainerOperation(){return c._imageContainerOperation}static get textOperation(){return c._textOperation}static get canvasElementOperation(){return c._canvasElementOperation}static get setStorageValue(){return c._setStorageValue}static get setInitialStorageValue(){return c._setInitialStorageValue}static get narrationOperation(){return c._narrationOperation}static get effectOperation(){return c._effectOperation}static get animateOperation(){return c._animateOperation}static get getLogichValue(){return c._getLogichValue}static get getConditionalStep(){return c._getConditionalStep}};V(c,"_loadAssets",()=>{}),V(c,"_soundOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_imageOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_videoOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_imageContainerOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_textOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_canvasElementOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_setStorageValue",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_setInitialStorageValue",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_narrationOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_effectOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_animateOperation",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_getLogichValue",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")}),V(c,"_getConditionalStep",()=>{throw h.error("An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue."),new PixiError("invalid_usage","An error occurred! pixi-vn-json was not initialized. Please contact the Pixi'VN team to report the issue.")});var T=c;function G(a,e){if(e&&typeof e=="object"&&typeof a.functionName=="string"&&a.functionName in e){let r=e[a.functionName];if(typeof r=="function"){let t=a.args.map(n=>T.getLogichValue(n,e));return r(...t)}else h.warn(`getLogichValue function ${a.functionName} not found in props`);}}function F(a,e={}){let r="";return a.values.forEach(t=>{if(typeof t=="string")r+=t;else {let n=JsonUnifier.getLogichValue(t,e);r+=`${n}`;}}),r}async function $(a,e,r){let t=JsonUnifier.getLogichValue(a,e);if(t)switch(t.type){case "sound":JsonUnifier.soundOperation(t);break;case "assets":case "bundle":await JsonUnifier.loadAssets(t);break;case "image":await JsonUnifier.imageOperation(t);break;case "video":await JsonUnifier.videoOperation(t);break;case "imagecontainer":await JsonUnifier.imageContainerOperation(t);break;case "text":await JsonUnifier.textOperation(t);break;case "canvaselement":await JsonUnifier.canvasElementOperation(t);break;case "value":JsonUnifier.setStorageValue(t,e);break;case "operationtoconvert":if(r){let n=F(t,e),s=await r(n);s&&await $(s,e,r);}break;case "input":case "dialogue":JsonUnifier.narrationOperation(t);break;case "shake":await JsonUnifier.effectOperation(t);break;case "animate":case "animate-sequence":JsonUnifier.animateOperation(t);break;case "function":await G(t,e);break}}function X(a){let e=JsonUnifier.getLogichValue(a,{});e&&e.type==="value"&&e.storageOperationType==="set"&&(e.storageType==="storage"||e.storageType==="tempstorage")&&JsonUnifier.setInitialStorageValue(e);}var ee=pe(Z());var _=class extends LabelAbstract{constructor(r,t,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let p of t){let d;if(typeof p=="function"?d=p():d=p,d=JsonUnifier.getConditionalStep(d),d.operations)try{let g=d.operations.map(y=>JsonUnifier.loadAssets(y));await Promise.all(g);}catch(g){h.error("The operation in the onLoadingLabel function of the label has an error:",g);}}};super(r,n);V(this,"_steps");V(this,"operationStringConvert");V(this,"skipEmptyDialogs",false);this._steps=t,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(r=>this.stepConverter(r))}get stepCount(){return this._steps.length}getStepById(r){if(r<0||r>=this._steps.length)return;let t=this._steps[r];return this.stepConverter(t)}getStepSha(r){if(r<0||r>=this.steps.length)return;let t=this._steps[r];return (0, ee.default)(t.toString().toLocaleLowerCase()).toString()}getDialogueText(r,t){let n="";if(Array.isArray(r)){let s=[];r.forEach(p=>{if(typeof p=="string")s.push(p);else if(p&&typeof p=="object"){let d=JsonUnifier.getLogichValue(p,t);d?(d&&!Array.isArray(d)&&typeof d=="object"&&(d=JsonUnifier.getLogichValue(d,t)||""),Array.isArray(d)?s=s.map(g=>`${g}`).concat(d):s.push(`${d}`)):s.push(`${p}`);}else s.push(`${p}`);}),n=s;}else {let s=JsonUnifier.getLogichValue(r,t);s&&!Array.isArray(s)&&typeof s=="object"&&(s=JsonUnifier.getLogichValue(s,t)),s&&Array.isArray(s)?n=s.map(p=>`${p}`):n=`${s}`;}return n}getDialogue(r,t){if(r==null)return;let n=JsonUnifier.getLogichValue(r,t);return n==null?`${n}`:typeof n=="object"&&"character"in n&&"text"in n?{character:n.character,text:translator.t(this.getDialogueText(n.text,t))}:translator.t(this.getDialogueText(n,t))}getChoices(r,t){return JsonUnifier.getLogichValue(r,t)?.map(p=>JsonUnifier.getLogichValue(p,t)).filter(p=>p!==void 0)}stepConverter(r){return async t=>{let n=typeof r=="function"?r():r;n=createExportableElement(n),n=JsonUnifier.getConditionalStep(n,t);let s=this.operationStringConvert?m=>this.operationStringConvert(m,n,t):void 0,{operations:p=[]}=n;for(let m of p)await $(m,t,s);let{labelToOpen:d=[]}=n,g=this.getChoices(n.choices,t),y=JsonUnifier.getLogichValue(n.glueEnabled,t),f=this.getDialogue(n.dialogue,t),J=[];Array.isArray(d)||(d=[d]),d.forEach(m=>{let x=JsonUnifier.getLogichValue(m,t);x&&J.push(x);});let N=JsonUnifier.getLogichValue(n.goNextStep,t),C=JsonUnifier.getLogichValue(n.end,t);if(g){let m=g.map(x=>{let P="";if(Array.isArray(x.text)){let o=[];x.text.forEach(u=>{if(typeof u=="string")o.push(translator.t(u));else if(u&&typeof u=="object"){let l=JsonUnifier.getLogichValue(u,t);l&&!Array.isArray(l)&&typeof l=="object"&&(l=JsonUnifier.getLogichValue(l,t)||""),l&&(Array.isArray(l)?o=o.concat(translator.t(l)):o.push(translator.t(l)));}}),P=o;}else typeof x.text=="string"&&(P=translator.t(x.text));return {label:x.label,text:P,props:x.props,type:x.type,oneTime:x.oneTime,onlyHaveNoChoice:x.onlyHaveNoChoice,autoSelect:x.autoSelect}});narration.choices=m;}else narration.choices=void 0;f!==void 0&&(narration.dialogue=f,this.skipEmptyDialogs&&typeof f=="string"&&(f===""||RegExp(/^\s+$/).test(f))&&(N=true)),y?narration.dialogGlue=true:y===false&&(narration.dialogGlue=false);for(let m of J){let x=m.label;typeof x=="object"&&(x=JsonUnifier.getLogichValue(x,t)||"");let P=m.params?.map(i=>JsonUnifier.getLogichValue(i,t));t={...t,...m.props},m.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${H}${narration.openedLabels.length}`,P),await narration.call(x,t)):(storage.setTempVariable(`${H}${narration.openedLabels.length}`,P),await narration.call(x,t));}C==="game_end"?(narration.closeAllLabels(),await narration.continue(t,{runNow:true})):C==="label_end"&&narration.closeCurrentLabel(),N&&await narration.continue(t,{runNow:true});}}};async function ge(a,e={}){if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {h.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let t=a.map(n=>{if(typeof n=="string")try{return JSON.parse(n)}catch(s){return h.error("Error parsing imported Pixi'VN JSON",s),{}}return n}).map(async n=>{if(n.initialOperations)for(let s of n.initialOperations)X(s);if(n.labels){let s=n.labels;for(let p in s)try{let d=s[p],g=new _(p,d,void 0,e);RegisteredLabels.add(g);}catch(d){h.error(`Error creating JSON label ${p}`,d);}}});await Promise.all(t);}export{_ as LabelJson,ge as importPixiVNJson};
|
package/dist/schema.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { w as PixiVNJsonLabelStep, n as PixiVNJsonValueSet, a as PixiVNJsonIfElse } from './PixiVNJsonLabelStep-dVwPLFMT.cjs';
|
|
2
|
+
export { x as PixiVNJsonAnimateBase, y as PixiVNJsonAnimateSequence, t as PixiVNJsonArithmeticOperations, z as PixiVNJsonArithmeticOperationsArithmetic, A as PixiVNJsonArithmeticOperationsArithmeticSingle, B as PixiVNJsonCanvas, r as PixiVNJsonCanvasAnimate, C as PixiVNJsonCanvasEdit, q as PixiVNJsonCanvasEffect, i as PixiVNJsonCanvasImageContainerShow, d as PixiVNJsonCanvasImageVideoShow, f as PixiVNJsonCanvasRemove, D as PixiVNJsonCanvasShow, k as PixiVNJsonCanvasTextShow, E as PixiVNJsonChoice, F as PixiVNJsonChoiceGet, G as PixiVNJsonChoices, H as PixiVNJsonComparation, I as PixiVNJsonComparationOperatorsType, J as PixiVNJsonConditionalOperation, K as PixiVNJsonConditionalResultToCombine, v as PixiVNJsonConditionalStatements, u as PixiVNJsonConditions, L as PixiVNJsonDialog, M as PixiVNJsonDialogText, N as PixiVNJsonFunction, j as PixiVNJsonImageContainerEdit, e as PixiVNJsonImageEdit, O as PixiVNJsonLabelGet, Q as PixiVNJsonLabelToOpen, R as PixiVNJsonLogicGet, S as PixiVNJsonMediaTransiotions, p as PixiVNJsonNarration, o as PixiVNJsonOnlyStorageSet, P as PixiVNJsonOperation, b as PixiVNJsonOperationString, T as PixiVNJsonParamGet, c as PixiVNJsonSound, U as PixiVNJsonStepSwitch, V as PixiVNJsonStepSwitchElementType, W as PixiVNJsonStepSwitchElementsType, X as PixiVNJsonStorageGet, l as PixiVNJsonTextEdit, Y as PixiVNJsonUnionCondition, m as PixiVNJsonUnknownEdit, s as PixiVNJsonValueGet, g as PixiVNJsonVideoEdit, h as PixiVNJsonVideoPauseResume } from './PixiVNJsonLabelStep-dVwPLFMT.cjs';
|
|
3
|
+
import '@drincs/pixi-vn';
|
|
4
|
+
import '@drincs/pixi-vn/motion';
|
|
5
|
+
import 'pixi.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Collection of labels to be used in the narrative.
|
|
9
|
+
*/
|
|
10
|
+
type PixiVNJsonLabels = {
|
|
11
|
+
[labelId: string]: PixiVNJsonLabelStep[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* PixiVNJson It can be defined as a programming language to write a narrative written in json.
|
|
16
|
+
*/
|
|
17
|
+
interface PixiVNJson {
|
|
18
|
+
/**
|
|
19
|
+
* The URI of the JSON Schema that describes and validates this document.
|
|
20
|
+
*
|
|
21
|
+
* You can point to a specific version of the schema, for example:
|
|
22
|
+
* - `"https://pixi-vn.web.app/schemas/1.13.0/schema.json"` — pin to a specific version
|
|
23
|
+
* - `"https://pixi-vn.web.app/schemas/latest/schema.json"` — always use the latest version
|
|
24
|
+
*
|
|
25
|
+
* Most editors (VS Code, WebStorm, etc.) use this field to provide
|
|
26
|
+
* auto-completion, hover documentation, and validation for the document.
|
|
27
|
+
*/
|
|
28
|
+
$schema?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The operations to be executed before the narrative starts.
|
|
31
|
+
* For the set storage: They will be set only if there are no variables with the same key already.
|
|
32
|
+
* For the det tempstorage: if there are variables with the same key already, they will be overwritten.
|
|
33
|
+
*/
|
|
34
|
+
initialOperations?: (PixiVNJsonValueSet | PixiVNJsonIfElse<PixiVNJsonValueSet>)[];
|
|
35
|
+
/**
|
|
36
|
+
* The labels to be used in the narrative. They will be added to the system
|
|
37
|
+
*/
|
|
38
|
+
labels?: PixiVNJsonLabels;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { type PixiVNJson, PixiVNJsonIfElse, PixiVNJsonLabelStep, type PixiVNJsonLabels, PixiVNJsonValueSet };
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { w as PixiVNJsonLabelStep, n as PixiVNJsonValueSet, a as PixiVNJsonIfElse } from './PixiVNJsonLabelStep-dVwPLFMT.js';
|
|
2
|
+
export { x as PixiVNJsonAnimateBase, y as PixiVNJsonAnimateSequence, t as PixiVNJsonArithmeticOperations, z as PixiVNJsonArithmeticOperationsArithmetic, A as PixiVNJsonArithmeticOperationsArithmeticSingle, B as PixiVNJsonCanvas, r as PixiVNJsonCanvasAnimate, C as PixiVNJsonCanvasEdit, q as PixiVNJsonCanvasEffect, i as PixiVNJsonCanvasImageContainerShow, d as PixiVNJsonCanvasImageVideoShow, f as PixiVNJsonCanvasRemove, D as PixiVNJsonCanvasShow, k as PixiVNJsonCanvasTextShow, E as PixiVNJsonChoice, F as PixiVNJsonChoiceGet, G as PixiVNJsonChoices, H as PixiVNJsonComparation, I as PixiVNJsonComparationOperatorsType, J as PixiVNJsonConditionalOperation, K as PixiVNJsonConditionalResultToCombine, v as PixiVNJsonConditionalStatements, u as PixiVNJsonConditions, L as PixiVNJsonDialog, M as PixiVNJsonDialogText, N as PixiVNJsonFunction, j as PixiVNJsonImageContainerEdit, e as PixiVNJsonImageEdit, O as PixiVNJsonLabelGet, Q as PixiVNJsonLabelToOpen, R as PixiVNJsonLogicGet, S as PixiVNJsonMediaTransiotions, p as PixiVNJsonNarration, o as PixiVNJsonOnlyStorageSet, P as PixiVNJsonOperation, b as PixiVNJsonOperationString, T as PixiVNJsonParamGet, c as PixiVNJsonSound, U as PixiVNJsonStepSwitch, V as PixiVNJsonStepSwitchElementType, W as PixiVNJsonStepSwitchElementsType, X as PixiVNJsonStorageGet, l as PixiVNJsonTextEdit, Y as PixiVNJsonUnionCondition, m as PixiVNJsonUnknownEdit, s as PixiVNJsonValueGet, g as PixiVNJsonVideoEdit, h as PixiVNJsonVideoPauseResume } from './PixiVNJsonLabelStep-dVwPLFMT.js';
|
|
3
|
+
import '@drincs/pixi-vn';
|
|
4
|
+
import '@drincs/pixi-vn/motion';
|
|
5
|
+
import 'pixi.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Collection of labels to be used in the narrative.
|
|
9
|
+
*/
|
|
10
|
+
type PixiVNJsonLabels = {
|
|
11
|
+
[labelId: string]: PixiVNJsonLabelStep[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* PixiVNJson It can be defined as a programming language to write a narrative written in json.
|
|
16
|
+
*/
|
|
17
|
+
interface PixiVNJson {
|
|
18
|
+
/**
|
|
19
|
+
* The URI of the JSON Schema that describes and validates this document.
|
|
20
|
+
*
|
|
21
|
+
* You can point to a specific version of the schema, for example:
|
|
22
|
+
* - `"https://pixi-vn.web.app/schemas/1.13.0/schema.json"` — pin to a specific version
|
|
23
|
+
* - `"https://pixi-vn.web.app/schemas/latest/schema.json"` — always use the latest version
|
|
24
|
+
*
|
|
25
|
+
* Most editors (VS Code, WebStorm, etc.) use this field to provide
|
|
26
|
+
* auto-completion, hover documentation, and validation for the document.
|
|
27
|
+
*/
|
|
28
|
+
$schema?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The operations to be executed before the narrative starts.
|
|
31
|
+
* For the set storage: They will be set only if there are no variables with the same key already.
|
|
32
|
+
* For the det tempstorage: if there are variables with the same key already, they will be overwritten.
|
|
33
|
+
*/
|
|
34
|
+
initialOperations?: (PixiVNJsonValueSet | PixiVNJsonIfElse<PixiVNJsonValueSet>)[];
|
|
35
|
+
/**
|
|
36
|
+
* The labels to be used in the narrative. They will be added to the system
|
|
37
|
+
*/
|
|
38
|
+
labels?: PixiVNJsonLabels;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { type PixiVNJson, PixiVNJsonIfElse, PixiVNJsonLabelStep, type PixiVNJsonLabels, PixiVNJsonValueSet };
|
package/dist/schema.mjs
ADDED
|
File without changes
|
package/dist/translator.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var core=require('@drincs/pixi-vn-json/core');var
|
|
1
|
+
'use strict';var core=require('@drincs/pixi-vn-json/core');var P=Object.defineProperty;var V=(c,e,i)=>e in c?P(c,e,{enumerable:true,configurable:true,writable:true,value:i}):c[e]=i;var m=(c,e,i)=>V(c,typeof e!="symbol"?e+"":e,i);function E(c,e={}){let i="";return c.values.forEach(n=>{if(typeof n=="string")i+=n;else {let s=core.JsonUnifier.getLogichValue(n,e);i+=`${s}`;}}),i}var t=class t{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,n){let s=n.defaultValue||"empty_string";typeof i=="string"&&(i=[i]),Array.isArray(i)&&i.forEach(l=>{e[l]===void 0&&(s==="empty_string"?e[l]="":s==="copy_key"&&(t._beforeToTranslate?e[l]=t._beforeToTranslate(l):e[l]=l));});}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(n=>{t.getConditionalsThenElse(n,i);});else if(e.elements.type==="ifelse"){let n=[];t.getConditionalsThenElse(e.elements,n),n.forEach(s=>{i.push(...s);});}else if(e.elements.type==="stepswitch"){let n=[];t.getConditionalsThenElse(e.elements,n),n.forEach(s=>{i.push(...s);});}else t.getConditionalsThenElse(e.elements,i);}else e.type==="resulttocombine"?(e.firstItem&&t.getConditionalsThenElse(e.firstItem,i),e.secondConditionalItem&&e.secondConditionalItem.forEach(n=>{t.getConditionalsThenElse(n,i);})):i.push(e);else e&&i.push(e);return i}static async generateJsonTranslation(e,i={},n={}){let{defaultValue:s="copy_key",operationStringConvert:l}=n,x=e.map(async r=>{if(r.choices){let o=[];Array.isArray(r.choices)?o=[r.choices]:o=t.getConditionalsThenElse(r.choices),o.forEach(f=>f.forEach(a=>{if("type"in a){let g=[];a.type==="ifelse"||a.type==="stepswitch"?t.getConditionalsThenElse(a,g):g=[a],g.map(p=>t.getConditionalsThenElse(p.text)).forEach(p=>{Array.isArray(p)&&p.forEach(y=>{Array.isArray(y)?y.forEach(T=>{typeof T=="string"?t.addKey(i,T,{defaultValue:s}):t.getConditionalsThenElse(T).forEach(d=>{Array.isArray(d)?d.forEach(u=>{typeof u=="string"&&t.addKey(i,u,{defaultValue:s});}):typeof d=="string"&&t.addKey(i,d,{defaultValue:s});});}):typeof y=="string"&&t.addKey(i,y,{defaultValue:s});});});}}));}if(r.dialogue){let o=[];Array.isArray(r.dialogue)?o=[r.dialogue]:o=t.getConditionalsThenElse(r.dialogue),o.forEach(f=>{if(typeof f=="string")t.addKey(i,f,{defaultValue:s});else if("text"in f){let a=t.getConditionalsThenElse(f.text);typeof a=="string"&&(a=[a]),a.forEach(g=>{typeof g=="string"?t.addKey(i,g,{defaultValue:s}):t.getConditionalsThenElse(g).forEach(p=>{typeof p=="string"?t.addKey(i,p,{defaultValue:s}):Array.isArray(p)&&p.forEach(y=>{typeof y=="string"?t.addKey(i,y,{defaultValue:s}):t.getConditionalsThenElse(y).forEach(T=>{typeof T=="string"&&t.addKey(i,T,{defaultValue:s});});});});});}});}if(r.operations)for(let o of r.operations){if(o.type==="operationtoconvert"&&l){let f=E(o),a=await l(f,r,{});if(!a)return;o=a;}o.type==="text"&&o.operationType==="show"&&t.addKey(i,o.text,{defaultValue:s});}r.conditionalStep&&t.getConditionalsThenElse(r.conditionalStep).forEach(f=>{Array.isArray(f)?t.generateJsonTranslation(f,i,n):t.generateJsonTranslation([f],i,n);});});return await Promise.all(x),i}};m(t,"_beforeToTranslate"),m(t,"_translate",e=>e),m(t,"_afterToTranslate");var h=t;var L=h;exports.translator=L;
|