Compare commits
No commits in common. "ai-dev" and "master" have entirely different histories.
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
function ensureWorldsTable(): void {
|
||||
$sql = "CREATE TABLE IF NOT EXISTS worlds (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(120) NOT NULL,
|
||||
size INT UNSIGNED NOT NULL DEFAULT 16,
|
||||
world_json MEDIUMTEXT NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_worlds_updated_at (updated_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
db()->exec($sql);
|
||||
}
|
||||
|
||||
function listWorlds(int $limit = 10): array {
|
||||
$stmt = db()->prepare('SELECT id, name, size, updated_at FROM worlds ORDER BY updated_at DESC LIMIT :limit');
|
||||
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
function getWorldById(int $id): ?array {
|
||||
$stmt = db()->prepare('SELECT id, name, size, world_json, created_at, updated_at FROM worlds WHERE id = :id');
|
||||
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
function saveWorld(string $name, string $worldJson, int $size): int {
|
||||
$stmt = db()->prepare('INSERT INTO worlds (name, size, world_json) VALUES (:name, :size, :world_json)');
|
||||
$stmt->bindValue(':name', $name);
|
||||
$stmt->bindValue(':size', $size, PDO::PARAM_INT);
|
||||
$stmt->bindValue(':world_json', $worldJson);
|
||||
$stmt->execute();
|
||||
return (int)db()->lastInsertId();
|
||||
}
|
||||
288
index.php
288
index.php
@ -4,197 +4,147 @@ declare(strict_types=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>
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<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(); ?>" />
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
</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>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</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>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</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>
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
header('Content-Type: application/json');
|
||||
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
require_once __DIR__ . '/includes/worlds.php';
|
||||
|
||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'error' => 'Missing world id.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
ensureWorldsTable();
|
||||
$world = getWorldById($id);
|
||||
} catch (Throwable $e) {
|
||||
echo json_encode(['success' => false, 'error' => 'Database unavailable.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$world) {
|
||||
echo json_encode(['success' => false, 'error' => 'World not found.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$worldData = json_decode($world['world_json'], true);
|
||||
if (!is_array($worldData)) {
|
||||
echo json_encode(['success' => false, 'error' => 'World data corrupted.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'world' => $worldData,
|
||||
'meta' => [
|
||||
'id' => (int)$world['id'],
|
||||
'name' => $world['name'],
|
||||
'size' => (int)$world['size'],
|
||||
'updated_at' => $world['updated_at']
|
||||
]
|
||||
]);
|
||||
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
header('Content-Type: application/json');
|
||||
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
require_once __DIR__ . '/includes/worlds.php';
|
||||
|
||||
try {
|
||||
ensureWorldsTable();
|
||||
} catch (Throwable $e) {
|
||||
echo json_encode(['success' => false, 'error' => 'Database unavailable.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$payload = json_decode(file_get_contents('php://input'), true);
|
||||
if (!is_array($payload)) {
|
||||
echo json_encode(['success' => false, 'error' => 'Invalid payload.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$name = trim((string)($payload['name'] ?? ''));
|
||||
$world = $payload['world'] ?? null;
|
||||
$size = (int)($payload['size'] ?? 0);
|
||||
|
||||
if ($name === '' || mb_strlen($name) < 2 || mb_strlen($name) > 80) {
|
||||
echo json_encode(['success' => false, 'error' => 'World name must be 2-80 characters.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!is_array($world) || $size <= 0 || $size > 32) {
|
||||
echo json_encode(['success' => false, 'error' => 'World data is invalid.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$worldJson = json_encode($world, JSON_UNESCAPED_UNICODE);
|
||||
if ($worldJson === false || strlen($worldJson) > 200000) {
|
||||
echo json_encode(['success' => false, 'error' => 'World data too large.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$id = saveWorld($name, $worldJson, $size);
|
||||
echo json_encode(['success' => true, 'id' => $id]);
|
||||
} catch (Throwable $e) {
|
||||
echo json_encode(['success' => false, 'error' => 'Unable to save world right now.']);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user