aboutsummaryrefslogtreecommitdiff
path: root/tests/prefabs-test.scm
diff options
context:
space:
mode:
Diffstat (limited to 'tests/prefabs-test.scm')
-rw-r--r--tests/prefabs-test.scm32
1 files changed, 12 insertions, 20 deletions
diff --git a/tests/prefabs-test.scm b/tests/prefabs-test.scm
index f8cec0a..e635d0a 100644
--- a/tests/prefabs-test.scm
+++ b/tests/prefabs-test.scm
@@ -24,12 +24,6 @@
(define (entity-type entity) (entity-ref entity #:type #f)))
(import downstroke-entity)
-;; Mock downstroke-ai
-(module downstroke-ai *
- (import scheme (chicken base))
- (define (make-enemy-ai-machine) 'mock-ai-machine))
-(import downstroke-ai)
-
;; Load module under test
(include "entity.scm")
(import downstroke-entity)
@@ -45,7 +39,6 @@
(test-assert "physics-body entry exists" (assq 'physics-body m))
(test-assert "has-facing entry exists" (assq 'has-facing m))
(test-assert "animated entry exists" (assq 'animated m))
- (test-assert "ai-body entry exists" (assq 'ai-body m))
(let ((pb (cdr (assq 'physics-body m))))
(test-equal "physics-body has #:vx 0" 0 (cadr (memq #:vx pb)))
@@ -55,12 +48,7 @@
(let ((an (cdr (assq 'animated m))))
(test-equal "animated has #:anim-tick 0" 0 (cadr (memq #:anim-tick an)))
(test-equal "animated has #:tile-id 0" 0 (cadr (memq #:tile-id an)))
- (test-equal "animated has #:anim-name idle" 'idle (cadr (memq #:anim-name an))))
-
- (let ((ai (cdr (assq 'ai-body m))))
- (test-equal "ai-body has #:ai-machine #f" #f (cadr (memq #:ai-machine ai)))
- (test-equal "ai-body has #:disabled #f" #f (cadr (memq #:disabled ai)))
- (test-equal "ai-body has #:chase-origin-x 0" 0 (cadr (memq #:chase-origin-x ai))))))
+ (test-equal "animated has #:anim-name idle" 'idle (cadr (memq #:anim-name an))))))
(test-group "compose-prefab (via load-prefabs with temp file)"
@@ -176,14 +164,18 @@
#t
(entity-ref e #:initialized))))))
- (test-group "init-enemy-ai engine hook"
- (with-hook-registry
- "(npc ai-body has-facing #:type npc #:on-instantiate init-enemy-ai)"
- '()
- (lambda (reg)
+ (test-group "game hook via user-hooks (e.g. init-enemy-ai pattern)"
+ (let ((tmp "/tmp/test-prefabs-user-init.scm"))
+ (with-output-to-file tmp
+ (lambda ()
+ (display
+ "((mixins (ai-body #:ai-facing 1 #:ai-machine #f #:chase-origin-x 0 #:disabled #f))
+ (prefabs (npc ai-body has-facing #:type npc #:on-instantiate init-npc)))")))
+ (let ((reg (load-prefabs tmp (engine-mixins)
+ `((init-npc . ,(lambda (e) (entity-set e #:ai-machine 'from-user-hook)))))))
(let ((e (instantiate-prefab reg 'npc 0 0 16 16)))
- (test-equal "engine hook sets #:ai-machine via make-enemy-ai-machine"
- 'mock-ai-machine
+ (test-equal "user hook sets #:ai-machine"
+ 'from-user-hook
(entity-ref e #:ai-machine))))))
(test-group "no hook: entity returned unchanged"