Skip to content

Commit

Permalink
Merge pull request #62 from endlessm/add-send-signal-to-node
Browse files Browse the repository at this point in the history
Add a "Send signal to node" block
  • Loading branch information
wnbaum authored Jun 21, 2024
2 parents 19e1c57 + 34335fd commit c5fb838
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions addons/block_code/block_code_node/utilities/signal_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ func broadcast_signal(group: String, signal_name: String):
await get_tree().root.ready

get_tree().call_group(group, "signal_" + signal_name)


func send_signal_to_node(path: NodePath, signal_name: String):
# Make sure all nodes have been readied and scripts loaded before running signals
if not get_tree().root.is_node_ready():
await get_tree().root.ready

var node = get_node(path)
if node:
node.call("signal_" + signal_name)
8 changes: 7 additions & 1 deletion addons/block_code/ui/picker/categories/category_factory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ static func get_general_blocks() -> Array[Block]:

b = BLOCKS["statement_block"].instantiate()
b.block_format = "Send signal {signal: STRING} to group {group: STRING}"
b.statement = 'var signal_manager = get_tree().root.get_node_or_null("SignalManager")\n' + "if signal_manager:\n" + "\tsignal_manager.broadcast_signal({group}, {signal})"
b.statement = 'if get_tree().root.has_node("SignalManager"):\n' + '\tget_tree().root.get_node_or_null("SignalManager").broadcast_signal({group}, {signal})'
b.category = "Signal"
block_list.append(b)

b = BLOCKS["statement_block"].instantiate()
b.block_format = "Send signal {signal: STRING} to node {node: NODE_PATH}"
b.statement = 'if get_tree().root.has_node("SignalManager"):\n' + '\tget_tree().root.get_node_or_null("SignalManager").send_signal_to_node({node}, {signal})'
b.category = "Signal"
block_list.append(b)

Expand Down

0 comments on commit c5fb838

Please sign in to comment.