@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
47 lines (46 loc) • 1.63 kB
JavaScript
;
import { TypedEventNode } from "./_Base";
import { EventConnectionPoint, EventConnectionPointType } from "../utils/io/connections/Event";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { isBooleanTrue } from "../../../core/BooleanValue";
class MessageParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param toggle on for the message to be displayed in a popup */
this.alert = ParamConfig.BOOLEAN(0);
/** @param toggle on for the message to be printed in the console */
this.console = ParamConfig.BOOLEAN(1);
}
}
const ParamsConfig = new MessageParamsConfig();
const _MessageEventNode = class extends TypedEventNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "message";
}
initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new EventConnectionPoint("trigger", EventConnectionPointType.BASE, this._process_trigger_event.bind(this))
]);
this.io.outputs.setNamedOutputConnectionPoints([
new EventConnectionPoint(_MessageEventNode.OUTPUT, EventConnectionPointType.BASE)
]);
}
trigger_output(context) {
this.dispatchEventToOutput(_MessageEventNode.OUTPUT, context);
}
_process_trigger_event(context) {
if (isBooleanTrue(this.pv.alert)) {
alert(context);
}
if (isBooleanTrue(this.pv.console)) {
console.log(this.path(), Date.now(), context);
}
this.trigger_output(context);
}
};
export let MessageEventNode = _MessageEventNode;
MessageEventNode.OUTPUT = "output";