10000 BlockDefinition: Support extension scripts · endlessm/godot-block-coding@dc99328 · GitHub
[go: up one dir, main page]

Skip to content

Commit dc99328

Browse files
committed
BlockDefinition: Support extension scripts
An extension script can implement functions which refine a block's presentation depending on the current context, such as the node it is attached to. https://phabricator.endlessm.com/T35564
1 parent 4118bae commit dc99328

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

addons/block_code/code_generation/block_definition.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ const Types = preload("res://addons/block_code/types/types.gd")
2727
## Empty except for blocks that have a defined scope
2828
@export var scope: String
2929

30+
@export var extension_script: GDScript
31+
32+
var _extension: BlockExtension:
33+
get:
34+
if _extension == null and extension_script and extension_script.can_instantiate():
35+
_extension = extension_script.new()
36+
return _extension as BlockExtension
37+
3038

3139
func _init(
3240
p_name: StringName = &"",
@@ -40,6 +48,7 @@ func _init(
4048
p_defaults = {},
4149
p_signal_name: String = "",
4250
p_scope: String = "",
51+
p_extension_script: GDScript = null,
4352
):
4453
name = p_name
4554
target_node_class = p_target_node_class
@@ -52,6 +61,7 @@ func _init(
5261
defaults = p_defaults
5362
signal_name = p_signal_name
5463
scope = p_scope
64+
extension_script = p_extension_script
5565

5666

5767
func _to_string():
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@tool
2+
class_name BlockExtension
3+
extends Object

0 commit comments

Comments
 (0)
0