@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
172 lines (171 loc) • 6.41 kB
JavaScript
"use strict";
import { TRIGGER_CONNECTION_NAME, TypedJsNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import {
JsConnectionPoint,
JsConnectionPointType,
JS_CONNECTION_POINT_IN_NODE_DEF,
PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES
} from "../utils/io/connections/Js";
import { Poly } from "../../Poly";
import { TypeAssert } from "../../poly/Assert";
import { JsType } from "../../poly/registers/nodes/types/Js";
import { inputParam } from "./_BaseObject3D";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
export var SetParamJsNodeInputName = /* @__PURE__ */ ((SetParamJsNodeInputName2) => {
SetParamJsNodeInputName2["lerp"] = "lerp";
SetParamJsNodeInputName2["val"] = "val";
return SetParamJsNodeInputName2;
})(SetParamJsNodeInputName || {});
class SetParamJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param type of the parameter to update */
this.type = ParamConfig.INTEGER(PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.indexOf(JsConnectionPointType.FLOAT), {
menu: {
entries: PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.map((name, value) => {
return { name, value };
})
}
});
}
}
const ParamsConfig = new SetParamJsParamsConfig();
export class SetParamJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return JsType.SET_PARAM;
}
initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(JsConnectionPointType.TRIGGER, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS),
new JsConnectionPoint(JsConnectionPointType.PARAM, JsConnectionPointType.PARAM, CONNECTION_OPTIONS),
new JsConnectionPoint(
"lerp" /* lerp */,
JsConnectionPointType.FLOAT,
{
...CONNECTION_OPTIONS,
init_value: 1
}
)
]);
this.io.connection_points.set_input_name_function(() => "val" /* val */);
this.io.connection_points.set_expected_input_types_function(() => [this._currentConnectionType()]);
this.io.connection_points.set_output_name_function(() => TRIGGER_CONNECTION_NAME);
this.io.connection_points.set_expected_output_types_function(() => [JsConnectionPointType.TRIGGER]);
}
_currentConnectionType() {
if (this.pv.type == null) {
console.warn(`${this.type()} type not valid`);
}
const connectionType = PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES[this.pv.type];
if (connectionType == null) {
console.warn(`${this.type()} type not valid`);
}
return connectionType || JsConnectionPointType.FLOAT;
}
setParamType(paramType) {
const index = PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.indexOf(paramType);
if (index < 0) {
console.warn(
`only the following types are accepted: ${PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.join(", ")}`
);
return;
}
this.p.type.set(index);
}
setParamPath(paramPath) {
this.params.get(JsConnectionPointType.PARAM).set(paramPath);
}
setParamParam(param) {
this.params.get(JsConnectionPointType.PARAM).setParam(param);
}
setTriggerableLines(controller) {
const param = inputParam(this, controller);
const paramValue = this.variableForInput(controller, "val" /* val */);
const lerp = this.variableForInput(controller, "lerp" /* lerp */);
const bodyLine = this._bodyLine({
controller,
param,
paramValue,
lerp
});
if (!bodyLine) {
return;
}
controller.addTriggerableLines(this, [bodyLine]);
}
_bodyLine(options) {
const type = PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES[this.pv.type];
switch (type) {
case JsConnectionPointType.BOOLEAN: {
return this._setBoolean(options);
}
case JsConnectionPointType.COLOR: {
return this._setColor(options);
}
case JsConnectionPointType.FLOAT: {
return this._setFloat(options);
}
case JsConnectionPointType.INT: {
return this._setInt(options);
}
case JsConnectionPointType.STRING: {
return this._setString(options);
}
case JsConnectionPointType.VECTOR2: {
return this._setVector2(options);
}
case JsConnectionPointType.VECTOR3: {
return this._setVector3(options);
}
case JsConnectionPointType.VECTOR4: {
return this._setVector4(options);
}
}
TypeAssert.unreachable(type);
}
_setBoolean(options) {
const { controller, param, paramValue } = options;
const func = Poly.namedFunctionsRegister.getFunction("setParamBoolean", this, controller);
return func.asString(param, paramValue);
}
_setColor(options) {
const { controller, param, paramValue, lerp } = options;
const func = Poly.namedFunctionsRegister.getFunction("setParamColor", this, controller);
return func.asString(param, paramValue, lerp);
}
_setFloat(options) {
const { controller, param, paramValue, lerp } = options;
const func = Poly.namedFunctionsRegister.getFunction("setParamFloat", this, controller);
return func.asString(param, paramValue, lerp);
}
_setInt(options) {
const { controller, param, paramValue, lerp } = options;
const func = Poly.namedFunctionsRegister.getFunction("setParamInteger", this, controller);
return func.asString(param, paramValue, lerp);
}
_setString(options) {
const { controller, param, paramValue } = options;
const func = Poly.namedFunctionsRegister.getFunction("setParamString", this, controller);
return func.asString(param, paramValue);
}
_setVector2(options) {
const { controller, param, paramValue, lerp } = options;
const func = Poly.namedFunctionsRegister.getFunction("setParamVector2", this, controller);
return func.asString(param, paramValue, lerp);
}
_setVector3(options) {
const { controller, param, paramValue, lerp } = options;
const func = Poly.namedFunctionsRegister.getFunction("setParamVector3", this, controller);
return func.asString(param, paramValue, lerp);
}
_setVector4(options) {
const { controller, param, paramValue, lerp } = options;
const func = Poly.namedFunctionsRegister.getFunction("setParamVector4", this, controller);
return func.asString(param, paramValue, lerp);
}
}