import { BaseModel } from './base-model'; import { Servicer } from '../servicer/servicer'; import { MessageType } from '../core/message-type'; import { Param } from '../core/handlers/filter-handler'; import { FilterType } from '../enums/filter-type'; const commands = MessageType.filter; /** * 滤镜实体 */ export class Filter extends BaseModel { private _type: FilterType; private _name: string; private _params: { [key in string]: Param }; constructor( obj: { id: string, params: { [key in string]: Param }, type: FilterType, name: string }, servicer: Servicer ) { super(obj.id, servicer); this._type = obj.type; this._name = obj.name; this._params = obj.params; } get type() { return this._type; } get name() { return this._name; } get params() { return this._params; } async destory() { await this.servicer.do(commands.destory, [this.id]); } /** * 同步底层的滤镜参数列表 */ async syncParams() { const params: { [key in string]: Param } = await this.servicer.do(commands.getParams, [this.id]); this._params = params; return params; } /** * 更新滤镜参数 * @param name - 参数名 * @param value - 参数值 */ async updateParamValue(name: string, value: any) { const param = this.params[name]; if(param) { if(!Array.isArray(value)) { value = [value]; } await this.servicer.do(commands.updateParam, [this.id, name, value]); param.array = value; } } }