Compare commits

..

No commits in common. "d7bc833df70ca8014b9f2aafb9c78109858fc0cd" and "dab56a3f8c1762da2377ad2b4e9a7747157e28a5" have entirely different histories.

3 changed files with 83 additions and 67 deletions

39
app.lua
View File

@ -16,32 +16,33 @@ app:post("/clickme", function(self)
self.text = "Map is already initialized. Beginning game." self.text = "Map is already initialized. Beginning game."
self.isPopulated = mapFunc:mapExists(map) self.isPopulated = mapFunc:mapExists(map)
if not self.isPopulated then if not self.isPopulated then
mapFunc:populate(map) mapFunc:populate(map)
self.text = "Populated map." self.text = "Populated map."
end end
return { self.text, layout = false } return {self.text, layout = false}
end) end)
app:get("/", function(self) app:get("/", function(self)
self.text = say.hello() self.text = say.hello()
self.isPopulated = mapFunc:mapExists(map) self.isPopulated = mapFunc:mapExists(map)
return { render = "index", return {render = "index",
} }
end) end)
app:match("/map/render", function(self) app:match("/map/render", function(self)
self.tiles = {} self.tiles = {}
for h = 1, 10 do for h=1,10 do
self.tiles[h] = {} self.tiles[h] = {}
for i = 1, 10 do for i=1,10 do
-- The map database has floor_stone and wall_floor instead of simple ASCII characters self.tiles[h][i] = map:find({x = h, y = i})
-- So we run mapFunc:mapDecrypt to convert it back to the desired characters for visual display -- The map database has floor_stone and wall_floor instead of simple ASCII characters
local tile = map:find({ x = h, y = i }) -- So we run mapFunc:mapDecrypt to convert it back to the desired characters for visual display
self.tiles[h][i] = mapFunc:mapDecrypt(tile.occupied_by_type) self.tiles[h][i].occupied_by_type = mapFunc:mapDecrypt(self.tiles[h][i].occupied_by_type)[1]
end end
end end
return { render = "map", layout = false } return {render = "map", layout = false}
end) end)
return app return app

View File

@ -1,15 +1,15 @@
local map = { local map = {
map_tiles = { 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) mapCrypt = function(self, tile)
if tile == "-" then if tile == "-" then
@ -21,46 +21,61 @@ local map = {
mapDecrypt = function(self, tile) mapDecrypt = function(self, tile)
-- TODO: Rework function so it returns both char and mat type -- TODO: Rework function so it returns both char and mat type
-- This introduces breaking changes -- This introduces breaking changes
local tileset = {} local tileset = {}
if string.find(tile, "wall") then if string.find(tile, "wall") then
tileset.char = "w" tileset[1] = "w"
elseif string.find(tile, "floor") then elseif string.find(tile, "floor") then
tileset.char = "-" tileset[1] = "-"
end end
if string.find(tile, "stone") then if string.find(tile, "stone") then
tileset.material = "stone" tileset[2] = "stone"
elseif string.find(tile, "wood") then elseif string.find(tile, "wood") then
tileset.material = "wood" tileset[2] = "wood"
end end
return tileset return tileset
-- if tile == "floor_stone" then -- if tile == "floor_stone" then
-- return "-" -- return "-"
-- elseif tile == "wall_stone" then -- elseif tile == "wall_stone" then
-- return "w" -- return "w"
-- end -- end
end, end,
-- Map Populate / check if map exists -- Map Populate / check if map exists
populate = function(self, map) populate = function(self, map)
for h = 1, 10 do for h=1,10 do
for i = 1, 10 do for i=1,10 do
local tile = map:create({ local tile = map:create({
x = h, x = h,
y = i, y = i,
occupied_by_type = self:mapCrypt(self.map_tiles[h][i]), occupied_by_type = self:mapCrypt(self.map_tiles[h][i]),
occupied_by_id = "" occupied_by_id = ""
}) })
end end
end end
end, end,
mapExists = function(self, map) mapExists = function(self, map)
local f = map:select("limit 1") local f = map:select("limit 1")
if not f[1] then if not f[1] then
return false return false
else else
return true return true
end end
end, end,
} }
local tiles = {}
return map return map

View File

@ -2,7 +2,7 @@
<% for h=1,10 do %> <% for h=1,10 do %>
<div class="grid"> <div class="grid">
<% for i=1,10 do %> <% for i=1,10 do %>
<div><%= tiles[h][i].char %></div> <div><%= tiles[h][i].occupied_by_type %></div>
<% end %> <% end %>
<br> <br>
</div> </div>