Skip to content

Commit 16eac33

Browse files
committed
Derive block color from category
Stop persisting the color in the serialization. https://phabricator.endlessm.com/T35591
1 parent c13f64d commit 16eac33

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

addons/block_code/ui/blocks/block/block.gd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,8 @@ func get_serialized_props() -> Array:
138138
return serialize_props(["block_name", "label", "color", "block_type", "position", "scope"])
139139

140140
# TODO: Remove remaining serialization:
141-
# - Derive color from category.
142141
# - Handle scope in a different way?
143-
return serialize_props(["color", "scope"])
142+
return serialize_props(["scope"])
144143

145144

146145
func _to_string():

addons/block_code/ui/picker/categories/block_category_display.gd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,5 @@ var category: BlockCategory
1212
func _ready():
1313
_label.text = category.name
1414

15-
for _block in category.block_list:
16-
var block: Block = _block as Block
17-
18-
block.color = category.color
19-
15+
for block: Block in category.block_list:
2016
_blocks.add_child(block)

addons/block_code/ui/util.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ const SCENE_PER_TYPE = {
1313
}
1414

1515

16+
static func get_category_color(category: String) -> Color:
17+
var category_props: Dictionary = Constants.BUILTIN_CATEGORIES_PROPS.get(category, {})
18+
return category_props.get("color", Color.SLATE_GRAY)
19+
20+
1621
static func instantiate_block(block_definition: BlockDefinition) -> Block:
1722
var scene = SCENE_PER_TYPE[block_definition.type]
1823
var b = scene.instantiate()
@@ -31,6 +36,8 @@ static func instantiate_block(block_definition: BlockDefinition) -> Block:
3136
b.defaults = block_definition.defaults
3237
b.tooltip_text = block_definition.description
3338
b.category = block_definition.category
39+
b.color = get_category_color(block_definition.category)
40+
3441
return b
3542

3643

0 commit comments

Comments
 (0)