66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Render;
|
|
|
|
/*
|
|
This file contains functions to render various UI elements. The goal is to begin shifting elements in the game
|
|
to HTMX/AJAX for more fluid gameplay.
|
|
*/
|
|
|
|
function header_links(): string
|
|
{
|
|
if (user() !== false) {
|
|
$links = "<a href='/logout'><img src='/img/button_logout.gif' alt='Log Out' title='Log Out'></a>";
|
|
} else {
|
|
$links = <<<HTML
|
|
<a href='/login'><img src='/img/button_login.gif' alt='Log In' title='Log In'></a>
|
|
<a href='/register'><img src='/img/button_register.gif' alt='Register' title='Register'></a>
|
|
HTML;
|
|
}
|
|
|
|
return $links .= "<a href='/help'><img src='/img/button_help.gif' alt='Help' title='Help'></a>";
|
|
}
|
|
|
|
function debug_db_info(): string {
|
|
$total_time = round(microtime(true) - START, 4);
|
|
return '<div id="debug-db-info" hx-swap-oob="true">'. $total_time . ' Seconds, ' . db()->count . ' Queries</div>';
|
|
}
|
|
|
|
function right_nav(): string
|
|
{
|
|
if (user() === false) return '';
|
|
|
|
// Flashy numbers if they're low
|
|
$hp = (user()->currenthp <= (user()->maxhp / 5)) ? "<blink><span class=\"highlight\"><b>*" . user()->currenthp . "*</b></span></blink>" : user()->currenthp;
|
|
$mp = (user()->currentmp <= (user()->maxmp / 5)) ? "<blink><span class=\"highlight\"><b>*" . user()->currentmp . "*</b></span></blink>" : user()->currentmp;
|
|
|
|
$template = render('right_nav', ['hp' => $hp, 'mp' => $mp]);
|
|
if (is_htmx()) $template = '<section id="right" hx-swap-oob="true">'.$template."</section>";
|
|
return $template;
|
|
}
|
|
|
|
function left_nav(): string
|
|
{
|
|
if (user() === false) return '';
|
|
|
|
$template = render('left_nav');
|
|
if (is_htmx()) $template = '<section id="left" hx-swap-oob="true">'.$template."</section>";
|
|
return $template;
|
|
}
|
|
|
|
function babblebox(): string
|
|
{
|
|
return render('babblebox', ['messages' => babblebox_messages()]);
|
|
}
|
|
|
|
function debug_query_log(): string
|
|
{
|
|
$html = '<pre id="debug-query-log" hx-swap-oob="true">';
|
|
foreach (db()->log as $record) {
|
|
$query_string = str_replace(["\r\n", "\n", "\r"], ' ', $record[0]);
|
|
$error_string = !empty($record[2]) ? '// '.$record[2] : '';
|
|
$html .= '<div>['.round($record[1], 2)."s] {$query_string}{$error_string}</div>";
|
|
}
|
|
return $html . '</pre>';
|
|
}
|