Skip to content

Commit a5c9b4b

Browse files
committed
Blocks catalog: Read definitions from resource files
And remove the 2 definitions from code. Please note the name of the On Ready block has changed. This will be addressed in the next commit.
1 parent bc69f1b commit a5c9b4b

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

addons/block_code/code_generation/blocks_catalog.gd

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ extends Object
22

33
const BlockDefinition = preload("res://addons/block_code/code_generation/block_definition.gd")
44
const Types = preload("res://addons/block_code/types/types.gd")
5+
const Util = preload("res://addons/block_code/code_generation/util.gd")
6+
7+
const _BLOCKS_PATH = "res://addons/block_code/blocks/"
58

69
static var _catalog: Dictionary
710

@@ -11,24 +14,11 @@ static func setup():
1114
return
1215

1316
_catalog = {}
14-
var block_definition: BlockDefinition = BlockDefinition.new()
15-
block_definition.name = &"ready_block"
16-
block_definition.type = Types.BlockType.ENTRY
17-
block_definition.display_template = "On Ready"
18-
block_definition.code_template = "func _ready():"
19-
block_definition.description = 'Attached blocks will be executed once when the node is "ready"'
20-
block_definition.category = "Lifecycle"
21-
_catalog[&"ready_block"] = block_definition
22-
23-
block_definition = BlockDefinition.new()
24-
block_definition.name = &"print"
25-
block_definition.type = Types.BlockType.STATEMENT
26-
block_definition.display_template = "print {text: STRING}"
27-
block_definition.code_template = "print({text})"
28-
block_definition.defaults = {"text": "Hello"}
29-
block_definition.description = "Print the text to output"
30-
block_definition.category = "Log"
31-
_catalog[&"print"] = block_definition
17+
18+
var definition_files = Util.get_files_in_dir_recursive(_BLOCKS_PATH, "*.tres")
19+
for file in definition_files:
20+
var block_definition = load(file)
21+
_catalog[block_definition.name] = block_definition
3222

3323

3424
static func get_block(block_name: StringName):

0 commit comments

Comments
 (0)