|
|
|
@ -27,8 +27,8 @@
|
|
|
|
|
(next-animation-cycle animation curr-cycle))]
|
|
|
|
|
(if trigger-cycle?
|
|
|
|
|
(assoc anim-def
|
|
|
|
|
:last-cycle now
|
|
|
|
|
:curr-id (:tileid next-cycle))
|
|
|
|
|
:last-cycle now
|
|
|
|
|
:curr-id (:tileid next-cycle))
|
|
|
|
|
anim-def)))
|
|
|
|
|
|
|
|
|
|
(defn ix->coords [ix width]
|
|
|
|
@ -36,17 +36,43 @@
|
|
|
|
|
[(dec x)
|
|
|
|
|
(/ (- ix x) width)]))
|
|
|
|
|
|
|
|
|
|
(defn layer->dest [tileset layer]
|
|
|
|
|
(defn map-tileset
|
|
|
|
|
[zoom {:keys [tilewidth tileheight columns tilecount]
|
|
|
|
|
:as tileset}]
|
|
|
|
|
(assoc tileset
|
|
|
|
|
:target-width (* zoom tilewidth)
|
|
|
|
|
:target-height (* zoom tileheight)
|
|
|
|
|
:tiles-x columns
|
|
|
|
|
:tiles-y (/ tilecount columns)))
|
|
|
|
|
|
|
|
|
|
(defn map-tilesets [zoom map-def]
|
|
|
|
|
(update map-def
|
|
|
|
|
:tilesets
|
|
|
|
|
(fn [tilesets]
|
|
|
|
|
(map (partial map-tileset zoom)
|
|
|
|
|
tilesets))))
|
|
|
|
|
|
|
|
|
|
(defn layer->dest [{:keys [target-width target-height]} layer]
|
|
|
|
|
(map-indexed
|
|
|
|
|
(fn [ix tile]
|
|
|
|
|
(let [[dxc dyc] (ix->coords ix (:width layer))
|
|
|
|
|
{:keys [target-width target-height]} tileset]
|
|
|
|
|
{:tile tile
|
|
|
|
|
:x (* dxc target-width)
|
|
|
|
|
:y (* dyc target-height)
|
|
|
|
|
:w target-width
|
|
|
|
|
:h target-height}))
|
|
|
|
|
(:data layer)))
|
|
|
|
|
(fn [ix tile]
|
|
|
|
|
(let [[dxc dyc] (ix->coords ix (:width layer))]
|
|
|
|
|
{:tile tile
|
|
|
|
|
:x (* dxc target-width)
|
|
|
|
|
:y (* dyc target-height)
|
|
|
|
|
:w target-width
|
|
|
|
|
:h target-height}))
|
|
|
|
|
(:data layer)))
|
|
|
|
|
|
|
|
|
|
(defn map-layers [map-def]
|
|
|
|
|
(let [first-tileset (-> map-def :tilesets first)]
|
|
|
|
|
(update map-def
|
|
|
|
|
:layers
|
|
|
|
|
(fn [layers]
|
|
|
|
|
(map (partial layer->dest first-tileset)
|
|
|
|
|
layers)))))
|
|
|
|
|
|
|
|
|
|
(defn prepare-map-def [zoom map-def]
|
|
|
|
|
(map-layers (map-tilesets zoom map-def)))
|
|
|
|
|
|
|
|
|
|
(defn draw-tile [ctx tileset image tileid dest]
|
|
|
|
|
(let [{:keys [tileheight tilewidth
|
|
|
|
@ -59,31 +85,12 @@
|
|
|
|
|
(int (:x dest)) (int (:y dest))
|
|
|
|
|
target-width target-height)))
|
|
|
|
|
|
|
|
|
|
(defn map-tilesets [zoom tileset]
|
|
|
|
|
(-> tileset
|
|
|
|
|
(assoc :target-width (* zoom (:tilewidth tileset)))
|
|
|
|
|
(assoc :target-height (* zoom (:tileheight tileset)))
|
|
|
|
|
(assoc :tiles-x (:columns tileset))
|
|
|
|
|
(assoc :tiles-y (/ (:tilecount tileset)
|
|
|
|
|
(:columns tileset)))))
|
|
|
|
|
|
|
|
|
|
(defn map-layers [map-def]
|
|
|
|
|
(let [ftileset (first (:tilesets map-def))]
|
|
|
|
|
(update map-def :layers
|
|
|
|
|
#(map (partial layer->dest ftileset)
|
|
|
|
|
%))))
|
|
|
|
|
|
|
|
|
|
(defn prepare-map-def [zoom map-def]
|
|
|
|
|
(-> map-def
|
|
|
|
|
(update :tilesets #(map (partial map-tilesets zoom) %))
|
|
|
|
|
map-layers))
|
|
|
|
|
|
|
|
|
|
(defn draw-viewport [map-def ctx viewport]
|
|
|
|
|
(let [def (:def map-def)
|
|
|
|
|
image (:image viewport)
|
|
|
|
|
tileset (:tileset-def viewport)]
|
|
|
|
|
(doseq [layer (:layers def)]
|
|
|
|
|
(doseq [dest layer
|
|
|
|
|
(doseq [layers (:layers def)]
|
|
|
|
|
(doseq [dest layers
|
|
|
|
|
:let [dx (- (:x dest) (:x viewport))
|
|
|
|
|
dy (- (:y dest) (:y viewport))]]
|
|
|
|
|
(draw-tile ctx tileset image
|
|
|
|
|