Skip to content

Commit 3b78183

Browse files
committed
Blocks catalog: Make property setter optional
The properties may be read-only. Also indent properly the changer definition, which was wrong.
1 parent d8dae7e commit 3b78183

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

addons/block_code/code_generation/blocks_catalog.gd

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,24 @@ static func _add_property_definitions(_class_name: String, property_list: Array[
141141
_by_class_name[_class_name] = {}
142142

143143
# Setter
144-
var block_definition: BlockDefinition = (
145-
BlockDefinition
146-
. new(
147-
&"%s_set_%s" % [_class_name, property.name],
148-
_class_name,
149-
"Set the %s property" % property.name,
150-
block_settings.category,
151-
Types.BlockType.STATEMENT,
152-
TYPE_NIL,
153-
"Set %s to {value: %s}" % [property.name.capitalize(), type_string],
154-
"%s = {value}" % property.name,
155-
{"value": block_settings.get("default_set", _FALLBACK_SET_FOR_TYPE[property.type])},
144+
var block_definition: BlockDefinition
145+
if block_settings.get("has_setter", true):
146+
block_definition = (
147+
BlockDefinition
148+
. new(
149+
&"%s_set_%s" % [_class_name, property.name],
150+
_class_name,
151+
"Set the %s property" % property.name,
152+
block_settings.category,
153+
Types.BlockType.STATEMENT,
154+
TYPE_NIL,
155+
"Set %s to {value: %s}" % [property.name.capitalize(), type_string],
156+
"%s = {value}" % property.name,
157+
{"value": block_settings.get("default_set", _FALLBACK_SET_FOR_TYPE[property.type])},
158+
)
156159
)
157-
)
158-
_catalog[block_definition.name] = block_definition
159-
_by_class_name[_class_name][block_definition.name] = block_definition
160+
_catalog[block_definition.name] = block_definition
161+
_by_class_name[_class_name][block_definition.name] = block_definition
160162

161163
# Changer
162164
if block_settings.get("has_change", true):
@@ -174,8 +176,8 @@ static func _add_property_definitions(_class_name: String, property_list: Array[
174176
{"value": block_settings.get("default_change", _FALLBACK_CHANGE_FOR_TYPE[property.type])},
175177
)
176178
)
177-
_catalog[block_definition.name] = block_definition
178-
_by_class_name[_class_name][block_definition.name] = block_definition
179+
_catalog[block_definition.name] = block_definition
180+
_by_class_name[_class_name][block_definition.name] = block_definition
179181

180182
# Getter
181183
block_definition = (

0 commit comments

Comments
 (0)