@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
77 lines (76 loc) • 2.32 kB
JavaScript
"use strict";
export class ParamsEditableStateController {
constructor(node) {
this.node = node;
this._initialized = false;
this._checkParamsEditableStateBound = this._checkParamsEditableState.bind(this);
}
initializeNode() {
if (this._initialized) {
console.warn("already initialized", this.node);
return;
}
this._initialized = true;
this.node.io.inputs.add_on_set_input_hook(
"_checkParamsEditableStateBound",
this._checkParamsEditableStateBound
);
}
initialized() {
return this._initialized;
}
_checkParamsEditableState() {
if (!this._paramsMatchEditableState()) {
this.updateParamsEditableStateIfNeeded();
}
}
_paramsMatchEditableState() {
let i = 0;
const params = this.node.params;
const connectionPoints = this.node.io.inputs.namedInputConnectionPoints();
if (!connectionPoints) {
return false;
}
for (const connectionPoint of connectionPoints) {
if (connectionPoint) {
const isConnected = this.node.io.inputs.input(i) != null;
const paramName = connectionPoint == null ? void 0 : connectionPoint.name();
const hasParam = params.has(paramName);
if (hasParam) {
const param = params.get(paramName);
if (param) {
const expectedEditableState = !isConnected;
const currentEditableState = param.options.editable();
if (expectedEditableState != currentEditableState) {
return false;
}
}
}
}
i++;
}
return true;
}
updateParamsEditableStateIfNeeded() {
let i = 0;
const params = this.node.params;
const connectionPoints = this.node.io.inputs.namedInputConnectionPoints();
if (!connectionPoints) {
return;
}
for (const connectionPoint of connectionPoints) {
if (connectionPoint) {
const isConnected = this.node.io.inputs.input(i) != null;
const paramName = connectionPoint == null ? void 0 : connectionPoint.name();
if (params.has(paramName)) {
const param = params.get(paramName);
if (param) {
const requiredState = !isConnected;
param.options.setEditableState(requiredState);
}
}
}
i++;
}
}
}