Skip to content

Commit

Permalink
Merge pull request #85311 from miv391/add-change-guards-to-sprite2d
Browse files Browse the repository at this point in the history
Add property change guards to Sprite2D, Sprite3D and AnimatedSprite2D
  • Loading branch information
YuriSizov committed Dec 18, 2023
2 parents 5c84817 + 5b9e67e commit 4600acf
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 23 deletions.
16 changes: 16 additions & 0 deletions scene/2d/animated_sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ float AnimatedSprite2D::get_playing_speed() const {
}

void AnimatedSprite2D::set_centered(bool p_center) {
if (centered == p_center) {
return;
}

centered = p_center;
queue_redraw();
item_rect_changed();
Expand All @@ -391,6 +395,10 @@ bool AnimatedSprite2D::is_centered() const {
}

void AnimatedSprite2D::set_offset(const Point2 &p_offset) {
if (offset == p_offset) {
return;
}

offset = p_offset;
queue_redraw();
item_rect_changed();
Expand All @@ -401,6 +409,10 @@ Point2 AnimatedSprite2D::get_offset() const {
}

void AnimatedSprite2D::set_flip_h(bool p_flip) {
if (hflip == p_flip) {
return;
}

hflip = p_flip;
queue_redraw();
}
Expand All @@ -410,6 +422,10 @@ bool AnimatedSprite2D::is_flipped_h() const {
}

void AnimatedSprite2D::set_flip_v(bool p_flip) {
if (vflip == p_flip) {
return;
}

vflip = p_flip;
queue_redraw();
}
Expand Down
38 changes: 34 additions & 4 deletions scene/2d/sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ Ref<Texture2D> Sprite2D::get_texture() const {
}

void Sprite2D::set_centered(bool p_center) {
if (centered == p_center) {
return;
}

centered = p_center;
queue_redraw();
item_rect_changed();
Expand All @@ -165,6 +169,10 @@ bool Sprite2D::is_centered() const {
}

void Sprite2D::set_offset(const Point2 &p_offset) {
if (offset == p_offset) {
return;
}

offset = p_offset;
queue_redraw();
item_rect_changed();
Expand All @@ -175,6 +183,10 @@ Point2 Sprite2D::get_offset() const {
}

void Sprite2D::set_flip_h(bool p_flip) {
if (hflip == p_flip) {
return;
}

hflip = p_flip;
queue_redraw();
}
Expand All @@ -184,6 +196,10 @@ bool Sprite2D::is_flipped_h() const {
}

void Sprite2D::set_flip_v(bool p_flip) {
if (vflip == p_flip) {
return;
}

vflip = p_flip;
queue_redraw();
}
Expand All @@ -193,7 +209,7 @@ bool Sprite2D::is_flipped_v() const {
}

void Sprite2D::set_region_enabled(bool p_region_enabled) {
if (p_region_enabled == region_enabled) {
if (region_enabled == p_region_enabled) {
return;
}

Expand Down Expand Up @@ -223,6 +239,10 @@ Rect2 Sprite2D::get_region_rect() const {
}

void Sprite2D::set_region_filter_clip_enabled(bool p_region_filter_clip_enabled) {
if (region_filter_clip_enabled == p_region_filter_clip_enabled) {
return;
}

region_filter_clip_enabled = p_region_filter_clip_enabled;
queue_redraw();
}
Expand All @@ -234,12 +254,12 @@ bool Sprite2D::is_region_filter_clip_enabled() const {
void Sprite2D::set_frame(int p_frame) {
ERR_FAIL_INDEX(p_frame, vframes * hframes);

if (frame != p_frame) {
item_rect_changed();
if (frame == p_frame) {
return;
}

frame = p_frame;

item_rect_changed();
emit_signal(SceneStringNames::get_singleton()->frame_changed);
}

Expand All @@ -260,6 +280,11 @@ Vector2i Sprite2D::get_frame_coords() const {

void Sprite2D::set_vframes(int p_amount) {
ERR_FAIL_COND_MSG(p_amount < 1, "Amount of vframes cannot be smaller than 1.");

if (vframes == p_amount) {
return;
}

vframes = p_amount;
if (frame >= vframes * hframes) {
frame = 0;
Expand All @@ -275,6 +300,11 @@ int Sprite2D::get_vframes() const {

void Sprite2D::set_hframes(int p_amount) {
ERR_FAIL_COND_MSG(p_amount < 1, "Amount of hframes cannot be smaller than 1.");

if (hframes == p_amount) {
return;
}

if (vframes > 1) {
// Adjust the frame to fit new sheet dimensions.
int original_column = frame % hframes;
Expand Down
Loading

0 comments on commit 4600acf

Please sign in to comment.