UNPKG

@polygonjs/polygonjs

Version:

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

66 lines (65 loc) 2.44 kB
"use strict"; import { Poly } from "../../Poly"; import { JsConnectionPointType } from "../utils/io/connections/Js"; import { nodeMethodName, triggerableMethodCalls } from "./code/assemblers/actor/ActorAssemblerUtils"; import { InitFunctionJsDefinition, TriggerableJsDefinition } from "./utils/JsDefinition"; import { BaseAudioSourceJsNode } from "./_BaseAudioSource"; import { inputObject3D } from "./_BaseObject3D"; export class PlayAudioSourceJsNode extends BaseAudioSourceJsNode { static type() { return "playAudioSource"; } _targetNodePath() { const node = this.pv.node.node(); if (!node) { return; } const nodePath = `'${node.path()}'`; return nodePath; } setTriggerableLines(shadersCollectionController) { const nodePath = this._targetNodePath(); if (!nodePath) { return; } const _addPlay = () => { const object3D = inputObject3D(this, shadersCollectionController); const func = Poly.namedFunctionsRegister.getFunction("playAudioSource", this, shadersCollectionController); const bodyLine = func.asString(object3D, nodePath); shadersCollectionController.addTriggerableLines(this, [bodyLine], { addTriggeredLines: false }); }; const _addOnStop = () => { const usedOutputNames = this.io.outputs.used_output_names(); if (!usedOutputNames.includes(JsConnectionPointType.TRIGGER)) { return; } const func = Poly.namedFunctionsRegister.getFunction( "addAudioStopEventListener", this, shadersCollectionController ); const onStopMethodName = nodeMethodName(this, "onStop"); const bodyLine = func.asString(nodePath, `this.${onStopMethodName}.bind(this)`, `this`); shadersCollectionController.addDefinitions(this, [ new InitFunctionJsDefinition( this, shadersCollectionController, JsConnectionPointType.OBJECT_3D, this.path(), bodyLine ) ]); const triggerableLines = triggerableMethodCalls(this); const value = triggerableLines; const varName = onStopMethodName; const dataType = JsConnectionPointType.BOOLEAN; shadersCollectionController.addDefinitions(this, [ new TriggerableJsDefinition(this, shadersCollectionController, dataType, varName, value, { methodName: onStopMethodName }) ]); }; _addPlay(); _addOnStop(); } }