From 6489bf1f143e7ea2a0099da91b4a5a406523de95 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 7 Mar 2026 04:07:33 +0000 Subject: [PATCH] ai --- includes/worlds.php | 39 ++++++ index.php | 288 ++++++++++++++++++++++++++------------------ load_world.php | 42 +++++++ save_world.php | 46 +++++++ 4 files changed, 296 insertions(+), 119 deletions(-) create mode 100644 includes/worlds.php create mode 100644 load_world.php create mode 100644 save_world.php diff --git a/includes/worlds.php b/includes/worlds.php new file mode 100644 index 0000000..552aef0 --- /dev/null +++ b/includes/worlds.php @@ -0,0 +1,39 @@ +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(); +} diff --git a/index.php b/index.php index 7205f3d..71f7fb6 100644 --- a/index.php +++ b/index.php @@ -4,147 +4,197 @@ 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); +} ?> - New Style - + <?= htmlspecialchars($projectTitle) ?> - - - - - - - - - + + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… + + +
+
+
+
+

Minecraft-like browser prototype

+

Build a tiny voxel world with place/break actions, save snapshots, and reload them instantly.

+
+
+ + +
+
+
+ + +
+ + +
+
+
+
+
+
+

Build canvas

+

Left click: place block · Right click: break · WASD: move

+
+ Prototype v1 +
+
+
+
+ +
+
+
+ Blocks: 0 · Camera: 0,0 +
+
+ Runtime: PHP · UTC +
+
+
+
+
+ +
+
+
+

Save current world

+
+
+
+ + + +

Saves are stored on the server for admin review.

+
+
+
+ +
+
+

Saved worlds

+
+
+ +

No saves yet. Build something and save your first world.

+ +
+ +
+
+
+
+
Updated
+
+ x +
+
+ Details + +
+
+ +
+ +
+
+
+
+ +
+
+

How it works

+
+
+

Build fast

+

A lightweight isometric renderer draws a voxel grid without any 3D libraries.

+
+
+

Save snapshots

+

Every save stores the height map in MariaDB for quick recall.

+
+
+

Review worlds

+

Admins can inspect each save and load it back into the game.

+
+
+
+
-