diff options
| author | Gene Pasquet <dev@etenil.net> | 2026-04-17 16:30:34 +0100 |
|---|---|---|
| committer | Gene Pasquet <dev@etenil.net> | 2026-04-17 16:30:34 +0100 |
| commit | 8251c85a4a588504d38a2fad05e4b0fe1cdccb9d (patch) | |
| tree | c3fcedb7331caf798f2355c7549b35aa3aaf6ac8 /tests/animation-test.scm | |
| parent | 5de3b9cf122542f2a0c1c906c8ce8add20e5c8c6 (diff) | |
Convert entities to alists
Diffstat (limited to 'tests/animation-test.scm')
| -rw-r--r-- | tests/animation-test.scm | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/tests/animation-test.scm b/tests/animation-test.scm index 87b18e7..aae829a 100644 --- a/tests/animation-test.scm +++ b/tests/animation-test.scm @@ -1,10 +1,15 @@ -(import srfi-64) +(import srfi-64 + (only (list-utils alist) plist->alist)) (include "entity.scm") (include "tilemap.scm") (include "world.scm") (include "animation.scm") (import downstroke-entity downstroke-world downstroke-animation) +;; Test helpers: construct alist entities / animation defs from readable plist kwargs. +(define (entity . kws) (plist->alist kws)) +(define (anim . kws) (plist->alist kws)) + (test-begin "animation") (test-group "frame->tile-id" @@ -24,44 +29,44 @@ ) (test-group "set-animation" - (let ((entity (list #:type 'player #:anim-name 'idle #:anim-frame 5 #:anim-tick 8))) - (test-equal "no-op if already active" entity (set-animation entity 'idle)) - (let ((switched (set-animation entity 'walk))) + (let ((e (entity #:type 'player #:anim-name 'idle #:anim-frame 5 #:anim-tick 8))) + (test-equal "no-op if already active" e (set-animation e 'idle)) + (let ((switched (set-animation e 'walk))) (test-equal "switches anim-name" 'walk (entity-ref switched #:anim-name)) (test-equal "resets frame" 0 (entity-ref switched #:anim-frame)) (test-equal "resets tick" 0 (entity-ref switched #:anim-tick))))) (test-group "animate-entity" (test-group "Single frames" - (let* ((anims '((#:name walk #:frames (2 3) #:duration 4))) - (entity (list #:type 'player #:anim-name 'walk #:anim-frame 0 #:anim-tick 0)) - (stepped (animate-entity entity anims))) + (let* ((anims (list (anim #:name 'walk #:frames '(2 3) #:duration 4))) + (e (entity #:type 'player #:anim-name 'walk #:anim-frame 0 #:anim-tick 0)) + (stepped (animate-entity e anims))) (test-equal "increments tick" 1 (entity-ref stepped #:anim-tick)) (test-equal "sets tile-id on first tick" 2 (entity-ref stepped #:tile-id))) - (let* ((anims '((#:name walk #:frames (0 1) #:duration 2))) - (entity (list #:type 'player #:anim-name 'walk #:anim-frame 0 #:anim-tick 1)) - (advanced (animate-entity entity anims))) + (let* ((anims (list (anim #:name 'walk #:frames '(0 1) #:duration 2))) + (e (entity #:type 'player #:anim-name 'walk #:anim-frame 0 #:anim-tick 1)) + (advanced (animate-entity e anims))) (test-equal "advances frame when tick reaches duration" 1 (entity-ref advanced #:anim-frame)) (test-equal "resets tick on frame advance" 0 (entity-ref advanced #:anim-tick)))) (test-group "Frames with duration" - (let* ((anims '((#:name walk #:frames ((0 10) (1 20)) #:duration 4))) - (entity (list #:type 'player #:anim-name 'walk #:anim-frame 0 #:anim-tick 9)) - (stepped (animate-entity entity anims))) + (let* ((anims (list (anim #:name 'walk #:frames '((0 10) (1 20)) #:duration 4))) + (e (entity #:type 'player #:anim-name 'walk #:anim-frame 0 #:anim-tick 9)) + (stepped (animate-entity e anims))) (test-equal "ticks resets on frame switch" 0 (entity-ref stepped #:anim-tick)) (test-equal "sets tile-id on 10th tick" 1 (entity-ref stepped #:tile-id)) (test-equal "sets duration to frame duration" 20 (entity-ref stepped #:duration)))) (test-group "Empty" - (let* ((entity (list #:type 'player))) - (test-equal "unchanged entity without anim-name" entity (animate-entity entity '()))))) + (let* ((e (entity #:type 'player))) + (test-equal "unchanged entity without anim-name" e (animate-entity e '()))))) (test-group "animation pipeline" (test-group "animated entity" - (let* ((anims '((#:name walk #:frames (2 3) #:duration 4))) - (entity (list #:type 'player #:anim-name 'walk #:anim-frame 0 #:anim-tick 0 #:animations anims)) - (stepped-entity (apply-animation #f entity 10))) + (let* ((anims (list (anim #:name 'walk #:frames '(2 3) #:duration 4))) + (e (entity #:type 'player #:anim-name 'walk #:anim-frame 0 #:anim-tick 0 #:animations anims)) + (stepped-entity (apply-animation #f e 10))) (test-equal "Updated animated entity" 1 (entity-ref stepped-entity #:anim-tick))) - (let* ((entity (list #:type 'static)) - (stepped-entity (apply-animation #f entity 10))) + (let* ((e (entity #:type 'static)) + (stepped-entity (apply-animation #f e 10))) (test-equal "unchanged static entity" #f (entity-ref stepped-entity #:anim-tick))))) (test-end "animation") |
