Compare commits
4 Commits
2683a5b4bb
...
0cdb25029f
Author | SHA1 | Date | |
---|---|---|---|
0cdb25029f | |||
a3819f9e16 | |||
056d3439e5 | |||
bceb55c4dd |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
server/database/dragon.db
|
server/database/dragon.db
|
||||||
|
server/database/dragon.db-shm
|
||||||
|
server/database/dragon.db-wal
|
||||||
server/.installed
|
server/.installed
|
|
@ -8,7 +8,7 @@ The Update has not been merged into `master` yet, but it will be. In the meantim
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- New database wrapper! Allows easy access to the database, which itself has been changed (see changed notes). Can CRUD with a simple interface.
|
- ~~New database wrapper! Allows easy access to the database, which itself has been changed (see changed notes). Can CRUD with a simple interface.~~ The wrapper has been dropped in favor of a leaner light debug-focused wrapper for PDO.
|
||||||
- New render method! Uses an output buffer and `extract()` to safely render templates and allows us to use pure PHP for templating... which we *were* doing before, but now it's even better!
|
- New render method! Uses an output buffer and `extract()` to safely render templates and allows us to use pure PHP for templating... which we *were* doing before, but now it's even better!
|
||||||
- New background image; this one is small, but the old garrish yellow background has been replaced with a smooth white/gray background. The plan is to add a theme toggle later to use the retro look on demand.
|
- New background image; this one is small, but the old garrish yellow background has been replaced with a smooth white/gray background. The plan is to add a theme toggle later to use the retro look on demand.
|
||||||
- Status points; to give the player more build agency, status points will be given per level-up. The number of points can be changed in the overall game settings.
|
- Status points; to give the player more build agency, status points will be given per level-up. The number of points can be changed in the overall game settings.
|
||||||
|
|
|
@ -8,7 +8,7 @@ body {
|
||||||
background-repeat: repeat;
|
background-repeat: repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
#container {
|
#install-container {
|
||||||
max-width: 996px;
|
max-width: 996px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
<?php // guide.php :: shows all kinds of useful information
|
|
||||||
|
|
||||||
const SERVER = '../../server';
|
|
||||||
require_once SERVER.'/bootstrap.php';
|
|
||||||
|
|
||||||
if (!installed()) redirect('/install');
|
|
||||||
|
|
||||||
$db = new Database(DB);
|
|
||||||
$control = $db->table('control')->select();
|
|
||||||
|
|
||||||
const GUIDES = ['main', 'items', 'monsters', 'spells', 'classes'];
|
|
||||||
$guide = isset($_GET['guide']) ? $_GET['guide'] : 'main';
|
|
||||||
|
|
||||||
const TITLES = [
|
|
||||||
'main' => 'Main',
|
|
||||||
'items' => 'Items & Drops',
|
|
||||||
'monsters' => 'Monsters',
|
|
||||||
'spells' => 'Spells',
|
|
||||||
'classes' => 'Classes'
|
|
||||||
];
|
|
||||||
|
|
||||||
echo render('/guide/layout', ['guide' => $guide, 'db' => $db, 'control' => $control, 'title' => TITLES[$guide]]);
|
|
|
@ -4,16 +4,16 @@
|
||||||
const SERVER = '../server';
|
const SERVER = '../server';
|
||||||
require_once SERVER.'/bootstrap.php';
|
require_once SERVER.'/bootstrap.php';
|
||||||
|
|
||||||
// check if the server has been installed
|
// spin up our app container and the initial route
|
||||||
if (!installed()) redirect('/install');
|
|
||||||
|
|
||||||
// spin up our app container
|
|
||||||
$app = new App(DB);
|
$app = new App(DB);
|
||||||
|
|
||||||
// route the request
|
|
||||||
// routing follows a simple rule; the first segment of the URI is the
|
|
||||||
// module, and the module handles the rest
|
|
||||||
$route = App::$req->uri(0);
|
$route = App::$req->uri(0);
|
||||||
$routes = [
|
|
||||||
'home' => 'HomeModule::home',
|
// redirect depending on installation status
|
||||||
];
|
installRedirect($route);
|
||||||
|
|
||||||
|
if ($route == '/') return HomeModule::home();
|
||||||
|
if ($route == 'install') return InstallModule::handle();
|
||||||
|
|
||||||
|
// 404
|
||||||
|
http_response_code(404);
|
||||||
|
echo '404: ' . $route;
|
||||||
|
|
|
@ -14,18 +14,4 @@ class App
|
||||||
self::$req = new Request(); // the current request
|
self::$req = new Request(); // the current request
|
||||||
self::$db = new Database($dbPath); // the database
|
self::$db = new Database($dbPath); // the database
|
||||||
}
|
}
|
||||||
|
|
||||||
public function route(string $uri, array $routes)
|
|
||||||
{
|
|
||||||
// check if the module exists
|
|
||||||
if (isset($routes[$module])) {
|
|
||||||
// if the module exists, call the module's handle method
|
|
||||||
$routes[$module]($this);
|
|
||||||
} else {
|
|
||||||
// if the module does not exist, render a 404 page
|
|
||||||
$this->render('404', [
|
|
||||||
'title' => '404',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,9 @@ const DB = SERVER.'/database/dragon.db';
|
||||||
|
|
||||||
require_once SERVER.'/library.php'; // include our miscellaneous functions
|
require_once SERVER.'/library.php'; // include our miscellaneous functions
|
||||||
|
|
||||||
|
// define whether we are installed or not
|
||||||
|
define('INSTALLED', file_exists(SERVER.'/.installed'));
|
||||||
|
|
||||||
// autoloader map
|
// autoloader map
|
||||||
const MAP = [
|
const MAP = [
|
||||||
// 'Class' => 'path/to/class.php',
|
// 'Class' => 'path/to/class.php',
|
||||||
|
@ -26,6 +29,7 @@ const MAP = [
|
||||||
|
|
||||||
// modules
|
// modules
|
||||||
'HomeModule' => SERVER.'/modules/HomeModule.php',
|
'HomeModule' => SERVER.'/modules/HomeModule.php',
|
||||||
|
'InstallModule' => SERVER.'/modules/InstallModule.php',
|
||||||
];
|
];
|
||||||
|
|
||||||
// autoloader
|
// autoloader
|
||||||
|
|
|
@ -1,33 +1,22 @@
|
||||||
<?php // library.php :: Common functions used throughout the program.
|
<?php // library.php :: Common functions used throughout the program.
|
||||||
|
|
||||||
/**
|
|
||||||
* A stopwatch function to return the elapsed time in seconds.
|
|
||||||
*/
|
|
||||||
function stopwatch(float $start, int $roundTo = 3): float
|
function stopwatch(float $start, int $roundTo = 3): float
|
||||||
{
|
{
|
||||||
return round(microtime(true) - $start, $roundTo);
|
return round(microtime(true) - $start, $roundTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Redirects to a URL.
|
|
||||||
*/
|
|
||||||
function redirect(string $url): void
|
function redirect(string $url): void
|
||||||
{
|
{
|
||||||
header("Location: $url");
|
header("Location: $url");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function installRedirect(string $route)
|
||||||
* Checks if the server is installed.
|
|
||||||
*/
|
|
||||||
function installed(): bool
|
|
||||||
{
|
{
|
||||||
return file_exists(SERVER.'/.installed');
|
if (!INSTALLED && $route != 'install') redirect('/install');
|
||||||
|
if (INSTALLED && $route == 'install') redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the path to a template.
|
|
||||||
*/
|
|
||||||
function template(string $name): string
|
function template(string $name): string
|
||||||
{
|
{
|
||||||
return SERVER."/templates/$name.php";
|
return SERVER."/templates/$name.php";
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
class HomeModule
|
class HomeModule
|
||||||
{
|
{
|
||||||
public static function home(App $app)
|
public static function home()
|
||||||
{
|
{
|
||||||
echo 'Welcome to the home module!';
|
echo 'Welcome to the home module!';
|
||||||
|
echo 'Your request is: ' . App::$req->uri(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
101
server/modules/InstallModule.php
Normal file
101
server/modules/InstallModule.php
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
The second URI segment determines the step/page we are on.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class InstallModule
|
||||||
|
{
|
||||||
|
public static function handle()
|
||||||
|
{
|
||||||
|
$s = App::$req->uri(1) ?? ''; // second segment
|
||||||
|
$m = App::$req->method; // request method
|
||||||
|
|
||||||
|
if ($s == '' || $s == 'intro') return self::intro();
|
||||||
|
if ($s == 'database' && $m == 'POST') return self::database();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function intro()
|
||||||
|
{
|
||||||
|
echo render('install/layout', ['title' => 'Intro', 'step' => 'first']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function database()
|
||||||
|
{
|
||||||
|
$istart = microtime(true); // time the database setup
|
||||||
|
if (!isset($_POST['mode'])) redirect('/install'); // redirect if no mode
|
||||||
|
$complete = $_POST['mode'] == 'complete'; // complete or partial setup
|
||||||
|
$resFmt = '%s <span class="extra-data">(%fs)</span><br />';
|
||||||
|
|
||||||
|
$results = '';
|
||||||
|
|
||||||
|
// @Settings
|
||||||
|
App::$db->q("CREATE TABLE IF NOT EXISTS settings (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
game_name TEXT DEFAULT 'Dragon Knight',
|
||||||
|
game_version TEXT DEFAULT '1.0',
|
||||||
|
game_dev TEXT DEFAULT 'Sharkk',
|
||||||
|
game_url TEXT DEFAULT 'https://dragonknight.dev',
|
||||||
|
game_size INT DEFAULT 250,
|
||||||
|
game_open INT DEFAULT 1,
|
||||||
|
admin_email TEXT DEFAULT 'admin@dragonknight.dev',
|
||||||
|
forum_type INT DEFAULT 1,
|
||||||
|
forum_url TEXT DEFAULT '',
|
||||||
|
verify_email INT DEFAULT 1,
|
||||||
|
show_news INT DEFAULT 1,
|
||||||
|
show_online INT DEFAULT 1,
|
||||||
|
show_babble INT DEFAULT 1
|
||||||
|
);");
|
||||||
|
|
||||||
|
$results .= sprintf($resFmt, 'Settings table created', stopwatch($istart));
|
||||||
|
|
||||||
|
// insert default settings
|
||||||
|
App::$db->q("INSERT INTO settings DEFAULT VALUES;");
|
||||||
|
|
||||||
|
$results .= sprintf($resFmt, 'Default settings inserted', stopwatch($istart));
|
||||||
|
|
||||||
|
// @Classes
|
||||||
|
App::$db->q("CREATE TABLE IF NOT EXISTS classes (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
name TEXT DEFAULT '',
|
||||||
|
start_hp INT DEFAULT 0,
|
||||||
|
start_mp INT DEFAULT 0,
|
||||||
|
start_str INT DEFAULT 0,
|
||||||
|
start_atk INT DEFAULT 0,
|
||||||
|
start_dex INT DEFAULT 0,
|
||||||
|
start_def INT DEFAULT 0
|
||||||
|
growth_hp INT DEFAULT 0,
|
||||||
|
growth_mp INT DEFAULT 0,
|
||||||
|
growth_str INT DEFAULT 0,
|
||||||
|
growth_atk INT DEFAULT 0,
|
||||||
|
growth_dex INT DEFAULT 0,
|
||||||
|
growth_def INT DEFAULT 0,
|
||||||
|
spells TEXT DEFAULT '',
|
||||||
|
);");
|
||||||
|
|
||||||
|
$results .= sprintf($resFmt, 'Classes table created', stopwatch($istart));
|
||||||
|
|
||||||
|
if ($complete) {
|
||||||
|
// add default classes if complete install
|
||||||
|
App::$db->q("INSERT INTO classes VALUES
|
||||||
|
(1, 'Mage', 10, 10, 5, 5, 5, 5, 3, 5, 1, 3, 1, 3, '1:6,18'),
|
||||||
|
(2, 'Warrior', 20, 0, 10, 5, 10, 5, 6, 2, 3, 1, 3, 1, ''),
|
||||||
|
(3, 'Paladin', 15, 5, 5, 5, 10, 10, 4, 4, 2, 2, 2, 2, '1:1,15,18');");
|
||||||
|
} else {
|
||||||
|
// there must be at least one class, for user creation to work
|
||||||
|
App::$db->q("INSERT INTO classes (name) VALUES ('Adventurer');");
|
||||||
|
}
|
||||||
|
|
||||||
|
$results .= sprintf($resFmt, 'Default classes inserted', stopwatch($istart));
|
||||||
|
|
||||||
|
// @Babble
|
||||||
|
App::$db->q("CREATE TABLE IF NOT EXISTS babble (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
author INTEGER NOT NULL,
|
||||||
|
babble TEXT NOT NULL,
|
||||||
|
posted DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);");
|
||||||
|
|
||||||
|
$results .= sprintf($resFmt, 'Babble table created', stopwatch($istart));
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,8 +25,8 @@
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Click the appropriate button below for your preferred installation method.
|
Click the appropriate button below for your preferred installation method.
|
||||||
<form action="/install/?step=second" method="post">
|
<form action="/install/database" method="post">
|
||||||
<button type="submit" name="mode" value="complete">Complete Setup</button>
|
<button type="submit" name="mode" value="complete">Complete Setup</button><br>
|
||||||
- OR - <br>
|
- OR - <br>
|
||||||
<button type="submit" name="mode" value="partial">Partial Setup</button>
|
<button type="submit" name="mode" value="partial">Partial Setup</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<link rel="stylesheet" href="/css/dragon.css">
|
<link rel="stylesheet" href="/css/dragon.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="container">
|
<div id="install-container">
|
||||||
<h1>Dragon Knight Installation</h1>
|
<h1>Dragon Knight Installation</h1>
|
||||||
<h2><?= $title ?></h2>
|
<h2><?= $title ?></h2>
|
||||||
<?= render("install/$step", $data) ?>
|
<?= render("install/$step", $data) ?>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user