UNPKG

polygonjs-engine

Version:

node-based webgl 3D engine https://polygonjs.com

47 lines (46 loc) 1.51 kB
import {TypedEventNode} from "./_Base"; import {EventConnectionPointType} from "../utils/io/connections/Event"; const OUTPUT_NAME = "event"; import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig"; class AnyEventParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.active = ParamConfig.BOOLEAN(1); this.inputsCount = ParamConfig.INTEGER(5, { range: [1, 10], rangeLocked: [true, false] }); } } const ParamsConfig2 = new AnyEventParamsConfig(); export class AnyEventNode extends TypedEventNode { constructor() { super(...arguments); this.params_config = ParamsConfig2; } static type() { return "any"; } initializeNode() { this.io.connection_points.set_expected_input_types_function(this._expected_input_types.bind(this)); this.io.connection_points.set_input_name_function(this._input_name.bind(this)); this.io.connection_points.set_output_name_function(() => OUTPUT_NAME); this.io.connection_points.set_expected_output_types_function(() => [EventConnectionPointType.BASE]); } _expected_input_types() { const list = new Array(this.pv.inputsCount); list.fill(EventConnectionPointType.BASE); return list; } _input_name(index) { return `trigger${index}`; } async process_event(event_context) { if (this.p.active.isDirty()) { await this.p.active.compute(); } if (this.pv.active) { this.dispatch_event_to_output(OUTPUT_NAME, event_context); } } }