forked from Jonathan/Peradventure
Worked on Homepage game creation UI
This commit is contained in:
parent
b72b8942c6
commit
523e33363c
31
app.lua
31
app.lua
@ -8,6 +8,7 @@ local db = require("lapis.db")
|
||||
local Model = require("lapis.db.model").Model
|
||||
|
||||
local map = Model:extend('map')
|
||||
local games = Model:extend('games')
|
||||
|
||||
app:enable("etlua")
|
||||
app.layout = require "views.layout"
|
||||
@ -38,6 +39,17 @@ app:get("/game", function(self)
|
||||
}
|
||||
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)
|
||||
self.tiles = {}
|
||||
for h = 1, 10 do
|
||||
@ -53,3 +65,22 @@ app:match("/map/render", function(self)
|
||||
end)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@ config("development", {
|
||||
server = "nginx",
|
||||
code_cache = "off",
|
||||
num_workers = "1",
|
||||
secret = "M2KisAmerican",
|
||||
sqlite = {
|
||||
database = "database.sqlite3",
|
||||
-- open_flags = ...
|
||||
|
BIN
database.sqlite3
BIN
database.sqlite3
Binary file not shown.
@ -16,22 +16,15 @@ local map = {
|
||||
db = { "floor_stone,", "floor_wood", "wall_stone", "wall_wood" }
|
||||
},
|
||||
mapCrypt = function(self, tile)
|
||||
-- stores tiles as detailed names within the DB
|
||||
for i=1, #self.tileset.display do
|
||||
if self.tileset.display[i] == tile then
|
||||
return self.tileset.db[i]
|
||||
end
|
||||
end
|
||||
--if tile == "-" then
|
||||
-- return "floor_stone"
|
||||
--elseif tile == "_" then
|
||||
-- return "floor_wood"
|
||||
--elseif tile == "w" then
|
||||
-- return "wall_stone"
|
||||
--end
|
||||
end,
|
||||
mapDecrypt = function(self, tile)
|
||||
-- TODO: Rework function so it returns both char and mat type
|
||||
-- This introduces breaking changes
|
||||
-- Decodes tiles into their type (represented by char) and their material
|
||||
local tileset = {}
|
||||
if string.find(tile, "wall") then
|
||||
tileset.char = "w"
|
||||
@ -44,12 +37,6 @@ local map = {
|
||||
tileset.material = "wood"
|
||||
end
|
||||
return tileset
|
||||
|
||||
-- if tile == "floor_stone" then
|
||||
-- return "-"
|
||||
-- elseif tile == "wall_stone" then
|
||||
-- return "w"
|
||||
-- end
|
||||
end,
|
||||
-- Map Populate / check if map exists
|
||||
populate = function(self, map, game)
|
||||
|
2
setup_db
2
setup_db
@ -25,7 +25,7 @@ sqlite3 database.sqlite3 "
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS games (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
player_id INTEGER
|
||||
player_id TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS players (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
@ -5,3 +5,7 @@
|
||||
.stone {
|
||||
color: gray;
|
||||
}
|
||||
|
||||
h1 {
|
||||
--pico-font-family: Pacifico, cursive;
|
||||
}
|
||||
|
@ -5,7 +5,11 @@
|
||||
<button hx-post="/clickme" hx-target="#clickable">Start</button>
|
||||
</div>
|
||||
<% end %>
|
||||
<article>
|
||||
<article class="container-fluid">
|
||||
<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>
|
||||
<div>
|
||||
<% render("views.player_ui") %>
|
||||
</div>
|
||||
</article>
|
||||
|
@ -1,4 +1,5 @@
|
||||
<!-- views/index.etlua -->
|
||||
<!DOCTYPE HTML>
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<% if not isPopulated then %>
|
||||
<div id="clickable">
|
||||
@ -6,15 +7,21 @@
|
||||
</div>
|
||||
<% 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>
|
||||
|
||||
<!--
|
||||
<ol>
|
||||
<p><% for i, thing in pairs(text) do %>
|
||||
<li><%= thing %></li>
|
||||
<% end %>
|
||||
</p>
|
||||
</ol>
|
||||
-->
|
||||
<!-- TODO: On player create use Model to make new game_ref and append game_ref to self_session -->
|
||||
|
@ -5,6 +5,7 @@
|
||||
<title><%= page_title or "My Page" %></title>
|
||||
<link rel="stylesheet" href="/static/css/pico/pico.min.css" />
|
||||
<link rel="stylesheet" href="/static/incertitude.css" />
|
||||
<link rel="stylesheet" href="/static/css/pico.colors.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
3
views/player_ui.etlua
Normal file
3
views/player_ui.etlua
Normal file
@ -0,0 +1,3 @@
|
||||
<!DOCTYPE HTML>
|
||||
|
||||
<p>Look at me!</p>
|
Loading…
Reference in New Issue
Block a user