diff --git a/resources/public/map/map.json b/resources/public/map/map.json index e1373d7..dff98f3 100644 --- a/resources/public/map/map.json +++ b/resources/public/map/map.json @@ -2,13 +2,13 @@ "infinite":false, "layers":[ { - "data":[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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"visible":true, "width":20, "x":0, "y":0 @@ -296,4 +296,4 @@ "type":"map", "version":1.2, "width":20 -} +} \ No newline at end of file diff --git a/resources/public/map/map.tmx b/resources/public/map/map.tmx index c8e603f..1a3eaf1 100644 --- a/resources/public/map/map.tmx +++ b/resources/public/map/map.tmx @@ -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,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,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,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, diff --git a/src/cljs/topdown2d/demoscene.cljs b/src/cljs/topdown2d/demoscene.cljs index c845475..0dcb498 100644 --- a/src/cljs/topdown2d/demoscene.cljs +++ b/src/cljs/topdown2d/demoscene.cljs @@ -49,31 +49,15 @@ (:keep-in 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] (if (and (not (get-in scenestate [:map-def :def])) (some? @map-def)) - (let [zoom (get-in scenestate [:map-def :zoom])] - (assoc-in - scenestate - [:map-def :def] - (-> @map-def - (walk/keywordize-keys) - (update :tilesets #(map (partial map-tilesets zoom) %)) - map-layer-tiles))) + (let [loaded-def (walk/keywordize-keys @map-def) + zoom (get-in scenestate [:map-def :zoom])] + (-> scenestate + (assoc-in [:map-def :def] loaded-def) + (update-in [:map-def :def] + (partial tileset/prepare-map-def zoom)))) scenestate)) (defn update-scene [gamestate scenestate] diff --git a/src/cljs/topdown2d/tileset.cljs b/src/cljs/topdown2d/tileset.cljs index 72c253f..70a06f7 100644 --- a/src/cljs/topdown2d/tileset.cljs +++ b/src/cljs/topdown2d/tileset.cljs @@ -64,6 +64,25 @@ (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 [{:keys [images def]} map-def {:keys [tileheight tilewidth