aboutsummaryrefslogtreecommitdiff
path: root/scene-loader.scm
diff options
context:
space:
mode:
Diffstat (limited to 'scene-loader.scm')
-rw-r--r--scene-loader.scm29
1 files changed, 8 insertions, 21 deletions
diff --git a/scene-loader.scm b/scene-loader.scm
index f00cbce..9b5545e 100644
--- a/scene-loader.scm
+++ b/scene-loader.scm
@@ -2,39 +2,26 @@
(import scheme
(chicken base)
(only srfi-1 filter-map)
- (srfi 69)
(prefix sdl2 "sdl2:")
(prefix sdl2-ttf "ttf:")
defstruct
downstroke-tilemap
downstroke-world
- downstroke-engine)
+ downstroke-assets
+ downstroke-engine
+ downstroke-prefabs)
- ;; Create a prefab registry from alternating symbol/constructor pairs.
- ;; Returns a srfi-69 hash-table mapping symbols to constructor functions.
- (define (make-prefab-registry . pairs)
- (let ((ht (make-hash-table)))
- (let loop ((p pairs))
- (if (null? p) ht
- (begin
- (hash-table-set! ht (car p) (cadr p))
- (loop (cddr p)))))))
-
- ;; Instantiate a prefab by type from the registry.
- ;; Returns the entity plist if type exists, #f otherwise.
- (define (instantiate-prefab registry type x y w h)
- (let ((ctor (hash-table-ref/default registry type #f)))
- (and ctor (ctor x y w h))))
;; Convert TMX object list to entities.
;; Object types are strings from XML; convert to symbols before instantiating.
;; Filters out #f results (objects without registered prefabs).
- (define (tilemap-objects->entities tilemap instantiate-fn)
+ (define (tilemap-objects->entities tilemap registry)
(filter-map
(lambda (obj)
- (instantiate-fn (string->symbol (object-type obj))
- (object-x obj) (object-y obj)
- (object-width obj) (object-height obj)))
+ (instantiate-prefab registry
+ (string->symbol (object-type obj))
+ (object-x obj) (object-y obj)
+ (object-width obj) (object-height obj)))
(tilemap-objects tilemap)))
;; Create an SDL2 texture from the tileset image embedded in a tilemap.