From 2f92233ca0994bf5ea8902759d42c3ddc1a2f4c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Fri, 21 Jul 2023 11:26:43 +0300 Subject: [PATCH] saving and loading port values --- classes/deck/deck.gd | 4 ++++ classes/deck/deck_node.gd | 6 ++++++ classes/deck/port.gd | 6 ++++++ graph_node_renderer/deck_node_renderer_graph_node.gd | 3 +++ 4 files changed, 19 insertions(+) diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index 88d1f03..153a67c 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -123,6 +123,10 @@ static func from_json(json: String) -> Deck: var connection_data = nodes_data[node_id].incoming_connections[connection_id] node.incoming_connections[int(connection_id)] = connection_data + for i in nodes_data[node_id].port_values.size(): + var port_value = nodes_data[node_id].port_values[i] + node.ports[i].value = port_value + for key in nodes_data[node_id].meta: node.set_meta(key, nodes_data[node_id].meta[key]) diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index a40af53..3597f7b 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -176,11 +176,17 @@ func to_dict(with_meta: bool = true) -> Dictionary: "incoming_connections": incoming_connections, "props": {}, "node_type": node_type, + "port_values": [] } for prop in props_to_serialize: d.props[prop] = get(prop) + ports.map( + func(port: Port) -> void: + d.port_values.append(port.value) + ) + if with_meta: d["meta"] = {} for meta in get_meta_list(): diff --git a/classes/deck/port.gd b/classes/deck/port.gd index 6ec1db3..61d47d5 100644 --- a/classes/deck/port.gd +++ b/classes/deck/port.gd @@ -9,6 +9,8 @@ var port_type: DeckNode.PortType var index_of_type: int var index: int +var value: Variant: set = set_value + func _init( p_type: Deck.Types, @@ -27,3 +29,7 @@ func _init( port_type = p_port_type index_of_type = p_index_of_type index = p_index + + +func set_value(v: Variant) -> void: + value = v diff --git a/graph_node_renderer/deck_node_renderer_graph_node.gd b/graph_node_renderer/deck_node_renderer_graph_node.gd index 7c8ab1e..ec37e2f 100644 --- a/graph_node_renderer/deck_node_renderer_graph_node.gd +++ b/graph_node_renderer/deck_node_renderer_graph_node.gd @@ -27,8 +27,11 @@ func _ready() -> void: "field": var line_edit := LineEdit.new() add_child(line_edit) + if port.value: + line_edit.text = str(port.value) line_edit.placeholder_text = port.label port.value_callback = line_edit.get_text + line_edit.text_changed.connect(port.set_value) _: var label := Label.new() add_child(label)