UNPKG

@polygonjs/polygonjs

Version:

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

81 lines (80 loc) 2.79 kB
"use strict"; import { isString, isNumber } from "../../../../core/Type"; export class ParamJsonExporter { constructor(_param) { this._param = _param; // protected _simple_data: SimpleParamJsonExporterData<ParamType>=0; this._complex_data = {}; } required() { const is_spare_and_not_component = this._param.options.isSpare() && !this._param.parentParam(); const value_changed = !this._param.isDefault(); return is_spare_and_not_component || value_changed || this._param.options.hasOptionsOverridden(); } data() { if (this._param.parentParam()) { console.warn("no component should be saved"); throw "no component should be saved"; } if (this._require_data_complex()) { return this._data_complex(); } else { return this._data_simple(); } } _data_simple() { return this._param.rawInputSerialized(); } _data_complex() { this._complex_data = {}; if (this._param.options.isSpare() && !this._param.parentParam()) { this._complex_data["type"] = this._param.type(); this._complex_data["default_value"] = this._param.defaultValueSerialized(); this._complex_data["options"] = this._param.options.current(); } if (!this._param.isDefault()) { this._complex_data["raw_input"] = this._param.rawInputSerialized(); } if (this._param.options.hasOptionsOverridden()) { const overridden_options = {}; const options_overridden = this._param.options.overriddenOptions(); for (let option_name of Object.keys(options_overridden)) { const option_value = options_overridden[option_name]; if (isString(option_value) || isNumber(option_value)) { overridden_options[option_name] = option_value; } else { overridden_options[option_name] = JSON.stringify(option_value); } } this._complex_data["overriden_options"] = overridden_options; } return this._complex_data; } _require_data_complex() { if (this._param.options.isSpare()) { return true; } if (this._param.options.hasOptionsOverridden()) { return true; } return false; } // default_value(): ParamValueSerialized { // return this._param.defaultValueSerialized(); // } // cannot remember why this is useful, but it messes up // with gl nodes like the noise node, as the default value // gets saved as a string '[1,1]' instead of an array [1,1] (should be without quotes) // protected default_value(){ // let default_value = this._param.default_value() // if(isString(default_value)){ // default_value = `'${default_value}'` // } // if (isArray(default_value)){ // default_value = `[${default_value}]` // } // return default_value // } add_main() { } }