Skip to content

Commit 284099c

Browse files
committed
animationplayer_play: Add an extension script to generate an option list
This extension customizes the block's "animation" options list using the list of animations in the block script's context node. https://phabricator.endlessm.com/T35564
1 parent 6f3c604 commit 284099c

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@tool
2+
extends BlockExtension
3+
4+
const OptionData = preload("res://addons/block_code/code_generation/option_data.gd")
5+
6+
7+
func get_defaults_for_node(context_node: Node) -> Dictionary:
8+
var animation_player = context_node as AnimationPlayer
9+
10+
if not animation_player:
11+
return {}
12+
13+
var animation_list = animation_player.get_animation_list()
14+
15+
return {"animation": OptionData.new(animation_list)}

addons/block_code/blocks/graphics/animationplayer_play.tres

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
[gd_resource type="Resource" load_steps=4 format=3 uid="uid://c5e1byehtxwc0"]
1+
[gd_resource type="Resource" load_steps=5 format=3 uid="uid://c5e1byehtxwc0"]
22

33
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_emeuv"]
44
[ext_resource type="Script" path="res://addons/block_code/code_generation/option_data.gd" id="1_xu43h"]
5+
[ext_resource type="Script" path="res://addons/block_code/blocks/graphics/animationplayer_play.gd" id="2_7ymgi"]
56

67
[sub_resource type="Resource" id="Resource_vnp2w"]
78
script = ExtResource("1_xu43h")
@@ -16,14 +17,15 @@ description = "Play the animation."
1617
category = "Graphics | Animation"
1718
type = 2
1819
variant_type = 0
19-
display_template = "Play {animation: STRING} {direction: OPTION}"
20+
display_template = "Play {animation: OPTION} {direction: OPTION}"
2021
code_template = "if \"{direction}\" == \"ahead\":
21-
play({animation})
22+
play(\"{animation}\")
2223
else:
23-
play_backwards({animation})
24+
play_backwards(\"{animation}\")
2425
"
2526
defaults = {
2627
"direction": SubResource("Resource_vnp2w")
2728
}
2829
signal_name = ""
2930
scope = ""
31+
extension_script = ExtResource("2_7ymgi")

addons/block_code/code_generation/block_definition.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,15 @@ func _init(
6464
extension_script = p_extension_script
6565

6666

67+
func get_defaults_for_node(parent_node: Node) -> Dictionary:
68+
if not _extension:
69+
return defaults
70+
71+
# Use Dictionary.merge instead of Dictionary.merged for Godot 4.2 compatibility
72+
var new_defaults := _extension.get_defaults_for_node(parent_node)
73+
new_defaults.merge(defaults)
74+
return new_defaults
75+
76+
6777
func _to_string():
6878
return "%s - %s" % [name, target_node_class]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
@tool
22
class_name BlockExtension
33
extends Object
4+
5+
6+
func get_defaults_for_node(context_node: Node) -> Dictionary:
7+
return {}

0 commit comments

Comments
 (0)