Skip to content

Commit 99699e9

Browse files
authored
Merge pull request #64 from endlessm/T35507-categories
Categories rework
2 parents dcf2afa + 88a9e25 commit 99699e9

File tree

9 files changed

+306
-166
lines changed

9 files changed

+306
-166
lines changed

addons/block_code/examples/pong_game/paddle.gd

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ static func get_exposed_properties() -> Array[String]:
1111
return ["position"]
1212

1313

14-
static func get_custom_blocks() -> Array[BlockCategory]:
14+
static func get_custom_blocks() -> Array[Block]:
1515
var b: Block
16+
var block_list: Array[Block] = []
1617

1718
# Movement
18-
var movement_list: Array[Block] = []
1919
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
2020
b.block_type = Types.BlockType.EXECUTE
2121
b.block_format = "Move with player 1 buttons, speed {speed: VECTOR2}"
2222
b.statement = 'velocity = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")*{speed}\n' + "move_and_slide()"
23-
movement_list.append(b)
23+
b.category = "Movement"
24+
block_list.append(b)
2425

2526
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
2627
b.block_type = Types.BlockType.EXECUTE
2728
b.block_format = "Move with player 2 buttons, speed {speed: VECTOR2}"
2829
b.statement = 'velocity = Input.get_vector("player_2_left", "player_2_right", "player_2_up", "player_2_down")*{speed}\n' + "move_and_slide()"
29-
movement_list.append(b)
30+
b.category = "Movement"
31+
block_list.append(b)
3032

31-
var movement_category: BlockCategory = BlockCategory.new("Movement", movement_list, Color("4a86d5"))
32-
33-
return [movement_category]
33+
return block_list

addons/block_code/examples/pong_game/pong_game.gd

+11-7
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,27 @@ func get_custom_class():
77
return "Pong"
88

99

10-
static func get_custom_blocks() -> Array[BlockCategory]:
10+
static func get_custom_categories() -> Array[BlockCategory]:
11+
return [BlockCategory.new("Scoring", Color("4a86d5"))]
12+
13+
14+
static func get_custom_blocks() -> Array[Block]:
1115
var b: Block
16+
var block_list: Array[Block] = []
1217

1318
# TODO: Only for testing. Move these blocks where they belong.
14-
var score_list: Array[Block] = []
1519
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
1620
b.block_type = Types.BlockType.EXECUTE
1721
b.block_format = "Set player 1 score to {score: INT}"
1822
b.statement = 'get_tree().call_group("hud", "set_player_score", "right", {score})'
19-
score_list.append(b)
23+
b.category = "Scoring"
24+
block_list.append(b)
2025

2126
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
2227
b.block_type = Types.BlockType.EXECUTE
2328
b.block_format = "Set player 2 score to {score: INT}"
2429
b.statement = 'get_tree().call_group("hud", "set_player_score", "left", {score})'
25-
score_list.append(b)
26-
27-
var score_category: BlockCategory = BlockCategory.new("Scoring", score_list, Color("4a86d5"))
30+
b.category = "Scoring"
31+
block_list.append(b)
2832

29-
return [score_category]
33+
return block_list

addons/block_code/simple_nodes/simple_character/simple_character.gd

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ static func get_exposed_properties() -> Array[String]:
1717
return ["position"]
1818

1919

20-
static func get_custom_blocks() -> Array[BlockCategory]:
20+
static func get_custom_blocks() -> Array[Block]:
2121
var b: Block
22+
var block_list: Array[Block] = []
2223

2324
# Movement
24-
var movement_list: Array[Block] = []
2525
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
2626
b.block_type = Types.BlockType.EXECUTE
2727
b.block_format = "Move with player 1 buttons, speed {speed: INT}"
2828
b.statement = 'velocity = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")*{speed}\n' + "move_and_slide()"
29-
movement_list.append(b)
29+
b.category = "Input"
30+
block_list.append(b)
3031

3132
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
3233
b.block_type = Types.BlockType.EXECUTE
3334
b.block_format = "Move with player 2 buttons, speed {speed: INT}"
3435
b.statement = 'velocity = Input.get_vector("player_2_left", "player_2_right", "player_2_up", "player_2_down")*{speed}\n' + "move_and_slide()"
35-
movement_list.append(b)
36+
b.category = "Input"
37+
block_list.append(b)
3638

37-
var movement_cat: BlockCategory = BlockCategory.new("Movement", movement_list, Color("4a86d5"))
38-
39-
return [movement_cat]
39+
return block_list

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

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ signal modified
1717
## Type of block to check if can be attached to snap point
1818
@export var block_type: Types.BlockType = Types.BlockType.EXECUTE
1919

20+
## Category to add the block to
21+
@export var category: String
22+
2023
## The next block in the line of execution (can be null if end)
2124
@export var bottom_snap_path: NodePath
2225

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ extends Object
44
var name: String
55
var block_list: Array[Block]
66
var color: Color
7+
var order: int
78

89

9-
func _init(p_name: String = "", p_block_list: Array[Block] = [], p_color: Color = Color.WHITE):
10+
func _init(p_name: String = "", p_color: Color = Color.WHITE, p_order: int = 0, p_block_list: Array[Block] = []):
1011
name = p_name
1112
block_list = p_block_list
1213
color = p_color
14+
order = p_order

0 commit comments

Comments
 (0)