Skip to content

Commit

Permalink
Merge pull request #64 from endlessm/T35507-categories
Browse files Browse the repository at this point in the history
Categories rework
  • Loading branch information
wnbaum authored Jun 20, 2024
2 parents dcf2afa + 88a9e25 commit 99699e9
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 166 deletions.
14 changes: 7 additions & 7 deletions addons/block_code/examples/pong_game/paddle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ static func get_exposed_properties() -> Array[String]:
return ["position"]


static func get_custom_blocks() -> Array[BlockCategory]:
static func get_custom_blocks() -> Array[Block]:
var b: Block
var block_list: Array[Block] = []

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

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

var movement_category: BlockCategory = BlockCategory.new("Movement", movement_list, Color("4a86d5"))

return [movement_category]
return block_list
18 changes: 11 additions & 7 deletions addons/block_code/examples/pong_game/pong_game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@ func get_custom_class():
return "Pong"


static func get_custom_blocks() -> Array[BlockCategory]:
static func get_custom_categories() -> Array[BlockCategory]:
return [BlockCategory.new("Scoring", Color("4a86d5"))]


static func get_custom_blocks() -> Array[Block]:
var b: Block
var block_list: Array[Block] = []

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

b = CategoryFactory.BLOCKS["statement_block"].instantiate()
b.block_type = Types.BlockType.EXECUTE
b.block_format = "Set player 2 score to {score: INT}"
b.statement = 'get_tree().call_group("hud", "set_player_score", "left", {score})'
score_list.append(b)

var score_category: BlockCategory = BlockCategory.new("Scoring", score_list, Color("4a86d5"))
b.category = "Scoring"
block_list.append(b)

return [score_category]
return block_list
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ static func get_exposed_properties() -> Array[String]:
return ["position"]


static func get_custom_blocks() -> Array[BlockCategory]:
static func get_custom_blocks() -> Array[Block]:
var b: Block
var block_list: Array[Block] = []

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

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

var movement_cat: BlockCategory = BlockCategory.new("Movement", movement_list, Color("4a86d5"))

return [movement_cat]
return block_list
3 changes: 3 additions & 0 deletions addons/block_code/ui/blocks/block/block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ signal modified
## Type of block to check if can be attached to snap point
@export var block_type: Types.BlockType = Types.BlockType.EXECUTE

## Category to add the block to
@export var category: String

## The next block in the line of execution (can be null if end)
@export var bottom_snap_path: NodePath

Expand Down
4 changes: 3 additions & 1 deletion addons/block_code/ui/picker/categories/block_category.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ extends Object
var name: String
var block_list: Array[Block]
var color: Color
var order: int


func _init(p_name: String = "", p_block_list: Array[Block] = [], p_color: Color = Color.WHITE):
func _init(p_name: String = "", p_color: Color = Color.WHITE, p_order: int = 0, p_block_list: Array[Block] = []):
name = p_name
block_list = p_block_list
color = p_color
order = p_order
Loading

0 comments on commit 99699e9

Please sign in to comment.