UNPKG

@polygonjs/polygonjs

Version:

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

47 lines (46 loc) 1.28 kB
"use strict"; import { isString } from "./../../../core/Type"; import { BaseMethod } from "./_Base"; import { DecomposedPath } from "../../../core/DecomposedPath"; export class ChExpression extends BaseMethod { static requiredArguments() { return [["string", "path to param"]]; } findDependency(args) { const { indexOrPath } = args; if (indexOrPath == null) { return null; } if (!isString(indexOrPath)) { return null; } const decomposedPath = new DecomposedPath(); const param = this.getReferencedParam(indexOrPath, decomposedPath); if (param) { this._referencedParam = param; return this.createDependency(param, { indexOrPath }, decomposedPath); } return null; } async processArguments(args) { return new Promise(async (resolve, reject) => { let val = 0; if (args.length == 1) { const path = args[0]; const ref = this._referencedParam || this.getReferencedParam(path); if (ref) { if (ref.isDirty()) { await ref.compute(); } const result = ref.value; if (result != null) { val = result; resolve(val); } } else { reject(0); } } }); } }