Skip to content

Commit

Permalink
Merge #308
Browse files Browse the repository at this point in the history
308: Apply Assets to Animation r=pathunstrom a=astronouth7303

Depends on #306

Part of #147

Co-authored-by: Jamie Bliss <jamie@ivyleav.es>
  • Loading branch information
bors[bot] and AstraLuma committed Jul 15, 2019
2 parents 4bea37e + d1af9ae commit 166cbc3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
7 changes: 4 additions & 3 deletions ppb/features/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import time
import re
import ppb

FILE_PATTERN = re.compile(r'\{(\d+)\.\.(\d+)\}')

Expand Down Expand Up @@ -65,7 +66,7 @@ def _compile_filename(self):
self._filename,
)
self._frames = [
template.format(n)
ppb.Image(template.format(n))
for n in range(start, end + 1)
]

Expand Down Expand Up @@ -108,11 +109,11 @@ def current_frame(self):
else:
return self._paused_frame

def __str__(self):
def load(self):
"""
Get the current frame path.
"""
return self._frames[self.current_frame]
return self._frames[self.current_frame].load()

# This is so that if you assign an Animation to a class, instances will get
# their own copy, so their animations run independently.
Expand Down
37 changes: 17 additions & 20 deletions tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ class FakeAnimation(Animation):

anim = FakeAnimation("{2..5}", 1)

assert [f.name for f in anim._frames] == ["2", "3", "4", "5"]

time = 0
assert anim.current_frame == 0
assert str(anim) == '2'

time = 1
assert anim.current_frame == 1
assert str(anim) == '3'

time = 3
assert anim.current_frame == 3
assert str(anim) == '5'

time = 4
assert anim.current_frame == 0
assert str(anim) == '2'


def test_pause():
Expand All @@ -42,26 +40,28 @@ class FakeAnimation(Animation):

anim = FakeAnimation("{0..9}", 1)

assert [f.name for f in anim._frames] == ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]

time = 0
assert str(anim) == '0'
assert anim.current_frame == 0

time = 5
assert str(anim) == '5'
assert anim.current_frame == 5

anim.pause()
assert str(anim) == '5'
assert anim.current_frame == 5

time = 12
assert str(anim) == '5'
assert anim.current_frame == 5

anim.unpause()
assert str(anim) == '5'
assert anim.current_frame == 5

time = 16
assert str(anim) == '9'
assert anim.current_frame == 9

time = 18
assert str(anim) == '1'
assert anim.current_frame == 1


def test_filename():
Expand All @@ -76,14 +76,11 @@ class FakeAnimation(Animation):

anim = FakeAnimation("spam{0..9}", 1)

time = 0
assert str(anim) == 'spam0'

time = 5
assert str(anim) == 'spam5'
assert [f.name for f in anim._frames] == [
"spam0", "spam1", "spam2", "spam3", "spam4", "spam5", "spam6", "spam7", "spam8", "spam9",
]

anim.filename = 'eggs{0..4}'
assert str(anim) == 'eggs0'

time = 7
assert str(anim) == 'eggs2'
assert [f.name for f in anim._frames] == [
"eggs0", "eggs1", "eggs2", "eggs3", "eggs4",
]

0 comments on commit 166cbc3

Please sign in to comment.