UNPKG

@polygonjs/polygonjs

Version:

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

57 lines (51 loc) 1.87 kB
/** * Receives multiple events * * @remarks * This is useful when you want to allow an downstream node to be triggered by multiple possible events * */ import {TypedEventNode} from './_Base'; import {EventConnectionPointType} from '../utils/io/connections/Event'; const OUTPUT_NAME = 'event'; import {NodeParamsConfig, ParamConfig} from '../utils/params/ParamsConfig'; import {isBooleanTrue} from '../../../core/BooleanValue'; import { EventContext } from '../../../core/event/EventContextType'; class AnyEventParamsConfig extends NodeParamsConfig { /** @param toggle on to ensure events are transfered */ active = ParamConfig.BOOLEAN(1); /** @param number of possible events */ inputsCount = ParamConfig.INTEGER(5, { range: [1, 10], rangeLocked: [true, false], }); } const ParamsConfig = new AnyEventParamsConfig(); export class AnyEventNode extends TypedEventNode<AnyEventParamsConfig> { override paramsConfig = ParamsConfig; static override type() { return 'any'; } override 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]); } private _expected_input_types() { const list: EventConnectionPointType[] = new Array(this.pv.inputsCount); list.fill(EventConnectionPointType.BASE); return list; } protected _input_name(index: number) { return `trigger${index}`; } override async processEvent(event_context: EventContext<Event>) { if (this.p.active.isDirty()) { await this.p.active.compute(); } if (isBooleanTrue(this.pv.active)) { this.dispatchEventToOutput(OUTPUT_NAME, event_context); } } }