diff options
Diffstat (limited to 'scene/2d/animated_sprite_2d.cpp')
-rw-r--r-- | scene/2d/animated_sprite_2d.cpp | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index fc34f967ce..842740aa5e 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -103,7 +103,6 @@ Rect2 AnimatedSprite2D::_get_rect() const { } void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture2D> &p_frame, int p_at_pos) { - Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); @@ -123,7 +122,6 @@ int SpriteFrames::get_frame_count(const StringName &p_anim) const { } void SpriteFrames::remove_frame(const StringName &p_anim, int p_idx) { - Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); @@ -131,7 +129,6 @@ void SpriteFrames::remove_frame(const StringName &p_anim, int p_idx) { emit_changed(); } void SpriteFrames::clear(const StringName &p_anim) { - Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); @@ -140,13 +137,11 @@ void SpriteFrames::clear(const StringName &p_anim) { } void SpriteFrames::clear_all() { - animations.clear(); add_animation("default"); } void SpriteFrames::add_animation(const StringName &p_anim) { - ERR_FAIL_COND_MSG(animations.has(p_anim), "SpriteFrames already has animation '" + p_anim + "'."); animations[p_anim] = Anim(); @@ -155,16 +150,13 @@ void SpriteFrames::add_animation(const StringName &p_anim) { } bool SpriteFrames::has_animation(const StringName &p_anim) const { - return animations.has(p_anim); } void SpriteFrames::remove_animation(const StringName &p_anim) { - animations.erase(p_anim); } void SpriteFrames::rename_animation(const StringName &p_prev, const StringName &p_next) { - ERR_FAIL_COND_MSG(!animations.has(p_prev), "SpriteFrames doesn't have animation '" + String(p_prev) + "'."); ERR_FAIL_COND_MSG(animations.has(p_next), "Animation '" + String(p_next) + "' already exists."); @@ -176,12 +168,10 @@ void SpriteFrames::rename_animation(const StringName &p_prev, const StringName & } Vector<String> SpriteFrames::_get_animation_list() const { - Vector<String> ret; List<StringName> al; get_animation_list(&al); for (List<StringName>::Element *E = al.front(); E; E = E->next()) { - ret.push_back(E->get()); } @@ -189,14 +179,12 @@ Vector<String> SpriteFrames::_get_animation_list() const { } void SpriteFrames::get_animation_list(List<StringName> *r_animations) const { - for (const Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) { r_animations->push_back(E->key()); } } Vector<String> SpriteFrames::get_animation_names() const { - Vector<String> names; for (const Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) { names.push_back(E->key()); @@ -206,14 +194,12 @@ Vector<String> SpriteFrames::get_animation_names() const { } void SpriteFrames::set_animation_speed(const StringName &p_anim, float p_fps) { - ERR_FAIL_COND_MSG(p_fps < 0, "Animation speed cannot be negative (" + itos(p_fps) + ")."); Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist."); E->get().speed = p_fps; } float SpriteFrames::get_animation_speed(const StringName &p_anim) const { - const Map<StringName, Anim>::Element *E = animations.find(p_anim); ERR_FAIL_COND_V_MSG(!E, 0, "Animation '" + String(p_anim) + "' doesn't exist."); return E->get().speed; @@ -231,7 +217,6 @@ bool SpriteFrames::get_animation_loop(const StringName &p_anim) const { } void SpriteFrames::_set_frames(const Array &p_frames) { - clear_all(); Map<StringName, Anim>::Element *E = animations.find(SceneStringNames::get_singleton()->_default); ERR_FAIL_COND(!E); @@ -241,12 +226,10 @@ void SpriteFrames::_set_frames(const Array &p_frames) { E->get().frames.write[i] = p_frames[i]; } Array SpriteFrames::_get_frames() const { - return Array(); } Array SpriteFrames::_get_animations() const { - Array anims; for (Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) { Dictionary d; @@ -264,10 +247,8 @@ Array SpriteFrames::_get_animations() const { return anims; } void SpriteFrames::_set_animations(const Array &p_animations) { - animations.clear(); for (int i = 0; i < p_animations.size(); i++) { - Dictionary d = p_animations[i]; ERR_CONTINUE(!d.has("name")); @@ -280,7 +261,6 @@ void SpriteFrames::_set_animations(const Array &p_animations) { anim.loop = d["loop"]; Array frames = d["frames"]; for (int j = 0; j < frames.size(); j++) { - RES res = frames[j]; anim.frames.push_back(res); } @@ -290,7 +270,6 @@ void SpriteFrames::_set_animations(const Array &p_animations) { } void SpriteFrames::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_animation", "anim"), &SpriteFrames::add_animation); ClassDB::bind_method(D_METHOD("has_animation", "anim"), &SpriteFrames::has_animation); ClassDB::bind_method(D_METHOD("remove_animation", "anim"), &SpriteFrames::remove_animation); @@ -324,16 +303,13 @@ void SpriteFrames::_bind_methods() { } SpriteFrames::SpriteFrames() { - add_animation(SceneStringNames::get_singleton()->_default); } void AnimatedSprite2D::_validate_property(PropertyInfo &property) const { - if (!frames.is_valid()) return; if (property.name == "animation") { - property.hint = PROPERTY_HINT_ENUM; List<StringName> names; frames->get_animation_list(&names); @@ -371,10 +347,8 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &property) const { } void AnimatedSprite2D::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_INTERNAL_PROCESS: { - if (frames.is_null()) return; if (!frames->has_animation(animation)) @@ -389,9 +363,7 @@ void AnimatedSprite2D::_notification(int p_what) { float remaining = get_process_delta_time(); while (remaining) { - if (timeout <= 0) { - timeout = _get_frame_duration(); int fc = frames->get_frame_count(animation); @@ -433,7 +405,6 @@ void AnimatedSprite2D::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { - if (frames.is_null()) return; if (frame < 0) @@ -473,7 +444,6 @@ void AnimatedSprite2D::_notification(int p_what) { } void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) { - if (frames.is_valid()) frames->disconnect("changed", callable_mp(this, &AnimatedSprite2D::_res_changed)); frames = p_frames; @@ -493,12 +463,10 @@ void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) { } Ref<SpriteFrames> AnimatedSprite2D::get_sprite_frames() const { - return frames; } void AnimatedSprite2D::set_frame(int p_frame) { - if (!frames.is_valid()) { return; } @@ -522,12 +490,10 @@ void AnimatedSprite2D::set_frame(int p_frame) { emit_signal(SceneStringNames::get_singleton()->frame_changed); } int AnimatedSprite2D::get_frame() const { - return frame; } void AnimatedSprite2D::set_speed_scale(float p_speed_scale) { - float elapsed = _get_frame_duration() - timeout; speed_scale = MAX(p_speed_scale, 0.0f); @@ -538,56 +504,46 @@ void AnimatedSprite2D::set_speed_scale(float p_speed_scale) { } float AnimatedSprite2D::get_speed_scale() const { - return speed_scale; } void AnimatedSprite2D::set_centered(bool p_center) { - centered = p_center; update(); item_rect_changed(); } bool AnimatedSprite2D::is_centered() const { - return centered; } void AnimatedSprite2D::set_offset(const Point2 &p_offset) { - offset = p_offset; update(); item_rect_changed(); _change_notify("offset"); } Point2 AnimatedSprite2D::get_offset() const { - return offset; } void AnimatedSprite2D::set_flip_h(bool p_flip) { - hflip = p_flip; update(); } bool AnimatedSprite2D::is_flipped_h() const { - return hflip; } void AnimatedSprite2D::set_flip_v(bool p_flip) { - vflip = p_flip; update(); } bool AnimatedSprite2D::is_flipped_v() const { - return vflip; } void AnimatedSprite2D::_res_changed() { - set_frame(frame); _change_notify("frame"); _change_notify("animation"); @@ -595,7 +551,6 @@ void AnimatedSprite2D::_res_changed() { } void AnimatedSprite2D::_set_playing(bool p_playing) { - if (playing == p_playing) return; playing = p_playing; @@ -604,12 +559,10 @@ void AnimatedSprite2D::_set_playing(bool p_playing) { } bool AnimatedSprite2D::_is_playing() const { - return playing; } void AnimatedSprite2D::play(const StringName &p_animation, const bool p_backwards) { - backwards = p_backwards; if (p_animation) { @@ -622,12 +575,10 @@ void AnimatedSprite2D::play(const StringName &p_animation, const bool p_backward } void AnimatedSprite2D::stop() { - _set_playing(false); } bool AnimatedSprite2D::is_playing() const { - return playing; } @@ -642,7 +593,6 @@ float AnimatedSprite2D::_get_frame_duration() { } void AnimatedSprite2D::_reset_timeout() { - if (!playing) return; @@ -651,7 +601,6 @@ void AnimatedSprite2D::_reset_timeout() { } void AnimatedSprite2D::set_animation(const StringName &p_animation) { - ERR_FAIL_COND_MSG(frames == nullptr, vformat("There is no animation with name '%s'.", p_animation)); ERR_FAIL_COND_MSG(frames->get_animation_names().find(p_animation) == -1, vformat("There is no animation with name '%s'.", p_animation)); @@ -665,12 +614,10 @@ void AnimatedSprite2D::set_animation(const StringName &p_animation) { update(); } StringName AnimatedSprite2D::get_animation() const { - return animation; } String AnimatedSprite2D::get_configuration_warning() const { - if (frames.is_null()) { return TTR("A SpriteFrames resource must be created or set in the \"Frames\" property in order for AnimatedSprite to display frames."); } @@ -697,7 +644,6 @@ float AnimatedSprite2D::get_shininess() const { } 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); @@ -755,7 +701,6 @@ void AnimatedSprite2D::_bind_methods() { } AnimatedSprite2D::AnimatedSprite2D() { - centered = true; hflip = false; vflip = false; |