-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add named classes for final blocks
Instead of defining blocks in category_factory.gd, define blocks ahead of time, each in their own GDScript file. Although it is not a concept in GDScript itself, we can consider block classes such as EntryBlock to be abstract block types. By doing this, we are able to reduce duplication in the block script resource associated with each BlockCode node. In particular, the serialized data can simply refer to "PrintBlock", and all of the EntryBlock properties expected for the print block are implied. This commit only adds ReadyBlock and PrintBlock as an example, and likely breaks everything else.
- Loading branch information
1 parent
2c47fde
commit 2886d40
Showing
6 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@tool | ||
class_name PrintBlock | ||
extends StatementBlock | ||
|
||
func _init(): | ||
var _block = load(StatementBlock.get_scene_path()).instantiate() as Node | ||
_block.replace_by(self, true) | ||
block_name = _block.block_name | ||
label = _block.label | ||
color = _block.color | ||
block_type = _block.block_type | ||
bottom_snap_path = _block.bottom_snap_path | ||
_block.queue_free() | ||
|
||
block_name = "print_block" | ||
block_format = "print {text: STRING}" | ||
statement = "print({text})" | ||
color = Color("9989df") | ||
|
||
func copy_block(): | ||
return PrintBlock.new() | ||
|
||
static func get_block_class(): | ||
return "PrintBlock" | ||
|
||
static func get_scene_path(): | ||
return "res://addons/block_code/ui/picker/categories/print_block.gd" | ||
|
||
# Strip out properties that never change for this block type | ||
func get_serialized_props() -> Array: | ||
var props = super() | ||
return props.filter(func(prop): return prop[0] not in ["block_name", "label", "color", "block_type", "block_format", "statement"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@tool | ||
class_name ReadyBlock | ||
extends EntryBlock | ||
|
||
func _init(): | ||
var _block = load(EntryBlock.get_scene_path()).instantiate() as Node | ||
_block.replace_by(self, true) | ||
block_name = _block.block_name | ||
label = _block.label | ||
color = _block.color | ||
block_type = _block.block_type | ||
bottom_snap_path = _block.bottom_snap_path | ||
_block.queue_free() | ||
|
||
block_name = "ready_block" | ||
block_format = "On Ready" | ||
statement = "func _ready():" | ||
color = Color("fa5956") | ||
|
||
func copy_block(): | ||
return ReadyBlock.new() | ||
|
||
static func get_block_class(): | ||
return "ReadyBlock" | ||
|
||
static func get_scene_path(): | ||
return "res://addons/block_code/ui/picker/categories/ready_block.gd" | ||
|
||
# Strip out properties that never change for this block type | ||
func get_serialized_props() -> Array: | ||
var props = super() | ||
return props.filter(func(prop): return prop[0] not in ["block_name", "label", "color", "block_type", "block_format", "statement"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters