Skip to content

Commit 51c3924

Browse files
committed
Add Variant type and type casting blocks
https://phabricator.endlessm.com/T35497
1 parent 38e7406 commit 51c3924

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

addons/block_code/types/types.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ enum BlockType {
66
EXECUTE,
77
ENTRY,
88
# Parameters
9+
VARIANT,
910
STRING,
1011
INT,
1112
FLOAT,

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ static func get_general_categories() -> Array[BlockCategory]:
8383
b.statement = "print({text})"
8484
test_list.append(b)
8585

86+
b = BLOCKS["statement_block"].instantiate()
87+
b.block_format = "print value {value: VARIANT}"
88+
b.statement = "print({value})"
89+
test_list.append(b)
90+
8691
b = BLOCKS["entry_block"].instantiate()
8792
b.block_format = "On body enter [body: NODE]"
8893
b.statement = "func _on_body_enter(body):"
@@ -170,6 +175,35 @@ static func get_general_categories() -> Array[BlockCategory]:
170175

171176
var variable_category: BlockCategory = BlockCategory.new("Variables", variable_list, Color("4f975d"))
172177

178+
# Objects & Types
179+
var type_list: Array[Block] = []
180+
181+
b = BLOCKS["parameter_block"].instantiate()
182+
b.block_type = Types.BlockType.STRING
183+
b.block_format = "As String {value: VARIANT}"
184+
b.statement = "String({value})"
185+
type_list.append(b)
186+
187+
b = BLOCKS["parameter_block"].instantiate()
188+
b.block_type = Types.BlockType.INT
189+
b.block_format = "As int {value: VARIANT}"
190+
b.statement = "int({value})"
191+
type_list.append(b)
192+
193+
b = BLOCKS["parameter_block"].instantiate()
194+
b.block_type = Types.BlockType.FLOAT
195+
b.block_format = "As float {value: VARIANT}"
196+
b.statement = "float({value})"
197+
type_list.append(b)
198+
199+
b = BLOCKS["parameter_block"].instantiate()
200+
b.block_type = Types.BlockType.BOOL
201+
b.block_format = "As boolean {value: VARIANT}"
202+
b.statement = "bool({value})"
203+
type_list.append(b)
204+
205+
var type_category: BlockCategory = BlockCategory.new("Objects & Types", type_list, Color("c12f8e"))
206+
173207
# Math
174208
var math_list: Array[Block] = []
175209

@@ -243,6 +277,7 @@ static func get_general_categories() -> Array[BlockCategory]:
243277
math_category,
244278
logic_category,
245279
variable_category,
280+
type_category,
246281
input_category,
247282
]
248283

0 commit comments

Comments
 (0)