diff --git a/app.lua b/app.lua index 26e71d3..fa56f0b 100644 --- a/app.lua +++ b/app.lua @@ -16,33 +16,32 @@ app:post("/clickme", function(self) self.text = "Map is already initialized. Beginning game." self.isPopulated = mapFunc:mapExists(map) if not self.isPopulated then - mapFunc:populate(map) - self.text = "Populated map." - end - return {self.text, layout = false} + mapFunc:populate(map) + self.text = "Populated map." + end + return { self.text, layout = false } end) app:get("/", function(self) - self.text = say.hello() - self.isPopulated = mapFunc:mapExists(map) - return {render = "index", + self.text = say.hello() + self.isPopulated = mapFunc:mapExists(map) + return { render = "index", - } + } end) app:match("/map/render", function(self) - self.tiles = {} - for h=1,10 do - self.tiles[h] = {} - for i=1,10 do - self.tiles[h][i] = map:find({x = h, y = i}) - -- The map database has floor_stone and wall_floor instead of simple ASCII characters - -- So we run mapFunc:mapDecrypt to convert it back to the desired characters for visual display - self.tiles[h][i].occupied_by_type = mapFunc:mapDecrypt(self.tiles[h][i].occupied_by_type)[1] - end - end - return {render = "map", layout = false} + self.tiles = {} + for h = 1, 10 do + self.tiles[h] = {} + for i = 1, 10 do + -- The map database has floor_stone and wall_floor instead of simple ASCII characters + -- So we run mapFunc:mapDecrypt to convert it back to the desired characters for visual display + local tile = map:find({ x = h, y = i }) + self.tiles[h][i] = mapFunc:mapDecrypt(tile.occupied_by_type) + end + end + return { render = "map", layout = false } end) return app - diff --git a/lua_scripts/map.lua b/lua_scripts/map.lua index ad2e657..68bb064 100644 --- a/lua_scripts/map.lua +++ b/lua_scripts/map.lua @@ -1,15 +1,15 @@ local map = { map_tiles = { - {"-", "-", "w", "w", "-", "-", "-", "-", "-", "-"}, - {"-", "-", "w", "w", "-", "-", "-", "-", "-", "-"}, - {"-", "-", "w", "w", "-", "w", "-", "-", "-", "-"}, - {"w", "-", "-", "-", "w", "w", "-", "-", "-", "-"}, - {"w", "-", "w", "-", "-", "w", "w", "w", "-", "-"}, - {"w", "-", "w", "-", "-", "w", "-", "-", "-", "-"}, - {"-", "-", "w", "-", "-", "w", "-", "w", "-", "-"}, - {"-", "-", "-", "-", "-", "-", "-", "w", "-", "-"}, - {"-", "-", "w", "-", "-", "-", "-", "w", "w", "-"}, - {"-", "-", "w", "-", "-", "-", "-", "-", "w", "-"} + { "-", "-", "w", "w", "-", "-", "-", "-", "-", "-" }, + { "-", "-", "w", "w", "-", "-", "-", "-", "-", "-" }, + { "-", "-", "w", "w", "-", "w", "-", "-", "-", "-" }, + { "w", "-", "-", "-", "w", "w", "-", "-", "-", "-" }, + { "w", "-", "w", "-", "-", "w", "w", "w", "-", "-" }, + { "w", "-", "w", "-", "-", "w", "-", "-", "-", "-" }, + { "-", "-", "w", "-", "-", "w", "-", "w", "-", "-" }, + { "-", "-", "-", "-", "-", "-", "-", "w", "-", "-" }, + { "-", "-", "w", "-", "-", "-", "-", "w", "w", "-" }, + { "-", "-", "w", "-", "-", "-", "-", "-", "w", "-" } }, mapCrypt = function(self, tile) if tile == "-" then @@ -21,61 +21,46 @@ local map = { mapDecrypt = function(self, tile) -- TODO: Rework function so it returns both char and mat type -- This introduces breaking changes - local tileset = {} - if string.find(tile, "wall") then - tileset[1] = "w" - elseif string.find(tile, "floor") then - tileset[1] = "-" - end - if string.find(tile, "stone") then - tileset[2] = "stone" - elseif string.find(tile, "wood") then - tileset[2] = "wood" - end - return tileset - - -- if tile == "floor_stone" then - -- return "-" - -- elseif tile == "wall_stone" then + local tileset = {} + if string.find(tile, "wall") then + tileset.char = "w" + elseif string.find(tile, "floor") then + tileset.char = "-" + end + if string.find(tile, "stone") then + tileset.material = "stone" + elseif string.find(tile, "wood") then + tileset.material = "wood" + end + return tileset + + -- if tile == "floor_stone" then + -- return "-" + -- elseif tile == "wall_stone" then -- return "w" - -- end + -- end end, -- Map Populate / check if map exists - populate = function(self, map) - for h=1,10 do - for i=1,10 do - local tile = map:create({ - x = h, - y = i, - occupied_by_type = self:mapCrypt(self.map_tiles[h][i]), - occupied_by_id = "" - }) - end - end - end, - mapExists = function(self, map) - local f = map:select("limit 1") - if not f[1] then - return false - else - return true - end - end, + populate = function(self, map) + for h = 1, 10 do + for i = 1, 10 do + local tile = map:create({ + x = h, + y = i, + occupied_by_type = self:mapCrypt(self.map_tiles[h][i]), + occupied_by_id = "" + }) + end + end + end, + mapExists = function(self, map) + local f = map:select("limit 1") + if not f[1] then + return false + else + return true + end + end, } -local tiles = {} return map - - - - - - - - - - - - - - diff --git a/views/map.etlua b/views/map.etlua index 7852fac..c85495c 100644 --- a/views/map.etlua +++ b/views/map.etlua @@ -2,7 +2,7 @@ <% for h=1,10 do %>
<% for i=1,10 do %> -
<%= tiles[h][i].occupied_by_type %>
+
<%= tiles[h][i].char %>
<% end %>