Upload 190 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .agents/agent_assets_metadata.toml +8 -0
- .gitignore +49 -0
- .npmrc +2 -0
- .replit +32 -0
- .replitignore +5 -0
- artifacts/api-server/.replit-artifact/artifact.toml +32 -0
- artifacts/api-server/build.mjs +126 -0
- artifacts/api-server/package.json +34 -0
- artifacts/api-server/src/app.ts +34 -0
- artifacts/api-server/src/index.ts +30 -0
- artifacts/api-server/src/lib/.gitkeep +0 -0
- artifacts/api-server/src/lib/logger.ts +20 -0
- artifacts/api-server/src/middlewares/.gitkeep +0 -0
- artifacts/api-server/src/multiplayer/rooms.ts +541 -0
- artifacts/api-server/src/multiplayer/wsHandler.ts +142 -0
- artifacts/api-server/src/routes/health.ts +11 -0
- artifacts/api-server/src/routes/index.ts +8 -0
- artifacts/api-server/tsconfig.json +17 -0
- artifacts/eco-cleanup-game/.replit-artifact/artifact.toml +31 -0
- artifacts/eco-cleanup-game/components.json +20 -0
- artifacts/eco-cleanup-game/index.html +16 -0
- artifacts/eco-cleanup-game/package.json +81 -0
- artifacts/eco-cleanup-game/public/favicon.svg +3 -0
- artifacts/eco-cleanup-game/public/opengraph.jpg +0 -0
- artifacts/eco-cleanup-game/src/App.tsx +863 -0
- artifacts/eco-cleanup-game/src/components/ui/accordion.tsx +55 -0
- artifacts/eco-cleanup-game/src/components/ui/alert-dialog.tsx +139 -0
- artifacts/eco-cleanup-game/src/components/ui/alert.tsx +59 -0
- artifacts/eco-cleanup-game/src/components/ui/aspect-ratio.tsx +5 -0
- artifacts/eco-cleanup-game/src/components/ui/avatar.tsx +50 -0
- artifacts/eco-cleanup-game/src/components/ui/badge.tsx +43 -0
- artifacts/eco-cleanup-game/src/components/ui/breadcrumb.tsx +115 -0
- artifacts/eco-cleanup-game/src/components/ui/button-group.tsx +83 -0
- artifacts/eco-cleanup-game/src/components/ui/button.tsx +65 -0
- artifacts/eco-cleanup-game/src/components/ui/calendar.tsx +213 -0
- artifacts/eco-cleanup-game/src/components/ui/card.tsx +76 -0
- artifacts/eco-cleanup-game/src/components/ui/carousel.tsx +260 -0
- artifacts/eco-cleanup-game/src/components/ui/chart.tsx +367 -0
- artifacts/eco-cleanup-game/src/components/ui/checkbox.tsx +28 -0
- artifacts/eco-cleanup-game/src/components/ui/collapsible.tsx +11 -0
- artifacts/eco-cleanup-game/src/components/ui/command.tsx +153 -0
- artifacts/eco-cleanup-game/src/components/ui/context-menu.tsx +198 -0
- artifacts/eco-cleanup-game/src/components/ui/dialog.tsx +120 -0
- artifacts/eco-cleanup-game/src/components/ui/drawer.tsx +116 -0
- artifacts/eco-cleanup-game/src/components/ui/dropdown-menu.tsx +201 -0
- artifacts/eco-cleanup-game/src/components/ui/empty.tsx +104 -0
- artifacts/eco-cleanup-game/src/components/ui/field.tsx +244 -0
- artifacts/eco-cleanup-game/src/components/ui/form.tsx +176 -0
- artifacts/eco-cleanup-game/src/components/ui/hover-card.tsx +27 -0
- artifacts/eco-cleanup-game/src/components/ui/input-group.tsx +168 -0
.agents/agent_assets_metadata.toml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
uploads = []
|
| 2 |
+
generated = []
|
| 3 |
+
|
| 4 |
+
[[outputs]]
|
| 5 |
+
id = "w_y6GAxuQ-z03XgEUHxmH"
|
| 6 |
+
uri = "file://exports/ecoclean-3d.tar.gz"
|
| 7 |
+
type = "unspecified"
|
| 8 |
+
title = "EcoClean 3D — full source (with advanced features + owner panel)"
|
.gitignore
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# See https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files for more about ignoring files.
|
| 2 |
+
|
| 3 |
+
# compiled output
|
| 4 |
+
dist
|
| 5 |
+
tmp
|
| 6 |
+
out-tsc
|
| 7 |
+
*.tsbuildinfo
|
| 8 |
+
.expo
|
| 9 |
+
.expo-shared
|
| 10 |
+
|
| 11 |
+
# dependencies
|
| 12 |
+
node_modules
|
| 13 |
+
|
| 14 |
+
# IDEs and editors
|
| 15 |
+
/.idea
|
| 16 |
+
.project
|
| 17 |
+
.classpath
|
| 18 |
+
.c9/
|
| 19 |
+
*.launch
|
| 20 |
+
.settings/
|
| 21 |
+
*.sublime-workspace
|
| 22 |
+
|
| 23 |
+
# IDE - VSCode
|
| 24 |
+
.vscode/*
|
| 25 |
+
!.vscode/settings.json
|
| 26 |
+
!.vscode/tasks.json
|
| 27 |
+
!.vscode/launch.json
|
| 28 |
+
!.vscode/extensions.json
|
| 29 |
+
|
| 30 |
+
# misc
|
| 31 |
+
/.sass-cache
|
| 32 |
+
/connect.lock
|
| 33 |
+
/coverage
|
| 34 |
+
/libpeerconnection.log
|
| 35 |
+
npm-debug.log
|
| 36 |
+
yarn-error.log
|
| 37 |
+
testem.log
|
| 38 |
+
/typings
|
| 39 |
+
|
| 40 |
+
# System Files
|
| 41 |
+
.DS_Store
|
| 42 |
+
Thumbs.db
|
| 43 |
+
|
| 44 |
+
.cursor/rules/nx-rules.mdc
|
| 45 |
+
.github/instructions/nx.instructions.md
|
| 46 |
+
|
| 47 |
+
# Replit
|
| 48 |
+
.cache/
|
| 49 |
+
.local/
|
.npmrc
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
auto-install-peers=false
|
| 2 |
+
strict-peer-dependencies=false
|
.replit
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modules = ["nodejs-24"]
|
| 2 |
+
|
| 3 |
+
[deployment]
|
| 4 |
+
router = "application"
|
| 5 |
+
deploymentTarget = "autoscale"
|
| 6 |
+
|
| 7 |
+
[deployment.postBuild]
|
| 8 |
+
args = ["pnpm", "store", "prune"]
|
| 9 |
+
env = { "CI" = "true" }
|
| 10 |
+
|
| 11 |
+
[workflows]
|
| 12 |
+
runButton = "Project"
|
| 13 |
+
|
| 14 |
+
[agent]
|
| 15 |
+
stack = "PNPM_WORKSPACE"
|
| 16 |
+
expertMode = true
|
| 17 |
+
|
| 18 |
+
[postMerge]
|
| 19 |
+
path = "scripts/post-merge.sh"
|
| 20 |
+
timeoutMs = 20000
|
| 21 |
+
|
| 22 |
+
[[ports]]
|
| 23 |
+
localPort = 8080
|
| 24 |
+
externalPort = 8080
|
| 25 |
+
|
| 26 |
+
[[ports]]
|
| 27 |
+
localPort = 8081
|
| 28 |
+
externalPort = 80
|
| 29 |
+
|
| 30 |
+
[[ports]]
|
| 31 |
+
localPort = 18257
|
| 32 |
+
externalPort = 3000
|
.replitignore
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The format of this file is identical to `.dockerignore`.
|
| 2 |
+
# It is used to reduce the size of deployed images to make the process of publishing faster.
|
| 3 |
+
|
| 4 |
+
# No need to store the pnpm store twice.
|
| 5 |
+
.local
|
artifacts/api-server/.replit-artifact/artifact.toml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind = "api"
|
| 2 |
+
previewPath = "/api" # TODO - should be excluded from preview in the first place
|
| 3 |
+
title = "API Server"
|
| 4 |
+
version = "1.0.0"
|
| 5 |
+
id = "3B4_FFSkEVBkAeYMFRJ2e"
|
| 6 |
+
|
| 7 |
+
[[services]]
|
| 8 |
+
localPort = 8080
|
| 9 |
+
name = "API Server"
|
| 10 |
+
paths = ["/api"]
|
| 11 |
+
|
| 12 |
+
[services.development]
|
| 13 |
+
run = "pnpm --filter @workspace/api-server run dev"
|
| 14 |
+
|
| 15 |
+
[services.production]
|
| 16 |
+
|
| 17 |
+
[services.production.build]
|
| 18 |
+
args = ["pnpm", "--filter", "@workspace/api-server", "run", "build"]
|
| 19 |
+
|
| 20 |
+
[services.production.build.env]
|
| 21 |
+
NODE_ENV = "production"
|
| 22 |
+
|
| 23 |
+
[services.production.run]
|
| 24 |
+
# we don't run through pnpm to make startup faster in production
|
| 25 |
+
args = ["node", "--enable-source-maps", "artifacts/api-server/dist/index.mjs"]
|
| 26 |
+
|
| 27 |
+
[services.production.run.env]
|
| 28 |
+
PORT = "8080"
|
| 29 |
+
NODE_ENV = "production"
|
| 30 |
+
|
| 31 |
+
[services.production.health.startup]
|
| 32 |
+
path = "/api/healthz"
|
artifacts/api-server/build.mjs
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { createRequire } from "node:module";
|
| 2 |
+
import path from "node:path";
|
| 3 |
+
import { fileURLToPath } from "node:url";
|
| 4 |
+
import { build as esbuild } from "esbuild";
|
| 5 |
+
import esbuildPluginPino from "esbuild-plugin-pino";
|
| 6 |
+
import { rm } from "node:fs/promises";
|
| 7 |
+
|
| 8 |
+
// Plugins (e.g. 'esbuild-plugin-pino') may use `require` to resolve dependencies
|
| 9 |
+
globalThis.require = createRequire(import.meta.url);
|
| 10 |
+
|
| 11 |
+
const artifactDir = path.dirname(fileURLToPath(import.meta.url));
|
| 12 |
+
|
| 13 |
+
async function buildAll() {
|
| 14 |
+
const distDir = path.resolve(artifactDir, "dist");
|
| 15 |
+
await rm(distDir, { recursive: true, force: true });
|
| 16 |
+
|
| 17 |
+
await esbuild({
|
| 18 |
+
entryPoints: [path.resolve(artifactDir, "src/index.ts")],
|
| 19 |
+
platform: "node",
|
| 20 |
+
bundle: true,
|
| 21 |
+
format: "esm",
|
| 22 |
+
outdir: distDir,
|
| 23 |
+
outExtension: { ".js": ".mjs" },
|
| 24 |
+
logLevel: "info",
|
| 25 |
+
// Some packages may not be bundleable, so we externalize them, we can add more here as needed.
|
| 26 |
+
// Some of the packages below may not be imported or installed, but we're adding them in case they are in the future.
|
| 27 |
+
// Examples of unbundleable packages:
|
| 28 |
+
// - uses native modules and loads them dynamically (e.g. sharp)
|
| 29 |
+
// - use path traversal to read files (e.g. @google-cloud/secret-manager loads sibling .proto files)
|
| 30 |
+
external: [
|
| 31 |
+
"*.node",
|
| 32 |
+
"sharp",
|
| 33 |
+
"better-sqlite3",
|
| 34 |
+
"sqlite3",
|
| 35 |
+
"canvas",
|
| 36 |
+
"bcrypt",
|
| 37 |
+
"argon2",
|
| 38 |
+
"fsevents",
|
| 39 |
+
"re2",
|
| 40 |
+
"farmhash",
|
| 41 |
+
"xxhash-addon",
|
| 42 |
+
"bufferutil",
|
| 43 |
+
"utf-8-validate",
|
| 44 |
+
"ssh2",
|
| 45 |
+
"cpu-features",
|
| 46 |
+
"dtrace-provider",
|
| 47 |
+
"isolated-vm",
|
| 48 |
+
"lightningcss",
|
| 49 |
+
"pg-native",
|
| 50 |
+
"oracledb",
|
| 51 |
+
"mongodb-client-encryption",
|
| 52 |
+
"nodemailer",
|
| 53 |
+
"handlebars",
|
| 54 |
+
"knex",
|
| 55 |
+
"typeorm",
|
| 56 |
+
"protobufjs",
|
| 57 |
+
"onnxruntime-node",
|
| 58 |
+
"@tensorflow/*",
|
| 59 |
+
"@prisma/client",
|
| 60 |
+
"@mikro-orm/*",
|
| 61 |
+
"@grpc/*",
|
| 62 |
+
"@swc/*",
|
| 63 |
+
"@aws-sdk/*",
|
| 64 |
+
"@azure/*",
|
| 65 |
+
"@opentelemetry/*",
|
| 66 |
+
"@google-cloud/*",
|
| 67 |
+
"@google/*",
|
| 68 |
+
"googleapis",
|
| 69 |
+
"firebase-admin",
|
| 70 |
+
"@parcel/watcher",
|
| 71 |
+
"@sentry/profiling-node",
|
| 72 |
+
"@tree-sitter/*",
|
| 73 |
+
"aws-sdk",
|
| 74 |
+
"classic-level",
|
| 75 |
+
"dd-trace",
|
| 76 |
+
"ffi-napi",
|
| 77 |
+
"grpc",
|
| 78 |
+
"hiredis",
|
| 79 |
+
"kerberos",
|
| 80 |
+
"leveldown",
|
| 81 |
+
"miniflare",
|
| 82 |
+
"mysql2",
|
| 83 |
+
"newrelic",
|
| 84 |
+
"odbc",
|
| 85 |
+
"piscina",
|
| 86 |
+
"realm",
|
| 87 |
+
"ref-napi",
|
| 88 |
+
"rocksdb",
|
| 89 |
+
"sass-embedded",
|
| 90 |
+
"sequelize",
|
| 91 |
+
"serialport",
|
| 92 |
+
"snappy",
|
| 93 |
+
"tinypool",
|
| 94 |
+
"usb",
|
| 95 |
+
"workerd",
|
| 96 |
+
"wrangler",
|
| 97 |
+
"zeromq",
|
| 98 |
+
"zeromq-prebuilt",
|
| 99 |
+
"playwright",
|
| 100 |
+
"puppeteer",
|
| 101 |
+
"puppeteer-core",
|
| 102 |
+
"electron",
|
| 103 |
+
],
|
| 104 |
+
sourcemap: "linked",
|
| 105 |
+
plugins: [
|
| 106 |
+
// pino relies on workers to handle logging, instead of externalizing it we use a plugin to handle it
|
| 107 |
+
esbuildPluginPino({ transports: ["pino-pretty"] })
|
| 108 |
+
],
|
| 109 |
+
// Make sure packages that are cjs only (e.g. express) but are bundled continue to work in our esm output file
|
| 110 |
+
banner: {
|
| 111 |
+
js: `import { createRequire as __bannerCrReq } from 'node:module';
|
| 112 |
+
import __bannerPath from 'node:path';
|
| 113 |
+
import __bannerUrl from 'node:url';
|
| 114 |
+
|
| 115 |
+
globalThis.require = __bannerCrReq(import.meta.url);
|
| 116 |
+
globalThis.__filename = __bannerUrl.fileURLToPath(import.meta.url);
|
| 117 |
+
globalThis.__dirname = __bannerPath.dirname(globalThis.__filename);
|
| 118 |
+
`,
|
| 119 |
+
},
|
| 120 |
+
});
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
buildAll().catch((err) => {
|
| 124 |
+
console.error(err);
|
| 125 |
+
process.exit(1);
|
| 126 |
+
});
|
artifacts/api-server/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@workspace/api-server",
|
| 3 |
+
"version": "0.0.0",
|
| 4 |
+
"private": true,
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "export NODE_ENV=development && pnpm run build && pnpm run start",
|
| 8 |
+
"build": "node ./build.mjs",
|
| 9 |
+
"start": "node --enable-source-maps ./dist/index.mjs",
|
| 10 |
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
| 11 |
+
},
|
| 12 |
+
"dependencies": {
|
| 13 |
+
"@workspace/api-zod": "workspace:*",
|
| 14 |
+
"@workspace/db": "workspace:*",
|
| 15 |
+
"cookie-parser": "^1.4.7",
|
| 16 |
+
"cors": "^2",
|
| 17 |
+
"drizzle-orm": "catalog:",
|
| 18 |
+
"express": "^5",
|
| 19 |
+
"pino": "^9",
|
| 20 |
+
"pino-http": "^10",
|
| 21 |
+
"ws": "^8.20.0"
|
| 22 |
+
},
|
| 23 |
+
"devDependencies": {
|
| 24 |
+
"@types/cookie-parser": "^1.4.10",
|
| 25 |
+
"@types/cors": "^2.8.19",
|
| 26 |
+
"@types/express": "^5.0.6",
|
| 27 |
+
"@types/node": "catalog:",
|
| 28 |
+
"@types/ws": "^8.18.1",
|
| 29 |
+
"esbuild": "^0.27.3",
|
| 30 |
+
"esbuild-plugin-pino": "^2.3.3",
|
| 31 |
+
"pino-pretty": "^13",
|
| 32 |
+
"thread-stream": "3.1.0"
|
| 33 |
+
}
|
| 34 |
+
}
|
artifacts/api-server/src/app.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express, { type Express } from "express";
|
| 2 |
+
import cors from "cors";
|
| 3 |
+
import pinoHttp from "pino-http";
|
| 4 |
+
import router from "./routes";
|
| 5 |
+
import { logger } from "./lib/logger";
|
| 6 |
+
|
| 7 |
+
const app: Express = express();
|
| 8 |
+
|
| 9 |
+
app.use(
|
| 10 |
+
pinoHttp({
|
| 11 |
+
logger,
|
| 12 |
+
serializers: {
|
| 13 |
+
req(req) {
|
| 14 |
+
return {
|
| 15 |
+
id: req.id,
|
| 16 |
+
method: req.method,
|
| 17 |
+
url: req.url?.split("?")[0],
|
| 18 |
+
};
|
| 19 |
+
},
|
| 20 |
+
res(res) {
|
| 21 |
+
return {
|
| 22 |
+
statusCode: res.statusCode,
|
| 23 |
+
};
|
| 24 |
+
},
|
| 25 |
+
},
|
| 26 |
+
}),
|
| 27 |
+
);
|
| 28 |
+
app.use(cors());
|
| 29 |
+
app.use(express.json());
|
| 30 |
+
app.use(express.urlencoded({ extended: true }));
|
| 31 |
+
|
| 32 |
+
app.use("/api", router);
|
| 33 |
+
|
| 34 |
+
export default app;
|
artifacts/api-server/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { createServer } from "http";
|
| 2 |
+
import app from "./app";
|
| 3 |
+
import { logger } from "./lib/logger";
|
| 4 |
+
import { attachMultiplayer } from "./multiplayer/wsHandler.js";
|
| 5 |
+
|
| 6 |
+
const rawPort = process.env["PORT"];
|
| 7 |
+
|
| 8 |
+
if (!rawPort) {
|
| 9 |
+
throw new Error(
|
| 10 |
+
"PORT environment variable is required but was not provided.",
|
| 11 |
+
);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
const port = Number(rawPort);
|
| 15 |
+
|
| 16 |
+
if (Number.isNaN(port) || port <= 0) {
|
| 17 |
+
throw new Error(`Invalid PORT value: "${rawPort}"`);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
const server = createServer(app);
|
| 21 |
+
attachMultiplayer(server);
|
| 22 |
+
|
| 23 |
+
server.listen(port, () => {
|
| 24 |
+
logger.info({ port }, "Server listening (HTTP + WebSocket)");
|
| 25 |
+
});
|
| 26 |
+
|
| 27 |
+
server.on("error", (err) => {
|
| 28 |
+
logger.error({ err }, "Server error");
|
| 29 |
+
process.exit(1);
|
| 30 |
+
});
|
artifacts/api-server/src/lib/.gitkeep
ADDED
|
File without changes
|
artifacts/api-server/src/lib/logger.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pino from "pino";
|
| 2 |
+
|
| 3 |
+
const isProduction = process.env.NODE_ENV === "production";
|
| 4 |
+
|
| 5 |
+
export const logger = pino({
|
| 6 |
+
level: process.env.LOG_LEVEL ?? "info",
|
| 7 |
+
redact: [
|
| 8 |
+
"req.headers.authorization",
|
| 9 |
+
"req.headers.cookie",
|
| 10 |
+
"res.headers['set-cookie']",
|
| 11 |
+
],
|
| 12 |
+
...(isProduction
|
| 13 |
+
? {}
|
| 14 |
+
: {
|
| 15 |
+
transport: {
|
| 16 |
+
target: "pino-pretty",
|
| 17 |
+
options: { colorize: true },
|
| 18 |
+
},
|
| 19 |
+
}),
|
| 20 |
+
});
|
artifacts/api-server/src/middlewares/.gitkeep
ADDED
|
File without changes
|
artifacts/api-server/src/multiplayer/rooms.ts
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Multiplayer game rooms for EcoClean 3D — v2 with game modes + new levels.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
import type { WebSocket } from "ws";
|
| 6 |
+
import { logger } from "../lib/logger.js";
|
| 7 |
+
|
| 8 |
+
export type Level = "park" | "beach" | "city" | "nightcity" | "arctic" | "jungle";
|
| 9 |
+
export type TrashType = "plastic" | "metal" | "organic" | "paper";
|
| 10 |
+
export type Difficulty = "easy" | "normal" | "hard";
|
| 11 |
+
export type PowerUpKind = "magnet" | "speed" | "bonus";
|
| 12 |
+
export type GameMode = "speedrun" | "percent100" | "powerup";
|
| 13 |
+
|
| 14 |
+
export const WORLD_HALF = 28;
|
| 15 |
+
export const COLLECT_RADIUS_SQ = 4.5;
|
| 16 |
+
export const POSITION_BROADCAST_HZ = 12;
|
| 17 |
+
export const END_HOLD_SEC = 8;
|
| 18 |
+
export const BASE_TRASH_POINTS = 10;
|
| 19 |
+
export const COMBO_WINDOW_MS = 4000;
|
| 20 |
+
export const COMBO_MAX = 5;
|
| 21 |
+
export const EMOTE_COOLDOWN_MS = 1500;
|
| 22 |
+
export const POWERUP_LIFETIME_SEC = 25;
|
| 23 |
+
export const POWERUP_EFFECT_SEC = 8;
|
| 24 |
+
export const POWERUP_BONUS_POINTS = 50;
|
| 25 |
+
export const POWERUP_PICKUP_RADIUS_SQ = 4;
|
| 26 |
+
|
| 27 |
+
export const DIFFICULTY_CONFIG: Record<
|
| 28 |
+
Difficulty,
|
| 29 |
+
{ roundDuration: number; trashCount: number; winThreshold: number; label: string }
|
| 30 |
+
> = {
|
| 31 |
+
easy: { roundDuration: 180, trashCount: 24, winThreshold: 0.6, label: "Easy" },
|
| 32 |
+
normal: { roundDuration: 120, trashCount: 32, winThreshold: 0.8, label: "Normal" },
|
| 33 |
+
hard: { roundDuration: 90, trashCount: 44, winThreshold: 0.9, label: "Hard" },
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
/** Per-mode overrides applied on top of difficulty settings. */
|
| 37 |
+
export const MODE_CONFIG: Record<GameMode, {
|
| 38 |
+
winThresholdOverride: number | null;
|
| 39 |
+
roundDurationScale: number;
|
| 40 |
+
trashCountScale: number;
|
| 41 |
+
powerUpSpawnIntervalSec: number;
|
| 42 |
+
maxActivePowerUps: number;
|
| 43 |
+
label: string;
|
| 44 |
+
}> = {
|
| 45 |
+
speedrun: {
|
| 46 |
+
winThresholdOverride: null, // uses difficulty threshold
|
| 47 |
+
roundDurationScale: 0.7, // 70% of normal time = hectic
|
| 48 |
+
trashCountScale: 1.3,
|
| 49 |
+
powerUpSpawnIntervalSec: 22,
|
| 50 |
+
maxActivePowerUps: 3,
|
| 51 |
+
label: "Speedrun",
|
| 52 |
+
},
|
| 53 |
+
percent100: {
|
| 54 |
+
winThresholdOverride: 1.0, // must collect EVERYTHING
|
| 55 |
+
roundDurationScale: 2.0, // generous time
|
| 56 |
+
trashCountScale: 0.8,
|
| 57 |
+
powerUpSpawnIntervalSec: 18,
|
| 58 |
+
maxActivePowerUps: 4,
|
| 59 |
+
label: "100% Clean",
|
| 60 |
+
},
|
| 61 |
+
powerup: {
|
| 62 |
+
winThresholdOverride: null,
|
| 63 |
+
roundDurationScale: 1.0,
|
| 64 |
+
trashCountScale: 1.0,
|
| 65 |
+
powerUpSpawnIntervalSec: 6, // power-ups rain down
|
| 66 |
+
maxActivePowerUps: 8,
|
| 67 |
+
label: "Power-Up Party",
|
| 68 |
+
},
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
export const VALID_LEVELS: Level[] = ["park", "beach", "city", "nightcity", "arctic", "jungle"];
|
| 72 |
+
export const VALID_DIFFICULTIES: Difficulty[] = ["easy", "normal", "hard"];
|
| 73 |
+
export const VALID_GAME_MODES: GameMode[] = ["speedrun", "percent100", "powerup"];
|
| 74 |
+
|
| 75 |
+
export const OWNER_PASSWORD = "Slayers";
|
| 76 |
+
|
| 77 |
+
/** Public room code from level + mode. */
|
| 78 |
+
export function publicCode(level: Level, mode: GameMode): string {
|
| 79 |
+
const lv: Record<Level, string> = {
|
| 80 |
+
park: "PK", beach: "BC", city: "CT", nightcity: "NK", arctic: "AC", jungle: "JG",
|
| 81 |
+
};
|
| 82 |
+
const md: Record<GameMode, string> = { speedrun: "SR", percent100: "PC", powerup: "PU" };
|
| 83 |
+
return `${lv[level]}-${md[mode]}`;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
const RESERVED = new Set<string>(
|
| 87 |
+
VALID_LEVELS.flatMap(l => VALID_GAME_MODES.map(m => publicCode(l, m)))
|
| 88 |
+
);
|
| 89 |
+
|
| 90 |
+
function generateCode(): string {
|
| 91 |
+
const alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
| 92 |
+
let s = "";
|
| 93 |
+
for (let i = 0; i < 4; i++) s += alphabet[Math.floor(Math.random() * alphabet.length)];
|
| 94 |
+
return s;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
export type EmoteKind = "wave" | "thumbsup" | "recycle" | "smile" | "cheer";
|
| 98 |
+
const VALID_EMOTES: EmoteKind[] = ["wave", "thumbsup", "recycle", "smile", "cheer"];
|
| 99 |
+
|
| 100 |
+
export type ClientToServer =
|
| 101 |
+
| { type: "join"; level: Level; name: string; color: string }
|
| 102 |
+
| { type: "move"; x: number; z: number; rot: number }
|
| 103 |
+
| { type: "collect"; trashId: string }
|
| 104 |
+
| { type: "collectPowerUp"; powerUpId: string }
|
| 105 |
+
| { type: "emote"; kind: EmoteKind }
|
| 106 |
+
| { type: "ping"; t: number }
|
| 107 |
+
| { type: "admin.endRound"; password: string; result: "won" | "lost" }
|
| 108 |
+
| { type: "admin.spawnTrash"; password: string; count: number }
|
| 109 |
+
| { type: "admin.spawnPowerUp"; password: string; kind: PowerUpKind }
|
| 110 |
+
| { type: "admin.kick"; password: string; playerId: string }
|
| 111 |
+
| { type: "admin.setTimer"; password: string; seconds: number }
|
| 112 |
+
| { type: "admin.identify"; password: string };
|
| 113 |
+
|
| 114 |
+
export type ServerToClient =
|
| 115 |
+
| {
|
| 116 |
+
type: "init";
|
| 117 |
+
selfId: string;
|
| 118 |
+
level: Level;
|
| 119 |
+
difficulty: Difficulty;
|
| 120 |
+
gameMode: GameMode;
|
| 121 |
+
code: string;
|
| 122 |
+
isPublic: boolean;
|
| 123 |
+
roundId: number;
|
| 124 |
+
timeLeft: number;
|
| 125 |
+
roundDuration: number;
|
| 126 |
+
winThreshold: number;
|
| 127 |
+
status: "playing" | "ended";
|
| 128 |
+
players: SerializedPlayer[];
|
| 129 |
+
trash: SerializedTrash[];
|
| 130 |
+
powerUps: SerializedPowerUp[];
|
| 131 |
+
mvpId: string | null;
|
| 132 |
+
}
|
| 133 |
+
| { type: "playerJoined"; player: SerializedPlayer }
|
| 134 |
+
| { type: "playerLeft"; id: string }
|
| 135 |
+
| { type: "positions"; players: { id: string; x: number; z: number; rot: number }[] }
|
| 136 |
+
| {
|
| 137 |
+
type: "trashCollected";
|
| 138 |
+
trashId: string; trashType: TrashType; byId: string; byName: string;
|
| 139 |
+
score: number; pointsGained: number; combo: number; comboExpiresInMs: number; totalCollected: number;
|
| 140 |
+
}
|
| 141 |
+
| { type: "powerUpSpawned"; powerUp: SerializedPowerUp }
|
| 142 |
+
| {
|
| 143 |
+
type: "powerUpCollected";
|
| 144 |
+
powerUpId: string; kind: PowerUpKind; byId: string; byName: string;
|
| 145 |
+
score: number; effectMs: number; bonusPoints: number;
|
| 146 |
+
}
|
| 147 |
+
| { type: "powerUpExpired"; powerUpId: string }
|
| 148 |
+
| {
|
| 149 |
+
type: "roundEnd";
|
| 150 |
+
result: "won" | "lost"; cleanedPct: number;
|
| 151 |
+
scores: { id: string; name: string; color: string; score: number }[];
|
| 152 |
+
mvpId: string | null; restartIn: number;
|
| 153 |
+
}
|
| 154 |
+
| {
|
| 155 |
+
type: "roundStart";
|
| 156 |
+
roundId: number; trash: SerializedTrash[]; powerUps: SerializedPowerUp[];
|
| 157 |
+
timeLeft: number; roundDuration: number; mvpId: string | null; gameMode: GameMode;
|
| 158 |
+
}
|
| 159 |
+
| { type: "emote"; playerId: string; kind: EmoteKind }
|
| 160 |
+
| { type: "kicked"; reason: string }
|
| 161 |
+
| { type: "adminAck"; ok: boolean; message: string }
|
| 162 |
+
| { type: "pong"; t: number }
|
| 163 |
+
| { type: "error"; message: string };
|
| 164 |
+
|
| 165 |
+
interface Player {
|
| 166 |
+
id: string; name: string; color: string;
|
| 167 |
+
x: number; z: number; rot: number;
|
| 168 |
+
score: number; combo: number; lastCollectAt: number; lastEmoteAt: number;
|
| 169 |
+
socket: WebSocket; alive: boolean;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
interface TrashItem {
|
| 173 |
+
id: string; type: TrashType; x: number; z: number; collected: boolean;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
interface PowerUp {
|
| 177 |
+
id: string; kind: PowerUpKind; x: number; z: number; expiresAt: number; collected: boolean;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
interface SerializedPlayer {
|
| 181 |
+
id: string; name: string; color: string; x: number; z: number; rot: number; score: number;
|
| 182 |
+
}
|
| 183 |
+
interface SerializedTrash { id: string; type: TrashType; x: number; z: number; }
|
| 184 |
+
interface SerializedPowerUp { id: string; kind: PowerUpKind; x: number; z: number; }
|
| 185 |
+
|
| 186 |
+
const PLAYER_COLORS = [
|
| 187 |
+
"#ff7043","#42a5f5","#ab47bc","#ffca28","#26a69a",
|
| 188 |
+
"#ec407a","#7e57c2","#5c6bc0","#66bb6a","#8d6e63",
|
| 189 |
+
];
|
| 190 |
+
|
| 191 |
+
function pickTrashType(level: Level): TrashType {
|
| 192 |
+
const r = Math.random();
|
| 193 |
+
if (level === "beach") {
|
| 194 |
+
if (r < 0.55) return "plastic"; if (r < 0.75) return "metal"; if (r < 0.9) return "paper"; return "organic";
|
| 195 |
+
}
|
| 196 |
+
if (level === "city" || level === "nightcity") {
|
| 197 |
+
if (r < 0.4) return "plastic"; if (r < 0.65) return "paper"; if (r < 0.85) return "metal"; return "organic";
|
| 198 |
+
}
|
| 199 |
+
if (level === "arctic") {
|
| 200 |
+
if (r < 0.5) return "plastic"; if (r < 0.75) return "metal"; if (r < 0.9) return "paper"; return "organic";
|
| 201 |
+
}
|
| 202 |
+
if (level === "jungle") {
|
| 203 |
+
if (r < 0.5) return "organic"; if (r < 0.75) return "plastic"; if (r < 0.9) return "paper"; return "metal";
|
| 204 |
+
}
|
| 205 |
+
// park
|
| 206 |
+
if (r < 0.4) return "plastic"; if (r < 0.6) return "organic"; if (r < 0.8) return "paper"; return "metal";
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
function randomTrashPos(): { x: number; z: number } {
|
| 210 |
+
for (let a = 0; a < 10; a++) {
|
| 211 |
+
const x = (Math.random() * 2 - 1) * WORLD_HALF;
|
| 212 |
+
const z = (Math.random() * 2 - 1) * WORLD_HALF;
|
| 213 |
+
if (Math.abs(x) > 2 || Math.abs(z) > 2) return { x, z };
|
| 214 |
+
}
|
| 215 |
+
return { x: WORLD_HALF * Math.random(), z: WORLD_HALF * Math.random() };
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
function generateTrash(level: Level, count: number): TrashItem[] {
|
| 219 |
+
const items: TrashItem[] = [];
|
| 220 |
+
for (let i = 0; i < count; i++) {
|
| 221 |
+
const { x, z } = randomTrashPos();
|
| 222 |
+
items.push({
|
| 223 |
+
id: `t-${Date.now().toString(36)}-${i}-${Math.random().toString(36).slice(2,6)}`,
|
| 224 |
+
type: pickTrashType(level), x, z, collected: false,
|
| 225 |
+
});
|
| 226 |
+
}
|
| 227 |
+
return items;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
const POWERUP_KINDS: PowerUpKind[] = ["magnet", "speed", "bonus"];
|
| 231 |
+
function pickPowerUpKind(): PowerUpKind { return POWERUP_KINDS[Math.floor(Math.random() * POWERUP_KINDS.length)]; }
|
| 232 |
+
let nextPowerUpSeq = 0;
|
| 233 |
+
function makePowerUp(kind?: PowerUpKind, lifetimeSec = POWERUP_LIFETIME_SEC): PowerUp {
|
| 234 |
+
const { x, z } = randomTrashPos();
|
| 235 |
+
return {
|
| 236 |
+
id: `pu-${Date.now().toString(36)}-${nextPowerUpSeq++}`,
|
| 237 |
+
kind: kind ?? pickPowerUpKind(), x, z,
|
| 238 |
+
expiresAt: Date.now() + lifetimeSec * 1000, collected: false,
|
| 239 |
+
};
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
function serializePlayer(p: Player): SerializedPlayer {
|
| 243 |
+
return { id: p.id, name: p.name, color: p.color, x: p.x, z: p.z, rot: p.rot, score: p.score };
|
| 244 |
+
}
|
| 245 |
+
function serializeTrash(t: TrashItem): SerializedTrash { return { id: t.id, type: t.type, x: t.x, z: t.z }; }
|
| 246 |
+
function serializePowerUp(p: PowerUp): SerializedPowerUp { return { id: p.id, kind: p.kind, x: p.x, z: p.z }; }
|
| 247 |
+
|
| 248 |
+
function send(socket: WebSocket, msg: ServerToClient) {
|
| 249 |
+
if (socket.readyState === socket.OPEN) socket.send(JSON.stringify(msg));
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
class Room {
|
| 253 |
+
level: Level;
|
| 254 |
+
difficulty: Difficulty;
|
| 255 |
+
gameMode: GameMode;
|
| 256 |
+
code: string;
|
| 257 |
+
isPublic: boolean;
|
| 258 |
+
players = new Map<string, Player>();
|
| 259 |
+
trash: TrashItem[] = [];
|
| 260 |
+
powerUps: PowerUp[] = [];
|
| 261 |
+
status: "playing" | "ended" = "playing";
|
| 262 |
+
result: "won" | "lost" | null = null;
|
| 263 |
+
timeLeft: number;
|
| 264 |
+
roundDuration: number;
|
| 265 |
+
trashCount: number;
|
| 266 |
+
winThreshold: number;
|
| 267 |
+
powerUpSpawnIntervalSec: number;
|
| 268 |
+
maxActivePowerUps: number;
|
| 269 |
+
roundId = 1;
|
| 270 |
+
endHold = 0;
|
| 271 |
+
usedColors = new Set<string>();
|
| 272 |
+
mvpId: string | null = null;
|
| 273 |
+
nextPowerUpAt: number;
|
| 274 |
+
|
| 275 |
+
constructor(level: Level, code: string, isPublic: boolean, difficulty: Difficulty, gameMode: GameMode = "speedrun") {
|
| 276 |
+
this.level = level;
|
| 277 |
+
this.code = code;
|
| 278 |
+
this.isPublic = isPublic;
|
| 279 |
+
this.difficulty = difficulty;
|
| 280 |
+
this.gameMode = gameMode;
|
| 281 |
+
const dc = DIFFICULTY_CONFIG[difficulty];
|
| 282 |
+
const mc = MODE_CONFIG[gameMode];
|
| 283 |
+
this.roundDuration = Math.round(dc.roundDuration * mc.roundDurationScale);
|
| 284 |
+
this.trashCount = Math.max(8, Math.round(dc.trashCount * mc.trashCountScale));
|
| 285 |
+
this.winThreshold = mc.winThresholdOverride ?? dc.winThreshold;
|
| 286 |
+
this.powerUpSpawnIntervalSec = mc.powerUpSpawnIntervalSec;
|
| 287 |
+
this.maxActivePowerUps = mc.maxActivePowerUps;
|
| 288 |
+
this.timeLeft = this.roundDuration;
|
| 289 |
+
this.trash = generateTrash(level, this.trashCount);
|
| 290 |
+
this.nextPowerUpAt = Date.now() + 8000;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
pickColor(): string {
|
| 294 |
+
for (const c of PLAYER_COLORS) if (!this.usedColors.has(c)) { this.usedColors.add(c); return c; }
|
| 295 |
+
return `hsl(${Math.floor(Math.random() * 360)}, 65%, 55%)`;
|
| 296 |
+
}
|
| 297 |
+
freeColor(c: string) { this.usedColors.delete(c); }
|
| 298 |
+
|
| 299 |
+
broadcast(msg: ServerToClient, exceptId?: string) {
|
| 300 |
+
for (const p of this.players.values()) {
|
| 301 |
+
if (p.id === exceptId) continue;
|
| 302 |
+
send(p.socket, msg);
|
| 303 |
+
}
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
addPlayer(player: Player) {
|
| 307 |
+
this.players.set(player.id, player);
|
| 308 |
+
send(player.socket, {
|
| 309 |
+
type: "init",
|
| 310 |
+
selfId: player.id, level: this.level, difficulty: this.difficulty, gameMode: this.gameMode,
|
| 311 |
+
code: this.code, isPublic: this.isPublic, roundId: this.roundId,
|
| 312 |
+
timeLeft: Math.ceil(this.timeLeft), roundDuration: this.roundDuration,
|
| 313 |
+
winThreshold: this.winThreshold, status: this.status,
|
| 314 |
+
players: Array.from(this.players.values()).map(serializePlayer),
|
| 315 |
+
trash: this.trash.filter(t => !t.collected).map(serializeTrash),
|
| 316 |
+
powerUps: this.powerUps.filter(p => !p.collected).map(serializePowerUp),
|
| 317 |
+
mvpId: this.mvpId,
|
| 318 |
+
});
|
| 319 |
+
this.broadcast({ type: "playerJoined", player: serializePlayer(player) }, player.id);
|
| 320 |
+
logger.info({ level: this.level, difficulty: this.difficulty, gameMode: this.gameMode, playerId: player.id, total: this.players.size }, "Player joined room");
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
removePlayer(id: string) {
|
| 324 |
+
const p = this.players.get(id); if (!p) return;
|
| 325 |
+
this.players.delete(id); this.freeColor(p.color);
|
| 326 |
+
this.broadcast({ type: "playerLeft", id });
|
| 327 |
+
logger.info({ level: this.level, playerId: id, total: this.players.size }, "Player left room");
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
handleMove(id: string, x: number, z: number, rot: number) {
|
| 331 |
+
const p = this.players.get(id); if (!p) return;
|
| 332 |
+
p.x = Math.max(-WORLD_HALF, Math.min(WORLD_HALF, x));
|
| 333 |
+
p.z = Math.max(-WORLD_HALF, Math.min(WORLD_HALF, z));
|
| 334 |
+
p.rot = rot;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
handleCollect(id: string, trashId: string) {
|
| 338 |
+
if (this.status !== "playing") return;
|
| 339 |
+
const p = this.players.get(id); if (!p) return;
|
| 340 |
+
const item = this.trash.find(t => t.id === trashId);
|
| 341 |
+
if (!item || item.collected) return;
|
| 342 |
+
const dx = item.x - p.x; const dz = item.z - p.z;
|
| 343 |
+
if (dx * dx + dz * dz > COLLECT_RADIUS_SQ * 4) return;
|
| 344 |
+
item.collected = true;
|
| 345 |
+
const now = Date.now();
|
| 346 |
+
p.combo = (now - p.lastCollectAt <= COMBO_WINDOW_MS) ? Math.min(COMBO_MAX, p.combo + 1) : 1;
|
| 347 |
+
p.lastCollectAt = now;
|
| 348 |
+
const pointsGained = BASE_TRASH_POINTS * p.combo;
|
| 349 |
+
p.score += pointsGained;
|
| 350 |
+
const totalCollected = this.trash.filter(t => t.collected).length;
|
| 351 |
+
this.broadcast({
|
| 352 |
+
type: "trashCollected", trashId, trashType: item.type, byId: id, byName: p.name,
|
| 353 |
+
score: p.score, pointsGained, combo: p.combo, comboExpiresInMs: COMBO_WINDOW_MS, totalCollected,
|
| 354 |
+
});
|
| 355 |
+
if (totalCollected / this.trash.length >= this.winThreshold) this.endRound("won");
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
handleCollectPowerUp(id: string, powerUpId: string) {
|
| 359 |
+
if (this.status !== "playing") return;
|
| 360 |
+
const p = this.players.get(id); if (!p) return;
|
| 361 |
+
const pu = this.powerUps.find(x => x.id === powerUpId);
|
| 362 |
+
if (!pu || pu.collected) return;
|
| 363 |
+
const dx = pu.x - p.x; const dz = pu.z - p.z;
|
| 364 |
+
if (dx * dx + dz * dz > POWERUP_PICKUP_RADIUS_SQ * 4) return;
|
| 365 |
+
pu.collected = true;
|
| 366 |
+
let bonusPoints = 0;
|
| 367 |
+
if (pu.kind === "bonus") { bonusPoints = POWERUP_BONUS_POINTS; p.score += bonusPoints; }
|
| 368 |
+
this.broadcast({
|
| 369 |
+
type: "powerUpCollected", powerUpId, kind: pu.kind, byId: id, byName: p.name,
|
| 370 |
+
score: p.score, effectMs: pu.kind === "bonus" ? 0 : POWERUP_EFFECT_SEC * 1000, bonusPoints,
|
| 371 |
+
});
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
handleEmote(id: string, kind: EmoteKind) {
|
| 375 |
+
const p = this.players.get(id); if (!p) return;
|
| 376 |
+
if (!VALID_EMOTES.includes(kind)) return;
|
| 377 |
+
const now = Date.now();
|
| 378 |
+
if (now - p.lastEmoteAt < EMOTE_COOLDOWN_MS) return;
|
| 379 |
+
p.lastEmoteAt = now;
|
| 380 |
+
this.broadcast({ type: "emote", playerId: id, kind });
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
endRound(result: "won" | "lost") {
|
| 384 |
+
if (this.status === "ended") return;
|
| 385 |
+
this.status = "ended"; this.result = result; this.endHold = END_HOLD_SEC;
|
| 386 |
+
const cleaned = this.trash.filter(t => t.collected).length;
|
| 387 |
+
const cleanedPct = Math.round((cleaned / this.trash.length) * 100);
|
| 388 |
+
const scores = Array.from(this.players.values())
|
| 389 |
+
.map(p => ({ id: p.id, name: p.name, color: p.color, score: p.score }))
|
| 390 |
+
.sort((a, b) => b.score - a.score);
|
| 391 |
+
this.mvpId = scores[0] && scores[0].score > 0 ? scores[0].id : null;
|
| 392 |
+
this.broadcast({ type: "roundEnd", result, cleanedPct, scores, mvpId: this.mvpId, restartIn: END_HOLD_SEC });
|
| 393 |
+
logger.info({ level: this.level, gameMode: this.gameMode, result, cleanedPct, mvpId: this.mvpId }, "Round ended");
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
startNewRound() {
|
| 397 |
+
this.roundId += 1; this.status = "playing"; this.result = null;
|
| 398 |
+
this.timeLeft = this.roundDuration;
|
| 399 |
+
this.trash = generateTrash(this.level, this.trashCount);
|
| 400 |
+
this.powerUps = []; this.nextPowerUpAt = Date.now() + 8000;
|
| 401 |
+
for (const p of this.players.values()) { p.score = 0; p.combo = 0; p.lastCollectAt = 0; }
|
| 402 |
+
this.broadcast({
|
| 403 |
+
type: "roundStart", roundId: this.roundId,
|
| 404 |
+
trash: this.trash.map(serializeTrash), powerUps: [],
|
| 405 |
+
timeLeft: this.timeLeft, roundDuration: this.roundDuration,
|
| 406 |
+
mvpId: this.mvpId, gameMode: this.gameMode,
|
| 407 |
+
});
|
| 408 |
+
logger.info({ level: this.level, difficulty: this.difficulty, gameMode: this.gameMode, roundId: this.roundId }, "Round started");
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
tickPowerUps() {
|
| 412 |
+
if (this.status !== "playing") return;
|
| 413 |
+
const now = Date.now();
|
| 414 |
+
for (const pu of this.powerUps) {
|
| 415 |
+
if (!pu.collected && now > pu.expiresAt) {
|
| 416 |
+
pu.collected = true;
|
| 417 |
+
this.broadcast({ type: "powerUpExpired", powerUpId: pu.id });
|
| 418 |
+
}
|
| 419 |
+
}
|
| 420 |
+
this.powerUps = this.powerUps.filter(pu => !pu.collected);
|
| 421 |
+
if (this.players.size > 0 && now >= this.nextPowerUpAt && this.powerUps.length < this.maxActivePowerUps) {
|
| 422 |
+
const pu = makePowerUp();
|
| 423 |
+
this.powerUps.push(pu);
|
| 424 |
+
this.broadcast({ type: "powerUpSpawned", powerUp: serializePowerUp(pu) });
|
| 425 |
+
this.nextPowerUpAt = now + this.powerUpSpawnIntervalSec * 1000;
|
| 426 |
+
}
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
tick(dt: number) {
|
| 430 |
+
if (this.status === "playing") {
|
| 431 |
+
this.timeLeft -= dt;
|
| 432 |
+
if (this.timeLeft <= 0) { this.timeLeft = 0; this.endRound("lost"); }
|
| 433 |
+
this.tickPowerUps();
|
| 434 |
+
} else {
|
| 435 |
+
this.endHold -= dt;
|
| 436 |
+
if (this.endHold <= 0) this.startNewRound();
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
adminEndRound(result: "won" | "lost") { if (this.status !== "playing") return; this.endRound(result); }
|
| 441 |
+
|
| 442 |
+
adminSpawnTrash(count: number) {
|
| 443 |
+
const safeCount = Math.max(1, Math.min(50, Math.floor(count)));
|
| 444 |
+
const newItems = generateTrash(this.level, safeCount);
|
| 445 |
+
this.trash.push(...newItems);
|
| 446 |
+
this.trashCount = this.trash.length;
|
| 447 |
+
for (const player of this.players.values()) {
|
| 448 |
+
send(player.socket, {
|
| 449 |
+
type: "init", selfId: player.id, level: this.level, difficulty: this.difficulty, gameMode: this.gameMode,
|
| 450 |
+
code: this.code, isPublic: this.isPublic, roundId: this.roundId,
|
| 451 |
+
timeLeft: Math.ceil(this.timeLeft), roundDuration: this.roundDuration,
|
| 452 |
+
winThreshold: this.winThreshold, status: this.status,
|
| 453 |
+
players: Array.from(this.players.values()).map(serializePlayer),
|
| 454 |
+
trash: this.trash.filter(t => !t.collected).map(serializeTrash),
|
| 455 |
+
powerUps: this.powerUps.filter(p => !p.collected).map(serializePowerUp),
|
| 456 |
+
mvpId: this.mvpId,
|
| 457 |
+
});
|
| 458 |
+
}
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
adminSpawnPowerUp(kind: PowerUpKind) {
|
| 462 |
+
if (this.status !== "playing") return;
|
| 463 |
+
const pu = makePowerUp(kind);
|
| 464 |
+
this.powerUps.push(pu);
|
| 465 |
+
this.broadcast({ type: "powerUpSpawned", powerUp: serializePowerUp(pu) });
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
adminKick(playerId: string): boolean {
|
| 469 |
+
const p = this.players.get(playerId); if (!p) return false;
|
| 470 |
+
send(p.socket, { type: "kicked", reason: "Removed by an owner." });
|
| 471 |
+
try { p.socket.close(); } catch { /* ignore */ }
|
| 472 |
+
return true;
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
adminSetTimer(seconds: number) {
|
| 476 |
+
if (this.status !== "playing") return;
|
| 477 |
+
this.timeLeft = Math.max(5, Math.min(600, Math.floor(seconds)));
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
broadcastPositions() {
|
| 481 |
+
if (this.players.size === 0) return;
|
| 482 |
+
const players = Array.from(this.players.values()).map(p => ({
|
| 483 |
+
id: p.id, x: +p.x.toFixed(2), z: +p.z.toFixed(2), rot: +p.rot.toFixed(2),
|
| 484 |
+
}));
|
| 485 |
+
this.broadcast({ type: "positions", players });
|
| 486 |
+
}
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
class RoomManager {
|
| 490 |
+
rooms = new Map<string, Room>();
|
| 491 |
+
positionTimer: NodeJS.Timeout | null = null;
|
| 492 |
+
tickTimer: NodeJS.Timeout | null = null;
|
| 493 |
+
lastTick = Date.now();
|
| 494 |
+
|
| 495 |
+
ensurePublic(level: Level, gameMode: GameMode): Room {
|
| 496 |
+
const code = publicCode(level, gameMode);
|
| 497 |
+
let room = this.rooms.get(code);
|
| 498 |
+
if (!room) {
|
| 499 |
+
room = new Room(level, code, true, "normal", gameMode);
|
| 500 |
+
this.rooms.set(code, room);
|
| 501 |
+
logger.info({ code, level, gameMode }, "Created public room");
|
| 502 |
+
}
|
| 503 |
+
return room;
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
joinByCode(code: string): Room | null {
|
| 507 |
+
return this.rooms.get(code.toUpperCase()) ?? null;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
createPrivate(level: Level, difficulty: Difficulty, gameMode: GameMode): Room {
|
| 511 |
+
let code: string;
|
| 512 |
+
do { code = generateCode(); } while (this.rooms.has(code) || RESERVED.has(code));
|
| 513 |
+
const room = new Room(level, code, false, difficulty, gameMode);
|
| 514 |
+
this.rooms.set(code, room);
|
| 515 |
+
logger.info({ code, level, difficulty, gameMode }, "Created private room");
|
| 516 |
+
return room;
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
disposeIfEmpty(room: Room): void {
|
| 520 |
+
if (room.isPublic) return;
|
| 521 |
+
if (room.players.size > 0) return;
|
| 522 |
+
this.rooms.delete(room.code);
|
| 523 |
+
logger.info({ code: room.code }, "Destroyed empty private room");
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
start() {
|
| 527 |
+
if (this.tickTimer) return;
|
| 528 |
+
this.lastTick = Date.now();
|
| 529 |
+
this.tickTimer = setInterval(() => {
|
| 530 |
+
const now = Date.now(); const dt = (now - this.lastTick) / 1000; this.lastTick = now;
|
| 531 |
+
for (const room of this.rooms.values()) room.tick(dt);
|
| 532 |
+
}, 1000);
|
| 533 |
+
this.positionTimer = setInterval(() => {
|
| 534 |
+
for (const room of this.rooms.values()) room.broadcastPositions();
|
| 535 |
+
}, Math.round(1000 / POSITION_BROADCAST_HZ));
|
| 536 |
+
}
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
export const roomManager = new RoomManager();
|
| 540 |
+
let nextPlayerId = 1;
|
| 541 |
+
export function makePlayerId(): string { return `p${nextPlayerId++}`; }
|
artifacts/api-server/src/multiplayer/wsHandler.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* WebSocket handler that wires raw `ws` connections to the room manager.
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
import { WebSocketServer, type WebSocket } from "ws";
|
| 6 |
+
import type { Server as HttpServer, IncomingMessage } from "http";
|
| 7 |
+
import { logger } from "../lib/logger.js";
|
| 8 |
+
import {
|
| 9 |
+
makePlayerId,
|
| 10 |
+
OWNER_PASSWORD,
|
| 11 |
+
roomManager,
|
| 12 |
+
VALID_DIFFICULTIES,
|
| 13 |
+
VALID_LEVELS,
|
| 14 |
+
VALID_GAME_MODES,
|
| 15 |
+
type ClientToServer,
|
| 16 |
+
type Difficulty,
|
| 17 |
+
type EmoteKind,
|
| 18 |
+
type GameMode,
|
| 19 |
+
type Level,
|
| 20 |
+
type PowerUpKind,
|
| 21 |
+
} from "./rooms.js";
|
| 22 |
+
|
| 23 |
+
const VALID_EMOTES: EmoteKind[] = ["wave", "thumbsup", "recycle", "smile", "cheer"];
|
| 24 |
+
function isEmote(x: string): x is EmoteKind { return (VALID_EMOTES as string[]).includes(x); }
|
| 25 |
+
function isLevel(x: string): x is Level { return (VALID_LEVELS as string[]).includes(x); }
|
| 26 |
+
function isDifficulty(x: string): x is Difficulty { return (VALID_DIFFICULTIES as string[]).includes(x); }
|
| 27 |
+
function isGameMode(x: string): x is GameMode { return (VALID_GAME_MODES as string[]).includes(x); }
|
| 28 |
+
|
| 29 |
+
const VALID_POWERUPS: PowerUpKind[] = ["magnet", "speed", "bonus"];
|
| 30 |
+
function isPowerUpKind(x: string): x is PowerUpKind { return (VALID_POWERUPS as string[]).includes(x); }
|
| 31 |
+
|
| 32 |
+
export function attachMultiplayer(server: HttpServer) {
|
| 33 |
+
const wss = new WebSocketServer({ noServer: true });
|
| 34 |
+
roomManager.start();
|
| 35 |
+
|
| 36 |
+
server.on("upgrade", (request: IncomingMessage, socket, head) => {
|
| 37 |
+
const url = request.url ?? "";
|
| 38 |
+
if (!url.startsWith("/api/ws")) { socket.destroy(); return; }
|
| 39 |
+
wss.handleUpgrade(request, socket, head, (ws) => { wss.emit("connection", ws, request); });
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
wss.on("connection", (ws: WebSocket, request: IncomingMessage) => {
|
| 43 |
+
const url = new URL(request.url ?? "/", "http://localhost");
|
| 44 |
+
const levelParam = url.searchParams.get("level") ?? "park";
|
| 45 |
+
const nameParam = (url.searchParams.get("name") ?? "Player").slice(0, 20);
|
| 46 |
+
const codeParam = url.searchParams.get("code");
|
| 47 |
+
const diffParam = url.searchParams.get("difficulty") ?? "normal";
|
| 48 |
+
const modeParam = url.searchParams.get("mode") ?? "speedrun";
|
| 49 |
+
const level: Level = isLevel(levelParam) ? levelParam : "park";
|
| 50 |
+
const difficulty: Difficulty = isDifficulty(diffParam) ? diffParam : "normal";
|
| 51 |
+
const gameMode: GameMode = isGameMode(modeParam) ? modeParam : "speedrun";
|
| 52 |
+
|
| 53 |
+
let room;
|
| 54 |
+
if (codeParam) {
|
| 55 |
+
const upper = codeParam.toUpperCase();
|
| 56 |
+
if (upper === "NEW") {
|
| 57 |
+
room = roomManager.createPrivate(level, difficulty, gameMode);
|
| 58 |
+
} else {
|
| 59 |
+
const existing = roomManager.joinByCode(upper);
|
| 60 |
+
if (!existing) {
|
| 61 |
+
ws.send(JSON.stringify({ type: "error", message: `No room with code "${upper}". Check the code and try again.` }));
|
| 62 |
+
ws.close(); return;
|
| 63 |
+
}
|
| 64 |
+
room = existing;
|
| 65 |
+
}
|
| 66 |
+
} else {
|
| 67 |
+
room = roomManager.ensurePublic(level, gameMode);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
const playerId = makePlayerId();
|
| 71 |
+
const color = room.pickColor();
|
| 72 |
+
const player = {
|
| 73 |
+
id: playerId,
|
| 74 |
+
name: nameParam || "Player",
|
| 75 |
+
color,
|
| 76 |
+
x: (Math.random() - 0.5) * 4,
|
| 77 |
+
z: (Math.random() - 0.5) * 4,
|
| 78 |
+
rot: 0,
|
| 79 |
+
score: 0,
|
| 80 |
+
combo: 0,
|
| 81 |
+
lastCollectAt: 0,
|
| 82 |
+
lastEmoteAt: 0,
|
| 83 |
+
socket: ws,
|
| 84 |
+
alive: true,
|
| 85 |
+
};
|
| 86 |
+
room.addPlayer(player);
|
| 87 |
+
|
| 88 |
+
ws.on("message", (raw) => {
|
| 89 |
+
let msg: ClientToServer;
|
| 90 |
+
try { msg = JSON.parse(raw.toString()); } catch { return; }
|
| 91 |
+
switch (msg.type) {
|
| 92 |
+
case "move":
|
| 93 |
+
if (typeof msg.x === "number" && typeof msg.z === "number" && typeof msg.rot === "number"
|
| 94 |
+
&& Number.isFinite(msg.x) && Number.isFinite(msg.z) && Number.isFinite(msg.rot)) {
|
| 95 |
+
room.handleMove(playerId, msg.x, msg.z, msg.rot);
|
| 96 |
+
}
|
| 97 |
+
break;
|
| 98 |
+
case "collect":
|
| 99 |
+
if (typeof msg.trashId === "string") room.handleCollect(playerId, msg.trashId);
|
| 100 |
+
break;
|
| 101 |
+
case "collectPowerUp":
|
| 102 |
+
if (typeof msg.powerUpId === "string") room.handleCollectPowerUp(playerId, msg.powerUpId);
|
| 103 |
+
break;
|
| 104 |
+
case "emote":
|
| 105 |
+
if (typeof msg.kind === "string" && isEmote(msg.kind)) room.handleEmote(playerId, msg.kind);
|
| 106 |
+
break;
|
| 107 |
+
case "ping":
|
| 108 |
+
ws.send(JSON.stringify({ type: "pong", t: msg.t }));
|
| 109 |
+
break;
|
| 110 |
+
case "join": break;
|
| 111 |
+
case "admin.identify":
|
| 112 |
+
ws.send(JSON.stringify(msg.password === OWNER_PASSWORD
|
| 113 |
+
? { type: "adminAck", ok: true, message: "Owner mode unlocked." }
|
| 114 |
+
: { type: "adminAck", ok: false, message: "Wrong owner password." }
|
| 115 |
+
));
|
| 116 |
+
break;
|
| 117 |
+
case "admin.endRound":
|
| 118 |
+
if (msg.password === OWNER_PASSWORD) room.adminEndRound(msg.result === "won" ? "won" : "lost");
|
| 119 |
+
break;
|
| 120 |
+
case "admin.spawnTrash":
|
| 121 |
+
if (msg.password === OWNER_PASSWORD && typeof msg.count === "number") room.adminSpawnTrash(msg.count);
|
| 122 |
+
break;
|
| 123 |
+
case "admin.spawnPowerUp":
|
| 124 |
+
if (msg.password === OWNER_PASSWORD && typeof msg.kind === "string" && isPowerUpKind(msg.kind))
|
| 125 |
+
room.adminSpawnPowerUp(msg.kind);
|
| 126 |
+
break;
|
| 127 |
+
case "admin.kick":
|
| 128 |
+
if (msg.password === OWNER_PASSWORD && typeof msg.playerId === "string" && msg.playerId !== playerId)
|
| 129 |
+
room.adminKick(msg.playerId);
|
| 130 |
+
break;
|
| 131 |
+
case "admin.setTimer":
|
| 132 |
+
if (msg.password === OWNER_PASSWORD && typeof msg.seconds === "number") room.adminSetTimer(msg.seconds);
|
| 133 |
+
break;
|
| 134 |
+
}
|
| 135 |
+
});
|
| 136 |
+
|
| 137 |
+
ws.on("close", () => { room.removePlayer(playerId); roomManager.disposeIfEmpty(room); });
|
| 138 |
+
ws.on("error", (err: Error) => { logger.warn({ err, playerId }, "WebSocket error"); });
|
| 139 |
+
});
|
| 140 |
+
|
| 141 |
+
logger.info("Multiplayer WebSocket server attached at /api/ws");
|
| 142 |
+
}
|
artifacts/api-server/src/routes/health.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router, type IRouter } from "express";
|
| 2 |
+
import { HealthCheckResponse } from "@workspace/api-zod";
|
| 3 |
+
|
| 4 |
+
const router: IRouter = Router();
|
| 5 |
+
|
| 6 |
+
router.get("/healthz", (_req, res) => {
|
| 7 |
+
const data = HealthCheckResponse.parse({ status: "ok" });
|
| 8 |
+
res.json(data);
|
| 9 |
+
});
|
| 10 |
+
|
| 11 |
+
export default router;
|
artifacts/api-server/src/routes/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router, type IRouter } from "express";
|
| 2 |
+
import healthRouter from "./health";
|
| 3 |
+
|
| 4 |
+
const router: IRouter = Router();
|
| 5 |
+
|
| 6 |
+
router.use(healthRouter);
|
| 7 |
+
|
| 8 |
+
export default router;
|
artifacts/api-server/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"extends": "../../tsconfig.base.json",
|
| 3 |
+
"compilerOptions": {
|
| 4 |
+
"outDir": "dist",
|
| 5 |
+
"rootDir": "src",
|
| 6 |
+
"types": ["node"]
|
| 7 |
+
},
|
| 8 |
+
"include": ["src"],
|
| 9 |
+
"references": [
|
| 10 |
+
{
|
| 11 |
+
"path": "../../lib/db"
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"path": "../../lib/api-zod"
|
| 15 |
+
}
|
| 16 |
+
]
|
| 17 |
+
}
|
artifacts/eco-cleanup-game/.replit-artifact/artifact.toml
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind = "web"
|
| 2 |
+
previewPath = "/"
|
| 3 |
+
title = "EcoClean 3D Game"
|
| 4 |
+
version = "1.0.0"
|
| 5 |
+
id = "artifacts/eco-cleanup-game"
|
| 6 |
+
router = "path"
|
| 7 |
+
|
| 8 |
+
[[integratedSkills]]
|
| 9 |
+
name = "react-vite"
|
| 10 |
+
version = "1.0.0"
|
| 11 |
+
|
| 12 |
+
[[services]]
|
| 13 |
+
name = "web"
|
| 14 |
+
paths = [ "/" ]
|
| 15 |
+
localPort = 18257
|
| 16 |
+
|
| 17 |
+
[services.development]
|
| 18 |
+
run = "pnpm --filter @workspace/eco-cleanup-game run dev"
|
| 19 |
+
|
| 20 |
+
[services.production]
|
| 21 |
+
build = [ "pnpm", "--filter", "@workspace/eco-cleanup-game", "run", "build" ]
|
| 22 |
+
publicDir = "artifacts/eco-cleanup-game/dist/public"
|
| 23 |
+
serve = "static"
|
| 24 |
+
|
| 25 |
+
[[services.production.rewrites]]
|
| 26 |
+
from = "/*"
|
| 27 |
+
to = "/index.html"
|
| 28 |
+
|
| 29 |
+
[services.env]
|
| 30 |
+
PORT = "18257"
|
| 31 |
+
BASE_PATH = "/"
|
artifacts/eco-cleanup-game/components.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://ui.shadcn.com/schema.json",
|
| 3 |
+
"style": "new-york",
|
| 4 |
+
"rsc": false,
|
| 5 |
+
"tsx": true,
|
| 6 |
+
"tailwind": {
|
| 7 |
+
"config": "",
|
| 8 |
+
"css": "src/index.css",
|
| 9 |
+
"baseColor": "neutral",
|
| 10 |
+
"cssVariables": true,
|
| 11 |
+
"prefix": ""
|
| 12 |
+
},
|
| 13 |
+
"aliases": {
|
| 14 |
+
"components": "@/components",
|
| 15 |
+
"utils": "@/lib/utils",
|
| 16 |
+
"ui": "@/components/ui",
|
| 17 |
+
"lib": "@/lib",
|
| 18 |
+
"hooks": "@/hooks"
|
| 19 |
+
}
|
| 20 |
+
}
|
artifacts/eco-cleanup-game/index.html
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1" />
|
| 6 |
+
<title>EcoClean 3D Game</title>
|
| 7 |
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
| 8 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 9 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 10 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 11 |
+
</head>
|
| 12 |
+
<body>
|
| 13 |
+
<div id="root"></div>
|
| 14 |
+
<script type="module" src="/src/main.tsx"></script>
|
| 15 |
+
</body>
|
| 16 |
+
</html>
|
artifacts/eco-cleanup-game/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@workspace/eco-cleanup-game",
|
| 3 |
+
"version": "0.0.0",
|
| 4 |
+
"private": true,
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite --config vite.config.ts --host 0.0.0.0",
|
| 8 |
+
"build": "vite build --config vite.config.ts",
|
| 9 |
+
"serve": "vite preview --config vite.config.ts --host 0.0.0.0",
|
| 10 |
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
| 11 |
+
},
|
| 12 |
+
"devDependencies": {
|
| 13 |
+
"@hookform/resolvers": "^3.10.0",
|
| 14 |
+
"@radix-ui/react-accordion": "^1.2.4",
|
| 15 |
+
"@radix-ui/react-alert-dialog": "^1.1.7",
|
| 16 |
+
"@radix-ui/react-aspect-ratio": "^1.1.3",
|
| 17 |
+
"@radix-ui/react-avatar": "^1.1.4",
|
| 18 |
+
"@radix-ui/react-checkbox": "^1.1.5",
|
| 19 |
+
"@radix-ui/react-collapsible": "^1.1.4",
|
| 20 |
+
"@radix-ui/react-context-menu": "^2.2.7",
|
| 21 |
+
"@radix-ui/react-dialog": "^1.1.7",
|
| 22 |
+
"@radix-ui/react-dropdown-menu": "^2.1.7",
|
| 23 |
+
"@radix-ui/react-hover-card": "^1.1.7",
|
| 24 |
+
"@radix-ui/react-label": "^2.1.3",
|
| 25 |
+
"@radix-ui/react-menubar": "^1.1.7",
|
| 26 |
+
"@radix-ui/react-navigation-menu": "^1.2.6",
|
| 27 |
+
"@radix-ui/react-popover": "^1.1.7",
|
| 28 |
+
"@radix-ui/react-progress": "^1.1.3",
|
| 29 |
+
"@radix-ui/react-radio-group": "^1.2.4",
|
| 30 |
+
"@radix-ui/react-scroll-area": "^1.2.4",
|
| 31 |
+
"@radix-ui/react-select": "^2.1.7",
|
| 32 |
+
"@radix-ui/react-separator": "^1.1.3",
|
| 33 |
+
"@radix-ui/react-slider": "^1.2.4",
|
| 34 |
+
"@radix-ui/react-slot": "^1.2.0",
|
| 35 |
+
"@radix-ui/react-switch": "^1.1.4",
|
| 36 |
+
"@radix-ui/react-tabs": "^1.1.4",
|
| 37 |
+
"@radix-ui/react-toast": "^1.2.7",
|
| 38 |
+
"@radix-ui/react-toggle": "^1.1.3",
|
| 39 |
+
"@radix-ui/react-toggle-group": "^1.1.3",
|
| 40 |
+
"@radix-ui/react-tooltip": "^1.2.0",
|
| 41 |
+
"@replit/vite-plugin-cartographer": "catalog:",
|
| 42 |
+
"@replit/vite-plugin-dev-banner": "catalog:",
|
| 43 |
+
"@replit/vite-plugin-runtime-error-modal": "catalog:",
|
| 44 |
+
"@tailwindcss/typography": "^0.5.15",
|
| 45 |
+
"@tailwindcss/vite": "catalog:",
|
| 46 |
+
"@tanstack/react-query": "catalog:",
|
| 47 |
+
"@types/node": "catalog:",
|
| 48 |
+
"@types/react": "catalog:",
|
| 49 |
+
"@types/react-dom": "catalog:",
|
| 50 |
+
"@types/three": "^0.184.0",
|
| 51 |
+
"@vitejs/plugin-react": "catalog:",
|
| 52 |
+
"@workspace/api-client-react": "workspace:*",
|
| 53 |
+
"class-variance-authority": "catalog:",
|
| 54 |
+
"clsx": "catalog:",
|
| 55 |
+
"cmdk": "^1.1.1",
|
| 56 |
+
"date-fns": "^3.6.0",
|
| 57 |
+
"embla-carousel-react": "^8.6.0",
|
| 58 |
+
"framer-motion": "catalog:",
|
| 59 |
+
"input-otp": "^1.4.2",
|
| 60 |
+
"lucide-react": "catalog:",
|
| 61 |
+
"next-themes": "^0.4.6",
|
| 62 |
+
"react": "catalog:",
|
| 63 |
+
"react-day-picker": "^9.11.1",
|
| 64 |
+
"react-dom": "catalog:",
|
| 65 |
+
"react-hook-form": "^7.55.0",
|
| 66 |
+
"react-icons": "^5.4.0",
|
| 67 |
+
"react-resizable-panels": "^2.1.7",
|
| 68 |
+
"recharts": "^2.15.2",
|
| 69 |
+
"sonner": "^2.0.7",
|
| 70 |
+
"tailwind-merge": "catalog:",
|
| 71 |
+
"tailwindcss": "catalog:",
|
| 72 |
+
"tw-animate-css": "^1.4.0",
|
| 73 |
+
"vaul": "^1.1.2",
|
| 74 |
+
"vite": "catalog:",
|
| 75 |
+
"wouter": "^3.3.5",
|
| 76 |
+
"zod": "catalog:"
|
| 77 |
+
},
|
| 78 |
+
"dependencies": {
|
| 79 |
+
"three": "^0.184.0"
|
| 80 |
+
}
|
| 81 |
+
}
|
artifacts/eco-cleanup-game/public/favicon.svg
ADDED
|
|
artifacts/eco-cleanup-game/public/opengraph.jpg
ADDED
|
artifacts/eco-cleanup-game/src/App.tsx
ADDED
|
@@ -0,0 +1,863 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect, useMemo, useRef, useState } from "react";
|
| 2 |
+
import {
|
| 3 |
+
DIFFICULTY_LABELS,
|
| 4 |
+
EMOTES,
|
| 5 |
+
GAME_MODE_DESCRIPTIONS,
|
| 6 |
+
GAME_MODE_LABELS,
|
| 7 |
+
LEVEL_LABELS,
|
| 8 |
+
POWERUP_EMOJIS,
|
| 9 |
+
POWERUP_LABELS,
|
| 10 |
+
startGame,
|
| 11 |
+
type AdminCommand,
|
| 12 |
+
type Difficulty,
|
| 13 |
+
type EmoteKind,
|
| 14 |
+
type GameHandle,
|
| 15 |
+
type GameMode,
|
| 16 |
+
type GameState,
|
| 17 |
+
type Level,
|
| 18 |
+
type MiniMapData,
|
| 19 |
+
type PowerUpKind,
|
| 20 |
+
} from "@/game";
|
| 21 |
+
|
| 22 |
+
const NAME_KEY = "ecoclean.playerName";
|
| 23 |
+
const SETTINGS_KEY = "ecoclean.settings";
|
| 24 |
+
|
| 25 |
+
const TRASH_LABELS: Record<string, string> = {
|
| 26 |
+
plastic: "a plastic bottle",
|
| 27 |
+
metal: "a soda can",
|
| 28 |
+
paper: "some paper",
|
| 29 |
+
organic: "some organic waste",
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
const DIFFICULTY_BLURBS: Record<Difficulty, string> = {
|
| 33 |
+
easy: "180s round · 24 trash · 60% to win",
|
| 34 |
+
normal: "120s round · 32 trash · 80% to win",
|
| 35 |
+
hard: "90s round · 44 trash · 90% to win",
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
const MODE_COLORS: Record<GameMode, string> = {
|
| 39 |
+
speedrun: "bg-yellow-500",
|
| 40 |
+
percent100: "bg-emerald-600",
|
| 41 |
+
powerup: "bg-purple-600",
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
const POWERUP_KINDS: PowerUpKind[] = ["magnet", "speed", "bonus"];
|
| 45 |
+
|
| 46 |
+
const ALL_LEVELS: Level[] = ["park", "beach", "city", "nightcity", "arctic", "jungle"];
|
| 47 |
+
|
| 48 |
+
const DEFAULT_STATE: GameState = {
|
| 49 |
+
status: "menu",
|
| 50 |
+
level: "park",
|
| 51 |
+
gameMode: "speedrun",
|
| 52 |
+
difficulty: "normal",
|
| 53 |
+
roundDuration: 120,
|
| 54 |
+
selfId: null, selfName: "", selfScore: 0, timeLeft: 0,
|
| 55 |
+
totalTrash: 0, collected: 0, players: [], fact: null, lastResult: null,
|
| 56 |
+
soundOn: true, musicVolume: 0.5, sfxVolume: 0.7, mouseSensitivity: 1.0,
|
| 57 |
+
pickupNotice: null, powerUpNotice: null, combo: null, mvpId: null, floatingPoints: [],
|
| 58 |
+
roomCode: null, isPublicRoom: false, errorMessage: null, sprintStamina: 1, isSprinting: false,
|
| 59 |
+
magnetMs: 0, speedMs: 0,
|
| 60 |
+
miniMap: { worldHalf: 28, selfX: 0, selfZ: 0, others: [], trash: [], powerUps: [] },
|
| 61 |
+
isOwner: false, ownerStatus: null, godMode: false,
|
| 62 |
+
stats: { trashCleaned: 0, powerUpsCollected: 0, bestCombo: 0, pointsEarned: 0 },
|
| 63 |
+
isPaused: false,
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
interface PersistedSettings { musicVolume: number; sfxVolume: number; mouseSensitivity: number; }
|
| 67 |
+
function loadSettings(): PersistedSettings | null {
|
| 68 |
+
if (typeof window === "undefined") return null;
|
| 69 |
+
try { const raw = window.localStorage.getItem(SETTINGS_KEY); if (!raw) return null; return JSON.parse(raw) as PersistedSettings; } catch { return null; }
|
| 70 |
+
}
|
| 71 |
+
function saveSettings(s: PersistedSettings) {
|
| 72 |
+
try { window.localStorage.setItem(SETTINGS_KEY, JSON.stringify(s)); } catch { /* ignore */ }
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/** Enhanced Mini-map with legend */
|
| 76 |
+
function MiniMap({ data, godMode }: { data: MiniMapData; godMode: boolean }) {
|
| 77 |
+
const SIZE = 200; const HALF = SIZE / 2; const scale = HALF / data.worldHalf;
|
| 78 |
+
const projX = (x: number) => HALF + (x - data.selfX) * scale;
|
| 79 |
+
const projZ = (z: number) => HALF + (z - data.selfZ) * scale;
|
| 80 |
+
return (
|
| 81 |
+
<div>
|
| 82 |
+
<div className="bg-black/80 backdrop-blur rounded-xl shadow-xl border border-white/20 overflow-hidden" style={{ width: SIZE, height: SIZE }}>
|
| 83 |
+
<svg width={SIZE} height={SIZE} className="block">
|
| 84 |
+
{/* Compass cardinal marks */}
|
| 85 |
+
<text x={HALF} y={10} textAnchor="middle" fontSize="8" fill="rgba(255,255,255,0.4)">N</text>
|
| 86 |
+
<text x={HALF} y={SIZE - 3} textAnchor="middle" fontSize="8" fill="rgba(255,255,255,0.4)">S</text>
|
| 87 |
+
<text x={6} y={HALF + 3} textAnchor="middle" fontSize="8" fill="rgba(255,255,255,0.4)">W</text>
|
| 88 |
+
<text x={SIZE - 6} y={HALF + 3} textAnchor="middle" fontSize="8" fill="rgba(255,255,255,0.4)">E</text>
|
| 89 |
+
{/* World border */}
|
| 90 |
+
<rect x={projX(-data.worldHalf)} y={projZ(-data.worldHalf)} width={2 * data.worldHalf * scale} height={2 * data.worldHalf * scale} fill="rgba(255,255,255,0.05)" stroke="rgba(255,255,255,0.25)" strokeWidth={1} />
|
| 91 |
+
{/* Grid lines */}
|
| 92 |
+
{[-14, 0, 14].map(v => (
|
| 93 |
+
<g key={v}>
|
| 94 |
+
<line x1={projX(v)} y1={projZ(-data.worldHalf)} x2={projX(v)} y2={projZ(data.worldHalf)} stroke="rgba(255,255,255,0.06)" strokeWidth={0.5} />
|
| 95 |
+
<line x1={projX(-data.worldHalf)} y1={projZ(v)} x2={projX(data.worldHalf)} y2={projZ(v)} stroke="rgba(255,255,255,0.06)" strokeWidth={0.5} />
|
| 96 |
+
</g>
|
| 97 |
+
))}
|
| 98 |
+
{/* Trash blips — yellow dots with a cross */}
|
| 99 |
+
{data.trash.map((t, i) => (
|
| 100 |
+
<g key={`t${i}`}>
|
| 101 |
+
<circle cx={projX(t.x)} cy={projZ(t.z)} r={2.5} fill="#fbbf24" opacity={0.9} />
|
| 102 |
+
</g>
|
| 103 |
+
))}
|
| 104 |
+
{/* Power-up blips */}
|
| 105 |
+
{data.powerUps.map((p, i) => (
|
| 106 |
+
<circle key={`p${i}`} cx={projX(p.x)} cy={projZ(p.z)} r={4} fill={p.kind === "magnet" ? "#ef4444" : p.kind === "speed" ? "#facc15" : "#c084fc"} stroke="white" strokeWidth={1} opacity={0.95} />
|
| 107 |
+
))}
|
| 108 |
+
{/* Other players */}
|
| 109 |
+
{data.others.map(o => (
|
| 110 |
+
<circle key={o.id} cx={projX(o.x)} cy={projZ(o.z)} r={4} fill={o.color} stroke="white" strokeWidth={1.5} />
|
| 111 |
+
))}
|
| 112 |
+
{/* Self — pulsing green dot */}
|
| 113 |
+
<circle cx={HALF} cy={HALF} r={5.5} fill={godMode ? "#a78bfa" : "#34d399"} stroke="white" strokeWidth={2} />
|
| 114 |
+
<circle cx={HALF} cy={HALF} r={2} fill="white" />
|
| 115 |
+
</svg>
|
| 116 |
+
</div>
|
| 117 |
+
{/* Legend */}
|
| 118 |
+
<div className="mt-1 flex gap-2 justify-center text-[9px] text-white/70 font-semibold">
|
| 119 |
+
<span className="flex items-center gap-1"><span className="inline-block w-2 h-2 rounded-full bg-yellow-400" />Trash</span>
|
| 120 |
+
<span className="flex items-center gap-1"><span className="inline-block w-2 h-2 rounded-full bg-emerald-400" />You</span>
|
| 121 |
+
{data.others.length > 0 && <span className="flex items-center gap-1"><span className="inline-block w-2 h-2 rounded-full bg-blue-400" />Team</span>}
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
function App() {
|
| 128 |
+
const mountRef = useRef<HTMLDivElement | null>(null);
|
| 129 |
+
const gameRef = useRef<GameHandle | null>(null);
|
| 130 |
+
|
| 131 |
+
const [name, setName] = useState<string>(() => {
|
| 132 |
+
if (typeof window !== "undefined") return window.localStorage.getItem(NAME_KEY) ?? "";
|
| 133 |
+
return "";
|
| 134 |
+
});
|
| 135 |
+
const initialJoinCode = useMemo(() => {
|
| 136 |
+
if (typeof window === "undefined") return "";
|
| 137 |
+
const c = new URL(window.location.href).searchParams.get("code");
|
| 138 |
+
return (c ?? "").toUpperCase().slice(0, 8);
|
| 139 |
+
}, []);
|
| 140 |
+
const [joinCode, setJoinCode] = useState(initialJoinCode);
|
| 141 |
+
const [showPrivate, setShowPrivate] = useState(false);
|
| 142 |
+
const [privateDifficulty, setPrivateDifficulty] = useState<Difficulty>("normal");
|
| 143 |
+
const [copied, setCopied] = useState(false);
|
| 144 |
+
|
| 145 |
+
// Lobby flow: mode → map → play
|
| 146 |
+
const [lobbyMode, setLobbyMode] = useState<GameMode | null>(null);
|
| 147 |
+
const [lobbyStep, setLobbyStep] = useState<"mode" | "map" | null>(null);
|
| 148 |
+
const [privateMode, setPrivateMode] = useState<GameMode>("speedrun");
|
| 149 |
+
|
| 150 |
+
// UI panels
|
| 151 |
+
const [showSettings, setShowSettings] = useState(false);
|
| 152 |
+
const [showStats, setShowStats] = useState(false);
|
| 153 |
+
const [showOwnerLogin, setShowOwnerLogin] = useState(false);
|
| 154 |
+
const [ownerPwInput, setOwnerPwInput] = useState("");
|
| 155 |
+
const [showOwnerPanel, setShowOwnerPanel] = useState(false);
|
| 156 |
+
const [adminTimerInput, setAdminTimerInput] = useState("60");
|
| 157 |
+
|
| 158 |
+
const [state, setState] = useState<GameState>(DEFAULT_STATE);
|
| 159 |
+
|
| 160 |
+
useEffect(() => {
|
| 161 |
+
if (!mountRef.current) return;
|
| 162 |
+
const handle = startGame(mountRef.current, setState);
|
| 163 |
+
gameRef.current = handle;
|
| 164 |
+
const saved = loadSettings();
|
| 165 |
+
if (saved) {
|
| 166 |
+
handle.setMusicVolume(saved.musicVolume);
|
| 167 |
+
handle.setSfxVolume(saved.sfxVolume);
|
| 168 |
+
handle.setMouseSensitivity(saved.mouseSensitivity);
|
| 169 |
+
}
|
| 170 |
+
return () => handle.dispose();
|
| 171 |
+
}, []);
|
| 172 |
+
|
| 173 |
+
useEffect(() => {
|
| 174 |
+
saveSettings({ musicVolume: state.musicVolume, sfxVolume: state.sfxVolume, mouseSensitivity: state.mouseSensitivity });
|
| 175 |
+
}, [state.musicVolume, state.sfxVolume, state.mouseSensitivity]);
|
| 176 |
+
|
| 177 |
+
// ESC key — pause/unpause (only when playing)
|
| 178 |
+
useEffect(() => {
|
| 179 |
+
const handleEsc = (e: KeyboardEvent) => {
|
| 180 |
+
if (e.key !== "Escape") return;
|
| 181 |
+
if (state.status !== "playing") return;
|
| 182 |
+
if (showSettings || showOwnerPanel || showOwnerLogin || showStats) {
|
| 183 |
+
setShowSettings(false); setShowOwnerPanel(false); setShowOwnerLogin(false); setShowStats(false);
|
| 184 |
+
return;
|
| 185 |
+
}
|
| 186 |
+
gameRef.current?.setPaused(!state.isPaused);
|
| 187 |
+
};
|
| 188 |
+
window.addEventListener("keydown", handleEsc);
|
| 189 |
+
return () => window.removeEventListener("keydown", handleEsc);
|
| 190 |
+
}, [state.status, state.isPaused, showSettings, showOwnerPanel, showOwnerLogin, showStats]);
|
| 191 |
+
|
| 192 |
+
// P key — admin panel
|
| 193 |
+
useEffect(() => {
|
| 194 |
+
const handleAdminKey = (e: KeyboardEvent) => {
|
| 195 |
+
if (e.key !== "p" && e.key !== "P") return;
|
| 196 |
+
if (state.status !== "playing" && state.status !== "waiting") return;
|
| 197 |
+
if (state.isPaused) return;
|
| 198 |
+
if (state.isOwner) setShowOwnerPanel(true); else setShowOwnerLogin(true);
|
| 199 |
+
};
|
| 200 |
+
window.addEventListener("keydown", handleAdminKey);
|
| 201 |
+
return () => window.removeEventListener("keydown", handleAdminKey);
|
| 202 |
+
}, [state.status, state.isOwner, state.isPaused]);
|
| 203 |
+
|
| 204 |
+
const finalName = () => (name.trim() || "Player").slice(0, 18);
|
| 205 |
+
const persistName = (n: string) => window.localStorage.setItem(NAME_KEY, n);
|
| 206 |
+
|
| 207 |
+
const handleJoinPublic = (level: Level) => {
|
| 208 |
+
const n = finalName(); persistName(n);
|
| 209 |
+
gameRef.current?.start({ kind: "public", level, name: n, gameMode: lobbyMode ?? "speedrun" });
|
| 210 |
+
setLobbyStep(null); setLobbyMode(null);
|
| 211 |
+
};
|
| 212 |
+
const handleCreatePrivate = (level: Level) => {
|
| 213 |
+
const n = finalName(); persistName(n);
|
| 214 |
+
gameRef.current?.start({ kind: "private", level, name: n, difficulty: privateDifficulty, gameMode: privateMode });
|
| 215 |
+
};
|
| 216 |
+
const handleJoinCode = () => {
|
| 217 |
+
const code = joinCode.trim().toUpperCase(); if (!code) return;
|
| 218 |
+
const n = finalName(); persistName(n);
|
| 219 |
+
gameRef.current?.start({ kind: "join", code, name: n });
|
| 220 |
+
};
|
| 221 |
+
|
| 222 |
+
const handleCopyCode = async () => {
|
| 223 |
+
if (!state.roomCode) return;
|
| 224 |
+
const shareUrl = `${window.location.origin}${window.location.pathname}?code=${state.roomCode}`;
|
| 225 |
+
try { await navigator.clipboard.writeText(shareUrl); } catch { await navigator.clipboard.writeText(state.roomCode).catch(() => undefined); }
|
| 226 |
+
setCopied(true); setTimeout(() => setCopied(false), 1500);
|
| 227 |
+
};
|
| 228 |
+
const handleSubmitOwner = () => {
|
| 229 |
+
const pw = ownerPwInput.trim(); if (!pw) return;
|
| 230 |
+
gameRef.current?.submitOwnerPassword(pw); setOwnerPwInput("");
|
| 231 |
+
};
|
| 232 |
+
const sendAdmin = (cmd: AdminCommand) => gameRef.current?.sendAdmin(cmd);
|
| 233 |
+
|
| 234 |
+
const cleanedPct = state.totalTrash > 0 ? Math.round((state.collected / state.totalTrash) * 100) : 0;
|
| 235 |
+
const minutes = Math.floor(state.timeLeft / 60);
|
| 236 |
+
const seconds = state.timeLeft % 60;
|
| 237 |
+
const timeStr = `${minutes}:${seconds.toString().padStart(2, "0")}`;
|
| 238 |
+
const comboPct = state.combo
|
| 239 |
+
? Math.max(0, Math.min(1, (state.combo.expiresAt - performance.now()) / state.combo.windowMs))
|
| 240 |
+
: 0;
|
| 241 |
+
const inGame = state.status === "playing" || state.status === "waiting";
|
| 242 |
+
|
| 243 |
+
return (
|
| 244 |
+
<div className="relative w-full h-full">
|
| 245 |
+
<div ref={mountRef} className="absolute inset-0" />
|
| 246 |
+
|
| 247 |
+
{/* Top HUD */}
|
| 248 |
+
{inGame && (
|
| 249 |
+
<div className="pointer-events-none absolute top-0 left-0 right-0 p-4 flex flex-col gap-3 z-10">
|
| 250 |
+
<div className="flex items-start justify-between gap-4">
|
| 251 |
+
<div className="bg-white/88 backdrop-blur rounded-xl shadow-lg px-4 py-3 flex items-center gap-4 flex-wrap">
|
| 252 |
+
<div>
|
| 253 |
+
<div className="text-[10px] uppercase tracking-wide text-emerald-700 font-semibold">Your Score</div>
|
| 254 |
+
<div className="text-2xl font-bold text-emerald-900 tabular-nums">{state.selfScore}</div>
|
| 255 |
+
</div>
|
| 256 |
+
<div className="w-px h-10 bg-emerald-200" />
|
| 257 |
+
<div>
|
| 258 |
+
<div className="text-[10px] uppercase tracking-wide text-emerald-700 font-semibold">Time</div>
|
| 259 |
+
<div className={`text-2xl font-bold tabular-nums ${state.timeLeft <= 15 && state.status === "playing" ? "text-red-600 animate-pulse" : "text-emerald-900"}`}>{timeStr}</div>
|
| 260 |
+
</div>
|
| 261 |
+
<div className="w-px h-10 bg-emerald-200" />
|
| 262 |
+
<div>
|
| 263 |
+
<div className="text-[10px] uppercase tracking-wide text-emerald-700 font-semibold">Map</div>
|
| 264 |
+
<div className="text-base font-bold text-emerald-900 capitalize">{LEVEL_LABELS[state.level]}</div>
|
| 265 |
+
</div>
|
| 266 |
+
<div className="w-px h-10 bg-emerald-200" />
|
| 267 |
+
<div>
|
| 268 |
+
<div className="text-[10px] uppercase tracking-wide text-emerald-700 font-semibold">Mode</div>
|
| 269 |
+
<div className={`text-xs font-bold px-2 py-0.5 rounded-full text-white ${MODE_COLORS[state.gameMode]}`}>
|
| 270 |
+
{GAME_MODE_LABELS[state.gameMode]}
|
| 271 |
+
</div>
|
| 272 |
+
</div>
|
| 273 |
+
<div className="w-px h-10 bg-emerald-200" />
|
| 274 |
+
<div>
|
| 275 |
+
<div className="text-[10px] uppercase tracking-wide text-emerald-700 font-semibold">Players</div>
|
| 276 |
+
<div className="text-lg font-bold text-emerald-900 tabular-nums">{state.players.length}</div>
|
| 277 |
+
</div>
|
| 278 |
+
{state.roomCode && (
|
| 279 |
+
<>
|
| 280 |
+
<div className="w-px h-10 bg-emerald-200" />
|
| 281 |
+
<button onClick={handleCopyCode} className="pointer-events-auto text-left group hover:bg-emerald-50 rounded px-2 py-1 -mx-2 -my-1 transition" title="Copy share link">
|
| 282 |
+
<div className="text-[10px] uppercase tracking-wide text-emerald-700 font-semibold flex items-center gap-1">
|
| 283 |
+
{state.isPublicRoom ? "Public Room" : "Room Code"}
|
| 284 |
+
<span className="text-emerald-500 group-hover:text-emerald-700">{copied ? "✓ copied" : "📋"}</span>
|
| 285 |
+
</div>
|
| 286 |
+
<div className="text-lg font-bold text-emerald-900 tracking-widest tabular-nums">{state.roomCode}</div>
|
| 287 |
+
</button>
|
| 288 |
+
</>
|
| 289 |
+
)}
|
| 290 |
+
</div>
|
| 291 |
+
|
| 292 |
+
<div className="flex flex-col items-end gap-2 pointer-events-auto">
|
| 293 |
+
<div className="flex gap-2 flex-wrap justify-end">
|
| 294 |
+
<button onClick={() => gameRef.current?.toggleSound()} className="bg-white/85 backdrop-blur rounded-lg px-3 py-2 text-sm font-semibold text-emerald-900 shadow hover:bg-white">{state.soundOn ? "🔊" : "🔈"}</button>
|
| 295 |
+
<button onClick={() => setShowSettings(true)} className="bg-white/85 backdrop-blur rounded-lg px-3 py-2 text-sm font-semibold text-emerald-900 shadow hover:bg-white" title="Settings">⚙️</button>
|
| 296 |
+
<button onClick={() => setShowStats(true)} className="bg-white/85 backdrop-blur rounded-lg px-3 py-2 text-sm font-semibold text-emerald-900 shadow hover:bg-white" title="Stats">📊</button>
|
| 297 |
+
{state.isOwner ? (
|
| 298 |
+
<button onClick={() => setShowOwnerPanel(true)} className="bg-purple-600 hover:bg-purple-700 text-white rounded-lg px-3 py-2 text-sm font-semibold shadow" title="Owner panel">👑 Owner</button>
|
| 299 |
+
) : (
|
| 300 |
+
<button onClick={() => setShowOwnerLogin(true)} className="bg-white/85 backdrop-blur rounded-lg px-3 py-2 text-sm font-semibold text-emerald-900 shadow hover:bg-white" title="Owner login">🔐</button>
|
| 301 |
+
)}
|
| 302 |
+
<button onClick={() => gameRef.current?.setPaused(!state.isPaused)} className="bg-white/85 backdrop-blur rounded-lg px-3 py-2 text-sm font-semibold text-emerald-900 shadow hover:bg-white" title="Pause (ESC)">{state.isPaused ? "▶" : "⏸"}</button>
|
| 303 |
+
<button onClick={() => gameRef.current?.backToMenu()} className="bg-white/85 backdrop-blur rounded-lg px-3 py-2 text-sm font-semibold text-emerald-900 shadow hover:bg-white">← Leave</button>
|
| 304 |
+
</div>
|
| 305 |
+
</div>
|
| 306 |
+
</div>
|
| 307 |
+
|
| 308 |
+
{/* Progress bar */}
|
| 309 |
+
<div className="bg-white/85 backdrop-blur rounded-xl shadow-lg p-3 max-w-3xl">
|
| 310 |
+
<div className="flex items-center justify-between mb-1">
|
| 311 |
+
<span className="text-xs uppercase tracking-wide text-emerald-700 font-semibold">
|
| 312 |
+
{state.gameMode === "percent100" ? "♻️ Must collect ALL trash!" : "Environment Cleaned (team)"}
|
| 313 |
+
</span>
|
| 314 |
+
<span className="text-sm font-bold text-emerald-900 tabular-nums">
|
| 315 |
+
{state.collected}/{state.collected + (state.totalTrash - state.collected)} ({cleanedPct}%)
|
| 316 |
+
</span>
|
| 317 |
+
</div>
|
| 318 |
+
<div className="relative h-3 bg-emerald-100 rounded-full overflow-hidden">
|
| 319 |
+
<div className="h-full bg-gradient-to-r from-emerald-400 to-emerald-600 transition-all duration-300" style={{ width: `${cleanedPct}%` }} />
|
| 320 |
+
{state.gameMode !== "speedrun" && (
|
| 321 |
+
<div className="absolute top-0 h-full w-0.5 bg-amber-500"
|
| 322 |
+
style={{ left: state.gameMode === "percent100" ? "100%" : state.difficulty === "easy" ? "60%" : state.difficulty === "hard" ? "90%" : "80%" }}
|
| 323 |
+
title="Win threshold" />
|
| 324 |
+
)}
|
| 325 |
+
{state.gameMode === "speedrun" && (
|
| 326 |
+
<div className="absolute top-0 h-full w-0.5 bg-amber-500"
|
| 327 |
+
style={{ left: state.difficulty === "easy" ? "60%" : state.difficulty === "hard" ? "90%" : "80%" }}
|
| 328 |
+
title="Win threshold" />
|
| 329 |
+
)}
|
| 330 |
+
</div>
|
| 331 |
+
</div>
|
| 332 |
+
|
| 333 |
+
{/* Active power-up timers */}
|
| 334 |
+
{(state.magnetMs > 0 || state.speedMs > 0 || state.godMode) && (
|
| 335 |
+
<div className="flex gap-2">
|
| 336 |
+
{state.magnetMs > 0 && <div className="bg-red-600/90 text-white rounded-lg px-3 py-1.5 text-sm font-semibold shadow flex items-center gap-2">🧲 Magnet · {(state.magnetMs / 1000).toFixed(1)}s</div>}
|
| 337 |
+
{state.speedMs > 0 && <div className="bg-yellow-500/90 text-yellow-950 rounded-lg px-3 py-1.5 text-sm font-semibold shadow flex items-center gap-2">⚡ Speed · {(state.speedMs / 1000).toFixed(1)}s</div>}
|
| 338 |
+
{state.godMode && <div className="bg-purple-600/90 text-white rounded-lg px-3 py-1.5 text-sm font-semibold shadow flex items-center gap-2">✨ God Mode</div>}
|
| 339 |
+
</div>
|
| 340 |
+
)}
|
| 341 |
+
</div>
|
| 342 |
+
)}
|
| 343 |
+
|
| 344 |
+
{/* Mini-map — bottom-right, always visible in-game */}
|
| 345 |
+
{inGame && (
|
| 346 |
+
<div className="absolute bottom-24 right-4 z-10 pointer-events-none">
|
| 347 |
+
<MiniMap data={state.miniMap} godMode={state.godMode} />
|
| 348 |
+
</div>
|
| 349 |
+
)}
|
| 350 |
+
|
| 351 |
+
{/* Sprint stamina bar */}
|
| 352 |
+
{state.status === "playing" && (
|
| 353 |
+
<div className="absolute bottom-28 left-4 z-10 pointer-events-none w-44">
|
| 354 |
+
<div className="bg-white/85 backdrop-blur rounded-lg p-2 shadow">
|
| 355 |
+
<div className="flex items-center justify-between text-[10px] uppercase tracking-wide text-emerald-700 font-semibold mb-1">
|
| 356 |
+
<span>Sprint (Shift)</span><span>{Math.round(state.sprintStamina * 100)}%</span>
|
| 357 |
+
</div>
|
| 358 |
+
<div className="h-1.5 bg-emerald-100 rounded-full overflow-hidden">
|
| 359 |
+
<div className={`h-full transition-[width] duration-100 ${state.isSprinting ? "bg-amber-500" : "bg-gradient-to-r from-emerald-400 to-emerald-600"}`} style={{ width: `${state.sprintStamina * 100}%` }} />
|
| 360 |
+
</div>
|
| 361 |
+
</div>
|
| 362 |
+
</div>
|
| 363 |
+
)}
|
| 364 |
+
|
| 365 |
+
{/* Scoreboard */}
|
| 366 |
+
{inGame && state.players.length > 0 && (
|
| 367 |
+
<div className="absolute top-4 right-56 mt-44 z-10 pointer-events-none">
|
| 368 |
+
<div className="bg-white/85 backdrop-blur rounded-xl shadow-lg p-3 min-w-[200px]">
|
| 369 |
+
<div className="text-[10px] uppercase tracking-wide text-emerald-700 font-semibold mb-2">Leaderboard</div>
|
| 370 |
+
<div className="space-y-1">
|
| 371 |
+
{state.players.slice(0, 8).map((p, idx) => (
|
| 372 |
+
<div key={p.id} className={`flex items-center gap-2 text-sm ${p.id === state.selfId ? "font-bold" : ""}`}>
|
| 373 |
+
<span className="w-4 text-right text-xs text-gray-500 tabular-nums">{idx + 1}.</span>
|
| 374 |
+
<span className="inline-block w-3 h-3 rounded-full flex-shrink-0" style={{ background: p.color }} />
|
| 375 |
+
<span className="flex-1 truncate text-emerald-900 flex items-center gap-1">
|
| 376 |
+
{state.mvpId === p.id && <span title="MVP">👑</span>}
|
| 377 |
+
{p.name}{p.id === state.selfId && <span className="text-emerald-600 ml-1 text-xs">(you)</span>}
|
| 378 |
+
</span>
|
| 379 |
+
<span className="tabular-nums text-emerald-900">{p.score}</span>
|
| 380 |
+
</div>
|
| 381 |
+
))}
|
| 382 |
+
</div>
|
| 383 |
+
</div>
|
| 384 |
+
</div>
|
| 385 |
+
)}
|
| 386 |
+
|
| 387 |
+
{/* Educational fact */}
|
| 388 |
+
{state.status === "playing" && state.fact && (
|
| 389 |
+
<div className="absolute bottom-24 left-1/2 -translate-x-1/2 z-20 max-w-md w-[90%] pointer-events-none">
|
| 390 |
+
<div className="bg-emerald-900/95 text-white rounded-xl shadow-2xl p-4 border-l-4 border-amber-400 animate-in fade-in slide-in-from-bottom-4">
|
| 391 |
+
<div className="text-xs uppercase tracking-wide text-amber-300 font-semibold mb-1">Did you know?</div>
|
| 392 |
+
<div className="text-sm leading-relaxed">{state.fact}</div>
|
| 393 |
+
</div>
|
| 394 |
+
</div>
|
| 395 |
+
)}
|
| 396 |
+
|
| 397 |
+
{/* Pickup/powerup notices */}
|
| 398 |
+
{state.status === "playing" && state.pickupNotice && (
|
| 399 |
+
<div className="absolute bottom-44 left-1/2 -translate-x-1/2 z-20 pointer-events-none">
|
| 400 |
+
<div className="bg-blue-900/90 text-white rounded-lg shadow-lg px-3 py-2 text-sm animate-in fade-in slide-in-from-bottom-2">
|
| 401 |
+
<span className="font-semibold">{state.pickupNotice.byName}</span>{" picked up "}{TRASH_LABELS[state.pickupNotice.trashType] ?? "trash"}
|
| 402 |
+
</div>
|
| 403 |
+
</div>
|
| 404 |
+
)}
|
| 405 |
+
{state.status === "playing" && state.powerUpNotice && (
|
| 406 |
+
<div className="absolute bottom-56 left-1/2 -translate-x-1/2 z-20 pointer-events-none">
|
| 407 |
+
<div className="bg-amber-700/90 text-white rounded-lg shadow-lg px-3 py-2 text-sm animate-in fade-in slide-in-from-bottom-2">
|
| 408 |
+
<span className="font-semibold">{state.powerUpNotice.byName}</span>{" grabbed "}
|
| 409 |
+
<span>{POWERUP_EMOJIS[state.powerUpNotice.kind]}</span>{" "}{POWERUP_LABELS[state.powerUpNotice.kind]}
|
| 410 |
+
{state.powerUpNotice.bonus > 0 ? ` (+${state.powerUpNotice.bonus})` : ""}
|
| 411 |
+
</div>
|
| 412 |
+
</div>
|
| 413 |
+
)}
|
| 414 |
+
|
| 415 |
+
{/* Combo + floating points */}
|
| 416 |
+
{state.status === "playing" && (state.combo || state.floatingPoints.length > 0) && (
|
| 417 |
+
<div className="absolute bottom-24 right-56 z-20 pointer-events-none flex flex-col items-end gap-2">
|
| 418 |
+
{state.combo && state.combo.combo > 1 && (
|
| 419 |
+
<div className="bg-amber-500/95 text-white rounded-xl shadow-lg px-4 py-2 min-w-[150px]">
|
| 420 |
+
<div className="text-xs uppercase tracking-wide text-amber-100 font-semibold">Combo</div>
|
| 421 |
+
<div className="text-2xl font-bold tabular-nums leading-none">{state.combo.combo}× streak</div>
|
| 422 |
+
<div className="mt-1 h-1.5 bg-amber-900/40 rounded-full overflow-hidden">
|
| 423 |
+
<div className="h-full bg-white transition-[width] duration-100" style={{ width: `${comboPct * 100}%` }} />
|
| 424 |
+
</div>
|
| 425 |
+
</div>
|
| 426 |
+
)}
|
| 427 |
+
<div className="flex flex-col items-end gap-1">
|
| 428 |
+
{state.floatingPoints.slice(-4).map(fp => (
|
| 429 |
+
<div key={fp.id} className={`px-3 py-1 rounded-full font-bold text-sm shadow-lg animate-in slide-in-from-bottom-2 fade-in ${fp.isCombo ? "bg-amber-400 text-amber-950" : "bg-emerald-600 text-white"}`}>
|
| 430 |
+
{fp.text}
|
| 431 |
+
</div>
|
| 432 |
+
))}
|
| 433 |
+
</div>
|
| 434 |
+
</div>
|
| 435 |
+
)}
|
| 436 |
+
|
| 437 |
+
{/* Emote bar */}
|
| 438 |
+
{inGame && (
|
| 439 |
+
<div className="absolute bottom-4 left-1/2 -translate-x-1/2 z-10 pointer-events-auto">
|
| 440 |
+
<div className="bg-white/85 backdrop-blur rounded-xl shadow px-2 py-1.5 flex items-center gap-1">
|
| 441 |
+
{EMOTES.map(e => (
|
| 442 |
+
<button key={e.kind} onClick={() => gameRef.current?.sendEmote(e.kind as EmoteKind)}
|
| 443 |
+
className="flex flex-col items-center justify-center w-10 h-10 rounded-lg hover:bg-emerald-100 transition"
|
| 444 |
+
title={`${e.kind} (press ${e.key})`}>
|
| 445 |
+
<span className="text-xl leading-none">{e.emoji}</span>
|
| 446 |
+
<span className="text-[9px] text-emerald-700 font-semibold leading-none mt-0.5">{e.key}</span>
|
| 447 |
+
</button>
|
| 448 |
+
))}
|
| 449 |
+
</div>
|
| 450 |
+
</div>
|
| 451 |
+
)}
|
| 452 |
+
|
| 453 |
+
{/* Controls helper */}
|
| 454 |
+
{state.status === "playing" && !state.isPaused && (
|
| 455 |
+
<div className="absolute bottom-20 left-4 z-10 pointer-events-none">
|
| 456 |
+
<div className="bg-black/65 backdrop-blur rounded-lg shadow px-3 py-2 text-xs text-white/90">
|
| 457 |
+
<div className="font-semibold mb-1 text-white">Controls</div>
|
| 458 |
+
<div>WASD / Arrows — Move</div>
|
| 459 |
+
<div>Shift — Sprint</div>
|
| 460 |
+
<div>Mouse — Look around</div>
|
| 461 |
+
<div>Walk over trash / power-ups</div>
|
| 462 |
+
<div>1–5 — Emote</div>
|
| 463 |
+
<div>P — Admin panel</div>
|
| 464 |
+
<div>ESC — Pause</div>
|
| 465 |
+
</div>
|
| 466 |
+
</div>
|
| 467 |
+
)}
|
| 468 |
+
|
| 469 |
+
{/* ── PAUSE MENU ────────────────────────────── */}
|
| 470 |
+
{state.isPaused && state.status === "playing" && (
|
| 471 |
+
<div className="absolute inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-md">
|
| 472 |
+
<div className="bg-white rounded-2xl shadow-2xl p-8 max-w-sm w-[90%] text-center">
|
| 473 |
+
<div className="text-5xl mb-3">⏸</div>
|
| 474 |
+
<h2 className="text-2xl font-bold text-emerald-900 mb-1">Game Paused</h2>
|
| 475 |
+
<p className="text-sm text-gray-600 mb-1">Other players keep playing. Your progress is saved.</p>
|
| 476 |
+
<div className="flex items-center justify-center gap-2 mb-5">
|
| 477 |
+
<span className={`text-xs font-bold px-2 py-0.5 rounded-full text-white ${MODE_COLORS[state.gameMode]}`}>{GAME_MODE_LABELS[state.gameMode]}</span>
|
| 478 |
+
<span className="text-xs text-gray-500">{LEVEL_LABELS[state.level]}</span>
|
| 479 |
+
</div>
|
| 480 |
+
<div className="space-y-2">
|
| 481 |
+
<button onClick={() => gameRef.current?.setPaused(false)} className="w-full py-3 bg-emerald-600 hover:bg-emerald-700 text-white font-semibold rounded-lg shadow transition">
|
| 482 |
+
▶ Resume
|
| 483 |
+
</button>
|
| 484 |
+
<button onClick={() => { gameRef.current?.setPaused(false); setShowSettings(true); }} className="w-full py-2 bg-gray-100 hover:bg-gray-200 text-gray-900 font-semibold rounded-lg shadow transition">
|
| 485 |
+
⚙️ Settings
|
| 486 |
+
</button>
|
| 487 |
+
<button onClick={() => { gameRef.current?.setPaused(false); setShowStats(true); }} className="w-full py-2 bg-gray-100 hover:bg-gray-200 text-gray-900 font-semibold rounded-lg shadow transition">
|
| 488 |
+
📊 Stats
|
| 489 |
+
</button>
|
| 490 |
+
<button onClick={() => { gameRef.current?.setPaused(false); gameRef.current?.backToMenu(); }} className="w-full py-2 bg-red-50 hover:bg-red-100 text-red-700 font-semibold rounded-lg shadow transition">
|
| 491 |
+
← Leave Game
|
| 492 |
+
</button>
|
| 493 |
+
</div>
|
| 494 |
+
<p className="text-[10px] text-gray-400 mt-4">Press ESC to resume</p>
|
| 495 |
+
</div>
|
| 496 |
+
</div>
|
| 497 |
+
)}
|
| 498 |
+
|
| 499 |
+
{/* Round-end overlay */}
|
| 500 |
+
{state.status === "waiting" && state.lastResult && (
|
| 501 |
+
<div className="absolute inset-0 z-20 flex items-center justify-center bg-black/40 backdrop-blur-sm pointer-events-none">
|
| 502 |
+
<div className="bg-white rounded-2xl shadow-2xl p-6 max-w-md w-[90%] text-center">
|
| 503 |
+
<div className="text-5xl mb-2">{state.lastResult.result === "won" ? "🎉" : "⏰"}</div>
|
| 504 |
+
<h2 className={`text-2xl font-bold mb-1 ${state.lastResult.result === "won" ? "text-emerald-700" : "text-red-600"}`}>
|
| 505 |
+
{state.lastResult.result === "won" ? "Environment Cleaned!" : "Time's Up!"}
|
| 506 |
+
</h2>
|
| 507 |
+
<p className="text-gray-700 text-sm mb-4">The team cleaned <strong>{state.lastResult.cleanedPct}%</strong> of the area.</p>
|
| 508 |
+
<div className="text-left bg-emerald-50 rounded-lg p-3 mb-4">
|
| 509 |
+
<div className="text-[10px] uppercase tracking-wide text-emerald-700 font-semibold mb-2">Final standings</div>
|
| 510 |
+
{state.lastResult.scores.map((s, i) => (
|
| 511 |
+
<div key={s.id} className="flex items-center gap-2 text-sm py-0.5">
|
| 512 |
+
<span className="w-5 text-right text-xs text-gray-500 tabular-nums">{i + 1}.</span>
|
| 513 |
+
<span className="inline-block w-3 h-3 rounded-full flex-shrink-0" style={{ background: s.color }} />
|
| 514 |
+
<span className="flex-1 truncate text-emerald-900 flex items-center gap-1">
|
| 515 |
+
{i === 0 && state.lastResult!.scores.length > 1 && <span title="MVP">👑</span>}
|
| 516 |
+
{s.name}
|
| 517 |
+
</span>
|
| 518 |
+
<span className="tabular-nums font-semibold text-emerald-900">{s.score}</span>
|
| 519 |
+
</div>
|
| 520 |
+
))}
|
| 521 |
+
</div>
|
| 522 |
+
<p className="text-sm text-emerald-700">Next round starting soon… hang tight!</p>
|
| 523 |
+
<p className="text-[10px] text-emerald-600 mt-3 italic">EcoClean 3D — Created by Utkarsh Pandey and Nishant Amrit</p>
|
| 524 |
+
</div>
|
| 525 |
+
</div>
|
| 526 |
+
)}
|
| 527 |
+
|
| 528 |
+
{/* Settings overlay */}
|
| 529 |
+
{showSettings && (
|
| 530 |
+
<div className="absolute inset-0 z-40 flex items-center justify-center bg-black/40 backdrop-blur-sm" onClick={() => setShowSettings(false)}>
|
| 531 |
+
<div className="bg-white rounded-2xl shadow-2xl p-6 max-w-md w-[90%]" onClick={e => e.stopPropagation()}>
|
| 532 |
+
<div className="flex items-center justify-between mb-3">
|
| 533 |
+
<h2 className="text-xl font-bold text-emerald-900">⚙️ Settings</h2>
|
| 534 |
+
<button onClick={() => setShowSettings(false)} className="text-emerald-700 text-2xl leading-none px-2 hover:bg-emerald-50 rounded">×</button>
|
| 535 |
+
</div>
|
| 536 |
+
<div className="space-y-4">
|
| 537 |
+
{[
|
| 538 |
+
{ label: "🎵 Music", value: state.musicVolume, fn: (v: number) => gameRef.current?.setMusicVolume(v), max: 1 },
|
| 539 |
+
{ label: "🔊 Sound effects", value: state.sfxVolume, fn: (v: number) => gameRef.current?.setSfxVolume(v), max: 1 },
|
| 540 |
+
].map(s => (
|
| 541 |
+
<label key={s.label} className="block">
|
| 542 |
+
<div className="flex justify-between text-sm font-semibold text-emerald-900 mb-1">
|
| 543 |
+
<span>{s.label}</span><span className="tabular-nums">{Math.round(s.value * 100)}%</span>
|
| 544 |
+
</div>
|
| 545 |
+
<input type="range" min={0} max={s.max} step={0.05} value={s.value} onChange={e => s.fn(parseFloat(e.target.value))} className="w-full" />
|
| 546 |
+
</label>
|
| 547 |
+
))}
|
| 548 |
+
<label className="block">
|
| 549 |
+
<div className="flex justify-between text-sm font-semibold text-emerald-900 mb-1">
|
| 550 |
+
<span>🖱️ Mouse sensitivity</span><span className="tabular-nums">{state.mouseSensitivity.toFixed(2)}×</span>
|
| 551 |
+
</div>
|
| 552 |
+
<input type="range" min={0.25} max={2.5} step={0.05} value={state.mouseSensitivity} onChange={e => gameRef.current?.setMouseSensitivity(parseFloat(e.target.value))} className="w-full" />
|
| 553 |
+
</label>
|
| 554 |
+
<button onClick={() => gameRef.current?.toggleSound()} className={`w-full py-2 rounded-lg font-semibold text-white shadow ${state.soundOn ? "bg-emerald-600 hover:bg-emerald-700" : "bg-gray-500 hover:bg-gray-600"}`}>
|
| 555 |
+
{state.soundOn ? "🔊 Sound is On" : "🔈 Sound is Off"}
|
| 556 |
+
</button>
|
| 557 |
+
</div>
|
| 558 |
+
</div>
|
| 559 |
+
</div>
|
| 560 |
+
)}
|
| 561 |
+
|
| 562 |
+
{/* Stats overlay */}
|
| 563 |
+
{showStats && (
|
| 564 |
+
<div className="absolute inset-0 z-40 flex items-center justify-center bg-black/40 backdrop-blur-sm" onClick={() => setShowStats(false)}>
|
| 565 |
+
<div className="bg-white rounded-2xl shadow-2xl p-6 max-w-sm w-[90%]" onClick={e => e.stopPropagation()}>
|
| 566 |
+
<div className="flex items-center justify-between mb-3">
|
| 567 |
+
<h2 className="text-xl font-bold text-emerald-900">📊 Stats</h2>
|
| 568 |
+
<button onClick={() => setShowStats(false)} className="text-emerald-700 text-2xl leading-none px-2 hover:bg-emerald-50 rounded">×</button>
|
| 569 |
+
</div>
|
| 570 |
+
<div className="grid grid-cols-2 gap-3 text-center">
|
| 571 |
+
<div className="bg-emerald-50 rounded-lg p-3"><div className="text-2xl font-bold text-emerald-900">{state.stats.trashCleaned}</div><div className="text-xs text-emerald-700 uppercase tracking-wide">Trash cleaned</div></div>
|
| 572 |
+
<div className="bg-amber-50 rounded-lg p-3"><div className="text-2xl font-bold text-amber-900">{state.stats.powerUpsCollected}</div><div className="text-xs text-amber-700 uppercase tracking-wide">Power-ups</div></div>
|
| 573 |
+
<div className="bg-rose-50 rounded-lg p-3"><div className="text-2xl font-bold text-rose-900">{state.stats.bestCombo}×</div><div className="text-xs text-rose-700 uppercase tracking-wide">Best combo</div></div>
|
| 574 |
+
<div className="bg-sky-50 rounded-lg p-3"><div className="text-2xl font-bold text-sky-900">{state.stats.pointsEarned}</div><div className="text-xs text-sky-700 uppercase tracking-wide">Points</div></div>
|
| 575 |
+
</div>
|
| 576 |
+
</div>
|
| 577 |
+
</div>
|
| 578 |
+
)}
|
| 579 |
+
|
| 580 |
+
{/* Owner login */}
|
| 581 |
+
{showOwnerLogin && (
|
| 582 |
+
<div className="absolute inset-0 z-40 flex items-center justify-center bg-black/40 backdrop-blur-sm" onClick={() => setShowOwnerLogin(false)}>
|
| 583 |
+
<div className="bg-white rounded-2xl shadow-2xl p-6 max-w-sm w-[90%]" onClick={e => e.stopPropagation()}>
|
| 584 |
+
<div className="flex items-center justify-between mb-3">
|
| 585 |
+
<h2 className="text-xl font-bold text-purple-900">🔐 Owner Sign-in</h2>
|
| 586 |
+
<button onClick={() => setShowOwnerLogin(false)} className="text-purple-700 text-2xl leading-none px-2 hover:bg-purple-50 rounded">×</button>
|
| 587 |
+
</div>
|
| 588 |
+
<p className="text-sm text-gray-600 mb-3">Enter the owner password to unlock admin commands for this room.</p>
|
| 589 |
+
<input type="password" value={ownerPwInput} onChange={e => setOwnerPwInput(e.target.value)}
|
| 590 |
+
onKeyDown={e => { if (e.key === "Enter") { handleSubmitOwner(); setShowOwnerLogin(false); } }}
|
| 591 |
+
placeholder="Owner password" autoFocus
|
| 592 |
+
className="w-full border-2 border-purple-200 focus:border-purple-500 focus:outline-none rounded-lg px-3 py-2 text-purple-900 mb-3" />
|
| 593 |
+
{state.ownerStatus && !state.ownerStatus.ok && (
|
| 594 |
+
<div className="mb-3 text-sm text-red-700 bg-red-50 border border-red-200 rounded px-3 py-2">{state.ownerStatus.message}</div>
|
| 595 |
+
)}
|
| 596 |
+
<button onClick={() => { handleSubmitOwner(); setShowOwnerLogin(false); }} disabled={!ownerPwInput.trim()}
|
| 597 |
+
className="w-full py-2 rounded-lg font-semibold text-white shadow bg-purple-600 hover:bg-purple-700 disabled:bg-purple-300">
|
| 598 |
+
Unlock Owner Mode
|
| 599 |
+
</button>
|
| 600 |
+
</div>
|
| 601 |
+
</div>
|
| 602 |
+
)}
|
| 603 |
+
|
| 604 |
+
{/* Owner panel */}
|
| 605 |
+
{showOwnerPanel && state.isOwner && (
|
| 606 |
+
<div className="absolute inset-0 z-40 flex items-center justify-center bg-black/40 backdrop-blur-sm" onClick={() => setShowOwnerPanel(false)}>
|
| 607 |
+
<div className="bg-white rounded-2xl shadow-2xl p-6 max-w-lg w-[92%] max-h-[90vh] overflow-y-auto" onClick={e => e.stopPropagation()}>
|
| 608 |
+
<div className="flex items-center justify-between mb-3">
|
| 609 |
+
<h2 className="text-xl font-bold text-purple-900">👑 Owner Panel</h2>
|
| 610 |
+
<button onClick={() => setShowOwnerPanel(false)} className="text-purple-700 text-2xl leading-none px-2 hover:bg-purple-50 rounded">×</button>
|
| 611 |
+
</div>
|
| 612 |
+
{state.ownerStatus?.ok && <div className="mb-3 text-sm text-emerald-700 bg-emerald-50 border border-emerald-200 rounded px-3 py-2">{state.ownerStatus.message}</div>}
|
| 613 |
+
<div className="mb-4">
|
| 614 |
+
<div className="text-xs uppercase tracking-wide text-purple-700 font-semibold mb-2">Round</div>
|
| 615 |
+
<div className="grid grid-cols-2 gap-2">
|
| 616 |
+
<button onClick={() => sendAdmin({ kind: "endRound", result: "won" })} className="bg-emerald-600 hover:bg-emerald-700 text-white text-sm font-semibold py-2 rounded shadow">End round (Win)</button>
|
| 617 |
+
<button onClick={() => sendAdmin({ kind: "endRound", result: "lost" })} className="bg-red-600 hover:bg-red-700 text-white text-sm font-semibold py-2 rounded shadow">End round (Lose)</button>
|
| 618 |
+
</div>
|
| 619 |
+
<div className="mt-2 flex items-center gap-2">
|
| 620 |
+
<input type="number" min={5} max={600} value={adminTimerInput} onChange={e => setAdminTimerInput(e.target.value)}
|
| 621 |
+
className="border-2 border-purple-200 focus:border-purple-500 focus:outline-none rounded px-2 py-1 w-24 text-purple-900" />
|
| 622 |
+
<button onClick={() => sendAdmin({ kind: "setTimer", seconds: parseInt(adminTimerInput, 10) || 60 })}
|
| 623 |
+
className="flex-1 bg-purple-600 hover:bg-purple-700 text-white text-sm font-semibold py-1.5 rounded shadow">Set timer (sec)</button>
|
| 624 |
+
</div>
|
| 625 |
+
</div>
|
| 626 |
+
<div className="mb-4">
|
| 627 |
+
<div className="text-xs uppercase tracking-wide text-purple-700 font-semibold mb-2">Spawn</div>
|
| 628 |
+
<div className="grid grid-cols-2 gap-2 mb-2">
|
| 629 |
+
<button onClick={() => sendAdmin({ kind: "spawnTrash", count: 10 })} className="bg-amber-600 hover:bg-amber-700 text-white text-sm font-semibold py-2 rounded shadow">+10 trash</button>
|
| 630 |
+
<button onClick={() => sendAdmin({ kind: "spawnTrash", count: 20 })} className="bg-amber-600 hover:bg-amber-700 text-white text-sm font-semibold py-2 rounded shadow">+20 trash</button>
|
| 631 |
+
</div>
|
| 632 |
+
<div className="grid grid-cols-3 gap-2">
|
| 633 |
+
{POWERUP_KINDS.map(k => (
|
| 634 |
+
<button key={k} onClick={() => sendAdmin({ kind: "spawnPowerUp", powerUp: k })} className="bg-fuchsia-600 hover:bg-fuchsia-700 text-white text-sm font-semibold py-2 rounded shadow">
|
| 635 |
+
{POWERUP_EMOJIS[k]} {POWERUP_LABELS[k]}
|
| 636 |
+
</button>
|
| 637 |
+
))}
|
| 638 |
+
</div>
|
| 639 |
+
</div>
|
| 640 |
+
{state.players.filter(p => p.id !== state.selfId).length > 0 && (
|
| 641 |
+
<div className="mb-4">
|
| 642 |
+
<div className="text-xs uppercase tracking-wide text-purple-700 font-semibold mb-2">Players</div>
|
| 643 |
+
<div className="space-y-1 max-h-40 overflow-y-auto">
|
| 644 |
+
{state.players.filter(p => p.id !== state.selfId).map(p => (
|
| 645 |
+
<div key={p.id} className="flex items-center gap-2 text-sm bg-purple-50 rounded px-2 py-1">
|
| 646 |
+
<span className="inline-block w-3 h-3 rounded-full flex-shrink-0" style={{ background: p.color }} />
|
| 647 |
+
<span className="flex-1 truncate text-purple-900">{p.name}</span>
|
| 648 |
+
<button onClick={() => sendAdmin({ kind: "kick", playerId: p.id })} className="bg-red-600 hover:bg-red-700 text-white text-xs font-semibold px-2 py-1 rounded">Kick</button>
|
| 649 |
+
</div>
|
| 650 |
+
))}
|
| 651 |
+
</div>
|
| 652 |
+
</div>
|
| 653 |
+
)}
|
| 654 |
+
<div className="mb-4">
|
| 655 |
+
<div className="text-xs uppercase tracking-wide text-purple-700 font-semibold mb-2">Local</div>
|
| 656 |
+
<button onClick={() => gameRef.current?.setGodMode(!state.godMode)} className={`w-full py-2 rounded font-semibold text-white shadow ${state.godMode ? "bg-purple-700 hover:bg-purple-800" : "bg-gray-500 hover:bg-gray-600"}`}>
|
| 657 |
+
{state.godMode ? "✨ God Mode: ON" : "God Mode: OFF"}
|
| 658 |
+
</button>
|
| 659 |
+
</div>
|
| 660 |
+
<p className="text-[10px] text-gray-500 text-center">Owner commands are gated by password on the server.</p>
|
| 661 |
+
</div>
|
| 662 |
+
</div>
|
| 663 |
+
)}
|
| 664 |
+
|
| 665 |
+
{/* Connecting */}
|
| 666 |
+
{state.status === "connecting" && (
|
| 667 |
+
<div className="absolute inset-0 z-30 flex items-center justify-center bg-gradient-to-b from-sky-400/40 to-emerald-700/60 backdrop-blur-sm">
|
| 668 |
+
<div className="bg-white rounded-2xl shadow-2xl p-8 max-w-sm w-[90%] text-center">
|
| 669 |
+
<div className="text-4xl mb-3 animate-spin">🌍</div>
|
| 670 |
+
<h2 className="text-xl font-bold text-emerald-900 mb-1">Connecting…</h2>
|
| 671 |
+
<p className="text-sm text-gray-600">Joining the {LEVEL_LABELS[state.level]} cleanup crew.</p>
|
| 672 |
+
</div>
|
| 673 |
+
</div>
|
| 674 |
+
)}
|
| 675 |
+
|
| 676 |
+
{/* Disconnected */}
|
| 677 |
+
{state.status === "disconnected" && (
|
| 678 |
+
<div className="absolute inset-0 z-30 flex items-center justify-center bg-black/50 backdrop-blur-sm">
|
| 679 |
+
<div className="bg-white rounded-2xl shadow-2xl p-8 max-w-md w-[90%] text-center">
|
| 680 |
+
<div className="text-5xl mb-3">📡</div>
|
| 681 |
+
<h2 className="text-2xl font-bold text-red-600 mb-2">Disconnected</h2>
|
| 682 |
+
<p className="text-gray-700 mb-4">Lost connection to the server. Check your internet and try again.</p>
|
| 683 |
+
<button onClick={() => gameRef.current?.backToMenu()} className="bg-emerald-600 hover:bg-emerald-700 text-white font-semibold py-3 px-6 rounded-lg shadow transition">Back to Menu</button>
|
| 684 |
+
</div>
|
| 685 |
+
</div>
|
| 686 |
+
)}
|
| 687 |
+
|
| 688 |
+
{/* ── MAIN MENU ─────────────────────────────── */}
|
| 689 |
+
{state.status === "menu" && (
|
| 690 |
+
<div className="absolute inset-0 z-30 flex items-center justify-center bg-gradient-to-b from-sky-400/40 to-emerald-700/60 backdrop-blur-sm overflow-y-auto p-4">
|
| 691 |
+
<div className="bg-white rounded-2xl shadow-2xl p-8 max-w-lg w-full text-center my-auto">
|
| 692 |
+
<div className="text-5xl mb-2">🌍</div>
|
| 693 |
+
<h1 className="text-3xl font-bold text-emerald-900 mb-1">EcoClean 3D</h1>
|
| 694 |
+
<p className="text-emerald-800 mb-1">Multiplayer cleanup. One world. One team.</p>
|
| 695 |
+
<p className="text-sm text-emerald-700 mb-4">Pick a game mode, choose your map, and clean up together!</p>
|
| 696 |
+
|
| 697 |
+
{state.errorMessage && (
|
| 698 |
+
<div className="mb-4 bg-red-50 border border-red-200 rounded-lg px-3 py-2 text-sm text-red-700 text-left">⚠️ {state.errorMessage}</div>
|
| 699 |
+
)}
|
| 700 |
+
|
| 701 |
+
{/* Player name */}
|
| 702 |
+
<div className="mb-4 text-left">
|
| 703 |
+
<label htmlFor="player-name" className="block text-xs uppercase tracking-wide text-emerald-700 font-semibold mb-1">Your name</label>
|
| 704 |
+
<input id="player-name" type="text" value={name} onChange={e => setName(e.target.value)} maxLength={18} placeholder="Enter your name"
|
| 705 |
+
className="w-full border-2 border-emerald-200 focus:border-emerald-500 focus:outline-none rounded-lg px-3 py-2 text-emerald-900" />
|
| 706 |
+
</div>
|
| 707 |
+
|
| 708 |
+
{/* ── LOBBY FLOW: mode → map ── */}
|
| 709 |
+
{lobbyStep === null && (
|
| 710 |
+
<>
|
| 711 |
+
{/* Quick join public */}
|
| 712 |
+
<div className="text-left mb-4">
|
| 713 |
+
<div className="text-xs uppercase tracking-wide text-emerald-700 font-semibold mb-2">Join a public room</div>
|
| 714 |
+
<button onClick={() => setLobbyStep("mode")}
|
| 715 |
+
className="w-full bg-emerald-600 hover:bg-emerald-700 text-white font-semibold py-3 rounded-lg shadow transition flex items-center justify-center gap-2">
|
| 716 |
+
<span>🎮 Select Game Mode + Map</span>
|
| 717 |
+
<span className="text-emerald-200 text-sm">→</span>
|
| 718 |
+
</button>
|
| 719 |
+
</div>
|
| 720 |
+
|
| 721 |
+
{/* Join with code */}
|
| 722 |
+
<div className="text-left mb-4 bg-sky-50 rounded-lg p-3">
|
| 723 |
+
<div className="text-xs uppercase tracking-wide text-sky-800 font-semibold mb-2">Join with a room code</div>
|
| 724 |
+
<div className="flex gap-2">
|
| 725 |
+
<input type="text" value={joinCode}
|
| 726 |
+
onChange={e => setJoinCode(e.target.value.toUpperCase().replace(/[^A-Z0-9\-]/g, "").slice(0, 10))}
|
| 727 |
+
onKeyDown={e => { if (e.key === "Enter") handleJoinCode(); }}
|
| 728 |
+
placeholder="ROOM-CODE" className="flex-1 border-2 border-sky-200 focus:border-sky-500 focus:outline-none rounded-lg px-3 py-2 text-sky-900 font-bold tracking-widest tabular-nums uppercase" />
|
| 729 |
+
<button onClick={handleJoinCode} disabled={!joinCode.trim()}
|
| 730 |
+
className="bg-sky-600 hover:bg-sky-700 disabled:bg-sky-300 text-white font-semibold px-4 rounded-lg shadow transition">Join</button>
|
| 731 |
+
</div>
|
| 732 |
+
</div>
|
| 733 |
+
|
| 734 |
+
{/* Private room */}
|
| 735 |
+
<div className="text-left mb-4 bg-amber-50 rounded-lg p-3">
|
| 736 |
+
<button onClick={() => setShowPrivate(v => !v)} className="w-full flex items-center justify-between text-xs uppercase tracking-wide text-amber-800 font-semibold">
|
| 737 |
+
<span>🔒 Create a private room</span>
|
| 738 |
+
<span className="text-base">{showPrivate ? "−" : "+"}</span>
|
| 739 |
+
</button>
|
| 740 |
+
{showPrivate && (
|
| 741 |
+
<>
|
| 742 |
+
<p className="text-xs text-amber-800 mt-2 mb-2">A new code will be generated. Share it with friends to join the same room.</p>
|
| 743 |
+
|
| 744 |
+
<div className="text-[10px] uppercase tracking-wide text-amber-800 font-semibold mb-1 mt-2">Game Mode</div>
|
| 745 |
+
<div className="grid grid-cols-3 gap-2 mb-3">
|
| 746 |
+
{(["speedrun", "percent100", "powerup"] as const).map(m => (
|
| 747 |
+
<button key={m} onClick={() => setPrivateMode(m)}
|
| 748 |
+
className={`text-xs font-bold py-2 px-1 rounded-lg shadow transition ${privateMode === m ? `${MODE_COLORS[m]} text-white` : "bg-white text-gray-700 hover:bg-gray-100"}`}>
|
| 749 |
+
{GAME_MODE_LABELS[m]}
|
| 750 |
+
</button>
|
| 751 |
+
))}
|
| 752 |
+
</div>
|
| 753 |
+
<p className="text-[10px] text-amber-700 mb-2 italic">{GAME_MODE_DESCRIPTIONS[privateMode]}</p>
|
| 754 |
+
|
| 755 |
+
<div className="text-[10px] uppercase tracking-wide text-amber-800 font-semibold mb-1">Difficulty</div>
|
| 756 |
+
<div className="grid grid-cols-3 gap-2 mb-2">
|
| 757 |
+
{(["easy", "normal", "hard"] as const).map(d => (
|
| 758 |
+
<button key={d} onClick={() => setPrivateDifficulty(d)}
|
| 759 |
+
className={`text-sm font-semibold py-2 rounded shadow transition ${privateDifficulty === d ? "bg-amber-600 text-white" : "bg-white text-amber-900 hover:bg-amber-100"}`}>
|
| 760 |
+
{DIFFICULTY_LABELS[d]}
|
| 761 |
+
</button>
|
| 762 |
+
))}
|
| 763 |
+
</div>
|
| 764 |
+
<p className="text-[11px] text-amber-700 mb-2 italic">{DIFFICULTY_BLURBS[privateDifficulty]}</p>
|
| 765 |
+
|
| 766 |
+
<div className="text-[10px] uppercase tracking-wide text-amber-800 font-semibold mb-1">Choose Map</div>
|
| 767 |
+
<div className="grid grid-cols-3 gap-2">
|
| 768 |
+
{ALL_LEVELS.map(lvl => (
|
| 769 |
+
<button key={lvl} onClick={() => handleCreatePrivate(lvl)}
|
| 770 |
+
className="bg-amber-500 hover:bg-amber-600 text-white text-xs font-semibold py-2 rounded-lg shadow transition">
|
| 771 |
+
{LEVEL_LABELS[lvl]}
|
| 772 |
+
</button>
|
| 773 |
+
))}
|
| 774 |
+
</div>
|
| 775 |
+
</>
|
| 776 |
+
)}
|
| 777 |
+
</div>
|
| 778 |
+
|
| 779 |
+
{/* Tips */}
|
| 780 |
+
<div className="text-xs text-emerald-700 space-y-1 text-left bg-emerald-50 rounded-lg p-3 mb-3">
|
| 781 |
+
<div>♻️ <strong>+10 pts</strong> per trash · combo multiplier for fast pickups</div>
|
| 782 |
+
<div>🧲⚡⭐ <strong>Power-ups</strong> spawn mid-round — grab them fast</div>
|
| 783 |
+
<div>🏃 <strong>Shift</strong> to sprint · 1–5 to emote · ESC to pause</div>
|
| 784 |
+
<div>👑 Top scorer wears the <strong>MVP crown</strong></div>
|
| 785 |
+
</div>
|
| 786 |
+
|
| 787 |
+
<div className="mt-1 flex gap-2 justify-center">
|
| 788 |
+
<button onClick={() => setShowSettings(true)} className="text-xs text-emerald-700 hover:text-emerald-900 underline">⚙️ Settings</button>
|
| 789 |
+
<span className="text-emerald-300">·</span>
|
| 790 |
+
<button onClick={() => setShowOwnerLogin(true)} className="text-xs text-purple-700 hover:text-purple-900 underline">🔐 Owner sign-in</button>
|
| 791 |
+
</div>
|
| 792 |
+
<p className="text-[11px] text-emerald-600 mt-4 italic">Created by Utkarsh Pandey and Nishant Amrit</p>
|
| 793 |
+
</>
|
| 794 |
+
)}
|
| 795 |
+
|
| 796 |
+
{/* Step 1: Pick game mode */}
|
| 797 |
+
{lobbyStep === "mode" && (
|
| 798 |
+
<div className="text-left animate-in fade-in">
|
| 799 |
+
<button onClick={() => setLobbyStep(null)} className="text-xs text-emerald-600 hover:text-emerald-800 mb-3 flex items-center gap-1">← Back</button>
|
| 800 |
+
<h2 className="text-lg font-bold text-emerald-900 mb-4 text-center">Choose Game Mode</h2>
|
| 801 |
+
<div className="space-y-3">
|
| 802 |
+
{(["speedrun", "percent100", "powerup"] as const).map(m => (
|
| 803 |
+
<button key={m} onClick={() => { setLobbyMode(m); setLobbyStep("map"); }}
|
| 804 |
+
className={`w-full rounded-xl p-4 text-left shadow-md border-2 transition hover:scale-[1.01] ${lobbyMode === m ? "border-emerald-500 bg-emerald-50" : "border-gray-100 bg-white hover:border-emerald-300"}`}>
|
| 805 |
+
<div className="flex items-center gap-3 mb-1">
|
| 806 |
+
<span className={`text-xs font-bold px-2 py-0.5 rounded-full text-white ${MODE_COLORS[m]}`}>{GAME_MODE_LABELS[m]}</span>
|
| 807 |
+
</div>
|
| 808 |
+
<p className="text-sm text-gray-600 leading-snug">{GAME_MODE_DESCRIPTIONS[m]}</p>
|
| 809 |
+
</button>
|
| 810 |
+
))}
|
| 811 |
+
</div>
|
| 812 |
+
</div>
|
| 813 |
+
)}
|
| 814 |
+
|
| 815 |
+
{/* Step 2: Pick map */}
|
| 816 |
+
{lobbyStep === "map" && lobbyMode && (
|
| 817 |
+
<div className="text-left animate-in fade-in">
|
| 818 |
+
<button onClick={() => setLobbyStep("mode")} className="text-xs text-emerald-600 hover:text-emerald-800 mb-3 flex items-center gap-1">← Back</button>
|
| 819 |
+
<div className="flex items-center gap-2 mb-4">
|
| 820 |
+
<h2 className="text-lg font-bold text-emerald-900">Choose Map</h2>
|
| 821 |
+
<span className={`text-xs font-bold px-2 py-0.5 rounded-full text-white ${MODE_COLORS[lobbyMode]}`}>{GAME_MODE_LABELS[lobbyMode]}</span>
|
| 822 |
+
</div>
|
| 823 |
+
<div className="grid grid-cols-2 gap-3">
|
| 824 |
+
{ALL_LEVELS.map(lvl => {
|
| 825 |
+
const desc: Record<Level, string> = {
|
| 826 |
+
park: "Lush green park with trees & flowers",
|
| 827 |
+
beach: "Sandy shore with palm trees & ocean",
|
| 828 |
+
city: "Busy urban streets & tall buildings",
|
| 829 |
+
nightcity: "Neon-lit cyberpunk city at night",
|
| 830 |
+
arctic: "Frozen tundra with ice & blizzards",
|
| 831 |
+
jungle: "Dense tropical rainforest with mist",
|
| 832 |
+
};
|
| 833 |
+
return (
|
| 834 |
+
<button key={lvl} onClick={() => handleJoinPublic(lvl)}
|
| 835 |
+
className="rounded-xl p-3 text-left shadow border-2 border-gray-100 hover:border-emerald-400 bg-white hover:bg-emerald-50 transition hover:scale-[1.01]">
|
| 836 |
+
<div className="text-xl mb-0.5">{LEVEL_LABELS[lvl].split(" ")[0]}</div>
|
| 837 |
+
<div className="text-sm font-bold text-emerald-900">{LEVEL_LABELS[lvl].slice(LEVEL_LABELS[lvl].indexOf(" ") + 1)}</div>
|
| 838 |
+
<div className="text-[11px] text-gray-500 mt-0.5 leading-snug">{desc[lvl]}</div>
|
| 839 |
+
</button>
|
| 840 |
+
);
|
| 841 |
+
})}
|
| 842 |
+
</div>
|
| 843 |
+
</div>
|
| 844 |
+
)}
|
| 845 |
+
</div>
|
| 846 |
+
</div>
|
| 847 |
+
)}
|
| 848 |
+
|
| 849 |
+
{/* Unsupported */}
|
| 850 |
+
{state.status === "unsupported" && (
|
| 851 |
+
<div className="absolute inset-0 z-30 flex items-center justify-center bg-gradient-to-b from-sky-400/40 to-emerald-700/60 backdrop-blur-sm">
|
| 852 |
+
<div className="bg-white rounded-2xl shadow-2xl p-8 max-w-md w-[90%] text-center">
|
| 853 |
+
<div className="text-5xl mb-3">🌐</div>
|
| 854 |
+
<h2 className="text-2xl font-bold text-emerald-900 mb-2">WebGL not available</h2>
|
| 855 |
+
<p className="text-gray-700">This 3D game needs a WebGL-capable browser. Try Chrome, Firefox, Edge, or Safari.</p>
|
| 856 |
+
</div>
|
| 857 |
+
</div>
|
| 858 |
+
)}
|
| 859 |
+
</div>
|
| 860 |
+
);
|
| 861 |
+
}
|
| 862 |
+
|
| 863 |
+
export default App;
|
artifacts/eco-cleanup-game/src/components/ui/accordion.tsx
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import * as AccordionPrimitive from "@radix-ui/react-accordion"
|
| 3 |
+
import { ChevronDown } from "lucide-react"
|
| 4 |
+
|
| 5 |
+
import { cn } from "@/lib/utils"
|
| 6 |
+
|
| 7 |
+
const Accordion = AccordionPrimitive.Root
|
| 8 |
+
|
| 9 |
+
const AccordionItem = React.forwardRef<
|
| 10 |
+
React.ElementRef<typeof AccordionPrimitive.Item>,
|
| 11 |
+
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
|
| 12 |
+
>(({ className, ...props }, ref) => (
|
| 13 |
+
<AccordionPrimitive.Item
|
| 14 |
+
ref={ref}
|
| 15 |
+
className={cn("border-b", className)}
|
| 16 |
+
{...props}
|
| 17 |
+
/>
|
| 18 |
+
))
|
| 19 |
+
AccordionItem.displayName = "AccordionItem"
|
| 20 |
+
|
| 21 |
+
const AccordionTrigger = React.forwardRef<
|
| 22 |
+
React.ElementRef<typeof AccordionPrimitive.Trigger>,
|
| 23 |
+
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
|
| 24 |
+
>(({ className, children, ...props }, ref) => (
|
| 25 |
+
<AccordionPrimitive.Header className="flex">
|
| 26 |
+
<AccordionPrimitive.Trigger
|
| 27 |
+
ref={ref}
|
| 28 |
+
className={cn(
|
| 29 |
+
"flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline text-left [&[data-state=open]>svg]:rotate-180",
|
| 30 |
+
className
|
| 31 |
+
)}
|
| 32 |
+
{...props}
|
| 33 |
+
>
|
| 34 |
+
{children}
|
| 35 |
+
<ChevronDown className="h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200" />
|
| 36 |
+
</AccordionPrimitive.Trigger>
|
| 37 |
+
</AccordionPrimitive.Header>
|
| 38 |
+
))
|
| 39 |
+
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
|
| 40 |
+
|
| 41 |
+
const AccordionContent = React.forwardRef<
|
| 42 |
+
React.ElementRef<typeof AccordionPrimitive.Content>,
|
| 43 |
+
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
|
| 44 |
+
>(({ className, children, ...props }, ref) => (
|
| 45 |
+
<AccordionPrimitive.Content
|
| 46 |
+
ref={ref}
|
| 47 |
+
className="overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
|
| 48 |
+
{...props}
|
| 49 |
+
>
|
| 50 |
+
<div className={cn("pb-4 pt-0", className)}>{children}</div>
|
| 51 |
+
</AccordionPrimitive.Content>
|
| 52 |
+
))
|
| 53 |
+
AccordionContent.displayName = AccordionPrimitive.Content.displayName
|
| 54 |
+
|
| 55 |
+
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|
artifacts/eco-cleanup-game/src/components/ui/alert-dialog.tsx
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
|
| 3 |
+
|
| 4 |
+
import { cn } from "@/lib/utils"
|
| 5 |
+
import { buttonVariants } from "@/components/ui/button"
|
| 6 |
+
|
| 7 |
+
const AlertDialog = AlertDialogPrimitive.Root
|
| 8 |
+
|
| 9 |
+
const AlertDialogTrigger = AlertDialogPrimitive.Trigger
|
| 10 |
+
|
| 11 |
+
const AlertDialogPortal = AlertDialogPrimitive.Portal
|
| 12 |
+
|
| 13 |
+
const AlertDialogOverlay = React.forwardRef<
|
| 14 |
+
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
|
| 15 |
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
|
| 16 |
+
>(({ className, ...props }, ref) => (
|
| 17 |
+
<AlertDialogPrimitive.Overlay
|
| 18 |
+
className={cn(
|
| 19 |
+
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
| 20 |
+
className
|
| 21 |
+
)}
|
| 22 |
+
{...props}
|
| 23 |
+
ref={ref}
|
| 24 |
+
/>
|
| 25 |
+
))
|
| 26 |
+
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName
|
| 27 |
+
|
| 28 |
+
const AlertDialogContent = React.forwardRef<
|
| 29 |
+
React.ElementRef<typeof AlertDialogPrimitive.Content>,
|
| 30 |
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
|
| 31 |
+
>(({ className, ...props }, ref) => (
|
| 32 |
+
<AlertDialogPortal>
|
| 33 |
+
<AlertDialogOverlay />
|
| 34 |
+
<AlertDialogPrimitive.Content
|
| 35 |
+
ref={ref}
|
| 36 |
+
className={cn(
|
| 37 |
+
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
| 38 |
+
className
|
| 39 |
+
)}
|
| 40 |
+
{...props}
|
| 41 |
+
/>
|
| 42 |
+
</AlertDialogPortal>
|
| 43 |
+
))
|
| 44 |
+
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName
|
| 45 |
+
|
| 46 |
+
const AlertDialogHeader = ({
|
| 47 |
+
className,
|
| 48 |
+
...props
|
| 49 |
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
| 50 |
+
<div
|
| 51 |
+
className={cn(
|
| 52 |
+
"flex flex-col space-y-2 text-center sm:text-left",
|
| 53 |
+
className
|
| 54 |
+
)}
|
| 55 |
+
{...props}
|
| 56 |
+
/>
|
| 57 |
+
)
|
| 58 |
+
AlertDialogHeader.displayName = "AlertDialogHeader"
|
| 59 |
+
|
| 60 |
+
const AlertDialogFooter = ({
|
| 61 |
+
className,
|
| 62 |
+
...props
|
| 63 |
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
| 64 |
+
<div
|
| 65 |
+
className={cn(
|
| 66 |
+
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
| 67 |
+
className
|
| 68 |
+
)}
|
| 69 |
+
{...props}
|
| 70 |
+
/>
|
| 71 |
+
)
|
| 72 |
+
AlertDialogFooter.displayName = "AlertDialogFooter"
|
| 73 |
+
|
| 74 |
+
const AlertDialogTitle = React.forwardRef<
|
| 75 |
+
React.ElementRef<typeof AlertDialogPrimitive.Title>,
|
| 76 |
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
|
| 77 |
+
>(({ className, ...props }, ref) => (
|
| 78 |
+
<AlertDialogPrimitive.Title
|
| 79 |
+
ref={ref}
|
| 80 |
+
className={cn("text-lg font-semibold", className)}
|
| 81 |
+
{...props}
|
| 82 |
+
/>
|
| 83 |
+
))
|
| 84 |
+
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName
|
| 85 |
+
|
| 86 |
+
const AlertDialogDescription = React.forwardRef<
|
| 87 |
+
React.ElementRef<typeof AlertDialogPrimitive.Description>,
|
| 88 |
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
|
| 89 |
+
>(({ className, ...props }, ref) => (
|
| 90 |
+
<AlertDialogPrimitive.Description
|
| 91 |
+
ref={ref}
|
| 92 |
+
className={cn("text-sm text-muted-foreground", className)}
|
| 93 |
+
{...props}
|
| 94 |
+
/>
|
| 95 |
+
))
|
| 96 |
+
AlertDialogDescription.displayName =
|
| 97 |
+
AlertDialogPrimitive.Description.displayName
|
| 98 |
+
|
| 99 |
+
const AlertDialogAction = React.forwardRef<
|
| 100 |
+
React.ElementRef<typeof AlertDialogPrimitive.Action>,
|
| 101 |
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
|
| 102 |
+
>(({ className, ...props }, ref) => (
|
| 103 |
+
<AlertDialogPrimitive.Action
|
| 104 |
+
ref={ref}
|
| 105 |
+
className={cn(buttonVariants(), className)}
|
| 106 |
+
{...props}
|
| 107 |
+
/>
|
| 108 |
+
))
|
| 109 |
+
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName
|
| 110 |
+
|
| 111 |
+
const AlertDialogCancel = React.forwardRef<
|
| 112 |
+
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
|
| 113 |
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
|
| 114 |
+
>(({ className, ...props }, ref) => (
|
| 115 |
+
<AlertDialogPrimitive.Cancel
|
| 116 |
+
ref={ref}
|
| 117 |
+
className={cn(
|
| 118 |
+
buttonVariants({ variant: "outline" }),
|
| 119 |
+
"mt-2 sm:mt-0",
|
| 120 |
+
className
|
| 121 |
+
)}
|
| 122 |
+
{...props}
|
| 123 |
+
/>
|
| 124 |
+
))
|
| 125 |
+
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName
|
| 126 |
+
|
| 127 |
+
export {
|
| 128 |
+
AlertDialog,
|
| 129 |
+
AlertDialogPortal,
|
| 130 |
+
AlertDialogOverlay,
|
| 131 |
+
AlertDialogTrigger,
|
| 132 |
+
AlertDialogContent,
|
| 133 |
+
AlertDialogHeader,
|
| 134 |
+
AlertDialogFooter,
|
| 135 |
+
AlertDialogTitle,
|
| 136 |
+
AlertDialogDescription,
|
| 137 |
+
AlertDialogAction,
|
| 138 |
+
AlertDialogCancel,
|
| 139 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/alert.tsx
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import { cva, type VariantProps } from "class-variance-authority"
|
| 3 |
+
|
| 4 |
+
import { cn } from "@/lib/utils"
|
| 5 |
+
|
| 6 |
+
const alertVariants = cva(
|
| 7 |
+
"relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",
|
| 8 |
+
{
|
| 9 |
+
variants: {
|
| 10 |
+
variant: {
|
| 11 |
+
default: "bg-background text-foreground",
|
| 12 |
+
destructive:
|
| 13 |
+
"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",
|
| 14 |
+
},
|
| 15 |
+
},
|
| 16 |
+
defaultVariants: {
|
| 17 |
+
variant: "default",
|
| 18 |
+
},
|
| 19 |
+
}
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
const Alert = React.forwardRef<
|
| 23 |
+
HTMLDivElement,
|
| 24 |
+
React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
|
| 25 |
+
>(({ className, variant, ...props }, ref) => (
|
| 26 |
+
<div
|
| 27 |
+
ref={ref}
|
| 28 |
+
role="alert"
|
| 29 |
+
className={cn(alertVariants({ variant }), className)}
|
| 30 |
+
{...props}
|
| 31 |
+
/>
|
| 32 |
+
))
|
| 33 |
+
Alert.displayName = "Alert"
|
| 34 |
+
|
| 35 |
+
const AlertTitle = React.forwardRef<
|
| 36 |
+
HTMLParagraphElement,
|
| 37 |
+
React.HTMLAttributes<HTMLHeadingElement>
|
| 38 |
+
>(({ className, ...props }, ref) => (
|
| 39 |
+
<h5
|
| 40 |
+
ref={ref}
|
| 41 |
+
className={cn("mb-1 font-medium leading-none tracking-tight", className)}
|
| 42 |
+
{...props}
|
| 43 |
+
/>
|
| 44 |
+
))
|
| 45 |
+
AlertTitle.displayName = "AlertTitle"
|
| 46 |
+
|
| 47 |
+
const AlertDescription = React.forwardRef<
|
| 48 |
+
HTMLParagraphElement,
|
| 49 |
+
React.HTMLAttributes<HTMLParagraphElement>
|
| 50 |
+
>(({ className, ...props }, ref) => (
|
| 51 |
+
<div
|
| 52 |
+
ref={ref}
|
| 53 |
+
className={cn("text-sm [&_p]:leading-relaxed", className)}
|
| 54 |
+
{...props}
|
| 55 |
+
/>
|
| 56 |
+
))
|
| 57 |
+
AlertDescription.displayName = "AlertDescription"
|
| 58 |
+
|
| 59 |
+
export { Alert, AlertTitle, AlertDescription }
|
artifacts/eco-cleanup-game/src/components/ui/aspect-ratio.tsx
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio"
|
| 2 |
+
|
| 3 |
+
const AspectRatio = AspectRatioPrimitive.Root
|
| 4 |
+
|
| 5 |
+
export { AspectRatio }
|
artifacts/eco-cleanup-game/src/components/ui/avatar.tsx
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client"
|
| 2 |
+
|
| 3 |
+
import * as React from "react"
|
| 4 |
+
import * as AvatarPrimitive from "@radix-ui/react-avatar"
|
| 5 |
+
|
| 6 |
+
import { cn } from "@/lib/utils"
|
| 7 |
+
|
| 8 |
+
const Avatar = React.forwardRef<
|
| 9 |
+
React.ElementRef<typeof AvatarPrimitive.Root>,
|
| 10 |
+
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
|
| 11 |
+
>(({ className, ...props }, ref) => (
|
| 12 |
+
<AvatarPrimitive.Root
|
| 13 |
+
ref={ref}
|
| 14 |
+
className={cn(
|
| 15 |
+
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
|
| 16 |
+
className
|
| 17 |
+
)}
|
| 18 |
+
{...props}
|
| 19 |
+
/>
|
| 20 |
+
))
|
| 21 |
+
Avatar.displayName = AvatarPrimitive.Root.displayName
|
| 22 |
+
|
| 23 |
+
const AvatarImage = React.forwardRef<
|
| 24 |
+
React.ElementRef<typeof AvatarPrimitive.Image>,
|
| 25 |
+
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
|
| 26 |
+
>(({ className, ...props }, ref) => (
|
| 27 |
+
<AvatarPrimitive.Image
|
| 28 |
+
ref={ref}
|
| 29 |
+
className={cn("aspect-square h-full w-full", className)}
|
| 30 |
+
{...props}
|
| 31 |
+
/>
|
| 32 |
+
))
|
| 33 |
+
AvatarImage.displayName = AvatarPrimitive.Image.displayName
|
| 34 |
+
|
| 35 |
+
const AvatarFallback = React.forwardRef<
|
| 36 |
+
React.ElementRef<typeof AvatarPrimitive.Fallback>,
|
| 37 |
+
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
|
| 38 |
+
>(({ className, ...props }, ref) => (
|
| 39 |
+
<AvatarPrimitive.Fallback
|
| 40 |
+
ref={ref}
|
| 41 |
+
className={cn(
|
| 42 |
+
"flex h-full w-full items-center justify-center rounded-full bg-muted",
|
| 43 |
+
className
|
| 44 |
+
)}
|
| 45 |
+
{...props}
|
| 46 |
+
/>
|
| 47 |
+
))
|
| 48 |
+
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
|
| 49 |
+
|
| 50 |
+
export { Avatar, AvatarImage, AvatarFallback }
|
artifacts/eco-cleanup-game/src/components/ui/badge.tsx
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import { cva, type VariantProps } from "class-variance-authority"
|
| 3 |
+
|
| 4 |
+
import { cn } from "@/lib/utils"
|
| 5 |
+
|
| 6 |
+
const badgeVariants = cva(
|
| 7 |
+
// @replit
|
| 8 |
+
// Whitespace-nowrap: Badges should never wrap.
|
| 9 |
+
"whitespace-nowrap inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2" +
|
| 10 |
+
" hover-elevate ",
|
| 11 |
+
{
|
| 12 |
+
variants: {
|
| 13 |
+
variant: {
|
| 14 |
+
default:
|
| 15 |
+
// @replit shadow-xs instead of shadow, no hover because we use hover-elevate
|
| 16 |
+
"border-transparent bg-primary text-primary-foreground shadow-xs",
|
| 17 |
+
secondary:
|
| 18 |
+
// @replit no hover because we use hover-elevate
|
| 19 |
+
"border-transparent bg-secondary text-secondary-foreground",
|
| 20 |
+
destructive:
|
| 21 |
+
// @replit shadow-xs instead of shadow, no hover because we use hover-elevate
|
| 22 |
+
"border-transparent bg-destructive text-destructive-foreground shadow-xs",
|
| 23 |
+
// @replit shadow-xs" - use badge outline variable
|
| 24 |
+
outline: "text-foreground border [border-color:var(--badge-outline)]",
|
| 25 |
+
},
|
| 26 |
+
},
|
| 27 |
+
defaultVariants: {
|
| 28 |
+
variant: "default",
|
| 29 |
+
},
|
| 30 |
+
}
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
export interface BadgeProps
|
| 34 |
+
extends React.HTMLAttributes<HTMLDivElement>,
|
| 35 |
+
VariantProps<typeof badgeVariants> {}
|
| 36 |
+
|
| 37 |
+
function Badge({ className, variant, ...props }: BadgeProps) {
|
| 38 |
+
return (
|
| 39 |
+
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
| 40 |
+
)
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
export { Badge, badgeVariants }
|
artifacts/eco-cleanup-game/src/components/ui/breadcrumb.tsx
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import { Slot } from "@radix-ui/react-slot"
|
| 3 |
+
import { ChevronRight, MoreHorizontal } from "lucide-react"
|
| 4 |
+
|
| 5 |
+
import { cn } from "@/lib/utils"
|
| 6 |
+
|
| 7 |
+
const Breadcrumb = React.forwardRef<
|
| 8 |
+
HTMLElement,
|
| 9 |
+
React.ComponentPropsWithoutRef<"nav"> & {
|
| 10 |
+
separator?: React.ReactNode
|
| 11 |
+
}
|
| 12 |
+
>(({ ...props }, ref) => <nav ref={ref} aria-label="breadcrumb" {...props} />)
|
| 13 |
+
Breadcrumb.displayName = "Breadcrumb"
|
| 14 |
+
|
| 15 |
+
const BreadcrumbList = React.forwardRef<
|
| 16 |
+
HTMLOListElement,
|
| 17 |
+
React.ComponentPropsWithoutRef<"ol">
|
| 18 |
+
>(({ className, ...props }, ref) => (
|
| 19 |
+
<ol
|
| 20 |
+
ref={ref}
|
| 21 |
+
className={cn(
|
| 22 |
+
"flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5",
|
| 23 |
+
className
|
| 24 |
+
)}
|
| 25 |
+
{...props}
|
| 26 |
+
/>
|
| 27 |
+
))
|
| 28 |
+
BreadcrumbList.displayName = "BreadcrumbList"
|
| 29 |
+
|
| 30 |
+
const BreadcrumbItem = React.forwardRef<
|
| 31 |
+
HTMLLIElement,
|
| 32 |
+
React.ComponentPropsWithoutRef<"li">
|
| 33 |
+
>(({ className, ...props }, ref) => (
|
| 34 |
+
<li
|
| 35 |
+
ref={ref}
|
| 36 |
+
className={cn("inline-flex items-center gap-1.5", className)}
|
| 37 |
+
{...props}
|
| 38 |
+
/>
|
| 39 |
+
))
|
| 40 |
+
BreadcrumbItem.displayName = "BreadcrumbItem"
|
| 41 |
+
|
| 42 |
+
const BreadcrumbLink = React.forwardRef<
|
| 43 |
+
HTMLAnchorElement,
|
| 44 |
+
React.ComponentPropsWithoutRef<"a"> & {
|
| 45 |
+
asChild?: boolean
|
| 46 |
+
}
|
| 47 |
+
>(({ asChild, className, ...props }, ref) => {
|
| 48 |
+
const Comp = asChild ? Slot : "a"
|
| 49 |
+
|
| 50 |
+
return (
|
| 51 |
+
<Comp
|
| 52 |
+
ref={ref}
|
| 53 |
+
className={cn("transition-colors hover:text-foreground", className)}
|
| 54 |
+
{...props}
|
| 55 |
+
/>
|
| 56 |
+
)
|
| 57 |
+
})
|
| 58 |
+
BreadcrumbLink.displayName = "BreadcrumbLink"
|
| 59 |
+
|
| 60 |
+
const BreadcrumbPage = React.forwardRef<
|
| 61 |
+
HTMLSpanElement,
|
| 62 |
+
React.ComponentPropsWithoutRef<"span">
|
| 63 |
+
>(({ className, ...props }, ref) => (
|
| 64 |
+
<span
|
| 65 |
+
ref={ref}
|
| 66 |
+
role="link"
|
| 67 |
+
aria-disabled="true"
|
| 68 |
+
aria-current="page"
|
| 69 |
+
className={cn("font-normal text-foreground", className)}
|
| 70 |
+
{...props}
|
| 71 |
+
/>
|
| 72 |
+
))
|
| 73 |
+
BreadcrumbPage.displayName = "BreadcrumbPage"
|
| 74 |
+
|
| 75 |
+
const BreadcrumbSeparator = ({
|
| 76 |
+
children,
|
| 77 |
+
className,
|
| 78 |
+
...props
|
| 79 |
+
}: React.ComponentProps<"li">) => (
|
| 80 |
+
<li
|
| 81 |
+
role="presentation"
|
| 82 |
+
aria-hidden="true"
|
| 83 |
+
className={cn("[&>svg]:w-3.5 [&>svg]:h-3.5", className)}
|
| 84 |
+
{...props}
|
| 85 |
+
>
|
| 86 |
+
{children ?? <ChevronRight />}
|
| 87 |
+
</li>
|
| 88 |
+
)
|
| 89 |
+
BreadcrumbSeparator.displayName = "BreadcrumbSeparator"
|
| 90 |
+
|
| 91 |
+
const BreadcrumbEllipsis = ({
|
| 92 |
+
className,
|
| 93 |
+
...props
|
| 94 |
+
}: React.ComponentProps<"span">) => (
|
| 95 |
+
<span
|
| 96 |
+
role="presentation"
|
| 97 |
+
aria-hidden="true"
|
| 98 |
+
className={cn("flex h-9 w-9 items-center justify-center", className)}
|
| 99 |
+
{...props}
|
| 100 |
+
>
|
| 101 |
+
<MoreHorizontal className="h-4 w-4" />
|
| 102 |
+
<span className="sr-only">More</span>
|
| 103 |
+
</span>
|
| 104 |
+
)
|
| 105 |
+
BreadcrumbEllipsis.displayName = "BreadcrumbElipssis"
|
| 106 |
+
|
| 107 |
+
export {
|
| 108 |
+
Breadcrumb,
|
| 109 |
+
BreadcrumbList,
|
| 110 |
+
BreadcrumbItem,
|
| 111 |
+
BreadcrumbLink,
|
| 112 |
+
BreadcrumbPage,
|
| 113 |
+
BreadcrumbSeparator,
|
| 114 |
+
BreadcrumbEllipsis,
|
| 115 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/button-group.tsx
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Slot } from "@radix-ui/react-slot"
|
| 2 |
+
import { cva, type VariantProps } from "class-variance-authority"
|
| 3 |
+
|
| 4 |
+
import { cn } from "@/lib/utils"
|
| 5 |
+
import { Separator } from "@/components/ui/separator"
|
| 6 |
+
|
| 7 |
+
const buttonGroupVariants = cva(
|
| 8 |
+
"flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1",
|
| 9 |
+
{
|
| 10 |
+
variants: {
|
| 11 |
+
orientation: {
|
| 12 |
+
horizontal:
|
| 13 |
+
"[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",
|
| 14 |
+
vertical:
|
| 15 |
+
"flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none",
|
| 16 |
+
},
|
| 17 |
+
},
|
| 18 |
+
defaultVariants: {
|
| 19 |
+
orientation: "horizontal",
|
| 20 |
+
},
|
| 21 |
+
}
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
function ButtonGroup({
|
| 25 |
+
className,
|
| 26 |
+
orientation,
|
| 27 |
+
...props
|
| 28 |
+
}: React.ComponentProps<"div"> & VariantProps<typeof buttonGroupVariants>) {
|
| 29 |
+
return (
|
| 30 |
+
<div
|
| 31 |
+
role="group"
|
| 32 |
+
data-slot="button-group"
|
| 33 |
+
data-orientation={orientation}
|
| 34 |
+
className={cn(buttonGroupVariants({ orientation }), className)}
|
| 35 |
+
{...props}
|
| 36 |
+
/>
|
| 37 |
+
)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function ButtonGroupText({
|
| 41 |
+
className,
|
| 42 |
+
asChild = false,
|
| 43 |
+
...props
|
| 44 |
+
}: React.ComponentProps<"div"> & {
|
| 45 |
+
asChild?: boolean
|
| 46 |
+
}) {
|
| 47 |
+
const Comp = asChild ? Slot : "div"
|
| 48 |
+
|
| 49 |
+
return (
|
| 50 |
+
<Comp
|
| 51 |
+
className={cn(
|
| 52 |
+
"bg-muted shadow-xs flex items-center gap-2 rounded-md border px-4 text-sm font-medium [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none",
|
| 53 |
+
className
|
| 54 |
+
)}
|
| 55 |
+
{...props}
|
| 56 |
+
/>
|
| 57 |
+
)
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
function ButtonGroupSeparator({
|
| 61 |
+
className,
|
| 62 |
+
orientation = "vertical",
|
| 63 |
+
...props
|
| 64 |
+
}: React.ComponentProps<typeof Separator>) {
|
| 65 |
+
return (
|
| 66 |
+
<Separator
|
| 67 |
+
data-slot="button-group-separator"
|
| 68 |
+
orientation={orientation}
|
| 69 |
+
className={cn(
|
| 70 |
+
"bg-input relative !m-0 self-stretch data-[orientation=vertical]:h-auto",
|
| 71 |
+
className
|
| 72 |
+
)}
|
| 73 |
+
{...props}
|
| 74 |
+
/>
|
| 75 |
+
)
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
export {
|
| 79 |
+
ButtonGroup,
|
| 80 |
+
ButtonGroupSeparator,
|
| 81 |
+
ButtonGroupText,
|
| 82 |
+
buttonGroupVariants,
|
| 83 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/button.tsx
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import { Slot } from "@radix-ui/react-slot"
|
| 3 |
+
import { cva, type VariantProps } from "class-variance-authority"
|
| 4 |
+
|
| 5 |
+
import { cn } from "@/lib/utils"
|
| 6 |
+
|
| 7 |
+
const buttonVariants = cva(
|
| 8 |
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0" +
|
| 9 |
+
" hover-elevate active-elevate-2",
|
| 10 |
+
{
|
| 11 |
+
variants: {
|
| 12 |
+
variant: {
|
| 13 |
+
default:
|
| 14 |
+
// @replit: no hover, and add primary border
|
| 15 |
+
"bg-primary text-primary-foreground border border-primary-border",
|
| 16 |
+
destructive:
|
| 17 |
+
"bg-destructive text-destructive-foreground shadow-sm border-destructive-border",
|
| 18 |
+
outline:
|
| 19 |
+
// @replit Shows the background color of whatever card / sidebar / accent background it is inside of.
|
| 20 |
+
// Inherits the current text color. Uses shadow-xs. no shadow on active
|
| 21 |
+
// No hover state
|
| 22 |
+
" border [border-color:var(--button-outline)] shadow-xs active:shadow-none ",
|
| 23 |
+
secondary:
|
| 24 |
+
// @replit border, no hover, no shadow, secondary border.
|
| 25 |
+
"border bg-secondary text-secondary-foreground border border-secondary-border ",
|
| 26 |
+
// @replit no hover, transparent border
|
| 27 |
+
ghost: "border border-transparent",
|
| 28 |
+
link: "text-primary underline-offset-4 hover:underline",
|
| 29 |
+
},
|
| 30 |
+
size: {
|
| 31 |
+
// @replit changed sizes
|
| 32 |
+
default: "min-h-9 px-4 py-2",
|
| 33 |
+
sm: "min-h-8 rounded-md px-3 text-xs",
|
| 34 |
+
lg: "min-h-10 rounded-md px-8",
|
| 35 |
+
icon: "h-9 w-9",
|
| 36 |
+
},
|
| 37 |
+
},
|
| 38 |
+
defaultVariants: {
|
| 39 |
+
variant: "default",
|
| 40 |
+
size: "default",
|
| 41 |
+
},
|
| 42 |
+
}
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
export interface ButtonProps
|
| 46 |
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
| 47 |
+
VariantProps<typeof buttonVariants> {
|
| 48 |
+
asChild?: boolean
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
| 52 |
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
| 53 |
+
const Comp = asChild ? Slot : "button"
|
| 54 |
+
return (
|
| 55 |
+
<Comp
|
| 56 |
+
className={cn(buttonVariants({ variant, size, className }))}
|
| 57 |
+
ref={ref}
|
| 58 |
+
{...props}
|
| 59 |
+
/>
|
| 60 |
+
)
|
| 61 |
+
}
|
| 62 |
+
)
|
| 63 |
+
Button.displayName = "Button"
|
| 64 |
+
|
| 65 |
+
export { Button, buttonVariants }
|
artifacts/eco-cleanup-game/src/components/ui/calendar.tsx
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client"
|
| 2 |
+
|
| 3 |
+
import * as React from "react"
|
| 4 |
+
import {
|
| 5 |
+
ChevronDownIcon,
|
| 6 |
+
ChevronLeftIcon,
|
| 7 |
+
ChevronRightIcon,
|
| 8 |
+
} from "lucide-react"
|
| 9 |
+
import { DayButton, DayPicker, getDefaultClassNames } from "react-day-picker"
|
| 10 |
+
|
| 11 |
+
import { cn } from "@/lib/utils"
|
| 12 |
+
import { Button, buttonVariants } from "@/components/ui/button"
|
| 13 |
+
|
| 14 |
+
function Calendar({
|
| 15 |
+
className,
|
| 16 |
+
classNames,
|
| 17 |
+
showOutsideDays = true,
|
| 18 |
+
captionLayout = "label",
|
| 19 |
+
buttonVariant = "ghost",
|
| 20 |
+
formatters,
|
| 21 |
+
components,
|
| 22 |
+
...props
|
| 23 |
+
}: React.ComponentProps<typeof DayPicker> & {
|
| 24 |
+
buttonVariant?: React.ComponentProps<typeof Button>["variant"]
|
| 25 |
+
}) {
|
| 26 |
+
const defaultClassNames = getDefaultClassNames()
|
| 27 |
+
|
| 28 |
+
return (
|
| 29 |
+
<DayPicker
|
| 30 |
+
showOutsideDays={showOutsideDays}
|
| 31 |
+
className={cn(
|
| 32 |
+
"bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
|
| 33 |
+
String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
|
| 34 |
+
String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
|
| 35 |
+
className
|
| 36 |
+
)}
|
| 37 |
+
captionLayout={captionLayout}
|
| 38 |
+
formatters={{
|
| 39 |
+
formatMonthDropdown: (date) =>
|
| 40 |
+
date.toLocaleString("default", { month: "short" }),
|
| 41 |
+
...formatters,
|
| 42 |
+
}}
|
| 43 |
+
classNames={{
|
| 44 |
+
root: cn("w-fit", defaultClassNames.root),
|
| 45 |
+
months: cn(
|
| 46 |
+
"relative flex flex-col gap-4 md:flex-row",
|
| 47 |
+
defaultClassNames.months
|
| 48 |
+
),
|
| 49 |
+
month: cn("flex w-full flex-col gap-4", defaultClassNames.month),
|
| 50 |
+
nav: cn(
|
| 51 |
+
"absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",
|
| 52 |
+
defaultClassNames.nav
|
| 53 |
+
),
|
| 54 |
+
button_previous: cn(
|
| 55 |
+
buttonVariants({ variant: buttonVariant }),
|
| 56 |
+
"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",
|
| 57 |
+
defaultClassNames.button_previous
|
| 58 |
+
),
|
| 59 |
+
button_next: cn(
|
| 60 |
+
buttonVariants({ variant: buttonVariant }),
|
| 61 |
+
"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",
|
| 62 |
+
defaultClassNames.button_next
|
| 63 |
+
),
|
| 64 |
+
month_caption: cn(
|
| 65 |
+
"flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",
|
| 66 |
+
defaultClassNames.month_caption
|
| 67 |
+
),
|
| 68 |
+
dropdowns: cn(
|
| 69 |
+
"flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",
|
| 70 |
+
defaultClassNames.dropdowns
|
| 71 |
+
),
|
| 72 |
+
dropdown_root: cn(
|
| 73 |
+
"has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",
|
| 74 |
+
defaultClassNames.dropdown_root
|
| 75 |
+
),
|
| 76 |
+
dropdown: cn(
|
| 77 |
+
"bg-popover absolute inset-0 opacity-0",
|
| 78 |
+
defaultClassNames.dropdown
|
| 79 |
+
),
|
| 80 |
+
caption_label: cn(
|
| 81 |
+
"select-none font-medium",
|
| 82 |
+
captionLayout === "label"
|
| 83 |
+
? "text-sm"
|
| 84 |
+
: "[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5",
|
| 85 |
+
defaultClassNames.caption_label
|
| 86 |
+
),
|
| 87 |
+
table: "w-full border-collapse",
|
| 88 |
+
weekdays: cn("flex", defaultClassNames.weekdays),
|
| 89 |
+
weekday: cn(
|
| 90 |
+
"text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",
|
| 91 |
+
defaultClassNames.weekday
|
| 92 |
+
),
|
| 93 |
+
week: cn("mt-2 flex w-full", defaultClassNames.week),
|
| 94 |
+
week_number_header: cn(
|
| 95 |
+
"w-[--cell-size] select-none",
|
| 96 |
+
defaultClassNames.week_number_header
|
| 97 |
+
),
|
| 98 |
+
week_number: cn(
|
| 99 |
+
"text-muted-foreground select-none text-[0.8rem]",
|
| 100 |
+
defaultClassNames.week_number
|
| 101 |
+
),
|
| 102 |
+
day: cn(
|
| 103 |
+
"group/day relative aspect-square h-full w-full select-none p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md",
|
| 104 |
+
defaultClassNames.day
|
| 105 |
+
),
|
| 106 |
+
range_start: cn(
|
| 107 |
+
"bg-accent rounded-l-md",
|
| 108 |
+
defaultClassNames.range_start
|
| 109 |
+
),
|
| 110 |
+
range_middle: cn("rounded-none", defaultClassNames.range_middle),
|
| 111 |
+
range_end: cn("bg-accent rounded-r-md", defaultClassNames.range_end),
|
| 112 |
+
today: cn(
|
| 113 |
+
"bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",
|
| 114 |
+
defaultClassNames.today
|
| 115 |
+
),
|
| 116 |
+
outside: cn(
|
| 117 |
+
"text-muted-foreground aria-selected:text-muted-foreground",
|
| 118 |
+
defaultClassNames.outside
|
| 119 |
+
),
|
| 120 |
+
disabled: cn(
|
| 121 |
+
"text-muted-foreground opacity-50",
|
| 122 |
+
defaultClassNames.disabled
|
| 123 |
+
),
|
| 124 |
+
hidden: cn("invisible", defaultClassNames.hidden),
|
| 125 |
+
...classNames,
|
| 126 |
+
}}
|
| 127 |
+
components={{
|
| 128 |
+
Root: ({ className, rootRef, ...props }) => {
|
| 129 |
+
return (
|
| 130 |
+
<div
|
| 131 |
+
data-slot="calendar"
|
| 132 |
+
ref={rootRef}
|
| 133 |
+
className={cn(className)}
|
| 134 |
+
{...props}
|
| 135 |
+
/>
|
| 136 |
+
)
|
| 137 |
+
},
|
| 138 |
+
Chevron: ({ className, orientation, ...props }) => {
|
| 139 |
+
if (orientation === "left") {
|
| 140 |
+
return (
|
| 141 |
+
<ChevronLeftIcon className={cn("size-4", className)} {...props} />
|
| 142 |
+
)
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
if (orientation === "right") {
|
| 146 |
+
return (
|
| 147 |
+
<ChevronRightIcon
|
| 148 |
+
className={cn("size-4", className)}
|
| 149 |
+
{...props}
|
| 150 |
+
/>
|
| 151 |
+
)
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
return (
|
| 155 |
+
<ChevronDownIcon className={cn("size-4", className)} {...props} />
|
| 156 |
+
)
|
| 157 |
+
},
|
| 158 |
+
DayButton: CalendarDayButton,
|
| 159 |
+
WeekNumber: ({ children, ...props }) => {
|
| 160 |
+
return (
|
| 161 |
+
<td {...props}>
|
| 162 |
+
<div className="flex size-[--cell-size] items-center justify-center text-center">
|
| 163 |
+
{children}
|
| 164 |
+
</div>
|
| 165 |
+
</td>
|
| 166 |
+
)
|
| 167 |
+
},
|
| 168 |
+
...components,
|
| 169 |
+
}}
|
| 170 |
+
{...props}
|
| 171 |
+
/>
|
| 172 |
+
)
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
function CalendarDayButton({
|
| 176 |
+
className,
|
| 177 |
+
day,
|
| 178 |
+
modifiers,
|
| 179 |
+
...props
|
| 180 |
+
}: React.ComponentProps<typeof DayButton>) {
|
| 181 |
+
const defaultClassNames = getDefaultClassNames()
|
| 182 |
+
|
| 183 |
+
const ref = React.useRef<HTMLButtonElement>(null)
|
| 184 |
+
React.useEffect(() => {
|
| 185 |
+
if (modifiers.focused) ref.current?.focus()
|
| 186 |
+
}, [modifiers.focused])
|
| 187 |
+
|
| 188 |
+
return (
|
| 189 |
+
<Button
|
| 190 |
+
ref={ref}
|
| 191 |
+
variant="ghost"
|
| 192 |
+
size="icon"
|
| 193 |
+
data-day={day.date.toLocaleDateString()}
|
| 194 |
+
data-selected-single={
|
| 195 |
+
modifiers.selected &&
|
| 196 |
+
!modifiers.range_start &&
|
| 197 |
+
!modifiers.range_end &&
|
| 198 |
+
!modifiers.range_middle
|
| 199 |
+
}
|
| 200 |
+
data-range-start={modifiers.range_start}
|
| 201 |
+
data-range-end={modifiers.range_end}
|
| 202 |
+
data-range-middle={modifiers.range_middle}
|
| 203 |
+
className={cn(
|
| 204 |
+
"data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 flex aspect-square h-auto w-full min-w-[--cell-size] flex-col gap-1 font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] [&>span]:text-xs [&>span]:opacity-70",
|
| 205 |
+
defaultClassNames.day,
|
| 206 |
+
className
|
| 207 |
+
)}
|
| 208 |
+
{...props}
|
| 209 |
+
/>
|
| 210 |
+
)
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
export { Calendar, CalendarDayButton }
|
artifacts/eco-cleanup-game/src/components/ui/card.tsx
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
|
| 3 |
+
import { cn } from "@/lib/utils"
|
| 4 |
+
|
| 5 |
+
const Card = React.forwardRef<
|
| 6 |
+
HTMLDivElement,
|
| 7 |
+
React.HTMLAttributes<HTMLDivElement>
|
| 8 |
+
>(({ className, ...props }, ref) => (
|
| 9 |
+
<div
|
| 10 |
+
ref={ref}
|
| 11 |
+
className={cn(
|
| 12 |
+
"rounded-xl border bg-card text-card-foreground shadow",
|
| 13 |
+
className
|
| 14 |
+
)}
|
| 15 |
+
{...props}
|
| 16 |
+
/>
|
| 17 |
+
))
|
| 18 |
+
Card.displayName = "Card"
|
| 19 |
+
|
| 20 |
+
const CardHeader = React.forwardRef<
|
| 21 |
+
HTMLDivElement,
|
| 22 |
+
React.HTMLAttributes<HTMLDivElement>
|
| 23 |
+
>(({ className, ...props }, ref) => (
|
| 24 |
+
<div
|
| 25 |
+
ref={ref}
|
| 26 |
+
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
| 27 |
+
{...props}
|
| 28 |
+
/>
|
| 29 |
+
))
|
| 30 |
+
CardHeader.displayName = "CardHeader"
|
| 31 |
+
|
| 32 |
+
const CardTitle = React.forwardRef<
|
| 33 |
+
HTMLDivElement,
|
| 34 |
+
React.HTMLAttributes<HTMLDivElement>
|
| 35 |
+
>(({ className, ...props }, ref) => (
|
| 36 |
+
<div
|
| 37 |
+
ref={ref}
|
| 38 |
+
className={cn("font-semibold leading-none tracking-tight", className)}
|
| 39 |
+
{...props}
|
| 40 |
+
/>
|
| 41 |
+
))
|
| 42 |
+
CardTitle.displayName = "CardTitle"
|
| 43 |
+
|
| 44 |
+
const CardDescription = React.forwardRef<
|
| 45 |
+
HTMLDivElement,
|
| 46 |
+
React.HTMLAttributes<HTMLDivElement>
|
| 47 |
+
>(({ className, ...props }, ref) => (
|
| 48 |
+
<div
|
| 49 |
+
ref={ref}
|
| 50 |
+
className={cn("text-sm text-muted-foreground", className)}
|
| 51 |
+
{...props}
|
| 52 |
+
/>
|
| 53 |
+
))
|
| 54 |
+
CardDescription.displayName = "CardDescription"
|
| 55 |
+
|
| 56 |
+
const CardContent = React.forwardRef<
|
| 57 |
+
HTMLDivElement,
|
| 58 |
+
React.HTMLAttributes<HTMLDivElement>
|
| 59 |
+
>(({ className, ...props }, ref) => (
|
| 60 |
+
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
| 61 |
+
))
|
| 62 |
+
CardContent.displayName = "CardContent"
|
| 63 |
+
|
| 64 |
+
const CardFooter = React.forwardRef<
|
| 65 |
+
HTMLDivElement,
|
| 66 |
+
React.HTMLAttributes<HTMLDivElement>
|
| 67 |
+
>(({ className, ...props }, ref) => (
|
| 68 |
+
<div
|
| 69 |
+
ref={ref}
|
| 70 |
+
className={cn("flex items-center p-6 pt-0", className)}
|
| 71 |
+
{...props}
|
| 72 |
+
/>
|
| 73 |
+
))
|
| 74 |
+
CardFooter.displayName = "CardFooter"
|
| 75 |
+
|
| 76 |
+
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
|
artifacts/eco-cleanup-game/src/components/ui/carousel.tsx
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import useEmblaCarousel, {
|
| 3 |
+
type UseEmblaCarouselType,
|
| 4 |
+
} from "embla-carousel-react"
|
| 5 |
+
import { ArrowLeft, ArrowRight } from "lucide-react"
|
| 6 |
+
|
| 7 |
+
import { cn } from "@/lib/utils"
|
| 8 |
+
import { Button } from "@/components/ui/button"
|
| 9 |
+
|
| 10 |
+
type CarouselApi = UseEmblaCarouselType[1]
|
| 11 |
+
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
|
| 12 |
+
type CarouselOptions = UseCarouselParameters[0]
|
| 13 |
+
type CarouselPlugin = UseCarouselParameters[1]
|
| 14 |
+
|
| 15 |
+
type CarouselProps = {
|
| 16 |
+
opts?: CarouselOptions
|
| 17 |
+
plugins?: CarouselPlugin
|
| 18 |
+
orientation?: "horizontal" | "vertical"
|
| 19 |
+
setApi?: (api: CarouselApi) => void
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
type CarouselContextProps = {
|
| 23 |
+
carouselRef: ReturnType<typeof useEmblaCarousel>[0]
|
| 24 |
+
api: ReturnType<typeof useEmblaCarousel>[1]
|
| 25 |
+
scrollPrev: () => void
|
| 26 |
+
scrollNext: () => void
|
| 27 |
+
canScrollPrev: boolean
|
| 28 |
+
canScrollNext: boolean
|
| 29 |
+
} & CarouselProps
|
| 30 |
+
|
| 31 |
+
const CarouselContext = React.createContext<CarouselContextProps | null>(null)
|
| 32 |
+
|
| 33 |
+
function useCarousel() {
|
| 34 |
+
const context = React.useContext(CarouselContext)
|
| 35 |
+
|
| 36 |
+
if (!context) {
|
| 37 |
+
throw new Error("useCarousel must be used within a <Carousel />")
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
return context
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
const Carousel = React.forwardRef<
|
| 44 |
+
HTMLDivElement,
|
| 45 |
+
React.HTMLAttributes<HTMLDivElement> & CarouselProps
|
| 46 |
+
>(
|
| 47 |
+
(
|
| 48 |
+
{
|
| 49 |
+
orientation = "horizontal",
|
| 50 |
+
opts,
|
| 51 |
+
setApi,
|
| 52 |
+
plugins,
|
| 53 |
+
className,
|
| 54 |
+
children,
|
| 55 |
+
...props
|
| 56 |
+
},
|
| 57 |
+
ref
|
| 58 |
+
) => {
|
| 59 |
+
const [carouselRef, api] = useEmblaCarousel(
|
| 60 |
+
{
|
| 61 |
+
...opts,
|
| 62 |
+
axis: orientation === "horizontal" ? "x" : "y",
|
| 63 |
+
},
|
| 64 |
+
plugins
|
| 65 |
+
)
|
| 66 |
+
const [canScrollPrev, setCanScrollPrev] = React.useState(false)
|
| 67 |
+
const [canScrollNext, setCanScrollNext] = React.useState(false)
|
| 68 |
+
|
| 69 |
+
const onSelect = React.useCallback((api: CarouselApi) => {
|
| 70 |
+
if (!api) {
|
| 71 |
+
return
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
setCanScrollPrev(api.canScrollPrev())
|
| 75 |
+
setCanScrollNext(api.canScrollNext())
|
| 76 |
+
}, [])
|
| 77 |
+
|
| 78 |
+
const scrollPrev = React.useCallback(() => {
|
| 79 |
+
api?.scrollPrev()
|
| 80 |
+
}, [api])
|
| 81 |
+
|
| 82 |
+
const scrollNext = React.useCallback(() => {
|
| 83 |
+
api?.scrollNext()
|
| 84 |
+
}, [api])
|
| 85 |
+
|
| 86 |
+
const handleKeyDown = React.useCallback(
|
| 87 |
+
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
| 88 |
+
if (event.key === "ArrowLeft") {
|
| 89 |
+
event.preventDefault()
|
| 90 |
+
scrollPrev()
|
| 91 |
+
} else if (event.key === "ArrowRight") {
|
| 92 |
+
event.preventDefault()
|
| 93 |
+
scrollNext()
|
| 94 |
+
}
|
| 95 |
+
},
|
| 96 |
+
[scrollPrev, scrollNext]
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
React.useEffect(() => {
|
| 100 |
+
if (!api || !setApi) {
|
| 101 |
+
return
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
setApi(api)
|
| 105 |
+
}, [api, setApi])
|
| 106 |
+
|
| 107 |
+
React.useEffect(() => {
|
| 108 |
+
if (!api) {
|
| 109 |
+
return
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
onSelect(api)
|
| 113 |
+
api.on("reInit", onSelect)
|
| 114 |
+
api.on("select", onSelect)
|
| 115 |
+
|
| 116 |
+
return () => {
|
| 117 |
+
api?.off("select", onSelect)
|
| 118 |
+
}
|
| 119 |
+
}, [api, onSelect])
|
| 120 |
+
|
| 121 |
+
return (
|
| 122 |
+
<CarouselContext.Provider
|
| 123 |
+
value={{
|
| 124 |
+
carouselRef,
|
| 125 |
+
api: api,
|
| 126 |
+
opts,
|
| 127 |
+
orientation:
|
| 128 |
+
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
| 129 |
+
scrollPrev,
|
| 130 |
+
scrollNext,
|
| 131 |
+
canScrollPrev,
|
| 132 |
+
canScrollNext,
|
| 133 |
+
}}
|
| 134 |
+
>
|
| 135 |
+
<div
|
| 136 |
+
ref={ref}
|
| 137 |
+
onKeyDownCapture={handleKeyDown}
|
| 138 |
+
className={cn("relative", className)}
|
| 139 |
+
role="region"
|
| 140 |
+
aria-roledescription="carousel"
|
| 141 |
+
{...props}
|
| 142 |
+
>
|
| 143 |
+
{children}
|
| 144 |
+
</div>
|
| 145 |
+
</CarouselContext.Provider>
|
| 146 |
+
)
|
| 147 |
+
}
|
| 148 |
+
)
|
| 149 |
+
Carousel.displayName = "Carousel"
|
| 150 |
+
|
| 151 |
+
const CarouselContent = React.forwardRef<
|
| 152 |
+
HTMLDivElement,
|
| 153 |
+
React.HTMLAttributes<HTMLDivElement>
|
| 154 |
+
>(({ className, ...props }, ref) => {
|
| 155 |
+
const { carouselRef, orientation } = useCarousel()
|
| 156 |
+
|
| 157 |
+
return (
|
| 158 |
+
<div ref={carouselRef} className="overflow-hidden">
|
| 159 |
+
<div
|
| 160 |
+
ref={ref}
|
| 161 |
+
className={cn(
|
| 162 |
+
"flex",
|
| 163 |
+
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
| 164 |
+
className
|
| 165 |
+
)}
|
| 166 |
+
{...props}
|
| 167 |
+
/>
|
| 168 |
+
</div>
|
| 169 |
+
)
|
| 170 |
+
})
|
| 171 |
+
CarouselContent.displayName = "CarouselContent"
|
| 172 |
+
|
| 173 |
+
const CarouselItem = React.forwardRef<
|
| 174 |
+
HTMLDivElement,
|
| 175 |
+
React.HTMLAttributes<HTMLDivElement>
|
| 176 |
+
>(({ className, ...props }, ref) => {
|
| 177 |
+
const { orientation } = useCarousel()
|
| 178 |
+
|
| 179 |
+
return (
|
| 180 |
+
<div
|
| 181 |
+
ref={ref}
|
| 182 |
+
role="group"
|
| 183 |
+
aria-roledescription="slide"
|
| 184 |
+
className={cn(
|
| 185 |
+
"min-w-0 shrink-0 grow-0 basis-full",
|
| 186 |
+
orientation === "horizontal" ? "pl-4" : "pt-4",
|
| 187 |
+
className
|
| 188 |
+
)}
|
| 189 |
+
{...props}
|
| 190 |
+
/>
|
| 191 |
+
)
|
| 192 |
+
})
|
| 193 |
+
CarouselItem.displayName = "CarouselItem"
|
| 194 |
+
|
| 195 |
+
const CarouselPrevious = React.forwardRef<
|
| 196 |
+
HTMLButtonElement,
|
| 197 |
+
React.ComponentProps<typeof Button>
|
| 198 |
+
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
|
| 199 |
+
const { orientation, scrollPrev, canScrollPrev } = useCarousel()
|
| 200 |
+
|
| 201 |
+
return (
|
| 202 |
+
<Button
|
| 203 |
+
ref={ref}
|
| 204 |
+
variant={variant}
|
| 205 |
+
size={size}
|
| 206 |
+
className={cn(
|
| 207 |
+
"absolute h-8 w-8 rounded-full",
|
| 208 |
+
orientation === "horizontal"
|
| 209 |
+
? "-left-12 top-1/2 -translate-y-1/2"
|
| 210 |
+
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
| 211 |
+
className
|
| 212 |
+
)}
|
| 213 |
+
disabled={!canScrollPrev}
|
| 214 |
+
onClick={scrollPrev}
|
| 215 |
+
{...props}
|
| 216 |
+
>
|
| 217 |
+
<ArrowLeft className="h-4 w-4" />
|
| 218 |
+
<span className="sr-only">Previous slide</span>
|
| 219 |
+
</Button>
|
| 220 |
+
)
|
| 221 |
+
})
|
| 222 |
+
CarouselPrevious.displayName = "CarouselPrevious"
|
| 223 |
+
|
| 224 |
+
const CarouselNext = React.forwardRef<
|
| 225 |
+
HTMLButtonElement,
|
| 226 |
+
React.ComponentProps<typeof Button>
|
| 227 |
+
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
|
| 228 |
+
const { orientation, scrollNext, canScrollNext } = useCarousel()
|
| 229 |
+
|
| 230 |
+
return (
|
| 231 |
+
<Button
|
| 232 |
+
ref={ref}
|
| 233 |
+
variant={variant}
|
| 234 |
+
size={size}
|
| 235 |
+
className={cn(
|
| 236 |
+
"absolute h-8 w-8 rounded-full",
|
| 237 |
+
orientation === "horizontal"
|
| 238 |
+
? "-right-12 top-1/2 -translate-y-1/2"
|
| 239 |
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
| 240 |
+
className
|
| 241 |
+
)}
|
| 242 |
+
disabled={!canScrollNext}
|
| 243 |
+
onClick={scrollNext}
|
| 244 |
+
{...props}
|
| 245 |
+
>
|
| 246 |
+
<ArrowRight className="h-4 w-4" />
|
| 247 |
+
<span className="sr-only">Next slide</span>
|
| 248 |
+
</Button>
|
| 249 |
+
)
|
| 250 |
+
})
|
| 251 |
+
CarouselNext.displayName = "CarouselNext"
|
| 252 |
+
|
| 253 |
+
export {
|
| 254 |
+
type CarouselApi,
|
| 255 |
+
Carousel,
|
| 256 |
+
CarouselContent,
|
| 257 |
+
CarouselItem,
|
| 258 |
+
CarouselPrevious,
|
| 259 |
+
CarouselNext,
|
| 260 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/chart.tsx
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import * as RechartsPrimitive from "recharts"
|
| 3 |
+
|
| 4 |
+
import { cn } from "@/lib/utils"
|
| 5 |
+
|
| 6 |
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
| 7 |
+
const THEMES = { light: "", dark: ".dark" } as const
|
| 8 |
+
|
| 9 |
+
export type ChartConfig = {
|
| 10 |
+
[k in string]: {
|
| 11 |
+
label?: React.ReactNode
|
| 12 |
+
icon?: React.ComponentType
|
| 13 |
+
} & (
|
| 14 |
+
| { color?: string; theme?: never }
|
| 15 |
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
| 16 |
+
)
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
type ChartContextProps = {
|
| 20 |
+
config: ChartConfig
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
const ChartContext = React.createContext<ChartContextProps | null>(null)
|
| 24 |
+
|
| 25 |
+
function useChart() {
|
| 26 |
+
const context = React.useContext(ChartContext)
|
| 27 |
+
|
| 28 |
+
if (!context) {
|
| 29 |
+
throw new Error("useChart must be used within a <ChartContainer />")
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
return context
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
const ChartContainer = React.forwardRef<
|
| 36 |
+
HTMLDivElement,
|
| 37 |
+
React.ComponentProps<"div"> & {
|
| 38 |
+
config: ChartConfig
|
| 39 |
+
children: React.ComponentProps<
|
| 40 |
+
typeof RechartsPrimitive.ResponsiveContainer
|
| 41 |
+
>["children"]
|
| 42 |
+
}
|
| 43 |
+
>(({ id, className, children, config, ...props }, ref) => {
|
| 44 |
+
const uniqueId = React.useId()
|
| 45 |
+
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
|
| 46 |
+
|
| 47 |
+
return (
|
| 48 |
+
<ChartContext.Provider value={{ config }}>
|
| 49 |
+
<div
|
| 50 |
+
data-chart={chartId}
|
| 51 |
+
ref={ref}
|
| 52 |
+
className={cn(
|
| 53 |
+
"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",
|
| 54 |
+
className
|
| 55 |
+
)}
|
| 56 |
+
{...props}
|
| 57 |
+
>
|
| 58 |
+
<ChartStyle id={chartId} config={config} />
|
| 59 |
+
<RechartsPrimitive.ResponsiveContainer>
|
| 60 |
+
{children}
|
| 61 |
+
</RechartsPrimitive.ResponsiveContainer>
|
| 62 |
+
</div>
|
| 63 |
+
</ChartContext.Provider>
|
| 64 |
+
)
|
| 65 |
+
})
|
| 66 |
+
ChartContainer.displayName = "Chart"
|
| 67 |
+
|
| 68 |
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
| 69 |
+
const colorConfig = Object.entries(config).filter(
|
| 70 |
+
([, config]) => config.theme || config.color
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
if (!colorConfig.length) {
|
| 74 |
+
return null
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
return (
|
| 78 |
+
<style
|
| 79 |
+
dangerouslySetInnerHTML={{
|
| 80 |
+
__html: Object.entries(THEMES)
|
| 81 |
+
.map(
|
| 82 |
+
([theme, prefix]) => `
|
| 83 |
+
${prefix} [data-chart=${id}] {
|
| 84 |
+
${colorConfig
|
| 85 |
+
.map(([key, itemConfig]) => {
|
| 86 |
+
const color =
|
| 87 |
+
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
| 88 |
+
itemConfig.color
|
| 89 |
+
return color ? ` --color-${key}: ${color};` : null
|
| 90 |
+
})
|
| 91 |
+
.join("\n")}
|
| 92 |
+
}
|
| 93 |
+
`
|
| 94 |
+
)
|
| 95 |
+
.join("\n"),
|
| 96 |
+
}}
|
| 97 |
+
/>
|
| 98 |
+
)
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
const ChartTooltip = RechartsPrimitive.Tooltip
|
| 102 |
+
|
| 103 |
+
const ChartTooltipContent = React.forwardRef<
|
| 104 |
+
HTMLDivElement,
|
| 105 |
+
React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
| 106 |
+
React.ComponentProps<"div"> & {
|
| 107 |
+
hideLabel?: boolean
|
| 108 |
+
hideIndicator?: boolean
|
| 109 |
+
indicator?: "line" | "dot" | "dashed"
|
| 110 |
+
nameKey?: string
|
| 111 |
+
labelKey?: string
|
| 112 |
+
}
|
| 113 |
+
>(
|
| 114 |
+
(
|
| 115 |
+
{
|
| 116 |
+
active,
|
| 117 |
+
payload,
|
| 118 |
+
className,
|
| 119 |
+
indicator = "dot",
|
| 120 |
+
hideLabel = false,
|
| 121 |
+
hideIndicator = false,
|
| 122 |
+
label,
|
| 123 |
+
labelFormatter,
|
| 124 |
+
labelClassName,
|
| 125 |
+
formatter,
|
| 126 |
+
color,
|
| 127 |
+
nameKey,
|
| 128 |
+
labelKey,
|
| 129 |
+
},
|
| 130 |
+
ref
|
| 131 |
+
) => {
|
| 132 |
+
const { config } = useChart()
|
| 133 |
+
|
| 134 |
+
const tooltipLabel = React.useMemo(() => {
|
| 135 |
+
if (hideLabel || !payload?.length) {
|
| 136 |
+
return null
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
const [item] = payload
|
| 140 |
+
const key = `${labelKey || item?.dataKey || item?.name || "value"}`
|
| 141 |
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
| 142 |
+
const value =
|
| 143 |
+
!labelKey && typeof label === "string"
|
| 144 |
+
? config[label as keyof typeof config]?.label || label
|
| 145 |
+
: itemConfig?.label
|
| 146 |
+
|
| 147 |
+
if (labelFormatter) {
|
| 148 |
+
return (
|
| 149 |
+
<div className={cn("font-medium", labelClassName)}>
|
| 150 |
+
{labelFormatter(value, payload)}
|
| 151 |
+
</div>
|
| 152 |
+
)
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
if (!value) {
|
| 156 |
+
return null
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>
|
| 160 |
+
}, [
|
| 161 |
+
label,
|
| 162 |
+
labelFormatter,
|
| 163 |
+
payload,
|
| 164 |
+
hideLabel,
|
| 165 |
+
labelClassName,
|
| 166 |
+
config,
|
| 167 |
+
labelKey,
|
| 168 |
+
])
|
| 169 |
+
|
| 170 |
+
if (!active || !payload?.length) {
|
| 171 |
+
return null
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
const nestLabel = payload.length === 1 && indicator !== "dot"
|
| 175 |
+
|
| 176 |
+
return (
|
| 177 |
+
<div
|
| 178 |
+
ref={ref}
|
| 179 |
+
className={cn(
|
| 180 |
+
"grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",
|
| 181 |
+
className
|
| 182 |
+
)}
|
| 183 |
+
>
|
| 184 |
+
{!nestLabel ? tooltipLabel : null}
|
| 185 |
+
<div className="grid gap-1.5">
|
| 186 |
+
{payload
|
| 187 |
+
.filter((item) => item.type !== "none")
|
| 188 |
+
.map((item, index) => {
|
| 189 |
+
const key = `${nameKey || item.name || item.dataKey || "value"}`
|
| 190 |
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
| 191 |
+
const indicatorColor = color || item.payload.fill || item.color
|
| 192 |
+
|
| 193 |
+
return (
|
| 194 |
+
<div
|
| 195 |
+
key={item.dataKey}
|
| 196 |
+
className={cn(
|
| 197 |
+
"flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
|
| 198 |
+
indicator === "dot" && "items-center"
|
| 199 |
+
)}
|
| 200 |
+
>
|
| 201 |
+
{formatter && item?.value !== undefined && item.name ? (
|
| 202 |
+
formatter(item.value, item.name, item, index, item.payload)
|
| 203 |
+
) : (
|
| 204 |
+
<>
|
| 205 |
+
{itemConfig?.icon ? (
|
| 206 |
+
<itemConfig.icon />
|
| 207 |
+
) : (
|
| 208 |
+
!hideIndicator && (
|
| 209 |
+
<div
|
| 210 |
+
className={cn(
|
| 211 |
+
"shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",
|
| 212 |
+
{
|
| 213 |
+
"h-2.5 w-2.5": indicator === "dot",
|
| 214 |
+
"w-1": indicator === "line",
|
| 215 |
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
| 216 |
+
indicator === "dashed",
|
| 217 |
+
"my-0.5": nestLabel && indicator === "dashed",
|
| 218 |
+
}
|
| 219 |
+
)}
|
| 220 |
+
style={
|
| 221 |
+
{
|
| 222 |
+
"--color-bg": indicatorColor,
|
| 223 |
+
"--color-border": indicatorColor,
|
| 224 |
+
} as React.CSSProperties
|
| 225 |
+
}
|
| 226 |
+
/>
|
| 227 |
+
)
|
| 228 |
+
)}
|
| 229 |
+
<div
|
| 230 |
+
className={cn(
|
| 231 |
+
"flex flex-1 justify-between leading-none",
|
| 232 |
+
nestLabel ? "items-end" : "items-center"
|
| 233 |
+
)}
|
| 234 |
+
>
|
| 235 |
+
<div className="grid gap-1.5">
|
| 236 |
+
{nestLabel ? tooltipLabel : null}
|
| 237 |
+
<span className="text-muted-foreground">
|
| 238 |
+
{itemConfig?.label || item.name}
|
| 239 |
+
</span>
|
| 240 |
+
</div>
|
| 241 |
+
{item.value && (
|
| 242 |
+
<span className="font-mono font-medium tabular-nums text-foreground">
|
| 243 |
+
{item.value.toLocaleString()}
|
| 244 |
+
</span>
|
| 245 |
+
)}
|
| 246 |
+
</div>
|
| 247 |
+
</>
|
| 248 |
+
)}
|
| 249 |
+
</div>
|
| 250 |
+
)
|
| 251 |
+
})}
|
| 252 |
+
</div>
|
| 253 |
+
</div>
|
| 254 |
+
)
|
| 255 |
+
}
|
| 256 |
+
)
|
| 257 |
+
ChartTooltipContent.displayName = "ChartTooltip"
|
| 258 |
+
|
| 259 |
+
const ChartLegend = RechartsPrimitive.Legend
|
| 260 |
+
|
| 261 |
+
const ChartLegendContent = React.forwardRef<
|
| 262 |
+
HTMLDivElement,
|
| 263 |
+
React.ComponentProps<"div"> &
|
| 264 |
+
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
| 265 |
+
hideIcon?: boolean
|
| 266 |
+
nameKey?: string
|
| 267 |
+
}
|
| 268 |
+
>(
|
| 269 |
+
(
|
| 270 |
+
{ className, hideIcon = false, payload, verticalAlign = "bottom", nameKey },
|
| 271 |
+
ref
|
| 272 |
+
) => {
|
| 273 |
+
const { config } = useChart()
|
| 274 |
+
|
| 275 |
+
if (!payload?.length) {
|
| 276 |
+
return null
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
return (
|
| 280 |
+
<div
|
| 281 |
+
ref={ref}
|
| 282 |
+
className={cn(
|
| 283 |
+
"flex items-center justify-center gap-4",
|
| 284 |
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
| 285 |
+
className
|
| 286 |
+
)}
|
| 287 |
+
>
|
| 288 |
+
{payload
|
| 289 |
+
.filter((item) => item.type !== "none")
|
| 290 |
+
.map((item) => {
|
| 291 |
+
const key = `${nameKey || item.dataKey || "value"}`
|
| 292 |
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
| 293 |
+
|
| 294 |
+
return (
|
| 295 |
+
<div
|
| 296 |
+
key={item.value}
|
| 297 |
+
className={cn(
|
| 298 |
+
"flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"
|
| 299 |
+
)}
|
| 300 |
+
>
|
| 301 |
+
{itemConfig?.icon && !hideIcon ? (
|
| 302 |
+
<itemConfig.icon />
|
| 303 |
+
) : (
|
| 304 |
+
<div
|
| 305 |
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
| 306 |
+
style={{
|
| 307 |
+
backgroundColor: item.color,
|
| 308 |
+
}}
|
| 309 |
+
/>
|
| 310 |
+
)}
|
| 311 |
+
{itemConfig?.label}
|
| 312 |
+
</div>
|
| 313 |
+
)
|
| 314 |
+
})}
|
| 315 |
+
</div>
|
| 316 |
+
)
|
| 317 |
+
}
|
| 318 |
+
)
|
| 319 |
+
ChartLegendContent.displayName = "ChartLegend"
|
| 320 |
+
|
| 321 |
+
// Helper to extract item config from a payload.
|
| 322 |
+
function getPayloadConfigFromPayload(
|
| 323 |
+
config: ChartConfig,
|
| 324 |
+
payload: unknown,
|
| 325 |
+
key: string
|
| 326 |
+
) {
|
| 327 |
+
if (typeof payload !== "object" || payload === null) {
|
| 328 |
+
return undefined
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
const payloadPayload =
|
| 332 |
+
"payload" in payload &&
|
| 333 |
+
typeof payload.payload === "object" &&
|
| 334 |
+
payload.payload !== null
|
| 335 |
+
? payload.payload
|
| 336 |
+
: undefined
|
| 337 |
+
|
| 338 |
+
let configLabelKey: string = key
|
| 339 |
+
|
| 340 |
+
if (
|
| 341 |
+
key in payload &&
|
| 342 |
+
typeof payload[key as keyof typeof payload] === "string"
|
| 343 |
+
) {
|
| 344 |
+
configLabelKey = payload[key as keyof typeof payload] as string
|
| 345 |
+
} else if (
|
| 346 |
+
payloadPayload &&
|
| 347 |
+
key in payloadPayload &&
|
| 348 |
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
| 349 |
+
) {
|
| 350 |
+
configLabelKey = payloadPayload[
|
| 351 |
+
key as keyof typeof payloadPayload
|
| 352 |
+
] as string
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
return configLabelKey in config
|
| 356 |
+
? config[configLabelKey]
|
| 357 |
+
: config[key as keyof typeof config]
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
export {
|
| 361 |
+
ChartContainer,
|
| 362 |
+
ChartTooltip,
|
| 363 |
+
ChartTooltipContent,
|
| 364 |
+
ChartLegend,
|
| 365 |
+
ChartLegendContent,
|
| 366 |
+
ChartStyle,
|
| 367 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/checkbox.tsx
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
| 3 |
+
import { Check } from "lucide-react"
|
| 4 |
+
|
| 5 |
+
import { cn } from "@/lib/utils"
|
| 6 |
+
|
| 7 |
+
const Checkbox = React.forwardRef<
|
| 8 |
+
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
| 9 |
+
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
| 10 |
+
>(({ className, ...props }, ref) => (
|
| 11 |
+
<CheckboxPrimitive.Root
|
| 12 |
+
ref={ref}
|
| 13 |
+
className={cn(
|
| 14 |
+
"grid place-content-center peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
| 15 |
+
className
|
| 16 |
+
)}
|
| 17 |
+
{...props}
|
| 18 |
+
>
|
| 19 |
+
<CheckboxPrimitive.Indicator
|
| 20 |
+
className={cn("grid place-content-center text-current")}
|
| 21 |
+
>
|
| 22 |
+
<Check className="h-4 w-4" />
|
| 23 |
+
</CheckboxPrimitive.Indicator>
|
| 24 |
+
</CheckboxPrimitive.Root>
|
| 25 |
+
))
|
| 26 |
+
Checkbox.displayName = CheckboxPrimitive.Root.displayName
|
| 27 |
+
|
| 28 |
+
export { Checkbox }
|
artifacts/eco-cleanup-game/src/components/ui/collapsible.tsx
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client"
|
| 2 |
+
|
| 3 |
+
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
|
| 4 |
+
|
| 5 |
+
const Collapsible = CollapsiblePrimitive.Root
|
| 6 |
+
|
| 7 |
+
const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger
|
| 8 |
+
|
| 9 |
+
const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent
|
| 10 |
+
|
| 11 |
+
export { Collapsible, CollapsibleTrigger, CollapsibleContent }
|
artifacts/eco-cleanup-game/src/components/ui/command.tsx
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client"
|
| 2 |
+
|
| 3 |
+
import * as React from "react"
|
| 4 |
+
import { type DialogProps } from "@radix-ui/react-dialog"
|
| 5 |
+
import { Command as CommandPrimitive } from "cmdk"
|
| 6 |
+
import { Search } from "lucide-react"
|
| 7 |
+
|
| 8 |
+
import { cn } from "@/lib/utils"
|
| 9 |
+
import { Dialog, DialogContent } from "@/components/ui/dialog"
|
| 10 |
+
|
| 11 |
+
const Command = React.forwardRef<
|
| 12 |
+
React.ElementRef<typeof CommandPrimitive>,
|
| 13 |
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive>
|
| 14 |
+
>(({ className, ...props }, ref) => (
|
| 15 |
+
<CommandPrimitive
|
| 16 |
+
ref={ref}
|
| 17 |
+
className={cn(
|
| 18 |
+
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
| 19 |
+
className
|
| 20 |
+
)}
|
| 21 |
+
{...props}
|
| 22 |
+
/>
|
| 23 |
+
))
|
| 24 |
+
Command.displayName = CommandPrimitive.displayName
|
| 25 |
+
|
| 26 |
+
const CommandDialog = ({ children, ...props }: DialogProps) => {
|
| 27 |
+
return (
|
| 28 |
+
<Dialog {...props}>
|
| 29 |
+
<DialogContent className="overflow-hidden p-0">
|
| 30 |
+
<Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
| 31 |
+
{children}
|
| 32 |
+
</Command>
|
| 33 |
+
</DialogContent>
|
| 34 |
+
</Dialog>
|
| 35 |
+
)
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const CommandInput = React.forwardRef<
|
| 39 |
+
React.ElementRef<typeof CommandPrimitive.Input>,
|
| 40 |
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
|
| 41 |
+
>(({ className, ...props }, ref) => (
|
| 42 |
+
<div className="flex items-center border-b px-3" cmdk-input-wrapper="">
|
| 43 |
+
<Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />
|
| 44 |
+
<CommandPrimitive.Input
|
| 45 |
+
ref={ref}
|
| 46 |
+
className={cn(
|
| 47 |
+
"flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
| 48 |
+
className
|
| 49 |
+
)}
|
| 50 |
+
{...props}
|
| 51 |
+
/>
|
| 52 |
+
</div>
|
| 53 |
+
))
|
| 54 |
+
|
| 55 |
+
CommandInput.displayName = CommandPrimitive.Input.displayName
|
| 56 |
+
|
| 57 |
+
const CommandList = React.forwardRef<
|
| 58 |
+
React.ElementRef<typeof CommandPrimitive.List>,
|
| 59 |
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
|
| 60 |
+
>(({ className, ...props }, ref) => (
|
| 61 |
+
<CommandPrimitive.List
|
| 62 |
+
ref={ref}
|
| 63 |
+
className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
|
| 64 |
+
{...props}
|
| 65 |
+
/>
|
| 66 |
+
))
|
| 67 |
+
|
| 68 |
+
CommandList.displayName = CommandPrimitive.List.displayName
|
| 69 |
+
|
| 70 |
+
const CommandEmpty = React.forwardRef<
|
| 71 |
+
React.ElementRef<typeof CommandPrimitive.Empty>,
|
| 72 |
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
|
| 73 |
+
>((props, ref) => (
|
| 74 |
+
<CommandPrimitive.Empty
|
| 75 |
+
ref={ref}
|
| 76 |
+
className="py-6 text-center text-sm"
|
| 77 |
+
{...props}
|
| 78 |
+
/>
|
| 79 |
+
))
|
| 80 |
+
|
| 81 |
+
CommandEmpty.displayName = CommandPrimitive.Empty.displayName
|
| 82 |
+
|
| 83 |
+
const CommandGroup = React.forwardRef<
|
| 84 |
+
React.ElementRef<typeof CommandPrimitive.Group>,
|
| 85 |
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
|
| 86 |
+
>(({ className, ...props }, ref) => (
|
| 87 |
+
<CommandPrimitive.Group
|
| 88 |
+
ref={ref}
|
| 89 |
+
className={cn(
|
| 90 |
+
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
|
| 91 |
+
className
|
| 92 |
+
)}
|
| 93 |
+
{...props}
|
| 94 |
+
/>
|
| 95 |
+
))
|
| 96 |
+
|
| 97 |
+
CommandGroup.displayName = CommandPrimitive.Group.displayName
|
| 98 |
+
|
| 99 |
+
const CommandSeparator = React.forwardRef<
|
| 100 |
+
React.ElementRef<typeof CommandPrimitive.Separator>,
|
| 101 |
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
|
| 102 |
+
>(({ className, ...props }, ref) => (
|
| 103 |
+
<CommandPrimitive.Separator
|
| 104 |
+
ref={ref}
|
| 105 |
+
className={cn("-mx-1 h-px bg-border", className)}
|
| 106 |
+
{...props}
|
| 107 |
+
/>
|
| 108 |
+
))
|
| 109 |
+
CommandSeparator.displayName = CommandPrimitive.Separator.displayName
|
| 110 |
+
|
| 111 |
+
const CommandItem = React.forwardRef<
|
| 112 |
+
React.ElementRef<typeof CommandPrimitive.Item>,
|
| 113 |
+
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
|
| 114 |
+
>(({ className, ...props }, ref) => (
|
| 115 |
+
<CommandPrimitive.Item
|
| 116 |
+
ref={ref}
|
| 117 |
+
className={cn(
|
| 118 |
+
"relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
| 119 |
+
className
|
| 120 |
+
)}
|
| 121 |
+
{...props}
|
| 122 |
+
/>
|
| 123 |
+
))
|
| 124 |
+
|
| 125 |
+
CommandItem.displayName = CommandPrimitive.Item.displayName
|
| 126 |
+
|
| 127 |
+
const CommandShortcut = ({
|
| 128 |
+
className,
|
| 129 |
+
...props
|
| 130 |
+
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
| 131 |
+
return (
|
| 132 |
+
<span
|
| 133 |
+
className={cn(
|
| 134 |
+
"ml-auto text-xs tracking-widest text-muted-foreground",
|
| 135 |
+
className
|
| 136 |
+
)}
|
| 137 |
+
{...props}
|
| 138 |
+
/>
|
| 139 |
+
)
|
| 140 |
+
}
|
| 141 |
+
CommandShortcut.displayName = "CommandShortcut"
|
| 142 |
+
|
| 143 |
+
export {
|
| 144 |
+
Command,
|
| 145 |
+
CommandDialog,
|
| 146 |
+
CommandInput,
|
| 147 |
+
CommandList,
|
| 148 |
+
CommandEmpty,
|
| 149 |
+
CommandGroup,
|
| 150 |
+
CommandItem,
|
| 151 |
+
CommandShortcut,
|
| 152 |
+
CommandSeparator,
|
| 153 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/context-menu.tsx
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import * as ContextMenuPrimitive from "@radix-ui/react-context-menu"
|
| 3 |
+
import { Check, ChevronRight, Circle } from "lucide-react"
|
| 4 |
+
|
| 5 |
+
import { cn } from "@/lib/utils"
|
| 6 |
+
|
| 7 |
+
const ContextMenu = ContextMenuPrimitive.Root
|
| 8 |
+
|
| 9 |
+
const ContextMenuTrigger = ContextMenuPrimitive.Trigger
|
| 10 |
+
|
| 11 |
+
const ContextMenuGroup = ContextMenuPrimitive.Group
|
| 12 |
+
|
| 13 |
+
const ContextMenuPortal = ContextMenuPrimitive.Portal
|
| 14 |
+
|
| 15 |
+
const ContextMenuSub = ContextMenuPrimitive.Sub
|
| 16 |
+
|
| 17 |
+
const ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup
|
| 18 |
+
|
| 19 |
+
const ContextMenuSubTrigger = React.forwardRef<
|
| 20 |
+
React.ElementRef<typeof ContextMenuPrimitive.SubTrigger>,
|
| 21 |
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubTrigger> & {
|
| 22 |
+
inset?: boolean
|
| 23 |
+
}
|
| 24 |
+
>(({ className, inset, children, ...props }, ref) => (
|
| 25 |
+
<ContextMenuPrimitive.SubTrigger
|
| 26 |
+
ref={ref}
|
| 27 |
+
className={cn(
|
| 28 |
+
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",
|
| 29 |
+
inset && "pl-8",
|
| 30 |
+
className
|
| 31 |
+
)}
|
| 32 |
+
{...props}
|
| 33 |
+
>
|
| 34 |
+
{children}
|
| 35 |
+
<ChevronRight className="ml-auto h-4 w-4" />
|
| 36 |
+
</ContextMenuPrimitive.SubTrigger>
|
| 37 |
+
))
|
| 38 |
+
ContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName
|
| 39 |
+
|
| 40 |
+
const ContextMenuSubContent = React.forwardRef<
|
| 41 |
+
React.ElementRef<typeof ContextMenuPrimitive.SubContent>,
|
| 42 |
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubContent>
|
| 43 |
+
>(({ className, ...props }, ref) => (
|
| 44 |
+
<ContextMenuPrimitive.SubContent
|
| 45 |
+
ref={ref}
|
| 46 |
+
className={cn(
|
| 47 |
+
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-context-menu-content-transform-origin]",
|
| 48 |
+
className
|
| 49 |
+
)}
|
| 50 |
+
{...props}
|
| 51 |
+
/>
|
| 52 |
+
))
|
| 53 |
+
ContextMenuSubContent.displayName = ContextMenuPrimitive.SubContent.displayName
|
| 54 |
+
|
| 55 |
+
const ContextMenuContent = React.forwardRef<
|
| 56 |
+
React.ElementRef<typeof ContextMenuPrimitive.Content>,
|
| 57 |
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Content>
|
| 58 |
+
>(({ className, ...props }, ref) => (
|
| 59 |
+
<ContextMenuPrimitive.Portal>
|
| 60 |
+
<ContextMenuPrimitive.Content
|
| 61 |
+
ref={ref}
|
| 62 |
+
className={cn(
|
| 63 |
+
"z-50 max-h-[--radix-context-menu-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-context-menu-content-transform-origin]",
|
| 64 |
+
className
|
| 65 |
+
)}
|
| 66 |
+
{...props}
|
| 67 |
+
/>
|
| 68 |
+
</ContextMenuPrimitive.Portal>
|
| 69 |
+
))
|
| 70 |
+
ContextMenuContent.displayName = ContextMenuPrimitive.Content.displayName
|
| 71 |
+
|
| 72 |
+
const ContextMenuItem = React.forwardRef<
|
| 73 |
+
React.ElementRef<typeof ContextMenuPrimitive.Item>,
|
| 74 |
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Item> & {
|
| 75 |
+
inset?: boolean
|
| 76 |
+
}
|
| 77 |
+
>(({ className, inset, ...props }, ref) => (
|
| 78 |
+
<ContextMenuPrimitive.Item
|
| 79 |
+
ref={ref}
|
| 80 |
+
className={cn(
|
| 81 |
+
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
| 82 |
+
inset && "pl-8",
|
| 83 |
+
className
|
| 84 |
+
)}
|
| 85 |
+
{...props}
|
| 86 |
+
/>
|
| 87 |
+
))
|
| 88 |
+
ContextMenuItem.displayName = ContextMenuPrimitive.Item.displayName
|
| 89 |
+
|
| 90 |
+
const ContextMenuCheckboxItem = React.forwardRef<
|
| 91 |
+
React.ElementRef<typeof ContextMenuPrimitive.CheckboxItem>,
|
| 92 |
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.CheckboxItem>
|
| 93 |
+
>(({ className, children, checked, ...props }, ref) => (
|
| 94 |
+
<ContextMenuPrimitive.CheckboxItem
|
| 95 |
+
ref={ref}
|
| 96 |
+
className={cn(
|
| 97 |
+
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
| 98 |
+
className
|
| 99 |
+
)}
|
| 100 |
+
checked={checked}
|
| 101 |
+
{...props}
|
| 102 |
+
>
|
| 103 |
+
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
| 104 |
+
<ContextMenuPrimitive.ItemIndicator>
|
| 105 |
+
<Check className="h-4 w-4" />
|
| 106 |
+
</ContextMenuPrimitive.ItemIndicator>
|
| 107 |
+
</span>
|
| 108 |
+
{children}
|
| 109 |
+
</ContextMenuPrimitive.CheckboxItem>
|
| 110 |
+
))
|
| 111 |
+
ContextMenuCheckboxItem.displayName =
|
| 112 |
+
ContextMenuPrimitive.CheckboxItem.displayName
|
| 113 |
+
|
| 114 |
+
const ContextMenuRadioItem = React.forwardRef<
|
| 115 |
+
React.ElementRef<typeof ContextMenuPrimitive.RadioItem>,
|
| 116 |
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.RadioItem>
|
| 117 |
+
>(({ className, children, ...props }, ref) => (
|
| 118 |
+
<ContextMenuPrimitive.RadioItem
|
| 119 |
+
ref={ref}
|
| 120 |
+
className={cn(
|
| 121 |
+
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
| 122 |
+
className
|
| 123 |
+
)}
|
| 124 |
+
{...props}
|
| 125 |
+
>
|
| 126 |
+
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
| 127 |
+
<ContextMenuPrimitive.ItemIndicator>
|
| 128 |
+
<Circle className="h-4 w-4 fill-current" />
|
| 129 |
+
</ContextMenuPrimitive.ItemIndicator>
|
| 130 |
+
</span>
|
| 131 |
+
{children}
|
| 132 |
+
</ContextMenuPrimitive.RadioItem>
|
| 133 |
+
))
|
| 134 |
+
ContextMenuRadioItem.displayName = ContextMenuPrimitive.RadioItem.displayName
|
| 135 |
+
|
| 136 |
+
const ContextMenuLabel = React.forwardRef<
|
| 137 |
+
React.ElementRef<typeof ContextMenuPrimitive.Label>,
|
| 138 |
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Label> & {
|
| 139 |
+
inset?: boolean
|
| 140 |
+
}
|
| 141 |
+
>(({ className, inset, ...props }, ref) => (
|
| 142 |
+
<ContextMenuPrimitive.Label
|
| 143 |
+
ref={ref}
|
| 144 |
+
className={cn(
|
| 145 |
+
"px-2 py-1.5 text-sm font-semibold text-foreground",
|
| 146 |
+
inset && "pl-8",
|
| 147 |
+
className
|
| 148 |
+
)}
|
| 149 |
+
{...props}
|
| 150 |
+
/>
|
| 151 |
+
))
|
| 152 |
+
ContextMenuLabel.displayName = ContextMenuPrimitive.Label.displayName
|
| 153 |
+
|
| 154 |
+
const ContextMenuSeparator = React.forwardRef<
|
| 155 |
+
React.ElementRef<typeof ContextMenuPrimitive.Separator>,
|
| 156 |
+
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Separator>
|
| 157 |
+
>(({ className, ...props }, ref) => (
|
| 158 |
+
<ContextMenuPrimitive.Separator
|
| 159 |
+
ref={ref}
|
| 160 |
+
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
| 161 |
+
{...props}
|
| 162 |
+
/>
|
| 163 |
+
))
|
| 164 |
+
ContextMenuSeparator.displayName = ContextMenuPrimitive.Separator.displayName
|
| 165 |
+
|
| 166 |
+
const ContextMenuShortcut = ({
|
| 167 |
+
className,
|
| 168 |
+
...props
|
| 169 |
+
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
| 170 |
+
return (
|
| 171 |
+
<span
|
| 172 |
+
className={cn(
|
| 173 |
+
"ml-auto text-xs tracking-widest text-muted-foreground",
|
| 174 |
+
className
|
| 175 |
+
)}
|
| 176 |
+
{...props}
|
| 177 |
+
/>
|
| 178 |
+
)
|
| 179 |
+
}
|
| 180 |
+
ContextMenuShortcut.displayName = "ContextMenuShortcut"
|
| 181 |
+
|
| 182 |
+
export {
|
| 183 |
+
ContextMenu,
|
| 184 |
+
ContextMenuTrigger,
|
| 185 |
+
ContextMenuContent,
|
| 186 |
+
ContextMenuItem,
|
| 187 |
+
ContextMenuCheckboxItem,
|
| 188 |
+
ContextMenuRadioItem,
|
| 189 |
+
ContextMenuLabel,
|
| 190 |
+
ContextMenuSeparator,
|
| 191 |
+
ContextMenuShortcut,
|
| 192 |
+
ContextMenuGroup,
|
| 193 |
+
ContextMenuPortal,
|
| 194 |
+
ContextMenuSub,
|
| 195 |
+
ContextMenuSubContent,
|
| 196 |
+
ContextMenuSubTrigger,
|
| 197 |
+
ContextMenuRadioGroup,
|
| 198 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/dialog.tsx
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import * as DialogPrimitive from "@radix-ui/react-dialog"
|
| 3 |
+
import { X } from "lucide-react"
|
| 4 |
+
|
| 5 |
+
import { cn } from "@/lib/utils"
|
| 6 |
+
|
| 7 |
+
const Dialog = DialogPrimitive.Root
|
| 8 |
+
|
| 9 |
+
const DialogTrigger = DialogPrimitive.Trigger
|
| 10 |
+
|
| 11 |
+
const DialogPortal = DialogPrimitive.Portal
|
| 12 |
+
|
| 13 |
+
const DialogClose = DialogPrimitive.Close
|
| 14 |
+
|
| 15 |
+
const DialogOverlay = React.forwardRef<
|
| 16 |
+
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
| 17 |
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
| 18 |
+
>(({ className, ...props }, ref) => (
|
| 19 |
+
<DialogPrimitive.Overlay
|
| 20 |
+
ref={ref}
|
| 21 |
+
className={cn(
|
| 22 |
+
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
| 23 |
+
className
|
| 24 |
+
)}
|
| 25 |
+
{...props}
|
| 26 |
+
/>
|
| 27 |
+
))
|
| 28 |
+
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
|
| 29 |
+
|
| 30 |
+
const DialogContent = React.forwardRef<
|
| 31 |
+
React.ElementRef<typeof DialogPrimitive.Content>,
|
| 32 |
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
| 33 |
+
>(({ className, children, ...props }, ref) => (
|
| 34 |
+
<DialogPortal>
|
| 35 |
+
<DialogOverlay />
|
| 36 |
+
<DialogPrimitive.Content
|
| 37 |
+
ref={ref}
|
| 38 |
+
className={cn(
|
| 39 |
+
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
| 40 |
+
className
|
| 41 |
+
)}
|
| 42 |
+
{...props}
|
| 43 |
+
>
|
| 44 |
+
{children}
|
| 45 |
+
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
| 46 |
+
<X className="h-4 w-4" />
|
| 47 |
+
<span className="sr-only">Close</span>
|
| 48 |
+
</DialogPrimitive.Close>
|
| 49 |
+
</DialogPrimitive.Content>
|
| 50 |
+
</DialogPortal>
|
| 51 |
+
))
|
| 52 |
+
DialogContent.displayName = DialogPrimitive.Content.displayName
|
| 53 |
+
|
| 54 |
+
const DialogHeader = ({
|
| 55 |
+
className,
|
| 56 |
+
...props
|
| 57 |
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
| 58 |
+
<div
|
| 59 |
+
className={cn(
|
| 60 |
+
"flex flex-col space-y-1.5 text-center sm:text-left",
|
| 61 |
+
className
|
| 62 |
+
)}
|
| 63 |
+
{...props}
|
| 64 |
+
/>
|
| 65 |
+
)
|
| 66 |
+
DialogHeader.displayName = "DialogHeader"
|
| 67 |
+
|
| 68 |
+
const DialogFooter = ({
|
| 69 |
+
className,
|
| 70 |
+
...props
|
| 71 |
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
| 72 |
+
<div
|
| 73 |
+
className={cn(
|
| 74 |
+
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
| 75 |
+
className
|
| 76 |
+
)}
|
| 77 |
+
{...props}
|
| 78 |
+
/>
|
| 79 |
+
)
|
| 80 |
+
DialogFooter.displayName = "DialogFooter"
|
| 81 |
+
|
| 82 |
+
const DialogTitle = React.forwardRef<
|
| 83 |
+
React.ElementRef<typeof DialogPrimitive.Title>,
|
| 84 |
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
| 85 |
+
>(({ className, ...props }, ref) => (
|
| 86 |
+
<DialogPrimitive.Title
|
| 87 |
+
ref={ref}
|
| 88 |
+
className={cn(
|
| 89 |
+
"text-lg font-semibold leading-none tracking-tight",
|
| 90 |
+
className
|
| 91 |
+
)}
|
| 92 |
+
{...props}
|
| 93 |
+
/>
|
| 94 |
+
))
|
| 95 |
+
DialogTitle.displayName = DialogPrimitive.Title.displayName
|
| 96 |
+
|
| 97 |
+
const DialogDescription = React.forwardRef<
|
| 98 |
+
React.ElementRef<typeof DialogPrimitive.Description>,
|
| 99 |
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
| 100 |
+
>(({ className, ...props }, ref) => (
|
| 101 |
+
<DialogPrimitive.Description
|
| 102 |
+
ref={ref}
|
| 103 |
+
className={cn("text-sm text-muted-foreground", className)}
|
| 104 |
+
{...props}
|
| 105 |
+
/>
|
| 106 |
+
))
|
| 107 |
+
DialogDescription.displayName = DialogPrimitive.Description.displayName
|
| 108 |
+
|
| 109 |
+
export {
|
| 110 |
+
Dialog,
|
| 111 |
+
DialogPortal,
|
| 112 |
+
DialogOverlay,
|
| 113 |
+
DialogTrigger,
|
| 114 |
+
DialogClose,
|
| 115 |
+
DialogContent,
|
| 116 |
+
DialogHeader,
|
| 117 |
+
DialogFooter,
|
| 118 |
+
DialogTitle,
|
| 119 |
+
DialogDescription,
|
| 120 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/drawer.tsx
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import { Drawer as DrawerPrimitive } from "vaul"
|
| 3 |
+
|
| 4 |
+
import { cn } from "@/lib/utils"
|
| 5 |
+
|
| 6 |
+
const Drawer = ({
|
| 7 |
+
shouldScaleBackground = true,
|
| 8 |
+
...props
|
| 9 |
+
}: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
|
| 10 |
+
<DrawerPrimitive.Root
|
| 11 |
+
shouldScaleBackground={shouldScaleBackground}
|
| 12 |
+
{...props}
|
| 13 |
+
/>
|
| 14 |
+
)
|
| 15 |
+
Drawer.displayName = "Drawer"
|
| 16 |
+
|
| 17 |
+
const DrawerTrigger = DrawerPrimitive.Trigger
|
| 18 |
+
|
| 19 |
+
const DrawerPortal = DrawerPrimitive.Portal
|
| 20 |
+
|
| 21 |
+
const DrawerClose = DrawerPrimitive.Close
|
| 22 |
+
|
| 23 |
+
const DrawerOverlay = React.forwardRef<
|
| 24 |
+
React.ElementRef<typeof DrawerPrimitive.Overlay>,
|
| 25 |
+
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
|
| 26 |
+
>(({ className, ...props }, ref) => (
|
| 27 |
+
<DrawerPrimitive.Overlay
|
| 28 |
+
ref={ref}
|
| 29 |
+
className={cn("fixed inset-0 z-50 bg-black/80", className)}
|
| 30 |
+
{...props}
|
| 31 |
+
/>
|
| 32 |
+
))
|
| 33 |
+
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName
|
| 34 |
+
|
| 35 |
+
const DrawerContent = React.forwardRef<
|
| 36 |
+
React.ElementRef<typeof DrawerPrimitive.Content>,
|
| 37 |
+
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
|
| 38 |
+
>(({ className, children, ...props }, ref) => (
|
| 39 |
+
<DrawerPortal>
|
| 40 |
+
<DrawerOverlay />
|
| 41 |
+
<DrawerPrimitive.Content
|
| 42 |
+
ref={ref}
|
| 43 |
+
className={cn(
|
| 44 |
+
"fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",
|
| 45 |
+
className
|
| 46 |
+
)}
|
| 47 |
+
{...props}
|
| 48 |
+
>
|
| 49 |
+
<div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />
|
| 50 |
+
{children}
|
| 51 |
+
</DrawerPrimitive.Content>
|
| 52 |
+
</DrawerPortal>
|
| 53 |
+
))
|
| 54 |
+
DrawerContent.displayName = "DrawerContent"
|
| 55 |
+
|
| 56 |
+
const DrawerHeader = ({
|
| 57 |
+
className,
|
| 58 |
+
...props
|
| 59 |
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
| 60 |
+
<div
|
| 61 |
+
className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
|
| 62 |
+
{...props}
|
| 63 |
+
/>
|
| 64 |
+
)
|
| 65 |
+
DrawerHeader.displayName = "DrawerHeader"
|
| 66 |
+
|
| 67 |
+
const DrawerFooter = ({
|
| 68 |
+
className,
|
| 69 |
+
...props
|
| 70 |
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
| 71 |
+
<div
|
| 72 |
+
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
| 73 |
+
{...props}
|
| 74 |
+
/>
|
| 75 |
+
)
|
| 76 |
+
DrawerFooter.displayName = "DrawerFooter"
|
| 77 |
+
|
| 78 |
+
const DrawerTitle = React.forwardRef<
|
| 79 |
+
React.ElementRef<typeof DrawerPrimitive.Title>,
|
| 80 |
+
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
|
| 81 |
+
>(({ className, ...props }, ref) => (
|
| 82 |
+
<DrawerPrimitive.Title
|
| 83 |
+
ref={ref}
|
| 84 |
+
className={cn(
|
| 85 |
+
"text-lg font-semibold leading-none tracking-tight",
|
| 86 |
+
className
|
| 87 |
+
)}
|
| 88 |
+
{...props}
|
| 89 |
+
/>
|
| 90 |
+
))
|
| 91 |
+
DrawerTitle.displayName = DrawerPrimitive.Title.displayName
|
| 92 |
+
|
| 93 |
+
const DrawerDescription = React.forwardRef<
|
| 94 |
+
React.ElementRef<typeof DrawerPrimitive.Description>,
|
| 95 |
+
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
|
| 96 |
+
>(({ className, ...props }, ref) => (
|
| 97 |
+
<DrawerPrimitive.Description
|
| 98 |
+
ref={ref}
|
| 99 |
+
className={cn("text-sm text-muted-foreground", className)}
|
| 100 |
+
{...props}
|
| 101 |
+
/>
|
| 102 |
+
))
|
| 103 |
+
DrawerDescription.displayName = DrawerPrimitive.Description.displayName
|
| 104 |
+
|
| 105 |
+
export {
|
| 106 |
+
Drawer,
|
| 107 |
+
DrawerPortal,
|
| 108 |
+
DrawerOverlay,
|
| 109 |
+
DrawerTrigger,
|
| 110 |
+
DrawerClose,
|
| 111 |
+
DrawerContent,
|
| 112 |
+
DrawerHeader,
|
| 113 |
+
DrawerFooter,
|
| 114 |
+
DrawerTitle,
|
| 115 |
+
DrawerDescription,
|
| 116 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/dropdown-menu.tsx
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client"
|
| 2 |
+
|
| 3 |
+
import * as React from "react"
|
| 4 |
+
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
|
| 5 |
+
import { Check, ChevronRight, Circle } from "lucide-react"
|
| 6 |
+
|
| 7 |
+
import { cn } from "@/lib/utils"
|
| 8 |
+
|
| 9 |
+
const DropdownMenu = DropdownMenuPrimitive.Root
|
| 10 |
+
|
| 11 |
+
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger
|
| 12 |
+
|
| 13 |
+
const DropdownMenuGroup = DropdownMenuPrimitive.Group
|
| 14 |
+
|
| 15 |
+
const DropdownMenuPortal = DropdownMenuPrimitive.Portal
|
| 16 |
+
|
| 17 |
+
const DropdownMenuSub = DropdownMenuPrimitive.Sub
|
| 18 |
+
|
| 19 |
+
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup
|
| 20 |
+
|
| 21 |
+
const DropdownMenuSubTrigger = React.forwardRef<
|
| 22 |
+
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
| 23 |
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
|
| 24 |
+
inset?: boolean
|
| 25 |
+
}
|
| 26 |
+
>(({ className, inset, children, ...props }, ref) => (
|
| 27 |
+
<DropdownMenuPrimitive.SubTrigger
|
| 28 |
+
ref={ref}
|
| 29 |
+
className={cn(
|
| 30 |
+
"flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
| 31 |
+
inset && "pl-8",
|
| 32 |
+
className
|
| 33 |
+
)}
|
| 34 |
+
{...props}
|
| 35 |
+
>
|
| 36 |
+
{children}
|
| 37 |
+
<ChevronRight className="ml-auto" />
|
| 38 |
+
</DropdownMenuPrimitive.SubTrigger>
|
| 39 |
+
))
|
| 40 |
+
DropdownMenuSubTrigger.displayName =
|
| 41 |
+
DropdownMenuPrimitive.SubTrigger.displayName
|
| 42 |
+
|
| 43 |
+
const DropdownMenuSubContent = React.forwardRef<
|
| 44 |
+
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
| 45 |
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
| 46 |
+
>(({ className, ...props }, ref) => (
|
| 47 |
+
<DropdownMenuPrimitive.SubContent
|
| 48 |
+
ref={ref}
|
| 49 |
+
className={cn(
|
| 50 |
+
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]",
|
| 51 |
+
className
|
| 52 |
+
)}
|
| 53 |
+
{...props}
|
| 54 |
+
/>
|
| 55 |
+
))
|
| 56 |
+
DropdownMenuSubContent.displayName =
|
| 57 |
+
DropdownMenuPrimitive.SubContent.displayName
|
| 58 |
+
|
| 59 |
+
const DropdownMenuContent = React.forwardRef<
|
| 60 |
+
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
| 61 |
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
| 62 |
+
>(({ className, sideOffset = 4, ...props }, ref) => (
|
| 63 |
+
<DropdownMenuPrimitive.Portal>
|
| 64 |
+
<DropdownMenuPrimitive.Content
|
| 65 |
+
ref={ref}
|
| 66 |
+
sideOffset={sideOffset}
|
| 67 |
+
className={cn(
|
| 68 |
+
"z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
|
| 69 |
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]",
|
| 70 |
+
className
|
| 71 |
+
)}
|
| 72 |
+
{...props}
|
| 73 |
+
/>
|
| 74 |
+
</DropdownMenuPrimitive.Portal>
|
| 75 |
+
))
|
| 76 |
+
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
|
| 77 |
+
|
| 78 |
+
const DropdownMenuItem = React.forwardRef<
|
| 79 |
+
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
| 80 |
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
|
| 81 |
+
inset?: boolean
|
| 82 |
+
}
|
| 83 |
+
>(({ className, inset, ...props }, ref) => (
|
| 84 |
+
<DropdownMenuPrimitive.Item
|
| 85 |
+
ref={ref}
|
| 86 |
+
className={cn(
|
| 87 |
+
"relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",
|
| 88 |
+
inset && "pl-8",
|
| 89 |
+
className
|
| 90 |
+
)}
|
| 91 |
+
{...props}
|
| 92 |
+
/>
|
| 93 |
+
))
|
| 94 |
+
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName
|
| 95 |
+
|
| 96 |
+
const DropdownMenuCheckboxItem = React.forwardRef<
|
| 97 |
+
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
| 98 |
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
|
| 99 |
+
>(({ className, children, checked, ...props }, ref) => (
|
| 100 |
+
<DropdownMenuPrimitive.CheckboxItem
|
| 101 |
+
ref={ref}
|
| 102 |
+
className={cn(
|
| 103 |
+
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
| 104 |
+
className
|
| 105 |
+
)}
|
| 106 |
+
checked={checked}
|
| 107 |
+
{...props}
|
| 108 |
+
>
|
| 109 |
+
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
| 110 |
+
<DropdownMenuPrimitive.ItemIndicator>
|
| 111 |
+
<Check className="h-4 w-4" />
|
| 112 |
+
</DropdownMenuPrimitive.ItemIndicator>
|
| 113 |
+
</span>
|
| 114 |
+
{children}
|
| 115 |
+
</DropdownMenuPrimitive.CheckboxItem>
|
| 116 |
+
))
|
| 117 |
+
DropdownMenuCheckboxItem.displayName =
|
| 118 |
+
DropdownMenuPrimitive.CheckboxItem.displayName
|
| 119 |
+
|
| 120 |
+
const DropdownMenuRadioItem = React.forwardRef<
|
| 121 |
+
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
| 122 |
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
|
| 123 |
+
>(({ className, children, ...props }, ref) => (
|
| 124 |
+
<DropdownMenuPrimitive.RadioItem
|
| 125 |
+
ref={ref}
|
| 126 |
+
className={cn(
|
| 127 |
+
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
| 128 |
+
className
|
| 129 |
+
)}
|
| 130 |
+
{...props}
|
| 131 |
+
>
|
| 132 |
+
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
| 133 |
+
<DropdownMenuPrimitive.ItemIndicator>
|
| 134 |
+
<Circle className="h-2 w-2 fill-current" />
|
| 135 |
+
</DropdownMenuPrimitive.ItemIndicator>
|
| 136 |
+
</span>
|
| 137 |
+
{children}
|
| 138 |
+
</DropdownMenuPrimitive.RadioItem>
|
| 139 |
+
))
|
| 140 |
+
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName
|
| 141 |
+
|
| 142 |
+
const DropdownMenuLabel = React.forwardRef<
|
| 143 |
+
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
| 144 |
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
|
| 145 |
+
inset?: boolean
|
| 146 |
+
}
|
| 147 |
+
>(({ className, inset, ...props }, ref) => (
|
| 148 |
+
<DropdownMenuPrimitive.Label
|
| 149 |
+
ref={ref}
|
| 150 |
+
className={cn(
|
| 151 |
+
"px-2 py-1.5 text-sm font-semibold",
|
| 152 |
+
inset && "pl-8",
|
| 153 |
+
className
|
| 154 |
+
)}
|
| 155 |
+
{...props}
|
| 156 |
+
/>
|
| 157 |
+
))
|
| 158 |
+
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName
|
| 159 |
+
|
| 160 |
+
const DropdownMenuSeparator = React.forwardRef<
|
| 161 |
+
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
| 162 |
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
|
| 163 |
+
>(({ className, ...props }, ref) => (
|
| 164 |
+
<DropdownMenuPrimitive.Separator
|
| 165 |
+
ref={ref}
|
| 166 |
+
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
| 167 |
+
{...props}
|
| 168 |
+
/>
|
| 169 |
+
))
|
| 170 |
+
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
|
| 171 |
+
|
| 172 |
+
const DropdownMenuShortcut = ({
|
| 173 |
+
className,
|
| 174 |
+
...props
|
| 175 |
+
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
| 176 |
+
return (
|
| 177 |
+
<span
|
| 178 |
+
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
|
| 179 |
+
{...props}
|
| 180 |
+
/>
|
| 181 |
+
)
|
| 182 |
+
}
|
| 183 |
+
DropdownMenuShortcut.displayName = "DropdownMenuShortcut"
|
| 184 |
+
|
| 185 |
+
export {
|
| 186 |
+
DropdownMenu,
|
| 187 |
+
DropdownMenuTrigger,
|
| 188 |
+
DropdownMenuContent,
|
| 189 |
+
DropdownMenuItem,
|
| 190 |
+
DropdownMenuCheckboxItem,
|
| 191 |
+
DropdownMenuRadioItem,
|
| 192 |
+
DropdownMenuLabel,
|
| 193 |
+
DropdownMenuSeparator,
|
| 194 |
+
DropdownMenuShortcut,
|
| 195 |
+
DropdownMenuGroup,
|
| 196 |
+
DropdownMenuPortal,
|
| 197 |
+
DropdownMenuSub,
|
| 198 |
+
DropdownMenuSubContent,
|
| 199 |
+
DropdownMenuSubTrigger,
|
| 200 |
+
DropdownMenuRadioGroup,
|
| 201 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/empty.tsx
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { cva, type VariantProps } from "class-variance-authority"
|
| 2 |
+
|
| 3 |
+
import { cn } from "@/lib/utils"
|
| 4 |
+
|
| 5 |
+
function Empty({ className, ...props }: React.ComponentProps<"div">) {
|
| 6 |
+
return (
|
| 7 |
+
<div
|
| 8 |
+
data-slot="empty"
|
| 9 |
+
className={cn(
|
| 10 |
+
"flex min-w-0 flex-1 flex-col items-center justify-center gap-6 text-balance rounded-lg border-dashed p-6 text-center md:p-12",
|
| 11 |
+
className
|
| 12 |
+
)}
|
| 13 |
+
{...props}
|
| 14 |
+
/>
|
| 15 |
+
)
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
function EmptyHeader({ className, ...props }: React.ComponentProps<"div">) {
|
| 19 |
+
return (
|
| 20 |
+
<div
|
| 21 |
+
data-slot="empty-header"
|
| 22 |
+
className={cn(
|
| 23 |
+
"flex max-w-sm flex-col items-center gap-2 text-center",
|
| 24 |
+
className
|
| 25 |
+
)}
|
| 26 |
+
{...props}
|
| 27 |
+
/>
|
| 28 |
+
)
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
const emptyMediaVariants = cva(
|
| 32 |
+
"mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
| 33 |
+
{
|
| 34 |
+
variants: {
|
| 35 |
+
variant: {
|
| 36 |
+
default: "bg-transparent",
|
| 37 |
+
icon: "bg-muted text-foreground flex size-10 shrink-0 items-center justify-center rounded-lg [&_svg:not([class*='size-'])]:size-6",
|
| 38 |
+
},
|
| 39 |
+
},
|
| 40 |
+
defaultVariants: {
|
| 41 |
+
variant: "default",
|
| 42 |
+
},
|
| 43 |
+
}
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
function EmptyMedia({
|
| 47 |
+
className,
|
| 48 |
+
variant = "default",
|
| 49 |
+
...props
|
| 50 |
+
}: React.ComponentProps<"div"> & VariantProps<typeof emptyMediaVariants>) {
|
| 51 |
+
return (
|
| 52 |
+
<div
|
| 53 |
+
data-slot="empty-icon"
|
| 54 |
+
data-variant={variant}
|
| 55 |
+
className={cn(emptyMediaVariants({ variant, className }))}
|
| 56 |
+
{...props}
|
| 57 |
+
/>
|
| 58 |
+
)
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
function EmptyTitle({ className, ...props }: React.ComponentProps<"div">) {
|
| 62 |
+
return (
|
| 63 |
+
<div
|
| 64 |
+
data-slot="empty-title"
|
| 65 |
+
className={cn("text-lg font-medium tracking-tight", className)}
|
| 66 |
+
{...props}
|
| 67 |
+
/>
|
| 68 |
+
)
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
function EmptyDescription({ className, ...props }: React.ComponentProps<"p">) {
|
| 72 |
+
return (
|
| 73 |
+
<div
|
| 74 |
+
data-slot="empty-description"
|
| 75 |
+
className={cn(
|
| 76 |
+
"text-muted-foreground [&>a:hover]:text-primary text-sm/relaxed [&>a]:underline [&>a]:underline-offset-4",
|
| 77 |
+
className
|
| 78 |
+
)}
|
| 79 |
+
{...props}
|
| 80 |
+
/>
|
| 81 |
+
)
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
function EmptyContent({ className, ...props }: React.ComponentProps<"div">) {
|
| 85 |
+
return (
|
| 86 |
+
<div
|
| 87 |
+
data-slot="empty-content"
|
| 88 |
+
className={cn(
|
| 89 |
+
"flex w-full min-w-0 max-w-sm flex-col items-center gap-4 text-balance text-sm",
|
| 90 |
+
className
|
| 91 |
+
)}
|
| 92 |
+
{...props}
|
| 93 |
+
/>
|
| 94 |
+
)
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
export {
|
| 98 |
+
Empty,
|
| 99 |
+
EmptyHeader,
|
| 100 |
+
EmptyTitle,
|
| 101 |
+
EmptyDescription,
|
| 102 |
+
EmptyContent,
|
| 103 |
+
EmptyMedia,
|
| 104 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/field.tsx
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client"
|
| 2 |
+
|
| 3 |
+
import { useMemo } from "react"
|
| 4 |
+
import { cva, type VariantProps } from "class-variance-authority"
|
| 5 |
+
|
| 6 |
+
import { cn } from "@/lib/utils"
|
| 7 |
+
import { Label } from "@/components/ui/label"
|
| 8 |
+
import { Separator } from "@/components/ui/separator"
|
| 9 |
+
|
| 10 |
+
function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
| 11 |
+
return (
|
| 12 |
+
<fieldset
|
| 13 |
+
data-slot="field-set"
|
| 14 |
+
className={cn(
|
| 15 |
+
"flex flex-col gap-6",
|
| 16 |
+
"has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
|
| 17 |
+
className
|
| 18 |
+
)}
|
| 19 |
+
{...props}
|
| 20 |
+
/>
|
| 21 |
+
)
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
function FieldLegend({
|
| 25 |
+
className,
|
| 26 |
+
variant = "legend",
|
| 27 |
+
...props
|
| 28 |
+
}: React.ComponentProps<"legend"> & { variant?: "legend" | "label" }) {
|
| 29 |
+
return (
|
| 30 |
+
<legend
|
| 31 |
+
data-slot="field-legend"
|
| 32 |
+
data-variant={variant}
|
| 33 |
+
className={cn(
|
| 34 |
+
"mb-3 font-medium",
|
| 35 |
+
"data-[variant=legend]:text-base",
|
| 36 |
+
"data-[variant=label]:text-sm",
|
| 37 |
+
className
|
| 38 |
+
)}
|
| 39 |
+
{...props}
|
| 40 |
+
/>
|
| 41 |
+
)
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
|
| 45 |
+
return (
|
| 46 |
+
<div
|
| 47 |
+
data-slot="field-group"
|
| 48 |
+
className={cn(
|
| 49 |
+
"group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4",
|
| 50 |
+
className
|
| 51 |
+
)}
|
| 52 |
+
{...props}
|
| 53 |
+
/>
|
| 54 |
+
)
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
const fieldVariants = cva(
|
| 58 |
+
"group/field data-[invalid=true]:text-destructive flex w-full gap-3",
|
| 59 |
+
{
|
| 60 |
+
variants: {
|
| 61 |
+
orientation: {
|
| 62 |
+
vertical: ["flex-col [&>*]:w-full [&>.sr-only]:w-auto"],
|
| 63 |
+
horizontal: [
|
| 64 |
+
"flex-row items-center",
|
| 65 |
+
"[&>[data-slot=field-label]]:flex-auto",
|
| 66 |
+
"has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px has-[>[data-slot=field-content]]:items-start",
|
| 67 |
+
],
|
| 68 |
+
responsive: [
|
| 69 |
+
"@md/field-group:flex-row @md/field-group:items-center @md/field-group:[&>*]:w-auto flex-col [&>*]:w-full [&>.sr-only]:w-auto",
|
| 70 |
+
"@md/field-group:[&>[data-slot=field-label]]:flex-auto",
|
| 71 |
+
"@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
|
| 72 |
+
],
|
| 73 |
+
},
|
| 74 |
+
},
|
| 75 |
+
defaultVariants: {
|
| 76 |
+
orientation: "vertical",
|
| 77 |
+
},
|
| 78 |
+
}
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
function Field({
|
| 82 |
+
className,
|
| 83 |
+
orientation = "vertical",
|
| 84 |
+
...props
|
| 85 |
+
}: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>) {
|
| 86 |
+
return (
|
| 87 |
+
<div
|
| 88 |
+
role="group"
|
| 89 |
+
data-slot="field"
|
| 90 |
+
data-orientation={orientation}
|
| 91 |
+
className={cn(fieldVariants({ orientation }), className)}
|
| 92 |
+
{...props}
|
| 93 |
+
/>
|
| 94 |
+
)
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
| 98 |
+
return (
|
| 99 |
+
<div
|
| 100 |
+
data-slot="field-content"
|
| 101 |
+
className={cn(
|
| 102 |
+
"group/field-content flex flex-1 flex-col gap-1.5 leading-snug",
|
| 103 |
+
className
|
| 104 |
+
)}
|
| 105 |
+
{...props}
|
| 106 |
+
/>
|
| 107 |
+
)
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
function FieldLabel({
|
| 111 |
+
className,
|
| 112 |
+
...props
|
| 113 |
+
}: React.ComponentProps<typeof Label>) {
|
| 114 |
+
return (
|
| 115 |
+
<Label
|
| 116 |
+
data-slot="field-label"
|
| 117 |
+
className={cn(
|
| 118 |
+
"group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50",
|
| 119 |
+
"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>[data-slot=field]]:p-4",
|
| 120 |
+
"has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10",
|
| 121 |
+
className
|
| 122 |
+
)}
|
| 123 |
+
{...props}
|
| 124 |
+
/>
|
| 125 |
+
)
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
|
| 129 |
+
return (
|
| 130 |
+
<div
|
| 131 |
+
data-slot="field-label"
|
| 132 |
+
className={cn(
|
| 133 |
+
"flex w-fit items-center gap-2 text-sm font-medium leading-snug group-data-[disabled=true]/field:opacity-50",
|
| 134 |
+
className
|
| 135 |
+
)}
|
| 136 |
+
{...props}
|
| 137 |
+
/>
|
| 138 |
+
)
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
|
| 142 |
+
return (
|
| 143 |
+
<p
|
| 144 |
+
data-slot="field-description"
|
| 145 |
+
className={cn(
|
| 146 |
+
"text-muted-foreground text-sm font-normal leading-normal group-has-[[data-orientation=horizontal]]/field:text-balance",
|
| 147 |
+
"nth-last-2:-mt-1 last:mt-0 [[data-variant=legend]+&]:-mt-1.5",
|
| 148 |
+
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
| 149 |
+
className
|
| 150 |
+
)}
|
| 151 |
+
{...props}
|
| 152 |
+
/>
|
| 153 |
+
)
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
function FieldSeparator({
|
| 157 |
+
children,
|
| 158 |
+
className,
|
| 159 |
+
...props
|
| 160 |
+
}: React.ComponentProps<"div"> & {
|
| 161 |
+
children?: React.ReactNode
|
| 162 |
+
}) {
|
| 163 |
+
return (
|
| 164 |
+
<div
|
| 165 |
+
data-slot="field-separator"
|
| 166 |
+
data-content={!!children}
|
| 167 |
+
className={cn(
|
| 168 |
+
"relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2",
|
| 169 |
+
className
|
| 170 |
+
)}
|
| 171 |
+
{...props}
|
| 172 |
+
>
|
| 173 |
+
<Separator className="absolute inset-0 top-1/2" />
|
| 174 |
+
{children && (
|
| 175 |
+
<span
|
| 176 |
+
className="bg-background text-muted-foreground relative mx-auto block w-fit px-2"
|
| 177 |
+
data-slot="field-separator-content"
|
| 178 |
+
>
|
| 179 |
+
{children}
|
| 180 |
+
</span>
|
| 181 |
+
)}
|
| 182 |
+
</div>
|
| 183 |
+
)
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
function FieldError({
|
| 187 |
+
className,
|
| 188 |
+
children,
|
| 189 |
+
errors,
|
| 190 |
+
...props
|
| 191 |
+
}: React.ComponentProps<"div"> & {
|
| 192 |
+
errors?: Array<{ message?: string } | undefined>
|
| 193 |
+
}) {
|
| 194 |
+
const content = useMemo(() => {
|
| 195 |
+
if (children) {
|
| 196 |
+
return children
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
if (!errors) {
|
| 200 |
+
return null
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
if (errors?.length === 1 && errors[0]?.message) {
|
| 204 |
+
return errors[0].message
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
return (
|
| 208 |
+
<ul className="ml-4 flex list-disc flex-col gap-1">
|
| 209 |
+
{errors.map(
|
| 210 |
+
(error, index) =>
|
| 211 |
+
error?.message && <li key={index}>{error.message}</li>
|
| 212 |
+
)}
|
| 213 |
+
</ul>
|
| 214 |
+
)
|
| 215 |
+
}, [children, errors])
|
| 216 |
+
|
| 217 |
+
if (!content) {
|
| 218 |
+
return null
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
return (
|
| 222 |
+
<div
|
| 223 |
+
role="alert"
|
| 224 |
+
data-slot="field-error"
|
| 225 |
+
className={cn("text-destructive text-sm font-normal", className)}
|
| 226 |
+
{...props}
|
| 227 |
+
>
|
| 228 |
+
{content}
|
| 229 |
+
</div>
|
| 230 |
+
)
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
export {
|
| 234 |
+
Field,
|
| 235 |
+
FieldLabel,
|
| 236 |
+
FieldDescription,
|
| 237 |
+
FieldError,
|
| 238 |
+
FieldGroup,
|
| 239 |
+
FieldLegend,
|
| 240 |
+
FieldSeparator,
|
| 241 |
+
FieldSet,
|
| 242 |
+
FieldContent,
|
| 243 |
+
FieldTitle,
|
| 244 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/form.tsx
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import * as LabelPrimitive from "@radix-ui/react-label"
|
| 3 |
+
import { Slot } from "@radix-ui/react-slot"
|
| 4 |
+
import {
|
| 5 |
+
Controller,
|
| 6 |
+
FormProvider,
|
| 7 |
+
useFormContext,
|
| 8 |
+
type ControllerProps,
|
| 9 |
+
type FieldPath,
|
| 10 |
+
type FieldValues,
|
| 11 |
+
} from "react-hook-form"
|
| 12 |
+
|
| 13 |
+
import { cn } from "@/lib/utils"
|
| 14 |
+
import { Label } from "@/components/ui/label"
|
| 15 |
+
|
| 16 |
+
const Form = FormProvider
|
| 17 |
+
|
| 18 |
+
type FormFieldContextValue<
|
| 19 |
+
TFieldValues extends FieldValues = FieldValues,
|
| 20 |
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
| 21 |
+
> = {
|
| 22 |
+
name: TName
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
const FormFieldContext = React.createContext<FormFieldContextValue | null>(null)
|
| 26 |
+
|
| 27 |
+
const FormField = <
|
| 28 |
+
TFieldValues extends FieldValues = FieldValues,
|
| 29 |
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
| 30 |
+
>({
|
| 31 |
+
...props
|
| 32 |
+
}: ControllerProps<TFieldValues, TName>) => {
|
| 33 |
+
return (
|
| 34 |
+
<FormFieldContext.Provider value={{ name: props.name }}>
|
| 35 |
+
<Controller {...props} />
|
| 36 |
+
</FormFieldContext.Provider>
|
| 37 |
+
)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
const useFormField = () => {
|
| 41 |
+
const fieldContext = React.useContext(FormFieldContext)
|
| 42 |
+
const itemContext = React.useContext(FormItemContext)
|
| 43 |
+
const { getFieldState, formState } = useFormContext()
|
| 44 |
+
|
| 45 |
+
if (!fieldContext) {
|
| 46 |
+
throw new Error("useFormField should be used within <FormField>")
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if (!itemContext) {
|
| 50 |
+
throw new Error("useFormField should be used within <FormItem>")
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
const fieldState = getFieldState(fieldContext.name, formState)
|
| 54 |
+
|
| 55 |
+
const { id } = itemContext
|
| 56 |
+
|
| 57 |
+
return {
|
| 58 |
+
id,
|
| 59 |
+
name: fieldContext.name,
|
| 60 |
+
formItemId: `${id}-form-item`,
|
| 61 |
+
formDescriptionId: `${id}-form-item-description`,
|
| 62 |
+
formMessageId: `${id}-form-item-message`,
|
| 63 |
+
...fieldState,
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
type FormItemContextValue = {
|
| 68 |
+
id: string
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
const FormItemContext = React.createContext<FormItemContextValue | null>(null)
|
| 72 |
+
|
| 73 |
+
const FormItem = React.forwardRef<
|
| 74 |
+
HTMLDivElement,
|
| 75 |
+
React.HTMLAttributes<HTMLDivElement>
|
| 76 |
+
>(({ className, ...props }, ref) => {
|
| 77 |
+
const id = React.useId()
|
| 78 |
+
|
| 79 |
+
return (
|
| 80 |
+
<FormItemContext.Provider value={{ id }}>
|
| 81 |
+
<div ref={ref} className={cn("space-y-2", className)} {...props} />
|
| 82 |
+
</FormItemContext.Provider>
|
| 83 |
+
)
|
| 84 |
+
})
|
| 85 |
+
FormItem.displayName = "FormItem"
|
| 86 |
+
|
| 87 |
+
const FormLabel = React.forwardRef<
|
| 88 |
+
React.ElementRef<typeof LabelPrimitive.Root>,
|
| 89 |
+
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
|
| 90 |
+
>(({ className, ...props }, ref) => {
|
| 91 |
+
const { error, formItemId } = useFormField()
|
| 92 |
+
|
| 93 |
+
return (
|
| 94 |
+
<Label
|
| 95 |
+
ref={ref}
|
| 96 |
+
className={cn(error && "text-destructive", className)}
|
| 97 |
+
htmlFor={formItemId}
|
| 98 |
+
{...props}
|
| 99 |
+
/>
|
| 100 |
+
)
|
| 101 |
+
})
|
| 102 |
+
FormLabel.displayName = "FormLabel"
|
| 103 |
+
|
| 104 |
+
const FormControl = React.forwardRef<
|
| 105 |
+
React.ElementRef<typeof Slot>,
|
| 106 |
+
React.ComponentPropsWithoutRef<typeof Slot>
|
| 107 |
+
>(({ ...props }, ref) => {
|
| 108 |
+
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
|
| 109 |
+
|
| 110 |
+
return (
|
| 111 |
+
<Slot
|
| 112 |
+
ref={ref}
|
| 113 |
+
id={formItemId}
|
| 114 |
+
aria-describedby={
|
| 115 |
+
!error
|
| 116 |
+
? `${formDescriptionId}`
|
| 117 |
+
: `${formDescriptionId} ${formMessageId}`
|
| 118 |
+
}
|
| 119 |
+
aria-invalid={!!error}
|
| 120 |
+
{...props}
|
| 121 |
+
/>
|
| 122 |
+
)
|
| 123 |
+
})
|
| 124 |
+
FormControl.displayName = "FormControl"
|
| 125 |
+
|
| 126 |
+
const FormDescription = React.forwardRef<
|
| 127 |
+
HTMLParagraphElement,
|
| 128 |
+
React.HTMLAttributes<HTMLParagraphElement>
|
| 129 |
+
>(({ className, ...props }, ref) => {
|
| 130 |
+
const { formDescriptionId } = useFormField()
|
| 131 |
+
|
| 132 |
+
return (
|
| 133 |
+
<p
|
| 134 |
+
ref={ref}
|
| 135 |
+
id={formDescriptionId}
|
| 136 |
+
className={cn("text-[0.8rem] text-muted-foreground", className)}
|
| 137 |
+
{...props}
|
| 138 |
+
/>
|
| 139 |
+
)
|
| 140 |
+
})
|
| 141 |
+
FormDescription.displayName = "FormDescription"
|
| 142 |
+
|
| 143 |
+
const FormMessage = React.forwardRef<
|
| 144 |
+
HTMLParagraphElement,
|
| 145 |
+
React.HTMLAttributes<HTMLParagraphElement>
|
| 146 |
+
>(({ className, children, ...props }, ref) => {
|
| 147 |
+
const { error, formMessageId } = useFormField()
|
| 148 |
+
const body = error ? String(error?.message ?? "") : children
|
| 149 |
+
|
| 150 |
+
if (!body) {
|
| 151 |
+
return null
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
return (
|
| 155 |
+
<p
|
| 156 |
+
ref={ref}
|
| 157 |
+
id={formMessageId}
|
| 158 |
+
className={cn("text-[0.8rem] font-medium text-destructive", className)}
|
| 159 |
+
{...props}
|
| 160 |
+
>
|
| 161 |
+
{body}
|
| 162 |
+
</p>
|
| 163 |
+
)
|
| 164 |
+
})
|
| 165 |
+
FormMessage.displayName = "FormMessage"
|
| 166 |
+
|
| 167 |
+
export {
|
| 168 |
+
useFormField,
|
| 169 |
+
Form,
|
| 170 |
+
FormItem,
|
| 171 |
+
FormLabel,
|
| 172 |
+
FormControl,
|
| 173 |
+
FormDescription,
|
| 174 |
+
FormMessage,
|
| 175 |
+
FormField,
|
| 176 |
+
}
|
artifacts/eco-cleanup-game/src/components/ui/hover-card.tsx
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import * as HoverCardPrimitive from "@radix-ui/react-hover-card"
|
| 3 |
+
|
| 4 |
+
import { cn } from "@/lib/utils"
|
| 5 |
+
|
| 6 |
+
const HoverCard = HoverCardPrimitive.Root
|
| 7 |
+
|
| 8 |
+
const HoverCardTrigger = HoverCardPrimitive.Trigger
|
| 9 |
+
|
| 10 |
+
const HoverCardContent = React.forwardRef<
|
| 11 |
+
React.ElementRef<typeof HoverCardPrimitive.Content>,
|
| 12 |
+
React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>
|
| 13 |
+
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
|
| 14 |
+
<HoverCardPrimitive.Content
|
| 15 |
+
ref={ref}
|
| 16 |
+
align={align}
|
| 17 |
+
sideOffset={sideOffset}
|
| 18 |
+
className={cn(
|
| 19 |
+
"z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-hover-card-content-transform-origin]",
|
| 20 |
+
className
|
| 21 |
+
)}
|
| 22 |
+
{...props}
|
| 23 |
+
/>
|
| 24 |
+
))
|
| 25 |
+
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName
|
| 26 |
+
|
| 27 |
+
export { HoverCard, HoverCardTrigger, HoverCardContent }
|
artifacts/eco-cleanup-game/src/components/ui/input-group.tsx
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as React from "react"
|
| 2 |
+
import { cva, type VariantProps } from "class-variance-authority"
|
| 3 |
+
|
| 4 |
+
import { cn } from "@/lib/utils"
|
| 5 |
+
import { Button } from "@/components/ui/button"
|
| 6 |
+
import { Input } from "@/components/ui/input"
|
| 7 |
+
import { Textarea } from "@/components/ui/textarea"
|
| 8 |
+
|
| 9 |
+
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
|
| 10 |
+
return (
|
| 11 |
+
<div
|
| 12 |
+
data-slot="input-group"
|
| 13 |
+
role="group"
|
| 14 |
+
className={cn(
|
| 15 |
+
"group/input-group border-input dark:bg-input/30 shadow-xs relative flex w-full items-center rounded-md border outline-none transition-[color,box-shadow]",
|
| 16 |
+
"h-9 has-[>textarea]:h-auto",
|
| 17 |
+
|
| 18 |
+
// Variants based on alignment.
|
| 19 |
+
"has-[>[data-align=inline-start]]:[&>input]:pl-2",
|
| 20 |
+
"has-[>[data-align=inline-end]]:[&>input]:pr-2",
|
| 21 |
+
"has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3",
|
| 22 |
+
"has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3",
|
| 23 |
+
|
| 24 |
+
// Focus state.
|
| 25 |
+
"has-[[data-slot=input-group-control]:focus-visible]:ring-ring has-[[data-slot=input-group-control]:focus-visible]:ring-1",
|
| 26 |
+
|
| 27 |
+
// Error state.
|
| 28 |
+
"has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",
|
| 29 |
+
|
| 30 |
+
className
|
| 31 |
+
)}
|
| 32 |
+
{...props}
|
| 33 |
+
/>
|
| 34 |
+
)
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
const inputGroupAddonVariants = cva(
|
| 38 |
+
"text-muted-foreground flex h-auto cursor-text select-none items-center justify-center gap-2 py-1.5 text-sm font-medium group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",
|
| 39 |
+
{
|
| 40 |
+
variants: {
|
| 41 |
+
align: {
|
| 42 |
+
"inline-start":
|
| 43 |
+
"order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]",
|
| 44 |
+
"inline-end":
|
| 45 |
+
"order-last pr-3 has-[>button]:mr-[-0.4rem] has-[>kbd]:mr-[-0.35rem]",
|
| 46 |
+
"block-start":
|
| 47 |
+
"[.border-b]:pb-3 order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5",
|
| 48 |
+
"block-end":
|
| 49 |
+
"[.border-t]:pt-3 order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5",
|
| 50 |
+
},
|
| 51 |
+
},
|
| 52 |
+
defaultVariants: {
|
| 53 |
+
align: "inline-start",
|
| 54 |
+
},
|
| 55 |
+
}
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
function InputGroupAddon({
|
| 59 |
+
className,
|
| 60 |
+
align = "inline-start",
|
| 61 |
+
...props
|
| 62 |
+
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
|
| 63 |
+
return (
|
| 64 |
+
<div
|
| 65 |
+
role="group"
|
| 66 |
+
data-slot="input-group-addon"
|
| 67 |
+
data-align={align}
|
| 68 |
+
className={cn(inputGroupAddonVariants({ align }), className)}
|
| 69 |
+
onClick={(e) => {
|
| 70 |
+
if ((e.target as HTMLElement).closest("button")) {
|
| 71 |
+
return
|
| 72 |
+
}
|
| 73 |
+
e.currentTarget.parentElement?.querySelector("input")?.focus()
|
| 74 |
+
}}
|
| 75 |
+
{...props}
|
| 76 |
+
/>
|
| 77 |
+
)
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
const inputGroupButtonVariants = cva(
|
| 81 |
+
"flex items-center gap-2 text-sm shadow-none",
|
| 82 |
+
{
|
| 83 |
+
variants: {
|
| 84 |
+
size: {
|
| 85 |
+
xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",
|
| 86 |
+
sm: "h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5",
|
| 87 |
+
"icon-xs":
|
| 88 |
+
"size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
|
| 89 |
+
"icon-sm": "size-8 p-0 has-[>svg]:p-0",
|
| 90 |
+
},
|
| 91 |
+
},
|
| 92 |
+
defaultVariants: {
|
| 93 |
+
size: "xs",
|
| 94 |
+
},
|
| 95 |
+
}
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
function InputGroupButton({
|
| 99 |
+
className,
|
| 100 |
+
type = "button",
|
| 101 |
+
variant = "ghost",
|
| 102 |
+
size = "xs",
|
| 103 |
+
...props
|
| 104 |
+
}: Omit<React.ComponentProps<typeof Button>, "size"> &
|
| 105 |
+
VariantProps<typeof inputGroupButtonVariants>) {
|
| 106 |
+
return (
|
| 107 |
+
<Button
|
| 108 |
+
type={type}
|
| 109 |
+
data-size={size}
|
| 110 |
+
variant={variant}
|
| 111 |
+
className={cn(inputGroupButtonVariants({ size }), className)}
|
| 112 |
+
{...props}
|
| 113 |
+
/>
|
| 114 |
+
)
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
|
| 118 |
+
return (
|
| 119 |
+
<span
|
| 120 |
+
className={cn(
|
| 121 |
+
"text-muted-foreground flex items-center gap-2 text-sm [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none",
|
| 122 |
+
className
|
| 123 |
+
)}
|
| 124 |
+
{...props}
|
| 125 |
+
/>
|
| 126 |
+
)
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
function InputGroupInput({
|
| 130 |
+
className,
|
| 131 |
+
...props
|
| 132 |
+
}: React.ComponentProps<"input">) {
|
| 133 |
+
return (
|
| 134 |
+
<Input
|
| 135 |
+
data-slot="input-group-control"
|
| 136 |
+
className={cn(
|
| 137 |
+
"flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent",
|
| 138 |
+
className
|
| 139 |
+
)}
|
| 140 |
+
{...props}
|
| 141 |
+
/>
|
| 142 |
+
)
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
function InputGroupTextarea({
|
| 146 |
+
className,
|
| 147 |
+
...props
|
| 148 |
+
}: React.ComponentProps<"textarea">) {
|
| 149 |
+
return (
|
| 150 |
+
<Textarea
|
| 151 |
+
data-slot="input-group-control"
|
| 152 |
+
className={cn(
|
| 153 |
+
"flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",
|
| 154 |
+
className
|
| 155 |
+
)}
|
| 156 |
+
{...props}
|
| 157 |
+
/>
|
| 158 |
+
)
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
export {
|
| 162 |
+
InputGroup,
|
| 163 |
+
InputGroupAddon,
|
| 164 |
+
InputGroupButton,
|
| 165 |
+
InputGroupText,
|
| 166 |
+
InputGroupInput,
|
| 167 |
+
InputGroupTextarea,
|
| 168 |
+
}
|