definition-generator-framework 2.0.7 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -11,6 +11,7 @@ interface AddFileOptions {
11
11
  variable: any;
12
12
  preText?: string | string[];
13
13
  variableType?: string;
14
+ satisfies?: string;
14
15
  replaceMap?: {
15
16
  target: string;
16
17
  replace: string;
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ interface AddFileOptions {
11
11
  variable: any;
12
12
  preText?: string | string[];
13
13
  variableType?: string;
14
+ satisfies?: string;
14
15
  replaceMap?: {
15
16
  target: string;
16
17
  replace: string;
package/dist/index.js CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  `);let i;if(t.assetUrl){if(!t.filePath)throw new Error("filePath is required when using assetUrl");if(!helpersLib.Comparator.isArray(t.variable))throw new Error("variable should be an array when using assetUrl");let{assetImports:r,replaceMap:o}=this.ɗi(t.variable,t.assetUrl,t.filePath);e+=r+`
4
4
 
5
- `,i=o;}return t.variableType?e+=`export const ${t.variableName}: ${t.variableType} = ${this.ɗcb(t.variable)}`:e+=`export const ${t.variableName} = ${this.ɗcb(t.variable)}`,i&&(e=this.ɗbo(e,i)),t.replaceMap&&(e=this.ɗbo(e,t.replaceMap)),this.format(e)}static async format(t){return standalone.format(t,{parser:"typescript",trailingComma:"none",tabWidth:2,printWidth:130,singleQuote:true,arrowParens:"avoid",plugins:[ne__namespace,re__namespace]})}static ɗj(t,e){let i=l.outputPath+t.substring(0,t.lastIndexOf("/")),r=l.config.projectRoot+e.substring(1);return dt__namespace.default.relative(i,r).replace(/\\/g,"/")}static ɗbo(t,e){return e.forEach(i=>{t=t.replace(new RegExp(i.target,"g"),i.replace);}),t}static ɗi(t,e,i){let r=t.map(p=>{let c=helpersLib.JsonHelper.deepFind(p,e);if(!c)throw new Error(`OutputHelperClass: Asset url is not found in the given variable! item: "${JSON.stringify(p)}", assetUrl: "${e}"`);return c}),o=new Map;r.forEach(p=>{if(!o.has(p)){let c=`asset${o.size}`;o.set(p,c);}});let s=Array.from(o,([p,c])=>({name:c,url:p})).map(p=>`import ${p.name} from '${this.ɗj(i,p.url)}';`).join(`
5
+ `,i=o;}return t.variableType?e+=`export const ${t.variableName}: ${t.variableType} = ${this.ɗcb(t.variable)}`:e+=`export const ${t.variableName} = ${this.ɗcb(t.variable)}`,t.satisfies&&(e+=` as const satisfies ${t.satisfies}`),i&&(e=this.ɗbo(e,i)),t.replaceMap&&(e=this.ɗbo(e,t.replaceMap)),this.format(e)}static async format(t){return standalone.format(t,{parser:"typescript",trailingComma:"none",tabWidth:2,printWidth:130,singleQuote:true,arrowParens:"avoid",plugins:[ne__namespace,re__namespace]})}static ɗj(t,e){let i=l.outputPath+t.substring(0,t.lastIndexOf("/")),r=l.config.projectRoot+e.substring(1);return dt__namespace.default.relative(i,r).replace(/\\/g,"/")}static ɗbo(t,e){return e.forEach(i=>{t=t.replace(new RegExp(i.target,"g"),i.replace);}),t}static ɗi(t,e,i){let r=t.map(p=>{let c=helpersLib.JsonHelper.deepFind(p,e);if(!c)throw new Error(`OutputHelperClass: Asset url is not found in the given variable! item: "${JSON.stringify(p)}", assetUrl: "${e}"`);return c}),o=new Map;r.forEach(p=>{if(!o.has(p)){let c=`asset${o.size}`;o.set(p,c);}});let s=Array.from(o,([p,c])=>({name:c,url:p})).map(p=>`import ${p.name} from '${this.ɗj(i,p.url)}';`).join(`
6
6
  `),a=r.reduce((p,c)=>[...p,{target:`"${c}"`,replace:o.get(c)}],[]);return {assetImports:s,replaceMap:a}}static ɗcb(t){return JSON.stringify(t,(e,i)=>i===void 0?null:i).replace(/null/gm,"undefined")}};var l=class{static{this.compilerExecutionPath="";}static{this.outputPath="";}static{this.config={projectRoot:"",compilerModulesPath:""};}static{this.rawDefinitions=[];}static{this.files=[];}static{this.output=[];}static{this.exports=[];}static{this.componentInProgressData=void 0;}static async addFile(t){this.exports.push({variableName:t.variableName,path:t.path}),this.output.push({path:t.path,content:await N.generate({preText:helpersLib.Comparator.isArray(t.preText)?t.preText.join(`
7
- `):t.preText,variableName:t.variableName,variableType:t.variableType,variable:t.variable,replaceMap:t.replaceMap,filePath:t.path,assetUrl:t.assetUrl})});}static get successful(){return this.errorLogs.length===0}static addErrorLog(t,e="default"){helpersLib.Comparator.isArray(t)?e==="lowPriority"?this.ɗu=[...t,...this.ɗu]:this.ɗu.push(...t):e==="lowPriority"?this.ɗu=[t,...this.ɗu]:this.ɗu.push(t);}static flushErrorLogs(){this.errorLogs=[...this.ɗu,...this.errorLogs],this.ɗu=[];}static{this.errorLogs=[];}static{this.ɗu=[];}static reset(){this.compilerExecutionPath="D:/test",this.outputPath="D:/test/.asset-build",this.config.projectRoot="D:/",this.files=[],this.rawDefinitions=[],this.errorLogs=[],this.ɗu=[],this.output=[];}};var G=class{constructor(t){this.ɗar=t;this.ɗav=new Set;this.ɗau=new Map;this.ɗb=new Set;this.ɗt=[];}newEntry(t,e){if(this.ɗav.has(t)){if(!this.ɗb.has(t)){this.ɗb.add(t);let i=this.ɗau.get(t);i&&this.ɗt.push({identifier:t,location:i});}return this.ɗt.push({identifier:t,location:e}),false}else return this.ɗav.add(t),this.ɗau.set(t,e),true}logDuplicateErrors(){this.ɗt.forEach(t=>{let e={description:`Value should be singular! Group: "${this.ɗar}", Value: "${t.identifier}"`,location:t.location};l.addErrorLog(e);});}};var C=class{static{this.ɗs=new Map;}static logDuplicates(){this.ɗs.forEach(t=>t.logDuplicateErrors());}static getDefinitionComponentName(t){return t.$meta.componentName}static getDefinitionComponentNamesFromArray(t){return helpersLib.Comparator.isArray(t)?t.map(e=>this.getDefinitionComponentName(e)):[this.getDefinitionComponentName(t)]}static getValidationState(t){return t.state.path&&(t.state.path.length===0||t.state.path[0]!==void 0&&t.prefs.context.rawDefinition)?"valid":"notValid"}static getPathAndRawDefinition(t){let e=t.state.path,i=t.prefs.context.rawDefinition;return {path:e,rawDefinition:i}}static getDuplicateHelper(t){let e=this.ɗs.get(t);return e||(e=new G(t),this.ɗs.set(t,e)),e}};var W=class{constructor(t){this.ɗac=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(C.getValidationState(e)==="valid"){let{rawDefinition:r}=C.getPathAndRawDefinition(e);if(t=r.location.path.substring(0,r.location.path.lastIndexOf("/")+1)+t,this.ɗac.existsSync(t))return t.replace(l.config.projectRoot,".");throw new Error(`No file is found in the path: "${t}"`)}else throw new Error(`Internal Error; joi validation context for path validator: Path: "${e.state.path}", RawDefinition: "${JSON.stringify(e.prefs.context.rawDefinition)}"`)};}};var K=class{constructor(t,e,i,r){t={x:t.x*i,y:t.y*i},this.ɗbq=i,this.ɗe=r||false,this.ɗc=this.ɗai(t,e),this.ɗd=this.ɗaj(t,this.ɗc);}convertPositionToSpriteAnchor(t){t={x:t.x*this.ɗbq,y:t.y*this.ɗbq};let e={x:t.x+this.ɗd.topLeft.x,y:t.y+this.ɗd.topLeft.y};if(this.ɗe&&!this.ɗce(e))throw new Error(`location is outside of the sprite boundaries. Entered position: {x: ${t.x}, y: ${t.y}}, position on sprite: {x: ${e.x}, y: ${e.y}}, bounding box: ${JSON.stringify(this.ɗd)}.`);return e}getRotationFromAnchor(t){return helpersLib.Vector.fromVec2(t).radian.value}ɗce(t){return !(t.x<this.ɗd.topLeft.x||t.x>this.ɗd.bottomRight.x||t.y<this.ɗd.topLeft.y||t.y>this.ɗd.bottomRight.y)}ɗai(t,e){return {x:t.x*e.x,y:t.y*e.y}}ɗaj(t,e){return {topLeft:{x:-e.x,y:-e.y},bottomRight:{x:t.x-e.x,y:t.y-e.y}}}};var Z=class{constructor(t){this.ɗbd=t;this.validate=(t,e)=>{let i=this.ɗbd.selectSpriteDefinition(t);if(!i)throw new Error("positionOnSprite - callback function did not return sprite definition.");let r=new K(i.url.size,i.anchor,i.scale,this.ɗbd.checkIfPositionIsOnSprite);return (Array.isArray(this.ɗbd.positionsJsonPath)?this.ɗbd.positionsJsonPath:[this.ɗbd.positionsJsonPath]).forEach(s=>jsonpathPlus.JSONPath({json:t,path:s}).forEach(a=>{if(helpersLib.Comparator.isObject(a)){if(!helpersLib.Comparator.isNumber(a.x)||!helpersLib.Comparator.isNumber(a.y))throw new Error(`positionOnSprite, positions json path returned a non-vec2 result. Value: "${a}".`)}else throw new Error(`positionOnSprite, positions json path returned a non-object result. Value: "${a}".`);let p=r.convertPositionToSpriteAnchor(a);p={x:Math.round(p.x),y:Math.round(p.y)},this.ɗbd.includeRotationFromAnchor?(a.rotationFromAnchor=r.getRotationFromAnchor(p),a.positionFromAnchor=p,delete a.x,delete a.y):(a.x=p.x,a.y=p.y);})),t};}};var I=class{static findLine(t,e){if(e.length===0)return t.parsedStructure.line;{let i,r=[...e];for(;i===void 0&&r.length>0;)i=this.ɗz(t.parsedStructure.rawData,[...r]),r.pop();return i||t.parsedStructure.line}}static flatten(t){return this.ɗaa(t.parsedStructure.rawData)}static ɗz(t,e){let i=e.shift(),r;if(t&&i!==void 0&&(helpersLib.Comparator.isNumber(i)?helpersLib.Comparator.isArray(t)&&(r=t[i]):helpersLib.Comparator.isObject(t)&&(r=t[i])),r)return e.length===0?r.line:this.ɗz(r.rawData,e)}static ɗaa(t){if(helpersLib.Comparator.isArray(t))return t.map(e=>this.ɗaa(e.rawData));if(helpersLib.Comparator.isObject(t)){let e=t;return Object.keys(e).reduce((i,r)=>{let o=e[r];return i[r]=this.ɗaa(o.rawData),i},{})}else return t}};var m=class{static{this.ɗas=new Map;}static{this.ɗp=new Map;}static{this.ɗq=new Map;}static{this.ɗh=new Map;}static getDefinitions(t){let e=this.ɗq.get(this.ɗal(t));return e?Array.from(e.values()):[]}static getDefinition(t,e){if(!t.$meta.keyName)throw new Error(`"${t.name}" doesn't have a keyName, getDefinition cannot be called on it.`);return this.ɗq.get(this.ɗal(t))?.get(e)}static getDefinitionOrFail(t,e){let i=this.getDefinition(t,e);if(!i)throw new Error(`No result found for "${e}" in "${t.name}".`);return i}static getSingletonDefinition(t){return this.ɗq.get(this.ɗal(t))?.get(this.ɗal(t))}static getSingletonDefinitionOrFail(t){let e=this.getSingletonDefinition(t);if(!e)throw new Error(`No result found for "${t.name}".`);return e}static getLocationInFile(t,e,i){let r=this.ɗp.get(t.name)?.get(e);if(!r)throw new Error(`No raw definition found for "${e}" in "${t.name}".`);return {line:I.findLine(r,i),path:r.location.path}}static getLocationInFileById(t,e,i){let r=this.ɗap(t,e);if(!r)throw new Error(`No raw definition found for "${e}" in "${t.name}".`);return {line:I.findLine(r,i),path:r.location.path}}static ɗay(t){return this.ɗq.has(t)}static ɗak(t){let e=this.ɗh.get(t);if(!e)throw new Error(`No component found for "${t}".`);return e}static ɗbw(t){t.forEach((e,i)=>{this.ɗq.set(i,new Map);}),this.ɗh=t;}static ɗbx(t,e,i){let r=this.ɗq.get(this.ɗal(t));r&&r.set(e,helpersLib.JsonHelper.deepCopy(i));}static ɗca(t,e){let i=this.ɗal(t),r=this.ɗq.get(i);r&&r.set(i,helpersLib.JsonHelper.deepCopy(e));}static ɗax(t,e){return !!this.ɗas.get(t.name)?.has(e)}static ɗap(t,e){return this.ɗas.get(t.name)?.get(e)}static ɗbz(t,e,i){this.ɗas.has(t.name)||this.ɗas.set(t.name,new Map);let r=this.ɗas.get(t.name);r&&r.set(e,helpersLib.JsonHelper.deepCopy(i));}static ɗby(t,e,i){this.ɗp.has(t.name)||this.ɗp.set(t.name,new Map);let r=this.ɗp.get(t.name);r&&r.set(e,helpersLib.JsonHelper.deepCopy(i));}static ɗal(t){return t.$meta.componentName}};var X=class{constructor(t){this.options=t;this.regex=/^[a-z]+([a-zA-Z0-9]+)*$/;}validatePropertyExistence(t,e,i){if(i?.additionalValidation){let r=m.ɗap(t,e),o=r?I.flatten(r):void 0,s=i.additionalValidation.validate(o);if(s.error)throw new Error(s.error.message)}}},Y=class extends X{constructor(e,i){super(i);this.validate=(e,i)=>{if(C.getValidationState(i)==="valid"){let o=this.ɗbl.find(s=>m.getDefinition(s,e));if(o)return this.validatePropertyExistence(o,e,this.options),this.ɗaw?{value:e,type:C.getDefinitionComponentName(o)}:e;if(this.ɗbl.find(a=>m.ɗax(a,e)))i.prefs.context.failSilently=true;else throw new Error(`There is no "${this.ɗbl.map(a=>C.getDefinitionComponentName(a)).join(" or ")}" definition found for "${e}"`)}else throw new Error(`Internal Error; joi validation context for reference validator: Path: "${i.state.path}", RawDefinition: "${JSON.stringify(i.prefs.context)}"`)};this.ɗbl=[];helpersLib.Comparator.isArray(e)?(this.ɗaw=true,this.ɗbl=e):(this.ɗaw=false,this.ɗbl=[e]);}},tt=class extends X{constructor(e,i){super(i);this.ɗg=e;this.validate=(e,i)=>{if(!l.componentInProgressData)helpersLib.ConsoleHelper.log("Unexpected error: Lazy reference validation has been called outside of the validation cycle.","red");else if(!l.componentInProgressData.meta.keyName)helpersLib.ConsoleHelper.log("Lazy reference can only be used for definitions with key name defined.","red");else if(l.componentInProgressData.meta.componentName!==this.ɗg)helpersLib.ConsoleHelper.log(`Lazy reference can only be used for self referencing. It is used under: "${this.ɗg}"`,"red");else if(l.componentInProgressData.meta.singleton)helpersLib.ConsoleHelper.log(`Lazy reference cannot be used for singleton components. It is used under: "${this.ɗg}"`,"red");else {let a=i.state.ancestors.at(-1)[l.componentInProgressData.meta.keyName];a?(l.componentInProgressData.idToReferencesMap.has(a)||l.componentInProgressData.idToReferencesMap.set(a,new Set),l.componentInProgressData.idToReferencesMap.get(a).add(e)):helpersLib.ConsoleHelper.log("Unexpected error: definitionId cannot be retrieved by keyname.","red");}let r=m.ɗak(this.ɗg);if(C.getValidationState(i)==="valid"){if(m.ɗax(r,e))return this.validatePropertyExistence(r,e,this.options),e;throw new Error(`There is no "${this.ɗg}" definition found for "${e}"`)}else throw new Error(`Internal Error; joi validation context for reference validator: Path: "${i.state.path}", RawDefinition: "${JSON.stringify(i.prefs.context)}"`)};}};var et=class{constructor(t){this.ɗac=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(C.getValidationState(e)==="valid"){let{rawDefinition:r}=C.getPathAndRawDefinition(e);if(t=r.location.path.substring(0,r.location.path.lastIndexOf("/")+1)+t,this.ɗac.existsSync(t))try{let s=ce__default.default(t);return {url:t.replace(l.config.projectRoot,"."),size:{x:s.width,y:s.height}}}catch{throw new Error(`The file in the path "${t}" is not an image`)}else throw new Error(`No file is found in the path: "${t}"`)}else throw new Error(`Internal Error; joi validation context for image validator: Path: "${e.state.path}", RawDefinition: "${JSON.stringify(e.prefs.context.rawDefinition)}"`)};}};var it=class{constructor(t){this.ɗbb=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(this.ɗbb.has(t))throw new Error(`Value "${t}" is not unique in the name space: "${Array.from(this.ɗbb).join(", ")}"`);return this.ɗbb.add(t),t};}};var H=class n{static decorate(t,e){t.string().__proto__.unique=function(i){let r=new it(i);return n.ɗn(this,r)},t.string().__proto__.path=function(){let i=new W(e);return n.ɗn(this,i)},t.string().__proto__.sprite=function(){let i=new et(e);return n.ɗn(this,i)},t.string().__proto__.reference=function(i,r){let o=new Y(i,r);return n.ɗn(this,o)},t.string().__proto__.lazyReference=function(i,r){let o=new tt(i,r);return n.ɗn(this,o)},t.object().__proto__.positionOnSprite=function(i){let r=new Z(i);return this.custom(r.validate)},t!==u__default.default&&this.decorate(u__default.default,e);}static ɗn(t,e){return t.regex(e.regex).custom(e.validate)}};H.decorate(u__default.default,S__namespace.default);function de(n){return n.replace(/[-_]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\s+/g," ").trim().toLowerCase().split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}function T(n){return function(t){if(n.singleton){if(n.keyName!==void 0)throw new Error(`Singleton components should not have keyName! Component: ${n.componentName}`);if(!(t.prototype instanceof rt))throw new Error(`Singleton components should extend SingleDefinitionComponent! Component: ${n.componentName}`)}else if(!(t.prototype instanceof g))throw new Error(`Non singleton components should extend DefinitionComponent! Component: ${n.componentName}`);t.$meta={componentName:n.componentName,pascalCaseComponentName:de(n.componentName),keyName:n.keyName,singleton:n.singleton,validationSchema:n.validationSchema};}}var g=class{static getSchema(){return this.$meta.validationSchema}},rt=class{static getSchema(){return this.$meta.validationSchema}};var R=class{static{this.definitionToRawDefintion=new Map;}static getRawDefinitions(t){return l.rawDefinitions.filter(e=>e.componentName===t)}static validateAndConvert(t,e){return this.getRawDefinitions(t).map(i=>{let r=this.ɗcd(i,e);if(this.definitionToRawDefintion.set(r,i),r)return {definition:r,rawDefinition:i}}).filter(i=>i)}static validateAndConvertSingular(t,e){let i=this.validateAndConvert(t,e);if(i.length===0){if(l.successful){let r={description:`Singleton definition has no declared entry "${t}"`,location:{line:0,path:"*"}};l.addErrorLog(r,"lowPriority");}}else if(i.length>1)l.rawDefinitions.filter(r=>r.componentName===t).forEach(r=>{let o={description:`Only one definition can be defined for "${t}"`,location:r.location};l.addErrorLog(o,"lowPriority");});else return i[0]}static ɗcd(t,e){let i={rawDefinition:t,failSilently:false};try{let{value:r,error:o}=e.validate(I.flatten(t),{abortEarly:!1,context:i});if(o?.details){let s=o.details.reverse().map(a=>({description:a.message,location:{line:I.findLine(t,a.path),path:t.location.path}}));l.addErrorLog(s.reverse());}else if(!i.failSilently)return r}catch(r){throw new Error(`Internal Error:
7
+ `):t.preText,variableName:t.variableName,variableType:t.variableType,satisfies:t.satisfies,variable:t.variable,replaceMap:t.replaceMap,filePath:t.path,assetUrl:t.assetUrl})});}static get successful(){return this.errorLogs.length===0}static addErrorLog(t,e="default"){helpersLib.Comparator.isArray(t)?e==="lowPriority"?this.ɗu=[...t,...this.ɗu]:this.ɗu.push(...t):e==="lowPriority"?this.ɗu=[t,...this.ɗu]:this.ɗu.push(t);}static flushErrorLogs(){this.errorLogs=[...this.ɗu,...this.errorLogs],this.ɗu=[];}static{this.errorLogs=[];}static{this.ɗu=[];}static reset(){this.compilerExecutionPath="D:/test",this.outputPath="D:/test/.asset-build",this.config.projectRoot="D:/",this.files=[],this.rawDefinitions=[],this.errorLogs=[],this.ɗu=[],this.output=[];}};var G=class{constructor(t){this.ɗar=t;this.ɗav=new Set;this.ɗau=new Map;this.ɗb=new Set;this.ɗt=[];}newEntry(t,e){if(this.ɗav.has(t)){if(!this.ɗb.has(t)){this.ɗb.add(t);let i=this.ɗau.get(t);i&&this.ɗt.push({identifier:t,location:i});}return this.ɗt.push({identifier:t,location:e}),false}else return this.ɗav.add(t),this.ɗau.set(t,e),true}logDuplicateErrors(){this.ɗt.forEach(t=>{let e={description:`Value should be singular! Group: "${this.ɗar}", Value: "${t.identifier}"`,location:t.location};l.addErrorLog(e);});}};var C=class{static{this.ɗs=new Map;}static logDuplicates(){this.ɗs.forEach(t=>t.logDuplicateErrors());}static getDefinitionComponentName(t){return t.$meta.componentName}static getDefinitionComponentNamesFromArray(t){return helpersLib.Comparator.isArray(t)?t.map(e=>this.getDefinitionComponentName(e)):[this.getDefinitionComponentName(t)]}static getValidationState(t){return t.state.path&&(t.state.path.length===0||t.state.path[0]!==void 0&&t.prefs.context.rawDefinition)?"valid":"notValid"}static getPathAndRawDefinition(t){let e=t.state.path,i=t.prefs.context.rawDefinition;return {path:e,rawDefinition:i}}static getDuplicateHelper(t){let e=this.ɗs.get(t);return e||(e=new G(t),this.ɗs.set(t,e)),e}};var W=class{constructor(t){this.ɗac=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(C.getValidationState(e)==="valid"){let{rawDefinition:r}=C.getPathAndRawDefinition(e);if(t=r.location.path.substring(0,r.location.path.lastIndexOf("/")+1)+t,this.ɗac.existsSync(t))return t.replace(l.config.projectRoot,".");throw new Error(`No file is found in the path: "${t}"`)}else throw new Error(`Internal Error; joi validation context for path validator: Path: "${e.state.path}", RawDefinition: "${JSON.stringify(e.prefs.context.rawDefinition)}"`)};}};var K=class{constructor(t,e,i,r){t={x:t.x*i,y:t.y*i},this.ɗbq=i,this.ɗe=r||false,this.ɗc=this.ɗai(t,e),this.ɗd=this.ɗaj(t,this.ɗc);}convertPositionToSpriteAnchor(t){t={x:t.x*this.ɗbq,y:t.y*this.ɗbq};let e={x:t.x+this.ɗd.topLeft.x,y:t.y+this.ɗd.topLeft.y};if(this.ɗe&&!this.ɗce(e))throw new Error(`location is outside of the sprite boundaries. Entered position: {x: ${t.x}, y: ${t.y}}, position on sprite: {x: ${e.x}, y: ${e.y}}, bounding box: ${JSON.stringify(this.ɗd)}.`);return e}getRotationFromAnchor(t){return helpersLib.Vector.fromVec2(t).radian.value}ɗce(t){return !(t.x<this.ɗd.topLeft.x||t.x>this.ɗd.bottomRight.x||t.y<this.ɗd.topLeft.y||t.y>this.ɗd.bottomRight.y)}ɗai(t,e){return {x:t.x*e.x,y:t.y*e.y}}ɗaj(t,e){return {topLeft:{x:-e.x,y:-e.y},bottomRight:{x:t.x-e.x,y:t.y-e.y}}}};var Z=class{constructor(t){this.ɗbd=t;this.validate=(t,e)=>{let i=this.ɗbd.selectSpriteDefinition(t);if(!i)throw new Error("positionOnSprite - callback function did not return sprite definition.");let r=new K(i.url.size,i.anchor,i.scale,this.ɗbd.checkIfPositionIsOnSprite);return (Array.isArray(this.ɗbd.positionsJsonPath)?this.ɗbd.positionsJsonPath:[this.ɗbd.positionsJsonPath]).forEach(s=>jsonpathPlus.JSONPath({json:t,path:s}).forEach(a=>{if(helpersLib.Comparator.isObject(a)){if(!helpersLib.Comparator.isNumber(a.x)||!helpersLib.Comparator.isNumber(a.y))throw new Error(`positionOnSprite, positions json path returned a non-vec2 result. Value: "${a}".`)}else throw new Error(`positionOnSprite, positions json path returned a non-object result. Value: "${a}".`);let p=r.convertPositionToSpriteAnchor(a);p={x:Math.round(p.x),y:Math.round(p.y)},this.ɗbd.includeRotationFromAnchor?(a.rotationFromAnchor=r.getRotationFromAnchor(p),a.positionFromAnchor=p,delete a.x,delete a.y):(a.x=p.x,a.y=p.y);})),t};}};var I=class{static findLine(t,e){if(e.length===0)return t.parsedStructure.line;{let i,r=[...e];for(;i===void 0&&r.length>0;)i=this.ɗz(t.parsedStructure.rawData,[...r]),r.pop();return i||t.parsedStructure.line}}static flatten(t){return this.ɗaa(t.parsedStructure.rawData)}static ɗz(t,e){let i=e.shift(),r;if(t&&i!==void 0&&(helpersLib.Comparator.isNumber(i)?helpersLib.Comparator.isArray(t)&&(r=t[i]):helpersLib.Comparator.isObject(t)&&(r=t[i])),r)return e.length===0?r.line:this.ɗz(r.rawData,e)}static ɗaa(t){if(helpersLib.Comparator.isArray(t))return t.map(e=>this.ɗaa(e.rawData));if(helpersLib.Comparator.isObject(t)){let e=t;return Object.keys(e).reduce((i,r)=>{let o=e[r];return i[r]=this.ɗaa(o.rawData),i},{})}else return t}};var m=class{static{this.ɗas=new Map;}static{this.ɗp=new Map;}static{this.ɗq=new Map;}static{this.ɗh=new Map;}static getDefinitions(t){let e=this.ɗq.get(this.ɗal(t));return e?Array.from(e.values()):[]}static getDefinition(t,e){if(!t.$meta.keyName)throw new Error(`"${t.name}" doesn't have a keyName, getDefinition cannot be called on it.`);return this.ɗq.get(this.ɗal(t))?.get(e)}static getDefinitionOrFail(t,e){let i=this.getDefinition(t,e);if(!i)throw new Error(`No result found for "${e}" in "${t.name}".`);return i}static getSingletonDefinition(t){return this.ɗq.get(this.ɗal(t))?.get(this.ɗal(t))}static getSingletonDefinitionOrFail(t){let e=this.getSingletonDefinition(t);if(!e)throw new Error(`No result found for "${t.name}".`);return e}static getLocationInFile(t,e,i){let r=this.ɗp.get(t.name)?.get(e);if(!r)throw new Error(`No raw definition found for "${e}" in "${t.name}".`);return {line:I.findLine(r,i),path:r.location.path}}static getLocationInFileById(t,e,i){let r=this.ɗap(t,e);if(!r)throw new Error(`No raw definition found for "${e}" in "${t.name}".`);return {line:I.findLine(r,i),path:r.location.path}}static ɗay(t){return this.ɗq.has(t)}static ɗak(t){let e=this.ɗh.get(t);if(!e)throw new Error(`No component found for "${t}".`);return e}static ɗbw(t){t.forEach((e,i)=>{this.ɗq.set(i,new Map);}),this.ɗh=t;}static ɗbx(t,e,i){let r=this.ɗq.get(this.ɗal(t));r&&r.set(e,helpersLib.JsonHelper.deepCopy(i));}static ɗca(t,e){let i=this.ɗal(t),r=this.ɗq.get(i);r&&r.set(i,helpersLib.JsonHelper.deepCopy(e));}static ɗax(t,e){return !!this.ɗas.get(t.name)?.has(e)}static ɗap(t,e){return this.ɗas.get(t.name)?.get(e)}static ɗbz(t,e,i){this.ɗas.has(t.name)||this.ɗas.set(t.name,new Map);let r=this.ɗas.get(t.name);r&&r.set(e,helpersLib.JsonHelper.deepCopy(i));}static ɗby(t,e,i){this.ɗp.has(t.name)||this.ɗp.set(t.name,new Map);let r=this.ɗp.get(t.name);r&&r.set(e,helpersLib.JsonHelper.deepCopy(i));}static ɗal(t){return t.$meta.componentName}};var X=class{constructor(t){this.options=t;this.regex=/^[a-z]+([a-zA-Z0-9]+)*$/;}validatePropertyExistence(t,e,i){if(i?.additionalValidation){let r=m.ɗap(t,e),o=r?I.flatten(r):void 0,s=i.additionalValidation.validate(o);if(s.error)throw new Error(s.error.message)}}},Y=class extends X{constructor(e,i){super(i);this.validate=(e,i)=>{if(C.getValidationState(i)==="valid"){let o=this.ɗbl.find(s=>m.getDefinition(s,e));if(o)return this.validatePropertyExistence(o,e,this.options),this.ɗaw?{value:e,type:C.getDefinitionComponentName(o)}:e;if(this.ɗbl.find(a=>m.ɗax(a,e)))i.prefs.context.failSilently=true;else throw new Error(`There is no "${this.ɗbl.map(a=>C.getDefinitionComponentName(a)).join(" or ")}" definition found for "${e}"`)}else throw new Error(`Internal Error; joi validation context for reference validator: Path: "${i.state.path}", RawDefinition: "${JSON.stringify(i.prefs.context)}"`)};this.ɗbl=[];helpersLib.Comparator.isArray(e)?(this.ɗaw=true,this.ɗbl=e):(this.ɗaw=false,this.ɗbl=[e]);}},tt=class extends X{constructor(e,i){super(i);this.ɗg=e;this.validate=(e,i)=>{if(!l.componentInProgressData)helpersLib.ConsoleHelper.log("Unexpected error: Lazy reference validation has been called outside of the validation cycle.","red");else if(!l.componentInProgressData.meta.keyName)helpersLib.ConsoleHelper.log("Lazy reference can only be used for definitions with key name defined.","red");else if(l.componentInProgressData.meta.componentName!==this.ɗg)helpersLib.ConsoleHelper.log(`Lazy reference can only be used for self referencing. It is used under: "${this.ɗg}"`,"red");else if(l.componentInProgressData.meta.singleton)helpersLib.ConsoleHelper.log(`Lazy reference cannot be used for singleton components. It is used under: "${this.ɗg}"`,"red");else {let a=i.state.ancestors.at(-1)[l.componentInProgressData.meta.keyName];a?(l.componentInProgressData.idToReferencesMap.has(a)||l.componentInProgressData.idToReferencesMap.set(a,new Set),l.componentInProgressData.idToReferencesMap.get(a).add(e)):helpersLib.ConsoleHelper.log("Unexpected error: definitionId cannot be retrieved by keyname.","red");}let r=m.ɗak(this.ɗg);if(C.getValidationState(i)==="valid"){if(m.ɗax(r,e))return this.validatePropertyExistence(r,e,this.options),e;throw new Error(`There is no "${this.ɗg}" definition found for "${e}"`)}else throw new Error(`Internal Error; joi validation context for reference validator: Path: "${i.state.path}", RawDefinition: "${JSON.stringify(i.prefs.context)}"`)};}};var et=class{constructor(t){this.ɗac=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(C.getValidationState(e)==="valid"){let{rawDefinition:r}=C.getPathAndRawDefinition(e);if(t=r.location.path.substring(0,r.location.path.lastIndexOf("/")+1)+t,this.ɗac.existsSync(t))try{let s=ce__default.default(t);return {url:t.replace(l.config.projectRoot,"."),size:{x:s.width,y:s.height}}}catch{throw new Error(`The file in the path "${t}" is not an image`)}else throw new Error(`No file is found in the path: "${t}"`)}else throw new Error(`Internal Error; joi validation context for image validator: Path: "${e.state.path}", RawDefinition: "${JSON.stringify(e.prefs.context.rawDefinition)}"`)};}};var it=class{constructor(t){this.ɗbb=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(this.ɗbb.has(t))throw new Error(`Value "${t}" is not unique in the name space: "${Array.from(this.ɗbb).join(", ")}"`);return this.ɗbb.add(t),t};}};var H=class n{static decorate(t,e){t.string().__proto__.unique=function(i){let r=new it(i);return n.ɗn(this,r)},t.string().__proto__.path=function(){let i=new W(e);return n.ɗn(this,i)},t.string().__proto__.sprite=function(){let i=new et(e);return n.ɗn(this,i)},t.string().__proto__.reference=function(i,r){let o=new Y(i,r);return n.ɗn(this,o)},t.string().__proto__.lazyReference=function(i,r){let o=new tt(i,r);return n.ɗn(this,o)},t.object().__proto__.positionOnSprite=function(i){let r=new Z(i);return this.custom(r.validate)},t!==u__default.default&&this.decorate(u__default.default,e);}static ɗn(t,e){return t.regex(e.regex).custom(e.validate)}};H.decorate(u__default.default,S__namespace.default);function de(n){return n.replace(/[-_]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\s+/g," ").trim().toLowerCase().split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}function T(n){return function(t){if(n.singleton){if(n.keyName!==void 0)throw new Error(`Singleton components should not have keyName! Component: ${n.componentName}`);if(!(t.prototype instanceof rt))throw new Error(`Singleton components should extend SingleDefinitionComponent! Component: ${n.componentName}`)}else if(!(t.prototype instanceof g))throw new Error(`Non singleton components should extend DefinitionComponent! Component: ${n.componentName}`);t.$meta={componentName:n.componentName,pascalCaseComponentName:de(n.componentName),keyName:n.keyName,singleton:n.singleton,validationSchema:n.validationSchema};}}var g=class{static getSchema(){return this.$meta.validationSchema}},rt=class{static getSchema(){return this.$meta.validationSchema}};var R=class{static{this.definitionToRawDefintion=new Map;}static getRawDefinitions(t){return l.rawDefinitions.filter(e=>e.componentName===t)}static validateAndConvert(t,e){return this.getRawDefinitions(t).map(i=>{let r=this.ɗcd(i,e);if(this.definitionToRawDefintion.set(r,i),r)return {definition:r,rawDefinition:i}}).filter(i=>i)}static validateAndConvertSingular(t,e){let i=this.validateAndConvert(t,e);if(i.length===0){if(l.successful){let r={description:`Singleton definition has no declared entry "${t}"`,location:{line:0,path:"*"}};l.addErrorLog(r,"lowPriority");}}else if(i.length>1)l.rawDefinitions.filter(r=>r.componentName===t).forEach(r=>{let o={description:`Only one definition can be defined for "${t}"`,location:r.location};l.addErrorLog(o,"lowPriority");});else return i[0]}static ɗcd(t,e){let i={rawDefinition:t,failSilently:false};try{let{value:r,error:o}=e.validate(I.flatten(t),{abortEarly:!1,context:i});if(o?.details){let s=o.details.reverse().map(a=>({description:a.message,location:{line:I.findLine(t,a.path),path:t.location.path}}));l.addErrorLog(s.reverse());}else if(!i.failSilently)return r}catch(r){throw new Error(`Internal Error:
8
8
 
9
9
  raw definition: "${JSON.stringify(t)}"
10
10
 
11
- error: "${r}"`)}}};var nt="CONFIG",kt=u__default.default.object().keys({projectRoot:u__default.default.string().regex(/^[\S]+$/).required(),compilerModulesPath:u__default.default.string().regex(/^[\S]+$/).optional()}),J=class{static{this.$meta={componentName:nt,validationSchema:kt};}static process(){let t=R.validateAndConvertSingular(nt,kt);if(t){let e=t.definition;l.config.projectRoot=e.projectRoot,e.compilerModulesPath&&(l.config.compilerModulesPath=`${e.projectRoot}${e.compilerModulesPath.replace("./","")}`);}}};var vt=class{decorateDefinitionName(t,e){return `${this.kebabCaseToCamelCase(e)}${this.upperCaseFirstLetter(t)}`}kebabCaseToCamelCase(t){return t.toLowerCase().replace(/-./g,e=>e[1].toUpperCase())}lowerCaseFirstLetter(t){return t.charAt(0).toLowerCase()+t.slice(1)}upperCaseFirstLetter(t){return t.charAt(0).toUpperCase()+t.slice(1)}removeWhiteSpace(t){return t.replace(/\r?\n|\r/g,"").replace(/\/\/.*$/gm,"").trim().replace(/ {2,}/g," ")}removeComments(t){return t.replace(/\/\/.*$/gm,"").trimEnd()}},q=new vt;var ot=class{constructor(){this.ɗr=false;this.ɗo=[];this.ɗv=[];this.ɗl="";}process(t){return this.ɗr=false,this.ɗm=void 0,this.ɗo=[],this.ɗv=[],this.ɗl=t.path,t.content.split(`
11
+ error: "${r}"`)}}};var nt="CONFIG",Jt=u__default.default.object().keys({projectRoot:u__default.default.string().regex(/^[\S]+$/).required(),compilerModulesPath:u__default.default.string().regex(/^[\S]+$/).optional()}),k=class{static{this.$meta={componentName:nt,validationSchema:Jt};}static process(){let t=R.validateAndConvertSingular(nt,Jt);if(t){let e=t.definition;l.config.projectRoot=e.projectRoot,e.compilerModulesPath&&(l.config.compilerModulesPath=`${e.projectRoot}${e.compilerModulesPath.replace("./","")}`);}}};var vt=class{decorateDefinitionName(t,e){return `${this.kebabCaseToCamelCase(e)}${this.upperCaseFirstLetter(t)}`}kebabCaseToCamelCase(t){return t.toLowerCase().replace(/-./g,e=>e[1].toUpperCase())}lowerCaseFirstLetter(t){return t.charAt(0).toLowerCase()+t.slice(1)}upperCaseFirstLetter(t){return t.charAt(0).toUpperCase()+t.slice(1)}removeWhiteSpace(t){return t.replace(/\r?\n|\r/g,"").replace(/\/\/.*$/gm,"").trim().replace(/ {2,}/g," ")}removeComments(t){return t.replace(/\/\/.*$/gm,"").trimEnd()}},q=new vt;var ot=class{constructor(){this.ɗr=false;this.ɗo=[];this.ɗv=[];this.ɗl="";}process(t){return this.ɗr=false,this.ɗm=void 0,this.ɗo=[],this.ɗv=[],this.ɗl=t.path,t.content.split(`
12
12
  `).forEach((e,i)=>{let r=q.removeWhiteSpace(e);this.ɗr?r.startsWith("###")?(this.ɗab(),this.ɗbc(e,i,r.substring(4))):this.ɗm&&r.length>0&&this.ɗm.content.push(q.removeComments(e)):r==="# DEFINITIONS"&&(this.ɗr=true);}),this.ɗab(),{definitionPlaneTexts:this.ɗo,errorLogs:this.ɗv}}ɗab(){if(this.ɗm)if(this.ɗm.content.length>0)this.ɗo.push(this.ɗm);else {let t={description:"Definitions cannot be empty!",location:this.ɗm.location};this.ɗv.push(t);}this.ɗm=void 0;}ɗbc(t,e,i){if(m.ɗay(i))this.ɗm={type:i,location:{line:e+1,path:this.ɗl},content:[]};else {let r={description:`Invalid definition header: "${t.trim()}"`,location:{line:e+1,path:this.ɗl}};this.ɗv.push(r),this.ɗm=void 0;}}};var at=class{static parse(t,e){let i=[],r=e.line,o=[];if(t.forEach((s,a)=>{if(s.startsWith(" ")){if(a===0)throw {description:"Invalid coding indent!",location:{line:e.line+a,path:e.path}};i.push(s.substring(2));}else {if(s.match(/^- {2}/g)||s.match(/^-[\S]/g))throw {description:`There should be one space after dash operator! "${s}"`,location:{line:e.line+a,path:e.path}};if(s.startsWith("-")){if(i.length){let p=b.getParsedStructure(i,{line:r,path:e.path});o.push(p);}i=[s.substring(2)],r=e.line+a;}else throw s.startsWith(" ")?{description:"Invalid coding indent!",location:{line:e.line+a,path:e.path}}:{description:`Unexpected array element! "${s}"`,location:{line:e.line+a,path:e.path}}}}),i.length){let s=b.getParsedStructure(i,{line:r,path:e.path});o.push(s);}return {line:e.line,rawData:o}}};var st=class{static parse(t,e){let i=[],r="",o=0,s,a={};if(t.forEach((p,c)=>{if(!p.startsWith(" ")&&!p.startsWith("- ")&&s!=="multiLineString"){if(p.startsWith(":"))throw {description:`Invalid row, row cannot start with columns! "${p}"`,location:{line:e.line+c,path:e.path}};if(p.match(/[\w]*:[\w]*:/g))throw {description:`Invalid row, multiple columns! "${p}"`,location:{line:e.line+c,path:e.path}};if(p.match(/: {2}/g)||p.match(/^[\w]+:[\S]/g))throw {description:`There should be one space after column operator! "${p}"`,location:{line:e.line+c,path:e.path}};if(p.startsWith(" "))throw {description:`Invalid coding indent! "${p}"`,location:{line:e.line+c,path:e.path}};if(p.indexOf(":")===-1)throw {description:`Unexpected object element! "${p}"`,location:{line:e.line+c,path:e.path}};{if(i.length){let P=b.getParsedStructure(i,{line:o,path:e.path});P.line-=1,a[r]=P,i=[],r="",o=0;}let d=q.lowerCaseFirstLetter(p.substring(0,p.indexOf(":")));if(p.trimEnd().endsWith(":"))if(r=d,o=e.line+c+1,t[c+1])s=t[c+1].startsWith("-")?"array":"object";else throw {description:`No value found after column! "${p}"`,location:{line:e.line+c,path:e.path}};else if(p.trimEnd().endsWith("`")&&p.indexOf("`")===p.lastIndexOf("`"))i.push("`"),r=d,o=e.line+c+1,s="multiLineString";else {let P=p.substring(p.indexOf(":")+2),U=b.getParsedStructure([P],{line:e.line+c,path:e.path});a[d]=U;}}}else {if(c===0)throw p.startsWith("-")?{description:`Unexpected object element! "${p}"`,location:{line:e.line+c,path:e.path}}:{description:`Invalid coding indent! "${p}"`,location:{line:e.line+c,path:e.path}};if(p.startsWith("`")){i.push(p);let d=b.getParsedStructure(i,{line:o,path:e.path});d.line-=1,a[r]=d,i=[],r="",o=0;}else i.push(p.substring(s==="object"?2:0));}}),i.length){let p=b.getParsedStructure(i,{line:o,path:e.path});p.line-=1,a[r]=p;}return {line:e.line,rawData:a}}};var pt=class{static parse(t,e){let i=t[0];if(i.startsWith("`"))return t.length===1?this.ɗbg(i,e,"`"):this.ɗbe(t,e);if(t.length>1)throw {description:`Invalid row! "${t[1]}"`,location:{line:e.line+2,path:e.path}};return i.startsWith('"')?this.ɗbg(i,e,'"'):this.ɗbf(i,e)}static ɗbf(t,e){if(t.indexOf(" ")!==-1)throw {description:`Unexpected space! "${t}"`,location:e};return {line:e.line,rawData:t==="undefined"?void 0:t}}static ɗbg(t,e,i){let r=new RegExp(i,"g");if((t.match(r)||[]).length>2)throw {description:"There should be only one opening and one closeing quote!",location:e};if(t.endsWith(i))return {line:e.line,rawData:t.replace(r,"")};throw {description:"Quote is not get closed!",location:e}}static ɗbe(t,e){let i=t[t.length-1];if(t[0]!=="`")throw {description:`There should be new line after backtick "${t[0]}"!`,location:{line:e.line,path:e.path}};if(i.startsWith("`")&&i!=="`")throw {description:`There should be new line after backtick "${i}"!`,location:{line:e.line+t.length,path:e.path}};if(i.trim().startsWith("`")){if(i!=="`")throw {description:"Invalid coding indent!",location:{line:e.line+t.length,path:e.path}};return {line:e.line,rawData:t.slice(0,t.length-1).slice(1).join(`
13
- `)}}else throw {description:`Multiline string should end with backtick in new line "${i}"!`,location:{line:e.line+t.length,path:e.path}}}};var b=class n{static getParsedStructure(t,e){let i=this.ɗaq(t[0]);switch(i){case "object":return st.parse(t,e);case "array":return at.parse(t,e);case "primitive":return pt.parse(t,e);default:{throw new Error(`Unexpected case! "${i}"`)}}}static ɗaq(t){return t.startsWith("-")&&!t.match(/^-?\d+(\.\d+)?$/)?"array":t.match(/^[\w]+:/)?"object":"primitive"}process(t){let e=[];return {rawDefinitions:t.map(r=>{try{if(r.content.length)return {componentName:r.type,location:r.location,parsedStructure:n.getParsedStructure(r.content,{line:r.location.line+1,path:r.location.path})}}catch(o){o?.description&&o?.location?e.push(o):e.push({description:`Unexpected Error! Error: "${o}"`,location:r.location});}}).filter(r=>r),errorLogs:e}}};var lt=class{static{this.ɗbv=new ot;}static{this.ɗcc=new b;}static process(){let t=l.files.reduce((i,r)=>{let o=this.ɗbv.process(r);return l.addErrorLog(o.errorLogs),i.push(...o.definitionPlaneTexts),i},[]),e=this.ɗcc.process(t);l.rawDefinitions.push(...e.rawDefinitions),l.addErrorLog(e.errorLogs),J.process();}};var bt="// ---- INDEX OUTPUT ----",ue="// ---- END ----",j=class{static{this.ɗbi=[];}static{this.ɗat=[];}static addPremadeInterface(t){this.ɗbi.push(t);}static addIdType(t,e){let i=`export type ${t}ID = ${e.map(r=>`'${r}'`).join(" | ")};`;this.ɗat.push(i);}static async generateFile(t,e){if(l.config.compilerModulesPath){let i=await this.ɗaf(t);i&&await this.ɗk(i);}else await this.ɗk(e);}static async ɗk(t){let e=t,i=this.generateTypes();i&&(e+=`
13
+ `)}}else throw {description:`Multiline string should end with backtick in new line "${i}"!`,location:{line:e.line+t.length,path:e.path}}}};var b=class n{static getParsedStructure(t,e){let i=this.ɗaq(t[0]);switch(i){case "object":return st.parse(t,e);case "array":return at.parse(t,e);case "primitive":return pt.parse(t,e);default:{throw new Error(`Unexpected case! "${i}"`)}}}static ɗaq(t){return t.startsWith("-")&&!t.match(/^-?\d+(\.\d+)?$/)?"array":t.match(/^[\w]+:/)?"object":"primitive"}process(t){let e=[];return {rawDefinitions:t.map(r=>{try{if(r.content.length)return {componentName:r.type,location:r.location,parsedStructure:n.getParsedStructure(r.content,{line:r.location.line+1,path:r.location.path})}}catch(o){o?.description&&o?.location?e.push(o):e.push({description:`Unexpected Error! Error: "${o}"`,location:r.location});}}).filter(r=>r),errorLogs:e}}};var lt=class{static{this.ɗbv=new ot;}static{this.ɗcc=new b;}static process(){let t=l.files.reduce((i,r)=>{let o=this.ɗbv.process(r);return l.addErrorLog(o.errorLogs),i.push(...o.definitionPlaneTexts),i},[]),e=this.ɗcc.process(t);l.rawDefinitions.push(...e.rawDefinitions),l.addErrorLog(e.errorLogs),k.process();}};var bt="// ---- INDEX OUTPUT ----",ue="// ---- END ----",j=class{static{this.ɗbi=[];}static{this.ɗat=[];}static addPremadeInterface(t){this.ɗbi.push(t);}static addIdType(t,e){let i=`export type ${t}ID = ${e.map(r=>`'${r}'`).join(" | ")};`;this.ɗat.push(i);}static async generateFile(t,e){if(l.config.compilerModulesPath){let i=await this.ɗaf(t);i&&await this.ɗk(i);}else await this.ɗk(e);}static async ɗk(t){let e=t,i=this.generateTypes();i&&(e+=`
14
14
 
15
15
  `+i),l.output.push({path:"/index.ts",content:await N.format(e)});}static async ɗaf(t){let e=Lt__namespace.sync(`${l.config.compilerModulesPath}/**/*.ts`).map(o=>o.replace(/\\/g,"/"));e.length===0&&helpersLib.ConsoleHelper.log("No typescript file found to generate index.ts file.","red");let i=this.ɗae(),r=await this.ɗag(e);if(r!==void 0){let o=`${t}
16
16
  ${i}
@@ -29,7 +29,7 @@ ${o.join(`
29
29
  `)}`}static generateTypes(){let t="";return this.ɗat.length>0&&(t+=`//-------------------------- ID TYPES --------------------------
30
30
  `,t+=this.ɗat.join(`
31
31
  `),t+=`
32
- `),t}};var he=/^[a-z]+([a-zA-Z0-9]+)*$/,mt="======================================================",ge="------------------------------------------------------",Mt=n=>n.path.replace(l.compilerExecutionPath+"/","")+":"+n.line,ft=class{static async process(t,e,i){let r=new Map;r.set(nt,J),t.forEach(s=>{let a=s.$meta.componentName;if(r.has(a))throw new Error(`Component name "${a}" is used more than once.`);r.set(a,s);}),m.ɗbw(r),helpersLib.ConsoleHelper.log("Compilation is in progress.","white"),this.ɗbk();let o=await this.ɗah(t,e,i);this.ɗcf(o,l.outputPath);}static ɗbk(){l.compilerExecutionPath=dt__namespace.resolve("./").replace(/\\/g,"/"),l.outputPath=`${l.compilerExecutionPath}/.asset-build`,l.files=Lt__namespace.sync(`${l.compilerExecutionPath}/**/*.md`).map(t=>t.replace(/\\/g,"/")).map(t=>{let e=S__namespace.readFileSync(t).toString();return {path:t,content:e}});}static ɗcf(t,e){let i=new Set;Lt__namespace.sync(`${l.outputPath}/**/*`,{nodir:true}).map(a=>a.replace(/\\/g,"/")).forEach(a=>{i.add(a);}),t.forEach(a=>{a.path=e+a.path,i.delete(a.path);}),l.successful&&(helpersLib.ConsoleHelper.log(mt,"gray"),helpersLib.ConsoleHelper.log("Changes:","gray"),helpersLib.ConsoleHelper.newLine());let r=0;l.successful&&i.forEach(a=>{r++,console.info(`${helpersLib.ConsoleHelper.red}Erasing file:${helpersLib.ConsoleHelper.gray} "${this.ɗf(a)}"${helpersLib.ConsoleHelper.default}`),S__namespace.unlinkSync(a);});let o=0,s=0;t.forEach(a=>{let p=a.path.substring(0,a.path.lastIndexOf("/"));S__namespace.mkdirSync(p,{recursive:true});let c=S__namespace.existsSync(a.path);(c?S__namespace.readFileSync(a.path).toString():"")!==a.content&&(c?(o++,console.info(`${helpersLib.ConsoleHelper.blue}Modifying file:${helpersLib.ConsoleHelper.gray} "${this.ɗf(a.path)}"${helpersLib.ConsoleHelper.default}`)):(s++,console.info(`${helpersLib.ConsoleHelper.cyan}Creating file:${helpersLib.ConsoleHelper.gray} "${this.ɗf(a.path)}"${helpersLib.ConsoleHelper.default}`)),S__namespace.writeFileSync(a.path,a.content));}),this.ɗbn(e),s+o+r>0&&helpersLib.ConsoleHelper.newLine(),helpersLib.ConsoleHelper.log(`Created file count: ${s}`,"gray"),helpersLib.ConsoleHelper.log(`Modified file count: ${o}`,"gray"),helpersLib.ConsoleHelper.log(`Erased file count: ${r}`,"gray"),helpersLib.ConsoleHelper.log(mt,"gray"),l.successful?helpersLib.ConsoleHelper.log("Compilation is completed successfuly!","green"):helpersLib.ConsoleHelper.log("Compilation encountered errors!","red");}static ɗf(t){let e=l.compilerExecutionPath.length;return t.substring(e)}static ɗbn(t){let e=S__namespace.readdirSync(t),i=true;for(let r of e){let o=dt__namespace.join(t,r);S__namespace.statSync(o).isDirectory()&&this.ɗbn(o)?(S__namespace.rmdirSync(o),console.info(`${helpersLib.ConsoleHelper.red}Erasing folder:${helpersLib.ConsoleHelper.gray} "${o.substring(t.length).replace(/\\/g,"/")}"${helpersLib.ConsoleHelper.default}`)):i=false;}return i}static async ɗah(t,e,i){lt.process(),l.flushErrorLogs();let r=t.map(o=>{let s=o.$meta;l.componentInProgressData={meta:s,idToReferencesMap:new Map};let a={addFile:c=>l.addFile(c),addError:c=>l.addErrorLog(c),convertLocationInFileToLink:c=>Mt(c)};this.ɗaz(s.keyName,s.componentName,o);let p;if(s.singleton){let c=R.validateAndConvertSingular(s.componentName,s.validationSchema);c&&(p=c.definition,m.ɗby(o,c.definition,c.rawDefinition),m.ɗca(o,p));}else {let c=R.validateAndConvert(s.componentName,s.validationSchema);if(l.componentInProgressData.idToReferencesMap.size>0){let d=s.keyName;if(!d)throw new Error("Unexpected Error: KeyName should be defined for lazy references.");let P=l.componentInProgressData.idToReferencesMap,U=true;for(;U;){let Wt=c.length,Kt=new Set(c.map(Ct=>Ct.definition[d]));c=c.filter(Ct=>{let Ot=Ct.definition[d];if(P.has(Ot)){let Zt=P.get(Ot),Vt=true;return Zt.forEach(Qt=>Kt.has(Qt)||(Vt=false)),Vt}return true}),U=Wt!==c.length;}}c.forEach(d=>{m.ɗby(o,d.definition,d.rawDefinition);}),p=c.map(d=>d.definition),this.ɗbm(p,s.keyName,o);}return l.flushErrorLogs(),l.componentInProgressData=void 0,{definitionToProcess:p,output:a,moduleClass:o}});for(let o of r)if(o.definitionToProcess){let s=new o.moduleClass,a=o.moduleClass.$meta.keyName;a&&j.addIdType(o.moduleClass.$meta.pascalCaseComponentName,o.definitionToProcess.map(p=>p[a])),await s.process(o.definitionToProcess,o.output);}return l.flushErrorLogs(),C.logDuplicates(),l.successful&&await j.generateFile(e,i),this.ɗao()}static ɗaz(t,e,i){let r=R.getRawDefinitions(e);t&&r.forEach(o=>{let s=o.parsedStructure.rawData;if(!helpersLib.Comparator.isObject(s)||helpersLib.Comparator.isArray(s))l.addErrorLog({description:`KeyName shold not be used with a content which is not an object, keyName: "${t}" in "${e}"`,location:{line:o.parsedStructure.line,path:o.location.path}});else {let a=s[t]?.rawData;helpersLib.Comparator.isString(a)&&(he.test(a)===false?l.addErrorLog({description:`KeyValue should be a valid key, keyValue: "${a}"`,location:{line:s[t].line,path:o.location.path}}):m.ɗax(i,a)?l.addErrorLog({description:`Definition with key "${a}" already exists`,location:{line:s[t].line,path:o.location.path}}):m.ɗbz(i,a,o));}});}static ɗbm(t,e,i){e&&t.forEach(r=>{let o=r[e];m.ɗbx(i,o,r);});}static ɗao(){return l.successful?l.output:(helpersLib.ConsoleHelper.newLine(),helpersLib.ConsoleHelper.log("ERROR LOGS:","red"),helpersLib.ConsoleHelper.log(mt,"gray"),l.errorLogs.forEach((t,e)=>{e>0&&helpersLib.ConsoleHelper.log(ge,"gray"),helpersLib.ConsoleHelper.log("Error:","red"),console.info(`${helpersLib.ConsoleHelper.white}Details:${helpersLib.ConsoleHelper.green} ${t.description}`),console.info(`${helpersLib.ConsoleHelper.white}Location:${helpersLib.ConsoleHelper.green} ${Mt(t.location)}`);}),helpersLib.ConsoleHelper.log(mt,"gray"),[{path:"/error-logs.md",content:l.errorLogs.map(t=>`${t.description}\r
32
+ `),t}};var he=/^[a-z]+([a-zA-Z0-9]+)*$/,mt="======================================================",ge="------------------------------------------------------",Mt=n=>n.path.replace(l.compilerExecutionPath+"/","")+":"+n.line,ft=class{static async process(t,e,i){let r=new Map;r.set(nt,k),t.forEach(s=>{let a=s.$meta.componentName;if(r.has(a))throw new Error(`Component name "${a}" is used more than once.`);r.set(a,s);}),m.ɗbw(r),helpersLib.ConsoleHelper.log("Compilation is in progress.","white"),this.ɗbk();let o=await this.ɗah(t,e,i);this.ɗcf(o,l.outputPath);}static ɗbk(){l.compilerExecutionPath=dt__namespace.resolve("./").replace(/\\/g,"/"),l.outputPath=`${l.compilerExecutionPath}/.asset-build`,l.files=Lt__namespace.sync(`${l.compilerExecutionPath}/**/*.md`).map(t=>t.replace(/\\/g,"/")).map(t=>{let e=S__namespace.readFileSync(t).toString();return {path:t,content:e}});}static ɗcf(t,e){let i=new Set;Lt__namespace.sync(`${l.outputPath}/**/*`,{nodir:true}).map(a=>a.replace(/\\/g,"/")).forEach(a=>{i.add(a);}),t.forEach(a=>{a.path=e+a.path,i.delete(a.path);}),l.successful&&(helpersLib.ConsoleHelper.log(mt,"gray"),helpersLib.ConsoleHelper.log("Changes:","gray"),helpersLib.ConsoleHelper.newLine());let r=0;l.successful&&i.forEach(a=>{r++,console.info(`${helpersLib.ConsoleHelper.red}Erasing file:${helpersLib.ConsoleHelper.gray} "${this.ɗf(a)}"${helpersLib.ConsoleHelper.default}`),S__namespace.unlinkSync(a);});let o=0,s=0;t.forEach(a=>{let p=a.path.substring(0,a.path.lastIndexOf("/"));S__namespace.mkdirSync(p,{recursive:true});let c=S__namespace.existsSync(a.path);(c?S__namespace.readFileSync(a.path).toString():"")!==a.content&&(c?(o++,console.info(`${helpersLib.ConsoleHelper.blue}Modifying file:${helpersLib.ConsoleHelper.gray} "${this.ɗf(a.path)}"${helpersLib.ConsoleHelper.default}`)):(s++,console.info(`${helpersLib.ConsoleHelper.cyan}Creating file:${helpersLib.ConsoleHelper.gray} "${this.ɗf(a.path)}"${helpersLib.ConsoleHelper.default}`)),S__namespace.writeFileSync(a.path,a.content));}),this.ɗbn(e),s+o+r>0&&helpersLib.ConsoleHelper.newLine(),helpersLib.ConsoleHelper.log(`Created file count: ${s}`,"gray"),helpersLib.ConsoleHelper.log(`Modified file count: ${o}`,"gray"),helpersLib.ConsoleHelper.log(`Erased file count: ${r}`,"gray"),helpersLib.ConsoleHelper.log(mt,"gray"),l.successful?helpersLib.ConsoleHelper.log("Compilation is completed successfuly!","green"):helpersLib.ConsoleHelper.log("Compilation encountered errors!","red");}static ɗf(t){let e=l.compilerExecutionPath.length;return t.substring(e)}static ɗbn(t){let e=S__namespace.readdirSync(t),i=true;for(let r of e){let o=dt__namespace.join(t,r);S__namespace.statSync(o).isDirectory()&&this.ɗbn(o)?(S__namespace.rmdirSync(o),console.info(`${helpersLib.ConsoleHelper.red}Erasing folder:${helpersLib.ConsoleHelper.gray} "${o.substring(t.length).replace(/\\/g,"/")}"${helpersLib.ConsoleHelper.default}`)):i=false;}return i}static async ɗah(t,e,i){lt.process(),l.flushErrorLogs();let r=t.map(o=>{let s=o.$meta;l.componentInProgressData={meta:s,idToReferencesMap:new Map};let a={addFile:c=>l.addFile(c),addError:c=>l.addErrorLog(c),convertLocationInFileToLink:c=>Mt(c)};this.ɗaz(s.keyName,s.componentName,o);let p;if(s.singleton){let c=R.validateAndConvertSingular(s.componentName,s.validationSchema);c&&(p=c.definition,m.ɗby(o,c.definition,c.rawDefinition),m.ɗca(o,p));}else {let c=R.validateAndConvert(s.componentName,s.validationSchema);if(l.componentInProgressData.idToReferencesMap.size>0){let d=s.keyName;if(!d)throw new Error("Unexpected Error: KeyName should be defined for lazy references.");let P=l.componentInProgressData.idToReferencesMap,U=true;for(;U;){let Wt=c.length,Kt=new Set(c.map(Ct=>Ct.definition[d]));c=c.filter(Ct=>{let Ot=Ct.definition[d];if(P.has(Ot)){let Zt=P.get(Ot),Vt=true;return Zt.forEach(Qt=>Kt.has(Qt)||(Vt=false)),Vt}return true}),U=Wt!==c.length;}}c.forEach(d=>{m.ɗby(o,d.definition,d.rawDefinition);}),p=c.map(d=>d.definition),this.ɗbm(p,s.keyName,o);}return l.flushErrorLogs(),l.componentInProgressData=void 0,{definitionToProcess:p,output:a,moduleClass:o}});for(let o of r)if(o.definitionToProcess){let s=new o.moduleClass,a=o.moduleClass.$meta.keyName;a&&j.addIdType(o.moduleClass.$meta.pascalCaseComponentName,o.definitionToProcess.map(p=>p[a])),await s.process(o.definitionToProcess,o.output);}return l.flushErrorLogs(),C.logDuplicates(),l.successful&&await j.generateFile(e,i),this.ɗao()}static ɗaz(t,e,i){let r=R.getRawDefinitions(e);t&&r.forEach(o=>{let s=o.parsedStructure.rawData;if(!helpersLib.Comparator.isObject(s)||helpersLib.Comparator.isArray(s))l.addErrorLog({description:`KeyName shold not be used with a content which is not an object, keyName: "${t}" in "${e}"`,location:{line:o.parsedStructure.line,path:o.location.path}});else {let a=s[t]?.rawData;helpersLib.Comparator.isString(a)&&(he.test(a)===false?l.addErrorLog({description:`KeyValue should be a valid key, keyValue: "${a}"`,location:{line:s[t].line,path:o.location.path}}):m.ɗax(i,a)?l.addErrorLog({description:`Definition with key "${a}" already exists`,location:{line:s[t].line,path:o.location.path}}):m.ɗbz(i,a,o));}});}static ɗbm(t,e,i){e&&t.forEach(r=>{let o=r[e];m.ɗbx(i,o,r);});}static ɗao(){return l.successful?l.output:(helpersLib.ConsoleHelper.newLine(),helpersLib.ConsoleHelper.log("ERROR LOGS:","red"),helpersLib.ConsoleHelper.log(mt,"gray"),l.errorLogs.forEach((t,e)=>{e>0&&helpersLib.ConsoleHelper.log(ge,"gray"),helpersLib.ConsoleHelper.log("Error:","red"),console.info(`${helpersLib.ConsoleHelper.white}Details:${helpersLib.ConsoleHelper.green} ${t.description}`),console.info(`${helpersLib.ConsoleHelper.white}Location:${helpersLib.ConsoleHelper.green} ${Mt(t.location)}`);}),helpersLib.ConsoleHelper.log(mt,"gray"),[{path:"/error-logs.md",content:l.errorLogs.map(t=>`${t.description}\r
33
33
  Path: '${t.location.path}', Line: '${t.location.line}'\r
34
34
  `).join(`\r
35
35
  `)}])}};var $t=class{constructor(t,e,i){h.setup(t,e,i);}setScriptInput(t,e){h.setScriptInput(t,e);}setEventInput(t,e){h.setEventInput(t,e);}addCustomScriptTestCase(t,e,i){h.addCustomScriptTestCase(e,i,t);}addCustomEventTestCase(t,e,i){h.addCustomEventTestCase(e,i,t);}},h=class{static{this.ɗbr=new Map;}static{this.ɗw=new Map;}static{this.ɗbt=new Map;}static{this.ɗy=new Map;}static get scriptSimulatorFunctionsConstructor(){if(!this.ɗbs)throw new Error("ScriptSimulatorFunctionsConstructor is not set");return this.ɗbs}static get eventSimulatorFunctionsConstructor(){if(!this.ɗx)throw new Error("ScriptSimulatorFunctionsConstructor is not set");return this.ɗx}static get richTextTags(){return this.ɗbp}static get isInitialized(){return this.ɗbs&&this.ɗx&&this.ɗbp!==void 0}static setup(t,e,i){this.ɗbs=t,this.ɗx=e,this.ɗbp=i;}static getScriptInput(t){return this.ɗbr.get(t)}static getEventInput(t){return this.ɗw.get(t)}static getCustomScriptTestCases(){return Array.from(this.ɗbt.values())}static getCustomEventTestCases(){return Array.from(this.ɗy.values())}static isCustomScriptTestCase(t){return this.ɗbt.has(t.script)}static isCustomEventTestCase(t){return this.ɗy.has(t.script)}static setScriptInput(t,e){if(this.ɗbr.has(t))throw new Error(`Script input for ${t} already set`);this.ɗbr.set(t,e);}static setEventInput(t,e){if(this.ɗw.has(t))throw new Error(`Event input for ${t} already set`);this.ɗw.set(t,e);}static addCustomScriptTestCase(t,e,i){let r={testDefinition:{script:t,setup:[],cases:[e]},customMessage:`Prebuild Test Case:
@@ -40,8 +40,8 @@ ${i}`};this.ɗy.set(t,r);}};var ut=()=>u__default.default.string().custom(n=>({t
40
40
 
41
41
  `,a=t.message.indexOf(`
42
42
  `,t.message.indexOf("Execution history"))+1,p=t.message.slice(0,a)+s+t.message.slice(a);return {description:e.customMessage?e.customMessage+`
43
- `+p:p,location:this.ɗba.getLocationOfDefinition(t.location.scriptId,t.location.path)}}else throw t}};var Ee=u__default.default.string().custom(n=>({type:"command",value:n})),Le=u__default.default.object().keys({runScript:u__default.default.string().reference(exports.ScriptComponent).required()}).custom(n=>({type:"runScript",value:n.runScript})),qt=()=>u__default.default.array().items(u__default.default.alternatives().conditional(u__default.default.string(),{then:Ee}).conditional(u__default.default.object({runScript:u__default.default.exist()}).unknown(),{then:Le}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, runScript";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).min(1);exports.ScriptTestComponent=class F extends g{async process(t,e){let i=m.getDefinitions(exports.ScriptComponent),r=new M(i,h.scriptSimulatorFunctionsConstructor,this.ɗan()),o=t.map(c=>({cases:c.cases,setup:c.setup,script:m.getDefinitionOrFail(exports.ScriptComponent,c.script),scriptInput:h.getScriptInput(c.script),testDefinitionRef:c})),s=h.getCustomScriptTestCases().map(c=>({cases:c.testDefinition.cases,setup:[],script:m.getDefinitionOrFail(exports.ScriptComponent,c.testDefinition.script),scriptInput:h.getScriptInput(c.testDefinition.script),testDefinitionRef:c.testDefinition,customMessage:c.customMessage})),a=o.concat(s),p=r.runTests(a,e);r.printErrors(p,e);}ɗan(){return {getLocationOfDefinition:(t,e)=>m.getLocationInFileById(exports.ScriptComponent,t,e),getLocationOfTestDefinition:(t,e)=>{if(h.isCustomScriptTestCase(t)){let i=`Internal error: custom script test case is failing. Definition: ${JSON.stringify(t)}, Path: ${JSON.stringify(e)}`;throw new Error(i)}else return m.getLocationInFile(exports.ScriptTestComponent,t,e)}}}};exports.ScriptTestComponent=w([T({componentName:"SCRIPT-TEST",validationSchema:u__default.default.object().keys({script:u__default.default.string().reference(exports.ScriptComponent).required(),setup:qt().default([]).optional(),cases:u__default.default.array().items(u__default.default.object().keys({actionsBeforeTesting:qt().default([]).optional()}).required()).required()}).required()})],exports.ScriptTestComponent);var Pe=u__default.default.object().keys({jumpTo:u__default.default.string().lazyReference("EVENT").required()}).custom(n=>({type:"jumpTo",value:n.jumpTo})),yt="EventActionsSchema",Ie=()=>u__default.default.array().items(u__default.default.alternatives().conditional(u__default.default.string(),{then:ut()}).conditional(u__default.default.object({jumpTo:u__default.default.exist()}).unknown(),{then:Pe}).conditional(u__default.default.object({branchByChance:u__default.default.exist()}).unknown(),{then:gt(yt)}).conditional(u__default.default.object({branchByCondition:u__default.default.exist()}).unknown(),{then:ht(yt)}).conditional(u__default.default.object({branchByPlayerChoice:u__default.default.exist()}).unknown(),{then:Bt(yt)}).conditional(u__default.default.object().min(1).max(1).unknown(),{then:Ht()}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, jumpTo, branchByCondition, branchByPlayerChoice, branchByChance";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).id(yt);exports.EventComponent=class x extends g{async process(t,e){await e.addFile({path:"/_premade/script-engine-definitions/events.ts",preText:'import { ScriptDefinition } from "script-engine-lib";',variableName:"EventDefinitions",variableType:"Readonly<Record<string, ScriptDefinition>>",variable:helpersLib.JsonHelper.arrayToObject(t,"id")});}};exports.EventComponent=w([T({componentName:"EVENT",keyName:"id",validationSchema:u__default.default.object().keys({id:u__default.default.string().unique(It).required(),actions:Ie().default([]).optional()}).required()})],exports.EventComponent);var Re=u__default.default.string().custom(n=>({type:"command",value:n})),Fe=u__default.default.object().keys({runEvent:u__default.default.string().reference(exports.EventComponent).required()}).custom(n=>({type:"runScript",value:n.runEvent})),zt=()=>u__default.default.array().items(u__default.default.alternatives().conditional(u__default.default.string(),{then:Re}).conditional(u__default.default.object({runEvent:u__default.default.exist()}).unknown(),{then:Fe}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, runEvent";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).min(1);exports.EventTestComponent=class O extends g{async process(t,e){let i=m.getDefinitions(exports.EventComponent),r=new M(i,h.eventSimulatorFunctionsConstructor,this.ɗan()),o=r.runTests(t.map(s=>({cases:s.cases,setup:s.setup,script:m.getDefinitionOrFail(exports.EventComponent,s.script),scriptInput:h.getEventInput(s.script),testDefinitionRef:s})),e);r.printErrors(o,e);}ɗan(){return {getLocationOfDefinition:(t,e)=>m.getLocationInFileById(exports.EventComponent,t,e),getLocationOfTestDefinition:(t,e)=>m.getLocationInFile(exports.EventTestComponent,t,e)}}};exports.EventTestComponent=w([T({componentName:"EVENT-TEST",validationSchema:u__default.default.object().keys({event:u__default.default.string().reference(exports.EventComponent).required(),setup:zt().default([]).optional(),cases:u__default.default.array().items(u__default.default.object().keys({actionsBeforeTesting:zt().default([]).optional()}).required()).required()}).required().custom(n=>({...n,script:n.event}))})],exports.EventTestComponent);var _t=false;function Oe(n){return function(t){if(_t)console.error("There can be only one definition generator!");else {_t=true;let e=[...n.modules];h.isInitialized&&(e=[exports.ScriptComponent,exports.EventComponent,...e,exports.ScriptTestComponent,exports.EventTestComponent]),ft.process(e,n.indexFilePretext,n.outputIndexFile);}}}var Rt=class{};var Ft=()=>u__default.default.array().items(u__default.default.array().items(Ut().required()).min(3).required()).min(1),Ut=()=>u__default.default.object().keys({x:u__default.default.number().required(),y:u__default.default.number().required()}),je=()=>u__default.default.string().pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/).custom(n=>helpersLib.ColorHelper.stringColorToRGBColor(n)),ke=()=>u__default.default.number().min(-Math.PI).max(Math.PI),Je=(n,t)=>u__default.default.array().items(n).max(t).custom(e=>{if(e.length>t)throw new Error(`Array exceeds maximum size of ${t}`);for(;e.length<t;)e.push(void 0);return e}).default(helpersLib.ArrayHelper.createEmptyArray(t)).optional();exports.SpriteComponent=class $ extends g{async process(t,e){await e.addFile({path:"/_premade/assets/sprites.ts",preText:"import { AssetDefinition } from 'bard-legends-framework';",variableName:"SpriteAssets",variableType:"readonly AssetDefinition[]",assetUrl:"url",variable:t.map(i=>({id:i.id,url:i.url.url}))}),await e.addFile({path:"/_premade/asset-definitions/sprites.ts",preText:'import { SpriteDefinition } from "bard-legends-framework";',variableName:"SpriteDefinitions",variableType:"Readonly<Record<string, SpriteDefinition>>",variable:helpersLib.JsonHelper.arrayToObject(t,"id",{transformFunction:i=>({id:i.id,size:i.url.size,scale:i.scale,anchor:i.anchor,boundingShapes:i.boundingShapes})})});}};exports.SpriteComponent=w([T({componentName:"SPRITE",keyName:"id",validationSchema:u__default.default.object().keys({id:u__default.default.string().required(),url:u__default.default.string().sprite().required(),scale:u__default.default.number().min(.1).max(1).default(1).optional(),anchor:u__default.default.object().keys({x:u__default.default.number().min(0).max(1).required(),y:u__default.default.number().min(0).max(1).required()}).default({x:.5,y:.5}).optional(),boundingShapes:Ft().optional()}).positionOnSprite({selectSpriteDefinition:n=>n,positionsJsonPath:["$..boundingShapes[*][*]"],includeRotationFromAnchor:false}).required()})],exports.SpriteComponent);var Ae=()=>u__default.default.string().reference(exports.SpriteComponent).custom(n=>{let t=m.getDefinitionOrFail(exports.SpriteComponent,n);if(t.url.size.x%4!==0)throw new Error(`Sprite width must be multiplier of four in order to keep the pixel perfection. Got: '${t.url.size.x}'`);if(t.url.size.y%4!==0)throw new Error(`Sprite height must be multiplier of four in order to keep the pixel perfection. Got: '${t.url.size.y}'`);return n}),Be=n=>u__default.default.string().reference(exports.SpriteComponent).custom(t=>{let e=m.getDefinitionOrFail(exports.SpriteComponent,t);if(n?.size){if(e.url.size.x!==n.size.x)throw new Error(`Sprite width must be '${n.size.x}px'. Got: '${e.url.size.x}'`);if(e.url.size.y!==n.size.y)throw new Error(`Sprite height must be '${n.size.y}px'. Got: '${e.url.size.y}'`)}if(n?.scale&&e.scale!==n.scale)throw new Error(`Sprite '${t}' scale must be '${n.scale}'. Got: '${e.scale}'`);return t});exports.SpriteGroupComponent=class z extends g{async process(t,e){await e.addFile({path:"/_premade/asset-definitions/sprite-groups.ts",preText:"",variableName:"SpriteGroupDefinitions",variableType:"Readonly<Record<string, readonly string[]>>",variable:helpersLib.JsonHelper.arrayToObject(t,"id",{transformFunction:i=>i.group})});}};exports.SpriteGroupComponent=w([T({componentName:"SPRITE-GROUP",keyName:"id",validationSchema:u__default.default.object().keys({id:u__default.default.string().required(),group:u__default.default.array().items(u__default.default.string().reference(exports.SpriteComponent)).unique().required()}).required()})],exports.SpriteGroupComponent);var ze=`
43
+ `+p:p,location:this.ɗba.getLocationOfDefinition(t.location.scriptId,t.location.path)}}else throw t}};var Ee=u__default.default.string().custom(n=>({type:"command",value:n})),Le=u__default.default.object().keys({runScript:u__default.default.string().reference(exports.ScriptComponent).required()}).custom(n=>({type:"runScript",value:n.runScript})),qt=()=>u__default.default.array().items(u__default.default.alternatives().conditional(u__default.default.string(),{then:Ee}).conditional(u__default.default.object({runScript:u__default.default.exist()}).unknown(),{then:Le}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, runScript";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).min(1);exports.ScriptTestComponent=class F extends g{async process(t,e){let i=m.getDefinitions(exports.ScriptComponent),r=new M(i,h.scriptSimulatorFunctionsConstructor,this.ɗan()),o=t.map(c=>({cases:c.cases,setup:c.setup,script:m.getDefinitionOrFail(exports.ScriptComponent,c.script),scriptInput:h.getScriptInput(c.script),testDefinitionRef:c})),s=h.getCustomScriptTestCases().map(c=>({cases:c.testDefinition.cases,setup:[],script:m.getDefinitionOrFail(exports.ScriptComponent,c.testDefinition.script),scriptInput:h.getScriptInput(c.testDefinition.script),testDefinitionRef:c.testDefinition,customMessage:c.customMessage})),a=o.concat(s),p=r.runTests(a,e);r.printErrors(p,e);}ɗan(){return {getLocationOfDefinition:(t,e)=>m.getLocationInFileById(exports.ScriptComponent,t,e),getLocationOfTestDefinition:(t,e)=>{if(h.isCustomScriptTestCase(t)){let i=`Internal error: custom script test case is failing. Definition: ${JSON.stringify(t)}, Path: ${JSON.stringify(e)}`;throw new Error(i)}else return m.getLocationInFile(exports.ScriptTestComponent,t,e)}}}};exports.ScriptTestComponent=w([T({componentName:"SCRIPT-TEST",validationSchema:u__default.default.object().keys({script:u__default.default.string().reference(exports.ScriptComponent).required(),setup:qt().default([]).optional(),cases:u__default.default.array().items(u__default.default.object().keys({actionsBeforeTesting:qt().default([]).optional()}).required()).required()}).required()})],exports.ScriptTestComponent);var Pe=u__default.default.object().keys({jumpTo:u__default.default.string().lazyReference("EVENT").required()}).custom(n=>({type:"jumpTo",value:n.jumpTo})),yt="EventActionsSchema",Ie=()=>u__default.default.array().items(u__default.default.alternatives().conditional(u__default.default.string(),{then:ut()}).conditional(u__default.default.object({jumpTo:u__default.default.exist()}).unknown(),{then:Pe}).conditional(u__default.default.object({branchByChance:u__default.default.exist()}).unknown(),{then:gt(yt)}).conditional(u__default.default.object({branchByCondition:u__default.default.exist()}).unknown(),{then:ht(yt)}).conditional(u__default.default.object({branchByPlayerChoice:u__default.default.exist()}).unknown(),{then:Bt(yt)}).conditional(u__default.default.object().min(1).max(1).unknown(),{then:Ht()}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, jumpTo, branchByCondition, branchByPlayerChoice, branchByChance";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).id(yt);exports.EventComponent=class x extends g{async process(t,e){await e.addFile({path:"/_premade/script-engine-definitions/events.ts",preText:'import { ScriptDefinition } from "script-engine-lib";',variableName:"EventDefinitions",variableType:"Readonly<Record<string, ScriptDefinition>>",variable:helpersLib.JsonHelper.arrayToObject(t,"id")});}};exports.EventComponent=w([T({componentName:"EVENT",keyName:"id",validationSchema:u__default.default.object().keys({id:u__default.default.string().unique(It).required(),actions:Ie().default([]).optional()}).required()})],exports.EventComponent);var Re=u__default.default.string().custom(n=>({type:"command",value:n})),Fe=u__default.default.object().keys({runEvent:u__default.default.string().reference(exports.EventComponent).required()}).custom(n=>({type:"runScript",value:n.runEvent})),zt=()=>u__default.default.array().items(u__default.default.alternatives().conditional(u__default.default.string(),{then:Re}).conditional(u__default.default.object({runEvent:u__default.default.exist()}).unknown(),{then:Fe}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, runEvent";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).min(1);exports.EventTestComponent=class O extends g{async process(t,e){let i=m.getDefinitions(exports.EventComponent),r=new M(i,h.eventSimulatorFunctionsConstructor,this.ɗan()),o=r.runTests(t.map(s=>({cases:s.cases,setup:s.setup,script:m.getDefinitionOrFail(exports.EventComponent,s.script),scriptInput:h.getEventInput(s.script),testDefinitionRef:s})),e);r.printErrors(o,e);}ɗan(){return {getLocationOfDefinition:(t,e)=>m.getLocationInFileById(exports.EventComponent,t,e),getLocationOfTestDefinition:(t,e)=>m.getLocationInFile(exports.EventTestComponent,t,e)}}};exports.EventTestComponent=w([T({componentName:"EVENT-TEST",validationSchema:u__default.default.object().keys({event:u__default.default.string().reference(exports.EventComponent).required(),setup:zt().default([]).optional(),cases:u__default.default.array().items(u__default.default.object().keys({actionsBeforeTesting:zt().default([]).optional()}).required()).required()}).required().custom(n=>({...n,script:n.event}))})],exports.EventTestComponent);var _t=false;function Oe(n){return function(t){if(_t)console.error("There can be only one definition generator!");else {_t=true;let e=[...n.modules];h.isInitialized&&(e=[exports.ScriptComponent,exports.EventComponent,...e,exports.ScriptTestComponent,exports.EventTestComponent]),ft.process(e,n.indexFilePretext,n.outputIndexFile);}}}var Rt=class{};var Ft=()=>u__default.default.array().items(u__default.default.array().items(Ut().required()).min(3).required()).min(1),Ut=()=>u__default.default.object().keys({x:u__default.default.number().required(),y:u__default.default.number().required()}),je=()=>u__default.default.string().pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/).custom(n=>helpersLib.ColorHelper.stringColorToRGBColor(n)),Je=()=>u__default.default.number().min(-Math.PI).max(Math.PI),ke=(n,t)=>u__default.default.array().items(n).max(t).custom(e=>{if(e.length>t)throw new Error(`Array exceeds maximum size of ${t}`);for(;e.length<t;)e.push(void 0);return e}).default(helpersLib.ArrayHelper.createEmptyArray(t)).optional();exports.SpriteComponent=class $ extends g{async process(t,e){await e.addFile({path:"/_premade/assets/sprites.ts",preText:"import { AssetDefinition } from 'bard-legends-framework';",variableName:"SpriteAssets",variableType:"readonly AssetDefinition[]",assetUrl:"url",variable:t.map(i=>({id:i.id,url:i.url.url}))}),await e.addFile({path:"/_premade/asset-definitions/sprites.ts",preText:'import { SpriteDefinition } from "bard-legends-framework";',variableName:"SpriteDefinitions",variableType:"Readonly<Record<string, SpriteDefinition>>",variable:helpersLib.JsonHelper.arrayToObject(t,"id",{transformFunction:i=>({id:i.id,size:i.url.size,scale:i.scale,anchor:i.anchor,boundingShapes:i.boundingShapes})})});}};exports.SpriteComponent=w([T({componentName:"SPRITE",keyName:"id",validationSchema:u__default.default.object().keys({id:u__default.default.string().required(),url:u__default.default.string().sprite().required(),scale:u__default.default.number().min(.1).max(1).default(1).optional(),anchor:u__default.default.object().keys({x:u__default.default.number().min(0).max(1).required(),y:u__default.default.number().min(0).max(1).required()}).default({x:.5,y:.5}).optional(),boundingShapes:Ft().optional()}).positionOnSprite({selectSpriteDefinition:n=>n,positionsJsonPath:["$..boundingShapes[*][*]"],includeRotationFromAnchor:false}).required()})],exports.SpriteComponent);var Ae=()=>u__default.default.string().reference(exports.SpriteComponent).custom(n=>{let t=m.getDefinitionOrFail(exports.SpriteComponent,n);if(t.url.size.x%4!==0)throw new Error(`Sprite width must be multiplier of four in order to keep the pixel perfection. Got: '${t.url.size.x}'`);if(t.url.size.y%4!==0)throw new Error(`Sprite height must be multiplier of four in order to keep the pixel perfection. Got: '${t.url.size.y}'`);return n}),Be=n=>u__default.default.string().reference(exports.SpriteComponent).custom(t=>{let e=m.getDefinitionOrFail(exports.SpriteComponent,t);if(n?.size){if(e.url.size.x!==n.size.x)throw new Error(`Sprite width must be '${n.size.x}px'. Got: '${e.url.size.x}'`);if(e.url.size.y!==n.size.y)throw new Error(`Sprite height must be '${n.size.y}px'. Got: '${e.url.size.y}'`)}if(n?.scale&&e.scale!==n.scale)throw new Error(`Sprite '${t}' scale must be '${n.scale}'. Got: '${e.scale}'`);return t});exports.SpriteGroupComponent=class z extends g{async process(t,e){await e.addFile({path:"/_premade/asset-definitions/sprite-groups.ts",preText:"",variableName:"SpriteGroupDefinitions",variableType:"Readonly<Record<string, readonly string[]>>",variable:helpersLib.JsonHelper.arrayToObject(t,"id",{transformFunction:i=>i.group})});}};exports.SpriteGroupComponent=w([T({componentName:"SPRITE-GROUP",keyName:"id",validationSchema:u__default.default.object().keys({id:u__default.default.string().required(),group:u__default.default.array().items(u__default.default.string().reference(exports.SpriteComponent)).unique().required()}).required()})],exports.SpriteGroupComponent);var ze=`
44
44
  export interface FontDefinition {
45
45
  readonly id: string;
46
46
  readonly fontFamily: string;
47
- }`;exports.FontComponent=class _ extends g{constructor(){super(),j.addPremadeInterface(ze);}async process(t,e){await e.addFile({path:"/_premade/assets/fonts.ts",preText:"import { AssetDefinition } from 'bard-legends-framework';",variableName:"FontAssets",variableType:"readonly AssetDefinition[]",assetUrl:"url",variable:t.map(i=>({id:i.id,url:i.url}))}),await e.addFile({path:"/_premade/asset-definitions/fonts.ts",preText:'import { FontDefinition } from "../../";',variableName:"FontDefinitions",variableType:"Readonly<Record<string, FontDefinition>>",variable:helpersLib.JsonHelper.arrayToObject(t,"id",{transformFunction:i=>({id:i.id,fontFamily:i.fontFamily})})});}};exports.FontComponent=w([T({componentName:"FONT",keyName:"id",validationSchema:u__default.default.object().keys({id:u__default.default.string().required(),fontFamily:u__default.default.string().required(),url:u__default.default.string().path().required()}).required()})],exports.FontComponent);exports.DefinitionComponent=g;exports.DefinitionComponentDecorator=T;exports.DefinitionGenerator=Rt;exports.DefinitionGeneratorDecorator=Oe;exports.DefinitionStore=m;exports.FixedArraySchema=Je;exports.HexColorSchema=je;exports.JoiCustomValidators=H;exports.PixelPerfectSpriteSchema=Ae;exports.PoligonSchema=Ft;exports.RichTextSchema=ye;exports.RotationSchema=ke;exports.ScriptTesting=$t;exports.SingleDefinitionComponent=rt;exports.SpriteSchema=Be;exports.Validator=R;exports.Vec2Schema=Ut;
47
+ }`;exports.FontComponent=class _ extends g{constructor(){super(),j.addPremadeInterface(ze);}async process(t,e){await e.addFile({path:"/_premade/assets/fonts.ts",preText:"import { AssetDefinition } from 'bard-legends-framework';",variableName:"FontAssets",variableType:"readonly AssetDefinition[]",assetUrl:"url",variable:t.map(i=>({id:i.id,url:i.url}))}),await e.addFile({path:"/_premade/asset-definitions/fonts.ts",preText:'import { FontDefinition } from "../../";',variableName:"FontDefinitions",variableType:"Readonly<Record<string, FontDefinition>>",variable:helpersLib.JsonHelper.arrayToObject(t,"id",{transformFunction:i=>({id:i.id,fontFamily:i.fontFamily})})});}};exports.FontComponent=w([T({componentName:"FONT",keyName:"id",validationSchema:u__default.default.object().keys({id:u__default.default.string().required(),fontFamily:u__default.default.string().required(),url:u__default.default.string().path().required()}).required()})],exports.FontComponent);exports.DefinitionComponent=g;exports.DefinitionComponentDecorator=T;exports.DefinitionGenerator=Rt;exports.DefinitionGeneratorDecorator=Oe;exports.DefinitionStore=m;exports.FixedArraySchema=ke;exports.HexColorSchema=je;exports.JoiCustomValidators=H;exports.PixelPerfectSpriteSchema=Ae;exports.PoligonSchema=Ft;exports.RichTextSchema=ye;exports.RotationSchema=Je;exports.ScriptTesting=$t;exports.SingleDefinitionComponent=rt;exports.SpriteSchema=Be;exports.Validator=R;exports.Vec2Schema=Ut;
package/dist/index.mjs CHANGED
@@ -2,15 +2,15 @@ import*as S from'fs';import S__default from'fs';import u from'joi';import {JsonH
2
2
 
3
3
  `);let i;if(t.assetUrl){if(!t.filePath)throw new Error("filePath is required when using assetUrl");if(!Comparator.isArray(t.variable))throw new Error("variable should be an array when using assetUrl");let{assetImports:r,replaceMap:o}=this.ɗi(t.variable,t.assetUrl,t.filePath);e+=r+`
4
4
 
5
- `,i=o;}return t.variableType?e+=`export const ${t.variableName}: ${t.variableType} = ${this.ɗcb(t.variable)}`:e+=`export const ${t.variableName} = ${this.ɗcb(t.variable)}`,i&&(e=this.ɗbo(e,i)),t.replaceMap&&(e=this.ɗbo(e,t.replaceMap)),this.format(e)}static async format(t){return format(t,{parser:"typescript",trailingComma:"none",tabWidth:2,printWidth:130,singleQuote:true,arrowParens:"avoid",plugins:[ne,re]})}static ɗj(t,e){let i=l.outputPath+t.substring(0,t.lastIndexOf("/")),r=l.config.projectRoot+e.substring(1);return dt__default.relative(i,r).replace(/\\/g,"/")}static ɗbo(t,e){return e.forEach(i=>{t=t.replace(new RegExp(i.target,"g"),i.replace);}),t}static ɗi(t,e,i){let r=t.map(p=>{let c=JsonHelper.deepFind(p,e);if(!c)throw new Error(`OutputHelperClass: Asset url is not found in the given variable! item: "${JSON.stringify(p)}", assetUrl: "${e}"`);return c}),o=new Map;r.forEach(p=>{if(!o.has(p)){let c=`asset${o.size}`;o.set(p,c);}});let s=Array.from(o,([p,c])=>({name:c,url:p})).map(p=>`import ${p.name} from '${this.ɗj(i,p.url)}';`).join(`
5
+ `,i=o;}return t.variableType?e+=`export const ${t.variableName}: ${t.variableType} = ${this.ɗcb(t.variable)}`:e+=`export const ${t.variableName} = ${this.ɗcb(t.variable)}`,t.satisfies&&(e+=` as const satisfies ${t.satisfies}`),i&&(e=this.ɗbo(e,i)),t.replaceMap&&(e=this.ɗbo(e,t.replaceMap)),this.format(e)}static async format(t){return format(t,{parser:"typescript",trailingComma:"none",tabWidth:2,printWidth:130,singleQuote:true,arrowParens:"avoid",plugins:[ne,re]})}static ɗj(t,e){let i=l.outputPath+t.substring(0,t.lastIndexOf("/")),r=l.config.projectRoot+e.substring(1);return dt__default.relative(i,r).replace(/\\/g,"/")}static ɗbo(t,e){return e.forEach(i=>{t=t.replace(new RegExp(i.target,"g"),i.replace);}),t}static ɗi(t,e,i){let r=t.map(p=>{let c=JsonHelper.deepFind(p,e);if(!c)throw new Error(`OutputHelperClass: Asset url is not found in the given variable! item: "${JSON.stringify(p)}", assetUrl: "${e}"`);return c}),o=new Map;r.forEach(p=>{if(!o.has(p)){let c=`asset${o.size}`;o.set(p,c);}});let s=Array.from(o,([p,c])=>({name:c,url:p})).map(p=>`import ${p.name} from '${this.ɗj(i,p.url)}';`).join(`
6
6
  `),a=r.reduce((p,c)=>[...p,{target:`"${c}"`,replace:o.get(c)}],[]);return {assetImports:s,replaceMap:a}}static ɗcb(t){return JSON.stringify(t,(e,i)=>i===void 0?null:i).replace(/null/gm,"undefined")}};var l=class{static{this.compilerExecutionPath="";}static{this.outputPath="";}static{this.config={projectRoot:"",compilerModulesPath:""};}static{this.rawDefinitions=[];}static{this.files=[];}static{this.output=[];}static{this.exports=[];}static{this.componentInProgressData=void 0;}static async addFile(t){this.exports.push({variableName:t.variableName,path:t.path}),this.output.push({path:t.path,content:await N.generate({preText:Comparator.isArray(t.preText)?t.preText.join(`
7
- `):t.preText,variableName:t.variableName,variableType:t.variableType,variable:t.variable,replaceMap:t.replaceMap,filePath:t.path,assetUrl:t.assetUrl})});}static get successful(){return this.errorLogs.length===0}static addErrorLog(t,e="default"){Comparator.isArray(t)?e==="lowPriority"?this.ɗu=[...t,...this.ɗu]:this.ɗu.push(...t):e==="lowPriority"?this.ɗu=[t,...this.ɗu]:this.ɗu.push(t);}static flushErrorLogs(){this.errorLogs=[...this.ɗu,...this.errorLogs],this.ɗu=[];}static{this.errorLogs=[];}static{this.ɗu=[];}static reset(){this.compilerExecutionPath="D:/test",this.outputPath="D:/test/.asset-build",this.config.projectRoot="D:/",this.files=[],this.rawDefinitions=[],this.errorLogs=[],this.ɗu=[],this.output=[];}};var G=class{constructor(t){this.ɗar=t;this.ɗav=new Set;this.ɗau=new Map;this.ɗb=new Set;this.ɗt=[];}newEntry(t,e){if(this.ɗav.has(t)){if(!this.ɗb.has(t)){this.ɗb.add(t);let i=this.ɗau.get(t);i&&this.ɗt.push({identifier:t,location:i});}return this.ɗt.push({identifier:t,location:e}),false}else return this.ɗav.add(t),this.ɗau.set(t,e),true}logDuplicateErrors(){this.ɗt.forEach(t=>{let e={description:`Value should be singular! Group: "${this.ɗar}", Value: "${t.identifier}"`,location:t.location};l.addErrorLog(e);});}};var C=class{static{this.ɗs=new Map;}static logDuplicates(){this.ɗs.forEach(t=>t.logDuplicateErrors());}static getDefinitionComponentName(t){return t.$meta.componentName}static getDefinitionComponentNamesFromArray(t){return Comparator.isArray(t)?t.map(e=>this.getDefinitionComponentName(e)):[this.getDefinitionComponentName(t)]}static getValidationState(t){return t.state.path&&(t.state.path.length===0||t.state.path[0]!==void 0&&t.prefs.context.rawDefinition)?"valid":"notValid"}static getPathAndRawDefinition(t){let e=t.state.path,i=t.prefs.context.rawDefinition;return {path:e,rawDefinition:i}}static getDuplicateHelper(t){let e=this.ɗs.get(t);return e||(e=new G(t),this.ɗs.set(t,e)),e}};var W=class{constructor(t){this.ɗac=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(C.getValidationState(e)==="valid"){let{rawDefinition:r}=C.getPathAndRawDefinition(e);if(t=r.location.path.substring(0,r.location.path.lastIndexOf("/")+1)+t,this.ɗac.existsSync(t))return t.replace(l.config.projectRoot,".");throw new Error(`No file is found in the path: "${t}"`)}else throw new Error(`Internal Error; joi validation context for path validator: Path: "${e.state.path}", RawDefinition: "${JSON.stringify(e.prefs.context.rawDefinition)}"`)};}};var K=class{constructor(t,e,i,r){t={x:t.x*i,y:t.y*i},this.ɗbq=i,this.ɗe=r||false,this.ɗc=this.ɗai(t,e),this.ɗd=this.ɗaj(t,this.ɗc);}convertPositionToSpriteAnchor(t){t={x:t.x*this.ɗbq,y:t.y*this.ɗbq};let e={x:t.x+this.ɗd.topLeft.x,y:t.y+this.ɗd.topLeft.y};if(this.ɗe&&!this.ɗce(e))throw new Error(`location is outside of the sprite boundaries. Entered position: {x: ${t.x}, y: ${t.y}}, position on sprite: {x: ${e.x}, y: ${e.y}}, bounding box: ${JSON.stringify(this.ɗd)}.`);return e}getRotationFromAnchor(t){return Vector.fromVec2(t).radian.value}ɗce(t){return !(t.x<this.ɗd.topLeft.x||t.x>this.ɗd.bottomRight.x||t.y<this.ɗd.topLeft.y||t.y>this.ɗd.bottomRight.y)}ɗai(t,e){return {x:t.x*e.x,y:t.y*e.y}}ɗaj(t,e){return {topLeft:{x:-e.x,y:-e.y},bottomRight:{x:t.x-e.x,y:t.y-e.y}}}};var Z=class{constructor(t){this.ɗbd=t;this.validate=(t,e)=>{let i=this.ɗbd.selectSpriteDefinition(t);if(!i)throw new Error("positionOnSprite - callback function did not return sprite definition.");let r=new K(i.url.size,i.anchor,i.scale,this.ɗbd.checkIfPositionIsOnSprite);return (Array.isArray(this.ɗbd.positionsJsonPath)?this.ɗbd.positionsJsonPath:[this.ɗbd.positionsJsonPath]).forEach(s=>JSONPath({json:t,path:s}).forEach(a=>{if(Comparator.isObject(a)){if(!Comparator.isNumber(a.x)||!Comparator.isNumber(a.y))throw new Error(`positionOnSprite, positions json path returned a non-vec2 result. Value: "${a}".`)}else throw new Error(`positionOnSprite, positions json path returned a non-object result. Value: "${a}".`);let p=r.convertPositionToSpriteAnchor(a);p={x:Math.round(p.x),y:Math.round(p.y)},this.ɗbd.includeRotationFromAnchor?(a.rotationFromAnchor=r.getRotationFromAnchor(p),a.positionFromAnchor=p,delete a.x,delete a.y):(a.x=p.x,a.y=p.y);})),t};}};var I=class{static findLine(t,e){if(e.length===0)return t.parsedStructure.line;{let i,r=[...e];for(;i===void 0&&r.length>0;)i=this.ɗz(t.parsedStructure.rawData,[...r]),r.pop();return i||t.parsedStructure.line}}static flatten(t){return this.ɗaa(t.parsedStructure.rawData)}static ɗz(t,e){let i=e.shift(),r;if(t&&i!==void 0&&(Comparator.isNumber(i)?Comparator.isArray(t)&&(r=t[i]):Comparator.isObject(t)&&(r=t[i])),r)return e.length===0?r.line:this.ɗz(r.rawData,e)}static ɗaa(t){if(Comparator.isArray(t))return t.map(e=>this.ɗaa(e.rawData));if(Comparator.isObject(t)){let e=t;return Object.keys(e).reduce((i,r)=>{let o=e[r];return i[r]=this.ɗaa(o.rawData),i},{})}else return t}};var m=class{static{this.ɗas=new Map;}static{this.ɗp=new Map;}static{this.ɗq=new Map;}static{this.ɗh=new Map;}static getDefinitions(t){let e=this.ɗq.get(this.ɗal(t));return e?Array.from(e.values()):[]}static getDefinition(t,e){if(!t.$meta.keyName)throw new Error(`"${t.name}" doesn't have a keyName, getDefinition cannot be called on it.`);return this.ɗq.get(this.ɗal(t))?.get(e)}static getDefinitionOrFail(t,e){let i=this.getDefinition(t,e);if(!i)throw new Error(`No result found for "${e}" in "${t.name}".`);return i}static getSingletonDefinition(t){return this.ɗq.get(this.ɗal(t))?.get(this.ɗal(t))}static getSingletonDefinitionOrFail(t){let e=this.getSingletonDefinition(t);if(!e)throw new Error(`No result found for "${t.name}".`);return e}static getLocationInFile(t,e,i){let r=this.ɗp.get(t.name)?.get(e);if(!r)throw new Error(`No raw definition found for "${e}" in "${t.name}".`);return {line:I.findLine(r,i),path:r.location.path}}static getLocationInFileById(t,e,i){let r=this.ɗap(t,e);if(!r)throw new Error(`No raw definition found for "${e}" in "${t.name}".`);return {line:I.findLine(r,i),path:r.location.path}}static ɗay(t){return this.ɗq.has(t)}static ɗak(t){let e=this.ɗh.get(t);if(!e)throw new Error(`No component found for "${t}".`);return e}static ɗbw(t){t.forEach((e,i)=>{this.ɗq.set(i,new Map);}),this.ɗh=t;}static ɗbx(t,e,i){let r=this.ɗq.get(this.ɗal(t));r&&r.set(e,JsonHelper.deepCopy(i));}static ɗca(t,e){let i=this.ɗal(t),r=this.ɗq.get(i);r&&r.set(i,JsonHelper.deepCopy(e));}static ɗax(t,e){return !!this.ɗas.get(t.name)?.has(e)}static ɗap(t,e){return this.ɗas.get(t.name)?.get(e)}static ɗbz(t,e,i){this.ɗas.has(t.name)||this.ɗas.set(t.name,new Map);let r=this.ɗas.get(t.name);r&&r.set(e,JsonHelper.deepCopy(i));}static ɗby(t,e,i){this.ɗp.has(t.name)||this.ɗp.set(t.name,new Map);let r=this.ɗp.get(t.name);r&&r.set(e,JsonHelper.deepCopy(i));}static ɗal(t){return t.$meta.componentName}};var X=class{constructor(t){this.options=t;this.regex=/^[a-z]+([a-zA-Z0-9]+)*$/;}validatePropertyExistence(t,e,i){if(i?.additionalValidation){let r=m.ɗap(t,e),o=r?I.flatten(r):void 0,s=i.additionalValidation.validate(o);if(s.error)throw new Error(s.error.message)}}},Y=class extends X{constructor(e,i){super(i);this.validate=(e,i)=>{if(C.getValidationState(i)==="valid"){let o=this.ɗbl.find(s=>m.getDefinition(s,e));if(o)return this.validatePropertyExistence(o,e,this.options),this.ɗaw?{value:e,type:C.getDefinitionComponentName(o)}:e;if(this.ɗbl.find(a=>m.ɗax(a,e)))i.prefs.context.failSilently=true;else throw new Error(`There is no "${this.ɗbl.map(a=>C.getDefinitionComponentName(a)).join(" or ")}" definition found for "${e}"`)}else throw new Error(`Internal Error; joi validation context for reference validator: Path: "${i.state.path}", RawDefinition: "${JSON.stringify(i.prefs.context)}"`)};this.ɗbl=[];Comparator.isArray(e)?(this.ɗaw=true,this.ɗbl=e):(this.ɗaw=false,this.ɗbl=[e]);}},tt=class extends X{constructor(e,i){super(i);this.ɗg=e;this.validate=(e,i)=>{if(!l.componentInProgressData)ConsoleHelper.log("Unexpected error: Lazy reference validation has been called outside of the validation cycle.","red");else if(!l.componentInProgressData.meta.keyName)ConsoleHelper.log("Lazy reference can only be used for definitions with key name defined.","red");else if(l.componentInProgressData.meta.componentName!==this.ɗg)ConsoleHelper.log(`Lazy reference can only be used for self referencing. It is used under: "${this.ɗg}"`,"red");else if(l.componentInProgressData.meta.singleton)ConsoleHelper.log(`Lazy reference cannot be used for singleton components. It is used under: "${this.ɗg}"`,"red");else {let a=i.state.ancestors.at(-1)[l.componentInProgressData.meta.keyName];a?(l.componentInProgressData.idToReferencesMap.has(a)||l.componentInProgressData.idToReferencesMap.set(a,new Set),l.componentInProgressData.idToReferencesMap.get(a).add(e)):ConsoleHelper.log("Unexpected error: definitionId cannot be retrieved by keyname.","red");}let r=m.ɗak(this.ɗg);if(C.getValidationState(i)==="valid"){if(m.ɗax(r,e))return this.validatePropertyExistence(r,e,this.options),e;throw new Error(`There is no "${this.ɗg}" definition found for "${e}"`)}else throw new Error(`Internal Error; joi validation context for reference validator: Path: "${i.state.path}", RawDefinition: "${JSON.stringify(i.prefs.context)}"`)};}};var et=class{constructor(t){this.ɗac=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(C.getValidationState(e)==="valid"){let{rawDefinition:r}=C.getPathAndRawDefinition(e);if(t=r.location.path.substring(0,r.location.path.lastIndexOf("/")+1)+t,this.ɗac.existsSync(t))try{let s=ce(t);return {url:t.replace(l.config.projectRoot,"."),size:{x:s.width,y:s.height}}}catch{throw new Error(`The file in the path "${t}" is not an image`)}else throw new Error(`No file is found in the path: "${t}"`)}else throw new Error(`Internal Error; joi validation context for image validator: Path: "${e.state.path}", RawDefinition: "${JSON.stringify(e.prefs.context.rawDefinition)}"`)};}};var it=class{constructor(t){this.ɗbb=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(this.ɗbb.has(t))throw new Error(`Value "${t}" is not unique in the name space: "${Array.from(this.ɗbb).join(", ")}"`);return this.ɗbb.add(t),t};}};var H=class n{static decorate(t,e){t.string().__proto__.unique=function(i){let r=new it(i);return n.ɗn(this,r)},t.string().__proto__.path=function(){let i=new W(e);return n.ɗn(this,i)},t.string().__proto__.sprite=function(){let i=new et(e);return n.ɗn(this,i)},t.string().__proto__.reference=function(i,r){let o=new Y(i,r);return n.ɗn(this,o)},t.string().__proto__.lazyReference=function(i,r){let o=new tt(i,r);return n.ɗn(this,o)},t.object().__proto__.positionOnSprite=function(i){let r=new Z(i);return this.custom(r.validate)},t!==u&&this.decorate(u,e);}static ɗn(t,e){return t.regex(e.regex).custom(e.validate)}};H.decorate(u,S__default);function de(n){return n.replace(/[-_]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\s+/g," ").trim().toLowerCase().split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}function T(n){return function(t){if(n.singleton){if(n.keyName!==void 0)throw new Error(`Singleton components should not have keyName! Component: ${n.componentName}`);if(!(t.prototype instanceof rt))throw new Error(`Singleton components should extend SingleDefinitionComponent! Component: ${n.componentName}`)}else if(!(t.prototype instanceof g))throw new Error(`Non singleton components should extend DefinitionComponent! Component: ${n.componentName}`);t.$meta={componentName:n.componentName,pascalCaseComponentName:de(n.componentName),keyName:n.keyName,singleton:n.singleton,validationSchema:n.validationSchema};}}var g=class{static getSchema(){return this.$meta.validationSchema}},rt=class{static getSchema(){return this.$meta.validationSchema}};var R=class{static{this.definitionToRawDefintion=new Map;}static getRawDefinitions(t){return l.rawDefinitions.filter(e=>e.componentName===t)}static validateAndConvert(t,e){return this.getRawDefinitions(t).map(i=>{let r=this.ɗcd(i,e);if(this.definitionToRawDefintion.set(r,i),r)return {definition:r,rawDefinition:i}}).filter(i=>i)}static validateAndConvertSingular(t,e){let i=this.validateAndConvert(t,e);if(i.length===0){if(l.successful){let r={description:`Singleton definition has no declared entry "${t}"`,location:{line:0,path:"*"}};l.addErrorLog(r,"lowPriority");}}else if(i.length>1)l.rawDefinitions.filter(r=>r.componentName===t).forEach(r=>{let o={description:`Only one definition can be defined for "${t}"`,location:r.location};l.addErrorLog(o,"lowPriority");});else return i[0]}static ɗcd(t,e){let i={rawDefinition:t,failSilently:false};try{let{value:r,error:o}=e.validate(I.flatten(t),{abortEarly:!1,context:i});if(o?.details){let s=o.details.reverse().map(a=>({description:a.message,location:{line:I.findLine(t,a.path),path:t.location.path}}));l.addErrorLog(s.reverse());}else if(!i.failSilently)return r}catch(r){throw new Error(`Internal Error:
7
+ `):t.preText,variableName:t.variableName,variableType:t.variableType,satisfies:t.satisfies,variable:t.variable,replaceMap:t.replaceMap,filePath:t.path,assetUrl:t.assetUrl})});}static get successful(){return this.errorLogs.length===0}static addErrorLog(t,e="default"){Comparator.isArray(t)?e==="lowPriority"?this.ɗu=[...t,...this.ɗu]:this.ɗu.push(...t):e==="lowPriority"?this.ɗu=[t,...this.ɗu]:this.ɗu.push(t);}static flushErrorLogs(){this.errorLogs=[...this.ɗu,...this.errorLogs],this.ɗu=[];}static{this.errorLogs=[];}static{this.ɗu=[];}static reset(){this.compilerExecutionPath="D:/test",this.outputPath="D:/test/.asset-build",this.config.projectRoot="D:/",this.files=[],this.rawDefinitions=[],this.errorLogs=[],this.ɗu=[],this.output=[];}};var G=class{constructor(t){this.ɗar=t;this.ɗav=new Set;this.ɗau=new Map;this.ɗb=new Set;this.ɗt=[];}newEntry(t,e){if(this.ɗav.has(t)){if(!this.ɗb.has(t)){this.ɗb.add(t);let i=this.ɗau.get(t);i&&this.ɗt.push({identifier:t,location:i});}return this.ɗt.push({identifier:t,location:e}),false}else return this.ɗav.add(t),this.ɗau.set(t,e),true}logDuplicateErrors(){this.ɗt.forEach(t=>{let e={description:`Value should be singular! Group: "${this.ɗar}", Value: "${t.identifier}"`,location:t.location};l.addErrorLog(e);});}};var C=class{static{this.ɗs=new Map;}static logDuplicates(){this.ɗs.forEach(t=>t.logDuplicateErrors());}static getDefinitionComponentName(t){return t.$meta.componentName}static getDefinitionComponentNamesFromArray(t){return Comparator.isArray(t)?t.map(e=>this.getDefinitionComponentName(e)):[this.getDefinitionComponentName(t)]}static getValidationState(t){return t.state.path&&(t.state.path.length===0||t.state.path[0]!==void 0&&t.prefs.context.rawDefinition)?"valid":"notValid"}static getPathAndRawDefinition(t){let e=t.state.path,i=t.prefs.context.rawDefinition;return {path:e,rawDefinition:i}}static getDuplicateHelper(t){let e=this.ɗs.get(t);return e||(e=new G(t),this.ɗs.set(t,e)),e}};var W=class{constructor(t){this.ɗac=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(C.getValidationState(e)==="valid"){let{rawDefinition:r}=C.getPathAndRawDefinition(e);if(t=r.location.path.substring(0,r.location.path.lastIndexOf("/")+1)+t,this.ɗac.existsSync(t))return t.replace(l.config.projectRoot,".");throw new Error(`No file is found in the path: "${t}"`)}else throw new Error(`Internal Error; joi validation context for path validator: Path: "${e.state.path}", RawDefinition: "${JSON.stringify(e.prefs.context.rawDefinition)}"`)};}};var K=class{constructor(t,e,i,r){t={x:t.x*i,y:t.y*i},this.ɗbq=i,this.ɗe=r||false,this.ɗc=this.ɗai(t,e),this.ɗd=this.ɗaj(t,this.ɗc);}convertPositionToSpriteAnchor(t){t={x:t.x*this.ɗbq,y:t.y*this.ɗbq};let e={x:t.x+this.ɗd.topLeft.x,y:t.y+this.ɗd.topLeft.y};if(this.ɗe&&!this.ɗce(e))throw new Error(`location is outside of the sprite boundaries. Entered position: {x: ${t.x}, y: ${t.y}}, position on sprite: {x: ${e.x}, y: ${e.y}}, bounding box: ${JSON.stringify(this.ɗd)}.`);return e}getRotationFromAnchor(t){return Vector.fromVec2(t).radian.value}ɗce(t){return !(t.x<this.ɗd.topLeft.x||t.x>this.ɗd.bottomRight.x||t.y<this.ɗd.topLeft.y||t.y>this.ɗd.bottomRight.y)}ɗai(t,e){return {x:t.x*e.x,y:t.y*e.y}}ɗaj(t,e){return {topLeft:{x:-e.x,y:-e.y},bottomRight:{x:t.x-e.x,y:t.y-e.y}}}};var Z=class{constructor(t){this.ɗbd=t;this.validate=(t,e)=>{let i=this.ɗbd.selectSpriteDefinition(t);if(!i)throw new Error("positionOnSprite - callback function did not return sprite definition.");let r=new K(i.url.size,i.anchor,i.scale,this.ɗbd.checkIfPositionIsOnSprite);return (Array.isArray(this.ɗbd.positionsJsonPath)?this.ɗbd.positionsJsonPath:[this.ɗbd.positionsJsonPath]).forEach(s=>JSONPath({json:t,path:s}).forEach(a=>{if(Comparator.isObject(a)){if(!Comparator.isNumber(a.x)||!Comparator.isNumber(a.y))throw new Error(`positionOnSprite, positions json path returned a non-vec2 result. Value: "${a}".`)}else throw new Error(`positionOnSprite, positions json path returned a non-object result. Value: "${a}".`);let p=r.convertPositionToSpriteAnchor(a);p={x:Math.round(p.x),y:Math.round(p.y)},this.ɗbd.includeRotationFromAnchor?(a.rotationFromAnchor=r.getRotationFromAnchor(p),a.positionFromAnchor=p,delete a.x,delete a.y):(a.x=p.x,a.y=p.y);})),t};}};var I=class{static findLine(t,e){if(e.length===0)return t.parsedStructure.line;{let i,r=[...e];for(;i===void 0&&r.length>0;)i=this.ɗz(t.parsedStructure.rawData,[...r]),r.pop();return i||t.parsedStructure.line}}static flatten(t){return this.ɗaa(t.parsedStructure.rawData)}static ɗz(t,e){let i=e.shift(),r;if(t&&i!==void 0&&(Comparator.isNumber(i)?Comparator.isArray(t)&&(r=t[i]):Comparator.isObject(t)&&(r=t[i])),r)return e.length===0?r.line:this.ɗz(r.rawData,e)}static ɗaa(t){if(Comparator.isArray(t))return t.map(e=>this.ɗaa(e.rawData));if(Comparator.isObject(t)){let e=t;return Object.keys(e).reduce((i,r)=>{let o=e[r];return i[r]=this.ɗaa(o.rawData),i},{})}else return t}};var m=class{static{this.ɗas=new Map;}static{this.ɗp=new Map;}static{this.ɗq=new Map;}static{this.ɗh=new Map;}static getDefinitions(t){let e=this.ɗq.get(this.ɗal(t));return e?Array.from(e.values()):[]}static getDefinition(t,e){if(!t.$meta.keyName)throw new Error(`"${t.name}" doesn't have a keyName, getDefinition cannot be called on it.`);return this.ɗq.get(this.ɗal(t))?.get(e)}static getDefinitionOrFail(t,e){let i=this.getDefinition(t,e);if(!i)throw new Error(`No result found for "${e}" in "${t.name}".`);return i}static getSingletonDefinition(t){return this.ɗq.get(this.ɗal(t))?.get(this.ɗal(t))}static getSingletonDefinitionOrFail(t){let e=this.getSingletonDefinition(t);if(!e)throw new Error(`No result found for "${t.name}".`);return e}static getLocationInFile(t,e,i){let r=this.ɗp.get(t.name)?.get(e);if(!r)throw new Error(`No raw definition found for "${e}" in "${t.name}".`);return {line:I.findLine(r,i),path:r.location.path}}static getLocationInFileById(t,e,i){let r=this.ɗap(t,e);if(!r)throw new Error(`No raw definition found for "${e}" in "${t.name}".`);return {line:I.findLine(r,i),path:r.location.path}}static ɗay(t){return this.ɗq.has(t)}static ɗak(t){let e=this.ɗh.get(t);if(!e)throw new Error(`No component found for "${t}".`);return e}static ɗbw(t){t.forEach((e,i)=>{this.ɗq.set(i,new Map);}),this.ɗh=t;}static ɗbx(t,e,i){let r=this.ɗq.get(this.ɗal(t));r&&r.set(e,JsonHelper.deepCopy(i));}static ɗca(t,e){let i=this.ɗal(t),r=this.ɗq.get(i);r&&r.set(i,JsonHelper.deepCopy(e));}static ɗax(t,e){return !!this.ɗas.get(t.name)?.has(e)}static ɗap(t,e){return this.ɗas.get(t.name)?.get(e)}static ɗbz(t,e,i){this.ɗas.has(t.name)||this.ɗas.set(t.name,new Map);let r=this.ɗas.get(t.name);r&&r.set(e,JsonHelper.deepCopy(i));}static ɗby(t,e,i){this.ɗp.has(t.name)||this.ɗp.set(t.name,new Map);let r=this.ɗp.get(t.name);r&&r.set(e,JsonHelper.deepCopy(i));}static ɗal(t){return t.$meta.componentName}};var X=class{constructor(t){this.options=t;this.regex=/^[a-z]+([a-zA-Z0-9]+)*$/;}validatePropertyExistence(t,e,i){if(i?.additionalValidation){let r=m.ɗap(t,e),o=r?I.flatten(r):void 0,s=i.additionalValidation.validate(o);if(s.error)throw new Error(s.error.message)}}},Y=class extends X{constructor(e,i){super(i);this.validate=(e,i)=>{if(C.getValidationState(i)==="valid"){let o=this.ɗbl.find(s=>m.getDefinition(s,e));if(o)return this.validatePropertyExistence(o,e,this.options),this.ɗaw?{value:e,type:C.getDefinitionComponentName(o)}:e;if(this.ɗbl.find(a=>m.ɗax(a,e)))i.prefs.context.failSilently=true;else throw new Error(`There is no "${this.ɗbl.map(a=>C.getDefinitionComponentName(a)).join(" or ")}" definition found for "${e}"`)}else throw new Error(`Internal Error; joi validation context for reference validator: Path: "${i.state.path}", RawDefinition: "${JSON.stringify(i.prefs.context)}"`)};this.ɗbl=[];Comparator.isArray(e)?(this.ɗaw=true,this.ɗbl=e):(this.ɗaw=false,this.ɗbl=[e]);}},tt=class extends X{constructor(e,i){super(i);this.ɗg=e;this.validate=(e,i)=>{if(!l.componentInProgressData)ConsoleHelper.log("Unexpected error: Lazy reference validation has been called outside of the validation cycle.","red");else if(!l.componentInProgressData.meta.keyName)ConsoleHelper.log("Lazy reference can only be used for definitions with key name defined.","red");else if(l.componentInProgressData.meta.componentName!==this.ɗg)ConsoleHelper.log(`Lazy reference can only be used for self referencing. It is used under: "${this.ɗg}"`,"red");else if(l.componentInProgressData.meta.singleton)ConsoleHelper.log(`Lazy reference cannot be used for singleton components. It is used under: "${this.ɗg}"`,"red");else {let a=i.state.ancestors.at(-1)[l.componentInProgressData.meta.keyName];a?(l.componentInProgressData.idToReferencesMap.has(a)||l.componentInProgressData.idToReferencesMap.set(a,new Set),l.componentInProgressData.idToReferencesMap.get(a).add(e)):ConsoleHelper.log("Unexpected error: definitionId cannot be retrieved by keyname.","red");}let r=m.ɗak(this.ɗg);if(C.getValidationState(i)==="valid"){if(m.ɗax(r,e))return this.validatePropertyExistence(r,e,this.options),e;throw new Error(`There is no "${this.ɗg}" definition found for "${e}"`)}else throw new Error(`Internal Error; joi validation context for reference validator: Path: "${i.state.path}", RawDefinition: "${JSON.stringify(i.prefs.context)}"`)};}};var et=class{constructor(t){this.ɗac=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(C.getValidationState(e)==="valid"){let{rawDefinition:r}=C.getPathAndRawDefinition(e);if(t=r.location.path.substring(0,r.location.path.lastIndexOf("/")+1)+t,this.ɗac.existsSync(t))try{let s=ce(t);return {url:t.replace(l.config.projectRoot,"."),size:{x:s.width,y:s.height}}}catch{throw new Error(`The file in the path "${t}" is not an image`)}else throw new Error(`No file is found in the path: "${t}"`)}else throw new Error(`Internal Error; joi validation context for image validator: Path: "${e.state.path}", RawDefinition: "${JSON.stringify(e.prefs.context.rawDefinition)}"`)};}};var it=class{constructor(t){this.ɗbb=t;this.regex=/^[\S]+$/;this.validate=(t,e)=>{if(this.ɗbb.has(t))throw new Error(`Value "${t}" is not unique in the name space: "${Array.from(this.ɗbb).join(", ")}"`);return this.ɗbb.add(t),t};}};var H=class n{static decorate(t,e){t.string().__proto__.unique=function(i){let r=new it(i);return n.ɗn(this,r)},t.string().__proto__.path=function(){let i=new W(e);return n.ɗn(this,i)},t.string().__proto__.sprite=function(){let i=new et(e);return n.ɗn(this,i)},t.string().__proto__.reference=function(i,r){let o=new Y(i,r);return n.ɗn(this,o)},t.string().__proto__.lazyReference=function(i,r){let o=new tt(i,r);return n.ɗn(this,o)},t.object().__proto__.positionOnSprite=function(i){let r=new Z(i);return this.custom(r.validate)},t!==u&&this.decorate(u,e);}static ɗn(t,e){return t.regex(e.regex).custom(e.validate)}};H.decorate(u,S__default);function de(n){return n.replace(/[-_]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\s+/g," ").trim().toLowerCase().split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}function T(n){return function(t){if(n.singleton){if(n.keyName!==void 0)throw new Error(`Singleton components should not have keyName! Component: ${n.componentName}`);if(!(t.prototype instanceof rt))throw new Error(`Singleton components should extend SingleDefinitionComponent! Component: ${n.componentName}`)}else if(!(t.prototype instanceof g))throw new Error(`Non singleton components should extend DefinitionComponent! Component: ${n.componentName}`);t.$meta={componentName:n.componentName,pascalCaseComponentName:de(n.componentName),keyName:n.keyName,singleton:n.singleton,validationSchema:n.validationSchema};}}var g=class{static getSchema(){return this.$meta.validationSchema}},rt=class{static getSchema(){return this.$meta.validationSchema}};var R=class{static{this.definitionToRawDefintion=new Map;}static getRawDefinitions(t){return l.rawDefinitions.filter(e=>e.componentName===t)}static validateAndConvert(t,e){return this.getRawDefinitions(t).map(i=>{let r=this.ɗcd(i,e);if(this.definitionToRawDefintion.set(r,i),r)return {definition:r,rawDefinition:i}}).filter(i=>i)}static validateAndConvertSingular(t,e){let i=this.validateAndConvert(t,e);if(i.length===0){if(l.successful){let r={description:`Singleton definition has no declared entry "${t}"`,location:{line:0,path:"*"}};l.addErrorLog(r,"lowPriority");}}else if(i.length>1)l.rawDefinitions.filter(r=>r.componentName===t).forEach(r=>{let o={description:`Only one definition can be defined for "${t}"`,location:r.location};l.addErrorLog(o,"lowPriority");});else return i[0]}static ɗcd(t,e){let i={rawDefinition:t,failSilently:false};try{let{value:r,error:o}=e.validate(I.flatten(t),{abortEarly:!1,context:i});if(o?.details){let s=o.details.reverse().map(a=>({description:a.message,location:{line:I.findLine(t,a.path),path:t.location.path}}));l.addErrorLog(s.reverse());}else if(!i.failSilently)return r}catch(r){throw new Error(`Internal Error:
8
8
 
9
9
  raw definition: "${JSON.stringify(t)}"
10
10
 
11
- error: "${r}"`)}}};var nt="CONFIG",kt=u.object().keys({projectRoot:u.string().regex(/^[\S]+$/).required(),compilerModulesPath:u.string().regex(/^[\S]+$/).optional()}),J=class{static{this.$meta={componentName:nt,validationSchema:kt};}static process(){let t=R.validateAndConvertSingular(nt,kt);if(t){let e=t.definition;l.config.projectRoot=e.projectRoot,e.compilerModulesPath&&(l.config.compilerModulesPath=`${e.projectRoot}${e.compilerModulesPath.replace("./","")}`);}}};var vt=class{decorateDefinitionName(t,e){return `${this.kebabCaseToCamelCase(e)}${this.upperCaseFirstLetter(t)}`}kebabCaseToCamelCase(t){return t.toLowerCase().replace(/-./g,e=>e[1].toUpperCase())}lowerCaseFirstLetter(t){return t.charAt(0).toLowerCase()+t.slice(1)}upperCaseFirstLetter(t){return t.charAt(0).toUpperCase()+t.slice(1)}removeWhiteSpace(t){return t.replace(/\r?\n|\r/g,"").replace(/\/\/.*$/gm,"").trim().replace(/ {2,}/g," ")}removeComments(t){return t.replace(/\/\/.*$/gm,"").trimEnd()}},q=new vt;var ot=class{constructor(){this.ɗr=false;this.ɗo=[];this.ɗv=[];this.ɗl="";}process(t){return this.ɗr=false,this.ɗm=void 0,this.ɗo=[],this.ɗv=[],this.ɗl=t.path,t.content.split(`
11
+ error: "${r}"`)}}};var nt="CONFIG",Jt=u.object().keys({projectRoot:u.string().regex(/^[\S]+$/).required(),compilerModulesPath:u.string().regex(/^[\S]+$/).optional()}),k=class{static{this.$meta={componentName:nt,validationSchema:Jt};}static process(){let t=R.validateAndConvertSingular(nt,Jt);if(t){let e=t.definition;l.config.projectRoot=e.projectRoot,e.compilerModulesPath&&(l.config.compilerModulesPath=`${e.projectRoot}${e.compilerModulesPath.replace("./","")}`);}}};var vt=class{decorateDefinitionName(t,e){return `${this.kebabCaseToCamelCase(e)}${this.upperCaseFirstLetter(t)}`}kebabCaseToCamelCase(t){return t.toLowerCase().replace(/-./g,e=>e[1].toUpperCase())}lowerCaseFirstLetter(t){return t.charAt(0).toLowerCase()+t.slice(1)}upperCaseFirstLetter(t){return t.charAt(0).toUpperCase()+t.slice(1)}removeWhiteSpace(t){return t.replace(/\r?\n|\r/g,"").replace(/\/\/.*$/gm,"").trim().replace(/ {2,}/g," ")}removeComments(t){return t.replace(/\/\/.*$/gm,"").trimEnd()}},q=new vt;var ot=class{constructor(){this.ɗr=false;this.ɗo=[];this.ɗv=[];this.ɗl="";}process(t){return this.ɗr=false,this.ɗm=void 0,this.ɗo=[],this.ɗv=[],this.ɗl=t.path,t.content.split(`
12
12
  `).forEach((e,i)=>{let r=q.removeWhiteSpace(e);this.ɗr?r.startsWith("###")?(this.ɗab(),this.ɗbc(e,i,r.substring(4))):this.ɗm&&r.length>0&&this.ɗm.content.push(q.removeComments(e)):r==="# DEFINITIONS"&&(this.ɗr=true);}),this.ɗab(),{definitionPlaneTexts:this.ɗo,errorLogs:this.ɗv}}ɗab(){if(this.ɗm)if(this.ɗm.content.length>0)this.ɗo.push(this.ɗm);else {let t={description:"Definitions cannot be empty!",location:this.ɗm.location};this.ɗv.push(t);}this.ɗm=void 0;}ɗbc(t,e,i){if(m.ɗay(i))this.ɗm={type:i,location:{line:e+1,path:this.ɗl},content:[]};else {let r={description:`Invalid definition header: "${t.trim()}"`,location:{line:e+1,path:this.ɗl}};this.ɗv.push(r),this.ɗm=void 0;}}};var at=class{static parse(t,e){let i=[],r=e.line,o=[];if(t.forEach((s,a)=>{if(s.startsWith(" ")){if(a===0)throw {description:"Invalid coding indent!",location:{line:e.line+a,path:e.path}};i.push(s.substring(2));}else {if(s.match(/^- {2}/g)||s.match(/^-[\S]/g))throw {description:`There should be one space after dash operator! "${s}"`,location:{line:e.line+a,path:e.path}};if(s.startsWith("-")){if(i.length){let p=b.getParsedStructure(i,{line:r,path:e.path});o.push(p);}i=[s.substring(2)],r=e.line+a;}else throw s.startsWith(" ")?{description:"Invalid coding indent!",location:{line:e.line+a,path:e.path}}:{description:`Unexpected array element! "${s}"`,location:{line:e.line+a,path:e.path}}}}),i.length){let s=b.getParsedStructure(i,{line:r,path:e.path});o.push(s);}return {line:e.line,rawData:o}}};var st=class{static parse(t,e){let i=[],r="",o=0,s,a={};if(t.forEach((p,c)=>{if(!p.startsWith(" ")&&!p.startsWith("- ")&&s!=="multiLineString"){if(p.startsWith(":"))throw {description:`Invalid row, row cannot start with columns! "${p}"`,location:{line:e.line+c,path:e.path}};if(p.match(/[\w]*:[\w]*:/g))throw {description:`Invalid row, multiple columns! "${p}"`,location:{line:e.line+c,path:e.path}};if(p.match(/: {2}/g)||p.match(/^[\w]+:[\S]/g))throw {description:`There should be one space after column operator! "${p}"`,location:{line:e.line+c,path:e.path}};if(p.startsWith(" "))throw {description:`Invalid coding indent! "${p}"`,location:{line:e.line+c,path:e.path}};if(p.indexOf(":")===-1)throw {description:`Unexpected object element! "${p}"`,location:{line:e.line+c,path:e.path}};{if(i.length){let P=b.getParsedStructure(i,{line:o,path:e.path});P.line-=1,a[r]=P,i=[],r="",o=0;}let d=q.lowerCaseFirstLetter(p.substring(0,p.indexOf(":")));if(p.trimEnd().endsWith(":"))if(r=d,o=e.line+c+1,t[c+1])s=t[c+1].startsWith("-")?"array":"object";else throw {description:`No value found after column! "${p}"`,location:{line:e.line+c,path:e.path}};else if(p.trimEnd().endsWith("`")&&p.indexOf("`")===p.lastIndexOf("`"))i.push("`"),r=d,o=e.line+c+1,s="multiLineString";else {let P=p.substring(p.indexOf(":")+2),U=b.getParsedStructure([P],{line:e.line+c,path:e.path});a[d]=U;}}}else {if(c===0)throw p.startsWith("-")?{description:`Unexpected object element! "${p}"`,location:{line:e.line+c,path:e.path}}:{description:`Invalid coding indent! "${p}"`,location:{line:e.line+c,path:e.path}};if(p.startsWith("`")){i.push(p);let d=b.getParsedStructure(i,{line:o,path:e.path});d.line-=1,a[r]=d,i=[],r="",o=0;}else i.push(p.substring(s==="object"?2:0));}}),i.length){let p=b.getParsedStructure(i,{line:o,path:e.path});p.line-=1,a[r]=p;}return {line:e.line,rawData:a}}};var pt=class{static parse(t,e){let i=t[0];if(i.startsWith("`"))return t.length===1?this.ɗbg(i,e,"`"):this.ɗbe(t,e);if(t.length>1)throw {description:`Invalid row! "${t[1]}"`,location:{line:e.line+2,path:e.path}};return i.startsWith('"')?this.ɗbg(i,e,'"'):this.ɗbf(i,e)}static ɗbf(t,e){if(t.indexOf(" ")!==-1)throw {description:`Unexpected space! "${t}"`,location:e};return {line:e.line,rawData:t==="undefined"?void 0:t}}static ɗbg(t,e,i){let r=new RegExp(i,"g");if((t.match(r)||[]).length>2)throw {description:"There should be only one opening and one closeing quote!",location:e};if(t.endsWith(i))return {line:e.line,rawData:t.replace(r,"")};throw {description:"Quote is not get closed!",location:e}}static ɗbe(t,e){let i=t[t.length-1];if(t[0]!=="`")throw {description:`There should be new line after backtick "${t[0]}"!`,location:{line:e.line,path:e.path}};if(i.startsWith("`")&&i!=="`")throw {description:`There should be new line after backtick "${i}"!`,location:{line:e.line+t.length,path:e.path}};if(i.trim().startsWith("`")){if(i!=="`")throw {description:"Invalid coding indent!",location:{line:e.line+t.length,path:e.path}};return {line:e.line,rawData:t.slice(0,t.length-1).slice(1).join(`
13
- `)}}else throw {description:`Multiline string should end with backtick in new line "${i}"!`,location:{line:e.line+t.length,path:e.path}}}};var b=class n{static getParsedStructure(t,e){let i=this.ɗaq(t[0]);switch(i){case "object":return st.parse(t,e);case "array":return at.parse(t,e);case "primitive":return pt.parse(t,e);default:{throw new Error(`Unexpected case! "${i}"`)}}}static ɗaq(t){return t.startsWith("-")&&!t.match(/^-?\d+(\.\d+)?$/)?"array":t.match(/^[\w]+:/)?"object":"primitive"}process(t){let e=[];return {rawDefinitions:t.map(r=>{try{if(r.content.length)return {componentName:r.type,location:r.location,parsedStructure:n.getParsedStructure(r.content,{line:r.location.line+1,path:r.location.path})}}catch(o){o?.description&&o?.location?e.push(o):e.push({description:`Unexpected Error! Error: "${o}"`,location:r.location});}}).filter(r=>r),errorLogs:e}}};var lt=class{static{this.ɗbv=new ot;}static{this.ɗcc=new b;}static process(){let t=l.files.reduce((i,r)=>{let o=this.ɗbv.process(r);return l.addErrorLog(o.errorLogs),i.push(...o.definitionPlaneTexts),i},[]),e=this.ɗcc.process(t);l.rawDefinitions.push(...e.rawDefinitions),l.addErrorLog(e.errorLogs),J.process();}};var bt="// ---- INDEX OUTPUT ----",ue="// ---- END ----",j=class{static{this.ɗbi=[];}static{this.ɗat=[];}static addPremadeInterface(t){this.ɗbi.push(t);}static addIdType(t,e){let i=`export type ${t}ID = ${e.map(r=>`'${r}'`).join(" | ")};`;this.ɗat.push(i);}static async generateFile(t,e){if(l.config.compilerModulesPath){let i=await this.ɗaf(t);i&&await this.ɗk(i);}else await this.ɗk(e);}static async ɗk(t){let e=t,i=this.generateTypes();i&&(e+=`
13
+ `)}}else throw {description:`Multiline string should end with backtick in new line "${i}"!`,location:{line:e.line+t.length,path:e.path}}}};var b=class n{static getParsedStructure(t,e){let i=this.ɗaq(t[0]);switch(i){case "object":return st.parse(t,e);case "array":return at.parse(t,e);case "primitive":return pt.parse(t,e);default:{throw new Error(`Unexpected case! "${i}"`)}}}static ɗaq(t){return t.startsWith("-")&&!t.match(/^-?\d+(\.\d+)?$/)?"array":t.match(/^[\w]+:/)?"object":"primitive"}process(t){let e=[];return {rawDefinitions:t.map(r=>{try{if(r.content.length)return {componentName:r.type,location:r.location,parsedStructure:n.getParsedStructure(r.content,{line:r.location.line+1,path:r.location.path})}}catch(o){o?.description&&o?.location?e.push(o):e.push({description:`Unexpected Error! Error: "${o}"`,location:r.location});}}).filter(r=>r),errorLogs:e}}};var lt=class{static{this.ɗbv=new ot;}static{this.ɗcc=new b;}static process(){let t=l.files.reduce((i,r)=>{let o=this.ɗbv.process(r);return l.addErrorLog(o.errorLogs),i.push(...o.definitionPlaneTexts),i},[]),e=this.ɗcc.process(t);l.rawDefinitions.push(...e.rawDefinitions),l.addErrorLog(e.errorLogs),k.process();}};var bt="// ---- INDEX OUTPUT ----",ue="// ---- END ----",j=class{static{this.ɗbi=[];}static{this.ɗat=[];}static addPremadeInterface(t){this.ɗbi.push(t);}static addIdType(t,e){let i=`export type ${t}ID = ${e.map(r=>`'${r}'`).join(" | ")};`;this.ɗat.push(i);}static async generateFile(t,e){if(l.config.compilerModulesPath){let i=await this.ɗaf(t);i&&await this.ɗk(i);}else await this.ɗk(e);}static async ɗk(t){let e=t,i=this.generateTypes();i&&(e+=`
14
14
 
15
15
  `+i),l.output.push({path:"/index.ts",content:await N.format(e)});}static async ɗaf(t){let e=Lt.sync(`${l.config.compilerModulesPath}/**/*.ts`).map(o=>o.replace(/\\/g,"/"));e.length===0&&ConsoleHelper.log("No typescript file found to generate index.ts file.","red");let i=this.ɗae(),r=await this.ɗag(e);if(r!==void 0){let o=`${t}
16
16
  ${i}
@@ -29,7 +29,7 @@ ${o.join(`
29
29
  `)}`}static generateTypes(){let t="";return this.ɗat.length>0&&(t+=`//-------------------------- ID TYPES --------------------------
30
30
  `,t+=this.ɗat.join(`
31
31
  `),t+=`
32
- `),t}};var he=/^[a-z]+([a-zA-Z0-9]+)*$/,mt="======================================================",ge="------------------------------------------------------",Mt=n=>n.path.replace(l.compilerExecutionPath+"/","")+":"+n.line,ft=class{static async process(t,e,i){let r=new Map;r.set(nt,J),t.forEach(s=>{let a=s.$meta.componentName;if(r.has(a))throw new Error(`Component name "${a}" is used more than once.`);r.set(a,s);}),m.ɗbw(r),ConsoleHelper.log("Compilation is in progress.","white"),this.ɗbk();let o=await this.ɗah(t,e,i);this.ɗcf(o,l.outputPath);}static ɗbk(){l.compilerExecutionPath=dt.resolve("./").replace(/\\/g,"/"),l.outputPath=`${l.compilerExecutionPath}/.asset-build`,l.files=Lt.sync(`${l.compilerExecutionPath}/**/*.md`).map(t=>t.replace(/\\/g,"/")).map(t=>{let e=S.readFileSync(t).toString();return {path:t,content:e}});}static ɗcf(t,e){let i=new Set;Lt.sync(`${l.outputPath}/**/*`,{nodir:true}).map(a=>a.replace(/\\/g,"/")).forEach(a=>{i.add(a);}),t.forEach(a=>{a.path=e+a.path,i.delete(a.path);}),l.successful&&(ConsoleHelper.log(mt,"gray"),ConsoleHelper.log("Changes:","gray"),ConsoleHelper.newLine());let r=0;l.successful&&i.forEach(a=>{r++,console.info(`${ConsoleHelper.red}Erasing file:${ConsoleHelper.gray} "${this.ɗf(a)}"${ConsoleHelper.default}`),S.unlinkSync(a);});let o=0,s=0;t.forEach(a=>{let p=a.path.substring(0,a.path.lastIndexOf("/"));S.mkdirSync(p,{recursive:true});let c=S.existsSync(a.path);(c?S.readFileSync(a.path).toString():"")!==a.content&&(c?(o++,console.info(`${ConsoleHelper.blue}Modifying file:${ConsoleHelper.gray} "${this.ɗf(a.path)}"${ConsoleHelper.default}`)):(s++,console.info(`${ConsoleHelper.cyan}Creating file:${ConsoleHelper.gray} "${this.ɗf(a.path)}"${ConsoleHelper.default}`)),S.writeFileSync(a.path,a.content));}),this.ɗbn(e),s+o+r>0&&ConsoleHelper.newLine(),ConsoleHelper.log(`Created file count: ${s}`,"gray"),ConsoleHelper.log(`Modified file count: ${o}`,"gray"),ConsoleHelper.log(`Erased file count: ${r}`,"gray"),ConsoleHelper.log(mt,"gray"),l.successful?ConsoleHelper.log("Compilation is completed successfuly!","green"):ConsoleHelper.log("Compilation encountered errors!","red");}static ɗf(t){let e=l.compilerExecutionPath.length;return t.substring(e)}static ɗbn(t){let e=S.readdirSync(t),i=true;for(let r of e){let o=dt.join(t,r);S.statSync(o).isDirectory()&&this.ɗbn(o)?(S.rmdirSync(o),console.info(`${ConsoleHelper.red}Erasing folder:${ConsoleHelper.gray} "${o.substring(t.length).replace(/\\/g,"/")}"${ConsoleHelper.default}`)):i=false;}return i}static async ɗah(t,e,i){lt.process(),l.flushErrorLogs();let r=t.map(o=>{let s=o.$meta;l.componentInProgressData={meta:s,idToReferencesMap:new Map};let a={addFile:c=>l.addFile(c),addError:c=>l.addErrorLog(c),convertLocationInFileToLink:c=>Mt(c)};this.ɗaz(s.keyName,s.componentName,o);let p;if(s.singleton){let c=R.validateAndConvertSingular(s.componentName,s.validationSchema);c&&(p=c.definition,m.ɗby(o,c.definition,c.rawDefinition),m.ɗca(o,p));}else {let c=R.validateAndConvert(s.componentName,s.validationSchema);if(l.componentInProgressData.idToReferencesMap.size>0){let d=s.keyName;if(!d)throw new Error("Unexpected Error: KeyName should be defined for lazy references.");let P=l.componentInProgressData.idToReferencesMap,U=true;for(;U;){let Wt=c.length,Kt=new Set(c.map(Ct=>Ct.definition[d]));c=c.filter(Ct=>{let Ot=Ct.definition[d];if(P.has(Ot)){let Zt=P.get(Ot),Vt=true;return Zt.forEach(Qt=>Kt.has(Qt)||(Vt=false)),Vt}return true}),U=Wt!==c.length;}}c.forEach(d=>{m.ɗby(o,d.definition,d.rawDefinition);}),p=c.map(d=>d.definition),this.ɗbm(p,s.keyName,o);}return l.flushErrorLogs(),l.componentInProgressData=void 0,{definitionToProcess:p,output:a,moduleClass:o}});for(let o of r)if(o.definitionToProcess){let s=new o.moduleClass,a=o.moduleClass.$meta.keyName;a&&j.addIdType(o.moduleClass.$meta.pascalCaseComponentName,o.definitionToProcess.map(p=>p[a])),await s.process(o.definitionToProcess,o.output);}return l.flushErrorLogs(),C.logDuplicates(),l.successful&&await j.generateFile(e,i),this.ɗao()}static ɗaz(t,e,i){let r=R.getRawDefinitions(e);t&&r.forEach(o=>{let s=o.parsedStructure.rawData;if(!Comparator.isObject(s)||Comparator.isArray(s))l.addErrorLog({description:`KeyName shold not be used with a content which is not an object, keyName: "${t}" in "${e}"`,location:{line:o.parsedStructure.line,path:o.location.path}});else {let a=s[t]?.rawData;Comparator.isString(a)&&(he.test(a)===false?l.addErrorLog({description:`KeyValue should be a valid key, keyValue: "${a}"`,location:{line:s[t].line,path:o.location.path}}):m.ɗax(i,a)?l.addErrorLog({description:`Definition with key "${a}" already exists`,location:{line:s[t].line,path:o.location.path}}):m.ɗbz(i,a,o));}});}static ɗbm(t,e,i){e&&t.forEach(r=>{let o=r[e];m.ɗbx(i,o,r);});}static ɗao(){return l.successful?l.output:(ConsoleHelper.newLine(),ConsoleHelper.log("ERROR LOGS:","red"),ConsoleHelper.log(mt,"gray"),l.errorLogs.forEach((t,e)=>{e>0&&ConsoleHelper.log(ge,"gray"),ConsoleHelper.log("Error:","red"),console.info(`${ConsoleHelper.white}Details:${ConsoleHelper.green} ${t.description}`),console.info(`${ConsoleHelper.white}Location:${ConsoleHelper.green} ${Mt(t.location)}`);}),ConsoleHelper.log(mt,"gray"),[{path:"/error-logs.md",content:l.errorLogs.map(t=>`${t.description}\r
32
+ `),t}};var he=/^[a-z]+([a-zA-Z0-9]+)*$/,mt="======================================================",ge="------------------------------------------------------",Mt=n=>n.path.replace(l.compilerExecutionPath+"/","")+":"+n.line,ft=class{static async process(t,e,i){let r=new Map;r.set(nt,k),t.forEach(s=>{let a=s.$meta.componentName;if(r.has(a))throw new Error(`Component name "${a}" is used more than once.`);r.set(a,s);}),m.ɗbw(r),ConsoleHelper.log("Compilation is in progress.","white"),this.ɗbk();let o=await this.ɗah(t,e,i);this.ɗcf(o,l.outputPath);}static ɗbk(){l.compilerExecutionPath=dt.resolve("./").replace(/\\/g,"/"),l.outputPath=`${l.compilerExecutionPath}/.asset-build`,l.files=Lt.sync(`${l.compilerExecutionPath}/**/*.md`).map(t=>t.replace(/\\/g,"/")).map(t=>{let e=S.readFileSync(t).toString();return {path:t,content:e}});}static ɗcf(t,e){let i=new Set;Lt.sync(`${l.outputPath}/**/*`,{nodir:true}).map(a=>a.replace(/\\/g,"/")).forEach(a=>{i.add(a);}),t.forEach(a=>{a.path=e+a.path,i.delete(a.path);}),l.successful&&(ConsoleHelper.log(mt,"gray"),ConsoleHelper.log("Changes:","gray"),ConsoleHelper.newLine());let r=0;l.successful&&i.forEach(a=>{r++,console.info(`${ConsoleHelper.red}Erasing file:${ConsoleHelper.gray} "${this.ɗf(a)}"${ConsoleHelper.default}`),S.unlinkSync(a);});let o=0,s=0;t.forEach(a=>{let p=a.path.substring(0,a.path.lastIndexOf("/"));S.mkdirSync(p,{recursive:true});let c=S.existsSync(a.path);(c?S.readFileSync(a.path).toString():"")!==a.content&&(c?(o++,console.info(`${ConsoleHelper.blue}Modifying file:${ConsoleHelper.gray} "${this.ɗf(a.path)}"${ConsoleHelper.default}`)):(s++,console.info(`${ConsoleHelper.cyan}Creating file:${ConsoleHelper.gray} "${this.ɗf(a.path)}"${ConsoleHelper.default}`)),S.writeFileSync(a.path,a.content));}),this.ɗbn(e),s+o+r>0&&ConsoleHelper.newLine(),ConsoleHelper.log(`Created file count: ${s}`,"gray"),ConsoleHelper.log(`Modified file count: ${o}`,"gray"),ConsoleHelper.log(`Erased file count: ${r}`,"gray"),ConsoleHelper.log(mt,"gray"),l.successful?ConsoleHelper.log("Compilation is completed successfuly!","green"):ConsoleHelper.log("Compilation encountered errors!","red");}static ɗf(t){let e=l.compilerExecutionPath.length;return t.substring(e)}static ɗbn(t){let e=S.readdirSync(t),i=true;for(let r of e){let o=dt.join(t,r);S.statSync(o).isDirectory()&&this.ɗbn(o)?(S.rmdirSync(o),console.info(`${ConsoleHelper.red}Erasing folder:${ConsoleHelper.gray} "${o.substring(t.length).replace(/\\/g,"/")}"${ConsoleHelper.default}`)):i=false;}return i}static async ɗah(t,e,i){lt.process(),l.flushErrorLogs();let r=t.map(o=>{let s=o.$meta;l.componentInProgressData={meta:s,idToReferencesMap:new Map};let a={addFile:c=>l.addFile(c),addError:c=>l.addErrorLog(c),convertLocationInFileToLink:c=>Mt(c)};this.ɗaz(s.keyName,s.componentName,o);let p;if(s.singleton){let c=R.validateAndConvertSingular(s.componentName,s.validationSchema);c&&(p=c.definition,m.ɗby(o,c.definition,c.rawDefinition),m.ɗca(o,p));}else {let c=R.validateAndConvert(s.componentName,s.validationSchema);if(l.componentInProgressData.idToReferencesMap.size>0){let d=s.keyName;if(!d)throw new Error("Unexpected Error: KeyName should be defined for lazy references.");let P=l.componentInProgressData.idToReferencesMap,U=true;for(;U;){let Wt=c.length,Kt=new Set(c.map(Ct=>Ct.definition[d]));c=c.filter(Ct=>{let Ot=Ct.definition[d];if(P.has(Ot)){let Zt=P.get(Ot),Vt=true;return Zt.forEach(Qt=>Kt.has(Qt)||(Vt=false)),Vt}return true}),U=Wt!==c.length;}}c.forEach(d=>{m.ɗby(o,d.definition,d.rawDefinition);}),p=c.map(d=>d.definition),this.ɗbm(p,s.keyName,o);}return l.flushErrorLogs(),l.componentInProgressData=void 0,{definitionToProcess:p,output:a,moduleClass:o}});for(let o of r)if(o.definitionToProcess){let s=new o.moduleClass,a=o.moduleClass.$meta.keyName;a&&j.addIdType(o.moduleClass.$meta.pascalCaseComponentName,o.definitionToProcess.map(p=>p[a])),await s.process(o.definitionToProcess,o.output);}return l.flushErrorLogs(),C.logDuplicates(),l.successful&&await j.generateFile(e,i),this.ɗao()}static ɗaz(t,e,i){let r=R.getRawDefinitions(e);t&&r.forEach(o=>{let s=o.parsedStructure.rawData;if(!Comparator.isObject(s)||Comparator.isArray(s))l.addErrorLog({description:`KeyName shold not be used with a content which is not an object, keyName: "${t}" in "${e}"`,location:{line:o.parsedStructure.line,path:o.location.path}});else {let a=s[t]?.rawData;Comparator.isString(a)&&(he.test(a)===false?l.addErrorLog({description:`KeyValue should be a valid key, keyValue: "${a}"`,location:{line:s[t].line,path:o.location.path}}):m.ɗax(i,a)?l.addErrorLog({description:`Definition with key "${a}" already exists`,location:{line:s[t].line,path:o.location.path}}):m.ɗbz(i,a,o));}});}static ɗbm(t,e,i){e&&t.forEach(r=>{let o=r[e];m.ɗbx(i,o,r);});}static ɗao(){return l.successful?l.output:(ConsoleHelper.newLine(),ConsoleHelper.log("ERROR LOGS:","red"),ConsoleHelper.log(mt,"gray"),l.errorLogs.forEach((t,e)=>{e>0&&ConsoleHelper.log(ge,"gray"),ConsoleHelper.log("Error:","red"),console.info(`${ConsoleHelper.white}Details:${ConsoleHelper.green} ${t.description}`),console.info(`${ConsoleHelper.white}Location:${ConsoleHelper.green} ${Mt(t.location)}`);}),ConsoleHelper.log(mt,"gray"),[{path:"/error-logs.md",content:l.errorLogs.map(t=>`${t.description}\r
33
33
  Path: '${t.location.path}', Line: '${t.location.line}'\r
34
34
  `).join(`\r
35
35
  `)}])}};var $t=class{constructor(t,e,i){h.setup(t,e,i);}setScriptInput(t,e){h.setScriptInput(t,e);}setEventInput(t,e){h.setEventInput(t,e);}addCustomScriptTestCase(t,e,i){h.addCustomScriptTestCase(e,i,t);}addCustomEventTestCase(t,e,i){h.addCustomEventTestCase(e,i,t);}},h=class{static{this.ɗbr=new Map;}static{this.ɗw=new Map;}static{this.ɗbt=new Map;}static{this.ɗy=new Map;}static get scriptSimulatorFunctionsConstructor(){if(!this.ɗbs)throw new Error("ScriptSimulatorFunctionsConstructor is not set");return this.ɗbs}static get eventSimulatorFunctionsConstructor(){if(!this.ɗx)throw new Error("ScriptSimulatorFunctionsConstructor is not set");return this.ɗx}static get richTextTags(){return this.ɗbp}static get isInitialized(){return this.ɗbs&&this.ɗx&&this.ɗbp!==void 0}static setup(t,e,i){this.ɗbs=t,this.ɗx=e,this.ɗbp=i;}static getScriptInput(t){return this.ɗbr.get(t)}static getEventInput(t){return this.ɗw.get(t)}static getCustomScriptTestCases(){return Array.from(this.ɗbt.values())}static getCustomEventTestCases(){return Array.from(this.ɗy.values())}static isCustomScriptTestCase(t){return this.ɗbt.has(t.script)}static isCustomEventTestCase(t){return this.ɗy.has(t.script)}static setScriptInput(t,e){if(this.ɗbr.has(t))throw new Error(`Script input for ${t} already set`);this.ɗbr.set(t,e);}static setEventInput(t,e){if(this.ɗw.has(t))throw new Error(`Event input for ${t} already set`);this.ɗw.set(t,e);}static addCustomScriptTestCase(t,e,i){let r={testDefinition:{script:t,setup:[],cases:[e]},customMessage:`Prebuild Test Case:
@@ -40,8 +40,8 @@ ${i}`};this.ɗy.set(t,r);}};var ut=()=>u.string().custom(n=>({type:"command",val
40
40
 
41
41
  `,a=t.message.indexOf(`
42
42
  `,t.message.indexOf("Execution history"))+1,p=t.message.slice(0,a)+s+t.message.slice(a);return {description:e.customMessage?e.customMessage+`
43
- `+p:p,location:this.ɗba.getLocationOfDefinition(t.location.scriptId,t.location.path)}}else throw t}};var Ee=u.string().custom(n=>({type:"command",value:n})),Le=u.object().keys({runScript:u.string().reference(v).required()}).custom(n=>({type:"runScript",value:n.runScript})),qt=()=>u.array().items(u.alternatives().conditional(u.string(),{then:Ee}).conditional(u.object({runScript:u.exist()}).unknown(),{then:Le}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, runScript";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).min(1),F=class extends g{async process(t,e){let i=m.getDefinitions(v),r=new M(i,h.scriptSimulatorFunctionsConstructor,this.ɗan()),o=t.map(c=>({cases:c.cases,setup:c.setup,script:m.getDefinitionOrFail(v,c.script),scriptInput:h.getScriptInput(c.script),testDefinitionRef:c})),s=h.getCustomScriptTestCases().map(c=>({cases:c.testDefinition.cases,setup:[],script:m.getDefinitionOrFail(v,c.testDefinition.script),scriptInput:h.getScriptInput(c.testDefinition.script),testDefinitionRef:c.testDefinition,customMessage:c.customMessage})),a=o.concat(s),p=r.runTests(a,e);r.printErrors(p,e);}ɗan(){return {getLocationOfDefinition:(t,e)=>m.getLocationInFileById(v,t,e),getLocationOfTestDefinition:(t,e)=>{if(h.isCustomScriptTestCase(t)){let i=`Internal error: custom script test case is failing. Definition: ${JSON.stringify(t)}, Path: ${JSON.stringify(e)}`;throw new Error(i)}else return m.getLocationInFile(F,t,e)}}}};F=w([T({componentName:"SCRIPT-TEST",validationSchema:u.object().keys({script:u.string().reference(v).required(),setup:qt().default([]).optional(),cases:u.array().items(u.object().keys({actionsBeforeTesting:qt().default([]).optional()}).required()).required()}).required()})],F);var Pe=u.object().keys({jumpTo:u.string().lazyReference("EVENT").required()}).custom(n=>({type:"jumpTo",value:n.jumpTo})),yt="EventActionsSchema",Ie=()=>u.array().items(u.alternatives().conditional(u.string(),{then:ut()}).conditional(u.object({jumpTo:u.exist()}).unknown(),{then:Pe}).conditional(u.object({branchByChance:u.exist()}).unknown(),{then:gt(yt)}).conditional(u.object({branchByCondition:u.exist()}).unknown(),{then:ht(yt)}).conditional(u.object({branchByPlayerChoice:u.exist()}).unknown(),{then:Bt(yt)}).conditional(u.object().min(1).max(1).unknown(),{then:Ht()}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, jumpTo, branchByCondition, branchByPlayerChoice, branchByChance";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).id(yt),x=class extends g{async process(t,e){await e.addFile({path:"/_premade/script-engine-definitions/events.ts",preText:'import { ScriptDefinition } from "script-engine-lib";',variableName:"EventDefinitions",variableType:"Readonly<Record<string, ScriptDefinition>>",variable:JsonHelper.arrayToObject(t,"id")});}};x=w([T({componentName:"EVENT",keyName:"id",validationSchema:u.object().keys({id:u.string().unique(It).required(),actions:Ie().default([]).optional()}).required()})],x);var Re=u.string().custom(n=>({type:"command",value:n})),Fe=u.object().keys({runEvent:u.string().reference(x).required()}).custom(n=>({type:"runScript",value:n.runEvent})),zt=()=>u.array().items(u.alternatives().conditional(u.string(),{then:Re}).conditional(u.object({runEvent:u.exist()}).unknown(),{then:Fe}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, runEvent";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).min(1),O=class extends g{async process(t,e){let i=m.getDefinitions(x),r=new M(i,h.eventSimulatorFunctionsConstructor,this.ɗan()),o=r.runTests(t.map(s=>({cases:s.cases,setup:s.setup,script:m.getDefinitionOrFail(x,s.script),scriptInput:h.getEventInput(s.script),testDefinitionRef:s})),e);r.printErrors(o,e);}ɗan(){return {getLocationOfDefinition:(t,e)=>m.getLocationInFileById(x,t,e),getLocationOfTestDefinition:(t,e)=>m.getLocationInFile(O,t,e)}}};O=w([T({componentName:"EVENT-TEST",validationSchema:u.object().keys({event:u.string().reference(x).required(),setup:zt().default([]).optional(),cases:u.array().items(u.object().keys({actionsBeforeTesting:zt().default([]).optional()}).required()).required()}).required().custom(n=>({...n,script:n.event}))})],O);var _t=false;function Oe(n){return function(t){if(_t)console.error("There can be only one definition generator!");else {_t=true;let e=[...n.modules];h.isInitialized&&(e=[v,x,...e,F,O]),ft.process(e,n.indexFilePretext,n.outputIndexFile);}}}var Rt=class{};var Ft=()=>u.array().items(u.array().items(Ut().required()).min(3).required()).min(1),Ut=()=>u.object().keys({x:u.number().required(),y:u.number().required()}),je=()=>u.string().pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/).custom(n=>ColorHelper.stringColorToRGBColor(n)),ke=()=>u.number().min(-Math.PI).max(Math.PI),Je=(n,t)=>u.array().items(n).max(t).custom(e=>{if(e.length>t)throw new Error(`Array exceeds maximum size of ${t}`);for(;e.length<t;)e.push(void 0);return e}).default(ArrayHelper.createEmptyArray(t)).optional();var $=class extends g{async process(t,e){await e.addFile({path:"/_premade/assets/sprites.ts",preText:"import { AssetDefinition } from 'bard-legends-framework';",variableName:"SpriteAssets",variableType:"readonly AssetDefinition[]",assetUrl:"url",variable:t.map(i=>({id:i.id,url:i.url.url}))}),await e.addFile({path:"/_premade/asset-definitions/sprites.ts",preText:'import { SpriteDefinition } from "bard-legends-framework";',variableName:"SpriteDefinitions",variableType:"Readonly<Record<string, SpriteDefinition>>",variable:JsonHelper.arrayToObject(t,"id",{transformFunction:i=>({id:i.id,size:i.url.size,scale:i.scale,anchor:i.anchor,boundingShapes:i.boundingShapes})})});}};$=w([T({componentName:"SPRITE",keyName:"id",validationSchema:u.object().keys({id:u.string().required(),url:u.string().sprite().required(),scale:u.number().min(.1).max(1).default(1).optional(),anchor:u.object().keys({x:u.number().min(0).max(1).required(),y:u.number().min(0).max(1).required()}).default({x:.5,y:.5}).optional(),boundingShapes:Ft().optional()}).positionOnSprite({selectSpriteDefinition:n=>n,positionsJsonPath:["$..boundingShapes[*][*]"],includeRotationFromAnchor:false}).required()})],$);var Ae=()=>u.string().reference($).custom(n=>{let t=m.getDefinitionOrFail($,n);if(t.url.size.x%4!==0)throw new Error(`Sprite width must be multiplier of four in order to keep the pixel perfection. Got: '${t.url.size.x}'`);if(t.url.size.y%4!==0)throw new Error(`Sprite height must be multiplier of four in order to keep the pixel perfection. Got: '${t.url.size.y}'`);return n}),Be=n=>u.string().reference($).custom(t=>{let e=m.getDefinitionOrFail($,t);if(n?.size){if(e.url.size.x!==n.size.x)throw new Error(`Sprite width must be '${n.size.x}px'. Got: '${e.url.size.x}'`);if(e.url.size.y!==n.size.y)throw new Error(`Sprite height must be '${n.size.y}px'. Got: '${e.url.size.y}'`)}if(n?.scale&&e.scale!==n.scale)throw new Error(`Sprite '${t}' scale must be '${n.scale}'. Got: '${e.scale}'`);return t});var z=class extends g{async process(t,e){await e.addFile({path:"/_premade/asset-definitions/sprite-groups.ts",preText:"",variableName:"SpriteGroupDefinitions",variableType:"Readonly<Record<string, readonly string[]>>",variable:JsonHelper.arrayToObject(t,"id",{transformFunction:i=>i.group})});}};z=w([T({componentName:"SPRITE-GROUP",keyName:"id",validationSchema:u.object().keys({id:u.string().required(),group:u.array().items(u.string().reference($)).unique().required()}).required()})],z);var ze=`
43
+ `+p:p,location:this.ɗba.getLocationOfDefinition(t.location.scriptId,t.location.path)}}else throw t}};var Ee=u.string().custom(n=>({type:"command",value:n})),Le=u.object().keys({runScript:u.string().reference(v).required()}).custom(n=>({type:"runScript",value:n.runScript})),qt=()=>u.array().items(u.alternatives().conditional(u.string(),{then:Ee}).conditional(u.object({runScript:u.exist()}).unknown(),{then:Le}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, runScript";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).min(1),F=class extends g{async process(t,e){let i=m.getDefinitions(v),r=new M(i,h.scriptSimulatorFunctionsConstructor,this.ɗan()),o=t.map(c=>({cases:c.cases,setup:c.setup,script:m.getDefinitionOrFail(v,c.script),scriptInput:h.getScriptInput(c.script),testDefinitionRef:c})),s=h.getCustomScriptTestCases().map(c=>({cases:c.testDefinition.cases,setup:[],script:m.getDefinitionOrFail(v,c.testDefinition.script),scriptInput:h.getScriptInput(c.testDefinition.script),testDefinitionRef:c.testDefinition,customMessage:c.customMessage})),a=o.concat(s),p=r.runTests(a,e);r.printErrors(p,e);}ɗan(){return {getLocationOfDefinition:(t,e)=>m.getLocationInFileById(v,t,e),getLocationOfTestDefinition:(t,e)=>{if(h.isCustomScriptTestCase(t)){let i=`Internal error: custom script test case is failing. Definition: ${JSON.stringify(t)}, Path: ${JSON.stringify(e)}`;throw new Error(i)}else return m.getLocationInFile(F,t,e)}}}};F=w([T({componentName:"SCRIPT-TEST",validationSchema:u.object().keys({script:u.string().reference(v).required(),setup:qt().default([]).optional(),cases:u.array().items(u.object().keys({actionsBeforeTesting:qt().default([]).optional()}).required()).required()}).required()})],F);var Pe=u.object().keys({jumpTo:u.string().lazyReference("EVENT").required()}).custom(n=>({type:"jumpTo",value:n.jumpTo})),yt="EventActionsSchema",Ie=()=>u.array().items(u.alternatives().conditional(u.string(),{then:ut()}).conditional(u.object({jumpTo:u.exist()}).unknown(),{then:Pe}).conditional(u.object({branchByChance:u.exist()}).unknown(),{then:gt(yt)}).conditional(u.object({branchByCondition:u.exist()}).unknown(),{then:ht(yt)}).conditional(u.object({branchByPlayerChoice:u.exist()}).unknown(),{then:Bt(yt)}).conditional(u.object().min(1).max(1).unknown(),{then:Ht()}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, jumpTo, branchByCondition, branchByPlayerChoice, branchByChance";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).id(yt),x=class extends g{async process(t,e){await e.addFile({path:"/_premade/script-engine-definitions/events.ts",preText:'import { ScriptDefinition } from "script-engine-lib";',variableName:"EventDefinitions",variableType:"Readonly<Record<string, ScriptDefinition>>",variable:JsonHelper.arrayToObject(t,"id")});}};x=w([T({componentName:"EVENT",keyName:"id",validationSchema:u.object().keys({id:u.string().unique(It).required(),actions:Ie().default([]).optional()}).required()})],x);var Re=u.string().custom(n=>({type:"command",value:n})),Fe=u.object().keys({runEvent:u.string().reference(x).required()}).custom(n=>({type:"runScript",value:n.runEvent})),zt=()=>u.array().items(u.alternatives().conditional(u.string(),{then:Re}).conditional(u.object({runEvent:u.exist()}).unknown(),{then:Fe}).error(n=>n.map(t=>{if(t.code==="alternatives.any"){let e="command, runEvent";t.message=`${t.local.label} does not match any of the allowed types: ${e}`;}return t}))).min(1),O=class extends g{async process(t,e){let i=m.getDefinitions(x),r=new M(i,h.eventSimulatorFunctionsConstructor,this.ɗan()),o=r.runTests(t.map(s=>({cases:s.cases,setup:s.setup,script:m.getDefinitionOrFail(x,s.script),scriptInput:h.getEventInput(s.script),testDefinitionRef:s})),e);r.printErrors(o,e);}ɗan(){return {getLocationOfDefinition:(t,e)=>m.getLocationInFileById(x,t,e),getLocationOfTestDefinition:(t,e)=>m.getLocationInFile(O,t,e)}}};O=w([T({componentName:"EVENT-TEST",validationSchema:u.object().keys({event:u.string().reference(x).required(),setup:zt().default([]).optional(),cases:u.array().items(u.object().keys({actionsBeforeTesting:zt().default([]).optional()}).required()).required()}).required().custom(n=>({...n,script:n.event}))})],O);var _t=false;function Oe(n){return function(t){if(_t)console.error("There can be only one definition generator!");else {_t=true;let e=[...n.modules];h.isInitialized&&(e=[v,x,...e,F,O]),ft.process(e,n.indexFilePretext,n.outputIndexFile);}}}var Rt=class{};var Ft=()=>u.array().items(u.array().items(Ut().required()).min(3).required()).min(1),Ut=()=>u.object().keys({x:u.number().required(),y:u.number().required()}),je=()=>u.string().pattern(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/).custom(n=>ColorHelper.stringColorToRGBColor(n)),Je=()=>u.number().min(-Math.PI).max(Math.PI),ke=(n,t)=>u.array().items(n).max(t).custom(e=>{if(e.length>t)throw new Error(`Array exceeds maximum size of ${t}`);for(;e.length<t;)e.push(void 0);return e}).default(ArrayHelper.createEmptyArray(t)).optional();var $=class extends g{async process(t,e){await e.addFile({path:"/_premade/assets/sprites.ts",preText:"import { AssetDefinition } from 'bard-legends-framework';",variableName:"SpriteAssets",variableType:"readonly AssetDefinition[]",assetUrl:"url",variable:t.map(i=>({id:i.id,url:i.url.url}))}),await e.addFile({path:"/_premade/asset-definitions/sprites.ts",preText:'import { SpriteDefinition } from "bard-legends-framework";',variableName:"SpriteDefinitions",variableType:"Readonly<Record<string, SpriteDefinition>>",variable:JsonHelper.arrayToObject(t,"id",{transformFunction:i=>({id:i.id,size:i.url.size,scale:i.scale,anchor:i.anchor,boundingShapes:i.boundingShapes})})});}};$=w([T({componentName:"SPRITE",keyName:"id",validationSchema:u.object().keys({id:u.string().required(),url:u.string().sprite().required(),scale:u.number().min(.1).max(1).default(1).optional(),anchor:u.object().keys({x:u.number().min(0).max(1).required(),y:u.number().min(0).max(1).required()}).default({x:.5,y:.5}).optional(),boundingShapes:Ft().optional()}).positionOnSprite({selectSpriteDefinition:n=>n,positionsJsonPath:["$..boundingShapes[*][*]"],includeRotationFromAnchor:false}).required()})],$);var Ae=()=>u.string().reference($).custom(n=>{let t=m.getDefinitionOrFail($,n);if(t.url.size.x%4!==0)throw new Error(`Sprite width must be multiplier of four in order to keep the pixel perfection. Got: '${t.url.size.x}'`);if(t.url.size.y%4!==0)throw new Error(`Sprite height must be multiplier of four in order to keep the pixel perfection. Got: '${t.url.size.y}'`);return n}),Be=n=>u.string().reference($).custom(t=>{let e=m.getDefinitionOrFail($,t);if(n?.size){if(e.url.size.x!==n.size.x)throw new Error(`Sprite width must be '${n.size.x}px'. Got: '${e.url.size.x}'`);if(e.url.size.y!==n.size.y)throw new Error(`Sprite height must be '${n.size.y}px'. Got: '${e.url.size.y}'`)}if(n?.scale&&e.scale!==n.scale)throw new Error(`Sprite '${t}' scale must be '${n.scale}'. Got: '${e.scale}'`);return t});var z=class extends g{async process(t,e){await e.addFile({path:"/_premade/asset-definitions/sprite-groups.ts",preText:"",variableName:"SpriteGroupDefinitions",variableType:"Readonly<Record<string, readonly string[]>>",variable:JsonHelper.arrayToObject(t,"id",{transformFunction:i=>i.group})});}};z=w([T({componentName:"SPRITE-GROUP",keyName:"id",validationSchema:u.object().keys({id:u.string().required(),group:u.array().items(u.string().reference($)).unique().required()}).required()})],z);var ze=`
44
44
  export interface FontDefinition {
45
45
  readonly id: string;
46
46
  readonly fontFamily: string;
47
- }`,_=class extends g{constructor(){super(),j.addPremadeInterface(ze);}async process(t,e){await e.addFile({path:"/_premade/assets/fonts.ts",preText:"import { AssetDefinition } from 'bard-legends-framework';",variableName:"FontAssets",variableType:"readonly AssetDefinition[]",assetUrl:"url",variable:t.map(i=>({id:i.id,url:i.url}))}),await e.addFile({path:"/_premade/asset-definitions/fonts.ts",preText:'import { FontDefinition } from "../../";',variableName:"FontDefinitions",variableType:"Readonly<Record<string, FontDefinition>>",variable:JsonHelper.arrayToObject(t,"id",{transformFunction:i=>({id:i.id,fontFamily:i.fontFamily})})});}};_=w([T({componentName:"FONT",keyName:"id",validationSchema:u.object().keys({id:u.string().required(),fontFamily:u.string().required(),url:u.string().path().required()}).required()})],_);export{g as DefinitionComponent,T as DefinitionComponentDecorator,Rt as DefinitionGenerator,Oe as DefinitionGeneratorDecorator,m as DefinitionStore,x as EventComponent,O as EventTestComponent,Je as FixedArraySchema,_ as FontComponent,je as HexColorSchema,H as JoiCustomValidators,Ae as PixelPerfectSpriteSchema,Ft as PoligonSchema,ye as RichTextSchema,ke as RotationSchema,v as ScriptComponent,F as ScriptTestComponent,$t as ScriptTesting,rt as SingleDefinitionComponent,$ as SpriteComponent,z as SpriteGroupComponent,Be as SpriteSchema,R as Validator,Ut as Vec2Schema};
47
+ }`,_=class extends g{constructor(){super(),j.addPremadeInterface(ze);}async process(t,e){await e.addFile({path:"/_premade/assets/fonts.ts",preText:"import { AssetDefinition } from 'bard-legends-framework';",variableName:"FontAssets",variableType:"readonly AssetDefinition[]",assetUrl:"url",variable:t.map(i=>({id:i.id,url:i.url}))}),await e.addFile({path:"/_premade/asset-definitions/fonts.ts",preText:'import { FontDefinition } from "../../";',variableName:"FontDefinitions",variableType:"Readonly<Record<string, FontDefinition>>",variable:JsonHelper.arrayToObject(t,"id",{transformFunction:i=>({id:i.id,fontFamily:i.fontFamily})})});}};_=w([T({componentName:"FONT",keyName:"id",validationSchema:u.object().keys({id:u.string().required(),fontFamily:u.string().required(),url:u.string().path().required()}).required()})],_);export{g as DefinitionComponent,T as DefinitionComponentDecorator,Rt as DefinitionGenerator,Oe as DefinitionGeneratorDecorator,m as DefinitionStore,x as EventComponent,O as EventTestComponent,ke as FixedArraySchema,_ as FontComponent,je as HexColorSchema,H as JoiCustomValidators,Ae as PixelPerfectSpriteSchema,Ft as PoligonSchema,ye as RichTextSchema,Je as RotationSchema,v as ScriptComponent,F as ScriptTestComponent,$t as ScriptTesting,rt as SingleDefinitionComponent,$ as SpriteComponent,z as SpriteGroupComponent,Be as SpriteSchema,R as Validator,Ut as Vec2Schema};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "definition-generator-framework",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "description": "Definition Generator Framework",
5
5
  "main": "dist/index.js",
6
6
  "publishConfig": {
@@ -36,6 +36,7 @@
36
36
  "build": "npx ts-node scripts/generate-mangle-cache.ts && tsup && npx ts-node scripts/remove-private-properties-from-build.ts && npm run restart-vitest",
37
37
  "restart-vitest": "touch vitest.config.ts",
38
38
  "lint": "biome check . --write --max-diagnostics=1",
39
+ "type-check": "tsc --noEmit",
39
40
  "deploy": "vitest run && npm run build && npm publish",
40
41
  "prepack": "cp package.json package.json.bak && ts-node scripts/prepare-package-json.ts",
41
42
  "postpack": "mv package.json.bak package.json"