@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
48 lines (41 loc) • 1.49 kB
text/typescript
/**
* Blocks incoming envetts
*
* @remarks
* This can be useful to debug events, to prevents incoming events to be propagatted further.
*
*
*/
import {TypedEventNode} from './_Base';
import {EventConnectionPoint, EventConnectionPointType} from '../utils/io/connections/Event';
import {NodeParamsConfig, ParamConfig} from '../utils/params/ParamsConfig';
import {isBooleanTrue} from '../../../core/BooleanValue';
import { EventContext } from '../../../core/event/EventContextType';
class BlockParamsConfig extends NodeParamsConfig {
/** @param toggle on to block incoming events */
blocking = ParamConfig.BOOLEAN(1);
}
const ParamsConfig = new BlockParamsConfig();
export class BlockEventNode extends TypedEventNode<BlockParamsConfig> {
override paramsConfig = ParamsConfig;
static override type() {
return 'block';
}
static readonly OUTPUT = 'output';
override initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new EventConnectionPoint('in', EventConnectionPointType.BASE, this._process_incoming_event.bind(this)),
]);
this.io.outputs.setNamedOutputConnectionPoints([
new EventConnectionPoint(BlockEventNode.OUTPUT, EventConnectionPointType.BASE),
]);
}
private trigger_output(context: EventContext<MouseEvent>) {
this.dispatchEventToOutput(BlockEventNode.OUTPUT, context);
}
private _process_incoming_event(context: EventContext<MouseEvent>) {
if (!isBooleanTrue(this.pv.blocking)) {
this.trigger_output(context);
}
}
}