owl-bt
Version:
owl-bt is editor for Behavior trees. It has been inspired by Unreal engine behavior trees in a way, that it supports special node items like decorators and services. This makes trees smaller and much more readable.
46 lines (38 loc) • 1.21 kB
JavaScript
;
(function () {
class PropertyValidator {
constructor(_) {
this._ = _;
}
isValid(value, propertyDesc, customTypeDesc) {
if (this._.isNil(value)) {
return true;
}
if (customTypeDesc) {
if (customTypeDesc.pattern) {
return this._patternIsValid(value, customTypeDesc.pattern);
}
} else {
if (propertyDesc.type === 'number') {
return this._minMaxIsValid(value, propertyDesc);
}
}
return true;
}
_patternIsValid(value, pattern) {
var regex = new RegExp(`^${pattern}$`);
return regex.test(value);
}
_minMaxIsValid(value, propertyDesc) {
if (!_.isNil(propertyDesc.min) && value < propertyDesc.min) {
return false;
}
if (!_.isNil(propertyDesc.max) && value > propertyDesc.max) {
return false;
}
return true;
}
}
angular.module('editorApp')
.service('PropertyValidator', PropertyValidator);
})();