Christian Kellermann avatar Christian Kellermann committed aa84f60

Add support for #:tileset

Comments (0)

Files changed (1)

             (set! *resources*
                   (alist-update! name (make-img-res name file s w h x-off y-off scale-factor)
                                 *resources*))))
+         ('#:tileset
+          (when (or (null? data)
+                    (not (= (length data) 2)))
+                (error "Tileset needs tile-size and list of tiles but got " data))
+          (let* ((ts (cairo-image-surface-create-from-png file))
+                 (w (cairo-image-surface-get-width ts))
+                 (h (cairo-image-surface-get-height ts))
+                 (tile-size
+                  (if (number? (car data))
+                      (car data)
+                      (error "Tile-set parameter needs to be a number")))
+                 (tiles (if (list? (cadr data))
+                            (cadr data)
+                            (error "Second data parameter must be a list of tiles"))))
+            (for-each
+             (lambda (t)
+               (if (and (list t)
+                        (= (length t) 2))
+                   (let* ((tile-name (car t))
+                          (tile-number (cadr t))
+                          (tile-x (modulo (* tile-number tile-size) w))
+                          (tile-y (* tile-size (quotient (* tile-size tile-number) w)))
+                          (tile-img
+                           (cairo-surface-create-for-rectangle ts tile-x tile-y tile-size tile-size)))
+                     (set! *resources*
+                           (alist-update! (car t) (make-img-res tile-name file tile-img tile-size tile-size 0 0 #f)
+                                          *resources*)))
+                   (error "Malformed tile information entry " t)))
+             tiles)))
          (else (error "Unkown resource type " type))))
 
 (define (blit-image name x y)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.