Improve tilesets and pass them into map renderer instead of modified map rows. #17

Merged
Jonathan merged 1 commits from Noah/Peradventure:master into master 2024-03-19 12:39:34 -05:00
3 changed files with 67 additions and 83 deletions

39
app.lua
View File

@ -16,33 +16,32 @@ 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
self.tiles[h][i] = map:find({x = h, y = i}) -- The map database has floor_stone and wall_floor instead of simple ASCII characters
-- 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
-- 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].occupied_by_type = mapFunc:mapDecrypt(self.tiles[h][i].occupied_by_type)[1] self.tiles[h][i] = mapFunc:mapDecrypt(tile.occupied_by_type)
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,61 +21,46 @@ 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[1] = "w" tileset.char = "w"
elseif string.find(tile, "floor") then elseif string.find(tile, "floor") then
tileset[1] = "-" tileset.char = "-"
end end
if string.find(tile, "stone") then if string.find(tile, "stone") then
tileset[2] = "stone" tileset.material = "stone"
elseif string.find(tile, "wood") then elseif string.find(tile, "wood") then
tileset[2] = "wood" tileset.material = "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].occupied_by_type %></div> <div><%= tiles[h][i].char %></div>
<% end %> <% end %>
<br> <br>
</div> </div>