Skip to content

Commit 794a015

Browse files
authored
Merge pull request #82 from endlessm/multiline-and-renaming
Multiline and renaming
2 parents 161c2a6 + 124a7cf commit 794a015

File tree

4 files changed

+72
-39
lines changed

4 files changed

+72
-39
lines changed

addons/block_code/block_code_node/utilities/signal_manager.gd

Lines changed: 0 additions & 19 deletions
This file was deleted.

addons/block_code/block_code_plugin.gd

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ func _enter_tree():
5959
# Hide the main panel. Very much required.
6060
_make_visible(false)
6161

62-
# Add signal manager for block code nodes to access
63-
add_autoload_singleton("SignalManager", "res://addons/block_code/block_code_node/utilities/signal_manager.gd")
64-
6562
# Remove unwanted class nodes from create node
6663
old_feature_profile = EditorInterface.get_current_feature_profile()
6764

@@ -83,8 +80,6 @@ func _exit_tree():
8380
if main_panel:
8481
main_panel.queue_free()
8582

86-
remove_autoload_singleton("SignalManager")
87-
8883
var editor_paths: EditorPaths = EditorInterface.get_editor_paths()
8984
if editor_paths:
9085
var config_dir := editor_paths.get_config_dir()

addons/block_code/ui/picker/categories/category_factory.gd

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ static func get_general_blocks() -> Array[Block]:
142142
b.category = "Lifecycle"
143143
block_list.append(b)
144144

145+
b = BLOCKS["statement_block"].instantiate()
146+
b.block_format = "Await scene ready"
147+
b.statement = (
148+
"""
149+
if not get_tree().root.is_node_ready():
150+
await get_tree().root.ready
151+
"""
152+
. dedent()
153+
)
154+
b.category = "Lifecycle"
155+
block_list.append(b)
156+
145157
# Control
146158
b = BLOCKS["control_block"].instantiate()
147159
b.block_formats = ["if {condition: BOOL}"]
@@ -191,20 +203,27 @@ static func get_general_blocks() -> Array[Block]:
191203
b = BLOCKS["entry_block"].instantiate()
192204
# HACK: make signals work with new entry nodes. NIL instead of STRING type allows
193205
# plain text input for function name. Should revamp signals later
194-
b.block_format = "On signal {signal: NIL}"
195-
b.statement = "func signal_{signal}():"
206+
b.block_format = "Define method {method_name: NIL}"
207+
b.statement = "func {method_name}():"
196208
b.category = "Signal"
197209
block_list.append(b)
198210

199211
b = BLOCKS["statement_block"].instantiate()
200-
b.block_format = "Send signal {signal: STRING} to group {group: STRING}"
201-
b.statement = 'if get_tree().root.has_node("SignalManager"):\n' + '\tget_tree().root.get_node_or_null("SignalManager").broadcast_signal({group}, {signal})'
212+
b.block_format = "Call method {method_name: STRING} in group {group: STRING}"
213+
b.statement = "get_tree().call_group({group}, {method_name})"
202214
b.category = "Signal"
203215
block_list.append(b)
204216

205217
b = BLOCKS["statement_block"].instantiate()
206-
b.block_format = "Send signal {signal: STRING} to node {node: NODE_PATH}"
207-
b.statement = 'if get_tree().root.has_node("SignalManager"):\n' + '\tget_tree().root.get_node_or_null("SignalManager").send_signal_to_node({node}, {signal})'
218+
b.block_format = "Call method {method_name: STRING} in node {node_path: NODE_PATH}"
219+
b.statement = (
220+
"""
221+
var node = get_node({node_path})
222+
if node:
223+
node.call({method_name})
224+
"""
225+
. dedent()
226+
)
208227
b.category = "Signal"
209228
block_list.append(b)
210229

