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