mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-01-06 12:35:36 +08:00
3f18ea7bc2
Implement #1392 Assign different particles to each entry in same particle keyframe Fix issue with variables in particle curves Fix #1426 "Jump to Animation Start" does not stop the sound that was playing
2 lines
7.2 KiB
JavaScript
2 lines
7.2 KiB
JavaScript
!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),(e<r||isNaN(e))&&(e=r),e),random:(e,r)=>e+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;a<e;a++)n+=this.random(r,t);return n},dieRollInt(e,r,t){e=this.clamp(e,0,1e9);let n=0;for(var a=0;a<e;a++)n+=this.randomInt(r,t);return n},lerp:(e,r,t)=>e+(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<e.length-1;r++){switch(e[r]){case"(":t++;break;case")":t--}if(0==t)return!1}return!0}}function p(e,r,t,n){var a=g(e,r,n);if(a)return new i(t,a[0],a[1])}function g(e,r,t){for(var n=t?-1:1,a=t?e.length-1:0,s=0,u="string"==typeof r;t?a>=0:a<e.length;){if("("===e[a])s+=n;else if(")"===e[a])s-=n;else if(0===s){var i=e.substr(a,r.length);if(u&&i===r&&("-"!==r||!1==="+*/<>=|&?:".includes(e[a-1])))return[e.substr(0,a),e.substr(a+r.length)];if(!u)for(var c=0;c<r.length;c++)if(r[c]===i)return[e.substr(0,a),e.substr(a+r[c].length)]}a+=n}}function d(e,r){return"string"==typeof e&&"'"==e[0]||(e=w(e,!0)),"string"==typeof r&&"'"==r[0]||(r=w(r,!0)),e===r}function w(a,u){if(s=!1,"number"==typeof a)return a;if("string"==typeof a){if(void 0!==t[a])return t[a];var h=n[a];return void 0===h&&"function"==typeof e.variableHandler&&(h=e.variableHandler(a,n)),"string"!=typeof h||u?void 0===h?s=!0:"function"==typeof h&&(h=h()):h=e.parse(h,n),h||0}if(a instanceof o)return w(a.value);if(a instanceof l)return n[a.name]=e.variables[a.name]=w(a.value);if(a instanceof c){let r=a.args.map((e=>w(e)));return"function"==typeof n[a.query]?n[a.query](...r):("function"==typeof e.variableHandler&&(h=e.variableHandler(a.query,n,r)),0)}if(a instanceof i)switch(a.operator){case 1:return w(a.a)+w(a.b);case 2:return w(a.a)-w(a.b);case 3:return w(a.a)*w(a.b);case 4:return w(a.a)/w(a.b);case 5:return 0==w(a.a)?1:0;case 10:return w(a.a)?w(a.b):w(a.c);case 11:return w(a.a)&&w(a.b)?1:0;case 12:return w(a.a)||w(a.b)?1:0;case 13:return w(a.a)<w(a.b)?1:0;case 14:return w(a.a)<=w(a.b)?1:0;case 15:return w(a.a)>w(a.b)?1:0;case 16:return w(a.a)>=w(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=w(a.a);return s?w(a.b):b;case 100:return Math.abs(w(a.a));case 101:return Math.sin(w(a.a)*f());case 102:return Math.cos(w(a.a)*f());case 103:return Math.exp(w(a.a));case 104:return Math.log(w(a.a));case 105:return Math.pow(w(a.a),w(a.b));case 106:return Math.sqrt(w(a.a));case 107:return r.random(w(a.a),w(a.b));case 108:return Math.ceil(w(a.a));case 109:return Math.round(w(a.a));case 110:return Math.trunc(w(a.a));case 111:return Math.floor(w(a.a));case 112:return w(a.a)%w(a.b);case 113:return Math.min(w(a.a),w(a.b));case 114:return Math.max(w(a.a),w(a.b));case 115:return r.clamp(w(a.a),w(a.b),w(a.c));case 116:return r.lerp(w(a.a),w(a.b),w(a.c));case 117:return r.lerpRotate(w(a.a),w(a.b),w(a.c));case 118:return Math.asin(w(a.a))/f();case 119:return Math.acos(w(a.a))/f();case 120:return Math.atan(w(a.a))/f();case 121:return Math.atan2(w(a.a),w(a.b))/f();case 122:return r.dieRoll(w(a.a),w(a.b),w(a.c));case 123:return r.dieRollInt(w(a.a),w(a.b),w(a.c));case 124:let e=w(a.a);return 3*Math.pow(e,2)-2*Math.pow(e,3);case 125:return r.randomInt(w(a.a),w(a.b))}return 0}this.parse=(r,t)=>{if("number"==typeof r)return isNaN(r)?0:r;if("string"!=typeof r)return 0;var s;if((s=(s=r).toLowerCase().trim()).includes(";")&&(s=s.replace(/;\s+/g,";").replace(/;\s*$/,"")),""===(r=s))return 0;if(r.length<9&&!isNaN(r)&&r)return parseFloat(r);let i;return this.cache_enabled&&a[r]?i=a[r]:(i=new u(r),this.cache_enabled&&(a[r]=i)),function(r,t){for(var a in e.global_variables)n[a]=e.global_variables[a];for(var a in e.variables)n[a]=e.variables[a];if(t)for(var a in t)n[a]=t[a];let s=0,u=0;for(let e of r.lines){let t=w(e);if(s++,s==r.lines.length||e instanceof o&&"return"===e.type){u=t;break}}return n={},u}(i,t)},this.resetVariables=()=>{e.variables={}}}}));
|