From 296d13236fe7e8d76ccf9c8ddc0073229755ad0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Mon, 8 Jul 2024 15:41:56 -0300 Subject: [PATCH] Add blocks for AnimationPlayer - Play (ahead/backwards) - Pause - Stop - is playing? https://phabricator.endlessm.com/T35543 --- .../ui/picker/categories/category_factory.gd | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/addons/block_code/ui/picker/categories/category_factory.gd b/addons/block_code/ui/picker/categories/category_factory.gd index b1c57009..ba85a11e 100644 --- a/addons/block_code/ui/picker/categories/category_factory.gd +++ b/addons/block_code/ui/picker/categories/category_factory.gd @@ -47,6 +47,11 @@ const BUILTIN_PROPS: Dictionary = { "color": Color("03aa74"), "order": 61, }, + "Graphics | Animation": + { + "color": Color("03aa74"), + "order": 62, + }, "Sounds": { "color": Color("e30fc0"), @@ -630,6 +635,47 @@ static func get_built_in_blocks(_class_name: String) -> Array[Block]: "angular_velocity": "Physics | Velocity", } + "AnimationPlayer": + var b = BLOCKS["statement_block"].instantiate() + b.block_format = "Play {animation: STRING} {direction: OPTION}" + b.statement = ( + """ + if "{direction}" == "ahead": + play({animation}) + else: + play_backwards({animation}) + """ + . dedent() + ) + b.defaults = { + "direction": OptionData.new(["ahead", "backwards"]), + } + b.tooltip_text = "Play the animation." + b.category = "Graphics | Animation" + block_list.append(b) + + b = BLOCKS["statement_block"].instantiate() + b.block_format = "Pause" + b.statement = "pause()" + b.tooltip_text = "Pause the currently playing animation." + b.category = "Graphics | Animation" + block_list.append(b) + + b = BLOCKS["statement_block"].instantiate() + b.block_format = "Stop" + b.statement = "stop()" + b.tooltip_text = "Stop the currently playing animation." + b.category = "Graphics | Animation" + block_list.append(b) + + b = BLOCKS["parameter_block"].instantiate() + b.variant_type = TYPE_BOOL + b.block_format = "Is playing" + b.statement = "is_playing()" + b.tooltip_text = "Check if an animation is currently playing." + b.category = "Graphics | Animation" + block_list.append(b) + "Area2D": for verb in ["entered", "exited"]: var b = BLOCKS["entry_block"].instantiate()