From 296af5276f920c89d313dfa6d921fb4d94a1a40e Mon Sep 17 00:00:00 2001 From: danvalho Date: Mon, 21 May 2018 19:50:01 +0200 Subject: [PATCH] SpriteFrames: expose method to get array containing animation names --- doc/classes/SpriteFrames.xml | 7 +++++++ scene/2d/animated_sprite.cpp | 12 ++++++++++++ scene/2d/animated_sprite.h | 1 + 3 files changed, 20 insertions(+) diff --git a/doc/classes/SpriteFrames.xml b/doc/classes/SpriteFrames.xml index e806547b7df..57fdb5466e1 100644 --- a/doc/classes/SpriteFrames.xml +++ b/doc/classes/SpriteFrames.xml @@ -127,6 +127,13 @@ Changes the animation's name to [code]newname[/code]. + + + + + Returns an array containing the names associated to each animation. Values are placed in alphabetical order. + + diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index 54194ff5430..5449b1f9636 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -175,6 +175,16 @@ void SpriteFrames::get_animation_list(List *r_animations) const { } } +Vector SpriteFrames::get_animation_names() const { + + Vector names; + for (const Map::Element *E = animations.front(); E; E = E->next()) { + names.push_back(E->key()); + } + names.sort(); + return names; +} + void SpriteFrames::set_animation_speed(const StringName &p_anim, float p_fps) { ERR_FAIL_COND(p_fps < 0); @@ -266,6 +276,8 @@ void SpriteFrames::_bind_methods() { ClassDB::bind_method(D_METHOD("remove_animation", "anim"), &SpriteFrames::remove_animation); ClassDB::bind_method(D_METHOD("rename_animation", "anim", "newname"), &SpriteFrames::rename_animation); + ClassDB::bind_method(D_METHOD("get_animation_names"), &SpriteFrames::get_animation_names); + ClassDB::bind_method(D_METHOD("set_animation_speed", "anim", "speed"), &SpriteFrames::set_animation_speed); ClassDB::bind_method(D_METHOD("get_animation_speed", "anim"), &SpriteFrames::get_animation_speed); diff --git a/scene/2d/animated_sprite.h b/scene/2d/animated_sprite.h index be5b1ef6d66..b9dd840518d 100644 --- a/scene/2d/animated_sprite.h +++ b/scene/2d/animated_sprite.h @@ -72,6 +72,7 @@ public: void rename_animation(const StringName &p_prev, const StringName &p_next); void get_animation_list(List *r_animations) const; + Vector get_animation_names() const; void set_animation_speed(const StringName &p_anim, float p_fps); float get_animation_speed(const StringName &p_anim) const;