* serialize the content
()
| 812 | * serialize the content |
| 813 | */ |
| 814 | serialize(): ISerialisedNode { |
| 815 | // create serialization object |
| 816 | const o: ISerialisedNode = { |
| 817 | id: this.id, |
| 818 | type: this.type, |
| 819 | pos: [this.pos[0], this.pos[1]], |
| 820 | size: [this.size[0], this.size[1]], |
| 821 | flags: LiteGraph.cloneObject(this.flags), |
| 822 | order: this.order, |
| 823 | mode: this.mode, |
| 824 | showAdvanced: this.showAdvanced, |
| 825 | } |
| 826 | |
| 827 | // special case for when there were errors |
| 828 | if (this.constructor === LGraphNode && this.last_serialization) |
| 829 | return this.last_serialization |
| 830 | |
| 831 | if (this.inputs) o.inputs = this.inputs.map(input => inputAsSerialisable(input)) |
| 832 | if (this.outputs) o.outputs = this.outputs.map(output => outputAsSerialisable(output)) |
| 833 | |
| 834 | if (this.title && this.title != this.constructor.title) o.title = this.title |
| 835 | |
| 836 | if (this.properties) o.properties = LiteGraph.cloneObject(this.properties) |
| 837 | |
| 838 | const { widgets } = this |
| 839 | if (widgets && this.serialize_widgets) { |
| 840 | o.widgets_values = [] |
| 841 | for (const [i, widget] of widgets.entries()) { |
| 842 | if (widget.serialize === false) continue |
| 843 | // @ts-expect-error #595 No-null |
| 844 | o.widgets_values[i] = widget ? widget.value : null |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | if (!o.type) o.type = this.constructor.type |
| 849 | |
| 850 | if (this.color) o.color = this.color |
| 851 | if (this.bgcolor) o.bgcolor = this.bgcolor |
| 852 | if (this.boxcolor) o.boxcolor = this.boxcolor |
| 853 | if (this.shape) o.shape = this.shape |
| 854 | |
| 855 | if (this.onSerialize?.(o)) console.warn("node onSerialize shouldnt return anything, data should be stored in the object pass in the first parameter") |
| 856 | |
| 857 | return o |
| 858 | } |
| 859 | |
| 860 | /* Creates a clone of this node */ |
| 861 | clone(): LGraphNode | null { |
no test coverage detected