diff options
author | David Thompson <davet@gnu.org> | 2018-06-24 06:41:57 -0400 |
---|---|---|
committer | David Thompson <davet@gnu.org> | 2018-06-24 06:41:57 -0400 |
commit | 58a4315656fd58284d0a562263c3d947e5992e81 (patch) | |
tree | c2b17a36e7d6216626d239ec735ef3ead87a2987 | |
parent | 3fb346a481e6ce342e4fea742ffa29bb24b43dc2 (diff) |
render: tiled: Add support for external tilesets.
* chickadee/render/tiled.scm (load-tile-map): Handle both internal and
external tilesets.
-rw-r--r-- | chickadee/render/tiled.scm | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/chickadee/render/tiled.scm b/chickadee/render/tiled.scm index cce0683..42b6793 100644 --- a/chickadee/render/tiled.scm +++ b/chickadee/render/tiled.scm @@ -259,9 +259,10 @@ (vector-set! tiles i tile)) (loop (+ i 1)))) tiles)) - (define (parse-tileset node) - (let* ((first-gid (attr node 'firstgid string->number)) - (name (attr node 'name)) + (define (first-gid node) + (attr node 'firstgid string->number)) + (define (parse-internal-tileset node first-gid) + (let* ((name (attr node 'name)) (tile-width (attr node 'tilewidth string->number)) (tile-height (attr node 'tileheight string->number)) (margin (or (attr node 'margin string->number) 0)) @@ -276,6 +277,15 @@ ((sxpath '(properties property)) node)))) (%make-tileset name first-gid size tile-width tile-height atlas tiles properties))) + (define (parse-external-tileset node) + (let* ((first-gid (attr node 'firstgid string->number)) + (source (scope (attr node 'source))) + (tree (call-with-input-file source xml->sxml))) + (parse-internal-tileset (car ((sxpath '(tileset)) tree)) first-gid))) + (define (parse-tileset node) + (if (attr node 'source) + (parse-external-tileset node) + (parse-internal-tileset node (first-gid node)))) (define (tile-gid->map-tile gid tilesets x y tile-width tile-height) (let* ((tileset (find (lambda (t) (and (>= gid (tileset-first-gid t)) |