Build MVP: launcher, constructor, and AI game generation
A self-hosted, Roblox-flavored game platform: browse/play published browser games, build them by hand or by describing them to an LLM. Fully independent from top-tickets — separate repo, DB, port (8082). - Auth: email+password accounts (argon2, httpOnly session cookies), no admin/agent split — every account can create and play. - Three game templates (quiz, clicker, maze), each a zod schema paired with a Phaser 4 Scene that renders purely from a validated instance of that schema — manual and AI-generated games hit the same renderer, so a saved game is always guaranteed to load and run. The maze schema BFS-validates that the exit is reachable from the start. - Manual constructor: per-template builder forms, draft/publish/edit/ delete, a launcher grid of published games, a full-bleed play page. - AI generation: Anthropic API key configured under Settings → AI (encrypted at rest, validated with a live call before saving, same shape as top-tickets' mailbox/LDAP settings). Generation uses the SDK's zodOutputFormat/messages.parse to force schema-shaped JSON output, with one retry feeding back the validation error. Output always prefills the manual builder for review — never auto-published blind. Clean, distinct error message when no key is configured yet (no silent fallback exists here, so it doesn't pretend one does). - Docker Compose on port 8082 (bakes in the busy_timeout=30000 SQLite pragma from day one — top-tickets hit this build-time race twice). Deferred: more templates/genres, drag-and-drop level editor, likes/ leaderboards, AI-generated sprite assets, multiplayer, moderation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QcXH24ky6zjk2UyK5oZUPH
This commit is contained in:
1 parent
df16c90832
commit
c9a6c27a7a
60 files changed
+5601
-93
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const MAZE_CHARS = new Set(["#", ".", "S", "E", "*"]);
|
||||
|
||||
/** BFS from S to any E, treating '#' as the only impassable tile. */
|
||||
function isExitReachable(grid: string[]): boolean {
|
||||
const rows = grid.length;
|
||||
const cols = grid[0]?.length ?? 0;
|
||||
let start: [number, number] | null = null;
|
||||
for (let r = 0; r < rows; r++) {
|
||||
for (let c = 0; c < cols; c++) {
|
||||
if (grid[r][c] === "S") start = [r, c];
|
||||
}
|
||||
}
|
||||
if (!start) return false;
|
||||
|
||||
const visited = new Set<string>([`${start[0]},${start[1]}`]);
|
||||
const queue: [number, number][] = [start];
|
||||
while (queue.length > 0) {
|
||||
const [r, c] = queue.shift()!;
|
||||
if (grid[r][c] === "E") return true;
|
||||
for (const [dr, dc] of [
|
||||
[-1, 0],
|
||||
[1, 0],
|
||||
[0, -1],
|
||||
[0, 1],
|
||||
]) {
|
||||
const nr = r + dr;
|
||||
const nc = c + dc;
|
||||
if (nr < 0 || nr >= rows || nc < 0 || nc >= cols) continue;
|
||||
const key = `${nr},${nc}`;
|
||||
if (visited.has(key) || grid[nr][nc] === "#") continue;
|
||||
visited.add(key);
|
||||
queue.push([nr, nc]);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export const mazeDefinitionSchema = z
|
||||
.object({
|
||||
// Each string is one row. '#' wall, '.' floor, 'S' start, 'E' exit, '*' item.
|
||||
grid: z.array(z.string().min(1)).min(3).max(30),
|
||||
// 0 = no limit.
|
||||
timeLimitSec: z.number().int().min(0).max(600).default(0),
|
||||
})
|
||||
.refine((def) => def.grid.every((row) => row.length === def.grid[0].length), {
|
||||
message: "All grid rows must be the same length",
|
||||
path: ["grid"],
|
||||
})
|
||||
.refine((def) => def.grid.every((row) => [...row].every((c) => MAZE_CHARS.has(c))), {
|
||||
message: "Grid may only contain the characters # . S E *",
|
||||
path: ["grid"],
|
||||
})
|
||||
.refine((def) => def.grid.flatMap((row) => [...row]).filter((c) => c === "S").length === 1, {
|
||||
message: "Grid must contain exactly one S (start)",
|
||||
path: ["grid"],
|
||||
})
|
||||
.refine((def) => def.grid.some((row) => row.includes("E")), {
|
||||
message: "Grid must contain at least one E (exit)",
|
||||
path: ["grid"],
|
||||
})
|
||||
.refine((def) => isExitReachable(def.grid), {
|
||||
message: "Exit (E) must be reachable from the start (S)",
|
||||
path: ["grid"],
|
||||
});
|
||||
|
||||
export type MazeDefinition = z.infer<typeof mazeDefinitionSchema>;
|
||||
|
||||
export const DEFAULT_MAZE_DEFINITION: MazeDefinition = {
|
||||
grid: ["#######", "#S.*..#", "#.###.#", "#...*.#", "#.###.#", "#....E#", "#######"],
|
||||
timeLimitSec: 0,
|
||||
};
|
||||
Reference in new issue
Block a user