@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
68 lines (67 loc) • 2.77 kB
JavaScript
;
import { TRIGGER_CONNECTION_NAME, TypedJsNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF } from "../utils/io/connections/Js";
import { JsType } from "../../poly/registers/nodes/types/Js";
import { inputObject3D } from "./_BaseObject3D";
import { Poly } from "../../Poly";
import { InitFunctionJsDefinition } from "./utils/JsDefinition";
import { nodeMethodName } from "./code/assemblers/actor/ActorAssemblerUtils";
var OnObjectDispatchEventJsNodeInputName = /* @__PURE__ */ ((OnObjectDispatchEventJsNodeInputName2) => {
OnObjectDispatchEventJsNodeInputName2["eventName"] = "eventName";
return OnObjectDispatchEventJsNodeInputName2;
})(OnObjectDispatchEventJsNodeInputName || {});
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
class OnObjectDispatchEventJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param event names (space separated) */
this.eventNames = ParamConfig.STRING("my-eventA my-eventB");
}
}
const ParamsConfig = new OnObjectDispatchEventJsParamsConfig();
export class OnObjectDispatchEventJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return JsType.ON_OBJECT_DISPATCH_EVENT;
}
isTriggering() {
return true;
}
initializeNode() {
super.initializeNode();
this.io.connection_points.spare_params.setInputlessParamNames(["eventNames"]);
this.io.inputs.setNamedInputConnectionPoints([]);
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS),
new JsConnectionPoint(
"eventName" /* eventName */,
JsConnectionPointType.STRING,
CONNECTION_OPTIONS
)
]);
}
setTriggeringLines(shadersCollectionController, triggeredMethods) {
const object3D = inputObject3D(this, shadersCollectionController);
const eventNames = this.variableForInputParam(shadersCollectionController, this.p.eventNames);
const func = Poly.namedFunctionsRegister.getFunction(
"objectAddEventListeners",
this,
shadersCollectionController
);
const bodyLine = func.asString(object3D, eventNames, `this`, `this.${nodeMethodName(this)}.bind(this)`);
shadersCollectionController.addDefinitions(this, [
new InitFunctionJsDefinition(
this,
shadersCollectionController,
JsConnectionPointType.OBJECT_3D,
this.path(),
bodyLine
)
]);
shadersCollectionController.addTriggeringLines(this, [triggeredMethods], { gatherable: false });
}
}