Skip to content

Commit

Permalink
Finishing work for preemptively closed issue #2399 (#2415)
Browse files Browse the repository at this point in the history
* Update scale `__init__` argument, and delete floating simple.py file

* Adding correct typing to Sprite and AnimatedSprite for scale, and adding validation unit tests

* Sprite now makes input scale a 2 length tuple rather than arbitrary in length

* removing sprite.simple from quick index generation
  • Loading branch information
DragonMoffon authored Oct 14, 2024
1 parent 0444db5 commit 959d796
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
3 changes: 2 additions & 1 deletion arcade/sprite/animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import math

from arcade import Texture
from arcade.types import Point2

from .enums import (
FACE_DOWN,
Expand Down Expand Up @@ -236,7 +237,7 @@ class AnimatedWalkingSprite(Sprite):

def __init__(
self,
scale: float = 1.0,
scale: float | Point2 = 1.0,
center_x: float = 0.0,
center_y: float = 0.0,
**kwargs,
Expand Down
2 changes: 1 addition & 1 deletion arcade/sprite/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(
self._depth = 0.0
self._texture = texture
width, height = texture.size
self._scale = (scale, scale) if isinstance(scale, (float, int)) else scale
self._scale = (scale, scale) if isinstance(scale, (float, int)) else (scale[0], scale[1])
self._width = width * self._scale[0]
self._height = height * self._scale[1]
self._visible = bool(visible)
Expand Down
7 changes: 0 additions & 7 deletions arcade/sprite/simple.py

This file was deleted.

2 changes: 1 addition & 1 deletion arcade/sprite/sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Sprite(BasicSprite, PymunkMixin):
def __init__(
self,
path_or_texture: PathOrTexture | None = None,
scale: float = 1.0,
scale: float | Point2 = 1.0,
center_x: float = 0.0,
center_y: float = 0.0,
angle: float = 0.0,
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/sprite/test_sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@ def test_sprite_rgb_property_basics():
assert sprite.color.a == 15
assert sprite.alpha == 15

def test_sprite_scale_constructor(window):
sprite = arcade.BasicSprite(SPRITE_TEXTURE_GOLD_COIN, scale=2.0)
assert sprite.scale == (2.0, 2.0)
sprite = arcade.BasicSprite(SPRITE_TEXTURE_GOLD_COIN, scale=(2.0, 1.0))
assert sprite.scale == (2.0, 1.0)
sprite = arcade.Sprite(SPRITE_TEXTURE_GOLD_COIN, scale=3.0)
assert sprite.scale == (3.0, 3.0)
sprite = arcade.Sprite(SPRITE_TEXTURE_GOLD_COIN, scale=(3.0, 1.0))
assert sprite.scale == (3.0, 1.0)
sprite = arcade.Sprite(SPRITE_TEXTURE_GOLD_COIN, scale=(1.0, 2.0, 10.0, 100.0))
assert sprite.scale == (1.0, 2.0)
with pytest.raises(TypeError):
sprite = arcade.sprite(SPRITE_TEXTURE_GOLD_COIN, scale = test_sprite_scale_constructor)

sprite = arcade.Sprite(SPRITE_TEXTURE_GOLD_COIN, scale=1.0)
assert isinstance(sprite.scale, tuple)
sprite = arcade.Sprite(SPRITE_TEXTURE_GOLD_COIN, scale=(1.0, 1.0))
assert isinstance(sprite.scale, tuple)
sprite = arcade.Sprite(SPRITE_TEXTURE_GOLD_COIN, scale=[1.0, 1.0])
assert isinstance(sprite.scale, tuple)


def test_sprite_scale_xy(window):
sprite = arcade.SpriteSolidColor(20, 20, color=arcade.color.WHITE)
Expand Down
1 change: 0 additions & 1 deletion util/update_quick_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"arcade.sprite",
"arcade.sprite.base",
"arcade.sprite.sprite",
"arcade.sprite.simple",
"arcade.sprite.colored",
"arcade.sprite.mixins",
"arcade.sprite.animated",
Expand Down

0 comments on commit 959d796

Please sign in to comment.