Skip to content

Commit

Permalink
Merge pull request #60756 from timothyqiu/animated-sprite-autocomplete
Browse files Browse the repository at this point in the history
Add autocompletion for `AnimatedSprite.play()`
  • Loading branch information
akien-mga authored May 5, 2022
2 parents 90da6ad + 312ec61 commit f6e896a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions scene/2d/animated_sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,17 @@ TypedArray<String> AnimatedSprite2D::get_configuration_warnings() const {
return warnings;
}

void AnimatedSprite2D::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
if (p_idx == 0 && p_function == "play" && frames.is_valid()) {
List<StringName> al;
frames->get_animation_list(&al);
for (const StringName &name : al) {
r_options->push_back(String(name).quote());
}
}
Node::get_argument_options(p_function, p_idx, r_options);
}

void AnimatedSprite2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite2D::set_sprite_frames);
ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite2D::get_sprite_frames);
Expand Down
2 changes: 2 additions & 0 deletions scene/2d/animated_sprite_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class AnimatedSprite2D : public Node2D {
bool is_flipped_v() const;

TypedArray<String> get_configuration_warnings() const override;
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;

AnimatedSprite2D();
};

Expand Down
11 changes: 11 additions & 0 deletions scene/3d/sprite_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,17 @@ TypedArray<String> AnimatedSprite3D::get_configuration_warnings() const {
return warnings;
}

void AnimatedSprite3D::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
if (p_idx == 0 && p_function == "play" && frames.is_valid()) {
List<StringName> al;
frames->get_animation_list(&al);
for (const StringName &name : al) {
r_options->push_back(String(name).quote());
}
}
Node::get_argument_options(p_function, p_idx, r_options);
}

void AnimatedSprite3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite3D::set_sprite_frames);
ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite3D::get_sprite_frames);
Expand Down
2 changes: 2 additions & 0 deletions scene/3d/sprite_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ class AnimatedSprite3D : public SpriteBase3D {
virtual Rect2 get_item_rect() const override;

virtual TypedArray<String> get_configuration_warnings() const override;
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;

AnimatedSprite3D();
};

Expand Down

0 comments on commit f6e896a

Please sign in to comment.