Skip to content

Commit 77b4b49

Browse files
committed
BlockDefinition: Improve editing this resource
Improve editing the BlockDefinition resource in the Inspector: - Disable fields `variant_type` and `signal_name` when the block type doesn't correspond. - Remove `scope` from exports. This is handled internally by the `DragManager` so can be a regular variable.
1 parent 8750f7b commit 77b4b49

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

addons/block_code/code_generation/block_definition.gd

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const FORMAT_STRING_PATTERN = "\\[(?<out_parameter>[^\\]]+)\\]|\\{const (?<const
1818
@export var category: String
1919

2020
## Which kind of block is this. See [enum Types.BlockType].
21-
@export var type: Types.BlockType
21+
@export var type: Types.BlockType:
22+
set = _set_type
2223

2324
## Only relevant for Value blocks. The variant type that this block is
2425
## supposed to return.
@@ -56,16 +57,16 @@ const FORMAT_STRING_PATTERN = "\\[(?<out_parameter>[^\\]]+)\\]|\\{const (?<const
5657
## name.
5758
@export var signal_name: String
5859

59-
## Empty except for blocks that have a defined scope.
60-
@export var scope: String
61-
6260
## If checked, the block will be hidden by default in the Picker.
6361
@export var is_advanced: bool
6462

6563
## An optional script that can extend this block definition. For instance, to
6664
## dynamically add the defaults.
6765
@export var extension_script: GDScript
6866

67+
## Empty except for blocks that have a defined scope.
68+
var scope: String
69+
6970
static var _display_template_regex := RegEx.create_from_string(FORMAT_STRING_PATTERN)
7071

7172

@@ -99,6 +100,18 @@ func _init(
99100
is_advanced = p_is_advanced
100101

101102

103+
func _set_type(p_type):
104+
type = p_type
105+
notify_property_list_changed()
106+
107+
108+
func _validate_property(property: Dictionary):
109+
if property.name == "variant_type" and type != Types.BlockType.VALUE:
110+
property.usage |= PROPERTY_USAGE_READ_ONLY
111+
elif property.name == "signal_name" and type != Types.BlockType.ENTRY:
112+
property.usage |= PROPERTY_USAGE_READ_ONLY
113+
114+
102115
func create_block_extension() -> BlockExtension:
103116
if not extension_script:
104117
return null

0 commit comments

Comments
 (0)