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hintergrund", "name":"Hintergrund",
"opacity":1, "opacity":1,
"type":"tilelayer", "type":"tilelayer",
"visible":false, "visible":true,
"width":20, "width":20,
"x":0, "x":0,
"y":0 "y":0
@ -26,13 +26,13 @@
"y":0 "y":0
}, },
{ {
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 486, 487, 488, 489, 490, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 526, 527, 528, 529, 530, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 566, 567, 568, 569, 570, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 776, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0],
"height":16, "height":16,
"id":7, "id":7,
"name":"Vordergrund", "name":"Vordergrund",
"opacity":1, "opacity":1,
"type":"tilelayer", "type":"tilelayer",
"visible":false, "visible":true,
"width":20, "width":20,
"x":0, "x":0,
"y":0 "y":0
@ -296,4 +296,4 @@
"type":"map", "type":"map",
"version":1.2, "version":1.2,
"width":20 "width":20
} }

@ -112,8 +112,8 @@
0,0,0,0,0,0,0,0,0,0,0,0,526,527,528,529,530,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,526,527,528,529,530,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,566,567,568,569,570,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,566,567,568,569,570,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,780,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,776,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

@ -49,31 +49,15 @@
(:keep-in viewport) (:keep-in viewport)
(collision/pps->px gamestate viewport))) (collision/pps->px gamestate viewport)))
(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-layer-tiles [map-def]
(let [ftileset (first (:tilesets map-def))]
(update map-def :layers
#(map (partial tileset/layer->dest ftileset)
%))))
(defn init-map-def [scenestate] (defn init-map-def [scenestate]
(if (and (not (get-in scenestate [:map-def :def])) (if (and (not (get-in scenestate [:map-def :def]))
(some? @map-def)) (some? @map-def))
(let [zoom (get-in scenestate [:map-def :zoom])] (let [loaded-def (walk/keywordize-keys @map-def)
(assoc-in zoom (get-in scenestate [:map-def :zoom])]
scenestate (-> scenestate
[:map-def :def] (assoc-in [:map-def :def] loaded-def)
(-> @map-def (update-in [:map-def :def]
(walk/keywordize-keys) (partial tileset/prepare-map-def zoom))))
(update :tilesets #(map (partial map-tilesets zoom) %))
map-layer-tiles)))
scenestate)) scenestate))
(defn update-scene [gamestate scenestate] (defn update-scene [gamestate scenestate]

@ -64,6 +64,25 @@
(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 [{:keys [images def]} map-def (let [{:keys [images def]} map-def
{:keys [tileheight tilewidth {:keys [tileheight tilewidth

Loading…
Cancel
Save