@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
51 lines (50 loc) • 1.71 kB
JavaScript
;
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";
class AnyEventParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param toggle on to ensure events are transfered */
this.active = ParamConfig.BOOLEAN(1);
/** @param number of possible events */
this.inputsCount = ParamConfig.INTEGER(5, {
range: [1, 10],
rangeLocked: [true, false]
});
}
}
const ParamsConfig = new AnyEventParamsConfig();
export class AnyEventNode extends TypedEventNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
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 processEvent(event_context) {
if (this.p.active.isDirty()) {
await this.p.active.compute();
}
if (isBooleanTrue(this.pv.active)) {
this.dispatchEventToOutput(OUTPUT_NAME, event_context);
}
}
}