Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

10 changed files with 52 additions and 211 deletions

121
app.lua
View File

@ -1,5 +1,4 @@
local lapis = require("lapis") local lapis = require("lapis")
local util = require("lapis.util")
local app = lapis.Application() local app = lapis.Application()
local say = require('lua_scripts/main') local say = require('lua_scripts/main')
local mapFunc = require('lua_scripts/map') local mapFunc = require('lua_scripts/map')
@ -9,16 +8,15 @@ 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"
app:post("/clickme", function(self) app:post("/clickme", function(self)
self.text = "Map is already initialized. Beginning game." 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 if not self.isPopulated then
mapFunc:populate(map, self.session.gameref) mapFunc:populate(map)
self.text = "Populated map." self.text = "Populated map."
end end
return { self.text, layout = false } return { self.text, layout = false }
@ -26,135 +24,24 @@ end)
app:get("/", function(self) app:get("/", function(self)
self.text = say.hello() self.text = say.hello()
self.isPopulated = mapFunc:mapExists(map, self.session.gameref) self.isPopulated = mapFunc:mapExists(map)
return { render = "index", return { render = "index",
} }
end) 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) app:match("/map/render", function(self)
if mapFunc:mapExists(map, self.session.gameref) then
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
-- 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
local tile = map:find({ x = h, y = i, game_ref = self.session.gameref }) local tile = map:find({ x = h, y = i })
self.tiles[h][i] = mapFunc:mapDecrypt(tile.occupied_by_type) 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
return { layout = false }
end) end)
return app return app

View File

@ -4,7 +4,6 @@ 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

@ -4,27 +4,25 @@ local map = {
{ "-", "_", "w", "w", "-", "-", "-", "-", "-", "-" }, { "-", "_", "w", "w", "-", "-", "-", "-", "-", "-" },
{ "-", "-", "w", "w", "-", "w", "-", "-", "-", "-" }, { "-", "-", "w", "w", "-", "w", "-", "-", "-", "-" },
{ "w", "-", "-", "-", "w", "w", "-", "-", "-", "-" }, { "w", "-", "-", "-", "w", "w", "-", "-", "-", "-" },
{ "w", "-", "ww", "-", "-", "w", "w", "w", "-", "-" }, { "w", "-", "w", "-", "-", "w", "w", "w", "-", "-" },
{ "w", "-", "ww", "-", "-", "w", "-", "-", "-", "-" }, { "w", "-", "w", "-", "-", "w", "-", "-", "-", "-" },
{ "-", "-", "ww", "-", "-", "w", "-", "w", "-", "-" }, { "-", "-", "w", "-", "-", "w", "-", "w", "-", "-" },
{ "-", "-", "-", "-", "-", "-", "-", "w", "-", "-" }, { "-", "-", "-", "-", "-", "-", "-", "w", "-", "-" },
{ "-", "-", "ww", "-", "-", "-", "-", "w", "w", "-" }, { "-", "-", "w", "-", "-", "-", "-", "w", "w", "-" },
{ "-", "-", "ww", "-", "-", "-", "-", "-", "w", "-" } { "-", "-", "w", "-", "-", "-", "-", "-", "w", "-" }
},
tileset = {
display = { "-", "_", "w", "ww" },
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 if tile == "-" then
for i=1, #self.tileset.display do return "floor_stone"
if self.tileset.display[i] == tile then elseif tile == "_" then
return self.tileset.db[i] return "floor_wood"
end elseif tile == "w" then
return "wall_stone"
end end
end, end,
mapDecrypt = function(self, tile) 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 = {} local tileset = {}
if string.find(tile, "wall") then if string.find(tile, "wall") then
tileset.char = "w" tileset.char = "w"
@ -37,24 +35,29 @@ 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)
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,
occupied_by_type = self:mapCrypt(self.map_tiles[h][i]), occupied_by_type = self:mapCrypt(self.map_tiles[h][i]),
occupied_by_id = "", occupied_by_id = ""
game_ref = game
}) })
end end
end end
end, end,
mapExists = function(self, map, game) mapExists = function(self, map)
local f = map:find({game_ref = game}) local f = map:select("limit 1")
if not f then if not f[1] then
return false return false
else else
return true return true

View File

@ -6,33 +6,19 @@ sqlite3 database.sqlite3 "
x TEXT, x TEXT,
y TEXT, y TEXT,
occupied_by_type TEXT, occupied_by_type TEXT,
occupied_by_id INTEGER, occupied_by_id INTEGER
game_ref INTEGER
); );
CREATE TABLE IF NOT EXISTS entity_ref ( CREATE TABLE IF NOT EXISTS entity_ref (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
entity_id INTEGER, entity_id INTEGER,
type TEXT, type TEXT,
hp INTEGER, hp INTEGER,
inventory_ref INTEGER, inventory_ref INTEGER
game_ref INTEGER
); );
CREATE TABLE IF NOT EXISTS player_inventory ( CREATE TABLE IF NOT EXISTS player_inventory (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
type TEXT, type TEXT,
quantity INTEGER, quantity INTEGER,
game_ref INTEGER func_ref TEXT
);
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
) )
" "

View File

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

View File

@ -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>

View File

@ -1,5 +1,4 @@
<!-- 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">
@ -7,21 +6,18 @@
</div> </div>
<% end %> <% end %>
<article style="text-align: center;"> <article>
<h3>Log In / Create Game</h3> <p style="text-align: center;">Game</p>
<p>Player will be created if player name does not already exist. Names may not contain whitespace.</p> <main style="width: 50%;" class="container" id="map" hx-get="/map/render" hx-trigger="every 1s,load">
<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> </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,7 +5,6 @@
<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>

View File

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