39030-vm/index.php
Flatlogic Bot 6489bf1f14 ai
2026-03-07 04:07:33 +00:00

201 lines
8.6 KiB
PHP

<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/worlds.php';
$dbError = null;
try {
ensureWorldsTable();
} catch (Throwable $e) {
$dbError = 'Database connection issue. Saving/loading is temporarily unavailable.';
}
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
$projectTitle = $_SERVER['PROJECT_NAME'] ?? 'Blockcraft Studio';
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
$initialWorldId = isset($_GET['world_id']) ? (int)$_GET['world_id'] : 0;
$worlds = [];
if (!$dbError) {
$worlds = listWorlds(12);
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><?= htmlspecialchars($projectTitle) ?></title>
<?php if ($projectDescription): ?>
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time(); ?>" />
</head>
<body>
<nav class="navbar navbar-expand-lg bg-white border-bottom">
<div class="container-fluid px-4">
<a class="navbar-brand fw-semibold" href="/">Blockcraft Studio</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto align-items-lg-center gap-lg-3">
<li class="nav-item"><a class="nav-link" href="#play">Play</a></li>
<li class="nav-item"><a class="nav-link" href="#saves">Saved Worlds</a></li>
<li class="nav-item"><a class="nav-link" href="#how">How it works</a></li>
</ul>
</div>
</div>
</nav>
<main class="container-fluid px-4 py-4">
<section class="hero card shadow-sm mb-4">
<div class="card-body d-flex flex-column flex-lg-row align-items-lg-center justify-content-between gap-3">
<div>
<h1 class="display-6 fw-semibold mb-2">Minecraft-like browser prototype</h1>
<p class="text-muted mb-0">Build a tiny voxel world with place/break actions, save snapshots, and reload them instantly.</p>
</div>
<div class="d-flex gap-2">
<button class="btn btn-dark" id="new-world-btn">New flat world</button>
<button class="btn btn-outline-dark" id="reset-camera-btn">Reset camera</button>
</div>
</div>
</section>
<?php if ($dbError): ?>
<div class="alert alert-warning border-0 shadow-sm"><?= htmlspecialchars($dbError) ?></div>
<?php endif; ?>
<div class="row g-4">
<div class="col-lg-8" id="play">
<div class="card shadow-sm h-100">
<div class="card-header bg-white border-bottom">
<div class="d-flex flex-wrap align-items-center justify-content-between gap-2">
<div>
<h2 class="h5 mb-1">Build canvas</h2>
<p class="text-muted small mb-0">Left click: place block · Right click: break · WASD: move</p>
</div>
<span class="badge bg-light text-dark border">Prototype v1</span>
</div>
</div>
<div class="card-body">
<div class="canvas-shell">
<canvas id="game-canvas" width="900" height="560"></canvas>
</div>
<div class="d-flex flex-column flex-md-row justify-content-between gap-2 mt-3">
<div class="text-muted small">
Blocks: <span id="block-count">0</span> · Camera: <span id="camera-pos">0,0</span>
</div>
<div class="text-muted small">
Runtime: PHP <?= htmlspecialchars($phpVersion) ?> · UTC <?= htmlspecialchars($now) ?>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-4" id="saves">
<div class="card shadow-sm mb-4">
<div class="card-header bg-white border-bottom">
<h2 class="h6 mb-0">Save current world</h2>
</div>
<div class="card-body">
<form id="save-world-form">
<label class="form-label small text-muted">World name</label>
<input type="text" class="form-control mb-2" id="world-name" placeholder="Ex: Sandbox 01" maxlength="80" required />
<button type="submit" class="btn btn-dark w-100">Save snapshot</button>
<p class="text-muted small mt-2 mb-0">Saves are stored on the server for admin review.</p>
</form>
</div>
</div>
<div class="card shadow-sm">
<div class="card-header bg-white border-bottom">
<h2 class="h6 mb-0">Saved worlds</h2>
</div>
<div class="card-body">
<?php if (empty($worlds)): ?>
<p class="text-muted small mb-0">No saves yet. Build something and save your first world.</p>
<?php else: ?>
<div class="list-group">
<?php foreach ($worlds as $world): ?>
<div class="list-group-item d-flex flex-column gap-2">
<div class="d-flex justify-content-between align-items-center">
<div>
<div class="fw-semibold"><?= htmlspecialchars($world['name']) ?></div>
<div class="text-muted small">Updated <?= htmlspecialchars($world['updated_at']) ?></div>
</div>
<span class="badge bg-light text-dark border"><?= (int)$world['size'] ?>x<?= (int)$world['size'] ?></span>
</div>
<div class="d-flex gap-2">
<a class="btn btn-sm btn-outline-dark" href="world.php?id=<?= (int)$world['id'] ?>">Details</a>
<button class="btn btn-sm btn-dark load-world-btn" data-world-id="<?= (int)$world['id'] ?>">Load</button>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<section class="card shadow-sm mt-4" id="how">
<div class="card-body">
<h2 class="h5">How it works</h2>
<div class="row g-3 mt-1">
<div class="col-md-4">
<h3 class="h6">Build fast</h3>
<p class="text-muted small mb-0">A lightweight isometric renderer draws a voxel grid without any 3D libraries.</p>
</div>
<div class="col-md-4">
<h3 class="h6">Save snapshots</h3>
<p class="text-muted small mb-0">Every save stores the height map in MariaDB for quick recall.</p>
</div>
<div class="col-md-4">
<h3 class="h6">Review worlds</h3>
<p class="text-muted small mb-0">Admins can inspect each save and load it back into the game.</p>
</div>
</div>
</div>
</section>
</main>
<footer class="footer border-top py-3 mt-4">
<div class="container-fluid px-4 d-flex flex-column flex-md-row justify-content-between small text-muted">
<span>Blockcraft Studio · Prototype slice</span>
<span>Updated <?= htmlspecialchars($now) ?> (UTC)</span>
</div>
</footer>
<div class="toast-container position-fixed bottom-0 end-0 p-3">
<div id="app-toast" class="toast align-items-center text-bg-dark border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body" id="toast-body">Saved.</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>
<script>
window.__INITIAL_WORLD_ID__ = <?= (int)$initialWorldId ?>;
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?= time(); ?>"></script>
</body>
</html>