@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
84 lines (83 loc) • 3.34 kB
JavaScript
"use strict";
export class CoreNodeSerializer {
constructor(node) {
this.node = node;
}
dispose() {
}
toJSON(includeParamComponents = false) {
var _a, _b, _c, _d, _e, _f;
const data = {
name: this.node.name(),
type: this.node.type(),
graph_node_id: this.node.graphNodeId(),
is_dirty: this.node.isDirty(),
ui_data_json: this.node.uiData.toJSON(),
error_message: this.node.states.error.message(),
children: this.childrenIds(),
maxInputsCount: this.maxInputsCount(),
inputs: this.inputIds(),
input_connection_output_indices: this.inputConnectionOutputIndices(),
named_input_connection_points: this.namedInputConnectionPoints() || [],
named_output_connection_points: this.namedOutputConnectionPoints() || [],
param_ids: this.to_json_params(includeParamComponents),
// spare_params: this.to_json_spare_params(include_param_components),
override_cloned_state_allowed: this.node.io.inputs.overrideClonedStateAllowed(),
inputs_clone_required_states: this.node.io.inputs.cloneRequiredStates(),
flags: {
//has_display: this.has_display_flag()
display: (_b = (_a = this.node.flags) == null ? void 0 : _a.display) == null ? void 0 : _b.active(),
bypass: (_d = (_c = this.node.flags) == null ? void 0 : _c.bypass) == null ? void 0 : _d.active(),
optimize: (_f = (_e = this.node.flags) == null ? void 0 : _e.optimize) == null ? void 0 : _f.active()
},
selection: void 0
};
if (this.node.childrenAllowed() && this.node.childrenController) {
const selectedNodeIds = [];
this.node.childrenController.selection.toJSON(selectedNodeIds);
data["selection"] = selectedNodeIds;
}
if (this.node.polyNodeController) {
data["polyNode"] = {
locked: this.node.polyNodeController.locked()
};
}
return data;
}
childrenIds() {
return this.node.children().map((node) => node.graphNodeId());
}
maxInputsCount() {
return this.node.io.inputs.maxInputsCount();
}
inputIds() {
return this.node.io.inputs.inputs().map((node) => node != null ? node.graphNodeId() : void 0);
}
inputConnectionOutputIndices() {
var _a;
return (_a = this.node.io.connections.inputConnections()) == null ? void 0 : _a.map((connection) => connection != null ? connection.outputIndex() : void 0);
}
namedInputConnectionPoints() {
return (this.node.io.inputs.namedInputConnectionPoints() || []).map((i) => i.toJSON());
}
namedOutputConnectionPoints() {
return (this.node.io.outputs.namedOutputConnectionPoints() || []).map((o) => o.toJSON());
}
to_json_params_from_names(param_names, include_components = false) {
return param_names.map((param_name) => {
return this.node.params.get(param_name).graphNodeId();
});
}
to_json_params(include_components = false) {
return this.to_json_params_from_names(this.node.params.names, include_components);
}
// to_json_params_without_components(){
// return this.to_json_params(false)
// }
// to_json_params_with_components(){
// return this.to_json_params(true)
// }
// to_json_spare_params(include_components: boolean = false) {
// return this.to_json_params_from_names(this.node.params.spare_names, include_components);
// }
}