diff options
| author | Gene Pasquet <dev@etenil.net> | 2026-04-06 01:26:46 +0100 |
|---|---|---|
| committer | Gene Pasquet <dev@etenil.net> | 2026-04-06 02:14:33 +0100 |
| commit | c4ebbbdd1a0bd081a2ed9447ba8188d97ae54717 (patch) | |
| tree | 3e15f87d7fda6ca0f4aa64ae236dd156796b01b2 /scene-loader.scm | |
| parent | 300131ca5a19d9de5250579d944a52b067b2d60b (diff) | |
Prefabs
Diffstat (limited to 'scene-loader.scm')
| -rw-r--r-- | scene-loader.scm | 29 |
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. |
