Impove molang validation

Fix uniform keyframe scaling being slow
Accumulate validation requests
This commit is contained in:
JannisX11 2022-08-23 17:29:45 +02:00
parent 45421d0735
commit f57ecc9a3f
3 changed files with 40 additions and 24 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;