diff --git a/js/animations/animation.js b/js/animations/animation.js index b49b0c33..4eed552f 100644 --- a/js/animations/animation.js +++ b/js/animations/animation.js @@ -773,10 +773,10 @@ class Animation { ]) new Property(Animation, 'boolean', 'saved', {default: true, condition: () => Format.animation_files}) new Property(Animation, 'string', 'path', {condition: () => isApp && Format.animation_files}) - new Property(Animation, 'molang', 'anim_time_update'); - new Property(Animation, 'molang', 'blend_weight'); - new Property(Animation, 'molang', 'start_delay'); - new Property(Animation, 'molang', 'loop_delay'); + new Property(Animation, 'molang', 'anim_time_update', {default: ''}); + new Property(Animation, 'molang', 'blend_weight', {default: ''}); + new Property(Animation, 'molang', 'start_delay', {default: ''}); + new Property(Animation, 'molang', 'loop_delay', {default: ''}); Blockbench.on('finish_edit', event => { if (!Format.animation_files) return; diff --git a/js/preview/transformer.js b/js/preview/transformer.js index e1f8ac63..8220c1eb 100644 --- a/js/preview/transformer.js +++ b/js/preview/transformer.js @@ -1374,7 +1374,7 @@ var round_num = getRotationInterval(event) } else { value = point[axis] - if (axis == 'e') value = point.length()/8 * Math.sign(point.y||point.x); + if (axis == 'e') value = point.length() * Math.sign(point.y||point.x); var round_num = canvasGridSize(event.shiftKey || Pressing.overrides.shift, event.ctrlOrCmd || Pressing.overrides.ctrl) if (Toolbox.selected.id === 'resize_tool') { value *= (scope.direction) ? 0.1 : -0.1; diff --git a/js/validator.js b/js/validator.js index f7069ce8..7705baad 100644 --- a/js/validator.js +++ b/js/validator.js @@ -3,25 +3,34 @@ const Validator = { warnings: [], errors: [], + _timeout: null, validate(trigger) { - Validator.warnings.empty(); - Validator.errors.empty(); - + if (this._timeout) { + clearTimeout(this._timeout); + this._timeout = null; + } if (!Project) return; - Validator.checks.forEach(check => { - try { - if (!Condition(check.condition)) return; - if (!trigger || check.update_triggers.includes(trigger)) { - check.update(); + this._timeout = setTimeout(() => { + this._timeout = null; + Validator.warnings.empty(); + Validator.errors.empty(); + + Validator.checks.forEach(check => { + try { + if (!Condition(check.condition)) return; + + if (!trigger || check.update_triggers.includes(trigger)) { + check.update(); + } + Validator.warnings.push(...check.warnings); + Validator.errors.push(...check.errors); + + } catch (error) { + console.error(error); } - Validator.warnings.push(...check.warnings); - Validator.errors.push(...check.errors); - - } catch (error) { - console.error(error); - } - }) + }) + }, 400) }, openDialog() { if (!Validator.dialog) { @@ -208,16 +217,23 @@ new ValidatorCheck('molang_syntax', { let check = this; function validateMolang(string, message, instance) { if (!string || typeof string !== 'string') return; + let clear_string = string.replace(/'.*'/g, '0'); let issues = []; - if (string.match(/([-+*/]\s*[+*/])|(\+\s*-)/)) { + if (clear_string.match(/([-+*/]\s*[+*/])|(\+\s*-)/)) { issues.push('Two directly adjacent operators'); } - if (string.match(/[\w.]\s+[\w.]/)) { + if (clear_string.match(/^[+*/.,?=&<>|]/)) { + issues.push('Expression starts with an invalid character'); + } + if (clear_string.match(/(?!')[a-df-z_]+\s*[-?]+\s*[a-z_]+/i)) { + issues.push('Invalid expression "' + clear_string.match(/(?!')[a-df-z_]+\s*[-?]+\s*[a-z_]+/i)[0] + '"'); + } + if (clear_string.match(/[\w.]\s+[\w.]/)) { issues.push('Two expressions with no operator in between'); } - if (string.match(/[^\w\s+\-*/().,[\]!?=<>&|]/)) { - issues.push('Invalid character: ' + string.match(/[^\w+\-*/().,[\]!?=<>&|]+/g).join(', ')); + if (clear_string.match(/[^\w\s+\-*/().,;[\]!?=<>&|]/)) { + issues.push('Invalid character: ' + clear_string.match(/[^\w+\-*/().,;[\]!?=<>&|]+/g).join(', ')); } let left = string.match(/\(/g) || 0; let right = string.match(/\)/g) || 0;