Compare commits
No commits in common. "master" and "master" have entirely different histories.
139
app.lua
139
app.lua
@ -1,5 +1,4 @@
|
||||
local lapis = require("lapis")
|
||||
local util = require("lapis.util")
|
||||
local app = lapis.Application()
|
||||
local say = require('lua_scripts/main')
|
||||
local mapFunc = require('lua_scripts/map')
|
||||
@ -9,16 +8,15 @@ 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"
|
||||
|
||||
app:post("/clickme", function(self)
|
||||
self.text = "Map is already initialized. Beginning game."
|
||||
self.isPopulated = mapFunc:mapExists(map, self.session.gameref)
|
||||
self.isPopulated = mapFunc:mapExists(map)
|
||||
if not self.isPopulated then
|
||||
mapFunc:populate(map, self.session.gameref)
|
||||
mapFunc:populate(map)
|
||||
self.text = "Populated map."
|
||||
end
|
||||
return { self.text, layout = false }
|
||||
@ -26,135 +24,24 @@ end)
|
||||
|
||||
app:get("/", function(self)
|
||||
self.text = say.hello()
|
||||
self.isPopulated = mapFunc:mapExists(map, self.session.gameref)
|
||||
self.isPopulated = mapFunc:mapExists(map)
|
||||
return { render = "index",
|
||||
|
||||
}
|
||||
end)
|
||||
|
||||
app:get("/game", function(self)
|
||||
self.text = say.hello()
|
||||
self.isPopulated = mapFunc:mapExists(map, self.session.gameref)
|
||||
return { render = "game",
|
||||
|
||||
}
|
||||
end)
|
||||
|
||||
app:post("/character-create", function(self)
|
||||
self.params.playername = util.trim(self.params.playername)
|
||||
if self.params.playername == "" then
|
||||
self.text = "Player name must not be nil. Try again."
|
||||
return {
|
||||
self.text, layout = false
|
||||
}
|
||||
end
|
||||
local player_exists = games:find({player_id = self.params.playername})
|
||||
if player_exists then
|
||||
self.text = "Welcome back, " .. self.params.playername .. "."
|
||||
local game = games:find({player_id = self.params.playername})
|
||||
self.session.gameref = game.id
|
||||
self.link = "<a href='/game'> Play Now</a>"
|
||||
return {
|
||||
self.text, self.link, layout = false
|
||||
}
|
||||
end
|
||||
if not player_exists then
|
||||
self.text = "Created new player."
|
||||
self.game = games:create({
|
||||
player_id = self.params.playername
|
||||
})
|
||||
self.session.gameref = self.game.id
|
||||
self.link = "<a href='/game'> Play Now</a>"
|
||||
return {
|
||||
self.text, self.link, layout = false
|
||||
}
|
||||
end
|
||||
end)
|
||||
|
||||
app:match("/map/render", function(self)
|
||||
if mapFunc:mapExists(map, self.session.gameref) then
|
||||
self.tiles = {}
|
||||
for h = 1, 10 do
|
||||
self.tiles[h] = {}
|
||||
for i = 1, 10 do
|
||||
-- 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
|
||||
local tile = map:find({ x = h, y = i, game_ref = self.session.gameref })
|
||||
self.tiles[h][i] = mapFunc:mapDecrypt(tile.occupied_by_type)
|
||||
end
|
||||
self.tiles = {}
|
||||
for h = 1, 10 do
|
||||
self.tiles[h] = {}
|
||||
for i = 1, 10 do
|
||||
-- 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
|
||||
local tile = map:find({ x = h, y = i })
|
||||
self.tiles[h][i] = mapFunc:mapDecrypt(tile.occupied_by_type)
|
||||
end
|
||||
return { render = "map", layout = false }
|
||||
end
|
||||
return { layout = false }
|
||||
end)
|
||||
return { render = "map", layout = false }
|
||||
end)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -4,7 +4,6 @@ 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.
@ -4,27 +4,25 @@ local map = {
|
||||
{ "-", "_", "w", "w", "-", "-", "-", "-", "-", "-" },
|
||||
{ "-", "-", "w", "w", "-", "w", "-", "-", "-", "-" },
|
||||
{ "w", "-", "-", "-", "w", "w", "-", "-", "-", "-" },
|
||||
{ "w", "-", "ww", "-", "-", "w", "w", "w", "-", "-" },
|
||||
{ "w", "-", "ww", "-", "-", "w", "-", "-", "-", "-" },
|
||||
{ "-", "-", "ww", "-", "-", "w", "-", "w", "-", "-" },
|
||||
{ "w", "-", "w", "-", "-", "w", "w", "w", "-", "-" },
|
||||
{ "w", "-", "w", "-", "-", "w", "-", "-", "-", "-" },
|
||||
{ "-", "-", "w", "-", "-", "w", "-", "w", "-", "-" },
|
||||
{ "-", "-", "-", "-", "-", "-", "-", "w", "-", "-" },
|
||||
{ "-", "-", "ww", "-", "-", "-", "-", "w", "w", "-" },
|
||||
{ "-", "-", "ww", "-", "-", "-", "-", "-", "w", "-" }
|
||||
},
|
||||
tileset = {
|
||||
display = { "-", "_", "w", "ww" },
|
||||
db = { "floor_stone,", "floor_wood", "wall_stone", "wall_wood" }
|
||||
{ "-", "-", "w", "-", "-", "-", "-", "w", "w", "-" },
|
||||
{ "-", "-", "w", "-", "-", "-", "-", "-", "w", "-" }
|
||||
},
|
||||
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
|
||||
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)
|
||||
-- Decodes tiles into their type (represented by char) and their material
|
||||
-- TODO: Rework function so it returns both char and mat type
|
||||
-- This introduces breaking changes
|
||||
local tileset = {}
|
||||
if string.find(tile, "wall") then
|
||||
tileset.char = "w"
|
||||
@ -37,24 +35,29 @@ 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)
|
||||
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:mapCrypt(self.map_tiles[h][i]),
|
||||
occupied_by_id = "",
|
||||
game_ref = game
|
||||
occupied_by_id = ""
|
||||
})
|
||||
end
|
||||
end
|
||||
end,
|
||||
mapExists = function(self, map, game)
|
||||
local f = map:find({game_ref = game})
|
||||
if not f then
|
||||
mapExists = function(self, map)
|
||||
local f = map:select("limit 1")
|
||||
if not f[1] then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
|
20
setup_db
20
setup_db
@ -6,33 +6,19 @@ sqlite3 database.sqlite3 "
|
||||
x TEXT,
|
||||
y TEXT,
|
||||
occupied_by_type TEXT,
|
||||
occupied_by_id INTEGER,
|
||||
game_ref INTEGER
|
||||
occupied_by_id INTEGER
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS entity_ref (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
entity_id INTEGER,
|
||||
type TEXT,
|
||||
hp INTEGER,
|
||||
inventory_ref INTEGER,
|
||||
game_ref INTEGER
|
||||
inventory_ref INTEGER
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS player_inventory (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
type TEXT,
|
||||
quantity INTEGER,
|
||||
game_ref INTEGER
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS games (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
player_id TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS players (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
player_name TEXT,
|
||||
x INTEGER,
|
||||
y INTEGER,
|
||||
health INTEGER,
|
||||
game_ref INTEGER
|
||||
func_ref TEXT
|
||||
)
|
||||
"
|
||||
|
@ -5,7 +5,3 @@
|
||||
.stone {
|
||||
color: gray;
|
||||
}
|
||||
|
||||
h1 {
|
||||
--pico-font-family: Pacifico, cursive;
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<% if not isPopulated then %>
|
||||
<div id="clickable">
|
||||
<button hx-post="/clickme" hx-target="#clickable" onclick="location.reload()">Start</button>
|
||||
</div>
|
||||
<% end %>
|
||||
<article class="container-fluid">
|
||||
<div class="grid">
|
||||
<script></script>
|
||||
<% if isPopulated then %>
|
||||
<div>
|
||||
<p style="text-align: center;">Map</p>
|
||||
<main style="width: 50%;" class="container" id="map" hx-get="/map/render" hx-trigger="every 5s,load">
|
||||
</div>
|
||||
</main>
|
||||
<div>
|
||||
<% render("views.player_ui") %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</article>
|
@ -1,5 +1,4 @@
|
||||
<!-- views/index.etlua -->
|
||||
<!DOCTYPE HTML>
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<% if not isPopulated then %>
|
||||
<div id="clickable">
|
||||
@ -7,21 +6,18 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<article style="text-align: center;">
|
||||
<h3>Log In / Create Game</h3>
|
||||
<p>Player will be created if player name does not already exist. Names may not contain whitespace.</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>
|
||||
<p style="text-align: center;">Game</p>
|
||||
<main style="width: 50%;" class="container" id="map" hx-get="/map/render" hx-trigger="every 1s,load">
|
||||
</article>
|
||||
|
||||
<a href="/game">Play Now</a>
|
||||
</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>
|
||||
-->
|
||||
|
@ -5,11 +5,10 @@
|
||||
<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>
|
||||
<h1 style="text-align: center; margin-top: 3rem;" >Peradventure</h1>
|
||||
<h1 style="text-align: center; margin-top: 3rem;">Peradventure</h1>
|
||||
<% content_for("inner") %>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,3 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
|
||||
<p>Look at me!</p>
|
Loading…
Reference in New Issue
Block a user