fix grouping nodes not removing incoming connections (#6)

Reviewed-on: https://codeberg.org/Eroax/Re-DotDeck/pulls/6
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
Lera Elvoé 2023-11-25 11:00:52 +00:00 committed by yagich
parent b36bdaf71c
commit 1fb71617bb
2 changed files with 16 additions and 11 deletions

View file

@ -158,6 +158,11 @@ func group_nodes(nodes_to_group: Array) -> Deck:
if !(connection.keys()[0] in node_ids_to_keep):
disconnect_nodes(node, get_node(connection.keys()[0]), from_port, connection.values()[0])
for to_port: int in node.incoming_connections:
for from_node: String in node.incoming_connections[to_port]:
if !(from_node in node_ids_to_keep):
disconnect_nodes(get_node(from_node), node, node.incoming_connections[to_port].values()[0], to_port)
midpoint += node.position_as_vector2()
remove_node(node._id)
group.add_node_inst(node, node._id)

View file

@ -3,8 +3,8 @@ class_name NodeDB_
## Filepath used for referencing all [DeckNode] Files from.
const BASE_NODE_PATH := "res://classes/deck/nodes/"
## Filepath where an Index of [NodeDB_.NodeDescriptor]s are saved to avoid reloading
## everything each run.
## Filepath where an Index of [NodeDB_.NodeDescriptor]s are saved to avoid reloading
## everything each run.
## @experimental
const NODE_INDEX_CACHE_PATH := "user://nodes_index.json"
## Filepath where the the list of Favorite Nodes is stored.
@ -14,11 +14,11 @@ const FAVORITE_NODES_PATH := "user://favorite_nodes.json"
var favorite_nodes: Array[String]
# Dictionary[node_type, NodeDescriptor]
## [Dictionary] filled with node_type, or [String] keys. Correlating to
## [Dictionary] filled with node_type, or [String] keys. Correlating to
## [NodeDB_.NodeDescriptor]'s. Essentially where all the nodes are loaded in for data reference.
var nodes: Dictionary = {}
## Loads in all the [DeckNode]s from [member BASE_NODE_PATH]. Or if a working
## Loads in all the [DeckNode]s from [member BASE_NODE_PATH]. Or if a working
## cache exists at [member NODE_INDEX_CACHE_PATH] that takes priority
func _init() -> void:
load_favorites()
@ -69,7 +69,7 @@ func save_node_index() -> void:
var f := FileAccess.open(NODE_INDEX_CACHE_PATH, FileAccess.WRITE)
f.store_string(json)
## Loads the Node Index from [member NODE_INDEX_CACHE_PATH] adding all of the
## Loads the Node Index from [member NODE_INDEX_CACHE_PATH] adding all of the
## [NodeDB_.NodeDescriptor]s in it to the [member nodes] [Dictionary]
func load_node_index() -> bool:
var f := FileAccess.open(NODE_INDEX_CACHE_PATH, FileAccess.READ)
@ -90,7 +90,7 @@ func load_node_index() -> bool:
print("node index file exists, loaded")
return true
## Sets a specific [member DeckNode.node_type] to be a "favorite" for use in
## Sets a specific [member DeckNode.node_type] to be a "favorite" for use in
## [AddNodeMenu]. Then stores the updated list of favorites at [member FAVORITE_NODES_PATH]
func set_node_favorite(node_type: String, favorite: bool) -> void:
if (favorite && node_type in favorite_nodes) || (!favorite && !(node_type in favorite_nodes)):
@ -113,14 +113,14 @@ func load_favorites() -> void:
favorite_nodes.clear()
favorite_nodes.assign(data)
## Returns [code]true[/code] if the specified [member DeckNode.node_type] is marked Favorite
## Returns [code]true[/code] if the specified [member DeckNode.node_type] is marked Favorite
## by the user.
func is_node_favorite(node_type: String) -> bool:
return node_type in favorite_nodes
## Used for storing the shorthand data of a [DeckNode].
##
## Allows for more simply storing [DeckNode]s properties without needing to
## Allows for more simply storing [DeckNode]s properties without needing to
## keep an instance
class NodeDescriptor:
## Default Name of the [DeckNode] type this is storing properties of.
@ -135,10 +135,10 @@ class NodeDescriptor:
var category: String
## The description of the [DeckNode] reference [member DeckNode.appears_in_search]
var appears_in_search: bool
## Stores the path to this nodes [Script] in res:// for later instantiation.
var script_path: String
func _init(
p_script_path: String,
p_name: String,
@ -170,7 +170,7 @@ class NodeDescriptor:
}
return d
## Creates a [NodeDB_.NodeDescriptor] from a given [Dictionary] of properties.
## Creates a [NodeDB_.NodeDescriptor] from a given [Dictionary] of properties.
static func from_dictionary(data: Dictionary) -> NodeDescriptor:
var nd := NodeDescriptor.new(
data.get("script_path", ""),