UNPKG

@polygonjs/polygonjs

Version:

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

81 lines (80 loc) 3.07 kB
"use strict"; import { TRIGGER_CONNECTION_NAME } 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 { BaseUserInputJsNode } from "./_BaseUserInput"; import { CoreEventEmitter, EVENT_EMITTERS, EVENT_EMITTER_PARAM_MENU_OPTIONS } from "../../../core/event/CoreEventEmitter"; import { PointerEventType } from "../../../core/event/PointerEventType"; import { TouchEventType } from "../../../core/event/TouchEventType"; import { isTouchDevice } from "../../../core/UserAgent"; import { inputObject3D } from "./_BaseObject3D"; import { Poly } from "../../Poly"; import { InitFunctionJsDefinition } from "./utils/JsDefinition"; import { nodeMethodName } from "./code/assemblers/actor/ActorAssemblerUtils"; const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF; class OnPointerupJsParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param set which element triggers the event */ this.element = ParamConfig.INTEGER(EVENT_EMITTERS.indexOf(CoreEventEmitter.CANVAS), { ...EVENT_EMITTER_PARAM_MENU_OPTIONS, separatorAfter: true }); } } const ParamsConfig = new OnPointerupJsParamsConfig(); export class OnPointerupJsNode extends BaseUserInputJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return JsType.ON_POINTERUP; } isTriggering() { return true; } eventData() { if (isTouchDevice()) { return { type: TouchEventType.touchend, emitter: this.eventEmitter(), jsType: JsType.ON_POINTERUP }; } else { return { type: PointerEventType.pointerup, emitter: this.eventEmitter(), jsType: JsType.ON_POINTERUP }; } } eventEmitter() { return EVENT_EMITTERS[this.pv.element]; } setEventEmitter(emitter) { this.p.element.set(EVENT_EMITTERS.indexOf(emitter)); } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS) ]); } setTriggeringLines(linesController, triggeredMethods) { const object3D = inputObject3D(this, linesController); const func = Poly.namedFunctionsRegister.getFunction("addObjectToPointerupCheck", this, linesController); const options = { pointerup: { callback: `this.${nodeMethodName(this)}.bind(this)` } }; const jsonOptions = JSON.stringify(options).replace(/"/g, ""); const bodyLine = func.asString(object3D, `this`, jsonOptions); linesController.addDefinitions(this, [ new InitFunctionJsDefinition(this, linesController, JsConnectionPointType.OBJECT_3D, this.path(), bodyLine) ]); linesController.addTriggeringLines(this, [triggeredMethods], { gatherable: true }); } }