@drincs/pixi-vn-json 1.12.1 → 1.13.1
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-C-9WKwTo.d.cts} +479 -77
- package/dist/{importer.d.ts → PixiVNJsonLabelStep-C-9WKwTo.d.ts} +479 -77
- package/dist/PixiVNJsonLabelStep-DQx6TBvZ.d.cts +999 -0
- package/dist/PixiVNJsonLabelStep-DQx6TBvZ.d.ts +999 -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 -541
- package/dist/core.d.ts +33 -541
- package/dist/core.mjs +1 -1
- package/dist/index.cjs +2 -3
- package/dist/index.d.cts +557 -21
- package/dist/index.d.ts +557 -21
- 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 +513 -13
- package/dist/translator.d.ts +513 -13
- package/dist/translator.mjs +1 -1
- package/package.json +33 -4
- package/dist/importer.cjs +0 -1
- package/dist/importer.mjs +0 -1
package/dist/translator.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {JsonUnifier}from'@drincs/pixi-vn-json/core';var
|
|
1
|
+
import {JsonUnifier}from'@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=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;export{L as translator};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drincs/pixi-vn-json",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.1",
|
|
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",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"dev": "tsup --watch",
|
|
14
14
|
"build": "tsup --config tsup.config.ts",
|
|
15
|
+
"generate-schema": "node scripts/generate-schema.mjs",
|
|
15
16
|
"lint": "biome lint",
|
|
16
17
|
"check": "biome check",
|
|
17
18
|
"format": "biome format --write",
|
|
@@ -42,6 +43,24 @@
|
|
|
42
43
|
"import": "./dist/translator.mjs",
|
|
43
44
|
"require": "./dist/translator.cjs",
|
|
44
45
|
"default": "./dist/translator.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./interpreter": {
|
|
48
|
+
"types": "./dist/interpreter.d.ts",
|
|
49
|
+
"import": "./dist/interpreter.mjs",
|
|
50
|
+
"require": "./dist/interpreter.cjs",
|
|
51
|
+
"default": "./dist/interpreter.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./actions": {
|
|
54
|
+
"types": "./dist/actions.d.ts",
|
|
55
|
+
"import": "./dist/actions.mjs",
|
|
56
|
+
"require": "./dist/actions.cjs",
|
|
57
|
+
"default": "./dist/actions.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./schema": {
|
|
60
|
+
"types": "./dist/schema.d.ts",
|
|
61
|
+
"import": "./dist/schema.mjs",
|
|
62
|
+
"require": "./dist/schema.cjs",
|
|
63
|
+
"default": "./dist/schema.mjs"
|
|
45
64
|
}
|
|
46
65
|
},
|
|
47
66
|
"typesVersions": {
|
|
@@ -54,6 +73,15 @@
|
|
|
54
73
|
],
|
|
55
74
|
"translator": [
|
|
56
75
|
"./dist/translator.d.ts"
|
|
76
|
+
],
|
|
77
|
+
"interpreter": [
|
|
78
|
+
"./dist/interpreter.d.ts"
|
|
79
|
+
],
|
|
80
|
+
"actions": [
|
|
81
|
+
"./dist/actions.d.ts"
|
|
82
|
+
],
|
|
83
|
+
"schema": [
|
|
84
|
+
"./dist/schema.d.ts"
|
|
57
85
|
]
|
|
58
86
|
}
|
|
59
87
|
},
|
|
@@ -69,16 +97,17 @@
|
|
|
69
97
|
"homepage": "hthttps://pixi-vn.web.app/other-topics/pixi-vn-json",
|
|
70
98
|
"funding": "https://github.com/DRincs-Productions/pixi-vn?sponsor=1",
|
|
71
99
|
"devDependencies": {
|
|
72
|
-
"@biomejs/biome": "^2.4.
|
|
100
|
+
"@biomejs/biome": "^2.4.14",
|
|
73
101
|
"@types/crypto-js": "^4.2.2",
|
|
74
102
|
"crypto-js": "^4.2.0",
|
|
75
|
-
"jsdom": "^29.1.
|
|
103
|
+
"jsdom": "^29.1.1",
|
|
76
104
|
"pixi.js": "^8.18.1",
|
|
105
|
+
"ts-json-schema-generator": "^2.9.0",
|
|
77
106
|
"ts-node": "^10.9.2",
|
|
78
107
|
"tsup": "^8.5.1",
|
|
79
108
|
"typedoc": "^0.28.19",
|
|
80
109
|
"typedoc-plugin-markdown": "^4.11.0",
|
|
81
|
-
"typescript": "^
|
|
110
|
+
"typescript": "^6.0.3",
|
|
82
111
|
"typescript-json-schema": "^0.67.1",
|
|
83
112
|
"vite-tsconfig-paths": "^6.1.1"
|
|
84
113
|
},
|
package/dist/importer.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var core=require('@drincs/pixi-vn-json/core'),narration=require('@drincs/pixi-vn/narration'),pixiVn=require('@drincs/pixi-vn'),translator=require('@drincs/pixi-vn-json/translator'),storage=require('@drincs/pixi-vn/storage');var K=Object.create;var D=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var te=(a,i,t)=>i in a?D(a,i,{enumerable:true,configurable:true,writable:true,value:t}):a[i]=t;var H=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(i,t)=>(typeof require<"u"?require:i)[t]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var R=(a,i)=>()=>(i||a((i={exports:{}}).exports,i),i.exports);var ie=(a,i,t,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of Y(i))!ee.call(a,n)&&n!==t&&D(a,n,{get:()=>i[n],enumerable:!(o=Q(i,n))||o.enumerable});return a};var ne=(a,i,t)=>(t=a!=null?K(Z(a)):{},ie(D(t,"default",{value:a,enumerable:true}),a));var T=(a,i,t)=>te(a,typeof i!="symbol"?i+"":i,t);var q=R((A,U)=>{(function(a,i){typeof A=="object"?U.exports=A=i():typeof define=="function"&&define.amd?define([],i):a.CryptoJS=i();})(A,function(){var a=a||(function(i,t){var o;if(typeof window<"u"&&window.crypto&&(o=window.crypto),typeof self<"u"&&self.crypto&&(o=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(o=globalThis.crypto),!o&&typeof window<"u"&&window.msCrypto&&(o=window.msCrypto),!o&&typeof global<"u"&&global.crypto&&(o=global.crypto),!o&&typeof H=="function")try{o=H("crypto");}catch{}var n=function(){if(o){if(typeof o.getRandomValues=="function")try{return o.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof o.randomBytes=="function")try{return o.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function e(){}return function(r){var p;return e.prototype=r,p=new e,e.prototype=null,p}})(),l={},u=l.lib={},g=u.Base=(function(){return {extend:function(e){var r=s(this);return e&&r.mixIn(e),(!r.hasOwnProperty("init")||this.init===r.init)&&(r.init=function(){r.$super.init.apply(this,arguments);}),r.init.prototype=r,r.$super=this,r},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var r in e)e.hasOwnProperty(r)&&(this[r]=e[r]);e.hasOwnProperty("toString")&&(this.toString=e.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),x=u.WordArray=g.extend({init:function(e,r){e=this.words=e||[],r!=t?this.sigBytes=r:this.sigBytes=e.length*4;},toString:function(e){return (e||V).stringify(this)},concat:function(e){var r=this.words,p=e.words,c=this.sigBytes,v=e.sigBytes;if(this.clamp(),c%4)for(var P=0;P<v;P++){var k=p[P>>>2]>>>24-P%4*8&255;r[c+P>>>2]|=k<<24-(c+P)%4*8;}else for(var L=0;L<v;L+=4)r[c+L>>>2]=p[L>>>2];return this.sigBytes+=v,this},clamp:function(){var e=this.words,r=this.sigBytes;e[r>>>2]&=4294967295<<32-r%4*8,e.length=i.ceil(r/4);},clone:function(){var e=g.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var r=[],p=0;p<e;p+=4)r.push(n());return new x.init(r,e)}}),f=l.enc={},V=f.Hex={stringify:function(e){for(var r=e.words,p=e.sigBytes,c=[],v=0;v<p;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push((P>>>4).toString(16)),c.push((P&15).toString(16));}return c.join("")},parse:function(e){for(var r=e.length,p=[],c=0;c<r;c+=2)p[c>>>3]|=parseInt(e.substr(c,2),16)<<24-c%8*4;return new x.init(p,r/2)}},b=f.Latin1={stringify:function(e){for(var r=e.words,p=e.sigBytes,c=[],v=0;v<p;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push(String.fromCharCode(P));}return c.join("")},parse:function(e){for(var r=e.length,p=[],c=0;c<r;c++)p[c>>>2]|=(e.charCodeAt(c)&255)<<24-c%4*8;return new x.init(p,r)}},N=f.Utf8={stringify:function(e){try{return decodeURIComponent(escape(b.stringify(e)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(e){return b.parse(unescape(encodeURIComponent(e)))}},h=u.BufferedBlockAlgorithm=g.extend({reset:function(){this._data=new x.init,this._nDataBytes=0;},_append:function(e){typeof e=="string"&&(e=N.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes;},_process:function(e){var r,p=this._data,c=p.words,v=p.sigBytes,P=this.blockSize,k=P*4,L=v/k;e?L=i.ceil(L):L=i.max((L|0)-this._minBufferSize,0);var C=L*P,j=i.min(C*4,v);if(C){for(var E=0;E<C;E+=P)this._doProcessBlock(c,E);r=c.splice(0,C),p.sigBytes-=j;}return new x.init(r,j)},clone:function(){var e=g.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});u.Hasher=h.extend({cfg:g.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset();},reset:function(){h.reset.call(this),this._doReset();},update:function(e){return this._append(e),this._process(),this},finalize:function(e){e&&this._append(e);var r=this._doFinalize();return r},blockSize:512/32,_createHelper:function(e){return function(r,p){return new e.init(p).finalize(r)}},_createHmacHelper:function(e){return function(r,p){return new y.HMAC.init(e,p).finalize(r)}}});var y=l.algo={};return l})(Math);return a});});var M=R((B,F)=>{(function(a,i){typeof B=="object"?F.exports=B=i(q()):typeof define=="function"&&define.amd?define(["./core"],i):i(a.CryptoJS);})(B,function(a){return (function(){var i=a,t=i.lib,o=t.WordArray,n=t.Hasher,s=i.algo,l=[],u=s.SHA1=n.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(g,x){for(var f=this._hash.words,V=f[0],b=f[1],N=f[2],h=f[3],d=f[4],y=0;y<80;y++){if(y<16)l[y]=g[x+y]|0;else {var e=l[y-3]^l[y-8]^l[y-14]^l[y-16];l[y]=e<<1|e>>>31;}var r=(V<<5|V>>>27)+d+l[y];y<20?r+=(b&N|~b&h)+1518500249:y<40?r+=(b^N^h)+1859775393:y<60?r+=(b&N|b&h|N&h)-1894007588:r+=(b^N^h)-899497514,d=h,h=N,N=b<<30|b>>>2,b=V,V=r;}f[0]=f[0]+V|0,f[1]=f[1]+b|0,f[2]=f[2]+N|0,f[3]=f[3]+h|0,f[4]=f[4]+d|0;},_doFinalize:function(){var g=this._data,x=g.words,f=this._nDataBytes*8,V=g.sigBytes*8;return x[V>>>5]|=128<<24-V%32,x[(V+64>>>9<<4)+14]=Math.floor(f/4294967296),x[(V+64>>>9<<4)+15]=f,g.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var g=n.clone.call(this);return g._hash=this._hash.clone(),g}});i.SHA1=n._createHelper(u),i.HmacSHA1=n._createHmacHelper(u);})(),a.SHA1});});function z(a){let i="";return a.values.forEach(t=>{if(typeof t=="string")i+=t;else {let o=core.JsonUnifier.getLogichValue(t);i+=`${o}`;}}),i}async function I(a,i){let t=core.JsonUnifier.getLogichValue(a);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);break;case "operationtoconvert":if(i){let o=z(t),n=await i(o);n&&await I(n,i);}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}}function W(a){let i=core.JsonUnifier.getLogichValue(a);i&&i.type==="value"&&i.storageOperationType==="set"&&(i.storageType==="storage"||i.storageType==="tempstorage")&&core.JsonUnifier.setInitialStorageValue(i);}var w;(n=>(n.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),n.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),n.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),n.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(w||(w={}));async function ae(a,i={}){if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {w.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let t=a.map(async s=>{if(typeof s=="string")try{s=JSON.parse(s);}catch(l){w.error("Error parsing imported Pixi'VN JSON",l),s={};}return s}),n=(await Promise.all(t)).map(async s=>{let l=[];if(s.initialOperations)for(let u of s.initialOperations)W(u);if(s.labels){let u=s.labels;for(let g in u)try{let x=u[g],f=new _(g,x,void 0,i);narration.RegisteredLabels.add(f);}catch(x){w.error(`Error creating JSON label ${g}`,x);}}return Promise.all(l)});await Promise.all(n);}var X=ne(M());var $="___param___";var _=class extends narration.LabelAbstract{constructor(t,o,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let l of o){let u;if(typeof l=="function"?u=l():u=l,u=core.JsonUnifier.getConditionalStep(u),u.operations)try{let g=u.operations.map(x=>core.JsonUnifier.loadAssets(x));await Promise.all(g);}catch(g){w.error("The operation in the onLoadingLabel function of the label has an error:",g);}}};super(t,n);T(this,"_steps");T(this,"operationStringConvert");T(this,"skipEmptyDialogs",false);this._steps=o,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(t=>this.stepConverter(t))}get stepCount(){return this._steps.length}getStepById(t){if(t<0||t>=this._steps.length)return;let o=this._steps[t];return this.stepConverter(o)}getStepSha(t){if(t<0||t>=this.steps.length)return;let o=this._steps[t];return (0, X.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let o="";if(Array.isArray(t)){let n=[];t.forEach(s=>{if(typeof s=="string")n.push(s);else if(s&&typeof s=="object"){let l=core.JsonUnifier.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=core.JsonUnifier.getLogichValue(l)||""),Array.isArray(l)?n=n.map(u=>`${u}`).concat(l):n.push(`${l}`)):n.push(`${s}`);}else n.push(`${s}`);}),o=n;}else {let n=core.JsonUnifier.getLogichValue(t);n&&!Array.isArray(n)&&typeof n=="object"&&(n=core.JsonUnifier.getLogichValue(n)),n&&Array.isArray(n)?o=n.map(s=>`${s}`):o=`${n}`;}return o}getDialogue(t){if(t==null)return;let o=core.JsonUnifier.getLogichValue(t);return o==null?`${o}`:typeof o=="object"&&"character"in o&&"text"in o?{character:o.character,text:translator.translator.t(this.getDialogueText(o.text))}:translator.translator.t(this.getDialogueText(o))}getChoices(t){return core.JsonUnifier.getLogichValue(t)?.map(s=>core.JsonUnifier.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(t){return async o=>{let n=typeof t=="function"?t():t;n=pixiVn.createExportableElement(n),n=core.JsonUnifier.getConditionalStep(n);let s=this.operationStringConvert?h=>this.operationStringConvert(h,n,o):void 0,{operations:l=[]}=n;for(let h of l)await I(h,s);let{labelToOpen:u=[]}=n,g=this.getChoices(n.choices),x=core.JsonUnifier.getLogichValue(n.glueEnabled),f=this.getDialogue(n.dialogue),V=[];Array.isArray(u)||(u=[u]),u.forEach(h=>{let d=core.JsonUnifier.getLogichValue(h);d&&V.push(d);});let b=core.JsonUnifier.getLogichValue(n.goNextStep),N=core.JsonUnifier.getLogichValue(n.end);if(g){let h=g.map(d=>{let y="";if(Array.isArray(d.text)){let r=[];d.text.forEach(p=>{if(typeof p=="string")r.push(translator.translator.t(p));else if(p&&typeof p=="object"){let c=core.JsonUnifier.getLogichValue(p);c&&!Array.isArray(c)&&typeof c=="object"&&(c=core.JsonUnifier.getLogichValue(c)||""),c&&(Array.isArray(c)?r=r.concat(translator.translator.t(c)):r.push(translator.translator.t(c)));}}),y=r;}else typeof d.text=="string"&&(y=translator.translator.t(d.text));return {label:d.label,text:y,props:d.props,type:d.type,oneTime:d.oneTime,onlyHaveNoChoice:d.onlyHaveNoChoice,autoSelect:d.autoSelect}});narration.narration.choices=h;}else narration.narration.choices=void 0;f!==void 0&&(narration.narration.dialogue=f,this.skipEmptyDialogs&&typeof f=="string"&&(f===""||RegExp(/^\s+$/).test(f))&&(b=true)),x?narration.narration.dialogGlue=true:x===false&&(narration.narration.dialogGlue=false);for(let h of V){let d=h.label;typeof d=="object"&&(d=core.JsonUnifier.getLogichValue(d)||"");let y=h.params?.map(e=>core.JsonUnifier.getLogichValue(e));o={...o,...h.props},h.type==="jump"?(narration.narration.openedLabels.length>0&&narration.narration.closeCurrentLabel(),storage.storage.setTempVariable(`${$}${narration.narration.openedLabels.length}`,y),await narration.narration.call(d,o)):(storage.storage.setTempVariable(`${$}${narration.narration.openedLabels.length}`,y),await narration.narration.call(d,o));}N==="game_end"?(narration.narration.closeAllLabels(),await narration.narration.continue(o,{runNow:true})):N==="label_end"&&narration.narration.closeCurrentLabel(),b&&await narration.narration.continue(o,{runNow:true});}}};exports.LabelJson=_;exports.importPixiVNJson=ae;
|
package/dist/importer.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {JsonUnifier}from'@drincs/pixi-vn-json/core';import {RegisteredLabels,LabelAbstract,narration}from'@drincs/pixi-vn/narration';import {createExportableElement}from'@drincs/pixi-vn';import {translator}from'@drincs/pixi-vn-json/translator';import {storage}from'@drincs/pixi-vn/storage';var K=Object.create;var D=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var te=(a,i,t)=>i in a?D(a,i,{enumerable:true,configurable:true,writable:true,value:t}):a[i]=t;var H=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(i,t)=>(typeof require<"u"?require:i)[t]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var R=(a,i)=>()=>(i||a((i={exports:{}}).exports,i),i.exports);var ie=(a,i,t,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of Y(i))!ee.call(a,n)&&n!==t&&D(a,n,{get:()=>i[n],enumerable:!(o=Q(i,n))||o.enumerable});return a};var ne=(a,i,t)=>(t=a!=null?K(Z(a)):{},ie(D(t,"default",{value:a,enumerable:true}),a));var T=(a,i,t)=>te(a,typeof i!="symbol"?i+"":i,t);var q=R((A,U)=>{(function(a,i){typeof A=="object"?U.exports=A=i():typeof define=="function"&&define.amd?define([],i):a.CryptoJS=i();})(A,function(){var a=a||(function(i,t){var o;if(typeof window<"u"&&window.crypto&&(o=window.crypto),typeof self<"u"&&self.crypto&&(o=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(o=globalThis.crypto),!o&&typeof window<"u"&&window.msCrypto&&(o=window.msCrypto),!o&&typeof global<"u"&&global.crypto&&(o=global.crypto),!o&&typeof H=="function")try{o=H("crypto");}catch{}var n=function(){if(o){if(typeof o.getRandomValues=="function")try{return o.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof o.randomBytes=="function")try{return o.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||(function(){function e(){}return function(r){var p;return e.prototype=r,p=new e,e.prototype=null,p}})(),l={},u=l.lib={},g=u.Base=(function(){return {extend:function(e){var r=s(this);return e&&r.mixIn(e),(!r.hasOwnProperty("init")||this.init===r.init)&&(r.init=function(){r.$super.init.apply(this,arguments);}),r.init.prototype=r,r.$super=this,r},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var r in e)e.hasOwnProperty(r)&&(this[r]=e[r]);e.hasOwnProperty("toString")&&(this.toString=e.toString);},clone:function(){return this.init.prototype.extend(this)}}})(),x=u.WordArray=g.extend({init:function(e,r){e=this.words=e||[],r!=t?this.sigBytes=r:this.sigBytes=e.length*4;},toString:function(e){return (e||V).stringify(this)},concat:function(e){var r=this.words,p=e.words,c=this.sigBytes,v=e.sigBytes;if(this.clamp(),c%4)for(var P=0;P<v;P++){var k=p[P>>>2]>>>24-P%4*8&255;r[c+P>>>2]|=k<<24-(c+P)%4*8;}else for(var L=0;L<v;L+=4)r[c+L>>>2]=p[L>>>2];return this.sigBytes+=v,this},clamp:function(){var e=this.words,r=this.sigBytes;e[r>>>2]&=4294967295<<32-r%4*8,e.length=i.ceil(r/4);},clone:function(){var e=g.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var r=[],p=0;p<e;p+=4)r.push(n());return new x.init(r,e)}}),f=l.enc={},V=f.Hex={stringify:function(e){for(var r=e.words,p=e.sigBytes,c=[],v=0;v<p;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push((P>>>4).toString(16)),c.push((P&15).toString(16));}return c.join("")},parse:function(e){for(var r=e.length,p=[],c=0;c<r;c+=2)p[c>>>3]|=parseInt(e.substr(c,2),16)<<24-c%8*4;return new x.init(p,r/2)}},b=f.Latin1={stringify:function(e){for(var r=e.words,p=e.sigBytes,c=[],v=0;v<p;v++){var P=r[v>>>2]>>>24-v%4*8&255;c.push(String.fromCharCode(P));}return c.join("")},parse:function(e){for(var r=e.length,p=[],c=0;c<r;c++)p[c>>>2]|=(e.charCodeAt(c)&255)<<24-c%4*8;return new x.init(p,r)}},N=f.Utf8={stringify:function(e){try{return decodeURIComponent(escape(b.stringify(e)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(e){return b.parse(unescape(encodeURIComponent(e)))}},h=u.BufferedBlockAlgorithm=g.extend({reset:function(){this._data=new x.init,this._nDataBytes=0;},_append:function(e){typeof e=="string"&&(e=N.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes;},_process:function(e){var r,p=this._data,c=p.words,v=p.sigBytes,P=this.blockSize,k=P*4,L=v/k;e?L=i.ceil(L):L=i.max((L|0)-this._minBufferSize,0);var C=L*P,j=i.min(C*4,v);if(C){for(var E=0;E<C;E+=P)this._doProcessBlock(c,E);r=c.splice(0,C),p.sigBytes-=j;}return new x.init(r,j)},clone:function(){var e=g.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});u.Hasher=h.extend({cfg:g.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset();},reset:function(){h.reset.call(this),this._doReset();},update:function(e){return this._append(e),this._process(),this},finalize:function(e){e&&this._append(e);var r=this._doFinalize();return r},blockSize:512/32,_createHelper:function(e){return function(r,p){return new e.init(p).finalize(r)}},_createHmacHelper:function(e){return function(r,p){return new y.HMAC.init(e,p).finalize(r)}}});var y=l.algo={};return l})(Math);return a});});var M=R((B,F)=>{(function(a,i){typeof B=="object"?F.exports=B=i(q()):typeof define=="function"&&define.amd?define(["./core"],i):i(a.CryptoJS);})(B,function(a){return (function(){var i=a,t=i.lib,o=t.WordArray,n=t.Hasher,s=i.algo,l=[],u=s.SHA1=n.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878,3285377520]);},_doProcessBlock:function(g,x){for(var f=this._hash.words,V=f[0],b=f[1],N=f[2],h=f[3],d=f[4],y=0;y<80;y++){if(y<16)l[y]=g[x+y]|0;else {var e=l[y-3]^l[y-8]^l[y-14]^l[y-16];l[y]=e<<1|e>>>31;}var r=(V<<5|V>>>27)+d+l[y];y<20?r+=(b&N|~b&h)+1518500249:y<40?r+=(b^N^h)+1859775393:y<60?r+=(b&N|b&h|N&h)-1894007588:r+=(b^N^h)-899497514,d=h,h=N,N=b<<30|b>>>2,b=V,V=r;}f[0]=f[0]+V|0,f[1]=f[1]+b|0,f[2]=f[2]+N|0,f[3]=f[3]+h|0,f[4]=f[4]+d|0;},_doFinalize:function(){var g=this._data,x=g.words,f=this._nDataBytes*8,V=g.sigBytes*8;return x[V>>>5]|=128<<24-V%32,x[(V+64>>>9<<4)+14]=Math.floor(f/4294967296),x[(V+64>>>9<<4)+15]=f,g.sigBytes=x.length*4,this._process(),this._hash},clone:function(){var g=n.clone.call(this);return g._hash=this._hash.clone(),g}});i.SHA1=n._createHelper(u),i.HmacSHA1=n._createHmacHelper(u);})(),a.SHA1});});function z(a){let i="";return a.values.forEach(t=>{if(typeof t=="string")i+=t;else {let o=JsonUnifier.getLogichValue(t);i+=`${o}`;}}),i}async function I(a,i){let t=JsonUnifier.getLogichValue(a);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);break;case "operationtoconvert":if(i){let o=z(t),n=await i(o);n&&await I(n,i);}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}}function W(a){let i=JsonUnifier.getLogichValue(a);i&&i.type==="value"&&i.storageOperationType==="set"&&(i.storageType==="storage"||i.storageType==="tempstorage")&&JsonUnifier.setInitialStorageValue(i);}var w;(n=>(n.log=(s,...l)=>console.log(`[Pixi\u2019VN Json] ${s}`,...l),n.warn=(s,...l)=>console.warn(`[Pixi\u2019VN Json] ${s}`,...l),n.error=(s,...l)=>console.error(`[Pixi\u2019VN Json] ${s}`,...l),n.info=(s,...l)=>console.info(`[Pixi\u2019VN Json] ${s}`,...l)))(w||(w={}));async function ae(a,i={}){if(!Array.isArray(a))if(typeof a=="object"||typeof a=="string")a=[a];else {w.error("Error parsing imported Pixi'VN JSON: data is not an object");return}let t=a.map(async s=>{if(typeof s=="string")try{s=JSON.parse(s);}catch(l){w.error("Error parsing imported Pixi'VN JSON",l),s={};}return s}),n=(await Promise.all(t)).map(async s=>{let l=[];if(s.initialOperations)for(let u of s.initialOperations)W(u);if(s.labels){let u=s.labels;for(let g in u)try{let x=u[g],f=new _(g,x,void 0,i);RegisteredLabels.add(f);}catch(x){w.error(`Error creating JSON label ${g}`,x);}}return Promise.all(l)});await Promise.all(n);}var X=ne(M());var $="___param___";var _=class extends LabelAbstract{constructor(t,o,n,s={}){n||(n={}),n.onLoadingLabel=async()=>{for(let l of o){let u;if(typeof l=="function"?u=l():u=l,u=JsonUnifier.getConditionalStep(u),u.operations)try{let g=u.operations.map(x=>JsonUnifier.loadAssets(x));await Promise.all(g);}catch(g){w.error("The operation in the onLoadingLabel function of the label has an error:",g);}}};super(t,n);T(this,"_steps");T(this,"operationStringConvert");T(this,"skipEmptyDialogs",false);this._steps=o,this.operationStringConvert=s.operationStringConvert,this.skipEmptyDialogs=s.skipEmptyDialogs||false;}get steps(){return this._steps.map(t=>this.stepConverter(t))}get stepCount(){return this._steps.length}getStepById(t){if(t<0||t>=this._steps.length)return;let o=this._steps[t];return this.stepConverter(o)}getStepSha(t){if(t<0||t>=this.steps.length)return;let o=this._steps[t];return (0, X.default)(o.toString().toLocaleLowerCase()).toString()}getDialogueText(t){let o="";if(Array.isArray(t)){let n=[];t.forEach(s=>{if(typeof s=="string")n.push(s);else if(s&&typeof s=="object"){let l=JsonUnifier.getLogichValue(s);l?(l&&!Array.isArray(l)&&typeof l=="object"&&(l=JsonUnifier.getLogichValue(l)||""),Array.isArray(l)?n=n.map(u=>`${u}`).concat(l):n.push(`${l}`)):n.push(`${s}`);}else n.push(`${s}`);}),o=n;}else {let n=JsonUnifier.getLogichValue(t);n&&!Array.isArray(n)&&typeof n=="object"&&(n=JsonUnifier.getLogichValue(n)),n&&Array.isArray(n)?o=n.map(s=>`${s}`):o=`${n}`;}return o}getDialogue(t){if(t==null)return;let o=JsonUnifier.getLogichValue(t);return o==null?`${o}`:typeof o=="object"&&"character"in o&&"text"in o?{character:o.character,text:translator.t(this.getDialogueText(o.text))}:translator.t(this.getDialogueText(o))}getChoices(t){return JsonUnifier.getLogichValue(t)?.map(s=>JsonUnifier.getLogichValue(s)).filter(s=>s!==void 0)}stepConverter(t){return async o=>{let n=typeof t=="function"?t():t;n=createExportableElement(n),n=JsonUnifier.getConditionalStep(n);let s=this.operationStringConvert?h=>this.operationStringConvert(h,n,o):void 0,{operations:l=[]}=n;for(let h of l)await I(h,s);let{labelToOpen:u=[]}=n,g=this.getChoices(n.choices),x=JsonUnifier.getLogichValue(n.glueEnabled),f=this.getDialogue(n.dialogue),V=[];Array.isArray(u)||(u=[u]),u.forEach(h=>{let d=JsonUnifier.getLogichValue(h);d&&V.push(d);});let b=JsonUnifier.getLogichValue(n.goNextStep),N=JsonUnifier.getLogichValue(n.end);if(g){let h=g.map(d=>{let y="";if(Array.isArray(d.text)){let r=[];d.text.forEach(p=>{if(typeof p=="string")r.push(translator.t(p));else if(p&&typeof p=="object"){let c=JsonUnifier.getLogichValue(p);c&&!Array.isArray(c)&&typeof c=="object"&&(c=JsonUnifier.getLogichValue(c)||""),c&&(Array.isArray(c)?r=r.concat(translator.t(c)):r.push(translator.t(c)));}}),y=r;}else typeof d.text=="string"&&(y=translator.t(d.text));return {label:d.label,text:y,props:d.props,type:d.type,oneTime:d.oneTime,onlyHaveNoChoice:d.onlyHaveNoChoice,autoSelect:d.autoSelect}});narration.choices=h;}else narration.choices=void 0;f!==void 0&&(narration.dialogue=f,this.skipEmptyDialogs&&typeof f=="string"&&(f===""||RegExp(/^\s+$/).test(f))&&(b=true)),x?narration.dialogGlue=true:x===false&&(narration.dialogGlue=false);for(let h of V){let d=h.label;typeof d=="object"&&(d=JsonUnifier.getLogichValue(d)||"");let y=h.params?.map(e=>JsonUnifier.getLogichValue(e));o={...o,...h.props},h.type==="jump"?(narration.openedLabels.length>0&&narration.closeCurrentLabel(),storage.setTempVariable(`${$}${narration.openedLabels.length}`,y),await narration.call(d,o)):(storage.setTempVariable(`${$}${narration.openedLabels.length}`,y),await narration.call(d,o));}N==="game_end"?(narration.closeAllLabels(),await narration.continue(o,{runNow:true})):N==="label_end"&&narration.closeCurrentLabel(),b&&await narration.continue(o,{runNow:true});}}};export{_ as LabelJson,ae as importPixiVNJson};
|