@@ -345,14 +364,29 @@ static func get_general_blocks() -> Array[Block]:
345364
b = BLOCKS["statement_block"].instantiate()
346365
b.block_type = Types.BlockType.EXECUTE
347366
b.block_format = "Load file {file_path: STRING} as sound {name: STRING}"
348-
b.statement = "VAR_DICT[{name}] = AudioStreamPlayer.new()\nVAR_DICT[{name}].name = {name}\nVAR_DICT[{name}].set_stream(load({file_path}))\nadd_child(VAR_DICT[{name}])"
367+
b.statement = (
368+
"""
369+
VAR_DICT[{name}] = AudioStreamPlayer.new()
370+
VAR_DICT[{name}].name = {name}
371+
VAR_DICT[{name}].set_stream(load({file_path}))
372+
add_child(VAR_DICT[{name}])
373+
"""
374+
. dedent()
375+
)
349376
b.category = "Sound"
350377
block_list.append(b)
351378

352379
b = BLOCKS["statement_block"].instantiate()
353380
b.block_type = Types.BlockType.EXECUTE
354381
b.block_format = "Play the sound {name: STRING} with Volume dB {db: FLOAT} and Pitch Scale {pitch: FLOAT}"
355-
b.statement = "VAR_DICT[{name}].volume_db = {db}\nVAR_DICT[{name}].pitch_scale = {pitch}\nVAR_DICT[{name}].play()"
382+
b.statement = (
383+
"""
384+
VAR_DICT[{name}].volume_db = {db}
385+
VAR_DICT[{name}].pitch_scale = {pitch}
386+
VAR_DICT[{name}].play()
387+
"""
388+
. dedent()
389+
)
356390
b.defaults = {"db": "0.0", "pitch": "1.0"}
357391
b.category = "Sound"
358392
block_list.append(b)
@@ -450,14 +484,32 @@ static func get_built_in_blocks(_class_name: String) -> Array[Block]:
450484
b.block_format = "On [body: NODE_PATH] %s" % [verb]
451485
# HACK: Blocks refer to nodes by path but the callback receives the node itself;
452486
# convert to path
453-
b.statement = "func _on_body_%s(_body: Node):\n\tvar body: NodePath = _body.get_path()" % [verb]
487+
b.statement = (
488+
(
489+
"""
490+
func _on_body_%s(_body: Node):
491+
var body: NodePath = _body.get_path()
492+
"""
493+
. dedent()
494+
)
495+
% [verb]
496+
)
454497
b.signal_name = "body_%s" % [verb]
455498
b.category = "Signal"
456499
block_list.append(b)
457500

458501
var b = BLOCKS["statement_block"].instantiate()
459502
b.block_format = "Set Physics Position {position: VECTOR2}"
460-
b.statement = "PhysicsServer2D.body_set_state(get_rid(),PhysicsServer2D.BODY_STATE_TRANSFORM,Transform2D.IDENTITY.translated({position}))"
503+
b.statement = (
504+
"""
505+
PhysicsServer2D.body_set_state(
506+
get_rid(),
507+
PhysicsServer2D.BODY_STATE_TRANSFORM,
508+
Transform2D.IDENTITY.translated({position})
509+
)
510+
"""
511+
. dedent()
512+
)
461513
b.category = "Movement"
462514
block_list.append(b)
463515

@@ -473,7 +525,16 @@ static func get_built_in_blocks(_class_name: String) -> Array[Block]:
473525
b.block_format = "On [body: NODE_PATH] %s" % [verb]
474526
# HACK: Blocks refer to nodes by path but the callback receives the node itself;
475527
# convert to path
476-
b.statement = "func _on_body_%s(_body: Node2D):\n\tvar body: NodePath = _body.get_path()" % [verb]
528+
b.statement = (
529+
(
530+
"""
531+
func _on_body_%s(_body: Node2D):
532+
var body: NodePath = _body.get_path()
533+
"""
534+
. dedent()
535+
)
536+
% [verb]
537+
)
477538
b.signal_name = "body_%s" % [verb]
478539
b.category = "Signal"
479540
block_list.append(b)

project.godot

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ run/main_scene="res://addons/block_code/examples/pong_game/pong_game.tscn"
1515
config/features=PackedStringArray("4.2", "GL Compatibility")
1616
config/icon="res://icon.svg"
1717

18-
[autoload]
19-
20-
SignalManager="*res://addons/block_code/block_code_node/utilities/signal_manager.gd"
21-
2218
[editor_plugins]
2319

2420
enabled=PackedStringArray("res://addons/block_code/plugin.cfg", "res://addons/gut/plugin.cfg", "res://addons/plugin_refresher/plugin.cfg")

0 commit comments

Comments
 (0)