I'll analyze the reference code and explore your existing codebase, then delegate the implementation to agents.
Let me first understand what you have.
Assistant
Let me read the key files directly.
Assistant
Now I have a clear picture of the existing codebase and what needs to change. The reference React code is a "Live Puzzle" with full-screen camera, two-hand framing to capture, pinch-to-drag tile swapping, and fist-to-reset. Your existing code has a sliding puzzle with gesture control.
I need to:
Rewrite game.js for swap puzzle mechanics
Add raw detection API to gesture.js
Rewrite main.js for full-screen camera render loop
Update index.html and style.css for new layout
Let me implement this now - writing all files in parallel.
Assistant
Writing game.js, gesture.js modifications, index.html, and style.css in parallel.
Assistant
Now let me update gesture.js with the new API methods and write the main.js controller.
Assistant
Now writing the main controller - the core of the Live Puzzle experience.
Assistant
All files written. Let me verify the gesture.js modifications are correct.
Assistant
Good. Now let me do a quick review of each file to catch any issues.
Assistant
Review passed with zero critical issues and all cross-references verified. Let me fix the 2 actionable items found.
Assistant
Also remove the unused file input from HTML.
Assistant
Implementation complete. Let me serve it and test in the browser.
Assistant· <synthetic>
Prompt is too long
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
please call agents team to work demo like code below, ENTIRE like this, just use our BE, but the experience should be the same import React, { useEffect, useRef, useState, useCallback } from 'react';
import { FilesetResolver, HandLandmarker, DrawingUtils } from '@mediapipe/tasks-vision';
import { Loader2, RotateCcw, Trophy, Hand, Timer, ListOrdered, ArrowRight, User, Star, Wifi, WifiOff, Globe, Copy, Info } from 'lucide-react';
// --- FIREBASE IMPORTS ---
import { initializeApp } from 'firebase/app';
import { getAuth, signInAnonymously, onAuthStateChanged, signInWithCustomToken, User as FirebaseUser } from 'firebase/auth';
import { getFirestore, collection, addDoc, onSnapshot } from 'firebase/firestore';
// --- GLOBAL CONFIG ---
// We MUST use the system provided App ID to comply with Firestore security rules.
// Writing to any other path will cause a Permission Denied error.
// @ts-ignore
const appId = typeof __app_id !== 'undefined' ? __app_id : 'default-app-id';
// --- UTILS (from processing.ts) ---
/**
Captures the current video frame to an ImageData object.
*/
function captureFrame(video: HTMLVideoElement, width: number, height: number): ImageData {
const offscreen = document.createElement('canvas');
offscreen.width = width;
offscreen.height = height;
const ctx = offscreen.getContext('2d');
if (!ctx) throw new Error('Could not get context');
Generates the shuffled state for the puzzle.
*/
function generatePuzzleState(cols: number, rows: number) {
const tiles = [];
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
tiles.push({
currentX: x,
currentY: y,
origX: x,
origY: y,
id: y * cols + x
});
}
}
// Fisher-Yates Shuffle
for (let i = tiles.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[tiles[i], tiles[j]] = [tiles[j], tiles[i]];
}
return tiles;
}
/**
Checks if the puzzle is solved
*/
function checkWinCondition(tiles: any[]) {
return tiles.every((tile, index) => tile.id === index);
}
/**
Renders the interactive puzzle game.
*/
function renderPuzzleGame(
ctx: CanvasRenderingContext2D,
imageSource: ImageBitmap | HTMLCanvasElement,
tiles: any[], // The shuffled array
cols: number,
rows: number,
destWidth: number,
destHeight: number,
dragInfo: { index: number, x: number, y: number } | null, // x,y are relative to the board
hoverIndex: number | null
) {
const destTileW = destWidth / cols;
const destTileH = destHeight / rows;
const srcTileW = imageSource.width / cols;
const srcTileH = imageSource.height / rows;
// Fill background
ctx.fillStyle = '#111';
ctx.fillRect(0, 0, destWidth, destHeight);
if (dragInfo && dragInfo.index === currentIndex) {
// Draw "hole" or dimmed version
ctx.fillStyle = '#222';
ctx.fillRect(dx, dy, destTileW, destTileH);
ctx.strokeStyle = '#333';
ctx.strokeRect(dx, dy, destTileW, destTileH);
// Draw the target highlight if we are hovering over a valid drop zone
if (hoverIndex !== null && hoverIndex !== currentIndex) {
// This logic is handled below broadly, but we can do specific slot highlighting here
}
} else {
// Normal tile
// Check if this is a potential drop target
if (dragInfo && hoverIndex === currentIndex) {
// Highlight the tile we might swap with
ctx.save();
ctx.globalAlpha = 0.5;
drawTile(tile, dx, dy, destTileW, destTileH);
ctx.fillStyle = 'rgba(204, 255, 0, 0.2)'; // Green Tint
ctx.fillRect(dx, dy, destTileW, destTileH);
ctx.strokeStyle = '#ccff00'; // Green Stroke
ctx.lineWidth = 2;
ctx.strokeRect(dx, dy, destTileW, destTileH);
ctx.restore();
} else {
drawTile(tile, dx, dy, destTileW, destTileH);
}
}
});
// 2. Draw dragged tile on top
if (dragInfo) {
const tile = tiles[dragInfo.index];
// Draw centered on cursor
const dragW = destTileW * 1.1; // Slightly larger
const dragH = destTileH * 1.1;
const dx = dragInfo.x - (dragW / 2);
const dy = dragInfo.y - (dragH / 2);
code
drawTile(tile, dx, dy, dragW, dragH, true);
}
}
// --- CONSTANTS ---
const PINCH_THRESHOLD = 0.05; // Distance between thumb and index
const FRAME_THRESHOLD = 0.1;
const RESET_DWELL_MS = 1500; // Time to hold fist to reset
// Game Constants
const ROWS = 3;
const COLS = 3;
type GameState = 'SCANNING' | 'PLAYING' | 'SOLVED' | 'LEADERBOARD';