2021SC@SDUSC
接下来是对Option类的分析
Option类具有一个枚举,用来对基本数据类型进行标识
Option类具有以下的基础参数
其中id是进行唯一标识作用
type表示类型
name表示Option的名字
dafault_value表示Option中的默认值
并具有着callback参数进行回调操作
然后具有着onChange参数用来对Option发生变化时进行修改操作
然后进行初始化与get、set
Option.prototype.initialize = function(id, tool_id, type, name, default_value, options, callback) {
this._id = id;
this._tool_id = tool_id;
this._type = type;
this._name = name;
this._default_value = default_value;
this._options = options;
this._callback = callback;
this._on_change = this.onChange.bind(this);
}
Object.defineProperty(Option.prototype, 'id', {
get: function() {
return this._id;
},
configurable: true
});
Object.defineProperty(Option.prototype, 'tool_id', {
get: function() {
return this._tool_id;
},
configurable: true
});
Object.defineProperty(Option.prototype, 'type', {
get: function() {
return this._type;
},
configurable: true
});
Object.defineProperty(Option.prototype, 'name', {
get: function() {
return this._name;
},
configurable: true
});
Object.defineProperty(Option.prototype, 'default_value', {
get: function() {
return this._default_value;
},
configurable: true
});
Object.defineProperty(Option.prototype, 'options', {
get: function() {
return this._options;
},
configurable: true
});
Object.defineProperty(Tool.prototype, 'callback', {
get: function() {
return this._callback;
},
configurable: true
});
Object.defineProperty(Option.prototype, 'on_change', {
get: function() {
return this._on_change;
},
configurable: true
});
实现onchange方法来进行当id变化时进行执行
Option.prototype.onChange = function(value){
OptionManager.setValue(this._tool_id, this._id, value);
if(this._callback) {
this._callback.call(this);
}
Engine.updateEditorOptionData();
};