Merge pull request 'Improve tilesets and pass them into map renderer instead of modified map rows.' (#17) from Noah/Peradventure:master into master

Reviewed-on: Jonathan/Peradventure#17
This commit is contained in:
Jonathan 2024-03-19 12:39:33 -05:00
commit d7bc833df7
3 changed files with 67 additions and 83 deletions

15
app.lua
View File

@ -19,30 +19,29 @@ app:post("/clickme", function(self)
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
self.tiles[h][i].occupied_by_type = mapFunc:mapDecrypt(self.tiles[h][i].occupied_by_type)[1] local tile = map:find({ x = h, y = i })
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
@ -23,14 +23,14 @@ local map = {
-- 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
@ -42,8 +42,8 @@ local map = {
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,
@ -62,20 +62,5 @@ local map = {
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>