Worked on Homepage game creation UI

This commit is contained in:
Jonathan 2024-03-21 15:16:19 -05:00
parent b72b8942c6
commit 523e33363c
10 changed files with 65 additions and 27 deletions

31
app.lua
View File

@ -8,6 +8,7 @@ local db = require("lapis.db")
local Model = require("lapis.db.model").Model local Model = require("lapis.db.model").Model
local map = Model:extend('map') local map = Model:extend('map')
local games = Model:extend('games')
app:enable("etlua") app:enable("etlua")
app.layout = require "views.layout" app.layout = require "views.layout"
@ -38,6 +39,17 @@ app:get("/game", function(self)
} }
end) end)
app:post("/character-create", function(self)
self.text = "Created new player"
self.game = games:create({
player_id = self.params.playername
})
self.session.gameref = self.game
return {
self.text, layout = false
}
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
@ -53,3 +65,22 @@ app:match("/map/render", function(self)
end) end)
return app return app

View File

@ -4,6 +4,7 @@ config("development", {
server = "nginx", server = "nginx",
code_cache = "off", code_cache = "off",
num_workers = "1", num_workers = "1",
secret = "M2KisAmerican",
sqlite = { sqlite = {
database = "database.sqlite3", database = "database.sqlite3",
-- open_flags = ... -- open_flags = ...

Binary file not shown.

View File

@ -16,22 +16,15 @@ local map = {
db = { "floor_stone,", "floor_wood", "wall_stone", "wall_wood" } db = { "floor_stone,", "floor_wood", "wall_stone", "wall_wood" }
}, },
mapCrypt = function(self, tile) mapCrypt = function(self, tile)
-- stores tiles as detailed names within the DB
for i=1, #self.tileset.display do for i=1, #self.tileset.display do
if self.tileset.display[i] == tile then if self.tileset.display[i] == tile then
return self.tileset.db[i] return self.tileset.db[i]
end end
end end
--if tile == "-" then
-- return "floor_stone"
--elseif tile == "_" then
-- return "floor_wood"
--elseif tile == "w" then
-- return "wall_stone"
--end
end, end,
mapDecrypt = function(self, tile) mapDecrypt = function(self, tile)
-- TODO: Rework function so it returns both char and mat type -- Decodes tiles into their type (represented by char) and their material
-- This introduces breaking changes
local tileset = {} local tileset = {}
if string.find(tile, "wall") then if string.find(tile, "wall") then
tileset.char = "w" tileset.char = "w"
@ -44,12 +37,6 @@ local map = {
tileset.material = "wood" tileset.material = "wood"
end end
return tileset return tileset
-- if tile == "floor_stone" then
-- return "-"
-- elseif tile == "wall_stone" then
-- return "w"
-- end
end, end,
-- Map Populate / check if map exists -- Map Populate / check if map exists
populate = function(self, map, game) populate = function(self, map, game)

View File

@ -25,7 +25,7 @@ sqlite3 database.sqlite3 "
); );
CREATE TABLE IF NOT EXISTS games ( CREATE TABLE IF NOT EXISTS games (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
player_id INTEGER player_id TEXT
); );
CREATE TABLE IF NOT EXISTS players ( CREATE TABLE IF NOT EXISTS players (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,

View File

@ -5,3 +5,7 @@
.stone { .stone {
color: gray; color: gray;
} }
h1 {
--pico-font-family: Pacifico, cursive;
}

View File

@ -5,7 +5,11 @@
<button hx-post="/clickme" hx-target="#clickable">Start</button> <button hx-post="/clickme" hx-target="#clickable">Start</button>
</div> </div>
<% end %> <% end %>
<article> <article class="container-fluid">
<p style="text-align: center;">Game</p> <p style="text-align: center;">Game</p>
<main style="width: 50%;" class="container" id="map" hx-get="/map/render" hx-trigger="every 1s,load"> <main style="width: 50%;" class="container" id="map" hx-get="/map/render" hx-trigger="every 1s,load">
</main>
<div>
<% render("views.player_ui") %>
</div>
</article> </article>

View File

@ -1,4 +1,5 @@
<!-- views/index.etlua --> <!-- views/index.etlua -->
<!DOCTYPE HTML>
<script src="/static/htmx.min.js"></script> <script src="/static/htmx.min.js"></script>
<% if not isPopulated then %> <% if not isPopulated then %>
<div id="clickable"> <div id="clickable">
@ -6,15 +7,21 @@
</div> </div>
<% end %> <% end %>
<a href="/game">Play Now</a> <article style="text-align: center;">
<h3>Log In / Create Game</h3>
<p>Player will be created if player name does not already exist.</p>
<form>
<div class="grid">
<input type="text" name="playername">
<input type="submit" hx-post="/character-create" hx-trigger="click" value="Execute" hx-target="#replace">
</div>
</form>
<div>
<p id="replace"></p>
</div>
</article>
<a href="/game">Play Now</a>
</main> </main>
<!-- <!-- TODO: On player create use Model to make new game_ref and append game_ref to self_session -->
<ol>
<p><% for i, thing in pairs(text) do %>
<li><%= thing %></li>
<% end %>
</p>
</ol>
-->

View File

@ -5,6 +5,7 @@
<title><%= page_title or "My Page" %></title> <title><%= page_title or "My Page" %></title>
<link rel="stylesheet" href="/static/css/pico/pico.min.css" /> <link rel="stylesheet" href="/static/css/pico/pico.min.css" />
<link rel="stylesheet" href="/static/incertitude.css" /> <link rel="stylesheet" href="/static/incertitude.css" />
<link rel="stylesheet" href="/static/css/pico.colors.css" />
</head> </head>
<body> <body>

3
views/player_ui.etlua Normal file
View File

@ -0,0 +1,3 @@
<!DOCTYPE HTML>
<p>Look at me!</p>