added real-time map render!

This commit is contained in:
Jonathan 2024-03-18 15:31:53 -05:00
parent 0d9e48752d
commit 684ebb61a8
9 changed files with 79 additions and 6 deletions

15
app.lua
View File

@ -1,18 +1,20 @@
local lapis = require("lapis")
local app = lapis.Application()
local say = require('lua_scripts/main')
local mapFunc = require('lua_scripts/map')
local player = require('player')
local db = require("lapis.db")
local Model = require("lapis.db.model").Model
local db = Model:extend('database')
local map = Model:extend('map')
app:enable("etlua")
app.layout = require "views.layout"
app:post("/clickme", function(self)
self.plane = "P-38L"
mapFunc:populate(map)
return {self.plane, layout = false}
end)
@ -23,6 +25,17 @@ app:get("/", function(self)
}
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})
end
end
return {render = "map", layout = false}
end)
return app

View File

@ -5,7 +5,7 @@ config("development", {
code_cache = "off",
num_workers = "1",
sqlite = {
database = "my_database.sqlite",
database = "database.sqlite3",
-- open_flags = ...
}
})

Binary file not shown.

44
lua_scripts/map.lua Normal file
View File

@ -0,0 +1,44 @@
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", "-"}
},
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.map_tiles[h][i],
occupied_by_id = ""
})
end
end
end
}
local tiles = {}
return map

View File

@ -12,6 +12,8 @@ http {
init_by_lua_block {
require "lpeg"
require "lsqlite3"
lapis = require "lapis"
}
server {

View File

@ -13,6 +13,8 @@ http {
init_by_lua_block {
require "lpeg"
require "lsqlite3"
lapis = require "lapis"
}
server {

View File

@ -15,7 +15,7 @@ sqlite3 database.sqlite3 "
hp INTEGER,
inventory_ref INTEGER
);
CREATE TABLE IF NOT EXISTS player_inventory (
CREATE TABLE IF NOT EXISTS player_inventory (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type TEXT,
quantity INTEGER,

View File

@ -1,11 +1,15 @@
<!-- views/index.etlua -->
<script src="/static/htmx.min.js"></script>
<div id="clickable">
<button hx-post="/clickme" hx-target="#clickable">Start</button>
</div>
<button hx-post="/clickme" hx-target="#clickable">Start</button>
<p id="clickable"></p>
<div id="map" hx-get="/map/render" hx-trigger="every 5s">
</div>
<ol>
<!--
<ol>
<p><% for i, thing in pairs(text) do %>
<li><%= thing %></li>
<% end %>

8
views/map.etlua Normal file
View File

@ -0,0 +1,8 @@
<p style="text-align: center;">
<% for h=1,10 do %>
<% for i=1,10 do %>
<%= tiles[h][i].occupied_by_type %>
<% end %>
<br>
<% end %>
</p>