UNPKG

@polygonjs/polygonjs

Version:

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

40 lines (39 loc) 1.26 kB
"use strict"; import { TypedEventNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { EventConnectionPoint, EventConnectionPointType } from "../utils/io/connections/Event"; const INPUT_NAME = "in"; const OUTPUT_NAME = "out"; class DelayEventParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param delay before dispatching (in milliseconds) */ this.delay = ParamConfig.INTEGER(1e3, { range: [0, 1e3], rangeLocked: [true, false] }); } } const ParamsConfig = new DelayEventParamsConfig(); export class DelayEventNode extends TypedEventNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "delay"; } initializeNode() { this.io.inputs.setNamedInputConnectionPoints([ new EventConnectionPoint(INPUT_NAME, EventConnectionPointType.BASE, this._process_input.bind(this)) ]); this.io.outputs.setNamedOutputConnectionPoints([ new EventConnectionPoint(OUTPUT_NAME, EventConnectionPointType.BASE) ]); } _process_input(event_context) { setTimeout(() => { this.dispatchEventToOutput(OUTPUT_NAME, event_context); }, this.pv.delay); } }