diff --git a/js/animations/animation.js b/js/animations/animation.js index 8872917e8..1a8627bc7 100644 --- a/js/animations/animation.js +++ b/js/animations/animation.js @@ -312,7 +312,7 @@ class Animation { if (data) { let animation = content.animations[this.name]; content = data; - if (this.saved_name) delete content.animations[this.saved_name]; + if (this.saved_name && this.saved_name !== this.name) delete content.animations[this.saved_name]; content.animations[this.name] = animation; // Sort diff --git a/lib/molang.umd.js b/lib/molang.umd.js index b110e574d..9e1b6213f 100644 --- a/lib/molang.umd.js +++ b/lib/molang.umd.js @@ -1 +1 @@ -!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).Molang=r()}(this,(function(){"use strict";const e=e=>((e+180)%360+180)%360;var r={clamp:(e,r,t)=>(e>t&&(e=t),(ee+Math.random()*(r-e),randomInt:(e,r)=>(e=Math.ceil(e),r=Math.floor(r),e+Math.floor(Math.random()*(r-e+1))),dieRoll(e,r,t){e=this.clamp(e,0,1e9);let n=0;for(var a=0;ae+(r-e)*t,lerpRotate(r,t,n){let a=e(r),s=e(t);a>s&&([a,s]=[s,a]);var u=s-a;return u>180?e(s+n*(360-u)):a+n*u}};const t={true:1,false:0};return function(){const e=this;this.global_variables={},this.cache_enabled=!0,this.use_radians=!1,this.variables={},this.variableHandler=null;let n={},a=!1;function s(e){this.lines=e.split(";").map((e=>f(e)))}function u(e,r,t,n){this.operator=e,this.a=f(r),void 0!==t&&(this.b=f(t)),void 0!==n&&(this.c=f(n))}function i(e,r){this.query=e,this.args=r.map((e=>f(e)))}function c(e,r){this.value=f(r),this.name=e}function l(e,r){this.value=f(r),this.type=e}let o=()=>this.use_radians?1:Math.PI/180;function f(e){if(!e)return 0;if(!isNaN(e))return parseFloat(e);for(e=e.replace(/\s/g,"");h(e);)e=e.substr(1,e.length-2);var r;if(r=e.length>5&&e.match(/^return/))return new l(r[0],e.substr(r[0].length));if("."==e.substring(1,2)){let r=e.substring(0,1);"q"==r&&(e="query"+e.substring(1)),"v"==r&&(e="variable"+e.substring(1)),"t"==r&&(e="temp"+e.substring(1)),"c"==r&&(e="context"+e.substring(1))}if((r=e.length>4&&e.match(/(temp|variable)\.\w+=/))&&"="!==e[r.index+r[0].length]){return new c(r[0].replace(/=$/,""),e.substr(r.index+r[0].length))}if(t=b(e,"??",19))return t;var t,n=p(e,"?");if(n){let e=p(n[1],":");return e&&e.length?new u(10,n[0],e[0],e[1]):new u(10,n[0],n[1],0)}if(t=b(e,"&&",11)||b(e,"||",12)||b(e,"<=",14)||b(e,"<",13)||b(e,">=",16)||b(e,">",15)||b(e,"==",17)||b(e,"!=",18)||b(e,"+",1,!0)||function(e,r,t,n){var a=p(e,r,n);if(a){if(0===a[0].length)return new u(t,0,a[1]);if(!1==="+*/<>=|&?:".includes(a[0].substr(-1)))return new u(t,a[0],a[1])}}(e,"-",2,!0)||b(e,"*",3)||b(e,"/",4,!0)||function(e,r){if(e[0]==r&&e.length>1)return new u(5,e.substr(1),0)}(e,"!"))return t;if("math."===e.substr(0,5)){if("math.pi"===e.substr(0,7))return Math.PI;let r=e.search(/\(/),t=e.substr(5,r-5),n=e.substr(r+1,e.length-r-2),s=p(n,",")||[n];if(s.length>1){var a=p(s[1],",");a&&a.length>1&&(s[1]=a[0],s[2]=a[1])}switch(t){case"abs":return new u(100,s[0]);case"sin":return new u(101,s[0]);case"cos":return new u(102,s[0]);case"exp":return new u(103,s[0]);case"ln":return new u(104,s[0]);case"pow":return new u(105,s[0],s[1]);case"sqrt":return new u(106,s[0]);case"random":return new u(107,s[0],s[1]);case"ceil":return new u(108,s[0]);case"round":return new u(109,s[0]);case"trunc":return new u(110,s[0]);case"floor":return new u(111,s[0]);case"mod":return new u(112,s[0],s[1]);case"min":return new u(113,s[0],s[1]);case"max":return new u(114,s[0],s[1]);case"clamp":return new u(115,s[0],s[1],s[2]);case"lerp":return new u(116,s[0],s[1],s[2]);case"lerprotate":return new u(117,s[0],s[1],s[2]);case"asin":return new u(118,s[0]);case"acos":return new u(119,s[0]);case"atan":return new u(120,s[0]);case"atan2":return new u(121,s[0],s[1]);case"die_roll":return new u(122,s[0],s[1],s[2]);case"die_roll_integer":return new u(123,s[0],s[1],s[2]);case"hermite_blend":return new u(124,s[0]);case"random_integer":return new u(125,s[0],s[1],s[2])}}if((n=e.match(/[a-zA-Z0-9._]{2,}/g))&&1===n.length&&n[0].length>=e.length-2)return e;if(e.includes("(")&&")"==e[e.length-1]){let r,t=e.search(/\(/),n=e.substr(0,t),a=[e.substr(t+1,e.length-t-2)];for(;r=p(a[a.length-1],",");)a.splice(a.length-1,1,...r);return new i(n,a)}return 0}function h(e){if("("===e.substr(0,1)&&")"===e.substr(-1)){let t=0;for(var r=0;r=0:av(e)));return"function"==typeof e.variables[n.query]?e.variables[n.query](...r):"function"==typeof e.global_variables[n.query]?e.global_variables[n.query](...r):("function"==typeof e.variableHandler&&(f=e.variableHandler(n.query,e.variables,r)),0)}if(n instanceof u)switch(n.operator){case 1:return v(n.a)+v(n.b);case 2:return v(n.a)-v(n.b);case 3:return v(n.a)*v(n.b);case 4:return v(n.a)/v(n.b);case 5:return 0==v(n.a)?1:0;case 10:return v(n.a)?v(n.b):v(n.c);case 11:return v(n.a)&&v(n.b)?1:0;case 12:return v(n.a)||v(n.b)?1:0;case 13:return v(n.a)v(n.b)?1:0;case 16:return v(n.a)>=v(n.b)?1:0;case 17:return g(n.a,n.b)?1:0;case 18:return g(n.a,n.b)?0:1;case 19:var h=v(n.a);return a?v(n.b):h;case 100:return Math.abs(v(n.a));case 101:return Math.sin(v(n.a)*o());case 102:return Math.cos(v(n.a)*o());case 103:return Math.exp(v(n.a));case 104:return Math.log(v(n.a));case 105:return Math.pow(v(n.a),v(n.b));case 106:return Math.sqrt(v(n.a));case 107:return r.random(v(n.a),v(n.b));case 108:return Math.ceil(v(n.a));case 109:return Math.round(v(n.a));case 110:return Math.trunc(v(n.a));case 111:return Math.floor(v(n.a));case 112:return v(n.a)%v(n.b);case 113:return Math.min(v(n.a),v(n.b));case 114:return Math.max(v(n.a),v(n.b));case 115:return r.clamp(v(n.a),v(n.b),v(n.c));case 116:return r.lerp(v(n.a),v(n.b),v(n.c));case 117:return r.lerpRotate(v(n.a),v(n.b),v(n.c));case 118:return Math.asin(v(n.a))/o();case 119:return Math.acos(v(n.a))/o();case 120:return Math.atan(v(n.a))/o();case 121:return Math.atan2(v(n.a),v(n.b))/o();case 122:return r.dieRoll(v(n.a),v(n.b),v(n.c));case 123:return r.dieRollInt(v(n.a),v(n.b),v(n.c));case 124:let e=v(n.a);return 3*Math.pow(e,2)-2*Math.pow(e,3);case 125:return r.randomInt(v(n.a),v(n.b))}return 0}this.parse=(r,t)=>{if("number"==typeof r)return isNaN(r)?0:r;if("string"!=typeof r)return 0;var a;if((a=(a=r).toLowerCase().trim()).includes(";")&&(a=a.replace(/;\s+/g,";").replace(/;\s*$/,"")),r=a,this.cache_enabled&&n[r])var u=n[r];else{u=new s(r);this.cache_enabled&&(n[r]=u)}return function(r,t){if(t)for(var n in t)e.variables[n]=t[n];var a=0;for(var s of r.lines){let e=v(s);if(++a==r.lines.length||s instanceof l&&"return"===s.type)return e}return 0}(u,t)},this.resetVariables=()=>{e.variables={}}}})); +!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).Molang=r()}(this,(function(){"use strict";const e=e=>((e+180)%360+180)%360;var r={clamp:(e,r,t)=>(e>t&&(e=t),(ee+Math.random()*(r-e),randomInt:(e,r)=>(e=Math.ceil(e),r=Math.floor(r),e+Math.floor(Math.random()*(r-e+1))),dieRoll(e,r,t){e=this.clamp(e,0,1e9);let n=0;for(var a=0;ae+(r-e)*t,lerpRotate(r,t,n){let a=e(r),s=e(t);a>s&&([a,s]=[s,a]);var u=s-a;return u>180?e(s+n*(360-u)):a+n*u}};const t={true:1,false:0};return function(){const e=this;this.global_variables={},this.cache_enabled=!0,this.use_radians=!1,this.variables={},this.variableHandler=null;let n={},a={},s=!1;function u(e){this.lines=e.split(";").map((e=>h(e)))}function i(e,r,t,n){this.operator=e,this.a=h(r),void 0!==t&&(this.b=h(t)),void 0!==n&&(this.c=h(n))}function c(e,r){this.query=e,this.args=r.map((e=>h(e)))}function l(e,r){this.value=h(r),this.name=e}function o(e,r){this.value=h(r),this.type=e}let f=()=>this.use_radians?1:Math.PI/180;function h(e){if(!e)return 0;if(!isNaN(e))return parseFloat(e);for(e=e.replace(/\s/g,"");b(e);)e=e.substr(1,e.length-2);var r;if(r=e.length>5&&e.match(/^return/))return new o(r[0],e.substr(r[0].length));if("."==e.substring(1,2)){let r=e.substring(0,1);"q"==r&&(e="query"+e.substring(1)),"v"==r&&(e="variable"+e.substring(1)),"t"==r&&(e="temp"+e.substring(1)),"c"==r&&(e="context"+e.substring(1))}if((r=e.length>4&&e.match(/(temp|variable)\.\w+=/))&&"="!==e[r.index+r[0].length]){return new l(r[0].replace(/=$/,""),e.substr(r.index+r[0].length))}if(t=p(e,"??",19))return t;var t,n=g(e,"?");if(n){let e=g(n[1],":");return e&&e.length?new i(10,n[0],e[0],e[1]):new i(10,n[0],n[1],0)}if(t=p(e,"&&",11)||p(e,"||",12)||p(e,"<=",14)||p(e,"<",13)||p(e,">=",16)||p(e,">",15)||p(e,"==",17)||p(e,"!=",18)||p(e,"+",1,!0)||function(e,r,t){var n=g(e,r,!0);if(n)return 0===n[0].length?new i(t,0,n[1]):new i(t,n[0],n[1])}(e,"-",2)||p(e,"*",3)||p(e,"/",4,!0)||function(e,r){if(e[0]==r&&e.length>1)return new i(5,e.substr(1),0)}(e,"!"))return t;if("math."===e.substr(0,5)){if("math.pi"===e.substr(0,7))return Math.PI;let r=e.search(/\(/),t=e.substr(5,r-5),n=e.substr(r+1,e.length-r-2),s=g(n,",")||[n];if(s.length>1){var a=g(s[1],",");a&&a.length>1&&(s[1]=a[0],s[2]=a[1])}switch(t){case"abs":return new i(100,s[0]);case"sin":return new i(101,s[0]);case"cos":return new i(102,s[0]);case"exp":return new i(103,s[0]);case"ln":return new i(104,s[0]);case"pow":return new i(105,s[0],s[1]);case"sqrt":return new i(106,s[0]);case"random":return new i(107,s[0],s[1]);case"ceil":return new i(108,s[0]);case"round":return new i(109,s[0]);case"trunc":return new i(110,s[0]);case"floor":return new i(111,s[0]);case"mod":return new i(112,s[0],s[1]);case"min":return new i(113,s[0],s[1]);case"max":return new i(114,s[0],s[1]);case"clamp":return new i(115,s[0],s[1],s[2]);case"lerp":return new i(116,s[0],s[1],s[2]);case"lerprotate":return new i(117,s[0],s[1],s[2]);case"asin":return new i(118,s[0]);case"acos":return new i(119,s[0]);case"atan":return new i(120,s[0]);case"atan2":return new i(121,s[0],s[1]);case"die_roll":return new i(122,s[0],s[1],s[2]);case"die_roll_integer":return new i(123,s[0],s[1],s[2]);case"hermite_blend":return new i(124,s[0]);case"random_integer":return new i(125,s[0],s[1],s[2])}}if((n=e.match(/[a-zA-Z0-9._]{2,}/g))&&1===n.length&&n[0].length>=e.length-2)return e;if(e.includes("(")&&")"==e[e.length-1]){let r,t=e.search(/\(/),n=e.substr(0,t),a=[e.substr(t+1,e.length-t-2)];for(;r=g(a[a.length-1],",");)a.splice(a.length-1,1,...r);return new c(n,a)}return 0}function b(e){if("("===e.substr(0,1)&&")"===e.substr(-1)){let t=0;for(var r=0;r=0:a=|&?:".includes(e[a-1])))return[e.substr(0,a),e.substr(a+r.length)];if(!u)for(var c=0;cv(e)));return"function"==typeof e.variables[a.query]?e.variables[a.query](...r):"function"==typeof n[a.query]?n[a.query](...r):"function"==typeof e.global_variables[a.query]?e.global_variables[a.query](...r):("function"==typeof e.variableHandler&&(h=e.variableHandler(a.query,e.variables,r)),0)}if(a instanceof i)switch(a.operator){case 1:return v(a.a)+v(a.b);case 2:return v(a.a)-v(a.b);case 3:return v(a.a)*v(a.b);case 4:return v(a.a)/v(a.b);case 5:return 0==v(a.a)?1:0;case 10:return v(a.a)?v(a.b):v(a.c);case 11:return v(a.a)&&v(a.b)?1:0;case 12:return v(a.a)||v(a.b)?1:0;case 13:return v(a.a)v(a.b)?1:0;case 16:return v(a.a)>=v(a.b)?1:0;case 17:return d(a.a,a.b)?1:0;case 18:return d(a.a,a.b)?0:1;case 19:var b=v(a.a);return s?v(a.b):b;case 100:return Math.abs(v(a.a));case 101:return Math.sin(v(a.a)*f());case 102:return Math.cos(v(a.a)*f());case 103:return Math.exp(v(a.a));case 104:return Math.log(v(a.a));case 105:return Math.pow(v(a.a),v(a.b));case 106:return Math.sqrt(v(a.a));case 107:return r.random(v(a.a),v(a.b));case 108:return Math.ceil(v(a.a));case 109:return Math.round(v(a.a));case 110:return Math.trunc(v(a.a));case 111:return Math.floor(v(a.a));case 112:return v(a.a)%v(a.b);case 113:return Math.min(v(a.a),v(a.b));case 114:return Math.max(v(a.a),v(a.b));case 115:return r.clamp(v(a.a),v(a.b),v(a.c));case 116:return r.lerp(v(a.a),v(a.b),v(a.c));case 117:return r.lerpRotate(v(a.a),v(a.b),v(a.c));case 118:return Math.asin(v(a.a))/f();case 119:return Math.acos(v(a.a))/f();case 120:return Math.atan(v(a.a))/f();case 121:return Math.atan2(v(a.a),v(a.b))/f();case 122:return r.dieRoll(v(a.a),v(a.b),v(a.c));case 123:return r.dieRollInt(v(a.a),v(a.b),v(a.c));case 124:let e=v(a.a);return 3*Math.pow(e,2)-2*Math.pow(e,3);case 125:return r.randomInt(v(a.a),v(a.b))}return 0}this.parse=(e,r)=>{if("number"==typeof e)return isNaN(e)?0:e;if("string"!=typeof e)return 0;var t;let s;return(t=(t=e).toLowerCase().trim()).includes(";")&&(t=t.replace(/;\s+/g,";").replace(/;\s*$/,"")),e=t,this.cache_enabled&&a[e]?s=a[e]:(s=new u(e),this.cache_enabled&&(a[e]=s)),function(e,r){if(r)for(var t in r)n[t]=r[t];let a=0,s=0;for(let r of e.lines){let t=v(r);if(a++,a==e.lines.length||r instanceof o&&"return"===r.type){s=t;break}}return n={},s}(s,r)},this.resetVariables=()=>{e.variables={}}}}));