slightly better tileset code

master
Josha von Gizycki 6 years ago
parent edcfd29de8
commit 635c391e54

@ -54,15 +54,22 @@
(assoc :tiles-y (/ (:tilecount tileset)
(:columns tileset)))))
(defn map-layer-tiles [map-def]
(let [ftileset (first (:tilesets map-def))]
(-> map-def
(update :layers
#(map (partial tileset/layer->dest ftileset) %)))))
(defn init-map-def [scenestate]
(if (and (not (get-in scenestate [:tileset :def]))
(some? @map-def))
(assoc-in scenestate
[:tileset :def]
(update (walk/keywordize-keys @map-def)
:tilesets
(fn [tilesets]
(map map-tileset-size tilesets))))
(assoc-in
scenestate
[:tileset :def]
(-> @map-def
(walk/keywordize-keys)
(update :tilesets #(map map-tileset-size %))
map-layer-tiles))
scenestate))
(defn update-scene [gamestate scenestate]

@ -39,7 +39,7 @@
[(dec x)
(/ (- ix x) width)]))
(defn layer->dest [layer tileset data]
(defn layer->dest [tileset layer]
(map-indexed
(fn [ix tile]
(let [{:keys [width height]} layer
@ -50,7 +50,7 @@
:y (* dyc tileheight)
:w tilewidth
:h tileheight}))
data))
(:data layer)))
(defn draw-tile [ctx tileset image tileid dest]
(let [{:keys [tileheight tilewidth
@ -70,11 +70,8 @@
tileset-id (:tileset viewport)
image (tileset-id images)
tileset (map-def->tileset def (:tileset viewport))]
(doseq [layer layers
:let [destinations (->> (:data layer)
(layer->dest layer tileset)
(filter #(not= 0 (:tile %))))]]
(doseq [dest destinations
(doseq [layer layers]
(doseq [dest layer
:let [dx (- (:x dest) (:x viewport))
dy (- (:y dest) (:y viewport))]]
(draw-tile ctx tileset image

Loading…
Cancel
Save