forked from Jonathan/Peradventure
Session tokens control player options for create / login
This commit is contained in:
parent
514d4ebf40
commit
e0e6c30752
55
app.lua
55
app.lua
@ -1,4 +1,5 @@
|
|||||||
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')
|
||||||
@ -15,9 +16,9 @@ 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.isPopulated = mapFunc:mapExists(map, self.session.gameref)
|
||||||
if not self.isPopulated then
|
if not self.isPopulated then
|
||||||
mapFunc:populate(map)
|
mapFunc:populate(map, self.session.gameref)
|
||||||
self.text = "Populated map."
|
self.text = "Populated map."
|
||||||
end
|
end
|
||||||
return { self.text, layout = false }
|
return { self.text, layout = false }
|
||||||
@ -25,7 +26,7 @@ end)
|
|||||||
|
|
||||||
app:get("/", function(self)
|
app:get("/", function(self)
|
||||||
self.text = say.hello()
|
self.text = say.hello()
|
||||||
self.isPopulated = mapFunc:mapExists(map)
|
self.isPopulated = mapFunc:mapExists(map, self.session.gameref)
|
||||||
return { render = "index",
|
return { render = "index",
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -33,13 +34,14 @@ end)
|
|||||||
|
|
||||||
app:get("/game", function(self)
|
app:get("/game", function(self)
|
||||||
self.text = say.hello()
|
self.text = say.hello()
|
||||||
self.isPopulated = mapFunc:mapExists(map)
|
self.isPopulated = mapFunc:mapExists(map, self.session.gameref)
|
||||||
return { render = "game",
|
return { render = "game",
|
||||||
|
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
app:post("/character-create", function(self)
|
app:post("/character-create", function(self)
|
||||||
|
self.params.playername = util.trim(self.params.playername)
|
||||||
if self.params.playername == "" then
|
if self.params.playername == "" then
|
||||||
self.text = "Player name must not be nil. Try again."
|
self.text = "Player name must not be nil. Try again."
|
||||||
return {
|
return {
|
||||||
@ -48,9 +50,12 @@ app:post("/character-create", function(self)
|
|||||||
end
|
end
|
||||||
local player_exists = games:find({player_id = self.params.playername})
|
local player_exists = games:find({player_id = self.params.playername})
|
||||||
if player_exists then
|
if player_exists then
|
||||||
self.text = "Player name already exists. Try again."
|
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 {
|
return {
|
||||||
self.text, layout = false
|
self.text, self.link, layout = false
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
if not player_exists then
|
if not player_exists then
|
||||||
@ -67,18 +72,20 @@ app:post("/character-create", function(self)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
app:match("/map/render", function(self)
|
app:match("/map/render", function(self)
|
||||||
self.tiles = {}
|
if mapFunc:mapExists(map, self.session.gameref) then
|
||||||
for h = 1, 10 do
|
self.tiles = {}
|
||||||
self.tiles[h] = {}
|
for h = 1, 10 do
|
||||||
for i = 1, 10 do
|
self.tiles[h] = {}
|
||||||
-- The map database has floor_stone and wall_floor instead of simple ASCII characters
|
for i = 1, 10 do
|
||||||
-- So we run mapFunc:mapDecrypt to convert it back to the desired characters for visual display
|
-- The map database has floor_stone and wall_floor instead of simple ASCII characters
|
||||||
local tile = map:find({ x = h, y = i })
|
-- So we run mapFunc:mapDecrypt to convert it back to the desired characters for visual display
|
||||||
self.tiles[h][i] = mapFunc:mapDecrypt(tile.occupied_by_type)
|
local tile = map:find({ x = h, y = i })
|
||||||
|
self.tiles[h][i] = mapFunc:mapDecrypt(tile.occupied_by_type)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return { render = "map", layout = false }
|
||||||
end
|
end
|
||||||
return { render = "map", layout = false }
|
end)
|
||||||
end)
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
@ -112,6 +119,22 @@ return app
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BIN
database.sqlite3
BIN
database.sqlite3
Binary file not shown.
@ -52,9 +52,9 @@ local map = {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
mapExists = function(self, map)
|
mapExists = function(self, map, game)
|
||||||
local f = map:select("limit 1")
|
local f = map:find({game_ref = game})
|
||||||
if not f[1] then
|
if not f then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<article class="container-fluid">
|
<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 10s,load">
|
||||||
</main>
|
</main>
|
||||||
<div>
|
<div>
|
||||||
<% render("views.player_ui") %>
|
<% render("views.player_ui") %>
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<article style="text-align: center;">
|
<article style="text-align: center;">
|
||||||
<h3>Log In / Create Game</h3>
|
<h3>Log In / Create Game</h3>
|
||||||
<p>Player will be created if player name does not already exist.</p>
|
<p>Player will be created if player name does not already exist. Names may not contain whitespace.</p>
|
||||||
<form>
|
<form>
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<input type="text" name="playername">
|
<input type="text" name="playername">
|
||||||
|
Loading…
Reference in New Issue
Block a user