diff options
| author | Gene Pasquet <dev@etenil.net> | 2026-04-12 15:57:45 +0100 |
|---|---|---|
| committer | Gene Pasquet <dev@etenil.net> | 2026-04-12 15:57:45 +0100 |
| commit | c1c868d9b6ee61002c7ccb33fbc6a15c5b090e6a (patch) | |
| tree | b818607a0e2ab52113e3fcead77a096b9adfdbfb /animation.scm | |
| parent | e1da1b0c2b2df9880e7f0a76b6ecc7aefecaf229 (diff) | |
Enrich entities pipelining to provide scene context to processors
Diffstat (limited to 'animation.scm')
| -rw-r--r-- | animation.scm | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/animation.scm b/animation.scm index 468f7f0..c8f4497 100644 --- a/animation.scm +++ b/animation.scm @@ -1,17 +1,17 @@ (module downstroke-animation * - (import scheme - (chicken base) - (chicken keyword) - (only srfi-1 filter) - downstroke-entity - downstroke-world) +(import scheme + (chicken base) + (chicken keyword) + (only srfi-1 filter) + downstroke-entity + downstroke-world) - ;; ---- Animation data accessors ---- +;; ---- Animation data accessors ---- - (define (animation-frames anim) - (get-keyword #:frames anim)) - (define (animation-duration anim) - (get-keyword #:duration anim)) +(define (animation-frames anim) + (get-keyword #:frames anim)) +(define (animation-duration anim) + (get-keyword #:duration anim)) (define (frame-by-idx frames frame-idx) (list-ref frames (modulo frame-idx (length frames)))) @@ -19,9 +19,9 @@ ;; The tile ID is 1-indexed. (define (frame->tile-id frames frame-idx) (let ((frame-def (frame-by-idx frames frame-idx))) - (+ 1 (if (list? frame-def) - (car frame-def) - frame-def)))) + (if (list? frame-def) + (car frame-def) + frame-def))) (define (frame->duration frames frame-idx) (let ((frame-def (frame-by-idx frames frame-idx))) @@ -42,7 +42,7 @@ (define (animation-by-name animations name) - (let ((matching-anims (filter (lambda (anim) (eq? (get-keyword #:name anim) 'walk)) animations))) + (let ((matching-anims (filter (lambda (anim) (eq? (get-keyword #:name anim) name)) animations))) (if matching-anims (car matching-anims) #f))) @@ -68,10 +68,16 @@ (list (cons #:anim-tick tick) (cons #:tile-id (frame->tile-id frames frame))))))) - (define (animate-entity entity animations) - (let* ((anim-name (entity-ref entity #:anim-name #f)) - (anim (and anim-name (animation-by-name animations anim-name)))) - (if anim - (advance-animation entity anim) - entity))) +(define (animate-entity entity animations) + (let* ((anim-name (entity-ref entity #:anim-name #f)) + (anim (and anim-name (animation-by-name animations anim-name)))) + (if anim + (advance-animation entity anim) + entity))) + +(define-pipeline (apply-animation animation) (scene entity dt) + guard: (entity-ref entity #:animations #f) + (let ((animations (entity-ref entity #:animations #f))) + (animate-entity entity animations))) + ) ;; End of animation module |
