Feature prompts
Prompts to hand to a Gameix builder so it can add one of play-i's features to another game. Each one stands on its own: copy the block under a heading and paste it as a request. They describe what play-i actually does, with the shapes of the data and the code, so the builder can rebuild it rather than guess. Every prompt assumes a Three.js game in a React app on Gameix, with the platform SDK client at @/api/base44Client, entities as JSON schemas, and backend functions for anything that needs the service role or a secret. Change the names to fit your game.
1. Debug panel (press ` over any page)
Add a debug panel that opens over every page and every game with the backquote key (`) or ?debug=1 in the address.
Build it in two parts:
1. A tiny registry, src/lib/debugLog.js, with no React in it:
- debugSource(name, read, { live }) registers a function that returns a plain object of facts about one part of the page (the game, a co-play room, chat). It returns an unregister function; call it on teardown.
- debugSnapshot() calls every source and returns { [name]: facts } plus device facts: userAgent, screen size, devicePixelRatio, the WebGL renderer name (WEBGL_debug_renderer_info), language, and the last 50 console errors and warnings.
- installDebugLog() is called once in main.jsx: it wraps console.error/console.warn and listens for window 'error' and 'unhandledrejection', keeping a ring buffer of the last 50 with a timestamp.
- Sources marked live are cheap and may be read every second; others are read only when a full report is taken.
- Also expose window.playiDebug = debugSnapshot so the report can be read from the browser console.
2. A DebugPanel React component mounted once in App.jsx outside <Routes>, so it is on every page:
- Toggles on the Backquote key unless focus is in an input or textarea.
- Shows each source as a collapsible <details> section of name/value rows, re-read every second while open. A source that returns nothing shows "not in use".
- Shows a live frame-time readout (requestAnimationFrame deltas: fps, p95, worst) only while open.
- Has a note field and two buttons: "Copy report" (JSON to the clipboard) and "Send to builder", which creates a DebugReport record: { game, note, verdict, report (the full snapshot), picture }. picture is a private file of the game canvas: canvas.toBlob, then UploadPrivateFile, store the file_uri.
- DebugReport entity: owner only (admin-only read/create/update/delete RLS).
In each game, register a source in the game's start function, e.g. debugSource('play', () => ({ phase, score, enemies: list.length, quality: level }), { live: true }), and unregister it in the game's dispose. Keep facts small and JSON-safe. Never put secrets or other players' private data in a source.
Make the panel usable on touch screens: buttons at least 40px tall, the panel scrolls, and a small floating "Debug" button appears when ?debug=1 is set so phones (with no backquote key) can open it.3. Asset viewer for generated 3D models
Add an asset viewer to the game's lab: every generated GLB the game loads, shown one at a time in its own interactive 3D view, with its numbers.
1. Asset index. Each game exports a list of the models it loads:
type GameAsset = { id, name, kind: 'model', url, load: () => Promise<THREE.Object3D>, source?: 'generated' | 'hand-built', reference?: string (the picture it was made from) }.
In the game, load models through one readyModel(kind) function that caches the GLTFLoader.loadAsync promise per URL, so the viewer and the game share one download.
2. Stage (asset-stage.ts): a THREE.Scene with a neutral studio light (a hemisphere light plus one key light with soft shadow), a ground disc, and place(asset) that clones the model, measures it with Box3, centres it on the disc, and returns { clone, size, radius }. fit(radius) returns the camera distance that frames the bounding sphere for the camera's fov. look(form) switches the materials between 'lit', 'clay' (plain grey MeshStandardMaterial), 'wire' and 'normals' to judge shape apart from texture.
3. Viewer (asset-viewer.ts): createAssetViewer(host, asset, background) makes its OWN WebGLRenderer (never the game's), OrbitControls with damping and slow auto-rotate, a ResizeObserver on the host, and returns { triangles, meshes, materials, textures, textureMB, size, setSpin, setForm, picture(), reset, dispose }.
- dispose() stops the animation loop, disposes controls and renderer, calls forceContextLoss() and removes the canvas. It must never dispose the shared cached geometry or textures the game uses.
- picture() renders once and copies the canvas onto a plain 2D canvas before toDataURL, because one browser returns the WebGL canvas upside down.
4. UI (AssetViewer.tsx): a grid of asset cards (name, triangles, texture memory, load time), a click opens the viewer full size with buttons for Spin, Lit/Clay/Wire/Normals, Reset view and Keep picture. Show the model's reference picture beside it so the model can be compared to what it was made from.
Only one live viewer at a time: browsers allow about 16 WebGL contexts, so close the old viewer before opening the next.4. A Quality Lab for each game (LabKit)
Give the game its own Quality Lab at /lab/:game, built from one shared lab page plus a small kit the game supplies.
- The game's lab.ts exports a LabKit:
{
Game: the game's React component, started in lab mode (no saving, no scores, no player extras),
rubric: Criterion[] = { id, domain, title, method, acceptance, severity: 'critical' | 'high' | 'normal' }[],
playtest?: (handle, report) => Promise<PlaytestStep[]>, automated steps that drive the game through a dev-only test handle and return { id, criterion, title, status: 'pass'|'fail'|'skipped', detail, seconds },
diagnostics?: () => DiagnosticCheck[], checks the game runs on itself (assets loaded, no NaN positions, audio unlocked),
assets?: GameAsset[] for the asset viewer,
stress?: see the stress test prompt,
trailer?: see the trailer prompt,
}
- The game exposes a dev-only test handle on window (only under /lab): start(seed), step(seconds) to advance the game clock without waiting, state() for a JSON summary, and a few direct moves. Playtests use step() rather than real time, because preview machines can draw as slowly as one frame a second.
- The lab page measures frame pacing with a phase marker the game raises once its scene is fully drawn: collect frames for N seconds, report fps, p50/p95/p99 frame time, the share of frames over 20 ms, draw calls, triangles, geometries, textures and canvas size. Warm up for a few seconds before measuring so shader compilation does not count.
- Keep the lab's own diagnostics (measured by code) apart from AI review findings (judged from screenshots): they are stored and shown separately.
- The lab is for the owner: gate it behind role === 'admin' for everything that writes.5. Stress test (find where the frame rate breaks)
Add a stress test to the game's lab that turns the game's load up step by step until the frame rate falls under 30, and records where it broke on this device.
- The kit supplies stress: { dial: 'what is turned up, e.g. enemies and debris in view', steps: number[], set(level): void, clear(): void }. set(level) adds load the way real play would (more enemies, more copies of the generated models with instancing, more particles), not dummy cubes.
- For each step: set the level, wait 1.5 s to settle, then sample 3 s of frames. Record { level, fps, p95_ms, worst_ms }. Stop at the first step under 30 fps.
- Also call one cheap backend function 1, 5 and 10 times at once and record { at_once, median_ms, worst_ms, failed }.
- Save a StressRun record (owner only): { game, kind: 'load', dial, device: userAgent, gpu: WEBGL_debug_renderer_info name, view: canvas size, held: highest step at 30 fps or more, broke_at, steps, server }.
- Show past runs in a table grouped by device, so a phone and a desktop can be compared.
- Always call clear() at the end and on cancel, and dispose everything set() created.6. Trailer filmed from the real game
Add a trailer recorder to the game's lab that films the real game into an MP4/WebM with captions and music. Nothing in it is generated video: every frame is the game.
- The kit supplies trailer: { scenes: TrailerScene[], music?: url }, where TrailerScene = { id, seconds, caption, setup(game): Promise<void> (put the game in the right state, e.g. start a seeded battle), camera?(t, game) (move the game camera for time t in 0..1), overlay?(ctx, t) (draw extra 2D on top), expect: 'what this shot should show' }.
- Filming: for each scene, run setup, then WARM UP for at least 0.8 s (render without recording so shaders and textures are ready), then record. Two modes: live (MediaRecorder on canvas.captureStream(30)) and steady (advance the game clock by exactly 1/30 s per frame and encode each frame with WebCodecs, e.g. via the mediabunny package), so a slow machine still makes a smooth video.
- Draw captions and title cards onto a 2D canvas laid over the game frame before encoding; fade between shots.
- Mix music in with WebAudio (MediaStreamDestination) under the video track, at about -12 dB below effects.
- After filming, save a TrailerTake record (owner only) with a few sample frames per shot (private files), each with what it was expected to show and the game facts read at that moment (from the debug source), so a builder can check each shot without watching the video.
- Keep caption wording the owner types in a MarketingWords record keyed per video, so it survives reloads and other devices.7. Every screen in several languages, right-to-left included
Translate the whole game and platform into several languages, with Hebrew and Arabic reading right to left.
- src/lib/i18n.ts: LANGS = [{ id, name (in its own language), rtl }]. English is the source text; every other language is looked up from it.
- addWords({ 'English text': [he, lt, uk, ar, es, de], ... }) registers a table of rows in a fixed column order. Each game keeps its own words file (words/ui.ts) and imports it from its entry component.
- t(text, params?) returns the translation, or the English if none, and fills {name}-style placeholders.
- useLang() (useSyncExternalStore) re-renders components when the language changes; onLang(fn) does the same for code outside React, e.g. text painted onto canvas textures in the 3D scene, which must be repainted.
- The choice is kept in localStorage; ?lang=he in the address overrides it; otherwise the browser's language if supported.
- On change, set <html lang> and <html dir="rtl|ltr"> so layout flips. Use CSS logical properties (margin-inline-start, inset-inline-end) instead of left/right.
- A LanguagePicker in the corner of the main screen and each game's title screen.
- Wrap every visible string in t(), including the game card's type and description on the main screen, tooltips, rules, error messages from the server (translate on the client from a known English message), and text drawn in the 3D world.
- Shrink canvas-painted labels to fit when a translation is longer than the English.
- A lab check that walks every screen in each language and flags any English string left over.8. Controller support on every screen
Add gamepad support to the games and the menus around them. - src/lib/gamepad.ts: one requestAnimationFrame loop reads the first connected pad in the browser's "standard" mapping and hands listeners a frame: held(button), pressed(button), released(button), value(button) for analogue triggers, sticks lx/ly/rx/ry after an 0.18 dead zone, dt, and kind: 'xbox' | 'playstation' | 'nintendo' | 'generic' (guessed from gamepad.id). Buttons are named by position: A B X Y LB RB LT RT BACK START LS RS UP DOWN LEFT RIGHT. - padState() says whether the pad is the input in use (the last input was the pad, not mouse/touch/keys), so screens show the pad's own button names (PadGlyph component: A/B/X/Y or cross/circle/square/triangle) only then. - Menus: a PagePad component mounted once in App.jsx moves focus between focusable elements with the d-pad/left stick by screen position (nearest element in that direction), A clicks, B goes back (closes the open panel or history.back()). Draw a clear focus ring. - In game: each game maps the pad in its own pad.ts. Keep one action per button, the same in every game where possible (Start pauses, B backs out, Y recentres the camera). - Lab: a pad review that drives the game with a simulated pad (a fake navigator.getGamepads) and checks every screen can be reached and left with the pad alone.
9. Chat, friends, voice and video
Add a social dock on every page: a lobby channel, a channel per game, private messages, friends, and voice/video calls.
- Entities (all written only by one backend function, social, so names cannot be faked):
Profile { user_id, username (16), bio, colour, favourite, seen, playing }: public read.
ChatMessage { channel, author_id, username, colour, text (300), hidden }: read when not hidden.
DirectMessage { from_id, to_id, from_name, text, kind: 'say'|'invite', game, room, read }: read only by the two players (RLS on data.from_id / data.to_id = user.id).
Friendship { from_id, to_id, pair (both ids sorted, so one record per pair), status: 'pending'|'accepted' }.
ChatReport for reported lines, owner only.
- The social function checks the signed-in user, rate limits (1 line per second, 300 chars), trims and screens text, then writes with the service role. Actions: say, dm, befriend, accept, report, seen.
- The dock subscribes to ChatMessage and DirectMessage in real time (entity subscribe) and shows unread counts.
- Voice and video: a small server-side actor (a room) only relays WebRTC offers, answers and ICE candidates between the people in a channel; audio and video go peer to peer. Turning the camera on mid-call renegotiates with each peer; when two offers cross, the lower seat wins. Faces show in a draggable, resizable window that remembers its place.
- An "Invite" in the friends list sends a DirectMessage of kind invite with the game and the room code; opening it routes to /play/:game?room=CODE.10. An in-game adviser that knows the rules and the board
Add an adviser the player can ask questions in their own words, answered from the game's rules and what the player can see right now.
- adviser.ts in the game builds a compact text context: the rules and costs, the controls, and a summary of the current state as the player's seat may see it (never other players' hidden cards).
- A backend function askAdviser({ game, question, context }) checks the user is signed in, keeps a daily count in an AdviserUse record (one per user per day, cap 40), and calls the LLM integration with a system prompt that sets the adviser's voice and tells it to answer only from the given context, in the player's language, in at most 4 sentences.
- The box opens from a button in the game's top tools; it can read the answer aloud with speechSynthesis and take the question by voice with the browser's speech recognition where available.
- Show the remaining questions for the day. Guests see a prompt to sign in.11. Experimental VR mode (WebXR, with a preview without a headset)
Add an experimental VR mode to a first-person Three.js game.
- vr.ts: check navigator.xr?.isSessionSupported('immersive-vr'). If supported, renderer.xr.enabled = true and requestSession('immersive-vr', { optionalFeatures: ['local-floor', 'bounded-floor'] }), then switch the game loop to renderer.setAnimationLoop. Controllers: renderer.xr.getController(0/1) for aim and select, getControllerGrip for the hand models.
- If no headset is found (most desktop browsers, Firefox included), still offer the mode as a side-by-side stereo preview using THREE.StereoCamera rendered into two halves of the canvas, with a clear note that no headset was detected.
- Turn off post-processing passes in VR; they double the cost per eye.
- Keep HUD text on a plane in front of the camera in VR, not in the DOM.
- A VrButton in the game's settings, hidden while a run is in progress.12. Lore book per game
Add a lore book for each game at /lore/:game: pages with a painted picture and a short text about the game's world, its buildings, creatures and heroes, readable on a phone, translated.
- books.ts: { [gameId]: { title, pages: [{ title, text, picture (public image URL), model? (asset id to show in a small 3D viewer) }] } }.
- LoreBook component: one page at a time with previous/next, swipe on touch, arrows on keys, the pad's LB/RB. Keep the page in the address (#3) so a page can be shared.
- Words go through the same t() as the game; each book has its own words file.
- Link it from the game's card on the main screen and from the game's pause screen.