v0.9 工单修复部署
This commit is contained in:
Executable
+167
@@ -0,0 +1,167 @@
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
--color-sidebar-border: var(--sidebar-border);
|
||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||
--color-sidebar-accent: var(--sidebar-accent);
|
||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-ring: var(--ring);
|
||||
--color-input: var(--input);
|
||||
--color-border: var(--border);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-card: var(--card);
|
||||
--radius-sm: calc(var(--radius) - 4px);
|
||||
--radius-md: calc(var(--radius) - 2px);
|
||||
--radius-lg: var(--radius);
|
||||
--radius-xl: calc(var(--radius) + 4px);
|
||||
}
|
||||
|
||||
:root {
|
||||
--radius: 0.625rem;
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
--card: oklch(1 0 0);
|
||||
--card-foreground: oklch(0.145 0 0);
|
||||
--popover: oklch(1 0 0);
|
||||
--popover-foreground: oklch(0.145 0 0);
|
||||
--primary: oklch(0.205 0 0);
|
||||
--primary-foreground: oklch(0.985 0 0);
|
||||
--secondary: oklch(0.97 0 0);
|
||||
--secondary-foreground: oklch(0.205 0 0);
|
||||
--muted: oklch(0.97 0 0);
|
||||
--muted-foreground: oklch(0.556 0 0);
|
||||
--accent: oklch(0.97 0 0);
|
||||
--accent-foreground: oklch(0.205 0 0);
|
||||
--destructive: oklch(0.577 0.245 27.325);
|
||||
--border: oklch(0.922 0 0);
|
||||
--input: oklch(0.922 0 0);
|
||||
--ring: oklch(0.708 0 0);
|
||||
--chart-1: oklch(0.646 0.222 41.116);
|
||||
--chart-2: oklch(0.6 0.118 184.704);
|
||||
--chart-3: oklch(0.398 0.07 227.392);
|
||||
--chart-4: oklch(0.828 0.189 84.429);
|
||||
--chart-5: oklch(0.769 0.188 70.08);
|
||||
--sidebar: oklch(0.985 0 0);
|
||||
--sidebar-foreground: oklch(0.145 0 0);
|
||||
--sidebar-primary: oklch(0.205 0 0);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.97 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||
--sidebar-border: oklch(0.922 0 0);
|
||||
--sidebar-ring: oklch(0.708 0 0);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: oklch(0.13 0.02 290);
|
||||
--foreground: oklch(0.97 0.01 200);
|
||||
--card: oklch(0.19 0.025 290);
|
||||
--card-foreground: oklch(0.97 0.01 200);
|
||||
--popover: oklch(0.19 0.025 290);
|
||||
--popover-foreground: oklch(0.97 0.01 200);
|
||||
--primary: oklch(0.78 0.17 162);
|
||||
--primary-foreground: oklch(0.15 0.02 290);
|
||||
--secondary: oklch(0.28 0.03 290);
|
||||
--secondary-foreground: oklch(0.97 0.01 200);
|
||||
--muted: oklch(0.26 0.02 290);
|
||||
--muted-foreground: oklch(0.72 0.02 200);
|
||||
--accent: oklch(0.32 0.05 320);
|
||||
--accent-foreground: oklch(0.97 0.01 200);
|
||||
--destructive: oklch(0.704 0.191 22.216);
|
||||
--border: oklch(1 0 0 / 10%);
|
||||
--input: oklch(1 0 0 / 15%);
|
||||
--ring: oklch(0.72 0.16 320);
|
||||
--chart-1: oklch(0.72 0.19 162);
|
||||
--chart-2: oklch(0.74 0.18 15);
|
||||
--chart-3: oklch(0.82 0.17 75);
|
||||
--chart-4: oklch(0.72 0.22 320);
|
||||
--chart-5: oklch(0.78 0.13 195);
|
||||
--sidebar: oklch(0.19 0.025 290);
|
||||
--sidebar-foreground: oklch(0.97 0.01 200);
|
||||
--sidebar-primary: oklch(0.78 0.17 162);
|
||||
--sidebar-primary-foreground: oklch(0.15 0.02 290);
|
||||
--sidebar-accent: oklch(0.32 0.05 320);
|
||||
--sidebar-accent-foreground: oklch(0.97 0.01 200);
|
||||
--sidebar-border: oklch(1 0 0 / 10%);
|
||||
--sidebar-ring: oklch(0.72 0.16 320);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border outline-ring/50;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
background-color: #050410;
|
||||
}
|
||||
}
|
||||
|
||||
/* 全局滚动条 */
|
||||
::-webkit-scrollbar { width: 8px; height: 8px; }
|
||||
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 4px; }
|
||||
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.24); }
|
||||
::-webkit-scrollbar-track { background: transparent; }
|
||||
|
||||
/* 玻璃态卡片 */
|
||||
.glass {
|
||||
background: rgba(20, 16, 40, 0.45);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
/* 渐变文字 */
|
||||
.text-gradient {
|
||||
background: linear-gradient(135deg, #34d399 0%, #e879f9 50%, #fb7185 100%);
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
|
||||
/* 通用脉冲 */
|
||||
@keyframes echo-glow {
|
||||
0%, 100% { opacity: 0.6; }
|
||||
50% { opacity: 1; }
|
||||
}
|
||||
|
||||
/* 教程系统动画 */
|
||||
@keyframes tut-pulse {
|
||||
0%, 100% {
|
||||
box-shadow: 0 0 0 2px rgba(232,121,249,0.9), 0 0 24px 4px rgba(232,121,249,0.4);
|
||||
}
|
||||
50% {
|
||||
box-shadow: 0 0 0 3px rgba(232,121,249,1), 0 0 32px 8px rgba(232,121,249,0.7);
|
||||
}
|
||||
}
|
||||
|
||||
/* 教程提示气泡入场 */
|
||||
@keyframes tut-pop-in {
|
||||
0% { opacity: 0; transform: scale(0.92) translateY(8px); }
|
||||
100% { opacity: 1; transform: scale(1) translateY(0); }
|
||||
}
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import { Toaster } from "@/components/ui/toaster";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "回响星核 · Echo Nexus",
|
||||
description: "原创深空考古放置策略游戏 — 解码记忆晶体,拼凑以太文明的回响,跨越维度发起接触。",
|
||||
keywords: ["Echo Nexus", "回响星核", "idle game", "browser game", "放置游戏", "解谜", "深空考古"],
|
||||
authors: [{ name: "Super_Z" }],
|
||||
icons: {
|
||||
icon: "https://z-cdn.chatglm.cn/z-ai/static/logo.svg",
|
||||
},
|
||||
openGraph: {
|
||||
title: "回响星核 · Echo Nexus",
|
||||
description: "原创深空考古放置策略游戏",
|
||||
siteName: "Echo Nexus",
|
||||
type: "website",
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: "回响星核 · Echo Nexus",
|
||||
description: "原创深空考古放置策略游戏",
|
||||
},
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="zh-CN" suppressHydrationWarning className="dark">
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased bg-background text-foreground`}
|
||||
>
|
||||
{children}
|
||||
<Toaster />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
Executable
+608
@@ -0,0 +1,608 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 游戏主入口
|
||||
import { useState, useEffect } from "react";
|
||||
import { StarfieldCanvas } from "@/components/game/StarfieldCanvas";
|
||||
import { ResourceBar } from "@/components/game/ResourceBar";
|
||||
import { CrystalOrb } from "@/components/game/CrystalOrb";
|
||||
import { DecodePanel } from "@/components/game/DecodeArray";
|
||||
import { TechTree } from "@/components/game/TechTree";
|
||||
import { Codex } from "@/components/game/Codex";
|
||||
import { PrestigeDialog } from "@/components/game/PrestigeDialog";
|
||||
import { SettingsDialog } from "@/components/game/SettingsDialog";
|
||||
import { ExpeditionPanel } from "@/components/game/ExpeditionPanel";
|
||||
import { AchievementsPanel } from "@/components/game/AchievementsPanel";
|
||||
import { AchievementNotifier } from "@/components/game/AchievementNotifier";
|
||||
import { ConstellationPanel } from "@/components/game/ConstellationPanel";
|
||||
import { ConstellationDialog } from "@/components/game/ConstellationDialog";
|
||||
import { ChronicleDialog } from "@/components/game/ChronicleDialog";
|
||||
import { BeaconPanel } from "@/components/game/BeaconPanel";
|
||||
import { TutorialOverlay } from "@/components/game/TutorialOverlay";
|
||||
import { OfflineReportDialog } from "@/components/game/OfflineReportDialog";
|
||||
import { CruiseMode } from "@/components/game/CruiseMode";
|
||||
import { AttributesPanel } from "@/components/game/AttributesPanel";
|
||||
import {
|
||||
StarTideNotifier,
|
||||
StarTideIndicator,
|
||||
StarTideOverlay,
|
||||
} from "@/components/game/StarTide";
|
||||
import { useGameLoop } from "@/hooks/useGameLoop";
|
||||
import { useAudioSync } from "@/hooks/useAudio";
|
||||
import { useGlobalTide } from "@/hooks/useGlobalTide";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Settings,
|
||||
RotateCcw,
|
||||
Sparkles,
|
||||
Cpu,
|
||||
BookOpen,
|
||||
BarChart3,
|
||||
Rocket,
|
||||
Github,
|
||||
Trophy,
|
||||
Star,
|
||||
Radio,
|
||||
Navigation,
|
||||
User,
|
||||
Gem,
|
||||
Zap,
|
||||
Flame,
|
||||
Database,
|
||||
} from "lucide-react";
|
||||
import { TECH_TREE, FRAGMENTS, formatNum } from "@/lib/game/config";
|
||||
import { ACHIEVEMENTS } from "@/lib/game/achievements";
|
||||
import { TIDE_EVENTS } from "@/lib/game/starTide";
|
||||
import { CONSTELLATION_PERKS } from "@/lib/game/constellation";
|
||||
import { generateDailyChallenge, loadDailyProgress, loadLeaderboard } from "@/lib/game/beacon";
|
||||
|
||||
export default function Page() {
|
||||
useGameLoop();
|
||||
useAudioSync();
|
||||
useGlobalTide();
|
||||
const [prestigeOpen, setPrestigeOpen] = useState(false);
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const [constellationOpen, setConstellationOpen] = useState(false);
|
||||
const [chronicleOpen, setChronicleOpen] = useState(false);
|
||||
const [cruiseOpen, setCruiseOpen] = useState(false);
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
const contact = useGameStore((s) => s.contact);
|
||||
const totalDecoded = useGameStore((s) => s.totalDecoded);
|
||||
const crystalsPerSec = useGameStore((s) => s.crystalsPerSec);
|
||||
const ascensions = useGameStore((s) => s.ascensions);
|
||||
const ownedTech = useGameStore((s) => s.tech);
|
||||
const ownedFragments = useGameStore((s) => s.fragments);
|
||||
const ownedAchievements = useGameStore((s) => s.achievements);
|
||||
const ownedConstellation = useGameStore((s) => s.constellation ?? []);
|
||||
const pendingPerkChoices = useGameStore((s) => s.pendingPerkChoices);
|
||||
const crystals = useGameStore((s) => s.crystals);
|
||||
const crystalCap = useGameStore((s) => s.crystalCap);
|
||||
const activeTide = useGameStore((s) => s.activeTide);
|
||||
const globalTide = useGameStore((s) => s.globalTide);
|
||||
const energy = useGameStore((s) => s.energy);
|
||||
const hasActiveExpedition = useGameStore((s) => !!s.activeExpedition && !s.activeExpedition.finished);
|
||||
const chronicleCount = useGameStore((s) => s.chronicle?.length ?? 0);
|
||||
const pendingAttrPoints = useGameStore((s) => s.pendingAttrPoints ?? 0);
|
||||
|
||||
// 深空信标:检测是否有可领取的奖励(独立 localStorage)
|
||||
const [beaconClaimable, setBeaconClaimable] = useState(false);
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const check = () => {
|
||||
try {
|
||||
const c = generateDailyChallenge();
|
||||
const p = loadDailyProgress();
|
||||
if (!cancelled) {
|
||||
setBeaconClaimable(p.completedAt !== null && !p.claimed && p.dateKey === c.dateKey);
|
||||
}
|
||||
} catch {
|
||||
if (!cancelled) setBeaconClaimable(false);
|
||||
}
|
||||
};
|
||||
check();
|
||||
const id = setInterval(check, 2000);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
clearInterval(id);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 挂载检测:避免持久化 store 在 SSR/CSR 间产生 hydration 不一致
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
// 防止 SSR/CSR 不一致
|
||||
if (!mounted) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-[#050410] text-muted-foreground">
|
||||
<div className="animate-pulse">唤醒回响中…</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const ownedTechCount = Object.values(ownedTech).filter((v) => v > 0).length;
|
||||
const ownedFragCount = Object.values(ownedFragments).filter(Boolean).length;
|
||||
const ownedAchCount = Object.values(ownedAchievements).filter(Boolean).length;
|
||||
const canPrestige = contact >= 100;
|
||||
const hasPendingPerk = pendingPerkChoices && pendingPerkChoices.length > 0;
|
||||
|
||||
// 仓库满仓警告
|
||||
const warehouseFull = crystals >= crystalCap * 0.98;
|
||||
|
||||
// 目标提示
|
||||
let goal = "点击中央晶体发起脉冲,累积记忆晶体";
|
||||
if (totalDecoded === 0 && crystals >= 5) {
|
||||
goal = "右侧「待解码晶体」点击一颗晶体,开始解码";
|
||||
} else if (totalDecoded > 0 && ownedTechCount === 0) {
|
||||
goal = "用洞见解锁技术树,提升产能";
|
||||
} else if (totalDecoded > 0 && ownedFragCount < FRAGMENTS.length) {
|
||||
goal = `继续解码,拼凑记忆图谱(${ownedFragCount}/${FRAGMENTS.length})`;
|
||||
}
|
||||
if (energy >= 1 && totalDecoded >= 3) {
|
||||
goal = "「探险」标签可深入遗迹,获取丰厚奖励";
|
||||
}
|
||||
if (ascensions >= 1 && ownedConstellation.length > 0) {
|
||||
goal = `星图天赋已觉醒 ${ownedConstellation.length}/18,继续飞升获取更多`;
|
||||
}
|
||||
if (warehouseFull) {
|
||||
goal = "⚠ 仓库已满,产能浪费中!请解码晶体或升级仓库";
|
||||
}
|
||||
if (hasPendingPerk) {
|
||||
goal = "✦ 星图觉醒!点击顶部「星图」按钮选择一道天赋";
|
||||
}
|
||||
if (activeTide) {
|
||||
const tm = TIDE_EVENTS[activeTide.type];
|
||||
const prefix = globalTide ? "🌐 全球星潮 · " : "";
|
||||
goal = `${prefix}${tm.icon} 星潮「${tm.name}」进行中 · ${tm.desc}`;
|
||||
}
|
||||
if (canPrestige) goal = "✦ 接触进度已满,可发起飞升进入新周目";
|
||||
|
||||
return (
|
||||
<div className="relative min-h-screen flex flex-col bg-[#050410] text-foreground overflow-x-hidden">
|
||||
{/* 星空背景 */}
|
||||
<StarfieldCanvas className="fixed inset-0 w-full h-full -z-10" />
|
||||
{/* 星潮背景叠层 */}
|
||||
<StarTideOverlay />
|
||||
|
||||
{/* 顶部 Header */}
|
||||
<header className="sticky top-0 z-30 px-3 sm:px-5 pt-3 pb-2">
|
||||
<div className="flex items-center gap-3 mb-2.5">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="relative h-9 w-9">
|
||||
<div className="absolute inset-0 rounded-full bg-gradient-to-br from-emerald-400 via-fuchsia-500 to-rose-400 blur-md opacity-60" />
|
||||
<div className="absolute inset-1 rounded-full bg-[#050410] flex items-center justify-center">
|
||||
<Sparkles className="h-4 w-4 text-fuchsia-300" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="leading-tight">
|
||||
<h1 className="text-base sm:text-lg font-bold text-gradient">回响星核</h1>
|
||||
<p className="text-[9px] sm:text-[10px] text-muted-foreground/70 -mt-0.5 tracking-wider">
|
||||
ECHO NEXUS · v0.8
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="ml-auto flex items-center gap-1.5">
|
||||
<StarTideIndicator />
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => setCruiseOpen(true)}
|
||||
className="border-amber-400/50 text-amber-200 hover:bg-amber-500/10 h-8 px-2.5"
|
||||
aria-label="深空巡航"
|
||||
title="深空巡航 · 实时玩法"
|
||||
>
|
||||
<Navigation className="h-3.5 w-3.5 mr-1" />
|
||||
巡航
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
onClick={() => setChronicleOpen(true)}
|
||||
className="h-8 w-8 relative group"
|
||||
aria-label="编年史"
|
||||
title="回响编年史"
|
||||
>
|
||||
<BookOpen className="h-4 w-4 group-hover:text-fuchsia-300 transition-colors" />
|
||||
{chronicleCount > 0 && (
|
||||
<span className="absolute -top-0.5 -right-0.5 min-w-[14px] h-[14px] px-1 rounded-full bg-fuchsia-500 text-[9px] font-mono font-bold text-white flex items-center justify-center border border-fuchsia-300/50">
|
||||
{chronicleCount}
|
||||
</span>
|
||||
)}
|
||||
</Button>
|
||||
{hasPendingPerk && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => setConstellationOpen(true)}
|
||||
className="border-fuchsia-400/60 text-fuchsia-200 hover:bg-fuchsia-500/15 h-8 px-2.5 animate-pulse"
|
||||
>
|
||||
<Star className="h-3.5 w-3.5 mr-1" />
|
||||
觉醒
|
||||
</Button>
|
||||
)}
|
||||
{canPrestige && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => setPrestigeOpen(true)}
|
||||
data-tut="prestige-btn"
|
||||
className="border-fuchsia-400/50 text-fuchsia-200 hover:bg-fuchsia-500/10 h-8 px-2.5"
|
||||
>
|
||||
<RotateCcw className="h-3.5 w-3.5 mr-1" />
|
||||
飞升
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
onClick={() => setSettingsOpen(true)}
|
||||
className="h-8 w-8"
|
||||
aria-label="设置"
|
||||
>
|
||||
<Settings className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<ResourceBar onPrestige={() => setPrestigeOpen(true)} />
|
||||
</header>
|
||||
|
||||
{/* 主体 — 小屏允许自然滚动,避免 min-h 总和超过视口导致挤压重叠 */}
|
||||
<main className="flex-1 px-3 sm:px-5 pb-3 min-h-0">
|
||||
<div className="grid grid-cols-1 lg:grid-cols-[1fr_minmax(360px,420px)] gap-3 h-full">
|
||||
{/* 左侧:脉冲晶体 */}
|
||||
<section className="glass rounded-2xl p-4 sm:p-6 flex flex-col items-center justify-center min-h-[340px] sm:min-h-[420px] relative overflow-hidden">
|
||||
{/* 装饰光圈 */}
|
||||
<div className="pointer-events-none absolute -top-20 -left-20 h-60 w-60 rounded-full bg-emerald-500/10 blur-3xl" />
|
||||
<div className="pointer-events-none absolute -bottom-20 -right-20 h-60 w-60 rounded-full bg-fuchsia-500/10 blur-3xl" />
|
||||
{/* v0.8.2 装饰全息环(填充留白,提升视觉层次) */}
|
||||
<div className="pointer-events-none absolute inset-6 rounded-full border border-emerald-400/10 animate-[spin_60s_linear_infinite]" />
|
||||
<div className="pointer-events-none absolute inset-10 rounded-full border border-dashed border-fuchsia-400/10 animate-[spin_90s_linear_infinite_reverse]" />
|
||||
<div className="pointer-events-none absolute inset-16 rounded-full border border-rose-400/8" />
|
||||
{/* 四角全息标记 */}
|
||||
<div className="pointer-events-none absolute top-3 left-3 h-4 w-4 border-l border-t border-emerald-400/30 rounded-tl" />
|
||||
<div className="pointer-events-none absolute top-3 right-3 h-4 w-4 border-r border-t border-fuchsia-400/30 rounded-tr" />
|
||||
<div className="pointer-events-none absolute bottom-3 left-3 h-4 w-4 border-l border-b border-amber-400/30 rounded-bl" />
|
||||
<div className="pointer-events-none absolute bottom-3 right-3 h-4 w-4 border-r border-b border-rose-400/30 rounded-br" />
|
||||
{/* 顶部状态条 */}
|
||||
<div className="pointer-events-none absolute top-3 left-1/2 -translate-x-1/2 flex items-center gap-2 text-[9px] font-mono text-muted-foreground/60">
|
||||
<span className="h-1 w-1 rounded-full bg-emerald-400 animate-pulse" />
|
||||
<span>CRYSTAL CORE · ONLINE</span>
|
||||
<span className="h-1 w-1 rounded-full bg-fuchsia-400 animate-pulse" />
|
||||
</div>
|
||||
{/* 底部铭文 */}
|
||||
<div className="pointer-events-none absolute bottom-3 left-1/2 -translate-x-1/2 text-[8px] font-mono text-muted-foreground/40 tracking-[0.3em] uppercase">
|
||||
echo · nexus · archaeology
|
||||
</div>
|
||||
<div data-tut="crystal-orb" className="contents">
|
||||
<CrystalOrb />
|
||||
</div>
|
||||
{/* v0.9 工单 #2:全息收益信息面板 — 让晶体球价值可视化 */}
|
||||
<CrystalYieldPanel />
|
||||
</section>
|
||||
|
||||
{/* 右侧:解码 + 标签面板 */}
|
||||
<section className="flex flex-col gap-3 min-h-0">
|
||||
{/* 解码面板 */}
|
||||
<div data-tut="decode-panel" className="glass rounded-2xl p-4 flex-1 min-h-[300px] sm:min-h-[360px] max-h-[560px]">
|
||||
<DecodePanel />
|
||||
</div>
|
||||
{/* 标签面板:探险 / 技术 / 星图 / 图谱 / 成就 / 信标 / 统计 / 角色 */}
|
||||
{/* v0.9 工单修复:移除 max-h 硬限制,改用 min-h + flex 自适应,避免成就/技术树内容被挤压遮挡 */}
|
||||
<div className="glass rounded-2xl p-3 min-h-[300px] sm:min-h-[360px] max-h-[520px] flex flex-col">
|
||||
<Tabs defaultValue={hasActiveExpedition ? "expedition" : hasPendingPerk ? "constellation" : "tech"} className="h-full flex flex-col">
|
||||
{/* v0.9 工单修复:标签页响应式布局,小屏 4 列 2 行避免拥挤遮挡 */}
|
||||
<TabsList className="grid grid-cols-4 sm:grid-cols-8 h-auto sm:h-9 bg-black/30 gap-0.5 p-1">
|
||||
<TabsTrigger value="expedition" data-tut="tab-expedition" className="text-[11px] gap-1 relative px-0.5 flex-col h-7 data-[state=active]:bg-amber-500/15 data-[state=active]:shadow-[0_0_12px_rgba(251,191,36,0.3)] transition-all">
|
||||
<Rocket className="h-3.5 w-3.5" />
|
||||
<span className="leading-none">探险</span>
|
||||
{energy >= 1 && !hasActiveExpedition && (
|
||||
<span className="absolute -top-0.5 -right-0.5 h-2 w-2 rounded-full bg-amber-400 animate-pulse ring-1 ring-black/50" />
|
||||
)}
|
||||
{hasActiveExpedition && (
|
||||
<span className="absolute -top-0.5 -right-0.5 h-2 w-2 rounded-full bg-rose-400 animate-pulse ring-1 ring-black/50" />
|
||||
)}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="tech" data-tut="tab-tech" className="text-[11px] gap-1 px-0.5 flex-col h-7 data-[state=active]:bg-emerald-500/15 data-[state=active]:shadow-[0_0_12px_rgba(52,211,153,0.3)] transition-all">
|
||||
<Cpu className="h-3.5 w-3.5" />
|
||||
<span className="leading-none">技术</span>
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="constellation" className="text-[11px] gap-1 relative px-0.5 flex-col h-7 data-[state=active]:bg-fuchsia-500/15 data-[state=active]:shadow-[0_0_12px_rgba(232,121,249,0.3)] transition-all">
|
||||
<Star className="h-3.5 w-3.5" />
|
||||
<span className="leading-none">星图</span>
|
||||
{hasPendingPerk && (
|
||||
<span className="absolute -top-0.5 -right-0.5 h-2 w-2 rounded-full bg-fuchsia-400 animate-pulse ring-1 ring-black/50" />
|
||||
)}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="codex" className="text-[11px] gap-1 px-0.5 flex-col h-7 data-[state=active]:bg-cyan-500/15 data-[state=active]:shadow-[0_0_12px_rgba(34,211,238,0.3)] transition-all">
|
||||
<BookOpen className="h-3.5 w-3.5" />
|
||||
<span className="leading-none">图谱</span>
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="ach" className="text-[11px] gap-1 relative px-0.5 flex-col h-7 data-[state=active]:bg-amber-500/15 data-[state=active]:shadow-[0_0_12px_rgba(251,191,36,0.3)] transition-all">
|
||||
<Trophy className="h-3.5 w-3.5" />
|
||||
<span className="leading-none">成就</span>
|
||||
{ownedAchCount < ACHIEVEMENTS.length && (
|
||||
<span className="absolute -top-0.5 -right-0.5 h-2 w-2 rounded-full bg-amber-400 animate-pulse ring-1 ring-black/50" />
|
||||
)}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="beacon" className="text-[11px] gap-1 relative px-0.5 flex-col h-7 data-[state=active]:bg-emerald-500/15 data-[state=active]:shadow-[0_0_12px_rgba(52,211,153,0.3)] transition-all">
|
||||
<Radio className="h-3.5 w-3.5" />
|
||||
<span className="leading-none">信标</span>
|
||||
{beaconClaimable && (
|
||||
<span className="absolute -top-0.5 -right-0.5 h-2 w-2 rounded-full bg-emerald-400 animate-pulse ring-1 ring-black/50" />
|
||||
)}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="stats" className="text-[11px] gap-1 px-0.5 flex-col h-7 data-[state=active]:bg-slate-500/15 data-[state=active]:shadow-[0_0_12px_rgba(148,163,184,0.3)] transition-all">
|
||||
<BarChart3 className="h-3.5 w-3.5" />
|
||||
<span className="leading-none">统计</span>
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="attributes" className="text-[11px] gap-1 relative px-0.5 flex-col h-7 data-[state=active]:bg-gradient-to-br data-[state=active]:from-emerald-500/15 data-[state=active]:via-fuchsia-500/15 data-[state=active]:to-rose-500/15 data-[state=active]:shadow-[0_0_12px_rgba(232,121,249,0.3)] transition-all">
|
||||
<User className="h-3.5 w-3.5" />
|
||||
<span className="leading-none">角色</span>
|
||||
{pendingAttrPoints > 0 && (
|
||||
<span className="absolute -top-0.5 -right-0.5 h-2 w-2 rounded-full bg-rose-400 animate-pulse ring-1 ring-black/50" />
|
||||
)}
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value="expedition" className="flex-1 mt-2 min-h-0 data-[state=active]:flex data-[state=active]:flex-col">
|
||||
<ExpeditionPanel />
|
||||
</TabsContent>
|
||||
<TabsContent value="tech" className="flex-1 mt-2 min-h-0 data-[state=active]:flex data-[state=active]:flex-col">
|
||||
<TechTree />
|
||||
</TabsContent>
|
||||
<TabsContent value="constellation" className="flex-1 mt-2 min-h-0 data-[state=active]:flex data-[state=active]:flex-col">
|
||||
<ConstellationPanel />
|
||||
</TabsContent>
|
||||
<TabsContent value="codex" className="flex-1 mt-2 min-h-0 data-[state=active]:flex data-[state=active]:flex-col">
|
||||
<Codex />
|
||||
</TabsContent>
|
||||
<TabsContent value="ach" className="flex-1 mt-2 min-h-0 data-[state=active]:flex data-[state=active]:flex-col">
|
||||
<AchievementsPanel />
|
||||
</TabsContent>
|
||||
<TabsContent value="beacon" className="flex-1 mt-2 min-h-0 data-[state=active]:flex data-[state=active]:flex-col">
|
||||
<BeaconPanel />
|
||||
</TabsContent>
|
||||
<TabsContent value="stats" className="flex-1 mt-2 min-h-0">
|
||||
<StatsPanel />
|
||||
</TabsContent>
|
||||
<TabsContent value="attributes" className="flex-1 mt-2 min-h-0 data-[state=active]:flex data-[state=active]:flex-col">
|
||||
<AttributesPanel />
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{/* 底部 Footer */}
|
||||
<footer className="sticky bottom-0 z-20 mt-auto px-3 sm:px-5 pb-2 pt-1">
|
||||
<div
|
||||
className={`glass rounded-xl px-3 py-2 flex items-center gap-2 text-xs ${
|
||||
warehouseFull ? "border-amber-400/40 animate-pulse" : ""
|
||||
} ${activeTide ? "border-white/20" : ""}`}
|
||||
style={
|
||||
activeTide
|
||||
? { boxShadow: `inset 0 0 16px ${TIDE_EVENTS[activeTide.type].glow}` }
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<span
|
||||
className={
|
||||
warehouseFull
|
||||
? "text-amber-400"
|
||||
: activeTide
|
||||
? ""
|
||||
: "text-fuchsia-300"
|
||||
}
|
||||
style={activeTide ? { color: TIDE_EVENTS[activeTide.type].color } : undefined}
|
||||
>
|
||||
▶
|
||||
</span>
|
||||
<span
|
||||
className={`flex-1 truncate ${
|
||||
warehouseFull ? "text-amber-200" : "text-muted-foreground"
|
||||
}`}
|
||||
>
|
||||
{goal}
|
||||
</span>
|
||||
<span className="hidden sm:inline text-muted-foreground/60">|</span>
|
||||
<span className="hidden sm:inline text-muted-foreground/70">
|
||||
产能 {formatNum(crystalsPerSec)}/s
|
||||
</span>
|
||||
<a
|
||||
href="https://git.atdunbg.xyz/Super_Z/echo-nexus"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="text-muted-foreground/60 hover:text-foreground transition ml-1"
|
||||
aria-label="仓库"
|
||||
>
|
||||
<Github className="h-3.5 w-3.5" />
|
||||
</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<PrestigeDialog open={prestigeOpen} onOpenChange={setPrestigeOpen} />
|
||||
<ChronicleDialog open={chronicleOpen} onOpenChange={setChronicleOpen} />
|
||||
<ConstellationDialog open={constellationOpen} onOpenChange={setConstellationOpen} />
|
||||
<SettingsDialog open={settingsOpen} onOpenChange={setSettingsOpen} />
|
||||
<AchievementNotifier />
|
||||
<StarTideNotifier />
|
||||
<TutorialOverlay />
|
||||
<OfflineReportDialog />
|
||||
{cruiseOpen && <CruiseMode onClose={() => setCruiseOpen(false)} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* v0.9 工单 #2:全息收益信息面板
|
||||
* 在中央晶体球下方展示 4 项核心收益指标(产能 / 脉冲 / 连击 / 仓库),
|
||||
* 让玩家明确感知晶体球的价值,缓解"占地方又没用"的反馈。
|
||||
* 严格四色全息配色:emerald / rose / amber / fuchsia(禁止蓝色/靛色)。
|
||||
*/
|
||||
function CrystalYieldPanel() {
|
||||
const crystalsPerSec = useGameStore((s) => s.crystalsPerSec);
|
||||
const pulsePower = useGameStore((s) => s.pulsePower);
|
||||
const combo = useGameStore((s) => s._combo);
|
||||
const crystals = useGameStore((s) => s.crystals);
|
||||
const crystalCap = useGameStore((s) => s.crystalCap);
|
||||
|
||||
// 连击倍率:1 + (combo - 1) * 0.15(仅 combo≥1 时生效)
|
||||
const comboMult = combo >= 1 ? 1 + (combo - 1) * 0.15 : 1;
|
||||
const comboHot = combo >= 3; // 连击≥3 高亮闪烁
|
||||
|
||||
// 仓库容量百分比
|
||||
const fillPct = crystalCap > 0 ? (crystals / crystalCap) * 100 : 0;
|
||||
const warehouseWarn = fillPct >= 90; // ≥90% 警告色 + pulse
|
||||
|
||||
return (
|
||||
<div className="mt-3 grid grid-cols-2 sm:grid-cols-4 gap-2 w-full max-w-md pointer-events-none">
|
||||
{/* 晶体产能 — emerald */}
|
||||
<div className="rounded-lg border border-emerald-400/30 bg-black/30 backdrop-blur p-2 flex items-center gap-1.5">
|
||||
<Gem className="h-3.5 w-3.5 text-emerald-400 shrink-0" />
|
||||
<div className="min-w-0 leading-tight">
|
||||
<div className="text-[9px] uppercase tracking-wider text-emerald-300/70 truncate">
|
||||
晶体产能
|
||||
</div>
|
||||
<div className="text-sm font-mono tabular-nums text-emerald-200 truncate">
|
||||
{formatNum(crystalsPerSec)}
|
||||
<span className="text-[9px] text-emerald-300/60">/s</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 主动脉冲 — rose */}
|
||||
<div className="rounded-lg border border-rose-400/30 bg-black/30 backdrop-blur p-2 flex items-center gap-1.5">
|
||||
<Zap className="h-3.5 w-3.5 text-rose-400 shrink-0" />
|
||||
<div className="min-w-0 leading-tight">
|
||||
<div className="text-[9px] uppercase tracking-wider text-rose-300/70 truncate">
|
||||
主动脉冲
|
||||
</div>
|
||||
<div className="text-sm font-mono tabular-nums text-rose-200 truncate">
|
||||
{formatNum(pulsePower)}
|
||||
{combo >= 1 && (
|
||||
<span className="text-[9px] text-rose-300/80"> ×{comboMult.toFixed(2)}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 当前连击 — amber,≥3 时高亮闪烁 */}
|
||||
<div
|
||||
className={`rounded-lg border bg-black/30 backdrop-blur p-2 flex items-center gap-1.5 ${
|
||||
comboHot ? "border-amber-400/70 animate-pulse" : "border-amber-400/30"
|
||||
}`}
|
||||
>
|
||||
<Flame
|
||||
className={`h-3.5 w-3.5 text-amber-400 shrink-0 ${
|
||||
comboHot ? "drop-shadow-[0_0_4px_rgba(251,191,36,0.7)]" : ""
|
||||
}`}
|
||||
/>
|
||||
<div className="min-w-0 leading-tight">
|
||||
<div className="text-[9px] uppercase tracking-wider text-amber-300/70 truncate">
|
||||
当前连击
|
||||
</div>
|
||||
<div
|
||||
className={`text-sm font-mono tabular-nums truncate ${
|
||||
comboHot ? "text-amber-200" : "text-amber-300/80"
|
||||
}`}
|
||||
>
|
||||
{combo}
|
||||
<span className="text-[9px] text-amber-300/60">/10</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 仓库容量 — fuchsia,≥90% 切 rose 警告色 + pulse */}
|
||||
<div
|
||||
className={`rounded-lg border bg-black/30 backdrop-blur p-2 flex items-center gap-1.5 ${
|
||||
warehouseWarn ? "border-rose-400/70 animate-pulse" : "border-fuchsia-400/30"
|
||||
}`}
|
||||
>
|
||||
<Database
|
||||
className={`h-3.5 w-3.5 shrink-0 ${
|
||||
warehouseWarn ? "text-rose-400" : "text-fuchsia-400"
|
||||
}`}
|
||||
/>
|
||||
<div className="min-w-0 leading-tight">
|
||||
<div
|
||||
className={`text-[9px] uppercase tracking-wider truncate ${
|
||||
warehouseWarn ? "text-rose-300/80" : "text-fuchsia-300/70"
|
||||
}`}
|
||||
>
|
||||
仓库容量
|
||||
</div>
|
||||
<div
|
||||
className={`text-sm font-mono tabular-nums truncate ${
|
||||
warehouseWarn ? "text-rose-200" : "text-fuchsia-200"
|
||||
}`}
|
||||
>
|
||||
{formatNum(crystals)}
|
||||
<span
|
||||
className={`text-[9px] ${
|
||||
warehouseWarn ? "text-rose-300/70" : "text-fuchsia-300/60"
|
||||
}`}
|
||||
>
|
||||
/{formatNum(crystalCap)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StatsPanel() {
|
||||
const s = useGameStore();
|
||||
const achCount = Object.values(s.achievements).filter(Boolean).length;
|
||||
// 深空信标本地排行榜最高分(独立 localStorage)
|
||||
const [beaconBest, setBeaconBest] = useState<number | null>(null);
|
||||
useEffect(() => {
|
||||
try {
|
||||
const lb = loadLeaderboard();
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setBeaconBest(lb.length > 0 ? lb[0].score : null);
|
||||
} catch {
|
||||
setBeaconBest(null);
|
||||
}
|
||||
}, []);
|
||||
const rows = [
|
||||
{ label: "累计解码晶体", value: `${s.totalDecoded} 颗` },
|
||||
{ label: "飞升周目", value: `${s.ascensions}` },
|
||||
{ label: "持有蓝图", value: `${s.blueprints.length} / 6` },
|
||||
{ label: "已学技术", value: `${Object.values(s.tech).filter((v) => v > 0).length} / ${TECH_TREE.length}` },
|
||||
{ label: "已获碎片", value: `${Object.values(s.fragments).filter(Boolean).length} / ${FRAGMENTS.length}` },
|
||||
{ label: "已解锁成就", value: `${achCount} / ${ACHIEVEMENTS.length}` },
|
||||
{ label: "星图天赋", value: `${s.constellation?.length ?? 0} / ${CONSTELLATION_PERKS.length}` },
|
||||
{ label: "接触进度", value: `${s.contact.toFixed(1)}%` },
|
||||
{ label: "晶体产能", value: `${s.crystalsPerSec.toFixed(2)} /s` },
|
||||
{ label: "仓库上限", value: `${formatNum(s.crystalCap)}` },
|
||||
{ label: "洞见倍率", value: `×${s.insightMult.toFixed(2)}` },
|
||||
{ label: "累计探险", value: `${s.totalExpeditions} 次` },
|
||||
{ label: "BOSS 击破", value: `${s.bossKills ?? 0} 次` },
|
||||
{ label: "星潮亲历", value: `${(s.starTidesEncountered ?? []).length} / 9` },
|
||||
{ label: "编年史条目", value: `${(s.chronicle ?? []).length} 纪元` },
|
||||
{ label: "探险能量", value: `${Math.floor(s.energy)} / ${s.energyMax}` },
|
||||
{ label: "信标最高分", value: beaconBest !== null ? formatNum(beaconBest) : "—" },
|
||||
{ label: "探索力", value: `${s.attributes?.exploration ?? 0} / 100` },
|
||||
{ label: "智慧", value: `${s.attributes?.wisdom ?? 0} / 100` },
|
||||
{ label: "勇气", value: `${s.attributes?.courage ?? 0} / 100` },
|
||||
{ label: "灵感", value: `${s.attributes?.inspiration ?? 0} / 100` },
|
||||
{ label: "待分配属性点", value: `${s.pendingAttrPoints ?? 0}` },
|
||||
];
|
||||
return (
|
||||
<div className="grid grid-cols-2 gap-1.5 text-xs">
|
||||
{rows.map((r) => (
|
||||
<div
|
||||
key={r.label}
|
||||
className="flex items-center justify-between rounded-md bg-black/25 border border-white/5 px-2 py-1.5"
|
||||
>
|
||||
<span className="text-muted-foreground">{r.label}</span>
|
||||
<span className="font-mono text-foreground">{r.value}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+168
@@ -0,0 +1,168 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 成就解锁通知(v0.9 全屏特效增强)
|
||||
// 工单 Issue #2 反馈"成就系统没看出来有什么用",改为居中全息弹窗 + 奖励数字弹出
|
||||
import { useEffect, useState } from "react";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
import type { Achievement } from "@/lib/game/achievements";
|
||||
|
||||
interface NotificationItem {
|
||||
achievement: Achievement;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export function AchievementNotifier() {
|
||||
const queue = useGameStore((s) => s._achievementQueue);
|
||||
const consume = useGameStore((s) => s.consumeAchievementQueue);
|
||||
const { toast } = useToast();
|
||||
const [notifications, setNotifications] = useState<NotificationItem[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (queue.length === 0) return;
|
||||
const items = consume();
|
||||
for (const a of items) {
|
||||
sfx("achievement");
|
||||
// v0.9:全屏居中特效通知
|
||||
const id = Date.now() + Math.random();
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setNotifications((prev) => [...prev, { achievement: a, id }]);
|
||||
// 4 秒后自动移除
|
||||
setTimeout(() => {
|
||||
setNotifications((prev) => prev.filter((n) => n.id !== id));
|
||||
}, 4000);
|
||||
// 同时保留底部 toast 作为日志
|
||||
toast({
|
||||
title: `成就解锁:${a.name}`,
|
||||
description: `${a.desc} 奖励:${a.rewardText}`,
|
||||
});
|
||||
}
|
||||
}, [queue, consume, toast]);
|
||||
|
||||
if (notifications.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[120] pointer-events-none flex items-center justify-center">
|
||||
<AnimatePresence>
|
||||
{notifications.map((n, idx) => {
|
||||
const a = n.achievement;
|
||||
// 多个同时出现时垂直堆叠偏移
|
||||
const offset = (idx - (notifications.length - 1) / 2) * 140;
|
||||
return (
|
||||
<motion.div
|
||||
key={n.id}
|
||||
initial={{ opacity: 0, scale: 0.4, y: 40, rotateX: -30 }}
|
||||
animate={{ opacity: 1, scale: 1, y: offset, rotateX: 0 }}
|
||||
exit={{ opacity: 0, scale: 0.6, y: -60 }}
|
||||
transition={{ type: "spring", stiffness: 280, damping: 22 }}
|
||||
className="absolute"
|
||||
style={{ transformOrigin: "center center" }}
|
||||
>
|
||||
<div
|
||||
className="relative rounded-2xl border-2 px-8 py-5 backdrop-blur-xl overflow-hidden"
|
||||
style={{
|
||||
borderColor: a.color,
|
||||
background: `linear-gradient(135deg, ${a.color}22, rgba(5,4,16,0.92))`,
|
||||
boxShadow: `0 0 60px ${a.color}66, 0 0 120px ${a.color}33, inset 0 0 30px ${a.color}11`,
|
||||
minWidth: 320,
|
||||
maxWidth: 420,
|
||||
}}
|
||||
>
|
||||
{/* 背景径向辉光 */}
|
||||
<div
|
||||
className="absolute -top-20 -right-20 h-40 w-40 rounded-full blur-3xl opacity-50"
|
||||
style={{ background: a.color }}
|
||||
/>
|
||||
{/* 旋转光线 */}
|
||||
<motion.div
|
||||
className="absolute inset-0 rounded-2xl opacity-20"
|
||||
style={{
|
||||
background: `conic-gradient(from 0deg, transparent, ${a.color}, transparent, ${a.color}, transparent)`,
|
||||
}}
|
||||
animate={{ rotate: 360 }}
|
||||
transition={{ duration: 8, repeat: Infinity, ease: "linear" }}
|
||||
/>
|
||||
|
||||
<div className="relative flex items-center gap-4">
|
||||
{/* 图标徽章 */}
|
||||
<motion.div
|
||||
className="shrink-0 h-16 w-16 rounded-2xl flex items-center justify-center text-3xl"
|
||||
style={{
|
||||
background: `${a.color}33`,
|
||||
border: `2px solid ${a.color}`,
|
||||
boxShadow: `0 0 20px ${a.color}88, inset 0 0 12px ${a.color}44`,
|
||||
}}
|
||||
animate={{
|
||||
boxShadow: [
|
||||
`0 0 20px ${a.color}88, inset 0 0 12px ${a.color}44`,
|
||||
`0 0 40px ${a.color}cc, inset 0 0 20px ${a.color}66`,
|
||||
`0 0 20px ${a.color}88, inset 0 0 12px ${a.color}44`,
|
||||
],
|
||||
}}
|
||||
transition={{ duration: 2, repeat: Infinity }}
|
||||
>
|
||||
{a.icon}
|
||||
</motion.div>
|
||||
|
||||
{/* 文本 */}
|
||||
<div className="min-w-0 flex-1">
|
||||
<motion.div
|
||||
initial={{ opacity: 0, x: -10 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
transition={{ delay: 0.15 }}
|
||||
className="text-[10px] font-mono uppercase tracking-[0.2em] mb-0.5"
|
||||
style={{ color: a.color }}
|
||||
>
|
||||
✦ Achievement Unlocked
|
||||
</motion.div>
|
||||
<motion.h3
|
||||
initial={{ opacity: 0, x: -10 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
transition={{ delay: 0.2 }}
|
||||
className="text-lg font-bold truncate"
|
||||
style={{ color: a.color, textShadow: `0 0 12px ${a.color}66` }}
|
||||
>
|
||||
{a.name}
|
||||
</motion.h3>
|
||||
<motion.p
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
transition={{ delay: 0.3 }}
|
||||
className="text-[11px] text-muted-foreground/90 truncate"
|
||||
>
|
||||
{a.desc}
|
||||
</motion.p>
|
||||
{/* 奖励条 */}
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 8 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ delay: 0.4 }}
|
||||
className="mt-1.5 inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-mono font-semibold"
|
||||
style={{
|
||||
background: `${a.color}22`,
|
||||
border: `1px solid ${a.color}55`,
|
||||
color: a.color,
|
||||
}}
|
||||
>
|
||||
▸ {a.rewardText}
|
||||
</motion.div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 进度条(倒计时) */}
|
||||
<motion.div
|
||||
className="absolute bottom-0 left-0 h-0.5"
|
||||
style={{ background: a.color }}
|
||||
initial={{ width: "100%" }}
|
||||
animate={{ width: "0%" }}
|
||||
transition={{ duration: 4, ease: "linear" }}
|
||||
/>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
})}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+107
@@ -0,0 +1,107 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 成就系统面板
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import { ACHIEVEMENTS } from "@/lib/game/achievements";
|
||||
import { achievementBonuses } from "@/lib/game/achievements";
|
||||
import { Trophy, Lock } from "lucide-react";
|
||||
|
||||
export function AchievementsPanel() {
|
||||
const achievements = useGameStore((s) => s.achievements);
|
||||
const unlockedCount = Object.values(achievements).filter(Boolean).length;
|
||||
const bonus = achievementBonuses(achievements);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2.5 h-full">
|
||||
{/* 顶部:进度 + 加成总览 */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold flex items-center gap-1.5">
|
||||
<Trophy className="h-4 w-4 text-amber-400" />
|
||||
成就
|
||||
</h3>
|
||||
<span className="text-[10px] text-muted-foreground font-mono">
|
||||
{unlockedCount} / {ACHIEVEMENTS.length}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 永久加成条 */}
|
||||
<div className="rounded-lg border border-amber-400/20 bg-amber-950/20 px-2.5 py-1.5 flex items-center gap-3 text-[10px]">
|
||||
<span className="text-amber-300/80">永久加成</span>
|
||||
{bonus.crystalsPerSecPct > 0 && (
|
||||
<span className="text-emerald-300">产能 +{bonus.crystalsPerSecPct}%</span>
|
||||
)}
|
||||
{bonus.insightPct > 0 && (
|
||||
<span className="text-fuchsia-300">洞见 +{bonus.insightPct}%</span>
|
||||
)}
|
||||
{bonus.crystalsPerSecPct === 0 && bonus.insightPct === 0 && (
|
||||
<span className="text-muted-foreground/60">暂无(达成成就解锁)</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 成就网格 — 移除固定 max-h,用 flex-1 min-h-0 自适应父容器,避免小屏挤压重叠 */}
|
||||
<div className="flex-1 min-h-0 grid grid-cols-1 sm:grid-cols-2 gap-1.5 content-start overflow-y-auto echo-scroll pr-1">
|
||||
{ACHIEVEMENTS.map((a) => {
|
||||
const unlocked = !!achievements[a.id];
|
||||
return (
|
||||
<div
|
||||
key={a.id}
|
||||
className={`relative rounded-lg border px-2.5 py-2 transition-all duration-300 overflow-hidden ${
|
||||
unlocked
|
||||
? "border-white/15 bg-black/30"
|
||||
: "border-white/5 bg-black/15 opacity-60"
|
||||
}`}
|
||||
style={
|
||||
unlocked
|
||||
? { boxShadow: `inset 0 0 16px ${a.color}11` }
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{unlocked && (
|
||||
<div
|
||||
className="absolute -top-6 -right-6 h-16 w-16 rounded-full blur-2xl opacity-40"
|
||||
style={{ background: a.color }}
|
||||
/>
|
||||
)}
|
||||
<div className="relative flex items-start gap-2">
|
||||
{/* 图标徽章 */}
|
||||
<div
|
||||
className="shrink-0 h-8 w-8 rounded-lg flex items-center justify-center text-base"
|
||||
style={{
|
||||
background: unlocked ? `${a.color}22` : "rgba(255,255,255,0.04)",
|
||||
border: `1px solid ${unlocked ? a.color + "55" : "rgba(255,255,255,0.08)"}`,
|
||||
color: unlocked ? a.color : "#666",
|
||||
boxShadow: unlocked ? `0 0 10px ${a.color}33` : "none",
|
||||
}}
|
||||
>
|
||||
{unlocked ? a.icon : <Lock className="h-3.5 w-3.5" />}
|
||||
</div>
|
||||
{/* 文本 */}
|
||||
<div className="min-w-0 flex-1">
|
||||
<div
|
||||
className="text-[11px] font-semibold truncate"
|
||||
style={{ color: unlocked ? a.color : "rgba(255,255,255,0.5)" }}
|
||||
>
|
||||
{a.name}
|
||||
</div>
|
||||
<div className="text-[10px] text-muted-foreground/80 leading-tight mt-0.5">
|
||||
{a.desc}
|
||||
</div>
|
||||
{unlocked && (
|
||||
<div className="text-[9px] mt-1 font-mono" style={{ color: a.color + "cc" }}>
|
||||
✦ {a.rewardText}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<style jsx global>{`
|
||||
.echo-scroll::-webkit-scrollbar { width: 5px; }
|
||||
.echo-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 3px; }
|
||||
.echo-scroll::-webkit-scrollbar-track { background: transparent; }
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+334
@@ -0,0 +1,334 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 角色属性面板(v0.7 P1)
|
||||
//
|
||||
// 无人机驾驶员四维属性可视化:
|
||||
// • 探索力 emerald / 智慧 fuchsia / 勇气 amber / 灵感 rose
|
||||
// • 显示数值(0-100)、加成百分比、经验进度条、等级 badge
|
||||
// • 待分配属性点时高亮 + 闪烁提示,「+」按钮可分配 1 点
|
||||
// • 顶部待分配点数提示;底部总览
|
||||
// • 小屏 2×2 网格,大屏 1×4 横排
|
||||
import { useMemo } from "react";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import {
|
||||
ATTRIBUTE_CONFIG,
|
||||
ATTRIBUTE_KEYS,
|
||||
ATTRIBUTE_HARD_CAP,
|
||||
ATTRIBUTE_LINEAR_CAP,
|
||||
getAttributeBonus,
|
||||
getAllBonuses,
|
||||
totalAttributeLevel,
|
||||
totalAttributeBonusPct,
|
||||
expRequiredForLevel,
|
||||
type AttributeKey,
|
||||
} from "@/lib/game/attributes";
|
||||
import {
|
||||
Compass,
|
||||
Brain,
|
||||
Swords,
|
||||
Sparkles,
|
||||
Plus,
|
||||
ChevronUp,
|
||||
type LucideIcon,
|
||||
} from "lucide-react";
|
||||
|
||||
const ICON_MAP: Record<string, LucideIcon> = {
|
||||
Compass,
|
||||
Brain,
|
||||
Swords,
|
||||
Sparkles,
|
||||
};
|
||||
|
||||
/** 主题色 → Tailwind/CSS 颜色映射 */
|
||||
const COLOR_STYLES: Record<
|
||||
AttributeKey,
|
||||
{
|
||||
text: string;
|
||||
border: string;
|
||||
borderActive: string;
|
||||
bg: string;
|
||||
ring: string;
|
||||
barFrom: string;
|
||||
barTo: string;
|
||||
glow: string;
|
||||
}
|
||||
> = {
|
||||
exploration: {
|
||||
text: "text-emerald-300",
|
||||
border: "border-emerald-400/30",
|
||||
borderActive: "border-emerald-400/70",
|
||||
bg: "bg-emerald-500/10",
|
||||
ring: "ring-emerald-400/40",
|
||||
barFrom: "from-emerald-400",
|
||||
barTo: "to-emerald-500",
|
||||
glow: "rgba(52,211,153,0.45)",
|
||||
},
|
||||
wisdom: {
|
||||
text: "text-fuchsia-300",
|
||||
border: "border-fuchsia-400/30",
|
||||
borderActive: "border-fuchsia-400/70",
|
||||
bg: "bg-fuchsia-500/10",
|
||||
ring: "ring-fuchsia-400/40",
|
||||
barFrom: "from-fuchsia-400",
|
||||
barTo: "to-fuchsia-500",
|
||||
glow: "rgba(232,121,249,0.45)",
|
||||
},
|
||||
courage: {
|
||||
text: "text-amber-300",
|
||||
border: "border-amber-400/30",
|
||||
borderActive: "border-amber-400/70",
|
||||
bg: "bg-amber-500/10",
|
||||
ring: "ring-amber-400/40",
|
||||
barFrom: "from-amber-400",
|
||||
barTo: "to-amber-500",
|
||||
glow: "rgba(251,191,36,0.45)",
|
||||
},
|
||||
inspiration: {
|
||||
text: "text-rose-300",
|
||||
border: "border-rose-400/30",
|
||||
borderActive: "border-rose-400/70",
|
||||
bg: "bg-rose-500/10",
|
||||
ring: "ring-rose-400/40",
|
||||
barFrom: "from-rose-400",
|
||||
barTo: "to-rose-500",
|
||||
glow: "rgba(251,113,133,0.45)",
|
||||
},
|
||||
};
|
||||
|
||||
export function AttributesPanel() {
|
||||
const attributes = useGameStore((s) => s.attributes);
|
||||
const attributeProgress = useGameStore((s) => s.attributeProgress);
|
||||
const pendingAttrPoints = useGameStore((s) => s.pendingAttrPoints ?? 0);
|
||||
const allocateAttribute = useGameStore((s) => s.allocateAttribute);
|
||||
|
||||
const bonuses = useMemo(() => getAllBonuses(attributes), [attributes]);
|
||||
const totalLvl = useMemo(() => totalAttributeLevel(attributes), [attributes]);
|
||||
const totalBonus = useMemo(
|
||||
() => totalAttributeBonusPct(attributes),
|
||||
[attributes]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2.5 h-full overflow-y-auto echo-scroll pr-0.5">
|
||||
<style jsx global>{`
|
||||
.echo-scroll::-webkit-scrollbar { width: 4px; }
|
||||
.echo-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }
|
||||
.echo-scroll::-webkit-scrollbar-track { background: transparent; }
|
||||
@keyframes echo-pending-pulse {
|
||||
0%, 100% { box-shadow: 0 0 0 0 rgba(232,121,249,0.5); }
|
||||
50% { box-shadow: 0 0 14px 4px rgba(232,121,249,0.65); }
|
||||
}
|
||||
.echo-pending-pulse {
|
||||
animation: echo-pending-pulse 1.6s ease-in-out infinite;
|
||||
}
|
||||
@keyframes echo-card-glow {
|
||||
0%, 100% { opacity: 0.5; }
|
||||
50% { opacity: 1; }
|
||||
}
|
||||
`}</style>
|
||||
|
||||
{/* 顶部:标题 + 待分配点数 */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold flex items-center gap-1.5">
|
||||
<span className="bg-gradient-to-br from-emerald-300 via-fuchsia-300 to-rose-300 bg-clip-text text-transparent">
|
||||
驾驶员属性
|
||||
</span>
|
||||
</h3>
|
||||
<div
|
||||
className={`text-[10px] px-2 py-0.5 rounded-full border ${
|
||||
pendingAttrPoints > 0
|
||||
? "border-fuchsia-400/60 bg-fuchsia-500/15 text-fuchsia-200 echo-pending-pulse font-bold"
|
||||
: "border-white/15 bg-black/25 text-muted-foreground"
|
||||
}`}
|
||||
>
|
||||
待分配 {pendingAttrPoints}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 属性卡片网格:小屏 2×2,大屏 1×4 */}
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-2">
|
||||
{ATTRIBUTE_KEYS.map((key) => {
|
||||
const meta = ATTRIBUTE_CONFIG[key];
|
||||
const cs = COLOR_STYLES[key];
|
||||
const Icon = ICON_MAP[meta.icon] ?? Sparkles;
|
||||
const value = attributes?.[key] ?? 0;
|
||||
const prog = attributeProgress?.[key] ?? { exp: 0, level: value };
|
||||
const bonusPct = getAttributeBonus(value) * 100;
|
||||
const nextExp = expRequiredForLevel(value);
|
||||
const curExp = prog.exp;
|
||||
const expPct =
|
||||
nextExp > 0 ? Math.min(100, (curExp / nextExp) * 100) : 100;
|
||||
const isMax = value >= ATTRIBUTE_HARD_CAP;
|
||||
const canAllocate = pendingAttrPoints > 0 && !isMax;
|
||||
// 区域标记
|
||||
const inDiminishing = value > ATTRIBUTE_LINEAR_CAP;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={key}
|
||||
className={`relative rounded-xl border ${cs.border} ${cs.bg} p-2.5 flex flex-col gap-1.5 overflow-hidden transition-all duration-300`}
|
||||
style={{
|
||||
boxShadow: `inset 0 0 18px ${cs.glow}`,
|
||||
}}
|
||||
>
|
||||
{/* 顶部光晕装饰 */}
|
||||
<div
|
||||
className="pointer-events-none absolute -top-8 -right-8 h-20 w-20 rounded-full blur-2xl opacity-50"
|
||||
style={{ background: meta.hex }}
|
||||
/>
|
||||
{/* 标题行:图标 + 名称 + 等级 badge */}
|
||||
<div className="relative flex items-center gap-1.5">
|
||||
<div
|
||||
className={`shrink-0 h-7 w-7 rounded-lg flex items-center justify-center ${cs.bg} border ${cs.border}`}
|
||||
style={{ boxShadow: `0 0 8px ${cs.glow}` }}
|
||||
>
|
||||
<Icon className={`h-3.5 w-3.5 ${cs.text}`} />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1 leading-tight">
|
||||
<div className={`text-[11px] font-semibold ${cs.text} truncate`}>
|
||||
{meta.name}
|
||||
</div>
|
||||
<div className="text-[8px] text-muted-foreground/70 uppercase tracking-wider truncate">
|
||||
{meta.enName}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={`shrink-0 text-[9px] px-1.5 py-0.5 rounded font-mono font-bold ${
|
||||
isMax
|
||||
? "bg-amber-400/20 text-amber-200 border border-amber-400/40"
|
||||
: "bg-black/30 text-white/80 border border-white/10"
|
||||
}`}
|
||||
>
|
||||
Lv.{value}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 数值 + 加成 */}
|
||||
<div className="relative flex items-end justify-between">
|
||||
<span className={`text-lg font-mono font-bold ${cs.text} leading-none`}>
|
||||
{value}
|
||||
<span className="text-[9px] text-muted-foreground/60 ml-0.5">
|
||||
/{ATTRIBUTE_HARD_CAP}
|
||||
</span>
|
||||
</span>
|
||||
<span className={`text-[10px] ${cs.text} font-mono`}>
|
||||
+{bonusPct.toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 经验进度条 */}
|
||||
<div className="relative">
|
||||
<div className="h-1.5 rounded-full bg-black/40 overflow-hidden border border-white/5">
|
||||
<div
|
||||
className={`h-full bg-gradient-to-r ${cs.barFrom} ${cs.barTo} transition-all duration-500`}
|
||||
style={{
|
||||
width: `${isMax ? 100 : expPct}%`,
|
||||
boxShadow: `0 0 6px ${cs.glow}`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center justify-between mt-0.5 text-[8px] text-muted-foreground/70 font-mono">
|
||||
<span>
|
||||
{isMax ? "已满级" : `${curExp} / ${nextExp} EXP`}
|
||||
</span>
|
||||
{inDiminishing && !isMax && (
|
||||
<span className="text-amber-300/70">递减区</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 加成列表 */}
|
||||
<div className="relative flex flex-col gap-0.5 mt-0.5">
|
||||
{meta.effects.map((eff, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="text-[8.5px] text-muted-foreground/70 leading-tight flex items-center gap-1"
|
||||
>
|
||||
<span className={cs.text}>·</span>
|
||||
<span className="truncate">{eff}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 分配按钮 */}
|
||||
<button
|
||||
type="button"
|
||||
disabled={!canAllocate}
|
||||
onClick={() => allocateAttribute(key, 1)}
|
||||
aria-label={`分配 1 点到 ${meta.name}`}
|
||||
className={`relative mt-auto rounded-md border px-1.5 py-1 flex items-center justify-center gap-0.5 text-[10px] font-bold transition-all ${
|
||||
canAllocate
|
||||
? `${cs.borderActive} ${cs.bg} ${cs.text} hover:scale-105 cursor-pointer`
|
||||
: "border-white/5 bg-black/20 text-muted-foreground/30 cursor-not-allowed"
|
||||
}`}
|
||||
style={
|
||||
canAllocate
|
||||
? { boxShadow: `0 0 8px ${cs.glow}` }
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<Plus className="h-3 w-3" />
|
||||
<span>分配</span>
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* 底部:总览 */}
|
||||
<div className="mt-auto rounded-lg border border-white/10 bg-black/30 px-2.5 py-1.5 flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-1.5 text-[10px]">
|
||||
<ChevronUp className="h-3 w-3 text-fuchsia-300" />
|
||||
<span className="text-muted-foreground">总等级</span>
|
||||
<span className="font-mono font-bold text-fuchsia-200">
|
||||
{totalLvl}
|
||||
<span className="text-muted-foreground/60 text-[9px]">/{ATTRIBUTE_HARD_CAP * 4}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-[10px]">
|
||||
<span className="text-muted-foreground">总加成</span>
|
||||
<span className="font-mono font-bold text-emerald-200">
|
||||
+{totalBonus.toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 当前生效修饰器(细节展示) */}
|
||||
<div className="grid grid-cols-2 gap-1 text-[9px]">
|
||||
<DetailLine label="探险力" value={`×${bonuses.expeditionPowerMult.toFixed(2)}`} color="text-emerald-300" />
|
||||
<DetailLine label="解码步数" value={`+${bonuses.decodeStepsBonus}`} color="text-fuchsia-300" />
|
||||
<DetailLine label="洞见倍率" value={`+${(bonuses.insightMultAdd * 100).toFixed(1)}%`} color="text-fuchsia-300" />
|
||||
<DetailLine label="自动解码周期" value={`×${bonuses.autoDecodeIntervalMult.toFixed(2)}`} color="text-fuchsia-300" />
|
||||
<DetailLine label="探险生命" value={`+${bonuses.expeditionHpBonus}`} color="text-amber-300" />
|
||||
<DetailLine label="BOSS 胜率" value={`+${(bonuses.bossWinRateBonus * 100).toFixed(1)}%`} color="text-amber-300" />
|
||||
<DetailLine label="巡航护盾" value={`+${bonuses.cruiseShieldBonus}`} color="text-amber-300" />
|
||||
<DetailLine label="接触率" value={`×${bonuses.contactRateMult.toFixed(2)}`} color="text-rose-300" />
|
||||
<DetailLine label="星潮触发" value={`+${(bonuses.tideTriggerBonus * 100).toFixed(1)}%`} color="text-rose-300" />
|
||||
<DetailLine label="脉冲连击" value={`+${(bonuses.pulseComboBonus * 100).toFixed(1)}%`} color="text-rose-300" />
|
||||
<DetailLine label="巡航速度" value={`×${bonuses.cruiseShipSpeedMult.toFixed(2)}`} color="text-emerald-300" />
|
||||
<DetailLine label="产能加成" value={`×${bonuses.crystalsPerSecMult.toFixed(2)}`} color="text-emerald-300" />
|
||||
</div>
|
||||
|
||||
{/* 飞升获得属性点提示 */}
|
||||
<div className="text-[9px] text-muted-foreground/60 text-center leading-tight">
|
||||
每次飞升获得 <span className="text-fuchsia-300 font-mono">飞升次数 × 2 + 1</span> 点属性点;完成对应活动自动累积经验
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function DetailLine({
|
||||
label,
|
||||
value,
|
||||
color,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
color: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex items-center justify-between rounded bg-black/25 border border-white/5 px-1.5 py-0.5">
|
||||
<span className="text-muted-foreground/80 truncate">{label}</span>
|
||||
<span className={`font-mono ${color}`}>{value}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+1185
File diff suppressed because it is too large
Load Diff
Executable
+511
@@ -0,0 +1,511 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 回响编年史对话框(v0.4 跨周目叙事时间轴)
|
||||
import { useEffect, useState, useMemo } from "react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
} from "@/components/ui/dialog";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import {
|
||||
PERK_NAME_MAP,
|
||||
getCategoryColor,
|
||||
getCategoryName,
|
||||
getPerkCategoryBreakdown,
|
||||
regenerateLoreFromEntry,
|
||||
} from "@/lib/game/chronicle";
|
||||
import { getPerk } from "@/lib/game/constellation";
|
||||
import { TIDE_EVENTS } from "@/lib/game/starTide";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
import type { ChronicleEntry } from "@/lib/game/types";
|
||||
import { BookOpen, Clock, Swords, Trophy, Sparkles, Star, Waves, Cpu, Zap, ChevronLeft, ChevronRight } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
}
|
||||
|
||||
/** tide ID (tide_xxx) → 展示信息(从 TIDE_EVENTS 复用) */
|
||||
function getTideDisplay(tideId: string): { name: string; color: string } {
|
||||
// tideId 形如 "tide_crystal",剥离前缀后查 TIDE_EVENTS
|
||||
const type = tideId.startsWith("tide_") ? tideId.slice(5) : tideId;
|
||||
const ev = TIDE_EVENTS[type as keyof typeof TIDE_EVENTS];
|
||||
return ev ? { name: ev.name, color: ev.color } : { name: tideId, color: "#94a3b8" };
|
||||
}
|
||||
|
||||
function formatDuration(sec: number): string {
|
||||
if (sec < 60) return `${sec}秒`;
|
||||
const m = Math.floor(sec / 60);
|
||||
const s = sec % 60;
|
||||
if (m < 60) return s > 0 ? `${m}分${s}秒` : `${m}分钟`;
|
||||
const h = Math.floor(m / 60);
|
||||
return `${h}小时${m % 60}分`;
|
||||
}
|
||||
|
||||
function formatDate(ts: number): string {
|
||||
const d = new Date(ts);
|
||||
const mm = String(d.getMonth() + 1).padStart(2, "0");
|
||||
const dd = String(d.getDate()).padStart(2, "0");
|
||||
const hh = String(d.getHours()).padStart(2, "0");
|
||||
const mi = String(d.getMinutes()).padStart(2, "0");
|
||||
return `${mm}-${dd} ${hh}:${mi}`;
|
||||
}
|
||||
|
||||
export function ChronicleDialog({ open, onOpenChange }: Props) {
|
||||
const chronicle = useGameStore((s) => s.chronicle ?? []);
|
||||
const ascensions = useGameStore((s) => s.ascensions ?? 0);
|
||||
const bossKills = useGameStore((s) => s.bossKills ?? 0);
|
||||
const tidesAll = useGameStore((s) => s.starTidesEncountered ?? []);
|
||||
// 倒序展示(最新的在前)
|
||||
const entries: ChronicleEntry[] = useMemo(() => [...chronicle].reverse(), [chronicle]);
|
||||
|
||||
// v0.8.2 分页(工单 #8):编年史上限 200 条,每页 10 条
|
||||
const PAGE_SIZE = 10;
|
||||
const totalPages = Math.max(1, Math.ceil(entries.length / PAGE_SIZE));
|
||||
const [page, setPage] = useState(1);
|
||||
// 当 entries 变化(新飞升)且当前页超出范围时,回到第 1 页(最新)
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
if (page > totalPages) setPage(1);
|
||||
}, [page, totalPages]);
|
||||
// 打开时默认回到第 1 页(最新)
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
sfx("chronicleOpen");
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setPage(1);
|
||||
}
|
||||
}, [open]);
|
||||
const pagedEntries = entries.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="bg-gradient-to-br from-violet-950/80 via-black/90 to-fuchsia-950/60 border-fuchsia-400/30 max-w-3xl max-h-[88vh] overflow-hidden flex flex-col p-0 gap-0">
|
||||
{/* 顶部装饰条 */}
|
||||
<div className="h-1 bg-gradient-to-r from-emerald-500 via-fuchsia-500 to-amber-500 opacity-70" />
|
||||
|
||||
<DialogHeader className="px-6 pt-5 pb-3 space-y-1">
|
||||
<DialogTitle className="flex items-center gap-2 text-fuchsia-100 text-xl">
|
||||
<BookOpen className="h-5 w-5 text-fuchsia-300" />
|
||||
回响编年史
|
||||
<span className="text-[11px] font-normal text-fuchsia-300/60 ml-2">
|
||||
Chronicle of Echoes
|
||||
</span>
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-fuchsia-200/60 text-xs">
|
||||
每一次飞升都在深空留下回响。这里铭刻着跨越维度的全部纪元。
|
||||
</DialogDescription>
|
||||
|
||||
{/* 总览统计条 */}
|
||||
<div className="grid grid-cols-3 gap-2 pt-2">
|
||||
<OverviewStat
|
||||
icon={<Sparkles className="h-3 w-3" />}
|
||||
label="飞升次数"
|
||||
value={ascensions}
|
||||
color="#e879f9"
|
||||
/>
|
||||
<OverviewStat
|
||||
icon={<Trophy className="h-3 w-3" />}
|
||||
label="BOSS 击破"
|
||||
value={bossKills}
|
||||
color="#fbbf24"
|
||||
/>
|
||||
<OverviewStat
|
||||
icon={<Waves className="h-3 w-3" />}
|
||||
label="星潮亲历"
|
||||
value={tidesAll.length}
|
||||
color="#34d399"
|
||||
/>
|
||||
</div>
|
||||
</DialogHeader>
|
||||
|
||||
{/* 时间轴滚动区 */}
|
||||
<div className="flex-1 overflow-y-auto px-6 pb-3 echo-scroll">
|
||||
{entries.length === 0 ? (
|
||||
<EmptyState ascensions={ascensions} />
|
||||
) : (
|
||||
<div className="relative">
|
||||
{/* 中央时间轴线 */}
|
||||
<div className="absolute left-[27px] top-2 bottom-2 w-px bg-gradient-to-b from-fuchsia-400/40 via-violet-400/30 to-transparent" />
|
||||
|
||||
<div className="space-y-4">
|
||||
{pagedEntries.map((entry, idx) => (
|
||||
<ChronicleCard
|
||||
key={`${entry.ascensionNumber}-${entry.timestamp}`}
|
||||
entry={entry}
|
||||
isLatest={(page - 1) * PAGE_SIZE + idx === 0}
|
||||
index={(page - 1) * PAGE_SIZE + idx}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* v0.8.2 分页控制栏(工单 #8) */}
|
||||
{entries.length > PAGE_SIZE && (
|
||||
<div className="px-6 py-2.5 border-t border-fuchsia-400/15 bg-black/40 flex items-center justify-between gap-2">
|
||||
<span className="text-[11px] text-muted-foreground font-mono">
|
||||
第 {page} / {totalPages} 页 · 共 {entries.length} 条飞升记录
|
||||
</span>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={page <= 1}
|
||||
onClick={() => { sfx("tabSwitch"); setPage((p) => Math.max(1, p - 1)); }}
|
||||
className="h-7 px-2 text-fuchsia-300 hover:bg-fuchsia-500/15 disabled:opacity-30"
|
||||
>
|
||||
<ChevronLeft className="h-3.5 w-3.5" />
|
||||
上一页
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={page >= totalPages}
|
||||
onClick={() => { sfx("tabSwitch"); setPage((p) => Math.min(totalPages, p + 1)); }}
|
||||
className="h-7 px-2 text-fuchsia-300 hover:bg-fuchsia-500/15 disabled:opacity-30"
|
||||
>
|
||||
下一页
|
||||
<ChevronRight className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function OverviewStat({
|
||||
icon,
|
||||
label,
|
||||
value,
|
||||
color,
|
||||
}: {
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
value: number;
|
||||
color: string;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className="rounded-md border px-3 py-2 flex items-center gap-2"
|
||||
style={{
|
||||
borderColor: `${color}33`,
|
||||
background: `${color}0d`,
|
||||
}}
|
||||
>
|
||||
<div style={{ color }}>{icon}</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-[10px] text-muted-foreground truncate">{label}</div>
|
||||
<div className="text-sm font-mono font-bold" style={{ color }}>
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EmptyState({ ascensions }: { ascensions: number }) {
|
||||
const isPreV04 = ascensions > 0;
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-20 text-center">
|
||||
<div className="relative mb-4">
|
||||
<div className="absolute inset-0 blur-xl bg-fuchsia-500/20 rounded-full animate-pulse" />
|
||||
<BookOpen className="relative h-12 w-12 text-fuchsia-400/50" />
|
||||
</div>
|
||||
{isPreV04 ? (
|
||||
<>
|
||||
<div className="text-fuchsia-200/70 text-sm">
|
||||
已飞升 {ascensions} 次,但编年史尚无记录
|
||||
</div>
|
||||
<div className="text-fuchsia-300/40 text-[11px] mt-2 max-w-xs">
|
||||
编年史于 v0.4 启用。下一次飞升将自动铭刻新纪元,开启永恒叙事时间轴。
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="text-fuchsia-200/70 text-sm">尚未飞升,等待第一次跨越维度</div>
|
||||
<div className="text-fuchsia-300/40 text-[11px] mt-2 max-w-xs">
|
||||
当接触进度满溢时,发起飞升将开启新周目,并在编年史中铭刻一段永恒回响。
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ChronicleCard({
|
||||
entry,
|
||||
isLatest,
|
||||
index,
|
||||
}: {
|
||||
entry: ChronicleEntry;
|
||||
isLatest: boolean;
|
||||
index: number;
|
||||
}) {
|
||||
// 5 纪元循环颜色
|
||||
const epochColors = ["#34d399", "#fb7185", "#fbbf24", "#e879f9", "#fcd34d"];
|
||||
const epochColor = epochColors[(entry.ascensionNumber - 1) % 5];
|
||||
|
||||
return (
|
||||
<div
|
||||
className="relative pl-16 animate-in fade-in slide-in-from-bottom-2 duration-500"
|
||||
style={{ animationDelay: `${index * 80}ms` }}
|
||||
>
|
||||
{/* 时间轴节点 */}
|
||||
<div className="absolute left-[19px] top-3 z-10">
|
||||
<div
|
||||
className="w-4 h-4 rounded-full border-2 flex items-center justify-center"
|
||||
style={{
|
||||
borderColor: epochColor,
|
||||
background: `${epochColor}22`,
|
||||
boxShadow: `0 0 12px ${epochColor}88, 0 0 24px ${epochColor}44`,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="w-1.5 h-1.5 rounded-full"
|
||||
style={{ background: epochColor }}
|
||||
/>
|
||||
</div>
|
||||
{isLatest && (
|
||||
<div
|
||||
className="absolute inset-0 rounded-full animate-ping"
|
||||
style={{ background: `${epochColor}33` }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 卡片主体 */}
|
||||
<div
|
||||
className="rounded-lg border bg-black/40 backdrop-blur-sm overflow-hidden transition-all hover:scale-[1.005] hover:border-fuchsia-400/40"
|
||||
style={{
|
||||
borderColor: `${epochColor}33`,
|
||||
boxShadow: isLatest
|
||||
? `0 0 0 1px ${epochColor}22, 0 4px 24px ${epochColor}22`
|
||||
: `0 2px 8px rgba(0,0,0,0.4)`,
|
||||
}}
|
||||
>
|
||||
{/* 卡片头部 */}
|
||||
<div
|
||||
className="px-4 py-3 flex items-center justify-between border-b"
|
||||
style={{
|
||||
background: `linear-gradient(135deg, ${epochColor}11, transparent)`,
|
||||
borderColor: `${epochColor}22`,
|
||||
}}
|
||||
>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-baseline gap-2">
|
||||
<span
|
||||
className="text-[10px] font-mono font-bold px-1.5 py-0.5 rounded"
|
||||
style={{
|
||||
color: epochColor,
|
||||
background: `${epochColor}22`,
|
||||
}}
|
||||
>
|
||||
#{String(entry.ascensionNumber).padStart(2, "0")}
|
||||
</span>
|
||||
<h4
|
||||
className="text-sm font-bold tracking-wide truncate"
|
||||
style={{
|
||||
color: epochColor,
|
||||
textShadow: `0 0 12px ${epochColor}55`,
|
||||
}}
|
||||
>
|
||||
{entry.epochName}
|
||||
</h4>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-1 text-[10px] text-muted-foreground/80">
|
||||
<span className="flex items-center gap-0.5">
|
||||
<Clock className="h-2.5 w-2.5" />
|
||||
{formatDate(entry.timestamp)}
|
||||
</span>
|
||||
<span className="text-muted-foreground/40">·</span>
|
||||
<span>{formatDuration(entry.durationSec)}</span>
|
||||
{isLatest && (
|
||||
<>
|
||||
<span className="text-muted-foreground/40">·</span>
|
||||
<span className="text-fuchsia-300 font-bold">最新</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 叙事文本(显示时重新生成,修复历史条目中 tide_ruins 等原始键名) */}
|
||||
<div className="px-4 py-3 text-[12px] leading-relaxed text-fuchsia-100/75 font-serif">
|
||||
{regenerateLoreFromEntry(entry)}
|
||||
</div>
|
||||
|
||||
{/* 统计芯片 */}
|
||||
<div className="px-4 pb-3 flex flex-wrap gap-1.5">
|
||||
<StatChip
|
||||
icon={<Cpu className="h-2.5 w-2.5" />}
|
||||
label="解码"
|
||||
value={entry.summary.crystalsDecodedThisRun}
|
||||
color="#fb7185"
|
||||
/>
|
||||
<StatChip
|
||||
icon={<Sparkles className="h-2.5 w-2.5" />}
|
||||
label="技术"
|
||||
value={entry.summary.techsUnlocked}
|
||||
color="#34d399"
|
||||
/>
|
||||
<StatChip
|
||||
icon={<Swords className="h-2.5 w-2.5" />}
|
||||
label="探险"
|
||||
value={entry.summary.expeditionsCompleted}
|
||||
color="#fbbf24"
|
||||
/>
|
||||
{entry.summary.bossKills > 0 && (
|
||||
<StatChip
|
||||
icon={<Trophy className="h-2.5 w-2.5" />}
|
||||
label="BOSS"
|
||||
value={entry.summary.bossKills}
|
||||
color="#e879f9"
|
||||
/>
|
||||
)}
|
||||
<StatChip
|
||||
icon={<Waves className="h-2.5 w-2.5" />}
|
||||
label="星潮"
|
||||
value={entry.tidesThisRun.length}
|
||||
color="#94a3b8"
|
||||
/>
|
||||
<StatChip
|
||||
icon={<Star className="h-2.5 w-2.5" />}
|
||||
label="星图"
|
||||
value={entry.summary.constellationsTotal}
|
||||
color="#fcd34d"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 星潮列表 */}
|
||||
{entry.tidesThisRun.length > 0 && (
|
||||
<div className="px-4 pb-2 flex flex-wrap gap-1">
|
||||
{entry.tidesThisRun.map((tide) => {
|
||||
const td = getTideDisplay(tide);
|
||||
return (
|
||||
<span
|
||||
key={tide}
|
||||
className="text-[9px] px-1.5 py-0.5 rounded border"
|
||||
style={{
|
||||
color: td.color,
|
||||
borderColor: `${td.color}44`,
|
||||
background: `${td.color}11`,
|
||||
}}
|
||||
>
|
||||
✦ {td.name}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 天赋徽章 */}
|
||||
{entry.perksThisAscension.length > 0 && (
|
||||
<div className="px-4 pb-2 flex flex-wrap gap-1">
|
||||
{entry.perksThisAscension.map((perkId) => {
|
||||
const perk = getPerk(perkId);
|
||||
const cat = perk?.category || "cosmic";
|
||||
const color = getCategoryColor(cat);
|
||||
const catName = getCategoryName(cat);
|
||||
const perkName = PERK_NAME_MAP[perkId] || perkId;
|
||||
return (
|
||||
<span
|
||||
key={perkId}
|
||||
className="text-[9px] px-1.5 py-0.5 rounded border inline-flex items-center gap-1"
|
||||
style={{
|
||||
color,
|
||||
borderColor: `${color}55`,
|
||||
background: `${color}11`,
|
||||
}}
|
||||
title={`${catName} · ${perk?.desc || ""}`}
|
||||
>
|
||||
<Zap className="h-2 w-2" />
|
||||
{perkName}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 里程碑 */}
|
||||
{entry.milestones.length > 0 && (
|
||||
<div
|
||||
className="px-4 py-2 border-t flex flex-wrap gap-1.5"
|
||||
style={{
|
||||
borderColor: `${epochColor}22`,
|
||||
background: `${epochColor}08`,
|
||||
}}
|
||||
>
|
||||
{entry.milestones.map((m, i) => (
|
||||
<span
|
||||
key={i}
|
||||
className="text-[10px] px-1.5 py-0.5 rounded-full bg-fuchsia-500/15 text-fuchsia-200 border border-fuchsia-400/30 inline-flex items-center gap-1"
|
||||
>
|
||||
<Sparkles className="h-2 w-2" />
|
||||
{m}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StatChip({
|
||||
icon,
|
||||
label,
|
||||
value,
|
||||
color,
|
||||
}: {
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
value: number;
|
||||
color: string;
|
||||
}) {
|
||||
return (
|
||||
<span
|
||||
className="text-[10px] px-1.5 py-0.5 rounded inline-flex items-center gap-1 font-mono"
|
||||
style={{
|
||||
color,
|
||||
background: `${color}11`,
|
||||
border: `1px solid ${color}22`,
|
||||
}}
|
||||
>
|
||||
{icon}
|
||||
<span className="opacity-70">{label}</span>
|
||||
<span className="font-bold">{value}</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** 当前周目进度预览(在编年史对话框中以小卡片显示,提示玩家本周目已有数据) */
|
||||
export function ChronicleCurrentRunBadge() {
|
||||
const runStart = useGameStore((s) => s.runStart);
|
||||
const totalExpeditions = useGameStore((s) => s.totalExpeditions);
|
||||
const totalDecoded = useGameStore((s) => s.totalDecoded);
|
||||
const techCount = useGameStore((s) => Object.keys(s.tech || {}).length);
|
||||
|
||||
const exps = Math.max(0, totalExpeditions - (runStart?.expeditionsCompleted || 0));
|
||||
const decoded = Math.max(0, totalDecoded - (runStart?.crystalsDecoded || 0));
|
||||
const techs = Math.max(0, techCount - (runStart?.techsUnlocked || 0));
|
||||
|
||||
if (exps === 0 && decoded === 0 && techs === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="text-[10px] text-muted-foreground/60 flex items-center gap-2">
|
||||
<span className="text-fuchsia-300/80">本周目:</span>
|
||||
<span>{decoded}解码</span>
|
||||
<span>·</span>
|
||||
<span>{techs}技术</span>
|
||||
<span>·</span>
|
||||
<span>{exps}探险</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+128
@@ -0,0 +1,128 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 记忆图谱(碎片叙事)
|
||||
import { useState } from "react";
|
||||
import { useGameStore, FRAGMENTS } from "@/store/gameStore";
|
||||
import { nextFragmentThreshold } from "@/store/gameStore";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import { BookOpen, Lock, Sparkles } from "lucide-react";
|
||||
import type { Fragment } from "@/lib/game/types";
|
||||
|
||||
const ERA_NAMES = ["", "寂灭前夜", "谐振纪", "飞升潮", "回响纪", "接触纪"];
|
||||
|
||||
export function Codex() {
|
||||
const fragments = useGameStore((s) => s.fragments);
|
||||
const totalDecoded = useGameStore((s) => s.totalDecoded);
|
||||
const nextThreshold = nextFragmentThreshold(totalDecoded);
|
||||
const [selected, setSelected] = useState<Fragment | null>(null);
|
||||
|
||||
// v0.1 只展示第一纪元
|
||||
const era1 = FRAGMENTS.filter((f) => f.era === 1);
|
||||
const unlockedCount = era1.filter((f) => fragments[f.id]).length;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2 h-full">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold flex items-center gap-1.5">
|
||||
<BookOpen className="h-4 w-4 text-fuchsia-400" />
|
||||
记忆图谱
|
||||
</h3>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{unlockedCount}/{era1.length} · 第一纪元
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{nextThreshold && (
|
||||
<div className="text-[10px] text-muted-foreground/80 px-1">
|
||||
再解码 <span className="text-fuchsia-300 font-mono">{nextThreshold - totalDecoded}</span> 颗 → 下一个碎片
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ScrollArea className="flex-1 min-h-0">
|
||||
<div className="grid grid-cols-2 gap-2 pr-2">
|
||||
{era1.map((f, i) => {
|
||||
const unlocked = !!fragments[f.id];
|
||||
return (
|
||||
<button
|
||||
key={f.id}
|
||||
onClick={() => unlocked && setSelected(f)}
|
||||
disabled={!unlocked}
|
||||
className={`relative aspect-[4/3] rounded-xl border text-left p-2 transition-all duration-300 overflow-hidden ${
|
||||
unlocked
|
||||
? "border-fuchsia-400/40 bg-gradient-to-br from-fuchsia-950/40 to-black/40 hover:border-fuchsia-400/70 hover:scale-[1.02] cursor-pointer"
|
||||
: "border-white/5 bg-black/30 cursor-not-allowed"
|
||||
}`}
|
||||
style={
|
||||
unlocked
|
||||
? { boxShadow: "0 0 16px rgba(232,121,249,0.15)" }
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{/* 编号 */}
|
||||
<span
|
||||
className={`absolute top-1.5 right-1.5 text-[9px] font-mono ${
|
||||
unlocked ? "text-fuchsia-300/70" : "text-white/20"
|
||||
}`}
|
||||
>
|
||||
{String(i + 1).padStart(2, "0")}
|
||||
</span>
|
||||
{unlocked ? (
|
||||
<>
|
||||
<div className="absolute -top-3 -right-3 h-12 w-12 rounded-full bg-fuchsia-500/20 blur-xl" />
|
||||
<Sparkles className="h-3 w-3 text-fuchsia-300 mb-1" />
|
||||
<div className="text-[11px] font-semibold text-fuchsia-100 leading-tight">
|
||||
{f.title}
|
||||
</div>
|
||||
<div className="text-[9px] text-muted-foreground mt-1 line-clamp-2">
|
||||
{f.echo.slice(0, 28)}…
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex flex-col items-center justify-center h-full gap-1">
|
||||
<Lock className="h-4 w-4 text-white/20" />
|
||||
<span className="text-[9px] text-white/30">
|
||||
需解码 {f.threshold} 颗
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
{/* 详情弹层 */}
|
||||
{selected && (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/70 backdrop-blur-sm"
|
||||
onClick={() => setSelected(null)}
|
||||
>
|
||||
<Card
|
||||
className="max-w-md w-full p-5 bg-gradient-to-br from-fuchsia-950/60 to-black/80 border-fuchsia-400/40"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
style={{ boxShadow: "0 0 40px rgba(232,121,249,0.25)" }}
|
||||
>
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Sparkles className="h-4 w-4 text-fuchsia-300" />
|
||||
<span className="text-[10px] text-fuchsia-300/70 font-mono">
|
||||
第 {selected.era} 纪元 · {ERA_NAMES[selected.era] || ""}
|
||||
</span>
|
||||
</div>
|
||||
<h4 className="text-lg font-bold text-fuchsia-100 mb-3">
|
||||
{selected.title}
|
||||
</h4>
|
||||
<p className="text-sm text-foreground/90 leading-relaxed italic">
|
||||
「{selected.echo}」
|
||||
</p>
|
||||
<button
|
||||
onClick={() => setSelected(null)}
|
||||
className="mt-4 text-xs text-muted-foreground hover:text-foreground transition"
|
||||
>
|
||||
关闭
|
||||
</button>
|
||||
</Card>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+179
@@ -0,0 +1,179 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 星图天赋选择对话框(飞升后弹出,3 选 1)
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import {
|
||||
getPerk,
|
||||
CONSTELLATION_CATEGORY_META,
|
||||
constellationProgress,
|
||||
} from "@/lib/game/constellation";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
import { Sparkles, RefreshCw } from "lucide-react";
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
}
|
||||
|
||||
export function ConstellationDialog({ open, onOpenChange }: Props) {
|
||||
const pendingChoices = useGameStore((s) => s.pendingPerkChoices);
|
||||
const constellation = useGameStore((s) => s.constellation ?? []);
|
||||
const choosePerk = useGameStore((s) => s.chooseConstellationPerk);
|
||||
const reroll = useGameStore((s) => s.rerollPerkChoices);
|
||||
const [picked, setPicked] = useState<string | null>(null);
|
||||
|
||||
// 关闭时清理本地状态
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
if (!open) setPicked(null);
|
||||
}, [open]);
|
||||
|
||||
// 自动 open:当 pendingPerkChoices 存在且当前未 open 时
|
||||
useEffect(() => {
|
||||
if (pendingChoices && pendingChoices.length > 0 && !open) {
|
||||
onOpenChange(true);
|
||||
}
|
||||
if ((!pendingChoices || pendingChoices.length === 0) && open) {
|
||||
onOpenChange(false);
|
||||
}
|
||||
}, [pendingChoices, open, onOpenChange]);
|
||||
|
||||
const handlePick = (perkId: string) => {
|
||||
setPicked(perkId);
|
||||
const ok = choosePerk(perkId);
|
||||
if (ok) {
|
||||
sfx("constellation");
|
||||
// 延迟关闭,让选中动画播放
|
||||
setTimeout(() => onOpenChange(false), 500);
|
||||
}
|
||||
};
|
||||
|
||||
const handleReroll = () => {
|
||||
reroll();
|
||||
sfx("uiClick");
|
||||
};
|
||||
|
||||
if (!pendingChoices || pendingChoices.length === 0) return null;
|
||||
|
||||
const progress = constellationProgress(constellation);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-md border-fuchsia-400/30 bg-gradient-to-br from-[#0a0820]/95 to-[#1a0f30]/95 backdrop-blur-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2 text-fuchsia-200">
|
||||
<Sparkles className="h-4 w-4" />
|
||||
星图觉醒
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-muted-foreground text-xs">
|
||||
飞升带来的回响在星图上凝聚。从 3 道星辉中选择 1 道,永久获得其加成。
|
||||
<br />
|
||||
<span className="text-fuchsia-300/80">当前已觉醒 {progress.unlocked}/{progress.total}</span>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="grid grid-cols-1 gap-2 mt-1">
|
||||
{pendingChoices.map((perkId) => {
|
||||
const perk = getPerk(perkId);
|
||||
if (!perk) return null;
|
||||
const meta = CONSTELLATION_CATEGORY_META[perk.category];
|
||||
const isPicked = picked === perkId;
|
||||
return (
|
||||
<button
|
||||
key={perkId}
|
||||
onClick={() => handlePick(perkId)}
|
||||
disabled={!!picked}
|
||||
className={`group relative w-full text-left rounded-lg border px-3 py-2.5 transition-all overflow-hidden ${
|
||||
isPicked
|
||||
? "border-fuchsia-400/80 bg-fuchsia-500/10 scale-[1.02]"
|
||||
: picked
|
||||
? "border-white/5 opacity-40"
|
||||
: "border-white/10 hover:border-white/30 hover:bg-white/5"
|
||||
}`}
|
||||
style={{
|
||||
boxShadow: isPicked ? `0 0 20px ${meta.glow}` : undefined,
|
||||
}}
|
||||
>
|
||||
{/* 类别色条 */}
|
||||
<div
|
||||
className="absolute left-0 top-0 bottom-0 w-1"
|
||||
style={{ background: meta.hex, boxShadow: `0 0 8px ${meta.hex}` }}
|
||||
/>
|
||||
<div className="pl-2 flex items-start gap-3">
|
||||
{/* 类别图标 */}
|
||||
<div
|
||||
className="flex-shrink-0 mt-0.5 h-8 w-8 rounded-full flex items-center justify-center text-sm font-bold"
|
||||
style={{
|
||||
background: `${meta.hex}20`,
|
||||
color: meta.hex,
|
||||
border: `1px solid ${meta.hex}40`,
|
||||
}}
|
||||
>
|
||||
{meta.name.charAt(0)}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-0.5">
|
||||
<span className="text-sm font-bold text-foreground">{perk.name}</span>
|
||||
<span
|
||||
className="text-[9px] px-1 py-0.5 rounded font-mono"
|
||||
style={{
|
||||
background: `${meta.hex}20`,
|
||||
color: meta.hex,
|
||||
}}
|
||||
>
|
||||
{meta.name}
|
||||
</span>
|
||||
</div>
|
||||
<div className="text-[11px] text-muted-foreground">{perk.desc}</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* 选中粒子动画 */}
|
||||
{isPicked && (
|
||||
<div className="absolute inset-0 pointer-events-none">
|
||||
{[...Array(8)].map((_, i) => (
|
||||
<span
|
||||
key={i}
|
||||
className="absolute h-1 w-1 rounded-full animate-ping"
|
||||
style={{
|
||||
background: meta.hex,
|
||||
left: `${20 + i * 8}%`,
|
||||
top: `${30 + (i % 3) * 20}%`,
|
||||
animationDelay: `${i * 50}ms`,
|
||||
animationDuration: "800ms",
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between mt-3 pt-2 border-t border-white/5">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleReroll}
|
||||
disabled={!!picked}
|
||||
className="text-muted-foreground hover:text-foreground h-7 text-[11px]"
|
||||
>
|
||||
<RefreshCw className="h-3 w-3 mr-1" />
|
||||
重新抽取
|
||||
</Button>
|
||||
<span className="text-[10px] text-muted-foreground/60">
|
||||
✦ 选择后永久保留,跨周目生效
|
||||
</span>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Executable
+337
@@ -0,0 +1,337 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 星图天文台面板(飞升元进程可视化)
|
||||
// 6 个星座(六边形布局)× 3 颗星 = 18 个天赋节点,已解锁的星点亮 + 连线
|
||||
import { useEffect, useRef, useState, useMemo } from "react";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import {
|
||||
CONSTELLATION_PERKS,
|
||||
CONSTELLATION_CATEGORY_META,
|
||||
getPerk,
|
||||
constellationBonuses,
|
||||
getConstellationLayout,
|
||||
getStarsInCategory,
|
||||
countUnlockedInCategory,
|
||||
constellationProgress,
|
||||
type ConstellationCategory,
|
||||
} from "@/lib/game/constellation";
|
||||
import type { ConstellationPerk } from "@/lib/game/constellation";
|
||||
|
||||
interface StarPoint {
|
||||
perk: ConstellationPerk;
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
interface HoverState {
|
||||
perk: ConstellationPerk;
|
||||
x: number;
|
||||
y: number;
|
||||
unlocked: boolean;
|
||||
}
|
||||
|
||||
export function ConstellationPanel() {
|
||||
const constellation = useGameStore((s) => s.constellation ?? []);
|
||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
const [size, setSize] = useState({ w: 360, h: 360 });
|
||||
const [hover, setHover] = useState<HoverState | null>(null);
|
||||
const ownedSet = useMemo(() => new Set(constellation), [constellation]);
|
||||
|
||||
// 自适应尺寸
|
||||
useEffect(() => {
|
||||
const el = containerRef.current;
|
||||
if (!el) return;
|
||||
const ro = new ResizeObserver(() => {
|
||||
const r = el.getBoundingClientRect();
|
||||
setSize({ w: Math.max(280, r.width), h: Math.max(280, Math.min(420, r.width)) });
|
||||
});
|
||||
ro.observe(el);
|
||||
return () => ro.disconnect();
|
||||
}, []);
|
||||
|
||||
// 计算布局(中心点 + 半径)
|
||||
const layout = useMemo(() => {
|
||||
const cx = size.w / 2;
|
||||
const cy = size.h / 2;
|
||||
const radius = Math.min(size.w, size.h) * 0.32;
|
||||
return { cx, cy, radius };
|
||||
}, [size]);
|
||||
|
||||
// 收集所有星点 + 每个星座的星点列表
|
||||
const clusters = useMemo(() => {
|
||||
const centers = getConstellationLayout(layout.cx, layout.cy, layout.radius);
|
||||
return centers.map((c) => {
|
||||
const stars = getStarsInCategory(c.category, c.cx, c.cy, 1) as StarPoint[];
|
||||
return { ...c, stars };
|
||||
});
|
||||
}, [layout]);
|
||||
|
||||
// 绘制
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
canvas.width = size.w * dpr;
|
||||
canvas.height = size.h * dpr;
|
||||
canvas.style.width = `${size.w}px`;
|
||||
canvas.style.height = `${size.h}px`;
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
let rafId = 0;
|
||||
const start = performance.now();
|
||||
const draw = (now: number) => {
|
||||
const t = (now - start) / 1000;
|
||||
ctx.clearRect(0, 0, size.w, size.h);
|
||||
// 背景径向暗光
|
||||
const bg = ctx.createRadialGradient(layout.cx, layout.cy, 0, layout.cx, layout.cy, layout.radius * 1.6);
|
||||
bg.addColorStop(0, "rgba(40,30,80,0.18)");
|
||||
bg.addColorStop(1, "rgba(5,4,16,0)");
|
||||
ctx.fillStyle = bg;
|
||||
ctx.fillRect(0, 0, size.w, size.h);
|
||||
|
||||
// 中心装饰:星核
|
||||
ctx.save();
|
||||
ctx.translate(layout.cx, layout.cy);
|
||||
const coreR = 6 + Math.sin(t * 1.5) * 1.5;
|
||||
const coreGrad = ctx.createRadialGradient(0, 0, 0, 0, 0, coreR * 3);
|
||||
coreGrad.addColorStop(0, "rgba(232,121,249,0.9)");
|
||||
coreGrad.addColorStop(0.4, "rgba(232,121,249,0.3)");
|
||||
coreGrad.addColorStop(1, "rgba(232,121,249,0)");
|
||||
ctx.fillStyle = coreGrad;
|
||||
ctx.beginPath();
|
||||
ctx.arc(0, 0, coreR * 3, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.fillStyle = "#fce7ff";
|
||||
ctx.beginPath();
|
||||
ctx.arc(0, 0, coreR * 0.6, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
|
||||
// 连接星座到中心的虚线(已解锁 >=1 时)
|
||||
for (const c of clusters) {
|
||||
const cnt = countUnlockedInCategory(constellation, c.category);
|
||||
if (cnt > 0) {
|
||||
ctx.save();
|
||||
ctx.strokeStyle = c.meta.glow;
|
||||
ctx.lineWidth = 1;
|
||||
ctx.setLineDash([2, 4]);
|
||||
ctx.globalAlpha = 0.4 + Math.sin(t * 2 + c.cx) * 0.1;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(layout.cx, layout.cy);
|
||||
ctx.lineTo(c.cx, c.cy);
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
// 绘制每个星座
|
||||
for (const c of clusters) {
|
||||
const cnt = countUnlockedInCategory(constellation, c.category);
|
||||
// 星座中心标签
|
||||
ctx.save();
|
||||
ctx.font = "10px ui-monospace, monospace";
|
||||
ctx.textAlign = "center";
|
||||
ctx.fillStyle = cnt > 0 ? c.meta.hex : "rgba(148,163,184,0.5)";
|
||||
ctx.globalAlpha = 0.85;
|
||||
ctx.fillText(c.meta.name, c.cx, c.cy + 38);
|
||||
ctx.restore();
|
||||
|
||||
// 同星座内已解锁星点之间的连线
|
||||
const unlockedStars = c.stars.filter((s) => ownedSet.has(s.perk.id));
|
||||
if (unlockedStars.length >= 2) {
|
||||
ctx.save();
|
||||
ctx.strokeStyle = c.meta.glow;
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.globalAlpha = 0.6;
|
||||
ctx.beginPath();
|
||||
unlockedStars.forEach((s, i) => {
|
||||
if (i === 0) ctx.moveTo(s.x, s.y);
|
||||
else ctx.lineTo(s.x, s.y);
|
||||
});
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
// 绘制星点
|
||||
for (const star of c.stars) {
|
||||
const unlocked = ownedSet.has(star.perk.id);
|
||||
ctx.save();
|
||||
ctx.translate(star.x, star.y);
|
||||
// 闪烁系数
|
||||
const twinkle = unlocked ? 0.85 + Math.sin(t * 3 + star.x * 0.1) * 0.15 : 0.3;
|
||||
// 外光晕
|
||||
const haloR = unlocked ? 10 : 5;
|
||||
const haloGrad = ctx.createRadialGradient(0, 0, 0, 0, 0, haloR);
|
||||
haloGrad.addColorStop(0, unlocked ? c.meta.glow : "rgba(100,116,139,0.2)");
|
||||
haloGrad.addColorStop(1, "rgba(0,0,0,0)");
|
||||
ctx.fillStyle = haloGrad;
|
||||
ctx.globalAlpha = twinkle;
|
||||
ctx.beginPath();
|
||||
ctx.arc(0, 0, haloR, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
// 核心
|
||||
ctx.globalAlpha = unlocked ? 1 : 0.4;
|
||||
ctx.fillStyle = unlocked ? c.meta.hex : "#475569";
|
||||
ctx.beginPath();
|
||||
ctx.arc(0, 0, unlocked ? 3.5 : 2, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
// 解锁星点:4 道十字光线
|
||||
if (unlocked) {
|
||||
ctx.strokeStyle = c.meta.hex;
|
||||
ctx.globalAlpha = 0.7 * twinkle;
|
||||
ctx.lineWidth = 0.8;
|
||||
const ray = 7 + Math.sin(t * 4 + star.y * 0.1) * 1.5;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-ray, 0); ctx.lineTo(ray, 0);
|
||||
ctx.moveTo(0, -ray); ctx.lineTo(0, ray);
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
rafId = requestAnimationFrame(draw);
|
||||
};
|
||||
rafId = requestAnimationFrame(draw);
|
||||
return () => cancelAnimationFrame(rafId);
|
||||
}, [clusters, layout, size, constellation, ownedSet]);
|
||||
|
||||
// 鼠标交互:检测 hover
|
||||
const handleMove = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const mx = e.clientX - rect.left;
|
||||
const my = e.clientY - rect.top;
|
||||
let best: HoverState | null = null;
|
||||
let bestDist = 14;
|
||||
for (const c of clusters) {
|
||||
for (const star of c.stars) {
|
||||
const d = Math.hypot(star.x - mx, star.y - my);
|
||||
if (d < bestDist) {
|
||||
bestDist = d;
|
||||
best = {
|
||||
perk: star.perk,
|
||||
x: star.x,
|
||||
y: star.y,
|
||||
unlocked: ownedSet.has(star.perk.id),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
setHover(best);
|
||||
};
|
||||
const handleLeave = () => setHover(null);
|
||||
|
||||
const progress = constellationProgress(constellation);
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className="flex flex-col gap-2 min-h-0 h-full">
|
||||
{/* 顶部进度 */}
|
||||
<div className="flex items-center justify-between text-[11px] px-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="text-fuchsia-300">✦</span>
|
||||
<span className="text-muted-foreground">星图天赋</span>
|
||||
<span className="font-mono text-foreground">
|
||||
{progress.unlocked}/{progress.total}
|
||||
</span>
|
||||
</div>
|
||||
<span className="text-muted-foreground/60 text-[10px]">每次飞升可解锁 1 个</span>
|
||||
</div>
|
||||
|
||||
{/* Canvas 星图 */}
|
||||
<div className="relative rounded-xl bg-black/30 border border-white/5 overflow-hidden flex-shrink-0">
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
onMouseMove={handleMove}
|
||||
onMouseLeave={handleLeave}
|
||||
className="block cursor-pointer"
|
||||
/>
|
||||
{/* Hover tooltip */}
|
||||
{hover && (
|
||||
<div
|
||||
className="pointer-events-none absolute z-10 max-w-[200px] rounded-md bg-black/85 border border-white/10 px-2 py-1.5 text-[10px] leading-tight shadow-lg backdrop-blur-sm"
|
||||
style={{
|
||||
left: Math.min(hover.x + 12, size.w - 200),
|
||||
top: Math.max(0, hover.y - 40),
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="font-bold mb-0.5"
|
||||
style={{ color: CONSTELLATION_CATEGORY_META[hover.perk.category].hex }}
|
||||
>
|
||||
{hover.unlocked ? "★ " : "☆ "}
|
||||
{hover.perk.name}
|
||||
</div>
|
||||
<div className="text-muted-foreground">{hover.perk.desc}</div>
|
||||
<div className="text-muted-foreground/60 mt-0.5">
|
||||
{CONSTELLATION_CATEGORY_META[hover.perk.category].name} · 序{hover.perk.order}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 类别图例 + 当前总修饰 */}
|
||||
<div className="grid grid-cols-3 gap-1 text-[10px]">
|
||||
{(Object.keys(CONSTELLATION_CATEGORY_META) as ConstellationCategory[]).map((cat) => {
|
||||
const meta = CONSTELLATION_CATEGORY_META[cat];
|
||||
const cnt = countUnlockedInCategory(constellation, cat);
|
||||
const total = CONSTELLATION_PERKS.filter((p) => p.category === cat).length;
|
||||
return (
|
||||
<div
|
||||
key={cat}
|
||||
className="rounded-md bg-black/25 border border-white/5 px-1.5 py-1 flex items-center gap-1"
|
||||
style={cnt > 0 ? { borderColor: `${meta.hex}40` } : undefined}
|
||||
>
|
||||
<span
|
||||
className="inline-block h-1.5 w-1.5 rounded-full flex-shrink-0"
|
||||
style={{ background: meta.hex, boxShadow: cnt > 0 ? `0 0 4px ${meta.hex}` : "none" }}
|
||||
/>
|
||||
<span className="text-muted-foreground truncate">{meta.name}</span>
|
||||
<span className="ml-auto font-mono" style={{ color: cnt > 0 ? meta.hex : "rgba(148,163,184,0.5)" }}>
|
||||
{cnt}/{total}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* 已解锁天赋列表 */}
|
||||
<div className="flex-1 min-h-0 overflow-y-auto pr-1 echo-scrollbar">
|
||||
{constellation.length === 0 ? (
|
||||
<div className="rounded-md bg-black/25 border border-dashed border-white/10 px-3 py-3 text-center text-[11px] text-muted-foreground/70">
|
||||
<div className="mb-1 text-fuchsia-300/80">✦</div>
|
||||
尚未解锁任何天赋。<br />
|
||||
累积接触进度至 100%,发起「飞升」即可在 3 个随机天赋中选 1。
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-1">
|
||||
{constellation.map((id) => {
|
||||
const perk = getPerk(id);
|
||||
if (!perk) return null;
|
||||
const meta = CONSTELLATION_CATEGORY_META[perk.category];
|
||||
return (
|
||||
<div
|
||||
key={id}
|
||||
className="rounded-md bg-black/25 border px-2 py-1.5 flex items-center gap-2 text-[11px]"
|
||||
style={{ borderColor: `${meta.hex}30` }}
|
||||
>
|
||||
<span
|
||||
className="inline-block h-2 w-2 rounded-full flex-shrink-0"
|
||||
style={{ background: meta.hex, boxShadow: `0 0 6px ${meta.hex}` }}
|
||||
/>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-foreground truncate">{perk.name}</div>
|
||||
<div className="text-muted-foreground/70 text-[10px] truncate">{perk.desc}</div>
|
||||
</div>
|
||||
<span className="text-[9px] text-muted-foreground/50 font-mono">{meta.name}</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+2018
File diff suppressed because it is too large
Load Diff
Executable
+667
@@ -0,0 +1,667 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 中央晶体集群 + 主动脉冲(v0.7 Canvas 粒子系统)
|
||||
import { useRef, useState, useCallback, useEffect } from "react";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import { formatNum } from "@/lib/game/config";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
import { PULSE_WHISPERS, maybeWhisper } from "@/lib/game/narrative";
|
||||
|
||||
interface FloatNum {
|
||||
id: number;
|
||||
x: number;
|
||||
y: number;
|
||||
text: string;
|
||||
born: number;
|
||||
color: string;
|
||||
}
|
||||
|
||||
// ===== Canvas 粒子系统类型 =====
|
||||
interface EnergyParticle {
|
||||
// 环绕能量粒子(持续)
|
||||
angle: number;
|
||||
radius: number;
|
||||
baseRadius: number;
|
||||
speed: number;
|
||||
size: number;
|
||||
color: string;
|
||||
alpha: number;
|
||||
phase: number;
|
||||
}
|
||||
|
||||
interface AmbientParticle {
|
||||
// 环境星尘(缓慢漂浮)
|
||||
x: number;
|
||||
y: number;
|
||||
vx: number;
|
||||
vy: number;
|
||||
size: number;
|
||||
alpha: number;
|
||||
twinkle: number;
|
||||
}
|
||||
|
||||
interface ShockRing {
|
||||
// 冲击波环(点击触发)
|
||||
born: number;
|
||||
color: string;
|
||||
maxRadius: number;
|
||||
duration: number;
|
||||
}
|
||||
|
||||
interface BurstParticle {
|
||||
// 爆发粒子(点击触发,径向发散)
|
||||
x: number;
|
||||
y: number;
|
||||
vx: number;
|
||||
vy: number;
|
||||
size: number;
|
||||
color: string;
|
||||
born: number;
|
||||
life: number;
|
||||
}
|
||||
|
||||
const COLORS = {
|
||||
emerald: "#34d399",
|
||||
fuchsia: "#e879f9",
|
||||
rose: "#fb7185",
|
||||
amber: "#fbbf24",
|
||||
white: "#ffffff",
|
||||
};
|
||||
|
||||
function comboColor(combo: number): string {
|
||||
if (combo >= 5) return COLORS.amber;
|
||||
if (combo >= 3) return COLORS.fuchsia;
|
||||
return COLORS.emerald;
|
||||
}
|
||||
|
||||
export function CrystalOrb() {
|
||||
const pulse = useGameStore((s) => s.pulse);
|
||||
const crystals = useGameStore((s) => s.crystals);
|
||||
const crystalsPerSec = useGameStore((s) => s.crystalsPerSec);
|
||||
const crystalCap = useGameStore((s) => s.crystalCap);
|
||||
const combo = useGameStore((s) => s._combo);
|
||||
const { toast } = useToast();
|
||||
|
||||
const [floats, setFloats] = useState<FloatNum[]>([]);
|
||||
const idRef = useRef(0);
|
||||
|
||||
// Canvas refs
|
||||
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
const pulseAnimRef = useRef(0);
|
||||
const [pulseAnim, setPulseAnim] = useState(0); // 触发 SVG 环动画
|
||||
|
||||
// 粒子状态 refs(不触发 re-render)
|
||||
const energyParticlesRef = useRef<EnergyParticle[]>([]);
|
||||
const ambientParticlesRef = useRef<AmbientParticle[]>([]);
|
||||
const shockRingsRef = useRef<ShockRing[]>([]);
|
||||
const burstParticlesRef = useRef<BurstParticle[]>([]);
|
||||
|
||||
const comboRef = useRef(combo);
|
||||
const fillPctRef = useRef(0);
|
||||
const crystalsRef = useRef(crystals);
|
||||
const crystalCapRef = useRef(crystalCap);
|
||||
useEffect(() => {
|
||||
comboRef.current = combo;
|
||||
crystalsRef.current = crystals;
|
||||
crystalCapRef.current = crystalCap;
|
||||
}, [combo, crystals, crystalCap]);
|
||||
|
||||
const mouseRef = useRef<{ x: number; y: number; inside: boolean }>({
|
||||
x: 0,
|
||||
y: 0,
|
||||
inside: false,
|
||||
});
|
||||
|
||||
// ===== 初始化粒子 =====
|
||||
const initParticles = useCallback((w: number, h: number) => {
|
||||
const cx = w / 2;
|
||||
const cy = h / 2;
|
||||
const baseR = Math.min(w, h) * 0.28;
|
||||
|
||||
// 环绕能量粒子(3 层,每层不同速度方向)
|
||||
const energy: EnergyParticle[] = [];
|
||||
const layers = [
|
||||
{ count: 14, rMul: 0.95, speed: 0.6, color: COLORS.emerald },
|
||||
{ count: 10, rMul: 1.15, speed: -0.4, color: COLORS.fuchsia },
|
||||
{ count: 8, rMul: 1.35, speed: 0.3, color: COLORS.rose },
|
||||
];
|
||||
layers.forEach((layer) => {
|
||||
for (let i = 0; i < layer.count; i++) {
|
||||
energy.push({
|
||||
angle: (Math.PI * 2 * i) / layer.count + Math.random() * 0.3,
|
||||
radius: baseR * layer.rMul,
|
||||
baseRadius: baseR * layer.rMul,
|
||||
speed: layer.speed * (0.8 + Math.random() * 0.4),
|
||||
size: 1.5 + Math.random() * 2,
|
||||
color: layer.color,
|
||||
alpha: 0.5 + Math.random() * 0.4,
|
||||
phase: Math.random() * Math.PI * 2,
|
||||
});
|
||||
}
|
||||
});
|
||||
energyParticlesRef.current = energy;
|
||||
|
||||
// 环境星尘
|
||||
const ambient: AmbientParticle[] = [];
|
||||
for (let i = 0; i < 40; i++) {
|
||||
ambient.push({
|
||||
x: Math.random() * w,
|
||||
y: Math.random() * h,
|
||||
vx: (Math.random() - 0.5) * 8,
|
||||
vy: (Math.random() - 0.5) * 8,
|
||||
size: 0.5 + Math.random() * 1.5,
|
||||
alpha: 0.2 + Math.random() * 0.5,
|
||||
twinkle: Math.random() * Math.PI * 2,
|
||||
});
|
||||
}
|
||||
ambientParticlesRef.current = ambient;
|
||||
void cx;
|
||||
void cy;
|
||||
}, []);
|
||||
|
||||
// ===== 触发脉冲效果(Canvas 部分)=====
|
||||
const triggerPulseEffect = useCallback(
|
||||
(x: number, y: number, res: { combo: number; gain: number }) => {
|
||||
const color = comboColor(res.combo);
|
||||
const now = performance.now();
|
||||
|
||||
// 冲击波环(多层错峰)
|
||||
shockRingsRef.current.push({
|
||||
born: now,
|
||||
color: COLORS.emerald,
|
||||
maxRadius: 140,
|
||||
duration: 700,
|
||||
});
|
||||
if (res.combo >= 3) {
|
||||
shockRingsRef.current.push({
|
||||
born: now + 100,
|
||||
color: COLORS.fuchsia,
|
||||
maxRadius: 170,
|
||||
duration: 800,
|
||||
});
|
||||
}
|
||||
if (res.combo >= 5) {
|
||||
shockRingsRef.current.push({
|
||||
born: now + 200,
|
||||
color: COLORS.amber,
|
||||
maxRadius: 200,
|
||||
duration: 900,
|
||||
});
|
||||
}
|
||||
|
||||
// 径向爆发粒子
|
||||
const pcount = 10 + Math.min(10, res.combo) * 2;
|
||||
for (let i = 0; i < pcount; i++) {
|
||||
const angle = (Math.PI * 2 * i) / pcount + Math.random() * 0.4;
|
||||
const speed = 120 + Math.random() * 180;
|
||||
burstParticlesRef.current.push({
|
||||
x,
|
||||
y,
|
||||
vx: Math.cos(angle) * speed,
|
||||
vy: Math.sin(angle) * speed,
|
||||
size: 2 + Math.random() * 3,
|
||||
color,
|
||||
born: now,
|
||||
life: 600 + Math.random() * 300,
|
||||
});
|
||||
}
|
||||
|
||||
// 让能量粒子被"推开"再回弹
|
||||
energyParticlesRef.current.forEach((p) => {
|
||||
p.radius = p.baseRadius * (1.25 + Math.random() * 0.15);
|
||||
});
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
// ===== 点击处理 =====
|
||||
const handleClick = useCallback(
|
||||
(e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
const res = pulse();
|
||||
if (!res) return;
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
const x = e.clientX - rect.left;
|
||||
const y = e.clientY - rect.top;
|
||||
const id = idRef.current++;
|
||||
const floatColor = comboColor(res.combo);
|
||||
setFloats((f) => [
|
||||
...f,
|
||||
{
|
||||
id,
|
||||
x,
|
||||
y,
|
||||
text: `+${res.gain.toFixed(1)}`,
|
||||
born: Date.now(),
|
||||
color: floatColor,
|
||||
},
|
||||
]);
|
||||
triggerPulseEffect(x, y, res);
|
||||
setPulseAnim((n) => n + 1);
|
||||
sfx(res.combo >= 3 ? "pulseCombo" : "pulse", { combo: res.combo });
|
||||
setTimeout(() => {
|
||||
setFloats((f) => f.filter((it) => it.id !== id));
|
||||
}, 900);
|
||||
if (res.combo >= 5 && res.combo % 5 === 0) {
|
||||
// v0.9 叙事融入:高连击时注入世界观低语
|
||||
const whisper = maybeWhisper(PULSE_WHISPERS, 0.6);
|
||||
toast({
|
||||
title: `×${res.combo} 连击!`,
|
||||
description: whisper ? `「${whisper}」` : "谐振叠加,产能飙升。",
|
||||
});
|
||||
} else if (res.combo >= 3 && res.combo % 3 === 0) {
|
||||
// 3 连击时也有概率出现叙事
|
||||
const whisper = maybeWhisper(PULSE_WHISPERS, 0.3);
|
||||
if (whisper) {
|
||||
toast({ title: "低语", description: `「${whisper}」` });
|
||||
}
|
||||
}
|
||||
},
|
||||
[pulse, toast, triggerPulseEffect]
|
||||
);
|
||||
|
||||
// ===== Canvas 动画循环 =====
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
const container = containerRef.current;
|
||||
if (!canvas || !container) return;
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
|
||||
let rafId = 0;
|
||||
let lastTime = performance.now();
|
||||
let dpr = Math.min(window.devicePixelRatio || 1, 2);
|
||||
|
||||
const resize = () => {
|
||||
const rect = container.getBoundingClientRect();
|
||||
dpr = Math.min(window.devicePixelRatio || 1, 2);
|
||||
canvas.width = Math.max(1, Math.floor(rect.width * dpr));
|
||||
canvas.height = Math.max(1, Math.floor(rect.height * dpr));
|
||||
canvas.style.width = `${rect.width}px`;
|
||||
canvas.style.height = `${rect.height}px`;
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
initParticles(rect.width, rect.height);
|
||||
};
|
||||
resize();
|
||||
const ro = new ResizeObserver(resize);
|
||||
ro.observe(container);
|
||||
|
||||
const draw = (now: number) => {
|
||||
const dt = Math.min(0.05, (now - lastTime) / 1000);
|
||||
lastTime = now;
|
||||
const w = canvas.width / dpr;
|
||||
const h = canvas.height / dpr;
|
||||
const cx = w / 2;
|
||||
const cy = h / 2;
|
||||
const baseR = Math.min(w, h) * 0.28;
|
||||
|
||||
ctx.clearRect(0, 0, w, h);
|
||||
|
||||
// === 1. 环境星尘 ===
|
||||
ambientParticlesRef.current.forEach((p) => {
|
||||
p.x += p.vx * dt;
|
||||
p.y += p.vy * dt;
|
||||
p.twinkle += dt * 2;
|
||||
if (p.x < 0) p.x = w;
|
||||
if (p.x > w) p.x = 0;
|
||||
if (p.y < 0) p.y = h;
|
||||
if (p.y > h) p.y = 0;
|
||||
const tw = 0.5 + 0.5 * Math.sin(p.twinkle);
|
||||
ctx.globalAlpha = p.alpha * tw;
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.beginPath();
|
||||
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
});
|
||||
ctx.globalAlpha = 1;
|
||||
|
||||
// === 2. 外层辉光(呼吸)===
|
||||
const breath = 0.85 + 0.15 * Math.sin(now * 0.001);
|
||||
const glowGrad = ctx.createRadialGradient(
|
||||
cx,
|
||||
cy,
|
||||
baseR * 0.3,
|
||||
cx,
|
||||
cy,
|
||||
baseR * 2.2
|
||||
);
|
||||
glowGrad.addColorStop(0, `rgba(52,211,153,${0.18 * breath})`);
|
||||
glowGrad.addColorStop(0.5, `rgba(232,121,249,${0.1 * breath})`);
|
||||
glowGrad.addColorStop(1, "rgba(0,0,0,0)");
|
||||
ctx.fillStyle = glowGrad;
|
||||
ctx.fillRect(0, 0, w, h);
|
||||
|
||||
// === 3. 进度填充环(背景 + 进度)===
|
||||
ctx.lineWidth = 2.5;
|
||||
ctx.strokeStyle = "rgba(255,255,255,0.06)";
|
||||
ctx.beginPath();
|
||||
ctx.arc(cx, cy, baseR * 1.45, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
|
||||
const fp = Math.min(
|
||||
100,
|
||||
(crystalsRef.current / Math.max(1, crystalCapRef.current)) * 100
|
||||
);
|
||||
fillPctRef.current = fp;
|
||||
const ringR = baseR * 1.45;
|
||||
const grad = ctx.createLinearGradient(
|
||||
cx - ringR,
|
||||
cy - ringR,
|
||||
cx + ringR,
|
||||
cy + ringR
|
||||
);
|
||||
grad.addColorStop(0, COLORS.emerald);
|
||||
grad.addColorStop(0.5, COLORS.fuchsia);
|
||||
grad.addColorStop(1, COLORS.rose);
|
||||
ctx.strokeStyle = grad;
|
||||
ctx.lineWidth = 3;
|
||||
ctx.lineCap = "round";
|
||||
ctx.shadowBlur = 8;
|
||||
ctx.shadowColor = COLORS.emerald;
|
||||
ctx.beginPath();
|
||||
ctx.arc(
|
||||
cx,
|
||||
cy,
|
||||
ringR,
|
||||
-Math.PI / 2,
|
||||
-Math.PI / 2 + (Math.PI * 2 * fp) / 100
|
||||
);
|
||||
ctx.stroke();
|
||||
ctx.shadowBlur = 0;
|
||||
|
||||
// === 4. 环绕能量粒子 ===
|
||||
energyParticlesRef.current.forEach((p) => {
|
||||
p.angle += p.speed * dt;
|
||||
// 回弹到 baseRadius
|
||||
p.radius += (p.baseRadius - p.radius) * Math.min(1, dt * 4);
|
||||
const px = cx + Math.cos(p.angle) * p.radius;
|
||||
const py = cy + Math.sin(p.angle) * p.radius;
|
||||
const flicker = 0.7 + 0.3 * Math.sin(now * 0.005 + p.phase);
|
||||
ctx.globalAlpha = p.alpha * flicker;
|
||||
ctx.fillStyle = p.color;
|
||||
ctx.shadowBlur = 10;
|
||||
ctx.shadowColor = p.color;
|
||||
ctx.beginPath();
|
||||
ctx.arc(px, py, p.size, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
|
||||
// 拖尾(向心方向的小线段)
|
||||
ctx.globalAlpha = p.alpha * flicker * 0.4;
|
||||
ctx.strokeStyle = p.color;
|
||||
ctx.lineWidth = p.size * 0.6;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(px, py);
|
||||
ctx.lineTo(
|
||||
cx + Math.cos(p.angle - p.speed * 0.08) * (p.radius - 2),
|
||||
cy + Math.sin(p.angle - p.speed * 0.08) * (p.radius - 2)
|
||||
);
|
||||
ctx.stroke();
|
||||
});
|
||||
ctx.globalAlpha = 1;
|
||||
ctx.shadowBlur = 0;
|
||||
|
||||
// === 5. 中央晶核 ===
|
||||
const coreR = baseR * 0.95;
|
||||
// 鼠标接近时晶核轻微偏移(视差感)
|
||||
let coreOffsetX = 0;
|
||||
let coreOffsetY = 0;
|
||||
if (mouseRef.current.inside) {
|
||||
const dx = mouseRef.current.x - cx;
|
||||
const dy = mouseRef.current.y - cy;
|
||||
const dist = Math.hypot(dx, dy);
|
||||
if (dist > 0.1) {
|
||||
coreOffsetX = (dx / dist) * Math.min(8, dist * 0.05);
|
||||
coreOffsetY = (dy / dist) * Math.min(8, dist * 0.05);
|
||||
}
|
||||
}
|
||||
const ccx = cx + coreOffsetX;
|
||||
const ccy = cy + coreOffsetY;
|
||||
|
||||
// 晶核主体(径向渐变)
|
||||
const coreGrad = ctx.createRadialGradient(
|
||||
ccx - coreR * 0.25,
|
||||
ccy - coreR * 0.3,
|
||||
coreR * 0.1,
|
||||
ccx,
|
||||
ccy,
|
||||
coreR
|
||||
);
|
||||
coreGrad.addColorStop(0, "rgba(255,255,255,0.95)");
|
||||
coreGrad.addColorStop(0.3, `rgba(52,211,153,${0.85 * breath})`);
|
||||
coreGrad.addColorStop(0.65, "rgba(232,121,249,0.55)");
|
||||
coreGrad.addColorStop(1, "rgba(251,113,133,0.2)");
|
||||
ctx.fillStyle = coreGrad;
|
||||
ctx.shadowBlur = 30;
|
||||
ctx.shadowColor = COLORS.emerald;
|
||||
ctx.beginPath();
|
||||
ctx.arc(ccx, ccy, coreR, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
|
||||
// 晶核内部六边形纹理
|
||||
ctx.save();
|
||||
ctx.translate(ccx, ccy);
|
||||
ctx.globalAlpha = 0.25;
|
||||
ctx.strokeStyle = "rgba(255,255,255,0.6)";
|
||||
ctx.lineWidth = 0.8;
|
||||
const hexR = coreR * 0.7;
|
||||
for (let layer = 0; layer < 3; layer++) {
|
||||
const r = hexR * (1 - layer * 0.3);
|
||||
ctx.beginPath();
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const a = (Math.PI / 3) * i + now * 0.0002 * (layer % 2 ? 1 : -1);
|
||||
const px = Math.cos(a) * r;
|
||||
const py = Math.sin(a) * r;
|
||||
if (i === 0) ctx.moveTo(px, py);
|
||||
else ctx.lineTo(px, py);
|
||||
}
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
|
||||
// 高光
|
||||
ctx.globalAlpha = 0.4;
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.beginPath();
|
||||
ctx.ellipse(
|
||||
ccx - coreR * 0.25,
|
||||
ccy - coreR * 0.35,
|
||||
coreR * 0.35,
|
||||
coreR * 0.18,
|
||||
-0.4,
|
||||
0,
|
||||
Math.PI * 2
|
||||
);
|
||||
ctx.fill();
|
||||
ctx.globalAlpha = 1;
|
||||
ctx.shadowBlur = 0;
|
||||
|
||||
// === 6. 冲击波环 ===
|
||||
shockRingsRef.current = shockRingsRef.current.filter((ring) => {
|
||||
const elapsed = now - ring.born;
|
||||
if (elapsed < 0 || elapsed > ring.duration) return elapsed <= ring.duration + 50;
|
||||
const t = elapsed / ring.duration;
|
||||
const r = ring.maxRadius * t;
|
||||
const alpha = (1 - t) * 0.8;
|
||||
ctx.globalAlpha = alpha;
|
||||
ctx.strokeStyle = ring.color;
|
||||
ctx.lineWidth = 2.5 * (1 - t * 0.5);
|
||||
ctx.shadowBlur = 12;
|
||||
ctx.shadowColor = ring.color;
|
||||
ctx.beginPath();
|
||||
ctx.arc(cx, cy, r, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
ctx.shadowBlur = 0;
|
||||
return true;
|
||||
});
|
||||
shockRingsRef.current = shockRingsRef.current.filter(
|
||||
(r) => now - r.born < r.duration
|
||||
);
|
||||
ctx.globalAlpha = 1;
|
||||
|
||||
// === 7. 爆发粒子 ===
|
||||
burstParticlesRef.current = burstParticlesRef.current.filter((p) => {
|
||||
const age = now - p.born;
|
||||
if (age > p.life) return false;
|
||||
p.x += p.vx * dt;
|
||||
p.y += p.vy * dt;
|
||||
p.vx *= 0.96;
|
||||
p.vy *= 0.96;
|
||||
const t = age / p.life;
|
||||
const alpha = 1 - t;
|
||||
ctx.globalAlpha = alpha;
|
||||
ctx.fillStyle = p.color;
|
||||
ctx.shadowBlur = 8;
|
||||
ctx.shadowColor = p.color;
|
||||
ctx.beginPath();
|
||||
ctx.arc(p.x, p.y, p.size * (1 - t * 0.5), 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
return true;
|
||||
});
|
||||
ctx.globalAlpha = 1;
|
||||
ctx.shadowBlur = 0;
|
||||
|
||||
rafId = requestAnimationFrame(draw);
|
||||
};
|
||||
rafId = requestAnimationFrame(draw);
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(rafId);
|
||||
ro.disconnect();
|
||||
};
|
||||
}, [initParticles]);
|
||||
|
||||
// ===== 鼠标追踪(视差)=====
|
||||
const handleMouseMove = useCallback(
|
||||
(e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
mouseRef.current = {
|
||||
x: e.clientX - rect.left,
|
||||
y: e.clientY - rect.top,
|
||||
inside: true,
|
||||
};
|
||||
},
|
||||
[]
|
||||
);
|
||||
const handleMouseLeave = useCallback(() => {
|
||||
mouseRef.current.inside = false;
|
||||
}, []);
|
||||
|
||||
// 进度比例(用于显示)
|
||||
const fillPct = Math.min(100, (crystals / Math.max(1, crystalCap)) * 100);
|
||||
|
||||
return (
|
||||
<div className="relative flex flex-col items-center justify-center gap-4 select-none">
|
||||
{/* 连击显示 */}
|
||||
{combo > 1 && (
|
||||
<div className="absolute -top-2 left-1/2 -translate-x-1/2 px-3 py-1 rounded-full bg-rose-500/20 border border-rose-400/40 text-rose-200 text-xs font-mono animate-pulse z-10">
|
||||
×{combo} 连击
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
onClick={handleClick}
|
||||
onMouseMove={handleMouseMove}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
className="relative h-52 w-52 sm:h-64 sm:w-64 rounded-full focus:outline-none group"
|
||||
aria-label="脉冲扫描,获取记忆晶体"
|
||||
>
|
||||
{/* Canvas 粒子层 */}
|
||||
<div
|
||||
ref={containerRef}
|
||||
className="absolute inset-0 rounded-full overflow-hidden"
|
||||
>
|
||||
<canvas ref={canvasRef} className="block w-full h-full" />
|
||||
</div>
|
||||
|
||||
{/* CSS 旋转外环装饰(与 Canvas 叠加)*/}
|
||||
<div
|
||||
className="absolute inset-2 rounded-full border border-emerald-400/30 pointer-events-none"
|
||||
style={{ animation: "echo-spin 18s linear infinite" }}
|
||||
>
|
||||
<div className="absolute top-0 left-1/2 -translate-x-1/2 -translate-y-1/2 h-2 w-2 rounded-full bg-emerald-300 shadow-[0_0_8px_#34d399]" />
|
||||
<div className="absolute bottom-0 left-1/2 -translate-x-1/2 translate-y-1/2 h-1.5 w-1.5 rounded-full bg-rose-300 shadow-[0_0_8px_#fb7185]" />
|
||||
</div>
|
||||
{/* 反向旋转虚线内环 */}
|
||||
<div
|
||||
className="absolute inset-6 rounded-full border border-fuchsia-400/20 border-dashed pointer-events-none"
|
||||
style={{ animation: "echo-spin 24s linear infinite reverse" }}
|
||||
/>
|
||||
|
||||
{/* 脉冲扩散环(点击时,CSS 叠加 Canvas 冲击波)*/}
|
||||
<div
|
||||
key={`ring-${pulseAnim}`}
|
||||
className="absolute inset-8 rounded-full border-2 border-emerald-400/60 pointer-events-none"
|
||||
style={{ animation: "echo-ring 0.7s ease-out forwards" }}
|
||||
/>
|
||||
|
||||
{/* 浮动数字(保留 HTML,便于清晰文字)*/}
|
||||
{floats.map((f) => (
|
||||
<span
|
||||
key={f.id}
|
||||
className="absolute pointer-events-none font-mono font-bold text-sm z-10"
|
||||
style={{
|
||||
left: f.x,
|
||||
top: f.y,
|
||||
color: f.color,
|
||||
transform: "translate(-50%, -50%)",
|
||||
animation: "echo-float 0.9s ease-out forwards",
|
||||
textShadow: `0 0 8px ${f.color}`,
|
||||
}}
|
||||
>
|
||||
{f.text}
|
||||
</span>
|
||||
))}
|
||||
</button>
|
||||
|
||||
{/* 数值显示 */}
|
||||
<div className="text-center">
|
||||
<div
|
||||
className="text-2xl font-mono font-bold text-emerald-300"
|
||||
style={{ textShadow: "0 0 12px rgba(52,211,153,0.5)" }}
|
||||
>
|
||||
{formatNum(crystals)}
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground mt-0.5">
|
||||
记忆晶体 · {crystalsPerSec.toFixed(1)}/s · 上限{" "}
|
||||
{formatNum(crystalCap)}
|
||||
</div>
|
||||
<div className="text-[11px] text-muted-foreground/70 mt-2">
|
||||
点击晶体发起
|
||||
<span className="text-emerald-300">脉冲扫描</span>,连击叠加加成
|
||||
</div>
|
||||
<div className="text-[10px] text-muted-foreground/50 mt-1 tabular-nums">
|
||||
仓库 {fillPct.toFixed(1)}% · 连击 ×{Math.max(1, combo)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style jsx>{`
|
||||
@keyframes echo-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@keyframes echo-float {
|
||||
0% {
|
||||
opacity: 1;
|
||||
transform: translate(-50%, -50%) scale(1);
|
||||
}
|
||||
100% {
|
||||
opacity: 0;
|
||||
transform: translate(-50%, -180%) scale(1.3);
|
||||
}
|
||||
}
|
||||
@keyframes echo-ring {
|
||||
0% {
|
||||
transform: scale(0.8);
|
||||
opacity: 0.8;
|
||||
}
|
||||
100% {
|
||||
transform: scale(1.6);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+445
@@ -0,0 +1,445 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 解码共振谜题(核心原创玩法)
|
||||
//
|
||||
// 谐振序列:按目标颜色顺序点击四邻接节点,重建回路。
|
||||
import { useState } from "react";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
import { COLOR_VISUAL } from "@/lib/game/config";
|
||||
import { isSolvable, canStartFrom } from "@/lib/game/decode";
|
||||
import type { DecodeNode, ResonanceColor } from "@/lib/game/types";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { RotateCcw, X, Sparkles, Check, Undo2, AlertTriangle } from "lucide-react";
|
||||
|
||||
export function DecodeArray() {
|
||||
const activePuzzle = useGameStore((s) => s.activePuzzle);
|
||||
const clickNode = useGameStore((s) => s.clickNode);
|
||||
const undoStep = useGameStore((s) => s.undoStep);
|
||||
const retryPuzzle = useGameStore((s) => s.retryPuzzle);
|
||||
const abandonPuzzle = useGameStore((s) => s.abandonPuzzle);
|
||||
const { toast } = useToast();
|
||||
|
||||
const [hoverId, setHoverId] = useState<number | null>(null);
|
||||
const [flash, setFlash] = useState<{ id: number; ok: boolean } | null>(null);
|
||||
const [warned, setWarned] = useState(false);
|
||||
|
||||
if (!activePuzzle) return null;
|
||||
|
||||
const { grid, rows, cols, target, path, stepLimit, tier } = activePuzzle;
|
||||
const currentTargetIdx = path.length;
|
||||
const currentColor: ResonanceColor | undefined = target[currentTargetIdx];
|
||||
// 当前局面是否仍可解(精确判定)
|
||||
const stuck = path.length > 0 && path.length < target.length && !isSolvable(activePuzzle);
|
||||
|
||||
const handleNodeClick = (node: DecodeNode) => {
|
||||
const res = clickNode(node.id);
|
||||
if (res.ok && res.finished) {
|
||||
setWarned(false);
|
||||
sfx("decodeSuccess");
|
||||
if (res.failReason) {
|
||||
const ids = res.failReason.split(",").filter(Boolean);
|
||||
if (ids.length) {
|
||||
sfx("fragmentUnlock");
|
||||
toast({
|
||||
title: "✦ 记忆碎片浮现",
|
||||
description: "新的回响被拼入图谱,前往「记忆图谱」查看。",
|
||||
});
|
||||
}
|
||||
}
|
||||
toast({
|
||||
title: "谐振闭合!",
|
||||
description: "晶体解码成功,记忆已释放。",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!res.ok) {
|
||||
sfx("decodeFail");
|
||||
setFlash({ id: node.id, ok: false });
|
||||
setTimeout(() => setFlash(null), 280);
|
||||
} else {
|
||||
sfx("decodeClick", { color: node.color });
|
||||
setFlash({ id: node.id, ok: true });
|
||||
setTimeout(() => setFlash(null), 280);
|
||||
// 点击后若不可解,提示玩家撤销
|
||||
if (res.solvable === false && !warned) {
|
||||
setWarned(true);
|
||||
toast({
|
||||
title: "谐振受阻",
|
||||
description: "此路不通,建议撤销上一步或重排。",
|
||||
});
|
||||
}
|
||||
if (res.solvable === true) setWarned(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleUndo = () => {
|
||||
undoStep();
|
||||
setWarned(false);
|
||||
setFlash(null);
|
||||
};
|
||||
|
||||
const handleRetry = () => {
|
||||
retryPuzzle();
|
||||
setWarned(false);
|
||||
setFlash(null);
|
||||
};
|
||||
|
||||
// 计算节点位置(百分比)
|
||||
const cellW = 100 / cols;
|
||||
const cellH = 100 / rows;
|
||||
|
||||
// 路径线段
|
||||
const pathNodes = path
|
||||
.map((id) => grid.find((n) => n.id === id)!)
|
||||
.filter(Boolean);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 h-full">
|
||||
{/* 目标序列 */}
|
||||
<div className="flex items-center justify-center gap-2 flex-wrap">
|
||||
<span className="text-xs text-muted-foreground mr-1">目标谐振</span>
|
||||
{target.map((c, i) => {
|
||||
const done = i < currentTargetIdx;
|
||||
const active = i === currentTargetIdx;
|
||||
const v = COLOR_VISUAL[c];
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
className={`relative h-9 w-9 rounded-full flex items-center justify-center transition-all duration-300 ${
|
||||
done ? "opacity-30 scale-90" : ""
|
||||
} ${active ? "scale-125 ring-2 ring-offset-2 ring-offset-background" : ""}`}
|
||||
style={{
|
||||
background: `radial-gradient(circle at 35% 30%, ${v.hex}, ${v.hex}aa 60%, ${v.hex}44)`,
|
||||
boxShadow: active
|
||||
? `0 0 18px ${v.glow}, 0 0 36px ${v.glow}`
|
||||
: `0 0 8px ${v.glow}`,
|
||||
["--tw-ring-color" as string]: v.hex,
|
||||
}}
|
||||
>
|
||||
{done && <Check className="h-4 w-4 text-white" />}
|
||||
{active && (
|
||||
<span
|
||||
className="absolute -bottom-5 text-[10px] font-medium"
|
||||
style={{ color: v.hex }}
|
||||
>
|
||||
下一个
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* 节点阵列 */}
|
||||
<div className="relative flex-1 min-h-[260px] rounded-2xl border border-white/10 bg-black/30 backdrop-blur-sm overflow-hidden">
|
||||
{/* 背景网格线 */}
|
||||
<div
|
||||
className="absolute inset-0 opacity-20"
|
||||
style={{
|
||||
backgroundImage:
|
||||
"linear-gradient(rgba(255,255,255,0.08) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.08) 1px, transparent 1px)",
|
||||
backgroundSize: `${cellW}% ${cellH}%`,
|
||||
}}
|
||||
/>
|
||||
{/* 路径线 SVG */}
|
||||
<svg className="absolute inset-0 w-full h-full pointer-events-none">
|
||||
{pathNodes.map((n, i) => {
|
||||
if (i === 0) return null;
|
||||
const prev = pathNodes[i - 1];
|
||||
const x1 = (prev.col + 0.5) * cellW;
|
||||
const y1 = (prev.row + 0.5) * cellH;
|
||||
const x2 = (n.col + 0.5) * cellW;
|
||||
const y2 = (n.row + 0.5) * cellH;
|
||||
const v = COLOR_VISUAL[n.color];
|
||||
return (
|
||||
<line
|
||||
key={i}
|
||||
x1={`${x1}%`}
|
||||
y1={`${y1}%`}
|
||||
x2={`${x2}%`}
|
||||
y2={`${y2}%`}
|
||||
stroke={v.hex}
|
||||
strokeWidth={2.5}
|
||||
strokeLinecap="round"
|
||||
style={{ filter: `drop-shadow(0 0 4px ${v.glow})` }}
|
||||
className="echo-path-line"
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</svg>
|
||||
|
||||
{/* 节点 */}
|
||||
{grid.map((node) => {
|
||||
const v = COLOR_VISUAL[node.color];
|
||||
const used = node.used;
|
||||
const isCurrentTarget =
|
||||
currentColor !== undefined && node.color === currentColor && !used;
|
||||
// 选起点阶段:标记「可行起点」(选了之后仍可解),避免玩家踩死起点
|
||||
const isViableStart =
|
||||
path.length === 0 && isCurrentTarget && canStartFrom(activePuzzle, node.id);
|
||||
// 选起点阶段:是目标色但选了会死局的起点(淡化提示)
|
||||
const isDeadStart =
|
||||
path.length === 0 && isCurrentTarget && !isViableStart;
|
||||
const isHover = hoverId === node.id;
|
||||
const isFlash = flash?.id === node.id;
|
||||
const cx = (node.col + 0.5) * cellW;
|
||||
const cy = (node.row + 0.5) * cellH;
|
||||
return (
|
||||
<button
|
||||
key={node.id}
|
||||
onClick={() => handleNodeClick(node)}
|
||||
onMouseEnter={() => setHoverId(node.id)}
|
||||
onMouseLeave={() => setHoverId(null)}
|
||||
disabled={used}
|
||||
className="absolute rounded-full transition-[box-shadow,background,border,opacity] duration-200 focus:outline-none disabled:cursor-not-allowed"
|
||||
style={{
|
||||
left: `${cx}%`,
|
||||
top: `${cy}%`,
|
||||
width: `min(${(100 / cols) * 0.62}%, 56px)`,
|
||||
aspectRatio: "1",
|
||||
background: used
|
||||
? "rgba(255,255,255,0.04)"
|
||||
: `radial-gradient(circle at 35% 30%, ${v.hex}, ${v.hex}cc 55%, ${v.hex}55)`,
|
||||
boxShadow: used
|
||||
? "inset 0 0 12px rgba(0,0,0,0.5)"
|
||||
: isViableStart
|
||||
? `0 0 16px ${v.glow}, 0 0 32px ${v.glow}, inset 0 0 10px rgba(255,255,255,0.5)`
|
||||
: isCurrentTarget
|
||||
? `0 0 10px ${v.glow}, 0 0 20px ${v.glow}, inset 0 0 6px rgba(255,255,255,0.3)`
|
||||
: `0 0 6px ${v.glow}`,
|
||||
border: isViableStart
|
||||
? `2px solid ${v.hex}`
|
||||
: isCurrentTarget
|
||||
? `1.5px solid ${v.hex}aa`
|
||||
: "1px solid rgba(255,255,255,0.12)",
|
||||
opacity: used ? 0.35 : isDeadStart ? 0.5 : 1,
|
||||
// 统一用 inline transform 定位居中 + 缩放,避免与 Tailwind translate 冲突导致左上偏移
|
||||
transform: `translate(-50%, -50%) scale(${
|
||||
isHover && !used ? 1.12 : isFlash ? (flash?.ok ? 1.25 : 0.8) : 1
|
||||
})`,
|
||||
animation: isViableStart
|
||||
? "echo-pulse 1.2s ease-in-out infinite"
|
||||
: isCurrentTarget && !isDeadStart
|
||||
? "echo-pulse 1.6s ease-in-out infinite"
|
||||
: undefined,
|
||||
}}
|
||||
aria-label={`${v.label}色节点 ${node.row + 1}-${node.col + 1}`}
|
||||
>
|
||||
{!used && (
|
||||
<span
|
||||
className="absolute inset-0 rounded-full"
|
||||
style={{
|
||||
background:
|
||||
"radial-gradient(circle at 35% 30%, rgba(255,255,255,0.5), transparent 45%)",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* 卡死提示横幅 */}
|
||||
{stuck && (
|
||||
<div className="flex items-center gap-2 px-3 py-2 rounded-lg border border-rose-400/40 bg-rose-950/40 text-rose-200 text-xs animate-pulse">
|
||||
<AlertTriangle className="h-3.5 w-3.5 shrink-0" />
|
||||
<span>谐振受阻,此路已无解。</span>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={handleUndo}
|
||||
className="h-6 px-2 ml-auto border-rose-400/50 text-rose-100 hover:bg-rose-500/20 text-[11px]"
|
||||
>
|
||||
<Undo2 className="h-3 w-3 mr-1" />
|
||||
撤销
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 底栏:步数 + 操作 */}
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2 text-xs">
|
||||
<span className="text-muted-foreground">步数</span>
|
||||
<span
|
||||
className={`font-mono font-semibold ${
|
||||
path.length >= stepLimit ? "text-rose-400" : "text-foreground"
|
||||
}`}
|
||||
>
|
||||
{path.length} / {stepLimit}
|
||||
</span>
|
||||
<span className="ml-2 text-muted-foreground">T{tier}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleUndo}
|
||||
disabled={path.length === 0}
|
||||
className="h-7"
|
||||
>
|
||||
<Undo2 className="h-3.5 w-3.5 mr-1" />
|
||||
撤销
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleRetry}
|
||||
className="h-7"
|
||||
>
|
||||
<RotateCcw className="h-3.5 w-3.5 mr-1" />
|
||||
重排
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
abandonPuzzle();
|
||||
setFlash(null);
|
||||
setWarned(false);
|
||||
}}
|
||||
className="h-7"
|
||||
>
|
||||
<X className="h-3.5 w-3.5 mr-1" />
|
||||
放回
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 规则提示 */}
|
||||
<p className="text-[11px] text-muted-foreground/80 text-center leading-relaxed">
|
||||
{path.length === 0
|
||||
? <>点击<span className="text-emerald-300">高亮</span>的可行起点开始,按目标顺序走<span className="text-emerald-300">相邻同色</span>节点;走错可<span className="text-rose-300">撤销</span>。</>
|
||||
: <>按「目标谐振」顺序,点击<span className="text-emerald-300">上下左右相邻</span>的同色节点。每个节点仅可使用一次;走错可<span className="text-rose-300">撤销</span>。</>}
|
||||
</p>
|
||||
|
||||
<style jsx global>{`
|
||||
@keyframes echo-pulse {
|
||||
0%, 100% { filter: brightness(1); }
|
||||
50% { filter: brightness(1.4); }
|
||||
}
|
||||
@keyframes echo-line {
|
||||
from { stroke-dashoffset: 100; }
|
||||
to { stroke-dashoffset: 0; }
|
||||
}
|
||||
.echo-path-line {
|
||||
stroke-dasharray: 100;
|
||||
animation: echo-line 0.4s ease-out forwards;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 解码面板的容器(带标题) */
|
||||
export function DecodePanel() {
|
||||
const activePuzzle = useGameStore((s) => s.activePuzzle);
|
||||
const pendingCrystals = useGameStore((s) => s.pendingCrystals);
|
||||
const startDecode = useGameStore((s) => s.startDecode);
|
||||
const crystalsPerSec = useGameStore((s) => s.crystalsPerSec);
|
||||
const crystalCap = useGameStore((s) => s.crystalCap);
|
||||
const crystals = useGameStore((s) => s.crystals);
|
||||
|
||||
if (activePuzzle) {
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Sparkles className="h-4 w-4 text-rose-400" />
|
||||
<h3 className="text-sm font-semibold">解码共振阵列</h3>
|
||||
</div>
|
||||
<div className="flex-1 min-h-0">
|
||||
<DecodeArray />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 无活跃谜题:展示待解码晶体队列
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Sparkles className="h-4 w-4 text-rose-400" />
|
||||
<h3 className="text-sm font-semibold">待解码晶体</h3>
|
||||
<span className="text-xs text-muted-foreground ml-auto">
|
||||
产能 {crystalsPerSec.toFixed(1)}/s · {Math.floor(crystals)}/{Math.floor(crystalCap)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{pendingCrystals.length === 0 ? (
|
||||
<div className="flex-1 flex flex-col items-center justify-center text-center gap-3 rounded-2xl border border-dashed border-white/10 bg-black/20 p-6">
|
||||
<div className="relative h-16 w-16">
|
||||
<div className="absolute inset-0 rounded-full bg-rose-500/20 blur-xl animate-pulse" />
|
||||
<div className="absolute inset-2 rounded-full border-2 border-rose-400/40 rotate-45" />
|
||||
<div className="absolute inset-4 rounded-full bg-rose-500/30" />
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
晶体正在生成中…
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground/70 max-w-[220px]">
|
||||
自治无人机每数秒回收一颗记忆晶体,点击下方晶体开启解码。
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex-1 grid grid-cols-2 sm:grid-cols-3 gap-3 content-start max-h-[420px] overflow-y-auto echo-scroll pr-1">
|
||||
{pendingCrystals.map((c) => (
|
||||
<CrystalCard key={c.id} crystal={c} onClick={() => startDecode(c.id)} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<style jsx global>{`
|
||||
.echo-scroll::-webkit-scrollbar { width: 6px; }
|
||||
.echo-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
|
||||
.echo-scroll::-webkit-scrollbar-track { background: transparent; }
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CrystalCard({
|
||||
crystal,
|
||||
onClick,
|
||||
}: {
|
||||
crystal: { id: string; tier: 1 | 2 | 3; value: number };
|
||||
onClick: () => void;
|
||||
}) {
|
||||
const tierColor =
|
||||
crystal.tier === 1 ? "#34d399" : crystal.tier === 2 ? "#fbbf24" : "#e879f9";
|
||||
const tierLabel = crystal.tier === 1 ? "常见" : crystal.tier === 2 ? "稀有" : "史诗";
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className="group relative aspect-square rounded-2xl border border-white/10 bg-black/40 hover:border-white/30 transition-all duration-300 hover:scale-[1.03] focus:outline-none overflow-hidden"
|
||||
style={{ boxShadow: `inset 0 0 24px ${tierColor}22` }}
|
||||
>
|
||||
{/* 晶体图形 */}
|
||||
<div className="absolute inset-0 flex items-center justify-center">
|
||||
<div
|
||||
className="relative h-12 w-12 transition-transform duration-500 group-hover:rotate-180"
|
||||
style={{ filter: `drop-shadow(0 0 12px ${tierColor}88)` }}
|
||||
>
|
||||
<div
|
||||
className="absolute inset-0 rotate-45 rounded-md"
|
||||
style={{
|
||||
background: `linear-gradient(135deg, ${tierColor}, ${tierColor}66)`,
|
||||
border: `1px solid ${tierColor}`,
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
className="absolute inset-2 rotate-45 rounded-sm"
|
||||
style={{ background: `linear-gradient(135deg, rgba(255,255,255,0.5), transparent)` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/* 标签 */}
|
||||
<div className="absolute top-1.5 left-1.5 text-[10px] font-mono px-1.5 py-0.5 rounded bg-black/50" style={{ color: tierColor }}>
|
||||
T{crystal.tier}
|
||||
</div>
|
||||
<div className="absolute bottom-1.5 right-1.5 text-[10px] text-white/70">
|
||||
{tierLabel}
|
||||
</div>
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/60 to-transparent opacity-0 group-hover:opacity-100 transition-opacity flex items-end justify-center pb-2">
|
||||
<span className="text-[11px] font-medium text-white">解码 →</span>
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Executable
+424
@@ -0,0 +1,424 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 遗迹探险面板(v0.2 肉鸽系统,v0.9 工单修复)
|
||||
import { useState, useEffect } from "react";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
import { EXPEDITION_CONFIG, combatWinRate, computeEnergyRegenInterval } from "@/lib/game/expedition";
|
||||
import { formatNum } from "@/lib/game/config";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import {
|
||||
Swords,
|
||||
Gem,
|
||||
HelpCircle,
|
||||
Puzzle,
|
||||
Skull,
|
||||
Heart,
|
||||
Zap,
|
||||
ChevronRight,
|
||||
LogOut,
|
||||
Rocket,
|
||||
Sparkles,
|
||||
} from "lucide-react";
|
||||
import type { ExpeditionNodeType } from "@/lib/game/types";
|
||||
|
||||
const NODE_META: Record<
|
||||
ExpeditionNodeType,
|
||||
{ icon: React.ComponentType<{ className?: string }>; color: string; label: string; bg: string }
|
||||
> = {
|
||||
combat: { icon: Swords, color: "#fb7185", label: "战斗", bg: "rgba(251,113,133,0.15)" },
|
||||
treasure: { icon: Gem, color: "#fbbf24", label: "宝藏", bg: "rgba(251,191,36,0.15)" },
|
||||
choice: { icon: HelpCircle, color: "#a5f3fc", label: "抉择", bg: "rgba(165,243,252,0.15)" },
|
||||
puzzle: { icon: Puzzle, color: "#e879f9", label: "解谜", bg: "rgba(232,121,249,0.15)" },
|
||||
rest: { icon: Heart, color: "#34d399", label: "休整", bg: "rgba(52,211,153,0.15)" },
|
||||
boss: { icon: Skull, color: "#f43f5e", label: "BOSS", bg: "rgba(244,63,94,0.2)" },
|
||||
};
|
||||
|
||||
export function ExpeditionPanel() {
|
||||
const activeExpedition = useGameStore((s) => s.activeExpedition);
|
||||
const energy = useGameStore((s) => s.energy);
|
||||
const energyMax = useGameStore((s) => s.energyMax);
|
||||
const lastEnergyTick = useGameStore((s) => s.lastEnergyTick);
|
||||
const expeditionLog = useGameStore((s) => s.expeditionLog);
|
||||
const totalExpeditions = useGameStore((s) => s.totalExpeditions);
|
||||
const lastExpeditionSummary = useGameStore((s) => s.lastExpeditionSummary);
|
||||
// v0.8.1 动态能量恢复间隔(技术 + 探索力属性缩短)
|
||||
const regenIntervalSec = useGameStore((s) => computeEnergyRegenInterval(s));
|
||||
const startExpedition = useGameStore((s) => s.startExpedition);
|
||||
const resolveCurrentNode = useGameStore((s) => s.resolveCurrentNode);
|
||||
const advanceNode = useGameStore((s) => s.advanceNode);
|
||||
const abortExpedition = useGameStore((s) => s.abortExpedition);
|
||||
const dismissExpedition = useGameStore((s) => s.dismissExpedition);
|
||||
const { toast } = useToast();
|
||||
const [lastLog, setLastLog] = useState<string | null>(null);
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
// v0.9 工单修复:能量恢复实时倒计时(每秒刷新)
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setNow(Date.now()), 1000);
|
||||
return () => clearInterval(id);
|
||||
}, []);
|
||||
|
||||
// 能量恢复进度(v0.8.1 动态间隔,v0.9 实时刷新)
|
||||
const regenMs = regenIntervalSec * 1000;
|
||||
const elapsed = now - lastEnergyTick;
|
||||
const regenProgress = energy >= energyMax ? 100 : Math.min(100, (elapsed / regenMs) * 100);
|
||||
const regenBoosted = regenIntervalSec < EXPEDITION_CONFIG.energyRegenSec;
|
||||
const nextEnergyInSec = energy >= energyMax ? 0 : Math.max(0, Math.ceil((regenMs - elapsed) / 1000));
|
||||
const canStart = energy >= EXPEDITION_CONFIG.energyCost;
|
||||
|
||||
const handleStart = () => {
|
||||
const res = startExpedition();
|
||||
if (!res.ok) {
|
||||
toast({ title: "无法出发", description: res.reason, variant: "destructive" });
|
||||
} else {
|
||||
sfx("expeditionStart");
|
||||
toast({ title: "探险队出发", description: "深入遗迹,谨慎前行。" });
|
||||
setLastLog(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleResolve = () => {
|
||||
const result = resolveCurrentNode();
|
||||
if (!result) return;
|
||||
setLastLog(result.log);
|
||||
if (result.ended) {
|
||||
if (result.endReason === "victory") sfx("expeditionVictory");
|
||||
else sfx("expeditionDefeat");
|
||||
} else {
|
||||
sfx("expeditionNode");
|
||||
}
|
||||
toast({
|
||||
title: result.ended
|
||||
? result.endReason === "victory" ? "✦ 探险胜利!" : "探险失败"
|
||||
: "节点结算",
|
||||
description: result.log,
|
||||
variant: result.endReason === "defeat" ? "destructive" : "default",
|
||||
});
|
||||
};
|
||||
|
||||
const handleAdvance = () => {
|
||||
advanceNode();
|
||||
setLastLog(null);
|
||||
};
|
||||
|
||||
const handleAbort = () => {
|
||||
abortExpedition();
|
||||
toast({ title: "探险队撤退", description: "保留已获奖励,安全返回。" });
|
||||
setLastLog(null);
|
||||
};
|
||||
|
||||
// ===== 无活跃探险:展示入口 =====
|
||||
if (!activeExpedition || activeExpedition.finished) {
|
||||
// v0.9 工单修复:如果探险刚结束(finished 且有摘要),显示结算面板
|
||||
const justFinished = activeExpedition?.finished && lastExpeditionSummary &&
|
||||
Date.now() - lastExpeditionSummary.finishedAt < 60000;
|
||||
return (
|
||||
<div className="flex flex-col gap-3 h-full">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold flex items-center gap-1.5">
|
||||
<Rocket className="h-4 w-4 text-amber-400" />
|
||||
遗迹探险
|
||||
</h3>
|
||||
<span className="text-[10px] text-muted-foreground">已探索 {totalExpeditions} 次</span>
|
||||
</div>
|
||||
|
||||
{/* v0.9 工单修复:上次探险结果摘要 */}
|
||||
{lastExpeditionSummary && (
|
||||
<div
|
||||
className={`rounded-xl border p-2.5 relative overflow-hidden ${
|
||||
lastExpeditionSummary.result === "victory"
|
||||
? "border-emerald-400/40 bg-emerald-950/20"
|
||||
: lastExpeditionSummary.result === "defeat"
|
||||
? "border-rose-400/40 bg-rose-950/20"
|
||||
: "border-amber-400/30 bg-amber-950/10"
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<span className="text-[11px] font-semibold flex items-center gap-1">
|
||||
{lastExpeditionSummary.result === "victory" ? "✦ 上次探险:胜利" : lastExpeditionSummary.result === "defeat" ? "✕ 上次探险:失败" : "→ 上次探险:撤退"}
|
||||
</span>
|
||||
<span className="text-[9px] text-muted-foreground font-mono">{lastExpeditionSummary.nodeCount} 节点</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2.5 text-[10px]">
|
||||
{lastExpeditionSummary.rewards.crystals > 0 && (
|
||||
<span className="text-emerald-300">+{formatNum(lastExpeditionSummary.rewards.crystals)} 晶体</span>
|
||||
)}
|
||||
{lastExpeditionSummary.rewards.insights > 0 && (
|
||||
<span className="text-amber-300">+{lastExpeditionSummary.rewards.insights} 洞见</span>
|
||||
)}
|
||||
{lastExpeditionSummary.rewards.contact > 0 && (
|
||||
<span className="text-fuchsia-300">+{lastExpeditionSummary.rewards.contact.toFixed(1)} 接触</span>
|
||||
)}
|
||||
{lastExpeditionSummary.rewards.crystals === 0 && lastExpeditionSummary.rewards.insights === 0 && (
|
||||
<span className="text-muted-foreground/60">无奖励</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 能量条 */}
|
||||
<div className="rounded-xl border border-amber-400/20 bg-amber-950/20 p-3">
|
||||
<div className="flex items-center justify-between mb-1.5">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Zap className="h-3.5 w-3.5 text-amber-400" />
|
||||
<span className="text-xs text-amber-200">探险能量</span>
|
||||
</div>
|
||||
<span className="text-xs font-mono text-amber-100">
|
||||
{energy} / {energyMax}
|
||||
</span>
|
||||
</div>
|
||||
{energy < energyMax ? (
|
||||
<>
|
||||
<Progress
|
||||
value={regenProgress}
|
||||
className="h-1.5 bg-black/40 [&>div]:bg-gradient-to-r [&>div]:from-amber-500 [&>div]:to-yellow-300"
|
||||
/>
|
||||
<p className="text-[10px] text-muted-foreground/70 mt-1 flex items-center gap-1">
|
||||
<span>下一点能量</span>
|
||||
<span className="text-amber-300 font-mono font-semibold">{nextEnergyInSec}s</span>
|
||||
<span>后恢复</span>
|
||||
{regenBoosted && (
|
||||
<span className="text-emerald-400/80 ml-1">⚡ {regenIntervalSec.toFixed(0)}s/点 (已加速)</span>
|
||||
)}
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-[10px] text-amber-300/80 mt-0.5">能量已满,可立即出发</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 出发按钮 */}
|
||||
<div className="flex-1 flex flex-col items-center justify-center gap-3 rounded-2xl border border-dashed border-amber-400/20 bg-black/30 p-4 relative overflow-hidden">
|
||||
<div className="absolute -top-10 -right-10 h-32 w-32 rounded-full bg-amber-500/10 blur-2xl" />
|
||||
<div className="relative">
|
||||
<div className={`h-16 w-16 rounded-full bg-gradient-to-br from-amber-500/30 to-rose-500/20 flex items-center justify-center mx-auto ${canStart ? "animate-pulse" : ""}`} style={{ boxShadow: "0 0 30px rgba(251,191,36,0.3)" }}>
|
||||
<Rocket className="h-7 w-7 text-amber-300" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-center space-y-1">
|
||||
<p className="text-sm font-medium text-amber-100">深入以太遗迹</p>
|
||||
<p className="text-[11px] text-muted-foreground/80 max-w-[220px]">
|
||||
程序化生成的遗迹路径,沿途遭遇战斗、宝藏、抉择与解谜,击败终点 BOSS 获取丰厚奖励。
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleStart}
|
||||
disabled={!canStart}
|
||||
className="bg-gradient-to-r from-amber-600 to-rose-500 hover:from-amber-500 hover:to-rose-400 text-white border-0"
|
||||
>
|
||||
<Rocket className="h-4 w-4 mr-1.5" />
|
||||
{canStart ? `出发(消耗 ${EXPEDITION_CONFIG.energyCost} 能量)` : `能量不足(${nextEnergyInSec}s 后恢复)`}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 探险日志 */}
|
||||
{expeditionLog.length > 0 && (
|
||||
<div className="rounded-xl border border-white/5 bg-black/20 p-2 max-h-28 overflow-y-auto echo-scroll">
|
||||
<div className="text-[10px] text-muted-foreground/60 mb-1 px-1">最近探险记录</div>
|
||||
{expeditionLog.slice(0, 4).map((entry, i) => (
|
||||
<div key={i} className="text-[10px] text-muted-foreground/70 px-1 py-0.5 border-b border-white/5 last:border-0">
|
||||
<span className="text-amber-300/60">›</span> {entry.result}
|
||||
{entry.rewards && <span className="text-emerald-300/70 ml-1">{entry.rewards}</span>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* v0.9 工单修复:刚结束的探险,显示"返回"按钮 */}
|
||||
{justFinished && (
|
||||
<Button
|
||||
onClick={() => dismissExpedition()}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-7 text-[11px] border-amber-400/30 text-amber-200"
|
||||
>
|
||||
收起结算,准备下次出发
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 活跃探险:展示地图 + 事件 =====
|
||||
const exp = activeExpedition;
|
||||
const currentNode = exp.nodes[exp.currentNode];
|
||||
const nodeMeta = NODE_META[currentNode.type];
|
||||
const NodeIcon = nodeMeta.icon;
|
||||
const hpPct = (exp.hp / exp.maxHp) * 100;
|
||||
const pathProgress = ((exp.currentNode + (currentNode.cleared ? 1 : 0)) / exp.nodes.length) * 100;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2.5 h-full">
|
||||
{/* 头部:生命 + 路径进度 */}
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Rocket className="h-3.5 w-3.5 text-amber-400" />
|
||||
<span className="text-xs font-semibold">遗迹探险</span>
|
||||
<span className="text-[10px] text-muted-foreground">第 {exp.currentNode + 1}/{exp.nodes.length} 节点</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="text-[10px] text-muted-foreground">探险力</span>
|
||||
<span className="text-xs font-mono font-semibold text-amber-300">{exp.power}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 生命条 */}
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-0.5">
|
||||
<div className="flex items-center gap-1">
|
||||
<Heart className="h-3 w-3 text-rose-400" />
|
||||
<span className="text-[10px] text-muted-foreground">探险队生命</span>
|
||||
</div>
|
||||
<span className={`text-[10px] font-mono ${hpPct < 30 ? "text-rose-400" : "text-foreground"}`}>
|
||||
{exp.hp} / {exp.maxHp}
|
||||
</span>
|
||||
</div>
|
||||
<Progress
|
||||
value={hpPct}
|
||||
className="h-1.5 bg-black/40 [&>div]:bg-gradient-to-r [&>div]:from-rose-500 [&>div]:to-emerald-400"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 节点路径图 */}
|
||||
<div className="rounded-xl border border-white/10 bg-black/30 p-2.5">
|
||||
<div className="flex items-center gap-1 overflow-x-auto echo-scroll pb-1">
|
||||
{exp.nodes.map((node, i) => {
|
||||
const meta = NODE_META[node.type];
|
||||
const Icon = meta.icon;
|
||||
const isCurrent = i === exp.currentNode;
|
||||
const isCleared = node.cleared;
|
||||
const isPast = i < exp.currentNode;
|
||||
return (
|
||||
<div key={node.id} className="flex items-center shrink-0">
|
||||
<div
|
||||
className={`relative h-9 w-9 rounded-lg flex items-center justify-center transition-all duration-300 ${
|
||||
isCurrent ? "scale-125" : ""
|
||||
}`}
|
||||
style={{
|
||||
background: isCleared || isPast ? "rgba(255,255,255,0.04)" : meta.bg,
|
||||
border: isCurrent ? `1.5px solid ${meta.color}` : "1px solid rgba(255,255,255,0.08)",
|
||||
boxShadow: isCurrent ? `0 0 12px ${meta.color}66` : "none",
|
||||
}}
|
||||
title={`${meta.label} · ${node.title}`}
|
||||
>
|
||||
<Icon className={`h-4 w-4 ${isCleared || isPast ? "opacity-30" : ""}`} style={{ color: isCleared || isPast ? "#666" : meta.color }} />
|
||||
{isCleared && (
|
||||
<div className="absolute -top-1 -right-1 h-3 w-3 rounded-full bg-emerald-500/80 flex items-center justify-center">
|
||||
<span className="text-[8px] text-white">✓</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{i < exp.nodes.length - 1 && (
|
||||
<ChevronRight className={`h-3 w-3 mx-0.5 ${isPast || (isCurrent && isCleared) ? "text-amber-400/60" : "text-white/15"}`} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className="mt-1.5">
|
||||
<Progress value={pathProgress} className="h-1 bg-black/40 [&>div]:bg-gradient-to-r [&>div]:from-amber-500 [&>div]:to-rose-400" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 当前节点事件卡 */}
|
||||
<div
|
||||
className="rounded-xl border p-3 relative overflow-hidden"
|
||||
style={{
|
||||
borderColor: `${nodeMeta.color}44`,
|
||||
background: `linear-gradient(135deg, ${nodeMeta.color}11, rgba(0,0,0,0.4))`,
|
||||
boxShadow: `0 0 20px ${nodeMeta.color}22`,
|
||||
}}
|
||||
>
|
||||
<div className="absolute -top-8 -right-8 h-24 w-24 rounded-full blur-2xl" style={{ background: `${nodeMeta.color}22` }} />
|
||||
<div className="relative">
|
||||
<div className="flex items-center gap-2 mb-1.5">
|
||||
<div
|
||||
className="h-8 w-8 rounded-lg flex items-center justify-center"
|
||||
style={{ background: nodeMeta.bg, border: `1px solid ${nodeMeta.color}44` }}
|
||||
>
|
||||
<NodeIcon className="h-4 w-4" style={{ color: nodeMeta.color }} />
|
||||
</div>
|
||||
<div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="text-[10px] font-mono px-1.5 py-0.5 rounded" style={{ background: nodeMeta.bg, color: nodeMeta.color }}>
|
||||
{nodeMeta.label}
|
||||
</span>
|
||||
{currentNode.type === "combat" && (
|
||||
<span className="text-[10px] text-muted-foreground">
|
||||
胜率 {Math.round(combatWinRate(exp.power, currentNode.difficulty) * 100)}%
|
||||
</span>
|
||||
)}
|
||||
{currentNode.difficulty > 0 && (
|
||||
<span className="text-[10px] text-muted-foreground/60">难度 {currentNode.difficulty}</span>
|
||||
)}
|
||||
</div>
|
||||
<h4 className="text-sm font-semibold mt-0.5" style={{ color: nodeMeta.color }}>
|
||||
{currentNode.title}
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-[11px] text-muted-foreground/90 leading-relaxed">
|
||||
{currentNode.desc}
|
||||
</p>
|
||||
|
||||
{/* 上次结算结果 */}
|
||||
{lastLog && (
|
||||
<div className="mt-2 px-2 py-1.5 rounded-lg bg-black/40 border border-white/10">
|
||||
<p className="text-[11px] text-foreground/90">{lastLog}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 操作按钮 */}
|
||||
<div className="flex items-center gap-1.5">
|
||||
{!currentNode.cleared ? (
|
||||
<Button
|
||||
onClick={handleResolve}
|
||||
className="flex-1 bg-gradient-to-r from-amber-600 to-rose-500 hover:from-amber-500 hover:to-rose-400 text-white border-0 h-8"
|
||||
>
|
||||
<Sparkles className="h-3.5 w-3.5 mr-1" />
|
||||
探索节点
|
||||
</Button>
|
||||
) : exp.currentNode < exp.nodes.length - 1 ? (
|
||||
<Button
|
||||
onClick={handleAdvance}
|
||||
className="flex-1 h-8"
|
||||
variant="outline"
|
||||
>
|
||||
<ChevronRight className="h-3.5 w-3.5 mr-1" />
|
||||
前进
|
||||
</Button>
|
||||
) : (
|
||||
<div className="flex-1 text-center text-xs text-emerald-300 py-1.5">探险已完成 ✓</div>
|
||||
)}
|
||||
<Button
|
||||
onClick={handleAbort}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-8 px-2 text-muted-foreground hover:text-rose-300"
|
||||
>
|
||||
<LogOut className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 本次奖励累计 */}
|
||||
<div className="flex items-center gap-2 text-[10px] px-1">
|
||||
<span className="text-muted-foreground/60">本次已获:</span>
|
||||
{exp.rewards.crystals > 0 && <span className="text-emerald-300">{formatNum(exp.rewards.crystals)}晶体</span>}
|
||||
{exp.rewards.insights > 0 && <span className="text-amber-300">{exp.rewards.insights}洞见</span>}
|
||||
{exp.rewards.contact > 0 && <span className="text-fuchsia-300">{exp.rewards.contact.toFixed(1)}接触</span>}
|
||||
{(exp.rewards.crystals === 0 && exp.rewards.insights === 0) && (
|
||||
<span className="text-muted-foreground/40">暂无</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<style jsx global>{`
|
||||
.echo-scroll::-webkit-scrollbar { width: 4px; height: 4px; }
|
||||
.echo-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }
|
||||
.echo-scroll::-webkit-scrollbar-track { background: transparent; }
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+160
@@ -0,0 +1,160 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 离线收益报告弹窗(v0.5.2)
|
||||
import { useState, useEffect } from "react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Gem, Clock, TrendingUp, AlertCircle, Sparkles } from "lucide-react";
|
||||
import {
|
||||
getPendingOfflineReport,
|
||||
consumeOfflineReport,
|
||||
formatDuration,
|
||||
type OfflineReport,
|
||||
} from "@/lib/game/offlineReport";
|
||||
import { formatNum } from "@/lib/game/config";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
|
||||
export function OfflineReportDialog() {
|
||||
const [report, setReport] = useState<OfflineReport | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// 启动时检查是否有待处理报告
|
||||
const check = () => {
|
||||
const r = getPendingOfflineReport();
|
||||
if (r && r.gain > 0.1) {
|
||||
setReport(r);
|
||||
// 延迟播放音效,避免与初始化冲突
|
||||
setTimeout(() => sfx("decodeSuccess"), 300);
|
||||
} else if (r) {
|
||||
// 收益太小直接消费掉不弹窗
|
||||
consumeOfflineReport();
|
||||
}
|
||||
};
|
||||
// 等游戏 mount + init 完成(init 现在等 persist rehydrate,可能稍晚)
|
||||
const t = setTimeout(check, 1500);
|
||||
const handler = () => check();
|
||||
window.addEventListener("echo-nexus-offline-report", handler);
|
||||
return () => {
|
||||
clearTimeout(t);
|
||||
window.removeEventListener("echo-nexus-offline-report", handler);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const close = () => {
|
||||
consumeOfflineReport();
|
||||
setReport(null);
|
||||
};
|
||||
|
||||
if (!report) return null;
|
||||
|
||||
const cappedAtWarehouse = report.gain < report.rate * report.elapsedSec * report.eff - 0.01;
|
||||
|
||||
return (
|
||||
<Dialog open={!!report} onOpenChange={(v) => !v && close()}>
|
||||
<DialogContent className="bg-gradient-to-br from-[#0f0a2e]/95 to-[#050410]/95 border-emerald-400/30 max-w-[400px]">
|
||||
<DialogHeader>
|
||||
{/* 顶部装饰条 */}
|
||||
<div className="absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-emerald-400 via-cyan-400 to-blue-400 rounded-t-xl" />
|
||||
<DialogTitle className="flex items-center gap-2 text-emerald-100">
|
||||
<Sparkles className="h-4 w-4 text-emerald-300" />
|
||||
欢迎回来,无人机
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-muted-foreground">
|
||||
在你离开的这段时间里,采矿机群持续运转…
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-3 py-1">
|
||||
{/* 主要收益 */}
|
||||
<div className="relative rounded-xl border border-emerald-400/30 bg-emerald-500/5 p-4 overflow-hidden">
|
||||
{/* 背景光晕 */}
|
||||
<div className="pointer-events-none absolute -top-8 -right-8 h-24 w-24 rounded-full bg-emerald-500/20 blur-2xl" />
|
||||
<div className="relative flex items-center gap-3">
|
||||
<div className="h-12 w-12 rounded-xl bg-emerald-500/15 border border-emerald-400/40 flex items-center justify-center shrink-0">
|
||||
<Gem className="h-6 w-6 text-emerald-300" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-[11px] text-muted-foreground">离线采集获得</div>
|
||||
<div className="text-2xl font-bold font-mono text-emerald-200 tabular-nums leading-tight">
|
||||
+{formatNum(report.gain)}
|
||||
</div>
|
||||
<div className="text-[10px] text-muted-foreground/80">记忆晶体</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 详细统计 */}
|
||||
<div className="grid grid-cols-2 gap-2 text-xs">
|
||||
<div className="rounded-lg border border-white/10 bg-black/30 px-3 py-2">
|
||||
<div className="flex items-center gap-1.5 text-muted-foreground mb-1">
|
||||
<Clock className="h-3 w-3" />
|
||||
离线时长
|
||||
</div>
|
||||
<div className="font-mono font-semibold text-foreground">
|
||||
{formatDuration(report.rawElapsedSec)}
|
||||
</div>
|
||||
{report.capped && (
|
||||
<div className="text-[9px] text-amber-400/80 mt-0.5">已达 8h 上限</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="rounded-lg border border-white/10 bg-black/30 px-3 py-2">
|
||||
<div className="flex items-center gap-1.5 text-muted-foreground mb-1">
|
||||
<TrendingUp className="h-3 w-3" />
|
||||
采集速率
|
||||
</div>
|
||||
<div className="font-mono font-semibold text-foreground">
|
||||
{formatNum(report.rate)}/s
|
||||
</div>
|
||||
<div className="text-[9px] text-muted-foreground/70 mt-0.5">
|
||||
效率 {Math.round(report.eff * 100)}%
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 仓库满仓警告 */}
|
||||
{cappedAtWarehouse && (
|
||||
<div className="flex items-start gap-2 rounded-lg border border-amber-400/30 bg-amber-500/5 px-3 py-2 text-[11px] text-amber-200">
|
||||
<AlertCircle className="h-3.5 w-3.5 shrink-0 mt-0.5" />
|
||||
<span>
|
||||
仓库已满,部分离线产出被截断。升级仓库容量或解码晶体可避免浪费。
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 当前进度 */}
|
||||
<div className="rounded-lg border border-white/10 bg-black/20 px-3 py-2">
|
||||
<div className="flex items-center justify-between text-[11px]">
|
||||
<span className="text-muted-foreground">当前晶体</span>
|
||||
<span className="font-mono text-foreground tabular-nums">
|
||||
{formatNum(report.crystalsAfter)} / {formatNum(report.crystalCap)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-1.5 h-1.5 rounded-full bg-white/10 overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-gradient-to-r from-emerald-500 to-cyan-400 transition-all"
|
||||
style={{
|
||||
width: `${Math.min(100, (report.crystalsAfter / report.crystalCap) * 100)}%`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 mt-1">
|
||||
<Button
|
||||
onClick={close}
|
||||
className="bg-emerald-500 hover:bg-emerald-600 text-white border-emerald-400/50"
|
||||
>
|
||||
<Gem className="h-3.5 w-3.5 mr-1" />
|
||||
领取收益
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Executable
+189
@@ -0,0 +1,189 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 飞升(Prestige)对话框
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { RotateCcw, Sparkles, Star, BookOpen } from "lucide-react";
|
||||
import { PRESTIGE } from "@/lib/game/config";
|
||||
import { computeNewBlueprints, computePrestigeBonus } from "@/lib/game/engine";
|
||||
import { constellationProgress } from "@/lib/game/constellation";
|
||||
import { useState } from "react";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
|
||||
export function PrestigeDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
}) {
|
||||
const state = useGameStore();
|
||||
const doPrestige = useGameStore((s) => s.doPrestige);
|
||||
const { toast } = useToast();
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const [canReconfirm, setCanReconfirm] = useState(false);
|
||||
|
||||
const newBp = computeNewBlueprints(state);
|
||||
const bonus = computePrestigeBonus(state);
|
||||
const totalBpAfter = Math.min(PRESTIGE.maxBlueprints, state.blueprints.length + newBp);
|
||||
const cProgress = constellationProgress(state.constellation ?? []);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="bg-gradient-to-br from-fuchsia-950/70 to-black/90 border-fuchsia-400/40">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2 text-fuchsia-100">
|
||||
<RotateCcw className="h-5 w-5" />
|
||||
飞升 · 跨越维度
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-fuchsia-200/70">
|
||||
当接触进度满溢,你将跨越维度与以太族相会。本次飞升将重置资源与技术,但保留记忆图谱与蓝图加成。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-3 py-2">
|
||||
{/* 本次飞升获得 */}
|
||||
<div className="rounded-lg border border-fuchsia-400/30 bg-fuchsia-950/30 p-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm text-fuchsia-200">本次获得蓝图</span>
|
||||
<span className="text-2xl font-mono font-bold text-fuchsia-100">
|
||||
+{newBp}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-[11px] text-muted-foreground mt-1">
|
||||
蓝图总数将达 {totalBpAfter}/{PRESTIGE.maxBlueprints}(每 {PRESTIGE.blueprintsPerDecode} 次解码产出 1 张)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* 永久加成 */}
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
<BonusCard
|
||||
label="产能"
|
||||
value={`+${(totalBpAfter * PRESTIGE.perBlueprint.crystalsPerSecMult * 100).toFixed(0)}%`}
|
||||
color="#34d399"
|
||||
/>
|
||||
<BonusCard
|
||||
label="洞见"
|
||||
value={`+${(totalBpAfter * PRESTIGE.perBlueprint.insightMult * 100).toFixed(0)}%`}
|
||||
color="#fbbf24"
|
||||
/>
|
||||
<BonusCard
|
||||
label="接触"
|
||||
value={`+${(totalBpAfter * PRESTIGE.perBlueprint.contactRateMult * 100).toFixed(0)}%`}
|
||||
color="#e879f9"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 保留 / 重置 */}
|
||||
<div className="text-[11px] text-muted-foreground space-y-1 pt-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Sparkles className="h-3 w-3 text-fuchsia-400" />
|
||||
保留:记忆图谱、累计解码数、飞升次数、蓝图、星图天赋
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<RotateCcw className="h-3 w-3 text-rose-400" />
|
||||
重置:晶体、洞见、技术树、接触进度、待解码晶体
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 星图觉醒预告 */}
|
||||
<div className="rounded-lg border border-fuchsia-400/30 bg-gradient-to-r from-fuchsia-950/40 to-purple-950/40 p-2.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<Star className="h-4 w-4 text-fuchsia-300" />
|
||||
<div className="flex-1">
|
||||
<div className="text-[12px] text-fuchsia-200 font-bold">星图觉醒预告</div>
|
||||
<div className="text-[10px] text-muted-foreground">
|
||||
飞升后将从 3 道随机天赋中选 1,永久获得加成
|
||||
{cProgress.unlocked < cProgress.total && (
|
||||
<span className="text-fuchsia-300/80"> · 当前 {cProgress.unlocked}/{cProgress.total}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-[10px] text-fuchsia-300/70 font-mono">
|
||||
{cProgress.unlocked < cProgress.total ? "✦ 可觉醒" : "✧ 已圆满"}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 编年史铭刻提示(v0.4 新增) */}
|
||||
<div className="rounded-lg border border-violet-400/25 bg-violet-950/20 p-2.5 flex items-center gap-2">
|
||||
<BookOpen className="h-4 w-4 text-violet-300 flex-shrink-0" />
|
||||
<div className="flex-1 text-[10px] text-violet-100/70 leading-relaxed">
|
||||
本次飞升将铭刻入<span className="text-violet-200 font-bold">回响编年史</span>,
|
||||
记录本周目的解码、探险、星潮与觉醒天赋,形成永恒叙事时间轴。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="ghost" onClick={() => onOpenChange(false)}>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
disabled={confirming && !canReconfirm}
|
||||
onClick={() => {
|
||||
if (!confirming) {
|
||||
setConfirming(true);
|
||||
setCanReconfirm(false);
|
||||
window.setTimeout(() => setCanReconfirm(true), 900);
|
||||
return;
|
||||
}
|
||||
const res = doPrestige();
|
||||
onOpenChange(false);
|
||||
setConfirming(false);
|
||||
setCanReconfirm(false);
|
||||
if (res) {
|
||||
sfx("prestige");
|
||||
// 编年史铭刻音效(稍延迟,与飞升音分层)
|
||||
window.setTimeout(() => sfx("chronicle"), 600);
|
||||
toast({
|
||||
title: "✦ 飞升成功",
|
||||
description: `获得 ${res.newBp} 张蓝图,进入第 ${state.ascensions + 2} 周目。编年史已铭刻新纪元。`,
|
||||
});
|
||||
}
|
||||
}}
|
||||
className="bg-gradient-to-r from-fuchsia-600 to-rose-500 hover:from-fuchsia-500 hover:to-rose-400 text-white border-0"
|
||||
>
|
||||
{confirming
|
||||
? canReconfirm
|
||||
? "再次确认飞升"
|
||||
: "请确认…"
|
||||
: newBp <= 0
|
||||
? "飞升(无新蓝图)"
|
||||
: "飞升"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function BonusCard({
|
||||
label,
|
||||
value,
|
||||
color,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
color: string;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className="rounded-lg border p-2 text-center"
|
||||
style={{ borderColor: `${color}44`, background: `${color}11` }}
|
||||
>
|
||||
<div className="text-[10px] text-muted-foreground">{label}</div>
|
||||
<div className="text-sm font-mono font-bold" style={{ color }}>
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+101
@@ -0,0 +1,101 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 顶栏资源栏
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import { formatNum, PRESTIGE } from "@/lib/game/config";
|
||||
import { Gem, Lightbulb, Waves, RotateCcw } from "lucide-react";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
|
||||
export function ResourceBar({ onPrestige }: { onPrestige: () => void }) {
|
||||
const crystals = useGameStore((s) => s.crystals);
|
||||
const crystalsPerSec = useGameStore((s) => s.crystalsPerSec);
|
||||
const insights = useGameStore((s) => s.insights);
|
||||
const contact = useGameStore((s) => s.contact);
|
||||
const ascensions = useGameStore((s) => s.ascensions);
|
||||
const blueprints = useGameStore((s) => s.blueprints);
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-2 sm:gap-x-4 px-3.5 py-2.5 rounded-2xl border border-white/10 bg-black/40 backdrop-blur-md">
|
||||
{/* 晶体 */}
|
||||
<Stat
|
||||
icon={<Gem className="h-4 w-4 text-emerald-400" />}
|
||||
label="记忆晶体"
|
||||
value={formatNum(crystals)}
|
||||
sub={`+${crystalsPerSec.toFixed(1)}/s`}
|
||||
glow="rgba(52,211,153,0.4)"
|
||||
/>
|
||||
<div className="h-9 w-px bg-gradient-to-b from-transparent via-white/15 to-transparent hidden sm:block" />
|
||||
{/* 洞见 */}
|
||||
<Stat
|
||||
icon={<Lightbulb className="h-4 w-4 text-amber-400" />}
|
||||
label="技术洞见"
|
||||
value={formatNum(insights)}
|
||||
sub="解码产出"
|
||||
glow="rgba(251,191,36,0.4)"
|
||||
/>
|
||||
<div className="h-9 w-px bg-gradient-to-b from-transparent via-white/15 to-transparent hidden sm:block" />
|
||||
{/* 接触进度 */}
|
||||
<div className="flex-1 min-w-[200px] flex flex-col gap-1.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<Waves className="h-4 w-4 text-fuchsia-400 shrink-0" />
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">接触进度</span>
|
||||
<span className="text-xs font-mono font-semibold text-fuchsia-300 ml-auto tabular-nums">
|
||||
{contact.toFixed(1)}%
|
||||
</span>
|
||||
{contact >= 100 && (
|
||||
<button
|
||||
onClick={onPrestige}
|
||||
className="text-[10px] px-2 py-0.5 rounded-full bg-fuchsia-500/20 border border-fuchsia-400/50 text-fuchsia-200 hover:bg-fuchsia-500/30 transition animate-pulse whitespace-nowrap ml-1"
|
||||
>
|
||||
飞升
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<Progress
|
||||
value={contact}
|
||||
className="h-1.5 bg-white/10 [&>div]:bg-gradient-to-r [&>div]:from-fuchsia-500 [&>div]:to-rose-400"
|
||||
/>
|
||||
</div>
|
||||
<div className="h-9 w-px bg-gradient-to-b from-transparent via-white/15 to-transparent hidden sm:block" />
|
||||
{/* 飞升 */}
|
||||
<div className="flex items-center gap-2.5">
|
||||
<RotateCcw className="h-4 w-4 text-rose-400 shrink-0" />
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<span className="text-[10px] text-muted-foreground leading-none">飞升</span>
|
||||
<div className="flex items-baseline gap-1.5">
|
||||
<span className="text-sm font-mono font-semibold leading-none">
|
||||
{ascensions}
|
||||
</span>
|
||||
<span className="text-amber-300 text-xs leading-none">×{blueprints.length}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Stat({
|
||||
icon,
|
||||
label,
|
||||
value,
|
||||
sub,
|
||||
glow,
|
||||
}: {
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
value: string;
|
||||
sub: string;
|
||||
glow: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex items-center gap-2.5" style={{ filter: `drop-shadow(0 0 6px ${glow})` }}>
|
||||
{icon}
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<span className="text-[10px] text-muted-foreground leading-none">{label}</span>
|
||||
<div className="flex items-baseline gap-1.5">
|
||||
<span className="text-sm font-mono font-semibold leading-none tabular-nums">{value}</span>
|
||||
<span className="text-[10px] text-muted-foreground/80 whitespace-nowrap">{sub}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+165
@@ -0,0 +1,165 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 设置对话框
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Trash2, Github, AlertTriangle, Volume2, GraduationCap, ExternalLink } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
import { restartTutorial } from "@/lib/game/tutorial";
|
||||
|
||||
export function SettingsDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
}) {
|
||||
const soundOn = useGameStore((s) => s.soundOn);
|
||||
const toggleSound = useGameStore((s) => s.toggleSound);
|
||||
const hardReset = useGameStore((s) => s.hardReset);
|
||||
const ascensions = useGameStore((s) => s.ascensions);
|
||||
const totalDecoded = useGameStore((s) => s.totalDecoded);
|
||||
const { toast } = useToast();
|
||||
const [confirmReset, setConfirmReset] = useState(false);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="bg-gradient-to-br from-slate-900/80 to-black/90 border-white/15">
|
||||
<DialogHeader>
|
||||
<DialogTitle>设置</DialogTitle>
|
||||
<DialogDescription>游戏偏好与存档管理</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4 py-2">
|
||||
{/* 音效 */}
|
||||
<div className="flex items-center justify-between rounded-lg border border-white/10 bg-black/30 p-3">
|
||||
<div>
|
||||
<Label className="text-sm">音效反馈</Label>
|
||||
<p className="text-[11px] text-muted-foreground mt-0.5">
|
||||
脉冲、解码、探险、飞升等程序化音效
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 px-2 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => sfx("decodeSuccess")}
|
||||
aria-label="试听音效"
|
||||
>
|
||||
<Volume2 className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Switch checked={soundOn} onCheckedChange={toggleSound} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 教程 */}
|
||||
<div className="flex items-center justify-between rounded-lg border border-white/10 bg-black/30 p-3">
|
||||
<div>
|
||||
<Label className="text-sm">新手教程</Label>
|
||||
<p className="text-[11px] text-muted-foreground mt-0.5">
|
||||
重新查看 5 步玩法引导
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-7 px-2 text-[11px] border-fuchsia-400/40 text-fuchsia-200 hover:bg-fuchsia-500/10"
|
||||
onClick={() => {
|
||||
restartTutorial();
|
||||
onOpenChange(false);
|
||||
}}
|
||||
>
|
||||
<GraduationCap className="h-3.5 w-3.5 mr-1" />
|
||||
重看教程
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 存档信息 */}
|
||||
<div className="rounded-lg border border-white/10 bg-black/30 p-3 text-xs space-y-1.5">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">累计解码</span>
|
||||
<span className="font-mono">{totalDecoded} 颗</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">飞升周目</span>
|
||||
<span className="font-mono">{ascensions}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">存档位置</span>
|
||||
<span className="font-mono text-[10px]">浏览器本地</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 危险操作 */}
|
||||
<div className="rounded-lg border border-rose-500/30 bg-rose-950/20 p-3">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<AlertTriangle className="h-4 w-4 text-rose-400" />
|
||||
<span className="text-sm font-medium text-rose-200">危险操作</span>
|
||||
</div>
|
||||
<p className="text-[11px] text-muted-foreground mb-2">
|
||||
清空所有进度,包括记忆图谱与飞升记录,不可恢复。
|
||||
</p>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="border-rose-500/40 text-rose-300 hover:bg-rose-500/10"
|
||||
onClick={() => {
|
||||
if (!confirmReset) {
|
||||
setConfirmReset(true);
|
||||
return;
|
||||
}
|
||||
hardReset();
|
||||
setConfirmReset(false);
|
||||
onOpenChange(false);
|
||||
toast({ title: "存档已清空", description: "一切归零,重新开始。" });
|
||||
}}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5 mr-1" />
|
||||
{confirmReset ? "再次点击确认清空" : "清空存档"}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 仓库链接 + 在线游玩 */}
|
||||
<div className="space-y-1.5">
|
||||
<a
|
||||
href="https://gitea-pages.atdunbg.xyz/Super_Z/echo-nexus/"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex items-center gap-2 text-xs text-emerald-300/80 hover:text-emerald-200 transition px-1 py-1 rounded hover:bg-emerald-500/5"
|
||||
>
|
||||
<ExternalLink className="h-3.5 w-3.5" />
|
||||
在线游玩(gitea-pages)
|
||||
</a>
|
||||
<a
|
||||
href="https://git.atdunbg.xyz/Super_Z/echo-nexus"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground transition px-1 py-1 rounded hover:bg-white/5"
|
||||
>
|
||||
<Github className="h-3.5 w-3.5" />
|
||||
git.atdunbg.xyz/Super_Z/echo-nexus
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="ghost" onClick={() => onOpenChange(false)}>
|
||||
关闭
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Executable
+170
@@ -0,0 +1,170 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 星潮事件 UI(横幅 + 通知 + 背景叠层)
|
||||
import { useEffect, useState } from "react";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
import { TIDE_EVENTS, TIDE_CONFIG } from "@/lib/game/starTide";
|
||||
|
||||
/** 星潮事件通知消费者:监听 _tideEvents 队列,弹 Toast + 播音效 */
|
||||
export function StarTideNotifier() {
|
||||
const events = useGameStore((s) => s._tideEvents);
|
||||
const consume = useGameStore((s) => s.consumeTideEvents);
|
||||
const { toast } = useToast();
|
||||
|
||||
useEffect(() => {
|
||||
if (events.length === 0) return;
|
||||
const items = consume();
|
||||
for (const ev of items) {
|
||||
const globalTag = ev.isGlobal ? "🌐 " : "";
|
||||
if (ev.started) {
|
||||
const meta = TIDE_EVENTS[ev.started];
|
||||
sfx("tideStart");
|
||||
toast({
|
||||
title: `${globalTag}${meta.icon} ${ev.isGlobal ? "全球星潮" : "星潮降临"}:${meta.name}`,
|
||||
description: ev.isGlobal
|
||||
? `全球玩家同步经历 · ${meta.desc}`
|
||||
: meta.desc,
|
||||
});
|
||||
}
|
||||
if (ev.ended) {
|
||||
const meta = TIDE_EVENTS[ev.ended];
|
||||
if (ev.silenceCompensation && ev.silenceCompensation > 0) {
|
||||
sfx("techBuy");
|
||||
toast({
|
||||
title: `${globalTag}${meta.icon} 寂静期消散`,
|
||||
description: `虚空回赠 ${ev.silenceCompensation} 洞见。`,
|
||||
});
|
||||
} else {
|
||||
sfx("tideEnd");
|
||||
toast({
|
||||
title: `${globalTag}${meta.icon} ${meta.name}结束`,
|
||||
description: ev.isGlobal
|
||||
? "全球星潮退去,物理法则恢复。"
|
||||
: "星潮退去,物理法则恢复。",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [events, consume, toast]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 顶部星潮指示器(活跃时显示倒计时芯片) */
|
||||
export function StarTideIndicator() {
|
||||
const activeTide = useGameStore((s) => s.activeTide);
|
||||
const globalTide = useGameStore((s) => s.globalTide);
|
||||
const [, force] = useState(0);
|
||||
|
||||
// 每秒刷新倒计时
|
||||
useEffect(() => {
|
||||
if (!activeTide) return;
|
||||
const id = setInterval(() => force((n) => n + 1), 500);
|
||||
return () => clearInterval(id);
|
||||
}, [activeTide]);
|
||||
|
||||
if (!activeTide) return null;
|
||||
const meta = TIDE_EVENTS[activeTide.type];
|
||||
const remaining = Math.max(0, activeTide.endsAt - Date.now());
|
||||
const secs = Math.ceil(remaining / 1000);
|
||||
// 全球星潮持续 60s,本地 75s —— 用实际 endsAt-startedAt 计算 progress,避免越界
|
||||
const duration = globalTide
|
||||
? globalTide.endsAt - globalTide.startedAt
|
||||
: TIDE_CONFIG.duration;
|
||||
const progress = Math.min(1, Math.max(0, 1 - remaining / duration));
|
||||
const isGlobal = !!globalTide;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`flex items-center gap-1.5 px-2 py-1 rounded-full text-[10px] font-medium relative overflow-hidden ${
|
||||
isGlobal ? "ring-1 ring-amber-300/60" : ""
|
||||
}`}
|
||||
style={{
|
||||
background: isGlobal
|
||||
? `linear-gradient(135deg, ${meta.color}26, ${meta.color}11)`
|
||||
: `${meta.color}1a`,
|
||||
border: `1px solid ${meta.color}${isGlobal ? "88" : "55"}`,
|
||||
color: meta.color,
|
||||
boxShadow: `0 0 ${isGlobal ? "16" : "10"}px ${meta.glow}`,
|
||||
}}
|
||||
title={isGlobal ? `🌐 全球星潮 · ${meta.desc}` : meta.desc}
|
||||
>
|
||||
{/* 进度环背景 */}
|
||||
<div
|
||||
className="absolute inset-0 opacity-20"
|
||||
style={{
|
||||
background: `linear-gradient(90deg, ${meta.color}40 ${progress * 100}%, transparent ${progress * 100}%)`,
|
||||
}}
|
||||
/>
|
||||
{isGlobal && (
|
||||
<span
|
||||
className="relative text-[11px] leading-none animate-pulse"
|
||||
aria-label="全球星潮标记"
|
||||
>
|
||||
🌐
|
||||
</span>
|
||||
)}
|
||||
<span className="relative text-xs leading-none">{meta.icon}</span>
|
||||
<span className="relative leading-none">{meta.name}</span>
|
||||
<span className="relative font-mono leading-none opacity-80">{secs}s</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 全屏背景叠层:活跃星潮时给页面罩一层对应色的微光 */
|
||||
export function StarTideOverlay() {
|
||||
const activeTide = useGameStore((s) => s.activeTide);
|
||||
const globalTide = useGameStore((s) => s.globalTide);
|
||||
if (!activeTide) return null;
|
||||
const meta = TIDE_EVENTS[activeTide.type];
|
||||
const isGlobal = !!globalTide;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 pointer-events-none z-0 transition-opacity duration-1000">
|
||||
{/* 顶部色带 */}
|
||||
<div
|
||||
className="absolute top-0 left-0 right-0 h-24 opacity-40"
|
||||
style={{
|
||||
background: `linear-gradient(180deg, ${meta.color}22, transparent)`,
|
||||
}}
|
||||
/>
|
||||
{/* 底部色带 */}
|
||||
<div
|
||||
className="absolute bottom-0 left-0 right-0 h-24 opacity-40"
|
||||
style={{
|
||||
background: `linear-gradient(0deg, ${meta.color}22, transparent)`,
|
||||
}}
|
||||
/>
|
||||
{/* 边缘呼吸光 */}
|
||||
<div
|
||||
className="absolute inset-0"
|
||||
style={{
|
||||
boxShadow: `inset 0 0 ${isGlobal ? "160" : "120"}px ${meta.glow}`,
|
||||
animation: "tide-breathe 3s ease-in-out infinite",
|
||||
}}
|
||||
/>
|
||||
{/* 全球星潮:顶部多一道琥珀色光带,强化"全球同步"视觉信号 */}
|
||||
{isGlobal && (
|
||||
<div
|
||||
className="absolute top-0 left-0 right-0 h-1 opacity-90"
|
||||
style={{
|
||||
background: "linear-gradient(90deg, transparent, #fbbf24, #fcd34d, #fbbf24, transparent)",
|
||||
boxShadow: "0 0 16px rgba(251,191,36,0.7)",
|
||||
animation: "global-tide-sweep 2.5s linear infinite",
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<style jsx>{`
|
||||
@keyframes tide-breathe {
|
||||
0%, 100% { opacity: 0.5; }
|
||||
50% { opacity: 0.9; }
|
||||
}
|
||||
@keyframes global-tide-sweep {
|
||||
0% { transform: translateX(-30%); }
|
||||
100% { transform: translateX(30%); }
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+181
@@ -0,0 +1,181 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 深空星空背景 Canvas
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
interface Star {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number; // 深度 0-1
|
||||
r: number;
|
||||
tw: number; // 闪烁相位
|
||||
hue: number;
|
||||
}
|
||||
|
||||
interface Dust {
|
||||
x: number;
|
||||
y: number;
|
||||
vx: number;
|
||||
vy: number;
|
||||
life: number;
|
||||
maxLife: number;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export function StarfieldCanvas({ className }: { className?: string }) {
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
|
||||
let w = 0;
|
||||
let h = 0;
|
||||
let dpr = 1;
|
||||
let stars: Star[] = [];
|
||||
const dust: Dust[] = [];
|
||||
let raf = 0;
|
||||
let lastT = performance.now();
|
||||
|
||||
const palette = ["#34d399", "#fb7185", "#fbbf24", "#e879f9", "#a5f3fc"];
|
||||
|
||||
function resize() {
|
||||
dpr = Math.min(2, window.devicePixelRatio || 1);
|
||||
w = canvas!.clientWidth;
|
||||
h = canvas!.clientHeight;
|
||||
canvas!.width = Math.floor(w * dpr);
|
||||
canvas!.height = Math.floor(h * dpr);
|
||||
ctx!.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
// 生成星星:密度随面积
|
||||
const count = Math.min(220, Math.floor((w * h) / 7000));
|
||||
stars = Array.from({ length: count }, () => ({
|
||||
x: Math.random() * w,
|
||||
y: Math.random() * h,
|
||||
z: Math.random(),
|
||||
r: Math.random() * 1.4 + 0.2,
|
||||
tw: Math.random() * Math.PI * 2,
|
||||
hue: Math.random() < 0.15 ? Math.floor(Math.random() * palette.length) : -1,
|
||||
}));
|
||||
}
|
||||
resize();
|
||||
const ro = new ResizeObserver(resize);
|
||||
ro.observe(canvas);
|
||||
|
||||
function spawnDust() {
|
||||
if (dust.length > 60) return;
|
||||
const color = palette[Math.floor(Math.random() * palette.length)];
|
||||
dust.push({
|
||||
x: Math.random() * w,
|
||||
y: h + 10,
|
||||
vx: (Math.random() - 0.5) * 0.3,
|
||||
vy: -(Math.random() * 0.5 + 0.2),
|
||||
life: 0,
|
||||
maxLife: 600 + Math.random() * 800,
|
||||
color,
|
||||
});
|
||||
}
|
||||
|
||||
function draw(t: number) {
|
||||
const dt = t - lastT;
|
||||
lastT = t;
|
||||
// 背景渐变
|
||||
const g = ctx!.createRadialGradient(w * 0.5, h * 0.4, 0, w * 0.5, h * 0.5, Math.max(w, h) * 0.8);
|
||||
g.addColorStop(0, "#1a0f2e");
|
||||
g.addColorStop(0.45, "#0d0a1f");
|
||||
g.addColorStop(1, "#050410");
|
||||
ctx!.fillStyle = g;
|
||||
ctx!.fillRect(0, 0, w, h);
|
||||
|
||||
// 星云团块
|
||||
ctx!.globalCompositeOperation = "screen";
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const cx = w * (0.2 + i * 0.3) + Math.sin(t / 9000 + i) * 40;
|
||||
const cy = h * (0.3 + (i % 2) * 0.4) + Math.cos(t / 11000 + i) * 30;
|
||||
const rad = Math.max(80, Math.min(w, h) * (0.25 + i * 0.05));
|
||||
const ng = ctx!.createRadialGradient(cx, cy, 0, cx, cy, rad);
|
||||
const col = i === 0 ? "rgba(232,121,249,0.10)" : i === 1 ? "rgba(52,211,153,0.08)" : "rgba(251,113,133,0.08)";
|
||||
ng.addColorStop(0, col);
|
||||
ng.addColorStop(1, "rgba(0,0,0,0)");
|
||||
ctx!.fillStyle = ng;
|
||||
ctx!.beginPath();
|
||||
ctx!.arc(cx, cy, rad, 0, Math.PI * 2);
|
||||
ctx!.fill();
|
||||
}
|
||||
ctx!.globalCompositeOperation = "source-over";
|
||||
|
||||
// 星星
|
||||
for (const s of stars) {
|
||||
s.tw += 0.02 + s.z * 0.04;
|
||||
const alpha = 0.4 + Math.sin(s.tw) * 0.35 + s.z * 0.3;
|
||||
if (s.hue >= 0) {
|
||||
ctx!.fillStyle = palette[s.hue];
|
||||
ctx!.globalAlpha = Math.max(0, Math.min(1, alpha));
|
||||
ctx!.beginPath();
|
||||
ctx!.arc(s.x, s.y, s.r * 1.6, 0, Math.PI * 2);
|
||||
ctx!.fill();
|
||||
// 光晕
|
||||
ctx!.globalAlpha = Math.max(0, Math.min(1, alpha * 0.25));
|
||||
ctx!.beginPath();
|
||||
ctx!.arc(s.x, s.y, s.r * 4, 0, Math.PI * 2);
|
||||
ctx!.fill();
|
||||
} else {
|
||||
ctx!.fillStyle = `rgba(220,230,255,${Math.max(0, Math.min(1, alpha))})`;
|
||||
ctx!.beginPath();
|
||||
ctx!.arc(s.x, s.y, s.r, 0, Math.PI * 2);
|
||||
ctx!.fill();
|
||||
}
|
||||
// 缓慢漂移
|
||||
s.y += 0.02 + s.z * 0.05;
|
||||
if (s.y > h + 2) {
|
||||
s.y = -2;
|
||||
s.x = Math.random() * w;
|
||||
}
|
||||
}
|
||||
ctx!.globalAlpha = 1;
|
||||
|
||||
// 偶尔生成星尘
|
||||
if (Math.random() < 0.04) spawnDust();
|
||||
// 星尘
|
||||
ctx!.globalCompositeOperation = "screen";
|
||||
for (let i = dust.length - 1; i >= 0; i--) {
|
||||
const d = dust[i];
|
||||
d.life += dt;
|
||||
d.x += d.vx * dt * 0.06;
|
||||
d.y += d.vy * dt * 0.06;
|
||||
if (d.life > d.maxLife || d.y < -10) {
|
||||
dust.splice(i, 1);
|
||||
continue;
|
||||
}
|
||||
const a = Math.sin((d.life / d.maxLife) * Math.PI) * 0.7;
|
||||
ctx!.fillStyle = d.color;
|
||||
ctx!.globalAlpha = a;
|
||||
ctx!.beginPath();
|
||||
ctx!.arc(d.x, d.y, 1.6, 0, Math.PI * 2);
|
||||
ctx!.fill();
|
||||
ctx!.globalAlpha = a * 0.2;
|
||||
ctx!.beginPath();
|
||||
ctx!.arc(d.x, d.y, 5, 0, Math.PI * 2);
|
||||
ctx!.fill();
|
||||
}
|
||||
ctx!.globalAlpha = 1;
|
||||
ctx!.globalCompositeOperation = "source-over";
|
||||
|
||||
raf = requestAnimationFrame(draw);
|
||||
}
|
||||
raf = requestAnimationFrame(draw);
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(raf);
|
||||
ro.disconnect();
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
className={className}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
);
|
||||
}
|
||||
Executable
+146
@@ -0,0 +1,146 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 技术树
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import { TECH_TREE, TECH_BRANCH_META, formatNum } from "@/lib/game/config";
|
||||
import { sfx } from "@/hooks/useAudio";
|
||||
import { TECH_LORE } from "@/lib/game/narrative";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Pickaxe,
|
||||
ScanLine,
|
||||
Rocket,
|
||||
BookOpen,
|
||||
Check,
|
||||
Lock,
|
||||
} from "lucide-react";
|
||||
import type { TechBranch } from "@/lib/game/types";
|
||||
|
||||
const ICONS: Record<string, React.ComponentType<{ className?: string }>> = {
|
||||
Pickaxe,
|
||||
ScanLine,
|
||||
Rocket,
|
||||
BookOpen,
|
||||
};
|
||||
|
||||
const BRANCH_COLOR: Record<string, string> = {
|
||||
mining: "#34d399",
|
||||
decoding: "#fb7185",
|
||||
expedition: "#fbbf24",
|
||||
narrative: "#e879f9",
|
||||
};
|
||||
|
||||
export function TechTree() {
|
||||
const tech = useGameStore((s) => s.tech);
|
||||
const insights = useGameStore((s) => s.insights);
|
||||
const buyTech = useGameStore((s) => s.buyTech);
|
||||
|
||||
const branches: TechBranch[] = ["mining", "decoding", "expedition", "narrative"];
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3 h-full">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold">技术树</h3>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
洞见 <span className="text-amber-300 font-mono">{formatNum(insights)}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-y-auto echo-scroll pr-1 space-y-3">
|
||||
{branches.map((b) => {
|
||||
const meta = TECH_BRANCH_META[b];
|
||||
const Icon = ICONS[meta.icon];
|
||||
const color = BRANCH_COLOR[b];
|
||||
const nodes = TECH_TREE.filter((t) => t.branch === b);
|
||||
return (
|
||||
<div key={b}>
|
||||
<div className="flex items-center gap-2 mb-1.5 px-1">
|
||||
<Icon className="h-3.5 w-3.5" />
|
||||
<span className="text-xs font-medium" style={{ color }}>
|
||||
{meta.name}
|
||||
</span>
|
||||
<span className="text-[10px] text-muted-foreground/70 truncate flex-1">
|
||||
{meta.desc}
|
||||
</span>
|
||||
</div>
|
||||
{/* v0.9 叙事融入:每分支的以太族遗产描述 */}
|
||||
<p className="text-[9px] italic text-muted-foreground/50 px-1 mb-1.5 truncate">
|
||||
「{TECH_LORE[b] ?? ""}」
|
||||
</p>
|
||||
<div className="grid gap-1.5">
|
||||
{nodes.map((node) => {
|
||||
const owned = (tech[node.id] ?? 0) >= 1;
|
||||
const affordable = insights >= node.cost;
|
||||
return (
|
||||
<Card
|
||||
key={node.id}
|
||||
className={`p-2.5 transition-all duration-200 ${
|
||||
owned
|
||||
? "bg-white/5 border-white/10"
|
||||
: affordable
|
||||
? "bg-black/30 border-white/15 hover:border-white/30 cursor-pointer"
|
||||
: "bg-black/20 border-white/5 opacity-60"
|
||||
}`}
|
||||
style={
|
||||
owned
|
||||
? { boxShadow: `inset 0 0 0 1px ${color}44, 0 0 12px ${color}22` }
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span
|
||||
className="text-xs font-semibold truncate"
|
||||
style={{ color: owned ? color : undefined }}
|
||||
>
|
||||
{node.name}
|
||||
</span>
|
||||
{owned && (
|
||||
<Check className="h-3 w-3" style={{ color }} />
|
||||
)}
|
||||
</div>
|
||||
<p className="text-[10px] text-muted-foreground/80 truncate">
|
||||
{node.desc}
|
||||
</p>
|
||||
</div>
|
||||
{!owned && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant={affordable ? "default" : "ghost"}
|
||||
disabled={!affordable}
|
||||
onClick={() => {
|
||||
if (buyTech(node.id)) sfx("techBuy");
|
||||
}}
|
||||
className="h-7 px-2 text-[11px] shrink-0"
|
||||
style={
|
||||
affordable
|
||||
? {
|
||||
background: `${color}22`,
|
||||
border: `1px solid ${color}66`,
|
||||
color,
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<Lock className="h-2.5 w-2.5 mr-1" />
|
||||
{node.cost}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<style jsx global>{`
|
||||
.echo-scroll::-webkit-scrollbar { width: 5px; }
|
||||
.echo-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
|
||||
.echo-scroll::-webkit-scrollbar-track { background: transparent; }
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+320
@@ -0,0 +1,320 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 新手教程覆盖层
|
||||
import { useState, useEffect, useCallback, useRef } from "react";
|
||||
import { TUTORIAL_STEPS, hasSeenTutorial, markTutorialSeen } from "@/lib/game/tutorial";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ChevronLeft, ChevronRight, X, Sparkles } from "lucide-react";
|
||||
|
||||
interface Rect {
|
||||
left: number;
|
||||
top: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export function TutorialOverlay() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [stepIdx, setStepIdx] = useState(0);
|
||||
const [targetRect, setTargetRect] = useState<Rect | null>(null);
|
||||
const [actionDone, setActionDone] = useState(false);
|
||||
const rafRef = useRef<number | null>(null);
|
||||
|
||||
// 首次访问自动打开
|
||||
useEffect(() => {
|
||||
if (!hasSeenTutorial()) {
|
||||
// 等待游戏 mount
|
||||
const t = setTimeout(() => setOpen(true), 600);
|
||||
return () => clearTimeout(t);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 监听「重新查看教程」事件
|
||||
useEffect(() => {
|
||||
const handler = () => {
|
||||
setStepIdx(0);
|
||||
setActionDone(false);
|
||||
setOpen(true);
|
||||
};
|
||||
window.addEventListener("echo-nexus-tutorial-restart", handler);
|
||||
return () => window.removeEventListener("echo-nexus-tutorial-restart", handler);
|
||||
}, []);
|
||||
|
||||
// 监听预期动作(用现有 store 状态推断,避免改 schema)
|
||||
const crystals = useGameStore((s) => s.crystals);
|
||||
const pulsePower = useGameStore((s) => s.pulsePower);
|
||||
const ownedTech = useGameStore((s) => s.tech);
|
||||
const activePuzzle = useGameStore((s) => s.activePuzzle);
|
||||
const hasActiveExpedition = useGameStore(
|
||||
(s) => !!s.activeExpedition && !s.activeExpedition.finished
|
||||
);
|
||||
// 记录进入 pulse 步骤时的晶体基线
|
||||
const pulseBaseRef = useRef<number | null>(null);
|
||||
|
||||
// 动作完成检测:用 rAF 异步轮询,避免 effect 中同步 setState
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const step = TUTORIAL_STEPS[stepIdx];
|
||||
if (!step?.expectAction) {
|
||||
return;
|
||||
}
|
||||
let raf2 = 0;
|
||||
const check = () => {
|
||||
const s = useGameStore.getState();
|
||||
let done = false;
|
||||
if (step.expectAction === "pulse") {
|
||||
if (pulseBaseRef.current === null) pulseBaseRef.current = s.crystals;
|
||||
done = s.crystals >= (pulseBaseRef.current ?? 0) + Math.max(0.5, s.pulsePower * 0.5);
|
||||
} else if (step.expectAction === "decode-start") {
|
||||
done = !!s.activePuzzle;
|
||||
} else if (step.expectAction === "tech-buy") {
|
||||
done = Object.values(s.tech).some((v) => v > 0);
|
||||
} else if (step.expectAction === "expedition-start") {
|
||||
done = !!s.activeExpedition && !s.activeExpedition.finished;
|
||||
}
|
||||
setActionDone((prev) => (prev !== done ? done : prev));
|
||||
raf2 = requestAnimationFrame(check);
|
||||
};
|
||||
raf2 = requestAnimationFrame(check);
|
||||
return () => cancelAnimationFrame(raf2);
|
||||
}, [open, stepIdx]);
|
||||
|
||||
// 跟踪目标元素位置
|
||||
const updateTargetRect = useCallback(() => {
|
||||
const step = TUTORIAL_STEPS[stepIdx];
|
||||
if (!step?.target) {
|
||||
setTargetRect(null);
|
||||
return;
|
||||
}
|
||||
const el = document.querySelector(`[data-tut="${step.target}"]`) as HTMLElement | null;
|
||||
if (!el) {
|
||||
setTargetRect(null);
|
||||
return;
|
||||
}
|
||||
const r = el.getBoundingClientRect();
|
||||
setTargetRect({
|
||||
left: r.left,
|
||||
top: r.top,
|
||||
width: r.width,
|
||||
height: r.height,
|
||||
});
|
||||
}, [stepIdx]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
// 首帧不直接 setState,统一交给 rAF 循环检测
|
||||
const loop = () => {
|
||||
updateTargetRect();
|
||||
rafRef.current = requestAnimationFrame(loop);
|
||||
};
|
||||
rafRef.current = requestAnimationFrame(loop);
|
||||
return () => {
|
||||
if (rafRef.current) cancelAnimationFrame(rafRef.current);
|
||||
};
|
||||
}, [open, stepIdx, updateTargetRect]);
|
||||
|
||||
const close = useCallback(() => {
|
||||
setOpen(false);
|
||||
markTutorialSeen();
|
||||
}, []);
|
||||
|
||||
const next = useCallback(() => {
|
||||
if (stepIdx >= TUTORIAL_STEPS.length - 1) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
setStepIdx((i) => i + 1);
|
||||
setActionDone(false);
|
||||
}, [stepIdx, close]);
|
||||
|
||||
const prev = useCallback(() => {
|
||||
if (stepIdx <= 0) return;
|
||||
setStepIdx((i) => i - 1);
|
||||
setActionDone(false);
|
||||
}, [stepIdx]);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const step = TUTORIAL_STEPS[stepIdx];
|
||||
const isLast = stepIdx >= TUTORIAL_STEPS.length - 1;
|
||||
|
||||
// 计算提示气泡位置
|
||||
const placement = step.placement ?? "auto";
|
||||
let tooltipStyle: React.CSSProperties = {};
|
||||
if (targetRect) {
|
||||
const pad = 16;
|
||||
if (placement === "right") {
|
||||
tooltipStyle = {
|
||||
left: targetRect.left + targetRect.width + pad,
|
||||
top: targetRect.top + targetRect.height / 2,
|
||||
transform: "translateY(-50%)",
|
||||
};
|
||||
} else if (placement === "left") {
|
||||
tooltipStyle = {
|
||||
left: Math.max(16, targetRect.left - 360 - pad),
|
||||
top: targetRect.top + targetRect.height / 2,
|
||||
transform: "translateY(-50%)",
|
||||
maxWidth: 340,
|
||||
};
|
||||
} else if (placement === "top") {
|
||||
tooltipStyle = {
|
||||
left: Math.max(16, Math.min(targetRect.left, window.innerWidth - 360 - 16)),
|
||||
top: Math.max(16, targetRect.top - 220),
|
||||
maxWidth: 340,
|
||||
};
|
||||
} else {
|
||||
// bottom / auto
|
||||
tooltipStyle = {
|
||||
left: Math.max(16, Math.min(window.innerWidth / 2 - 170, window.innerWidth - 360 - 16)),
|
||||
top: Math.min(window.innerHeight - 260, (targetRect?.bottom ?? window.innerHeight / 2) + pad),
|
||||
maxWidth: 340,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// 无目标 → 居中
|
||||
tooltipStyle = {
|
||||
left: "50%",
|
||||
top: "50%",
|
||||
transform: "translate(-50%, -50%)",
|
||||
maxWidth: 440,
|
||||
};
|
||||
}
|
||||
|
||||
// 聚光灯遮罩:用 4 块 div 挖洞
|
||||
const renderMask = () => {
|
||||
if (!targetRect) {
|
||||
// 全屏半透明
|
||||
return <div className="fixed inset-0 bg-black/70 z-[80] pointer-events-auto" />;
|
||||
}
|
||||
const { left, top, width, height } = targetRect;
|
||||
const pad = 6;
|
||||
const l = left - pad;
|
||||
const t = top - pad;
|
||||
const w = width + pad * 2;
|
||||
const h = height + pad * 2;
|
||||
return (
|
||||
<>
|
||||
{/* 上 */}
|
||||
<div className="fixed bg-black/70 z-[80] pointer-events-auto" style={{ left: 0, top: 0, right: 0, height: Math.max(0, t) }} />
|
||||
{/* 下 */}
|
||||
<div className="fixed bg-black/70 z-[80] pointer-events-auto" style={{ left: 0, top: t + h, right: 0, bottom: 0 }} />
|
||||
{/* 左 */}
|
||||
<div className="fixed bg-black/70 z-[80] pointer-events-auto" style={{ left: 0, top: t, width: Math.max(0, l), height: h }} />
|
||||
{/* 右 */}
|
||||
<div className="fixed bg-black/70 z-[80] pointer-events-auto" style={{ left: l + w, top: t, right: 0, height: h }} />
|
||||
{/* 高亮边框 + 呼吸光 */}
|
||||
<div
|
||||
className="fixed z-[81] pointer-events-none rounded-lg"
|
||||
style={{
|
||||
left: l,
|
||||
top: t,
|
||||
width: w,
|
||||
height: h,
|
||||
boxShadow: `0 0 0 2px rgba(232,121,249,0.9), 0 0 24px 4px rgba(232,121,249,0.5)`,
|
||||
animation: "tut-pulse 1.6s ease-in-out infinite",
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[79]">
|
||||
{/* 遮罩(允许 pointer-events 透过到非高亮区,但拦截点击避免误操作) */}
|
||||
{renderMask()}
|
||||
|
||||
{/* 提示气泡 */}
|
||||
<div
|
||||
className="fixed z-[82] w-[340px] sm:w-[360px] max-w-[calc(100vw-32px)]"
|
||||
style={tooltipStyle}
|
||||
>
|
||||
<div className="relative rounded-2xl border border-fuchsia-400/40 bg-gradient-to-br from-[#1a0a2e]/95 to-[#0a0a1e]/95 backdrop-blur-xl shadow-2xl shadow-fuchsia-500/20 overflow-hidden">
|
||||
{/* 顶部装饰条 */}
|
||||
<div className="h-1 w-full bg-gradient-to-r from-emerald-400 via-fuchsia-500 to-rose-400" />
|
||||
{/* 关闭 */}
|
||||
<button
|
||||
onClick={close}
|
||||
className="absolute top-2 right-2 h-7 w-7 rounded-full flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-white/10 transition z-10"
|
||||
aria-label="关闭教程"
|
||||
>
|
||||
<X className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
|
||||
<div className="p-4 pt-3.5">
|
||||
{/* 步骤指示 */}
|
||||
<div className="flex items-center gap-1.5 mb-2.5">
|
||||
{TUTORIAL_STEPS.map((s, i) => (
|
||||
<div
|
||||
key={s.id}
|
||||
className={`h-1 rounded-full transition-all ${
|
||||
i === stepIdx
|
||||
? "w-6 bg-fuchsia-400"
|
||||
: i < stepIdx
|
||||
? "w-3 bg-fuchsia-400/50"
|
||||
: "w-3 bg-white/15"
|
||||
}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<h3 className="text-sm font-bold text-fuchsia-100 mb-1.5 flex items-center gap-1.5 pr-6">
|
||||
<Sparkles className="h-3.5 w-3.5 text-fuchsia-300 shrink-0" />
|
||||
{step.title}
|
||||
</h3>
|
||||
<p className="text-[12.5px] text-muted-foreground leading-relaxed whitespace-pre-line">
|
||||
{step.body}
|
||||
</p>
|
||||
|
||||
{/* 动作提示 */}
|
||||
{step.expectAction && !actionDone && (
|
||||
<div className="mt-3 px-2.5 py-1.5 rounded-lg bg-amber-500/10 border border-amber-400/30 text-[11px] text-amber-200 flex items-center gap-1.5">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-amber-400 animate-pulse" />
|
||||
完成动作后自动进入下一步,或点跳过
|
||||
</div>
|
||||
)}
|
||||
{step.expectAction && actionDone && (
|
||||
<div className="mt-3 px-2.5 py-1.5 rounded-lg bg-emerald-500/10 border border-emerald-400/30 text-[11px] text-emerald-200 flex items-center gap-1.5">
|
||||
✓ 已检测到动作
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 按钮 */}
|
||||
<div className="flex items-center gap-2 mt-4">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={prev}
|
||||
disabled={stepIdx === 0}
|
||||
className="h-7 px-2 text-[11px] text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<ChevronLeft className="h-3.5 w-3.5" />
|
||||
上一步
|
||||
</Button>
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={close}
|
||||
className="h-7 px-2 text-[11px] text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
跳过
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={next}
|
||||
className="h-7 px-3 text-[11px] bg-fuchsia-500 hover:bg-fuchsia-600 text-white border-fuchsia-400/50"
|
||||
>
|
||||
{isLast ? "完成" : "下一步"}
|
||||
<ChevronRight className="h-3.5 w-3.5 ml-0.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-[10px] text-muted-foreground/60 text-center mt-2">
|
||||
{stepIdx + 1} / {TUTORIAL_STEPS.length}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as AccordionPrimitive from "@radix-ui/react-accordion"
|
||||
import { ChevronDownIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Accordion({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
|
||||
return <AccordionPrimitive.Root data-slot="accordion" {...props} />
|
||||
}
|
||||
|
||||
function AccordionItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
|
||||
return (
|
||||
<AccordionPrimitive.Item
|
||||
data-slot="accordion-item"
|
||||
className={cn("border-b last:border-b-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AccordionTrigger({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
|
||||
return (
|
||||
<AccordionPrimitive.Header className="flex">
|
||||
<AccordionPrimitive.Trigger
|
||||
data-slot="accordion-trigger"
|
||||
className={cn(
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronDownIcon className="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200" />
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
)
|
||||
}
|
||||
|
||||
function AccordionContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
|
||||
return (
|
||||
<AccordionPrimitive.Content
|
||||
data-slot="accordion-content"
|
||||
className="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm"
|
||||
{...props}
|
||||
>
|
||||
<div className={cn("pt-0 pb-4", className)}>{children}</div>
|
||||
</AccordionPrimitive.Content>
|
||||
)
|
||||
}
|
||||
|
||||
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|
||||
Executable
+157
@@ -0,0 +1,157 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { buttonVariants } from "@/components/ui/button"
|
||||
|
||||
function AlertDialog({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
|
||||
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />
|
||||
}
|
||||
|
||||
function AlertDialogTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Overlay
|
||||
data-slot="alert-dialog-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Content>) {
|
||||
return (
|
||||
<AlertDialogPortal>
|
||||
<AlertDialogOverlay />
|
||||
<AlertDialogPrimitive.Content
|
||||
data-slot="alert-dialog-content"
|
||||
className={cn(
|
||||
"bg-background 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 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</AlertDialogPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogHeader({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-dialog-header"
|
||||
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogFooter({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-dialog-footer"
|
||||
className={cn(
|
||||
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Title
|
||||
data-slot="alert-dialog-title"
|
||||
className={cn("text-lg font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Description
|
||||
data-slot="alert-dialog-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogAction({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Action>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Action
|
||||
className={cn(buttonVariants(), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDialogCancel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Cancel
|
||||
className={cn(buttonVariants({ variant: "outline" }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
AlertDialog,
|
||||
AlertDialogPortal,
|
||||
AlertDialogOverlay,
|
||||
AlertDialogTrigger,
|
||||
AlertDialogContent,
|
||||
AlertDialogHeader,
|
||||
AlertDialogFooter,
|
||||
AlertDialogTitle,
|
||||
AlertDialogDescription,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const alertVariants = cva(
|
||||
"relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-card text-card-foreground",
|
||||
destructive:
|
||||
"text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Alert({
|
||||
className,
|
||||
variant,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert"
|
||||
role="alert"
|
||||
className={cn(alertVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-title"
|
||||
className={cn(
|
||||
"col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AlertDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-description"
|
||||
className={cn(
|
||||
"text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Alert, AlertTitle, AlertDescription }
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
"use client"
|
||||
|
||||
import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio"
|
||||
|
||||
function AspectRatio({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AspectRatioPrimitive.Root>) {
|
||||
return <AspectRatioPrimitive.Root data-slot="aspect-ratio" {...props} />
|
||||
}
|
||||
|
||||
export { AspectRatio }
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as AvatarPrimitive from "@radix-ui/react-avatar"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Avatar({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Root>) {
|
||||
return (
|
||||
<AvatarPrimitive.Root
|
||||
data-slot="avatar"
|
||||
className={cn(
|
||||
"relative flex size-8 shrink-0 overflow-hidden rounded-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarImage({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
|
||||
return (
|
||||
<AvatarPrimitive.Image
|
||||
data-slot="avatar-image"
|
||||
className={cn("aspect-square size-full", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarFallback({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
|
||||
return (
|
||||
<AvatarPrimitive.Fallback
|
||||
data-slot="avatar-fallback"
|
||||
className={cn(
|
||||
"bg-muted flex size-full items-center justify-center rounded-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Avatar, AvatarImage, AvatarFallback }
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
||||
secondary:
|
||||
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
||||
destructive:
|
||||
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"span"> &
|
||||
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "span"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="badge"
|
||||
className={cn(badgeVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
Executable
+109
@@ -0,0 +1,109 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { ChevronRight, MoreHorizontal } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Breadcrumb({ ...props }: React.ComponentProps<"nav">) {
|
||||
return <nav aria-label="breadcrumb" data-slot="breadcrumb" {...props} />
|
||||
}
|
||||
|
||||
function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
|
||||
return (
|
||||
<ol
|
||||
data-slot="breadcrumb-list"
|
||||
className={cn(
|
||||
"text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="breadcrumb-item"
|
||||
className={cn("inline-flex items-center gap-1.5", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbLink({
|
||||
asChild,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"a"> & {
|
||||
asChild?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "a"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="breadcrumb-link"
|
||||
className={cn("hover:text-foreground transition-colors", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="breadcrumb-page"
|
||||
role="link"
|
||||
aria-disabled="true"
|
||||
aria-current="page"
|
||||
className={cn("text-foreground font-normal", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbSeparator({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="breadcrumb-separator"
|
||||
role="presentation"
|
||||
aria-hidden="true"
|
||||
className={cn("[&>svg]:size-3.5", className)}
|
||||
{...props}
|
||||
>
|
||||
{children ?? <ChevronRight />}
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbEllipsis({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="breadcrumb-ellipsis"
|
||||
role="presentation"
|
||||
aria-hidden="true"
|
||||
className={cn("flex size-9 items-center justify-center", className)}
|
||||
{...props}
|
||||
>
|
||||
<MoreHorizontal className="size-4" />
|
||||
<span className="sr-only">More</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Breadcrumb,
|
||||
BreadcrumbList,
|
||||
BreadcrumbItem,
|
||||
BreadcrumbLink,
|
||||
BreadcrumbPage,
|
||||
BreadcrumbSeparator,
|
||||
BreadcrumbEllipsis,
|
||||
}
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
|
||||
destructive:
|
||||
"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
|
||||
ghost:
|
||||
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||
icon: "size-9",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Button({
|
||||
className,
|
||||
variant,
|
||||
size,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> &
|
||||
VariantProps<typeof buttonVariants> & {
|
||||
asChild?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="button"
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Button, buttonVariants }
|
||||
Executable
+213
@@ -0,0 +1,213 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import {
|
||||
ChevronDownIcon,
|
||||
ChevronLeftIcon,
|
||||
ChevronRightIcon,
|
||||
} from "lucide-react"
|
||||
import { DayButton, DayPicker, getDefaultClassNames } from "react-day-picker"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button, buttonVariants } from "@/components/ui/button"
|
||||
|
||||
function Calendar({
|
||||
className,
|
||||
classNames,
|
||||
showOutsideDays = true,
|
||||
captionLayout = "label",
|
||||
buttonVariant = "ghost",
|
||||
formatters,
|
||||
components,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DayPicker> & {
|
||||
buttonVariant?: React.ComponentProps<typeof Button>["variant"]
|
||||
}) {
|
||||
const defaultClassNames = getDefaultClassNames()
|
||||
|
||||
return (
|
||||
<DayPicker
|
||||
showOutsideDays={showOutsideDays}
|
||||
className={cn(
|
||||
"bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
|
||||
String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
|
||||
String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
|
||||
className
|
||||
)}
|
||||
captionLayout={captionLayout}
|
||||
formatters={{
|
||||
formatMonthDropdown: (date) =>
|
||||
date.toLocaleString("default", { month: "short" }),
|
||||
...formatters,
|
||||
}}
|
||||
classNames={{
|
||||
root: cn("w-fit", defaultClassNames.root),
|
||||
months: cn(
|
||||
"flex gap-4 flex-col md:flex-row relative",
|
||||
defaultClassNames.months
|
||||
),
|
||||
month: cn("flex flex-col w-full gap-4", defaultClassNames.month),
|
||||
nav: cn(
|
||||
"flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between",
|
||||
defaultClassNames.nav
|
||||
),
|
||||
button_previous: cn(
|
||||
buttonVariants({ variant: buttonVariant }),
|
||||
"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
|
||||
defaultClassNames.button_previous
|
||||
),
|
||||
button_next: cn(
|
||||
buttonVariants({ variant: buttonVariant }),
|
||||
"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
|
||||
defaultClassNames.button_next
|
||||
),
|
||||
month_caption: cn(
|
||||
"flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)",
|
||||
defaultClassNames.month_caption
|
||||
),
|
||||
dropdowns: cn(
|
||||
"w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5",
|
||||
defaultClassNames.dropdowns
|
||||
),
|
||||
dropdown_root: cn(
|
||||
"relative has-focus:border-ring border border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] rounded-md",
|
||||
defaultClassNames.dropdown_root
|
||||
),
|
||||
dropdown: cn(
|
||||
"absolute bg-popover inset-0 opacity-0",
|
||||
defaultClassNames.dropdown
|
||||
),
|
||||
caption_label: cn(
|
||||
"select-none font-medium",
|
||||
captionLayout === "label"
|
||||
? "text-sm"
|
||||
: "rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-muted-foreground [&>svg]:size-3.5",
|
||||
defaultClassNames.caption_label
|
||||
),
|
||||
table: "w-full border-collapse",
|
||||
weekdays: cn("flex", defaultClassNames.weekdays),
|
||||
weekday: cn(
|
||||
"text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none",
|
||||
defaultClassNames.weekday
|
||||
),
|
||||
week: cn("flex w-full mt-2", defaultClassNames.week),
|
||||
week_number_header: cn(
|
||||
"select-none w-(--cell-size)",
|
||||
defaultClassNames.week_number_header
|
||||
),
|
||||
week_number: cn(
|
||||
"text-[0.8rem] select-none text-muted-foreground",
|
||||
defaultClassNames.week_number
|
||||
),
|
||||
day: cn(
|
||||
"relative w-full h-full p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none",
|
||||
defaultClassNames.day
|
||||
),
|
||||
range_start: cn(
|
||||
"rounded-l-md bg-accent",
|
||||
defaultClassNames.range_start
|
||||
),
|
||||
range_middle: cn("rounded-none", defaultClassNames.range_middle),
|
||||
range_end: cn("rounded-r-md bg-accent", defaultClassNames.range_end),
|
||||
today: cn(
|
||||
"bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",
|
||||
defaultClassNames.today
|
||||
),
|
||||
outside: cn(
|
||||
"text-muted-foreground aria-selected:text-muted-foreground",
|
||||
defaultClassNames.outside
|
||||
),
|
||||
disabled: cn(
|
||||
"text-muted-foreground opacity-50",
|
||||
defaultClassNames.disabled
|
||||
),
|
||||
hidden: cn("invisible", defaultClassNames.hidden),
|
||||
...classNames,
|
||||
}}
|
||||
components={{
|
||||
Root: ({ className, rootRef, ...props }) => {
|
||||
return (
|
||||
<div
|
||||
data-slot="calendar"
|
||||
ref={rootRef}
|
||||
className={cn(className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
},
|
||||
Chevron: ({ className, orientation, ...props }) => {
|
||||
if (orientation === "left") {
|
||||
return (
|
||||
<ChevronLeftIcon className={cn("size-4", className)} {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
if (orientation === "right") {
|
||||
return (
|
||||
<ChevronRightIcon
|
||||
className={cn("size-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<ChevronDownIcon className={cn("size-4", className)} {...props} />
|
||||
)
|
||||
},
|
||||
DayButton: CalendarDayButton,
|
||||
WeekNumber: ({ children, ...props }) => {
|
||||
return (
|
||||
<td {...props}>
|
||||
<div className="flex size-(--cell-size) items-center justify-center text-center">
|
||||
{children}
|
||||
</div>
|
||||
</td>
|
||||
)
|
||||
},
|
||||
...components,
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CalendarDayButton({
|
||||
className,
|
||||
day,
|
||||
modifiers,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DayButton>) {
|
||||
const defaultClassNames = getDefaultClassNames()
|
||||
|
||||
const ref = React.useRef<HTMLButtonElement>(null)
|
||||
React.useEffect(() => {
|
||||
if (modifiers.focused) ref.current?.focus()
|
||||
}, [modifiers.focused])
|
||||
|
||||
return (
|
||||
<Button
|
||||
ref={ref}
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
data-day={day.date.toLocaleDateString()}
|
||||
data-selected-single={
|
||||
modifiers.selected &&
|
||||
!modifiers.range_start &&
|
||||
!modifiers.range_end &&
|
||||
!modifiers.range_middle
|
||||
}
|
||||
data-range-start={modifiers.range_start}
|
||||
data-range-end={modifiers.range_end}
|
||||
data-range-middle={modifiers.range_middle}
|
||||
className={cn(
|
||||
"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 dark:hover:text-accent-foreground flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70",
|
||||
defaultClassNames.day,
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Calendar, CalendarDayButton }
|
||||
Executable
+92
@@ -0,0 +1,92 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card"
|
||||
className={cn(
|
||||
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-header"
|
||||
className={cn(
|
||||
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-title"
|
||||
className={cn("leading-none font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-action"
|
||||
className={cn(
|
||||
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-content"
|
||||
className={cn("px-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-footer"
|
||||
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Card,
|
||||
CardHeader,
|
||||
CardFooter,
|
||||
CardTitle,
|
||||
CardAction,
|
||||
CardDescription,
|
||||
CardContent,
|
||||
}
|
||||
Executable
+241
@@ -0,0 +1,241 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import useEmblaCarousel, {
|
||||
type UseEmblaCarouselType,
|
||||
} from "embla-carousel-react"
|
||||
import { ArrowLeft, ArrowRight } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
|
||||
type CarouselApi = UseEmblaCarouselType[1]
|
||||
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
|
||||
type CarouselOptions = UseCarouselParameters[0]
|
||||
type CarouselPlugin = UseCarouselParameters[1]
|
||||
|
||||
type CarouselProps = {
|
||||
opts?: CarouselOptions
|
||||
plugins?: CarouselPlugin
|
||||
orientation?: "horizontal" | "vertical"
|
||||
setApi?: (api: CarouselApi) => void
|
||||
}
|
||||
|
||||
type CarouselContextProps = {
|
||||
carouselRef: ReturnType<typeof useEmblaCarousel>[0]
|
||||
api: ReturnType<typeof useEmblaCarousel>[1]
|
||||
scrollPrev: () => void
|
||||
scrollNext: () => void
|
||||
canScrollPrev: boolean
|
||||
canScrollNext: boolean
|
||||
} & CarouselProps
|
||||
|
||||
const CarouselContext = React.createContext<CarouselContextProps | null>(null)
|
||||
|
||||
function useCarousel() {
|
||||
const context = React.useContext(CarouselContext)
|
||||
|
||||
if (!context) {
|
||||
throw new Error("useCarousel must be used within a <Carousel />")
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
function Carousel({
|
||||
orientation = "horizontal",
|
||||
opts,
|
||||
setApi,
|
||||
plugins,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & CarouselProps) {
|
||||
const [carouselRef, api] = useEmblaCarousel(
|
||||
{
|
||||
...opts,
|
||||
axis: orientation === "horizontal" ? "x" : "y",
|
||||
},
|
||||
plugins
|
||||
)
|
||||
const [canScrollPrev, setCanScrollPrev] = React.useState(false)
|
||||
const [canScrollNext, setCanScrollNext] = React.useState(false)
|
||||
|
||||
const onSelect = React.useCallback((api: CarouselApi) => {
|
||||
if (!api) return
|
||||
setCanScrollPrev(api.canScrollPrev())
|
||||
setCanScrollNext(api.canScrollNext())
|
||||
}, [])
|
||||
|
||||
const scrollPrev = React.useCallback(() => {
|
||||
api?.scrollPrev()
|
||||
}, [api])
|
||||
|
||||
const scrollNext = React.useCallback(() => {
|
||||
api?.scrollNext()
|
||||
}, [api])
|
||||
|
||||
const handleKeyDown = React.useCallback(
|
||||
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
if (event.key === "ArrowLeft") {
|
||||
event.preventDefault()
|
||||
scrollPrev()
|
||||
} else if (event.key === "ArrowRight") {
|
||||
event.preventDefault()
|
||||
scrollNext()
|
||||
}
|
||||
},
|
||||
[scrollPrev, scrollNext]
|
||||
)
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!api || !setApi) return
|
||||
setApi(api)
|
||||
}, [api, setApi])
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!api) return
|
||||
onSelect(api)
|
||||
api.on("reInit", onSelect)
|
||||
api.on("select", onSelect)
|
||||
|
||||
return () => {
|
||||
api?.off("select", onSelect)
|
||||
}
|
||||
}, [api, onSelect])
|
||||
|
||||
return (
|
||||
<CarouselContext.Provider
|
||||
value={{
|
||||
carouselRef,
|
||||
api: api,
|
||||
opts,
|
||||
orientation:
|
||||
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
||||
scrollPrev,
|
||||
scrollNext,
|
||||
canScrollPrev,
|
||||
canScrollNext,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
onKeyDownCapture={handleKeyDown}
|
||||
className={cn("relative", className)}
|
||||
role="region"
|
||||
aria-roledescription="carousel"
|
||||
data-slot="carousel"
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</CarouselContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
const { carouselRef, orientation } = useCarousel()
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={carouselRef}
|
||||
className="overflow-hidden"
|
||||
data-slot="carousel-content"
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"flex",
|
||||
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
||||
const { orientation } = useCarousel()
|
||||
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
aria-roledescription="slide"
|
||||
data-slot="carousel-item"
|
||||
className={cn(
|
||||
"min-w-0 shrink-0 grow-0 basis-full",
|
||||
orientation === "horizontal" ? "pl-4" : "pt-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CarouselPrevious({
|
||||
className,
|
||||
variant = "outline",
|
||||
size = "icon",
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const { orientation, scrollPrev, canScrollPrev } = useCarousel()
|
||||
|
||||
return (
|
||||
<Button
|
||||
data-slot="carousel-previous"
|
||||
variant={variant}
|
||||
size={size}
|
||||
className={cn(
|
||||
"absolute size-8 rounded-full",
|
||||
orientation === "horizontal"
|
||||
? "top-1/2 -left-12 -translate-y-1/2"
|
||||
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
||||
className
|
||||
)}
|
||||
disabled={!canScrollPrev}
|
||||
onClick={scrollPrev}
|
||||
{...props}
|
||||
>
|
||||
<ArrowLeft />
|
||||
<span className="sr-only">Previous slide</span>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
function CarouselNext({
|
||||
className,
|
||||
variant = "outline",
|
||||
size = "icon",
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const { orientation, scrollNext, canScrollNext } = useCarousel()
|
||||
|
||||
return (
|
||||
<Button
|
||||
data-slot="carousel-next"
|
||||
variant={variant}
|
||||
size={size}
|
||||
className={cn(
|
||||
"absolute size-8 rounded-full",
|
||||
orientation === "horizontal"
|
||||
? "top-1/2 -right-12 -translate-y-1/2"
|
||||
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
||||
className
|
||||
)}
|
||||
disabled={!canScrollNext}
|
||||
onClick={scrollNext}
|
||||
{...props}
|
||||
>
|
||||
<ArrowRight />
|
||||
<span className="sr-only">Next slide</span>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
type CarouselApi,
|
||||
Carousel,
|
||||
CarouselContent,
|
||||
CarouselItem,
|
||||
CarouselPrevious,
|
||||
CarouselNext,
|
||||
}
|
||||
Executable
+353
@@ -0,0 +1,353 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as RechartsPrimitive from "recharts"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
// Format: { THEME_NAME: CSS_SELECTOR }
|
||||
const THEMES = { light: "", dark: ".dark" } as const
|
||||
|
||||
export type ChartConfig = {
|
||||
[k in string]: {
|
||||
label?: React.ReactNode
|
||||
icon?: React.ComponentType
|
||||
} & (
|
||||
| { color?: string; theme?: never }
|
||||
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
||||
)
|
||||
}
|
||||
|
||||
type ChartContextProps = {
|
||||
config: ChartConfig
|
||||
}
|
||||
|
||||
const ChartContext = React.createContext<ChartContextProps | null>(null)
|
||||
|
||||
function useChart() {
|
||||
const context = React.useContext(ChartContext)
|
||||
|
||||
if (!context) {
|
||||
throw new Error("useChart must be used within a <ChartContainer />")
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
function ChartContainer({
|
||||
id,
|
||||
className,
|
||||
children,
|
||||
config,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
config: ChartConfig
|
||||
children: React.ComponentProps<
|
||||
typeof RechartsPrimitive.ResponsiveContainer
|
||||
>["children"]
|
||||
}) {
|
||||
const uniqueId = React.useId()
|
||||
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
|
||||
|
||||
return (
|
||||
<ChartContext.Provider value={{ config }}>
|
||||
<div
|
||||
data-slot="chart"
|
||||
data-chart={chartId}
|
||||
className={cn(
|
||||
"[&_.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-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 flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChartStyle id={chartId} config={config} />
|
||||
<RechartsPrimitive.ResponsiveContainer>
|
||||
{children}
|
||||
</RechartsPrimitive.ResponsiveContainer>
|
||||
</div>
|
||||
</ChartContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
||||
const colorConfig = Object.entries(config).filter(
|
||||
([, config]) => config.theme || config.color
|
||||
)
|
||||
|
||||
if (!colorConfig.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<style
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: Object.entries(THEMES)
|
||||
.map(
|
||||
([theme, prefix]) => `
|
||||
${prefix} [data-chart=${id}] {
|
||||
${colorConfig
|
||||
.map(([key, itemConfig]) => {
|
||||
const color =
|
||||
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
||||
itemConfig.color
|
||||
return color ? ` --color-${key}: ${color};` : null
|
||||
})
|
||||
.join("\n")}
|
||||
}
|
||||
`
|
||||
)
|
||||
.join("\n"),
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const ChartTooltip = RechartsPrimitive.Tooltip
|
||||
|
||||
function ChartTooltipContent({
|
||||
active,
|
||||
payload,
|
||||
className,
|
||||
indicator = "dot",
|
||||
hideLabel = false,
|
||||
hideIndicator = false,
|
||||
label,
|
||||
labelFormatter,
|
||||
labelClassName,
|
||||
formatter,
|
||||
color,
|
||||
nameKey,
|
||||
labelKey,
|
||||
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
||||
React.ComponentProps<"div"> & {
|
||||
hideLabel?: boolean
|
||||
hideIndicator?: boolean
|
||||
indicator?: "line" | "dot" | "dashed"
|
||||
nameKey?: string
|
||||
labelKey?: string
|
||||
}) {
|
||||
const { config } = useChart()
|
||||
|
||||
const tooltipLabel = React.useMemo(() => {
|
||||
if (hideLabel || !payload?.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
const [item] = payload
|
||||
const key = `${labelKey || item?.dataKey || item?.name || "value"}`
|
||||
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
||||
const value =
|
||||
!labelKey && typeof label === "string"
|
||||
? config[label as keyof typeof config]?.label || label
|
||||
: itemConfig?.label
|
||||
|
||||
if (labelFormatter) {
|
||||
return (
|
||||
<div className={cn("font-medium", labelClassName)}>
|
||||
{labelFormatter(value, payload)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
return null
|
||||
}
|
||||
|
||||
return <div className={cn("font-medium", labelClassName)}>{value}</div>
|
||||
}, [
|
||||
label,
|
||||
labelFormatter,
|
||||
payload,
|
||||
hideLabel,
|
||||
labelClassName,
|
||||
config,
|
||||
labelKey,
|
||||
])
|
||||
|
||||
if (!active || !payload?.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
const nestLabel = payload.length === 1 && indicator !== "dot"
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",
|
||||
className
|
||||
)}
|
||||
>
|
||||
{!nestLabel ? tooltipLabel : null}
|
||||
<div className="grid gap-1.5">
|
||||
{payload.map((item, index) => {
|
||||
const key = `${nameKey || item.name || item.dataKey || "value"}`
|
||||
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
||||
const indicatorColor = color || item.payload.fill || item.color
|
||||
|
||||
return (
|
||||
<div
|
||||
key={item.dataKey}
|
||||
className={cn(
|
||||
"[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
|
||||
indicator === "dot" && "items-center"
|
||||
)}
|
||||
>
|
||||
{formatter && item?.value !== undefined && item.name ? (
|
||||
formatter(item.value, item.name, item, index, item.payload)
|
||||
) : (
|
||||
<>
|
||||
{itemConfig?.icon ? (
|
||||
<itemConfig.icon />
|
||||
) : (
|
||||
!hideIndicator && (
|
||||
<div
|
||||
className={cn(
|
||||
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
||||
{
|
||||
"h-2.5 w-2.5": indicator === "dot",
|
||||
"w-1": indicator === "line",
|
||||
"w-0 border-[1.5px] border-dashed bg-transparent":
|
||||
indicator === "dashed",
|
||||
"my-0.5": nestLabel && indicator === "dashed",
|
||||
}
|
||||
)}
|
||||
style={
|
||||
{
|
||||
"--color-bg": indicatorColor,
|
||||
"--color-border": indicatorColor,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-1 justify-between leading-none",
|
||||
nestLabel ? "items-end" : "items-center"
|
||||
)}
|
||||
>
|
||||
<div className="grid gap-1.5">
|
||||
{nestLabel ? tooltipLabel : null}
|
||||
<span className="text-muted-foreground">
|
||||
{itemConfig?.label || item.name}
|
||||
</span>
|
||||
</div>
|
||||
{item.value && (
|
||||
<span className="text-foreground font-mono font-medium tabular-nums">
|
||||
{item.value.toLocaleString()}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const ChartLegend = RechartsPrimitive.Legend
|
||||
|
||||
function ChartLegendContent({
|
||||
className,
|
||||
hideIcon = false,
|
||||
payload,
|
||||
verticalAlign = "bottom",
|
||||
nameKey,
|
||||
}: React.ComponentProps<"div"> &
|
||||
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
||||
hideIcon?: boolean
|
||||
nameKey?: string
|
||||
}) {
|
||||
const { config } = useChart()
|
||||
|
||||
if (!payload?.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center justify-center gap-4",
|
||||
verticalAlign === "top" ? "pb-3" : "pt-3",
|
||||
className
|
||||
)}
|
||||
>
|
||||
{payload.map((item) => {
|
||||
const key = `${nameKey || item.dataKey || "value"}`
|
||||
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
||||
|
||||
return (
|
||||
<div
|
||||
key={item.value}
|
||||
className={cn(
|
||||
"[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"
|
||||
)}
|
||||
>
|
||||
{itemConfig?.icon && !hideIcon ? (
|
||||
<itemConfig.icon />
|
||||
) : (
|
||||
<div
|
||||
className="h-2 w-2 shrink-0 rounded-[2px]"
|
||||
style={{
|
||||
backgroundColor: item.color,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{itemConfig?.label}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Helper to extract item config from a payload.
|
||||
function getPayloadConfigFromPayload(
|
||||
config: ChartConfig,
|
||||
payload: unknown,
|
||||
key: string
|
||||
) {
|
||||
if (typeof payload !== "object" || payload === null) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const payloadPayload =
|
||||
"payload" in payload &&
|
||||
typeof payload.payload === "object" &&
|
||||
payload.payload !== null
|
||||
? payload.payload
|
||||
: undefined
|
||||
|
||||
let configLabelKey: string = key
|
||||
|
||||
if (
|
||||
key in payload &&
|
||||
typeof payload[key as keyof typeof payload] === "string"
|
||||
) {
|
||||
configLabelKey = payload[key as keyof typeof payload] as string
|
||||
} else if (
|
||||
payloadPayload &&
|
||||
key in payloadPayload &&
|
||||
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
||||
) {
|
||||
configLabelKey = payloadPayload[
|
||||
key as keyof typeof payloadPayload
|
||||
] as string
|
||||
}
|
||||
|
||||
return configLabelKey in config
|
||||
? config[configLabelKey]
|
||||
: config[key as keyof typeof config]
|
||||
}
|
||||
|
||||
export {
|
||||
ChartContainer,
|
||||
ChartTooltip,
|
||||
ChartTooltipContent,
|
||||
ChartLegend,
|
||||
ChartLegendContent,
|
||||
ChartStyle,
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
||||
import { CheckIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Checkbox({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
||||
return (
|
||||
<CheckboxPrimitive.Root
|
||||
data-slot="checkbox"
|
||||
className={cn(
|
||||
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<CheckboxPrimitive.Indicator
|
||||
data-slot="checkbox-indicator"
|
||||
className="flex items-center justify-center text-current transition-none"
|
||||
>
|
||||
<CheckIcon className="size-3.5" />
|
||||
</CheckboxPrimitive.Indicator>
|
||||
</CheckboxPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Checkbox }
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
"use client"
|
||||
|
||||
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
|
||||
|
||||
function Collapsible({
|
||||
...props
|
||||
}: React.ComponentProps<typeof CollapsiblePrimitive.Root>) {
|
||||
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />
|
||||
}
|
||||
|
||||
function CollapsibleTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) {
|
||||
return (
|
||||
<CollapsiblePrimitive.CollapsibleTrigger
|
||||
data-slot="collapsible-trigger"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CollapsibleContent({
|
||||
...props
|
||||
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
|
||||
return (
|
||||
<CollapsiblePrimitive.CollapsibleContent
|
||||
data-slot="collapsible-content"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Collapsible, CollapsibleTrigger, CollapsibleContent }
|
||||
Executable
+184
@@ -0,0 +1,184 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Command as CommandPrimitive } from "cmdk"
|
||||
import { SearchIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog"
|
||||
|
||||
function Command({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive>) {
|
||||
return (
|
||||
<CommandPrimitive
|
||||
data-slot="command"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandDialog({
|
||||
title = "Command Palette",
|
||||
description = "Search for a command to run...",
|
||||
children,
|
||||
className,
|
||||
showCloseButton = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Dialog> & {
|
||||
title?: string
|
||||
description?: string
|
||||
className?: string
|
||||
showCloseButton?: boolean
|
||||
}) {
|
||||
return (
|
||||
<Dialog {...props}>
|
||||
<DialogHeader className="sr-only">
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<DialogDescription>{description}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogContent
|
||||
className={cn("overflow-hidden p-0", className)}
|
||||
showCloseButton={showCloseButton}
|
||||
>
|
||||
<Command className="[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[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">
|
||||
{children}
|
||||
</Command>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandInput({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="command-input-wrapper"
|
||||
className="flex h-9 items-center gap-2 border-b px-3"
|
||||
>
|
||||
<SearchIcon className="size-4 shrink-0 opacity-50" />
|
||||
<CommandPrimitive.Input
|
||||
data-slot="command-input"
|
||||
className={cn(
|
||||
"placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandList({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.List>) {
|
||||
return (
|
||||
<CommandPrimitive.List
|
||||
data-slot="command-list"
|
||||
className={cn(
|
||||
"max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandEmpty({
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
|
||||
return (
|
||||
<CommandPrimitive.Empty
|
||||
data-slot="command-empty"
|
||||
className="py-6 text-center text-sm"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandGroup({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
|
||||
return (
|
||||
<CommandPrimitive.Group
|
||||
data-slot="command-group"
|
||||
className={cn(
|
||||
"text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
|
||||
return (
|
||||
<CommandPrimitive.Separator
|
||||
data-slot="command-separator"
|
||||
className={cn("bg-border -mx-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
|
||||
return (
|
||||
<CommandPrimitive.Item
|
||||
data-slot="command-item"
|
||||
className={cn(
|
||||
"data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CommandShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="command-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Command,
|
||||
CommandDialog,
|
||||
CommandInput,
|
||||
CommandList,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandItem,
|
||||
CommandShortcut,
|
||||
CommandSeparator,
|
||||
}
|
||||
Executable
+252
@@ -0,0 +1,252 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as ContextMenuPrimitive from "@radix-ui/react-context-menu"
|
||||
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function ContextMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Root>) {
|
||||
return <ContextMenuPrimitive.Root data-slot="context-menu" {...props} />
|
||||
}
|
||||
|
||||
function ContextMenuTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Trigger data-slot="context-menu-trigger" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Group>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Group data-slot="context-menu-group" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Portal>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Portal data-slot="context-menu-portal" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Sub>) {
|
||||
return <ContextMenuPrimitive.Sub data-slot="context-menu-sub" {...props} />
|
||||
}
|
||||
|
||||
function ContextMenuRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.RadioGroup
|
||||
data-slot="context-menu-radio-group"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<ContextMenuPrimitive.SubTrigger
|
||||
data-slot="context-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto" />
|
||||
</ContextMenuPrimitive.SubTrigger>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.SubContent>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.SubContent
|
||||
data-slot="context-menu-sub-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground 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 z-50 min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Content>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Portal>
|
||||
<ContextMenuPrimitive.Content
|
||||
data-slot="context-menu-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground 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 z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</ContextMenuPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Item> & {
|
||||
inset?: boolean
|
||||
variant?: "default" | "destructive"
|
||||
}) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Item
|
||||
data-slot="context-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.CheckboxItem>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.CheckboxItem
|
||||
data-slot="context-menu-checkbox-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<ContextMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</ContextMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</ContextMenuPrimitive.CheckboxItem>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.RadioItem>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.RadioItem
|
||||
data-slot="context-menu-radio-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<ContextMenuPrimitive.ItemIndicator>
|
||||
<CircleIcon className="size-2 fill-current" />
|
||||
</ContextMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</ContextMenuPrimitive.RadioItem>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Label> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Label
|
||||
data-slot="context-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"text-foreground px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Separator>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Separator
|
||||
data-slot="context-menu-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="context-menu-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
ContextMenu,
|
||||
ContextMenuTrigger,
|
||||
ContextMenuContent,
|
||||
ContextMenuItem,
|
||||
ContextMenuCheckboxItem,
|
||||
ContextMenuRadioItem,
|
||||
ContextMenuLabel,
|
||||
ContextMenuSeparator,
|
||||
ContextMenuShortcut,
|
||||
ContextMenuGroup,
|
||||
ContextMenuPortal,
|
||||
ContextMenuSub,
|
||||
ContextMenuSubContent,
|
||||
ContextMenuSubTrigger,
|
||||
ContextMenuRadioGroup,
|
||||
}
|
||||
Executable
+143
@@ -0,0 +1,143 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog"
|
||||
import { XIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Dialog({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
||||
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
||||
}
|
||||
|
||||
function DialogTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
||||
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
||||
}
|
||||
|
||||
function DialogPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
||||
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
||||
}
|
||||
|
||||
function DialogClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
||||
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
||||
}
|
||||
|
||||
function DialogOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
||||
return (
|
||||
<DialogPrimitive.Overlay
|
||||
data-slot="dialog-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogContent({
|
||||
className,
|
||||
children,
|
||||
showCloseButton = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||
showCloseButton?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DialogPortal data-slot="dialog-portal">
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
data-slot="dialog-content"
|
||||
className={cn(
|
||||
"bg-background 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 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<DialogPrimitive.Close
|
||||
data-slot="dialog-close"
|
||||
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
||||
>
|
||||
<XIcon />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-header"
|
||||
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-footer"
|
||||
className={cn(
|
||||
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||
return (
|
||||
<DialogPrimitive.Title
|
||||
data-slot="dialog-title"
|
||||
className={cn("text-lg leading-none font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||
return (
|
||||
<DialogPrimitive.Description
|
||||
data-slot="dialog-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
}
|
||||
Executable
+135
@@ -0,0 +1,135 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Drawer as DrawerPrimitive } from "vaul"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Drawer({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Root>) {
|
||||
return <DrawerPrimitive.Root data-slot="drawer" {...props} />
|
||||
}
|
||||
|
||||
function DrawerTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Trigger>) {
|
||||
return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} />
|
||||
}
|
||||
|
||||
function DrawerPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Portal>) {
|
||||
return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props} />
|
||||
}
|
||||
|
||||
function DrawerClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Close>) {
|
||||
return <DrawerPrimitive.Close data-slot="drawer-close" {...props} />
|
||||
}
|
||||
|
||||
function DrawerOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Overlay>) {
|
||||
return (
|
||||
<DrawerPrimitive.Overlay
|
||||
data-slot="drawer-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Content>) {
|
||||
return (
|
||||
<DrawerPortal data-slot="drawer-portal">
|
||||
<DrawerOverlay />
|
||||
<DrawerPrimitive.Content
|
||||
data-slot="drawer-content"
|
||||
className={cn(
|
||||
"group/drawer-content bg-background fixed z-50 flex h-auto flex-col",
|
||||
"data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-lg data-[vaul-drawer-direction=top]:border-b",
|
||||
"data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-lg data-[vaul-drawer-direction=bottom]:border-t",
|
||||
"data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=right]:sm:max-w-sm",
|
||||
"data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=left]:sm:max-w-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className="bg-muted mx-auto mt-4 hidden h-2 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block" />
|
||||
{children}
|
||||
</DrawerPrimitive.Content>
|
||||
</DrawerPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="drawer-header"
|
||||
className={cn(
|
||||
"flex flex-col gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-1.5 md:text-left",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="drawer-footer"
|
||||
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Title>) {
|
||||
return (
|
||||
<DrawerPrimitive.Title
|
||||
data-slot="drawer-title"
|
||||
className={cn("text-foreground font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DrawerDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Description>) {
|
||||
return (
|
||||
<DrawerPrimitive.Description
|
||||
data-slot="drawer-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Drawer,
|
||||
DrawerPortal,
|
||||
DrawerOverlay,
|
||||
DrawerTrigger,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerHeader,
|
||||
DrawerFooter,
|
||||
DrawerTitle,
|
||||
DrawerDescription,
|
||||
}
|
||||
Executable
+257
@@ -0,0 +1,257 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
|
||||
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function DropdownMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Trigger
|
||||
data-slot="dropdown-menu-trigger"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuContent({
|
||||
className,
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
data-slot="dropdown-menu-content"
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground 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 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean
|
||||
variant?: "default" | "destructive"
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Item
|
||||
data-slot="dropdown-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.CheckboxItem
|
||||
data-slot="dropdown-menu-checkbox-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioGroup
|
||||
data-slot="dropdown-menu-radio-group"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioItem
|
||||
data-slot="dropdown-menu-radio-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CircleIcon className="size-2 fill-current" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Label
|
||||
data-slot="dropdown-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
data-slot="dropdown-menu-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="dropdown-menu-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
data-slot="dropdown-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto size-4" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
data-slot="dropdown-menu-sub-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground 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 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuSubContent,
|
||||
}
|
||||
Executable
+167
@@ -0,0 +1,167 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as LabelPrimitive from "@radix-ui/react-label"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import {
|
||||
Controller,
|
||||
FormProvider,
|
||||
useFormContext,
|
||||
useFormState,
|
||||
type ControllerProps,
|
||||
type FieldPath,
|
||||
type FieldValues,
|
||||
} from "react-hook-form"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Label } from "@/components/ui/label"
|
||||
|
||||
const Form = FormProvider
|
||||
|
||||
type FormFieldContextValue<
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
> = {
|
||||
name: TName
|
||||
}
|
||||
|
||||
const FormFieldContext = React.createContext<FormFieldContextValue>(
|
||||
{} as FormFieldContextValue
|
||||
)
|
||||
|
||||
const FormField = <
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
>({
|
||||
...props
|
||||
}: ControllerProps<TFieldValues, TName>) => {
|
||||
return (
|
||||
<FormFieldContext.Provider value={{ name: props.name }}>
|
||||
<Controller {...props} />
|
||||
</FormFieldContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
const useFormField = () => {
|
||||
const fieldContext = React.useContext(FormFieldContext)
|
||||
const itemContext = React.useContext(FormItemContext)
|
||||
const { getFieldState } = useFormContext()
|
||||
const formState = useFormState({ name: fieldContext.name })
|
||||
const fieldState = getFieldState(fieldContext.name, formState)
|
||||
|
||||
if (!fieldContext) {
|
||||
throw new Error("useFormField should be used within <FormField>")
|
||||
}
|
||||
|
||||
const { id } = itemContext
|
||||
|
||||
return {
|
||||
id,
|
||||
name: fieldContext.name,
|
||||
formItemId: `${id}-form-item`,
|
||||
formDescriptionId: `${id}-form-item-description`,
|
||||
formMessageId: `${id}-form-item-message`,
|
||||
...fieldState,
|
||||
}
|
||||
}
|
||||
|
||||
type FormItemContextValue = {
|
||||
id: string
|
||||
}
|
||||
|
||||
const FormItemContext = React.createContext<FormItemContextValue>(
|
||||
{} as FormItemContextValue
|
||||
)
|
||||
|
||||
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
|
||||
const id = React.useId()
|
||||
|
||||
return (
|
||||
<FormItemContext.Provider value={{ id }}>
|
||||
<div
|
||||
data-slot="form-item"
|
||||
className={cn("grid gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
</FormItemContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
function FormLabel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
const { error, formItemId } = useFormField()
|
||||
|
||||
return (
|
||||
<Label
|
||||
data-slot="form-label"
|
||||
data-error={!!error}
|
||||
className={cn("data-[error=true]:text-destructive", className)}
|
||||
htmlFor={formItemId}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
|
||||
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
|
||||
|
||||
return (
|
||||
<Slot
|
||||
data-slot="form-control"
|
||||
id={formItemId}
|
||||
aria-describedby={
|
||||
!error
|
||||
? `${formDescriptionId}`
|
||||
: `${formDescriptionId} ${formMessageId}`
|
||||
}
|
||||
aria-invalid={!!error}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||
const { formDescriptionId } = useFormField()
|
||||
|
||||
return (
|
||||
<p
|
||||
data-slot="form-description"
|
||||
id={formDescriptionId}
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
|
||||
const { error, formMessageId } = useFormField()
|
||||
const body = error ? String(error?.message ?? "") : props.children
|
||||
|
||||
if (!body) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<p
|
||||
data-slot="form-message"
|
||||
id={formMessageId}
|
||||
className={cn("text-destructive text-sm", className)}
|
||||
{...props}
|
||||
>
|
||||
{body}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
useFormField,
|
||||
Form,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormControl,
|
||||
FormDescription,
|
||||
FormMessage,
|
||||
FormField,
|
||||
}
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as HoverCardPrimitive from "@radix-ui/react-hover-card"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function HoverCard({
|
||||
...props
|
||||
}: React.ComponentProps<typeof HoverCardPrimitive.Root>) {
|
||||
return <HoverCardPrimitive.Root data-slot="hover-card" {...props} />
|
||||
}
|
||||
|
||||
function HoverCardTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof HoverCardPrimitive.Trigger>) {
|
||||
return (
|
||||
<HoverCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function HoverCardContent({
|
||||
className,
|
||||
align = "center",
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof HoverCardPrimitive.Content>) {
|
||||
return (
|
||||
<HoverCardPrimitive.Portal data-slot="hover-card-portal">
|
||||
<HoverCardPrimitive.Content
|
||||
data-slot="hover-card-content"
|
||||
align={align}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground 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 z-50 w-64 origin-(--radix-hover-card-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</HoverCardPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
export { HoverCard, HoverCardTrigger, HoverCardContent }
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { OTPInput, OTPInputContext } from "input-otp"
|
||||
import { MinusIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function InputOTP({
|
||||
className,
|
||||
containerClassName,
|
||||
...props
|
||||
}: React.ComponentProps<typeof OTPInput> & {
|
||||
containerClassName?: string
|
||||
}) {
|
||||
return (
|
||||
<OTPInput
|
||||
data-slot="input-otp"
|
||||
containerClassName={cn(
|
||||
"flex items-center gap-2 has-disabled:opacity-50",
|
||||
containerClassName
|
||||
)}
|
||||
className={cn("disabled:cursor-not-allowed", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function InputOTPGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="input-otp-group"
|
||||
className={cn("flex items-center", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function InputOTPSlot({
|
||||
index,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
index: number
|
||||
}) {
|
||||
const inputOTPContext = React.useContext(OTPInputContext)
|
||||
const { char, hasFakeCaret, isActive } = inputOTPContext?.slots[index] ?? {}
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="input-otp-slot"
|
||||
data-active={isActive}
|
||||
className={cn(
|
||||
"data-[active=true]:border-ring data-[active=true]:ring-ring/50 data-[active=true]:aria-invalid:ring-destructive/20 dark:data-[active=true]:aria-invalid:ring-destructive/40 aria-invalid:border-destructive data-[active=true]:aria-invalid:border-destructive dark:bg-input/30 border-input relative flex h-9 w-9 items-center justify-center border-y border-r text-sm shadow-xs transition-all outline-none first:rounded-l-md first:border-l last:rounded-r-md data-[active=true]:z-10 data-[active=true]:ring-[3px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{char}
|
||||
{hasFakeCaret && (
|
||||
<div className="pointer-events-none absolute inset-0 flex items-center justify-center">
|
||||
<div className="animate-caret-blink bg-foreground h-4 w-px duration-1000" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function InputOTPSeparator({ ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div data-slot="input-otp-separator" role="separator" {...props}>
|
||||
<MinusIcon />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export { InputOTP, InputOTPGroup, InputOTPSlot, InputOTPSeparator }
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Input }
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as LabelPrimitive from "@radix-ui/react-label"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Label({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
return (
|
||||
<LabelPrimitive.Root
|
||||
data-slot="label"
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Label }
|
||||
Executable
+276
@@ -0,0 +1,276 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as MenubarPrimitive from "@radix-ui/react-menubar"
|
||||
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Menubar({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Root>) {
|
||||
return (
|
||||
<MenubarPrimitive.Root
|
||||
data-slot="menubar"
|
||||
className={cn(
|
||||
"bg-background flex h-9 items-center gap-1 rounded-md border p-1 shadow-xs",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Menu>) {
|
||||
return <MenubarPrimitive.Menu data-slot="menubar-menu" {...props} />
|
||||
}
|
||||
|
||||
function MenubarGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Group>) {
|
||||
return <MenubarPrimitive.Group data-slot="menubar-group" {...props} />
|
||||
}
|
||||
|
||||
function MenubarPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Portal>) {
|
||||
return <MenubarPrimitive.Portal data-slot="menubar-portal" {...props} />
|
||||
}
|
||||
|
||||
function MenubarRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<MenubarPrimitive.RadioGroup data-slot="menubar-radio-group" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarTrigger({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Trigger>) {
|
||||
return (
|
||||
<MenubarPrimitive.Trigger
|
||||
data-slot="menubar-trigger"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex items-center rounded-sm px-2 py-1 text-sm font-medium outline-hidden select-none",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarContent({
|
||||
className,
|
||||
align = "start",
|
||||
alignOffset = -4,
|
||||
sideOffset = 8,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Content>) {
|
||||
return (
|
||||
<MenubarPortal>
|
||||
<MenubarPrimitive.Content
|
||||
data-slot="menubar-content"
|
||||
align={align}
|
||||
alignOffset={alignOffset}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in 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 z-50 min-w-[12rem] origin-(--radix-menubar-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-md",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</MenubarPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Item> & {
|
||||
inset?: boolean
|
||||
variant?: "default" | "destructive"
|
||||
}) {
|
||||
return (
|
||||
<MenubarPrimitive.Item
|
||||
data-slot="menubar-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.CheckboxItem>) {
|
||||
return (
|
||||
<MenubarPrimitive.CheckboxItem
|
||||
data-slot="menubar-checkbox-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-xs py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<MenubarPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</MenubarPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</MenubarPrimitive.CheckboxItem>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarRadioItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.RadioItem>) {
|
||||
return (
|
||||
<MenubarPrimitive.RadioItem
|
||||
data-slot="menubar-radio-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-xs py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<MenubarPrimitive.ItemIndicator>
|
||||
<CircleIcon className="size-2 fill-current" />
|
||||
</MenubarPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</MenubarPrimitive.RadioItem>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Label> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<MenubarPrimitive.Label
|
||||
data-slot="menubar-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Separator>) {
|
||||
return (
|
||||
<MenubarPrimitive.Separator
|
||||
data-slot="menubar-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="menubar-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.Sub>) {
|
||||
return <MenubarPrimitive.Sub data-slot="menubar-sub" {...props} />
|
||||
}
|
||||
|
||||
function MenubarSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.SubTrigger> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<MenubarPrimitive.SubTrigger
|
||||
data-slot="menubar-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none data-[inset]:pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto h-4 w-4" />
|
||||
</MenubarPrimitive.SubTrigger>
|
||||
)
|
||||
}
|
||||
|
||||
function MenubarSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof MenubarPrimitive.SubContent>) {
|
||||
return (
|
||||
<MenubarPrimitive.SubContent
|
||||
data-slot="menubar-sub-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground 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 z-50 min-w-[8rem] origin-(--radix-menubar-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Menubar,
|
||||
MenubarPortal,
|
||||
MenubarMenu,
|
||||
MenubarTrigger,
|
||||
MenubarContent,
|
||||
MenubarGroup,
|
||||
MenubarSeparator,
|
||||
MenubarLabel,
|
||||
MenubarItem,
|
||||
MenubarShortcut,
|
||||
MenubarCheckboxItem,
|
||||
MenubarRadioGroup,
|
||||
MenubarRadioItem,
|
||||
MenubarSub,
|
||||
MenubarSubTrigger,
|
||||
MenubarSubContent,
|
||||
}
|
||||
Executable
+168
@@ -0,0 +1,168 @@
|
||||
import * as React from "react"
|
||||
import * as NavigationMenuPrimitive from "@radix-ui/react-navigation-menu"
|
||||
import { cva } from "class-variance-authority"
|
||||
import { ChevronDownIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function NavigationMenu({
|
||||
className,
|
||||
children,
|
||||
viewport = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Root> & {
|
||||
viewport?: boolean
|
||||
}) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Root
|
||||
data-slot="navigation-menu"
|
||||
data-viewport={viewport}
|
||||
className={cn(
|
||||
"group/navigation-menu relative flex max-w-max flex-1 items-center justify-center",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{viewport && <NavigationMenuViewport />}
|
||||
</NavigationMenuPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
function NavigationMenuList({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.List>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.List
|
||||
data-slot="navigation-menu-list"
|
||||
className={cn(
|
||||
"group flex flex-1 list-none items-center justify-center gap-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function NavigationMenuItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Item>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Item
|
||||
data-slot="navigation-menu-item"
|
||||
className={cn("relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const navigationMenuTriggerStyle = cva(
|
||||
"group inline-flex h-9 w-max items-center justify-center rounded-md bg-background px-4 py-2 text-sm font-medium hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=open]:hover:bg-accent data-[state=open]:text-accent-foreground data-[state=open]:focus:bg-accent data-[state=open]:bg-accent/50 focus-visible:ring-ring/50 outline-none transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1"
|
||||
)
|
||||
|
||||
function NavigationMenuTrigger({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Trigger
|
||||
data-slot="navigation-menu-trigger"
|
||||
className={cn(navigationMenuTriggerStyle(), "group", className)}
|
||||
{...props}
|
||||
>
|
||||
{children}{" "}
|
||||
<ChevronDownIcon
|
||||
className="relative top-[1px] ml-1 size-3 transition duration-300 group-data-[state=open]:rotate-180"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</NavigationMenuPrimitive.Trigger>
|
||||
)
|
||||
}
|
||||
|
||||
function NavigationMenuContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Content>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Content
|
||||
data-slot="navigation-menu-content"
|
||||
className={cn(
|
||||
"data-[motion^=from-]:animate-in data-[motion^=to-]:animate-out data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52 data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52 top-0 left-0 w-full p-2 pr-2.5 md:absolute md:w-auto",
|
||||
"group-data-[viewport=false]/navigation-menu:bg-popover group-data-[viewport=false]/navigation-menu:text-popover-foreground group-data-[viewport=false]/navigation-menu:data-[state=open]:animate-in group-data-[viewport=false]/navigation-menu:data-[state=closed]:animate-out group-data-[viewport=false]/navigation-menu:data-[state=closed]:zoom-out-95 group-data-[viewport=false]/navigation-menu:data-[state=open]:zoom-in-95 group-data-[viewport=false]/navigation-menu:data-[state=open]:fade-in-0 group-data-[viewport=false]/navigation-menu:data-[state=closed]:fade-out-0 group-data-[viewport=false]/navigation-menu:top-full group-data-[viewport=false]/navigation-menu:mt-1.5 group-data-[viewport=false]/navigation-menu:overflow-hidden group-data-[viewport=false]/navigation-menu:rounded-md group-data-[viewport=false]/navigation-menu:border group-data-[viewport=false]/navigation-menu:shadow group-data-[viewport=false]/navigation-menu:duration-200 **:data-[slot=navigation-menu-link]:focus:ring-0 **:data-[slot=navigation-menu-link]:focus:outline-none",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function NavigationMenuViewport({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Viewport>) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"absolute top-full left-0 isolate z-50 flex justify-center"
|
||||
)}
|
||||
>
|
||||
<NavigationMenuPrimitive.Viewport
|
||||
data-slot="navigation-menu-viewport"
|
||||
className={cn(
|
||||
"origin-top-center bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-90 relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)] w-full overflow-hidden rounded-md border shadow md:w-[var(--radix-navigation-menu-viewport-width)]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function NavigationMenuLink({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Link>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Link
|
||||
data-slot="navigation-menu-link"
|
||||
className={cn(
|
||||
"data-[active=true]:focus:bg-accent data-[active=true]:hover:bg-accent data-[active=true]:bg-accent/50 data-[active=true]:text-accent-foreground hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring/50 [&_svg:not([class*='text-'])]:text-muted-foreground flex flex-col gap-1 rounded-sm p-2 text-sm transition-all outline-none focus-visible:ring-[3px] focus-visible:outline-1 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function NavigationMenuIndicator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof NavigationMenuPrimitive.Indicator>) {
|
||||
return (
|
||||
<NavigationMenuPrimitive.Indicator
|
||||
data-slot="navigation-menu-indicator"
|
||||
className={cn(
|
||||
"data-[state=visible]:animate-in data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:fade-in top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className="bg-border relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm shadow-md" />
|
||||
</NavigationMenuPrimitive.Indicator>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
NavigationMenu,
|
||||
NavigationMenuList,
|
||||
NavigationMenuItem,
|
||||
NavigationMenuContent,
|
||||
NavigationMenuTrigger,
|
||||
NavigationMenuLink,
|
||||
NavigationMenuIndicator,
|
||||
NavigationMenuViewport,
|
||||
navigationMenuTriggerStyle,
|
||||
}
|
||||
Executable
+127
@@ -0,0 +1,127 @@
|
||||
import * as React from "react"
|
||||
import {
|
||||
ChevronLeftIcon,
|
||||
ChevronRightIcon,
|
||||
MoreHorizontalIcon,
|
||||
} from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button, buttonVariants } from "@/components/ui/button"
|
||||
|
||||
function Pagination({ className, ...props }: React.ComponentProps<"nav">) {
|
||||
return (
|
||||
<nav
|
||||
role="navigation"
|
||||
aria-label="pagination"
|
||||
data-slot="pagination"
|
||||
className={cn("mx-auto flex w-full justify-center", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PaginationContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="pagination-content"
|
||||
className={cn("flex flex-row items-center gap-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PaginationItem({ ...props }: React.ComponentProps<"li">) {
|
||||
return <li data-slot="pagination-item" {...props} />
|
||||
}
|
||||
|
||||
type PaginationLinkProps = {
|
||||
isActive?: boolean
|
||||
} & Pick<React.ComponentProps<typeof Button>, "size"> &
|
||||
React.ComponentProps<"a">
|
||||
|
||||
function PaginationLink({
|
||||
className,
|
||||
isActive,
|
||||
size = "icon",
|
||||
...props
|
||||
}: PaginationLinkProps) {
|
||||
return (
|
||||
<a
|
||||
aria-current={isActive ? "page" : undefined}
|
||||
data-slot="pagination-link"
|
||||
data-active={isActive}
|
||||
className={cn(
|
||||
buttonVariants({
|
||||
variant: isActive ? "outline" : "ghost",
|
||||
size,
|
||||
}),
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PaginationPrevious({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PaginationLink>) {
|
||||
return (
|
||||
<PaginationLink
|
||||
aria-label="Go to previous page"
|
||||
size="default"
|
||||
className={cn("gap-1 px-2.5 sm:pl-2.5", className)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronLeftIcon />
|
||||
<span className="hidden sm:block">Previous</span>
|
||||
</PaginationLink>
|
||||
)
|
||||
}
|
||||
|
||||
function PaginationNext({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PaginationLink>) {
|
||||
return (
|
||||
<PaginationLink
|
||||
aria-label="Go to next page"
|
||||
size="default"
|
||||
className={cn("gap-1 px-2.5 sm:pr-2.5", className)}
|
||||
{...props}
|
||||
>
|
||||
<span className="hidden sm:block">Next</span>
|
||||
<ChevronRightIcon />
|
||||
</PaginationLink>
|
||||
)
|
||||
}
|
||||
|
||||
function PaginationEllipsis({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
aria-hidden
|
||||
data-slot="pagination-ellipsis"
|
||||
className={cn("flex size-9 items-center justify-center", className)}
|
||||
{...props}
|
||||
>
|
||||
<MoreHorizontalIcon className="size-4" />
|
||||
<span className="sr-only">More pages</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationLink,
|
||||
PaginationItem,
|
||||
PaginationPrevious,
|
||||
PaginationNext,
|
||||
PaginationEllipsis,
|
||||
}
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as PopoverPrimitive from "@radix-ui/react-popover"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Popover({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Root>) {
|
||||
return <PopoverPrimitive.Root data-slot="popover" {...props} />
|
||||
}
|
||||
|
||||
function PopoverTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
|
||||
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
|
||||
}
|
||||
|
||||
function PopoverContent({
|
||||
className,
|
||||
align = "center",
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Content>) {
|
||||
return (
|
||||
<PopoverPrimitive.Portal>
|
||||
<PopoverPrimitive.Content
|
||||
data-slot="popover-content"
|
||||
align={align}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground 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 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</PopoverPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function PopoverAnchor({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
|
||||
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />
|
||||
}
|
||||
|
||||
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as ProgressPrimitive from "@radix-ui/react-progress"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Progress({
|
||||
className,
|
||||
value,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ProgressPrimitive.Root>) {
|
||||
return (
|
||||
<ProgressPrimitive.Root
|
||||
data-slot="progress"
|
||||
className={cn(
|
||||
"bg-primary/20 relative h-2 w-full overflow-hidden rounded-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ProgressPrimitive.Indicator
|
||||
data-slot="progress-indicator"
|
||||
className="bg-primary h-full w-full flex-1 transition-all"
|
||||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
||||
/>
|
||||
</ProgressPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Progress }
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group"
|
||||
import { CircleIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function RadioGroup({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof RadioGroupPrimitive.Root>) {
|
||||
return (
|
||||
<RadioGroupPrimitive.Root
|
||||
data-slot="radio-group"
|
||||
className={cn("grid gap-3", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function RadioGroupItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof RadioGroupPrimitive.Item>) {
|
||||
return (
|
||||
<RadioGroupPrimitive.Item
|
||||
data-slot="radio-group-item"
|
||||
className={cn(
|
||||
"border-input text-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 aspect-square size-4 shrink-0 rounded-full border shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<RadioGroupPrimitive.Indicator
|
||||
data-slot="radio-group-indicator"
|
||||
className="relative flex items-center justify-center"
|
||||
>
|
||||
<CircleIcon className="fill-primary absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2" />
|
||||
</RadioGroupPrimitive.Indicator>
|
||||
</RadioGroupPrimitive.Item>
|
||||
)
|
||||
}
|
||||
|
||||
export { RadioGroup, RadioGroupItem }
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { GripVerticalIcon } from "lucide-react"
|
||||
import * as ResizablePrimitive from "react-resizable-panels"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function ResizablePanelGroup({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ResizablePrimitive.PanelGroup>) {
|
||||
return (
|
||||
<ResizablePrimitive.PanelGroup
|
||||
data-slot="resizable-panel-group"
|
||||
className={cn(
|
||||
"flex h-full w-full data-[panel-group-direction=vertical]:flex-col",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ResizablePanel({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ResizablePrimitive.Panel>) {
|
||||
return <ResizablePrimitive.Panel data-slot="resizable-panel" {...props} />
|
||||
}
|
||||
|
||||
function ResizableHandle({
|
||||
withHandle,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ResizablePrimitive.PanelResizeHandle> & {
|
||||
withHandle?: boolean
|
||||
}) {
|
||||
return (
|
||||
<ResizablePrimitive.PanelResizeHandle
|
||||
data-slot="resizable-handle"
|
||||
className={cn(
|
||||
"bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-hidden data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:translate-x-0 data-[panel-group-direction=vertical]:after:-translate-y-1/2 [&[data-panel-group-direction=vertical]>div]:rotate-90",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{withHandle && (
|
||||
<div className="bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border">
|
||||
<GripVerticalIcon className="size-2.5" />
|
||||
</div>
|
||||
)}
|
||||
</ResizablePrimitive.PanelResizeHandle>
|
||||
)
|
||||
}
|
||||
|
||||
export { ResizablePanelGroup, ResizablePanel, ResizableHandle }
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function ScrollArea({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
|
||||
return (
|
||||
<ScrollAreaPrimitive.Root
|
||||
data-slot="scroll-area"
|
||||
className={cn("relative", className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport
|
||||
data-slot="scroll-area-viewport"
|
||||
className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
|
||||
>
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
function ScrollBar({
|
||||
className,
|
||||
orientation = "vertical",
|
||||
...props
|
||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
|
||||
return (
|
||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||
data-slot="scroll-area-scrollbar"
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"flex touch-none p-px transition-colors select-none",
|
||||
orientation === "vertical" &&
|
||||
"h-full w-2.5 border-l border-l-transparent",
|
||||
orientation === "horizontal" &&
|
||||
"h-2.5 flex-col border-t border-t-transparent",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.ScrollAreaThumb
|
||||
data-slot="scroll-area-thumb"
|
||||
className="bg-border relative flex-1 rounded-full"
|
||||
/>
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
)
|
||||
}
|
||||
|
||||
export { ScrollArea, ScrollBar }
|
||||
Executable
+185
@@ -0,0 +1,185 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SelectPrimitive from "@radix-ui/react-select"
|
||||
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Select({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||
return <SelectPrimitive.Root data-slot="select" {...props} />
|
||||
}
|
||||
|
||||
function SelectGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||
return <SelectPrimitive.Group data-slot="select-group" {...props} />
|
||||
}
|
||||
|
||||
function SelectValue({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||
return <SelectPrimitive.Value data-slot="select-value" {...props} />
|
||||
}
|
||||
|
||||
function SelectTrigger({
|
||||
className,
|
||||
size = "default",
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||
size?: "sm" | "default"
|
||||
}) {
|
||||
return (
|
||||
<SelectPrimitive.Trigger
|
||||
data-slot="select-trigger"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon asChild>
|
||||
<ChevronDownIcon className="size-4 opacity-50" />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectContent({
|
||||
className,
|
||||
children,
|
||||
position = "popper",
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||
return (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Content
|
||||
data-slot="select-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground 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 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
|
||||
position === "popper" &&
|
||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||
className
|
||||
)}
|
||||
position={position}
|
||||
{...props}
|
||||
>
|
||||
<SelectScrollUpButton />
|
||||
<SelectPrimitive.Viewport
|
||||
className={cn(
|
||||
"p-1",
|
||||
position === "popper" &&
|
||||
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</SelectPrimitive.Viewport>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectLabel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||
return (
|
||||
<SelectPrimitive.Label
|
||||
data-slot="select-label"
|
||||
className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||
return (
|
||||
<SelectPrimitive.Item
|
||||
data-slot="select-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute right-2 flex size-3.5 items-center justify-center">
|
||||
<SelectPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</span>
|
||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||
return (
|
||||
<SelectPrimitive.Separator
|
||||
data-slot="select-separator"
|
||||
className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollUpButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollUpButton
|
||||
data-slot="select-scroll-up-button"
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronUpIcon className="size-4" />
|
||||
</SelectPrimitive.ScrollUpButton>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollDownButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollDownButton
|
||||
data-slot="select-scroll-down-button"
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronDownIcon className="size-4" />
|
||||
</SelectPrimitive.ScrollDownButton>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectScrollDownButton,
|
||||
SelectScrollUpButton,
|
||||
SelectSeparator,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
}
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SeparatorPrimitive from "@radix-ui/react-separator"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Separator({
|
||||
className,
|
||||
orientation = "horizontal",
|
||||
decorative = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
|
||||
return (
|
||||
<SeparatorPrimitive.Root
|
||||
data-slot="separator"
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Separator }
|
||||
Executable
+139
@@ -0,0 +1,139 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SheetPrimitive from "@radix-ui/react-dialog"
|
||||
import { XIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
|
||||
return <SheetPrimitive.Root data-slot="sheet" {...props} />
|
||||
}
|
||||
|
||||
function SheetTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Trigger>) {
|
||||
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />
|
||||
}
|
||||
|
||||
function SheetClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Close>) {
|
||||
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />
|
||||
}
|
||||
|
||||
function SheetPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Portal>) {
|
||||
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />
|
||||
}
|
||||
|
||||
function SheetOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Overlay>) {
|
||||
return (
|
||||
<SheetPrimitive.Overlay
|
||||
data-slot="sheet-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetContent({
|
||||
className,
|
||||
children,
|
||||
side = "right",
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
|
||||
side?: "top" | "right" | "bottom" | "left"
|
||||
}) {
|
||||
return (
|
||||
<SheetPortal>
|
||||
<SheetOverlay />
|
||||
<SheetPrimitive.Content
|
||||
data-slot="sheet-content"
|
||||
className={cn(
|
||||
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
|
||||
side === "right" &&
|
||||
"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",
|
||||
side === "left" &&
|
||||
"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",
|
||||
side === "top" &&
|
||||
"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",
|
||||
side === "bottom" &&
|
||||
"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none">
|
||||
<XIcon className="size-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</SheetPrimitive.Close>
|
||||
</SheetPrimitive.Content>
|
||||
</SheetPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sheet-header"
|
||||
className={cn("flex flex-col gap-1.5 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sheet-footer"
|
||||
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Title>) {
|
||||
return (
|
||||
<SheetPrimitive.Title
|
||||
data-slot="sheet-title"
|
||||
className={cn("text-foreground font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Description>) {
|
||||
return (
|
||||
<SheetPrimitive.Description
|
||||
data-slot="sheet-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Sheet,
|
||||
SheetTrigger,
|
||||
SheetClose,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetFooter,
|
||||
SheetTitle,
|
||||
SheetDescription,
|
||||
}
|
||||
Executable
+726
@@ -0,0 +1,726 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, VariantProps } from "class-variance-authority"
|
||||
import { PanelLeftIcon } from "lucide-react"
|
||||
|
||||
import { useIsMobile } from "@/hooks/use-mobile"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetDescription,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip"
|
||||
|
||||
const SIDEBAR_COOKIE_NAME = "sidebar_state"
|
||||
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
||||
const SIDEBAR_WIDTH = "16rem"
|
||||
const SIDEBAR_WIDTH_MOBILE = "18rem"
|
||||
const SIDEBAR_WIDTH_ICON = "3rem"
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = "b"
|
||||
|
||||
type SidebarContextProps = {
|
||||
state: "expanded" | "collapsed"
|
||||
open: boolean
|
||||
setOpen: (open: boolean) => void
|
||||
openMobile: boolean
|
||||
setOpenMobile: (open: boolean) => void
|
||||
isMobile: boolean
|
||||
toggleSidebar: () => void
|
||||
}
|
||||
|
||||
const SidebarContext = React.createContext<SidebarContextProps | null>(null)
|
||||
|
||||
function useSidebar() {
|
||||
const context = React.useContext(SidebarContext)
|
||||
if (!context) {
|
||||
throw new Error("useSidebar must be used within a SidebarProvider.")
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
function SidebarProvider({
|
||||
defaultOpen = true,
|
||||
open: openProp,
|
||||
onOpenChange: setOpenProp,
|
||||
className,
|
||||
style,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
defaultOpen?: boolean
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
}) {
|
||||
const isMobile = useIsMobile()
|
||||
const [openMobile, setOpenMobile] = React.useState(false)
|
||||
|
||||
// This is the internal state of the sidebar.
|
||||
// We use openProp and setOpenProp for control from outside the component.
|
||||
const [_open, _setOpen] = React.useState(defaultOpen)
|
||||
const open = openProp ?? _open
|
||||
const setOpen = React.useCallback(
|
||||
(value: boolean | ((value: boolean) => boolean)) => {
|
||||
const openState = typeof value === "function" ? value(open) : value
|
||||
if (setOpenProp) {
|
||||
setOpenProp(openState)
|
||||
} else {
|
||||
_setOpen(openState)
|
||||
}
|
||||
|
||||
// This sets the cookie to keep the sidebar state.
|
||||
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
|
||||
},
|
||||
[setOpenProp, open]
|
||||
)
|
||||
|
||||
// Helper to toggle the sidebar.
|
||||
const toggleSidebar = React.useCallback(() => {
|
||||
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open)
|
||||
}, [isMobile, setOpen, setOpenMobile])
|
||||
|
||||
// Adds a keyboard shortcut to toggle the sidebar.
|
||||
React.useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (
|
||||
event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
|
||||
(event.metaKey || event.ctrlKey)
|
||||
) {
|
||||
event.preventDefault()
|
||||
toggleSidebar()
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown)
|
||||
return () => window.removeEventListener("keydown", handleKeyDown)
|
||||
}, [toggleSidebar])
|
||||
|
||||
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||
// This makes it easier to style the sidebar with Tailwind classes.
|
||||
const state = open ? "expanded" : "collapsed"
|
||||
|
||||
const contextValue = React.useMemo<SidebarContextProps>(
|
||||
() => ({
|
||||
state,
|
||||
open,
|
||||
setOpen,
|
||||
isMobile,
|
||||
openMobile,
|
||||
setOpenMobile,
|
||||
toggleSidebar,
|
||||
}),
|
||||
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
|
||||
)
|
||||
|
||||
return (
|
||||
<SidebarContext.Provider value={contextValue}>
|
||||
<TooltipProvider delayDuration={0}>
|
||||
<div
|
||||
data-slot="sidebar-wrapper"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH,
|
||||
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
||||
...style,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
className={cn(
|
||||
"group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
</SidebarContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
function Sidebar({
|
||||
side = "left",
|
||||
variant = "sidebar",
|
||||
collapsible = "offcanvas",
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
side?: "left" | "right"
|
||||
variant?: "sidebar" | "floating" | "inset"
|
||||
collapsible?: "offcanvas" | "icon" | "none"
|
||||
}) {
|
||||
const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
|
||||
|
||||
if (collapsible === "none") {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar"
|
||||
className={cn(
|
||||
"bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
|
||||
<SheetContent
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar"
|
||||
data-mobile="true"
|
||||
className="bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
side={side}
|
||||
>
|
||||
<SheetHeader className="sr-only">
|
||||
<SheetTitle>Sidebar</SheetTitle>
|
||||
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
||||
</SheetHeader>
|
||||
<div className="flex h-full w-full flex-col">{children}</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="group peer text-sidebar-foreground hidden md:block"
|
||||
data-state={state}
|
||||
data-collapsible={state === "collapsed" ? collapsible : ""}
|
||||
data-variant={variant}
|
||||
data-side={side}
|
||||
data-slot="sidebar"
|
||||
>
|
||||
{/* This is what handles the sidebar gap on desktop */}
|
||||
<div
|
||||
data-slot="sidebar-gap"
|
||||
className={cn(
|
||||
"relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
|
||||
"group-data-[collapsible=offcanvas]:w-0",
|
||||
"group-data-[side=right]:rotate-180",
|
||||
variant === "floating" || variant === "inset"
|
||||
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
|
||||
)}
|
||||
/>
|
||||
<div
|
||||
data-slot="sidebar-container"
|
||||
className={cn(
|
||||
"fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",
|
||||
side === "left"
|
||||
? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
|
||||
: "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
|
||||
// Adjust the padding for floating and inset variants.
|
||||
variant === "floating" || variant === "inset"
|
||||
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar-inner"
|
||||
className="bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow-sm"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarTrigger({
|
||||
className,
|
||||
onClick,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const { toggleSidebar } = useSidebar()
|
||||
|
||||
return (
|
||||
<Button
|
||||
data-sidebar="trigger"
|
||||
data-slot="sidebar-trigger"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={cn("size-7", className)}
|
||||
onClick={(event) => {
|
||||
onClick?.(event)
|
||||
toggleSidebar()
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<PanelLeftIcon />
|
||||
<span className="sr-only">Toggle Sidebar</span>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
||||
const { toggleSidebar } = useSidebar()
|
||||
|
||||
return (
|
||||
<button
|
||||
data-sidebar="rail"
|
||||
data-slot="sidebar-rail"
|
||||
aria-label="Toggle Sidebar"
|
||||
tabIndex={-1}
|
||||
onClick={toggleSidebar}
|
||||
title="Toggle Sidebar"
|
||||
className={cn(
|
||||
"hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex",
|
||||
"in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
|
||||
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
||||
"hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
|
||||
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
||||
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
|
||||
return (
|
||||
<main
|
||||
data-slot="sidebar-inset"
|
||||
className={cn(
|
||||
"bg-background relative flex w-full flex-1 flex-col",
|
||||
"md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarInput({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Input>) {
|
||||
return (
|
||||
<Input
|
||||
data-slot="sidebar-input"
|
||||
data-sidebar="input"
|
||||
className={cn("bg-background h-8 w-full shadow-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-header"
|
||||
data-sidebar="header"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-footer"
|
||||
data-sidebar="footer"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Separator>) {
|
||||
return (
|
||||
<Separator
|
||||
data-slot="sidebar-separator"
|
||||
data-sidebar="separator"
|
||||
className={cn("bg-sidebar-border mx-2 w-auto", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-content"
|
||||
data-sidebar="content"
|
||||
className={cn(
|
||||
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-group"
|
||||
data-sidebar="group"
|
||||
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroupLabel({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "div"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-group-label"
|
||||
data-sidebar="group-label"
|
||||
className={cn(
|
||||
"text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroupAction({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-group-action"
|
||||
data-sidebar="group-action"
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 md:after:hidden",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroupContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-group-content"
|
||||
data-sidebar="group-content"
|
||||
className={cn("w-full text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="sidebar-menu"
|
||||
data-sidebar="menu"
|
||||
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="sidebar-menu-item"
|
||||
data-sidebar="menu-item"
|
||||
className={cn("group/menu-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const sidebarMenuButtonVariants = cva(
|
||||
"peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
||||
outline:
|
||||
"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
|
||||
},
|
||||
size: {
|
||||
default: "h-8 text-sm",
|
||||
sm: "h-7 text-xs",
|
||||
lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function SidebarMenuButton({
|
||||
asChild = false,
|
||||
isActive = false,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
tooltip,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
asChild?: boolean
|
||||
isActive?: boolean
|
||||
tooltip?: string | React.ComponentProps<typeof TooltipContent>
|
||||
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
const { isMobile, state } = useSidebar()
|
||||
|
||||
const button = (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-button"
|
||||
data-sidebar="menu-button"
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
|
||||
if (!tooltip) {
|
||||
return button
|
||||
}
|
||||
|
||||
if (typeof tooltip === "string") {
|
||||
tooltip = {
|
||||
children: tooltip,
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="right"
|
||||
align="center"
|
||||
hidden={state !== "collapsed" || isMobile}
|
||||
{...tooltip}
|
||||
/>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuAction({
|
||||
className,
|
||||
asChild = false,
|
||||
showOnHover = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
asChild?: boolean
|
||||
showOnHover?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-action"
|
||||
data-sidebar="menu-action"
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 md:after:hidden",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
showOnHover &&
|
||||
"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuBadge({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-menu-badge"
|
||||
data-sidebar="menu-badge"
|
||||
className={cn(
|
||||
"text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none",
|
||||
"peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSkeleton({
|
||||
className,
|
||||
showIcon = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
showIcon?: boolean
|
||||
}) {
|
||||
// Random width between 50 to 90%.
|
||||
const width = React.useMemo(() => {
|
||||
return `${Math.floor(Math.random() * 40) + 50}%`
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-menu-skeleton"
|
||||
data-sidebar="menu-skeleton"
|
||||
className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
|
||||
{...props}
|
||||
>
|
||||
{showIcon && (
|
||||
<Skeleton
|
||||
className="size-4 rounded-md"
|
||||
data-sidebar="menu-skeleton-icon"
|
||||
/>
|
||||
)}
|
||||
<Skeleton
|
||||
className="h-4 max-w-(--skeleton-width) flex-1"
|
||||
data-sidebar="menu-skeleton-text"
|
||||
style={
|
||||
{
|
||||
"--skeleton-width": width,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="sidebar-menu-sub"
|
||||
data-sidebar="menu-sub"
|
||||
className={cn(
|
||||
"border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSubItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="sidebar-menu-sub-item"
|
||||
data-sidebar="menu-sub-item"
|
||||
className={cn("group/menu-sub-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSubButton({
|
||||
asChild = false,
|
||||
size = "md",
|
||||
isActive = false,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"a"> & {
|
||||
asChild?: boolean
|
||||
size?: "sm" | "md"
|
||||
isActive?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "a"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-sub-button"
|
||||
data-sidebar="menu-sub-button"
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-hidden focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
|
||||
size === "sm" && "text-xs",
|
||||
size === "md" && "text-sm",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarGroup,
|
||||
SidebarGroupAction,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
SidebarInput,
|
||||
SidebarInset,
|
||||
SidebarMenu,
|
||||
SidebarMenuAction,
|
||||
SidebarMenuBadge,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
SidebarMenuSkeleton,
|
||||
SidebarMenuSub,
|
||||
SidebarMenuSubButton,
|
||||
SidebarMenuSubItem,
|
||||
SidebarProvider,
|
||||
SidebarRail,
|
||||
SidebarSeparator,
|
||||
SidebarTrigger,
|
||||
useSidebar,
|
||||
}
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="skeleton"
|
||||
className={cn("bg-accent animate-pulse rounded-md", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Skeleton }
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SliderPrimitive from "@radix-ui/react-slider"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Slider({
|
||||
className,
|
||||
defaultValue,
|
||||
value,
|
||||
min = 0,
|
||||
max = 100,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SliderPrimitive.Root>) {
|
||||
const _values = React.useMemo(
|
||||
() =>
|
||||
Array.isArray(value)
|
||||
? value
|
||||
: Array.isArray(defaultValue)
|
||||
? defaultValue
|
||||
: [min, max],
|
||||
[value, defaultValue, min, max]
|
||||
)
|
||||
|
||||
return (
|
||||
<SliderPrimitive.Root
|
||||
data-slot="slider"
|
||||
defaultValue={defaultValue}
|
||||
value={value}
|
||||
min={min}
|
||||
max={max}
|
||||
className={cn(
|
||||
"relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<SliderPrimitive.Track
|
||||
data-slot="slider-track"
|
||||
className={cn(
|
||||
"bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
|
||||
)}
|
||||
>
|
||||
<SliderPrimitive.Range
|
||||
data-slot="slider-range"
|
||||
className={cn(
|
||||
"bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
|
||||
)}
|
||||
/>
|
||||
</SliderPrimitive.Track>
|
||||
{Array.from({ length: _values.length }, (_, index) => (
|
||||
<SliderPrimitive.Thumb
|
||||
data-slot="slider-thumb"
|
||||
key={index}
|
||||
className="border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
|
||||
/>
|
||||
))}
|
||||
</SliderPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Slider }
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
"use client"
|
||||
|
||||
import { useTheme } from "next-themes"
|
||||
import { Toaster as Sonner, ToasterProps } from "sonner"
|
||||
|
||||
const Toaster = ({ ...props }: ToasterProps) => {
|
||||
const { theme = "system" } = useTheme()
|
||||
|
||||
return (
|
||||
<Sonner
|
||||
theme={theme as ToasterProps["theme"]}
|
||||
className="toaster group"
|
||||
style={
|
||||
{
|
||||
"--normal-bg": "var(--popover)",
|
||||
"--normal-text": "var(--popover-foreground)",
|
||||
"--normal-border": "var(--border)",
|
||||
} as React.CSSProperties
|
||||
}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Toaster }
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SwitchPrimitive from "@radix-ui/react-switch"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Switch({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SwitchPrimitive.Root>) {
|
||||
return (
|
||||
<SwitchPrimitive.Root
|
||||
data-slot="switch"
|
||||
className={cn(
|
||||
"peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<SwitchPrimitive.Thumb
|
||||
data-slot="switch-thumb"
|
||||
className={cn(
|
||||
"bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0"
|
||||
)}
|
||||
/>
|
||||
</SwitchPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Switch }
|
||||
Executable
+116
@@ -0,0 +1,116 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Table({ className, ...props }: React.ComponentProps<"table">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="table-container"
|
||||
className="relative w-full overflow-x-auto"
|
||||
>
|
||||
<table
|
||||
data-slot="table"
|
||||
className={cn("w-full caption-bottom text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
||||
return (
|
||||
<thead
|
||||
data-slot="table-header"
|
||||
className={cn("[&_tr]:border-b", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
||||
return (
|
||||
<tbody
|
||||
data-slot="table-body"
|
||||
className={cn("[&_tr:last-child]:border-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
||||
return (
|
||||
<tfoot
|
||||
data-slot="table-footer"
|
||||
className={cn(
|
||||
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
||||
return (
|
||||
<tr
|
||||
data-slot="table-row"
|
||||
className={cn(
|
||||
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
||||
return (
|
||||
<th
|
||||
data-slot="table-head"
|
||||
className={cn(
|
||||
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
||||
return (
|
||||
<td
|
||||
data-slot="table-cell"
|
||||
className={cn(
|
||||
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableCaption({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"caption">) {
|
||||
return (
|
||||
<caption
|
||||
data-slot="table-caption"
|
||||
className={cn("text-muted-foreground mt-4 text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableFooter,
|
||||
TableHead,
|
||||
TableRow,
|
||||
TableCell,
|
||||
TableCaption,
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Tabs({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
|
||||
return (
|
||||
<TabsPrimitive.Root
|
||||
data-slot="tabs"
|
||||
className={cn("flex flex-col gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsList({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.List>) {
|
||||
return (
|
||||
<TabsPrimitive.List
|
||||
data-slot="tabs-list"
|
||||
className={cn(
|
||||
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsTrigger({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
|
||||
return (
|
||||
<TabsPrimitive.Trigger
|
||||
data-slot="tabs-trigger"
|
||||
className={cn(
|
||||
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Content>) {
|
||||
return (
|
||||
<TabsPrimitive.Content
|
||||
data-slot="tabs-content"
|
||||
className={cn("flex-1 outline-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||
return (
|
||||
<textarea
|
||||
data-slot="textarea"
|
||||
className={cn(
|
||||
"border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Textarea }
|
||||
Executable
+129
@@ -0,0 +1,129 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as ToastPrimitives from "@radix-ui/react-toast"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
import { X } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const ToastProvider = ToastPrimitives.Provider
|
||||
|
||||
const ToastViewport = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Viewport
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed top-14 z-[90] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
|
||||
|
||||
const toastVariants = cva(
|
||||
"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "border bg-background text-foreground",
|
||||
destructive:
|
||||
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const Toast = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
||||
VariantProps<typeof toastVariants>
|
||||
>(({ className, variant, ...props }, ref) => {
|
||||
return (
|
||||
<ToastPrimitives.Root
|
||||
ref={ref}
|
||||
className={cn(toastVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
})
|
||||
Toast.displayName = ToastPrimitives.Root.displayName
|
||||
|
||||
const ToastAction = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Action>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Action
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
ToastAction.displayName = ToastPrimitives.Action.displayName
|
||||
|
||||
const ToastClose = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Close>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Close
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
||||
className
|
||||
)}
|
||||
toast-close=""
|
||||
{...props}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</ToastPrimitives.Close>
|
||||
))
|
||||
ToastClose.displayName = ToastPrimitives.Close.displayName
|
||||
|
||||
const ToastTitle = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Title
|
||||
ref={ref}
|
||||
className={cn("text-sm font-semibold [&+div]:text-xs", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
ToastTitle.displayName = ToastPrimitives.Title.displayName
|
||||
|
||||
const ToastDescription = React.forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm opacity-90", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
ToastDescription.displayName = ToastPrimitives.Description.displayName
|
||||
|
||||
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
|
||||
|
||||
type ToastActionElement = React.ReactElement<typeof ToastAction>
|
||||
|
||||
export {
|
||||
type ToastProps,
|
||||
type ToastActionElement,
|
||||
ToastProvider,
|
||||
ToastViewport,
|
||||
Toast,
|
||||
ToastTitle,
|
||||
ToastDescription,
|
||||
ToastClose,
|
||||
ToastAction,
|
||||
}
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
"use client"
|
||||
|
||||
import { useToast } from "@/hooks/use-toast"
|
||||
import {
|
||||
Toast,
|
||||
ToastClose,
|
||||
ToastDescription,
|
||||
ToastProvider,
|
||||
ToastTitle,
|
||||
ToastViewport,
|
||||
} from "@/components/ui/toast"
|
||||
|
||||
export function Toaster() {
|
||||
const { toasts } = useToast()
|
||||
|
||||
return (
|
||||
<ToastProvider>
|
||||
{toasts.map(function ({ id, title, description, action, ...props }) {
|
||||
return (
|
||||
<Toast key={id} {...props}>
|
||||
<div className="grid gap-1">
|
||||
{title && <ToastTitle>{title}</ToastTitle>}
|
||||
{description && (
|
||||
<ToastDescription>{description}</ToastDescription>
|
||||
)}
|
||||
</div>
|
||||
{action}
|
||||
<ToastClose />
|
||||
</Toast>
|
||||
)
|
||||
})}
|
||||
<ToastViewport />
|
||||
</ToastProvider>
|
||||
)
|
||||
}
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group"
|
||||
import { type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { toggleVariants } from "@/components/ui/toggle"
|
||||
|
||||
const ToggleGroupContext = React.createContext<
|
||||
VariantProps<typeof toggleVariants>
|
||||
>({
|
||||
size: "default",
|
||||
variant: "default",
|
||||
})
|
||||
|
||||
function ToggleGroup({
|
||||
className,
|
||||
variant,
|
||||
size,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ToggleGroupPrimitive.Root> &
|
||||
VariantProps<typeof toggleVariants>) {
|
||||
return (
|
||||
<ToggleGroupPrimitive.Root
|
||||
data-slot="toggle-group"
|
||||
data-variant={variant}
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"group/toggle-group flex w-fit items-center rounded-md data-[variant=outline]:shadow-xs",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ToggleGroupContext.Provider value={{ variant, size }}>
|
||||
{children}
|
||||
</ToggleGroupContext.Provider>
|
||||
</ToggleGroupPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
function ToggleGroupItem({
|
||||
className,
|
||||
children,
|
||||
variant,
|
||||
size,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ToggleGroupPrimitive.Item> &
|
||||
VariantProps<typeof toggleVariants>) {
|
||||
const context = React.useContext(ToggleGroupContext)
|
||||
|
||||
return (
|
||||
<ToggleGroupPrimitive.Item
|
||||
data-slot="toggle-group-item"
|
||||
data-variant={context.variant || variant}
|
||||
data-size={context.size || size}
|
||||
className={cn(
|
||||
toggleVariants({
|
||||
variant: context.variant || variant,
|
||||
size: context.size || size,
|
||||
}),
|
||||
"min-w-0 flex-1 shrink-0 rounded-none shadow-none first:rounded-l-md last:rounded-r-md focus:z-10 focus-visible:z-10 data-[variant=outline]:border-l-0 data-[variant=outline]:first:border-l",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</ToggleGroupPrimitive.Item>
|
||||
)
|
||||
}
|
||||
|
||||
export { ToggleGroup, ToggleGroupItem }
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as TogglePrimitive from "@radix-ui/react-toggle"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const toggleVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium hover:bg-muted hover:text-muted-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] outline-none transition-[color,box-shadow] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-transparent",
|
||||
outline:
|
||||
"border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground",
|
||||
},
|
||||
size: {
|
||||
default: "h-9 px-2 min-w-9",
|
||||
sm: "h-8 px-1.5 min-w-8",
|
||||
lg: "h-10 px-2.5 min-w-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Toggle({
|
||||
className,
|
||||
variant,
|
||||
size,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TogglePrimitive.Root> &
|
||||
VariantProps<typeof toggleVariants>) {
|
||||
return (
|
||||
<TogglePrimitive.Root
|
||||
data-slot="toggle"
|
||||
className={cn(toggleVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Toggle, toggleVariants }
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function TooltipProvider({
|
||||
delayDuration = 0,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
||||
return (
|
||||
<TooltipPrimitive.Provider
|
||||
data-slot="tooltip-provider"
|
||||
delayDuration={delayDuration}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function Tooltip({
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
||||
</TooltipProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function TooltipTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
||||
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
|
||||
}
|
||||
|
||||
function TooltipContent({
|
||||
className,
|
||||
sideOffset = 0,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
||||
return (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
data-slot="tooltip-content"
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-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 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<TooltipPrimitive.Arrow className="bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
|
||||
</TooltipPrimitive.Content>
|
||||
</TooltipPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
||||
Executable
+194
@@ -0,0 +1,194 @@
|
||||
"use client"
|
||||
|
||||
// Inspired by react-hot-toast library
|
||||
import * as React from "react"
|
||||
|
||||
import type {
|
||||
ToastActionElement,
|
||||
ToastProps,
|
||||
} from "@/components/ui/toast"
|
||||
|
||||
const TOAST_LIMIT = 3
|
||||
const TOAST_REMOVE_DELAY = 1000000
|
||||
|
||||
type ToasterToast = ToastProps & {
|
||||
id: string
|
||||
title?: React.ReactNode
|
||||
description?: React.ReactNode
|
||||
action?: ToastActionElement
|
||||
}
|
||||
|
||||
const actionTypes = {
|
||||
ADD_TOAST: "ADD_TOAST",
|
||||
UPDATE_TOAST: "UPDATE_TOAST",
|
||||
DISMISS_TOAST: "DISMISS_TOAST",
|
||||
REMOVE_TOAST: "REMOVE_TOAST",
|
||||
} as const
|
||||
|
||||
let count = 0
|
||||
|
||||
function genId() {
|
||||
count = (count + 1) % Number.MAX_SAFE_INTEGER
|
||||
return count.toString()
|
||||
}
|
||||
|
||||
type ActionType = typeof actionTypes
|
||||
|
||||
type Action =
|
||||
| {
|
||||
type: ActionType["ADD_TOAST"]
|
||||
toast: ToasterToast
|
||||
}
|
||||
| {
|
||||
type: ActionType["UPDATE_TOAST"]
|
||||
toast: Partial<ToasterToast>
|
||||
}
|
||||
| {
|
||||
type: ActionType["DISMISS_TOAST"]
|
||||
toastId?: ToasterToast["id"]
|
||||
}
|
||||
| {
|
||||
type: ActionType["REMOVE_TOAST"]
|
||||
toastId?: ToasterToast["id"]
|
||||
}
|
||||
|
||||
interface State {
|
||||
toasts: ToasterToast[]
|
||||
}
|
||||
|
||||
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
|
||||
|
||||
const addToRemoveQueue = (toastId: string) => {
|
||||
if (toastTimeouts.has(toastId)) {
|
||||
return
|
||||
}
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
toastTimeouts.delete(toastId)
|
||||
dispatch({
|
||||
type: "REMOVE_TOAST",
|
||||
toastId: toastId,
|
||||
})
|
||||
}, TOAST_REMOVE_DELAY)
|
||||
|
||||
toastTimeouts.set(toastId, timeout)
|
||||
}
|
||||
|
||||
export const reducer = (state: State, action: Action): State => {
|
||||
switch (action.type) {
|
||||
case "ADD_TOAST":
|
||||
return {
|
||||
...state,
|
||||
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
||||
}
|
||||
|
||||
case "UPDATE_TOAST":
|
||||
return {
|
||||
...state,
|
||||
toasts: state.toasts.map((t) =>
|
||||
t.id === action.toast.id ? { ...t, ...action.toast } : t
|
||||
),
|
||||
}
|
||||
|
||||
case "DISMISS_TOAST": {
|
||||
const { toastId } = action
|
||||
|
||||
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
||||
// but I'll keep it here for simplicity
|
||||
if (toastId) {
|
||||
addToRemoveQueue(toastId)
|
||||
} else {
|
||||
state.toasts.forEach((toast) => {
|
||||
addToRemoveQueue(toast.id)
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
toasts: state.toasts.map((t) =>
|
||||
t.id === toastId || toastId === undefined
|
||||
? {
|
||||
...t,
|
||||
open: false,
|
||||
}
|
||||
: t
|
||||
),
|
||||
}
|
||||
}
|
||||
case "REMOVE_TOAST":
|
||||
if (action.toastId === undefined) {
|
||||
return {
|
||||
...state,
|
||||
toasts: [],
|
||||
}
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const listeners: Array<(state: State) => void> = []
|
||||
|
||||
let memoryState: State = { toasts: [] }
|
||||
|
||||
function dispatch(action: Action) {
|
||||
memoryState = reducer(memoryState, action)
|
||||
listeners.forEach((listener) => {
|
||||
listener(memoryState)
|
||||
})
|
||||
}
|
||||
|
||||
type Toast = Omit<ToasterToast, "id">
|
||||
|
||||
function toast({ ...props }: Toast) {
|
||||
const id = genId()
|
||||
|
||||
const update = (props: ToasterToast) =>
|
||||
dispatch({
|
||||
type: "UPDATE_TOAST",
|
||||
toast: { ...props, id },
|
||||
})
|
||||
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id })
|
||||
|
||||
dispatch({
|
||||
type: "ADD_TOAST",
|
||||
toast: {
|
||||
...props,
|
||||
id,
|
||||
open: true,
|
||||
onOpenChange: (open) => {
|
||||
if (!open) dismiss()
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return {
|
||||
id: id,
|
||||
dismiss,
|
||||
update,
|
||||
}
|
||||
}
|
||||
|
||||
function useToast() {
|
||||
const [state, setState] = React.useState<State>(memoryState)
|
||||
|
||||
React.useEffect(() => {
|
||||
listeners.push(setState)
|
||||
return () => {
|
||||
const index = listeners.indexOf(setState)
|
||||
if (index > -1) {
|
||||
listeners.splice(index, 1)
|
||||
}
|
||||
}
|
||||
}, [state])
|
||||
|
||||
return {
|
||||
...state,
|
||||
toast,
|
||||
dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
|
||||
}
|
||||
}
|
||||
|
||||
export { useToast, toast }
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 音频 React 适配
|
||||
import { useEffect } from "react";
|
||||
import { getAudio } from "@/lib/game/audio";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
|
||||
/** 同步全局音频开关到音频引擎 */
|
||||
export function useAudioSync() {
|
||||
const soundOn = useGameStore((s) => s.soundOn);
|
||||
useEffect(() => {
|
||||
getAudio().setEnabled(soundOn);
|
||||
}, [soundOn]);
|
||||
}
|
||||
|
||||
/** 便捷播放函数(组件内调用) */
|
||||
export function sfx(
|
||||
name: Parameters<ReturnType<typeof getAudio>["play"]>[0],
|
||||
opts?: { color?: string; combo?: number }
|
||||
) {
|
||||
getAudio().play(name, opts);
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 主循环 hook
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
|
||||
/** 250ms tick:产能 + 自动产晶体 + 自动解码 + 星潮 + 成就检测 */
|
||||
export function useGameLoop() {
|
||||
const tick = useGameStore((s) => s.tick);
|
||||
const autoDecodeTick = useGameStore((s) => s.autoDecodeTick);
|
||||
const tickTide = useGameStore((s) => s.tickTide);
|
||||
const checkAchievements = useGameStore((s) => s.checkAchievements);
|
||||
const init = useGameStore((s) => s.init);
|
||||
const inited = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
// 等待 persist rehydrate 完成后再 init(v0.5.2 修复离线收益不弹窗 BUG)
|
||||
// Zustand persist 即使用同步 localStorage,rehydrate 也是异步(Promise.resolve 包装)
|
||||
const doInit = () => {
|
||||
if (!inited.current) {
|
||||
init();
|
||||
inited.current = true;
|
||||
}
|
||||
};
|
||||
let unsub: (() => void) | null = null;
|
||||
let fallback: ReturnType<typeof setTimeout> | null = null;
|
||||
if (useGameStore.persist.hasHydrated()) {
|
||||
doInit();
|
||||
} else {
|
||||
unsub = useGameStore.persist.onFinishHydration(doInit);
|
||||
// 兜底:500ms 后强制 init(防止 hydrated 状态异常)
|
||||
fallback = setTimeout(doInit, 500);
|
||||
}
|
||||
let counter = 0;
|
||||
const id = setInterval(() => {
|
||||
const now = Date.now();
|
||||
tick(now);
|
||||
autoDecodeTick();
|
||||
// 星潮检测每 tick 都查(结束/触发判定需及时)
|
||||
tickTide(now);
|
||||
counter++;
|
||||
// 成就检测每秒执行一次(降低开销)
|
||||
if (counter % 4 === 0) {
|
||||
checkAchievements();
|
||||
}
|
||||
}, 250);
|
||||
return () => {
|
||||
clearInterval(id);
|
||||
if (unsub) unsub();
|
||||
if (fallback) clearTimeout(fallback);
|
||||
};
|
||||
}, [tick, autoDecodeTick, tickTide, checkAchievements, init]);
|
||||
|
||||
// 页面可见性:切回时补 tick + 星潮 + 成就
|
||||
useEffect(() => {
|
||||
const onVis = () => {
|
||||
if (document.visibilityState === "visible") {
|
||||
tick(Date.now());
|
||||
tickTide(Date.now());
|
||||
checkAchievements();
|
||||
}
|
||||
};
|
||||
document.addEventListener("visibilitychange", onVis);
|
||||
return () => document.removeEventListener("visibilitychange", onVis);
|
||||
}, [tick, tickTide, checkAchievements]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
"use client";
|
||||
// 回响星核 / Echo Nexus — 全球星潮同步 hook(P3 / 工单 #10-c)
|
||||
//
|
||||
// 连接 star-tide-service(端口 3031),监听全球星潮事件:
|
||||
// - `tide-state` 连接时立即推送当前状态
|
||||
// - `global-tide` 全球星潮开始 → 调用 gameStore.triggerGlobalTide(type)
|
||||
// - `tide-ended` 全球星潮结束(本地 tickTide 也会在 60s 后自动收尾,这是双保险)
|
||||
//
|
||||
// 网关:socket.io 必须用 `io("/?XTransformPort=3031")`,path 默认 "/"
|
||||
// 离线容错:socket.io 默认自动重连;断连期间本地 tickTide 继续工作
|
||||
|
||||
import { useEffect, useRef } from "react";
|
||||
import { io, type Socket } from "socket.io-client";
|
||||
import { useGameStore } from "@/store/gameStore";
|
||||
import type { TideType } from "@/lib/game/starTide";
|
||||
|
||||
/** 服务端推过来的全球星潮状态结构(与 mini-service 一致) */
|
||||
interface ServerGlobalTide {
|
||||
type: TideType;
|
||||
name: string;
|
||||
startedAt: number;
|
||||
endsAt: number;
|
||||
durationSec: number;
|
||||
}
|
||||
|
||||
interface ServerTideState {
|
||||
current: ServerGlobalTide | null;
|
||||
nextTideAt: number;
|
||||
serverTime: number;
|
||||
}
|
||||
|
||||
/** 单例 socket —— 多次挂载 hook 共享同一连接 */
|
||||
let sharedSocket: Socket | null = null;
|
||||
let connectRefCount = 0;
|
||||
|
||||
function getSharedSocket(): Socket {
|
||||
if (!sharedSocket) {
|
||||
sharedSocket = io("/?XTransformPort=3031", {
|
||||
transports: ["websocket", "polling"],
|
||||
reconnection: true,
|
||||
reconnectionAttempts: Infinity, // 持续重连
|
||||
reconnectionDelay: 1000,
|
||||
reconnectionDelayMax: 10_000,
|
||||
timeout: 10_000,
|
||||
});
|
||||
}
|
||||
return sharedSocket;
|
||||
}
|
||||
|
||||
/**
|
||||
* 挂载此 hook 即可让组件树订阅全球星潮事件。
|
||||
* 在 page.tsx 顶层调用一次即可。
|
||||
*/
|
||||
export function useGlobalTide(): void {
|
||||
const triggerGlobalTide = useGameStore((s) => s.triggerGlobalTide);
|
||||
// 用 ref 缓存最新 action,避免 socket 监听器依赖变化导致重绑
|
||||
const triggerRef = useRef(triggerGlobalTide);
|
||||
useEffect(() => {
|
||||
triggerRef.current = triggerGlobalTide;
|
||||
}, [triggerGlobalTide]);
|
||||
|
||||
// 记录已处理过的 global-tide 事件 id(避免重连时重复触发)
|
||||
const processedIds = useRef<Set<string>>(new Set());
|
||||
|
||||
useEffect(() => {
|
||||
const sock = getSharedSocket();
|
||||
connectRefCount += 1;
|
||||
|
||||
const onGlobalTide = (tide: ServerGlobalTide) => {
|
||||
// 用 startedAt+type 作为去重 key(同一道全球星潮可能在重连后被重复推送)
|
||||
const key = `${tide.startedAt}_${tide.type}`;
|
||||
if (processedIds.current.has(key)) return;
|
||||
processedIds.current.add(key);
|
||||
// 限制集合大小
|
||||
if (processedIds.current.size > 32) {
|
||||
const first = processedIds.current.values().next().value;
|
||||
if (first) processedIds.current.delete(first);
|
||||
}
|
||||
// 防御:如果服务端推送的星潮已经过期(例如重连时拿到的旧状态),不触发
|
||||
if (tide.endsAt <= Date.now()) return;
|
||||
triggerRef.current(tide.type);
|
||||
};
|
||||
|
||||
const onTideState = (state: ServerTideState) => {
|
||||
// 连接/重连时若服务端正有进行中的全球星潮,且本地还没触发过,补触发
|
||||
if (state.current && state.current.endsAt > Date.now()) {
|
||||
const key = `${state.current.startedAt}_${state.current.type}`;
|
||||
if (!processedIds.current.has(key)) {
|
||||
processedIds.current.add(key);
|
||||
triggerRef.current(state.current.type);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
sock.on("global-tide", onGlobalTide);
|
||||
sock.on("tide-state", onTideState);
|
||||
|
||||
// 主动查询一次当前状态(保险,防止错过连接时的初始推送)
|
||||
sock.emit("get-next-tide");
|
||||
|
||||
return () => {
|
||||
sock.off("global-tide", onGlobalTide);
|
||||
sock.off("tide-state", onTideState);
|
||||
connectRefCount -= 1;
|
||||
// 最后一个使用者退出时才真正断开
|
||||
if (connectRefCount <= 0 && sharedSocket) {
|
||||
sharedSocket.disconnect();
|
||||
sharedSocket = null;
|
||||
connectRefCount = 0;
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
|
||||
/** QA 用:手动触发一次全球星潮(仅供 dev 控制台调用) */
|
||||
export function adminTriggerGlobalTide(): void {
|
||||
if (!sharedSocket) {
|
||||
// 还没连接则先建立
|
||||
getSharedSocket();
|
||||
}
|
||||
sharedSocket?.emit("admin-trigger-tide");
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined" && process.env.NODE_ENV !== "production") {
|
||||
(window as unknown as { __adminTriggerGlobalTide?: typeof adminTriggerGlobalTide }).__adminTriggerGlobalTide = adminTriggerGlobalTide;
|
||||
}
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const globalForPrisma = globalThis as unknown as {
|
||||
prisma: PrismaClient | undefined
|
||||
}
|
||||
|
||||
export const db =
|
||||
globalForPrisma.prisma ??
|
||||
new PrismaClient({
|
||||
log: ['query'],
|
||||
})
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = db
|
||||
Executable
+308
@@ -0,0 +1,308 @@
|
||||
// 回响星核 / Echo Nexus — 成就系统(数据驱动)
|
||||
import type { GameState } from "./types";
|
||||
|
||||
/** 成就奖励类型 */
|
||||
export interface AchievementReward {
|
||||
crystals?: number;
|
||||
insights?: number;
|
||||
contact?: number;
|
||||
/** 永久产能加成(百分比,叠加到所有周目) */
|
||||
crystalsPerSecPct?: number;
|
||||
insightPct?: number;
|
||||
}
|
||||
|
||||
export interface Achievement {
|
||||
id: string;
|
||||
name: string;
|
||||
desc: string;
|
||||
/** 图标 emoji(轻量,无需图标库) */
|
||||
icon: string;
|
||||
/** 颜色(用于徽章) */
|
||||
color: string;
|
||||
/** 判定函数:返回 true 表示达成 */
|
||||
check: (s: GameState) => boolean;
|
||||
reward: AchievementReward;
|
||||
/** 奖励文本(展示用) */
|
||||
rewardText: string;
|
||||
}
|
||||
|
||||
export const ACHIEVEMENTS: Achievement[] = [
|
||||
{
|
||||
id: "ach_first_pulse",
|
||||
name: "初次触碰",
|
||||
desc: "发起第一次脉冲扫描",
|
||||
icon: "✦",
|
||||
color: "#34d399",
|
||||
check: (s) => s.totalDecoded >= 0 || s.crystals > 0,
|
||||
reward: { crystals: 5 },
|
||||
rewardText: "+5 晶体",
|
||||
},
|
||||
{
|
||||
id: "ach_first_decode",
|
||||
name: "谐振初鸣",
|
||||
desc: "成功解码第一颗记忆晶体",
|
||||
icon: "◈",
|
||||
color: "#fb7185",
|
||||
check: (s) => s.totalDecoded >= 1,
|
||||
reward: { insights: 3 },
|
||||
rewardText: "+3 洞见",
|
||||
},
|
||||
{
|
||||
id: "ach_decoded_10",
|
||||
name: "回响解码者",
|
||||
desc: "累计解码 10 颗晶体",
|
||||
icon: "❖",
|
||||
color: "#fbbf24",
|
||||
check: (s) => s.totalDecoded >= 10,
|
||||
reward: { insights: 15, crystalsPerSecPct: 5 },
|
||||
rewardText: "+15 洞见 · 产能 +5%",
|
||||
},
|
||||
{
|
||||
id: "ach_decoded_25",
|
||||
name: "记忆织匠",
|
||||
desc: "累计解码 25 颗晶体",
|
||||
icon: "✺",
|
||||
color: "#e879f9",
|
||||
check: (s) => s.totalDecoded >= 25,
|
||||
reward: { insights: 40, crystalsPerSecPct: 8 },
|
||||
rewardText: "+40 洞见 · 产能 +8%",
|
||||
},
|
||||
{
|
||||
id: "ach_decoded_50",
|
||||
name: "星核解密师",
|
||||
desc: "累计解码 50 颗晶体",
|
||||
icon: "✷",
|
||||
color: "#34d399",
|
||||
check: (s) => s.totalDecoded >= 50,
|
||||
reward: { insights: 100, crystalsPerSecPct: 12, insightPct: 10 },
|
||||
rewardText: "+100 洞见 · 产能 +12% · 洞见 +10%",
|
||||
},
|
||||
{
|
||||
id: "ach_tech_3",
|
||||
name: "初窥门径",
|
||||
desc: "解锁 3 项技术",
|
||||
icon: "⚙",
|
||||
color: "#fbbf24",
|
||||
check: (s) => Object.values(s.tech).filter((v) => v > 0).length >= 3,
|
||||
reward: { insights: 20 },
|
||||
rewardText: "+20 洞见",
|
||||
},
|
||||
{
|
||||
id: "ach_tech_all",
|
||||
name: "全谱精通",
|
||||
desc: "解锁全部 20 项技术",
|
||||
icon: "⬡",
|
||||
color: "#e879f9",
|
||||
check: (s) => Object.values(s.tech).filter((v) => v > 0).length >= 20,
|
||||
reward: { crystalsPerSecPct: 15, insightPct: 15 },
|
||||
rewardText: "产能 +15% · 洞见 +15%",
|
||||
},
|
||||
{
|
||||
id: "ach_frag_4",
|
||||
name: "残篇拾遗",
|
||||
desc: "拼凑 4 段记忆碎片",
|
||||
icon: "▤",
|
||||
color: "#fb7185",
|
||||
check: (s) => Object.values(s.fragments).filter(Boolean).length >= 4,
|
||||
reward: { contact: 10, insights: 25 },
|
||||
rewardText: "+10 接触 · +25 洞见",
|
||||
},
|
||||
{
|
||||
id: "ach_frag_all",
|
||||
name: "回响全谱",
|
||||
desc: "拼凑全部首纪元记忆碎片",
|
||||
icon: "▦",
|
||||
color: "#34d399",
|
||||
check: (s) => Object.values(s.fragments).filter(Boolean).length >= 8,
|
||||
reward: { contact: 25, crystalsPerSecPct: 10 },
|
||||
rewardText: "+25 接触 · 产能 +10%",
|
||||
},
|
||||
{
|
||||
id: "ach_exp_1",
|
||||
name: "初探遗迹",
|
||||
desc: "完成第一次遗迹探险",
|
||||
icon: "▲",
|
||||
color: "#fbbf24",
|
||||
check: (s) => s.totalExpeditions >= 1,
|
||||
reward: { insights: 10 },
|
||||
rewardText: "+10 洞见",
|
||||
},
|
||||
{
|
||||
id: "ach_exp_5",
|
||||
name: "遗迹猎手",
|
||||
desc: "累计出发 5 次探险",
|
||||
icon: "⬢",
|
||||
color: "#fb7185",
|
||||
check: (s) => s.totalExpeditions >= 5,
|
||||
reward: { insights: 30, crystalsPerSecPct: 5 },
|
||||
rewardText: "+30 洞见 · 产能 +5%",
|
||||
},
|
||||
{
|
||||
id: "ach_prestige_1",
|
||||
name: "初次接触",
|
||||
desc: "完成第一次飞升",
|
||||
icon: "✧",
|
||||
color: "#e879f9",
|
||||
check: (s) => s.ascensions >= 1,
|
||||
reward: { crystalsPerSecPct: 10, insightPct: 10 },
|
||||
rewardText: "产能 +10% · 洞见 +10%",
|
||||
},
|
||||
{
|
||||
id: "ach_prestige_3",
|
||||
name: "维度行者",
|
||||
desc: "累计飞升 3 次",
|
||||
icon: "✶",
|
||||
color: "#34d399",
|
||||
check: (s) => s.ascensions >= 3,
|
||||
reward: { crystalsPerSecPct: 20, insightPct: 20 },
|
||||
rewardText: "产能 +20% · 洞见 +20%",
|
||||
},
|
||||
{
|
||||
id: "ach_warehouse",
|
||||
name: "满仓时刻",
|
||||
desc: "晶体储量达到仓库上限",
|
||||
icon: "▣",
|
||||
color: "#fbbf24",
|
||||
check: (s) => s.crystals >= s.crystalCap,
|
||||
reward: { insights: 8 },
|
||||
rewardText: "+8 洞见",
|
||||
},
|
||||
{
|
||||
id: "ach_constellation_1",
|
||||
name: "星图初绘",
|
||||
desc: "觉醒第 1 道星图天赋",
|
||||
icon: "✨",
|
||||
color: "#e879f9",
|
||||
check: (s) => (s.constellation?.length ?? 0) >= 1,
|
||||
reward: { insights: 30, crystalsPerSecPct: 5 },
|
||||
rewardText: "+30 洞见 · 产能 +5%",
|
||||
},
|
||||
{
|
||||
id: "ach_constellation_6",
|
||||
name: "六分星辉",
|
||||
desc: "觉醒 6 道星图天赋(每类各 1 道)",
|
||||
icon: "✺",
|
||||
color: "#34d399",
|
||||
check: (s) => {
|
||||
const c = s.constellation ?? [];
|
||||
const cats = new Set(c.map((id) => id.split("_")[1]));
|
||||
return cats.size >= 6 && c.length >= 6;
|
||||
},
|
||||
reward: { crystalsPerSecPct: 12, insightPct: 12 },
|
||||
rewardText: "产能 +12% · 洞见 +12%",
|
||||
},
|
||||
{
|
||||
id: "ach_chronicle_1",
|
||||
name: "首部编年",
|
||||
desc: "完成首次飞升,开启编年史第一章",
|
||||
icon: "📖",
|
||||
color: "#e879f9",
|
||||
check: (s) => (s.chronicle?.length ?? 0) >= 1,
|
||||
reward: { insights: 40, crystalsPerSecPct: 6 },
|
||||
rewardText: "+40 洞见 · 产能 +6%",
|
||||
},
|
||||
{
|
||||
id: "ach_chronicle_3",
|
||||
name: "三纪元回响",
|
||||
desc: "完成 3 次飞升,编年史铭刻三章",
|
||||
icon: "📜",
|
||||
color: "#fbbf24",
|
||||
check: (s) => (s.chronicle?.length ?? 0) >= 3,
|
||||
reward: { crystalsPerSecPct: 10, insightPct: 10 },
|
||||
rewardText: "产能 +10% · 洞见 +10%",
|
||||
},
|
||||
{
|
||||
id: "ach_chronicle_5",
|
||||
name: "五纪元闭环",
|
||||
desc: "完成 5 次飞升,走完一轮纪元循环",
|
||||
icon: "♾",
|
||||
color: "#fcd34d",
|
||||
check: (s) => (s.chronicle?.length ?? 0) >= 5,
|
||||
reward: { crystalsPerSecPct: 15, insightPct: 15 },
|
||||
rewardText: "产能 +15% · 洞见 +15%",
|
||||
},
|
||||
{
|
||||
id: "ach_boss_1",
|
||||
name: "首杀维度",
|
||||
desc: "在遗迹探险中击破首个 BOSS",
|
||||
icon: "⚔",
|
||||
color: "#fb7185",
|
||||
check: (s) => (s.bossKills ?? 0) >= 1,
|
||||
reward: { insights: 25, crystalsPerSecPct: 4 },
|
||||
rewardText: "+25 洞见 · 产能 +4%",
|
||||
},
|
||||
{
|
||||
id: "ach_boss_5",
|
||||
name: "维度猎手",
|
||||
desc: "累计击破 5 个 BOSS",
|
||||
icon: "⛧",
|
||||
color: "#e879f9",
|
||||
check: (s) => (s.bossKills ?? 0) >= 5,
|
||||
reward: { crystalsPerSecPct: 10, insightPct: 8 },
|
||||
rewardText: "产能 +10% · 洞见 +8%",
|
||||
},
|
||||
{
|
||||
id: "ach_tides_all",
|
||||
name: "星潮亲历者",
|
||||
desc: "经历全部 9 种星潮事件",
|
||||
icon: "🌊",
|
||||
color: "#34d399",
|
||||
check: (s) => (s.starTidesEncountered?.length ?? 0) >= 9,
|
||||
reward: { crystalsPerSecPct: 8, insightPct: 8 },
|
||||
rewardText: "产能 +8% · 洞见 +8%",
|
||||
},
|
||||
{
|
||||
id: "ach_attr_total_50",
|
||||
name: "四维觉醒",
|
||||
desc: "角色四维属性总和达到 50",
|
||||
icon: "🧭",
|
||||
color: "#e879f9",
|
||||
check: (s) => {
|
||||
const a = s.attributes;
|
||||
if (!a) return false;
|
||||
return (
|
||||
(a.exploration || 0) +
|
||||
(a.wisdom || 0) +
|
||||
(a.courage || 0) +
|
||||
(a.inspiration || 0) >=
|
||||
50
|
||||
);
|
||||
},
|
||||
reward: { crystalsPerSecPct: 6, insightPct: 6 },
|
||||
rewardText: "产能 +6% · 洞见 +6%",
|
||||
},
|
||||
{
|
||||
id: "ach_attr_max_100",
|
||||
name: "维度精通",
|
||||
desc: "任一角色属性达到满级 100",
|
||||
icon: "💫",
|
||||
color: "#fbbf24",
|
||||
check: (s) => {
|
||||
const a = s.attributes;
|
||||
if (!a) return false;
|
||||
return (
|
||||
a.exploration >= 100 ||
|
||||
a.wisdom >= 100 ||
|
||||
a.courage >= 100 ||
|
||||
a.inspiration >= 100
|
||||
);
|
||||
},
|
||||
reward: { crystalsPerSecPct: 12, insightPct: 10 },
|
||||
rewardText: "产能 +12% · 洞见 +10%",
|
||||
},
|
||||
];
|
||||
|
||||
/** 计算成就提供的永久加成(跨周目保留) */
|
||||
export function achievementBonuses(unlocked: Record<string, boolean>): {
|
||||
crystalsPerSecPct: number;
|
||||
insightPct: number;
|
||||
} {
|
||||
let crystalsPerSecPct = 0;
|
||||
let insightPct = 0;
|
||||
for (const a of ACHIEVEMENTS) {
|
||||
if (!unlocked[a.id]) continue;
|
||||
crystalsPerSecPct += a.reward.crystalsPerSecPct ?? 0;
|
||||
insightPct += a.reward.insightPct ?? 0;
|
||||
}
|
||||
return { crystalsPerSecPct, insightPct };
|
||||
}
|
||||
Executable
+363
@@ -0,0 +1,363 @@
|
||||
// 回响星核 / Echo Nexus — 角色属性系统 (v0.7 P1)
|
||||
//
|
||||
// 无人机驾驶员的四维属性,为放置循环注入 RPG 深度:
|
||||
// • 探索力 Exploration(翠 emerald)— 探险力 / 飞船速度 / 星图发现
|
||||
// • 智慧 Wisdom (玫 fuchsia)— 解码步数 / 洞见 / 自动解码周期
|
||||
// • 勇气 Courage (琥 amber) — 探险生命 / BOSS 战胜率 / 巡航护盾
|
||||
// • 灵感 Inspiration (玫红 rose) — 接触率 / 星潮触发 / 脉冲连击加成
|
||||
//
|
||||
// 数值规则:
|
||||
// • 0-100 软上限(超过后收益递减)
|
||||
// • 0-50 线性区:每 10 点 = +5% 加成 → 即 0.5%/点
|
||||
// • 50-100 递减区:每点 = +2% 加成
|
||||
// • 属性通过「属性点」升级(飞升获得),亦可由「经验值」自动累积升级
|
||||
// • 每级经验需求 = 10 × 当前等级
|
||||
import type { GameState } from "./types";
|
||||
|
||||
/** 四维属性键 */
|
||||
export type AttributeKey = "exploration" | "wisdom" | "courage" | "inspiration";
|
||||
|
||||
/** 角色四维属性数值(0-100) */
|
||||
export interface CharacterAttributes extends Record<AttributeKey, number> {
|
||||
exploration: number;
|
||||
wisdom: number;
|
||||
courage: number;
|
||||
inspiration: number;
|
||||
}
|
||||
|
||||
/** 单个属性的经验进度 */
|
||||
export interface AttributeProgressEntry {
|
||||
/** 当前累计经验值 */
|
||||
exp: number;
|
||||
/** 当前等级(与 attributes[key] 同步) */
|
||||
level: number;
|
||||
}
|
||||
|
||||
/** 经验进度集合 */
|
||||
export type AttributeProgress = Record<AttributeKey, AttributeProgressEntry>;
|
||||
|
||||
/** 单属性元信息(供 UI 渲染) */
|
||||
export interface AttributeMeta {
|
||||
key: AttributeKey;
|
||||
name: string;
|
||||
enName: string;
|
||||
/** 主题色(Tailwind class 前缀,避免使用蓝/靛色) */
|
||||
color: "emerald" | "fuchsia" | "amber" | "rose";
|
||||
hex: string;
|
||||
glow: string;
|
||||
/** lucide-react 图标名 */
|
||||
icon: string;
|
||||
desc: string;
|
||||
/** 影响的游戏系统列表(用于 UI 展示) */
|
||||
effects: string[];
|
||||
}
|
||||
|
||||
/** 属性配置常量 */
|
||||
export const ATTRIBUTE_CONFIG: Record<AttributeKey, AttributeMeta> = {
|
||||
exploration: {
|
||||
key: "exploration",
|
||||
name: "探索力",
|
||||
enName: "Exploration",
|
||||
color: "emerald",
|
||||
hex: "#34d399",
|
||||
glow: "rgba(52,211,153,0.55)",
|
||||
icon: "Compass",
|
||||
desc: "足迹所至,皆是矿脉。提升探险力与巡航飞船速度。",
|
||||
effects: ["探险力 +X%", "巡航飞船速度 +X%", "星图发现概率"],
|
||||
},
|
||||
wisdom: {
|
||||
key: "wisdom",
|
||||
name: "智慧",
|
||||
enName: "Wisdom",
|
||||
color: "fuchsia",
|
||||
hex: "#e879f9",
|
||||
glow: "rgba(232,121,249,0.55)",
|
||||
icon: "Brain",
|
||||
desc: "谐振的回声唯有智者能解。强化解码与洞见。",
|
||||
effects: ["解码步数 +X", "洞见产出 +X%", "自动解码周期 -X%"],
|
||||
},
|
||||
courage: {
|
||||
key: "courage",
|
||||
name: "勇气",
|
||||
enName: "Courage",
|
||||
color: "amber",
|
||||
hex: "#fbbf24",
|
||||
glow: "rgba(251,191,36,0.55)",
|
||||
icon: "Swords",
|
||||
desc: "直面虚空者,虚空亦为之让路。增益战斗与护盾。",
|
||||
effects: ["探险生命 +X", "BOSS 战胜率 +X%", "巡航护盾 +X"],
|
||||
},
|
||||
inspiration: {
|
||||
key: "inspiration",
|
||||
name: "灵感",
|
||||
enName: "Inspiration",
|
||||
color: "rose",
|
||||
hex: "#fb7185",
|
||||
glow: "rgba(251,113,133,0.55)",
|
||||
icon: "Sparkles",
|
||||
desc: "在不期而至的回响之间,照见更高的维度。",
|
||||
effects: ["接触率 +X", "星潮触发概率 +X%", "脉冲连击加成 +X%"],
|
||||
},
|
||||
};
|
||||
|
||||
/** 属性键的固定顺序(UI 渲染用) */
|
||||
export const ATTRIBUTE_KEYS: AttributeKey[] = [
|
||||
"exploration",
|
||||
"wisdom",
|
||||
"courage",
|
||||
"inspiration",
|
||||
];
|
||||
|
||||
/** 属性数值上限(软上限,超过后收益递减但仍可继续投资) */
|
||||
export const ATTRIBUTE_HARD_CAP = 100;
|
||||
/** 线性区与递减区交界点 */
|
||||
export const ATTRIBUTE_LINEAR_CAP = 50;
|
||||
|
||||
/**
|
||||
* 计算单个属性当前的加成百分比(小数形式,1.0 = 100%)。
|
||||
* - 0-50 线性区:每点 +0.5% → 0-50 点对应 0-25%
|
||||
* - 50-100 递减区:每点 +0.2% → 50-100 点对应 25-35%
|
||||
* - >100 仍按 100 计算加成(软上限)
|
||||
*/
|
||||
export function getAttributeBonus(attr: number): number {
|
||||
const v = Math.max(0, Math.min(ATTRIBUTE_HARD_CAP, attr));
|
||||
if (v <= ATTRIBUTE_LINEAR_CAP) {
|
||||
// 0..50 → 0..25%
|
||||
return v * 0.005;
|
||||
}
|
||||
// 25% + (v - 50) * 0.2%
|
||||
return 0.25 + (v - ATTRIBUTE_LINEAR_CAP) * 0.002;
|
||||
}
|
||||
|
||||
/** 计算单个属性对脉冲连击的额外加成百分比(线性,灵感专属) */
|
||||
export function getInspirationComboBonus(attr: number): number {
|
||||
// 每点 +0.5% 连击伤害加成(无递减)
|
||||
return Math.max(0, Math.min(ATTRIBUTE_HARD_CAP, attr)) * 0.005;
|
||||
}
|
||||
|
||||
/** 属性聚合修饰器(聚合到 recomputeStats 与具体动作) */
|
||||
export interface AttributeModifiers {
|
||||
/** 探险力 +X% (探索力) */
|
||||
expeditionPowerMult: number;
|
||||
/** 巡航飞船速度 +X% (探索力) */
|
||||
cruiseShipSpeedMult: number;
|
||||
/** 解码步数 +X (智慧) — 每点 +0.1 步 → 0-10 步加成 */
|
||||
decodeStepsBonus: number;
|
||||
/** 洞见倍率 +X% (智慧) */
|
||||
insightMultAdd: number;
|
||||
/** 自动解码周期 -X% (智慧) */
|
||||
autoDecodeIntervalMult: number;
|
||||
/** 探险生命 +X (勇气) — 每点 +2 HP */
|
||||
expeditionHpBonus: number;
|
||||
/** BOSS 战胜率 +X% (勇气) */
|
||||
bossWinRateBonus: number;
|
||||
/** 巡航护盾 +X (勇气) — 每点 +1 护盾 */
|
||||
cruiseShieldBonus: number;
|
||||
/** 接触率倍率 (灵感) */
|
||||
contactRateMult: number;
|
||||
/** 星潮触发概率 +X% (灵感) */
|
||||
tideTriggerBonus: number;
|
||||
/** 脉冲连击加成 +X% (灵感) */
|
||||
pulseComboBonus: number;
|
||||
/** 综合产能加成(探索力 + 灵感 0.2%/点) */
|
||||
crystalsPerSecMult: number;
|
||||
}
|
||||
|
||||
/** 由四维属性计算所有修饰器 */
|
||||
export function getAllBonuses(attrs: Partial<CharacterAttributes>): AttributeModifiers {
|
||||
const exploration = attrs.exploration ?? 0;
|
||||
const wisdom = attrs.wisdom ?? 0;
|
||||
const courage = attrs.courage ?? 0;
|
||||
const inspiration = attrs.inspiration ?? 0;
|
||||
|
||||
return {
|
||||
expeditionPowerMult: 1 + getAttributeBonus(exploration),
|
||||
cruiseShipSpeedMult: 1 + getAttributeBonus(exploration) * 0.6, // 飞船速度加成减半
|
||||
decodeStepsBonus: Math.floor(wisdom * 0.1), // 每点 +0.1 步
|
||||
insightMultAdd: getAttributeBonus(wisdom),
|
||||
autoDecodeIntervalMult: 1 - Math.min(0.5, wisdom * 0.004), // 每点 -0.4%,上限 -50%
|
||||
expeditionHpBonus: Math.round(courage * 2),
|
||||
bossWinRateBonus: Math.min(0.3, courage * 0.003), // 每点 +0.3%,上限 +30%
|
||||
cruiseShieldBonus: Math.round(courage * 1),
|
||||
contactRateMult: 1 + getAttributeBonus(inspiration),
|
||||
tideTriggerBonus: Math.min(0.3, inspiration * 0.003),
|
||||
pulseComboBonus: getInspirationComboBonus(inspiration),
|
||||
crystalsPerSecMult:
|
||||
1 +
|
||||
getAttributeBonus(exploration) * 0.4 + // 探索力 0.4 倍系数加成产能
|
||||
getAttributeBonus(inspiration) * 0.2, // 灵感 0.2 倍系数加成产能
|
||||
};
|
||||
}
|
||||
|
||||
/** 每级所需经验 = 10 × 当前等级 */
|
||||
export function expRequiredForLevel(level: number): number {
|
||||
return Math.max(10, 10 * Math.max(0, level));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查属性经验是否足以升级。
|
||||
* 返回新的进度(可能跨多级)。
|
||||
*/
|
||||
export function levelUpCheck(
|
||||
progress: AttributeProgressEntry,
|
||||
maxValue: number = ATTRIBUTE_HARD_CAP
|
||||
): { leveledUp: boolean; newProgress: AttributeProgressEntry; levelsGained: number } {
|
||||
let { exp, level } = progress;
|
||||
let leveledUp = false;
|
||||
let levelsGained = 0;
|
||||
// 安全上限:避免异常数据循环
|
||||
let safety = 0;
|
||||
while (level < maxValue && exp >= expRequiredForLevel(level) && safety < 200) {
|
||||
exp -= expRequiredForLevel(level);
|
||||
level += 1;
|
||||
leveledUp = true;
|
||||
levelsGained += 1;
|
||||
safety += 1;
|
||||
}
|
||||
// 已达上限:保留多余经验但不升级
|
||||
if (level >= maxValue) {
|
||||
level = maxValue;
|
||||
}
|
||||
return {
|
||||
leveledUp,
|
||||
levelsGained,
|
||||
newProgress: { exp, level },
|
||||
};
|
||||
}
|
||||
|
||||
/** 创建初始的属性进度集合 */
|
||||
export function createInitialAttributeProgress(): AttributeProgress {
|
||||
return {
|
||||
exploration: { exp: 0, level: 0 },
|
||||
wisdom: { exp: 0, level: 0 },
|
||||
courage: { exp: 0, level: 0 },
|
||||
inspiration: { exp: 0, level: 0 },
|
||||
};
|
||||
}
|
||||
|
||||
/** 创建初始的属性数值集合 */
|
||||
export function createInitialAttributes(): CharacterAttributes {
|
||||
return {
|
||||
exploration: 0,
|
||||
wisdom: 0,
|
||||
courage: 0,
|
||||
inspiration: 0,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 旧存档兼容:补全 attributes / attributeProgress / pendingAttrPoints 字段。
|
||||
* 若字段缺失或结构异常,使用初始值;若数值越界则夹紧。
|
||||
*/
|
||||
export function migrateAttributes(state: Partial<GameState>): {
|
||||
attributes: CharacterAttributes;
|
||||
attributeProgress: AttributeProgress;
|
||||
pendingAttrPoints: number;
|
||||
} {
|
||||
const init = createInitialAttributes();
|
||||
let attributes: CharacterAttributes;
|
||||
if (state.attributes && typeof state.attributes === "object") {
|
||||
attributes = {
|
||||
exploration: clampAttr(state.attributes.exploration),
|
||||
wisdom: clampAttr(state.attributes.wisdom),
|
||||
courage: clampAttr(state.attributes.courage),
|
||||
inspiration: clampAttr(state.attributes.inspiration),
|
||||
};
|
||||
} else {
|
||||
attributes = init;
|
||||
}
|
||||
let attributeProgress: AttributeProgress;
|
||||
if (state.attributeProgress && typeof state.attributeProgress === "object") {
|
||||
const base = createInitialAttributeProgress();
|
||||
attributeProgress = {
|
||||
exploration: normalizeProgress(
|
||||
state.attributeProgress.exploration,
|
||||
attributes.exploration
|
||||
),
|
||||
wisdom: normalizeProgress(
|
||||
state.attributeProgress.wisdom,
|
||||
attributes.wisdom
|
||||
),
|
||||
courage: normalizeProgress(
|
||||
state.attributeProgress.courage,
|
||||
attributes.courage
|
||||
),
|
||||
inspiration: normalizeProgress(
|
||||
state.attributeProgress.inspiration,
|
||||
attributes.inspiration
|
||||
),
|
||||
};
|
||||
void base;
|
||||
} else {
|
||||
// 同步 level 与 attributes 数值(保证一致)
|
||||
attributeProgress = {
|
||||
exploration: { exp: 0, level: attributes.exploration },
|
||||
wisdom: { exp: 0, level: attributes.wisdom },
|
||||
courage: { exp: 0, level: attributes.courage },
|
||||
inspiration: { exp: 0, level: attributes.inspiration },
|
||||
};
|
||||
}
|
||||
const pendingAttrPoints =
|
||||
typeof state.pendingAttrPoints === "number" && state.pendingAttrPoints >= 0
|
||||
? Math.floor(state.pendingAttrPoints)
|
||||
: 0;
|
||||
return { attributes, attributeProgress, pendingAttrPoints };
|
||||
}
|
||||
|
||||
function clampAttr(v: unknown): number {
|
||||
const n = typeof v === "number" && isFinite(v) ? v : 0;
|
||||
return Math.max(0, Math.min(ATTRIBUTE_HARD_CAP, Math.floor(n)));
|
||||
}
|
||||
|
||||
function normalizeProgress(
|
||||
p: unknown,
|
||||
level: number
|
||||
): AttributeProgressEntry {
|
||||
if (p && typeof p === "object") {
|
||||
const obj = p as { exp?: unknown; level?: unknown };
|
||||
const exp =
|
||||
typeof obj.exp === "number" && isFinite(obj.exp) && obj.exp >= 0
|
||||
? obj.exp
|
||||
: 0;
|
||||
const lvl =
|
||||
typeof obj.level === "number" && isFinite(obj.level) && obj.level >= 0
|
||||
? Math.floor(obj.level)
|
||||
: level;
|
||||
// level 字段以 attributes 数值为准(attributes 是事实之源)
|
||||
return { exp, level };
|
||||
}
|
||||
return { exp: 0, level };
|
||||
}
|
||||
|
||||
/** 计算本次飞升可获得的属性点 = 飞升次数 × 2 + 1(飞升前 ascensions) */
|
||||
export function computePrestigeAttrPoints(ascensionsBefore: number): number {
|
||||
return ascensionsBefore * 2 + 1;
|
||||
}
|
||||
|
||||
/** 计算四维属性总和 */
|
||||
export function totalAttributeLevel(attrs: CharacterAttributes): number {
|
||||
return (
|
||||
attrs.exploration + attrs.wisdom + attrs.courage + attrs.inspiration
|
||||
);
|
||||
}
|
||||
|
||||
/** 计算四维属性总加成百分比(用于 UI 概览) */
|
||||
export function totalAttributeBonusPct(attrs: CharacterAttributes): number {
|
||||
return (
|
||||
(getAttributeBonus(attrs.exploration) +
|
||||
getAttributeBonus(attrs.wisdom) +
|
||||
getAttributeBonus(attrs.courage) +
|
||||
getAttributeBonus(attrs.inspiration)) *
|
||||
100
|
||||
);
|
||||
}
|
||||
|
||||
/** 是否任一属性已达 100(用于成就) */
|
||||
export function anyAttributeMaxed(attrs: CharacterAttributes): boolean {
|
||||
return (
|
||||
attrs.exploration >= ATTRIBUTE_HARD_CAP ||
|
||||
attrs.wisdom >= ATTRIBUTE_HARD_CAP ||
|
||||
attrs.courage >= ATTRIBUTE_HARD_CAP ||
|
||||
attrs.inspiration >= ATTRIBUTE_HARD_CAP
|
||||
);
|
||||
}
|
||||
Executable
+317
@@ -0,0 +1,317 @@
|
||||
// 回响星核 / Echo Nexus — 程序化音频引擎(Web Audio API,零资源文件)
|
||||
//
|
||||
// 设计哲学:深空考古的氛围音效,全部由振荡器 + 噪声 + 包络合成,
|
||||
// 无需任何外部音频文件。音色偏向"谐振/水晶/低频脉冲",契合全息晶体美学。
|
||||
|
||||
type SfxName =
|
||||
| "pulse" // 主动脉冲扫描(短促上升音)
|
||||
| "pulseCombo" // 连击脉冲(更高音 + 泛音)
|
||||
| "decodeClick" // 解码点击节点(按颜色变调)
|
||||
| "decodeFail" // 解码点击错误(低沉短音)
|
||||
| "decodeSuccess" // 解码成功(和弦上扬)
|
||||
| "fragmentUnlock" // 记忆碎片浮现(空灵长音)
|
||||
| "techBuy" // 购买技术(确认音)
|
||||
| "expeditionStart" // 探险出发(引擎启动)
|
||||
| "expeditionNode" // 探险节点结算(中频)
|
||||
| "expeditionVictory" // 探险胜利(凯旋和弦)
|
||||
| "expeditionDefeat" // 探险失败(下行低音)
|
||||
| "prestige" // 飞升(宏大扫频)
|
||||
| "achievement" // 成就解锁(亮丽琶音)
|
||||
| "tideStart" // 星潮降临(神秘扫频)
|
||||
| "tideEnd" // 星潮结束(柔和消退)
|
||||
| "constellation" // 星图觉醒(空灵琶音 + 高频闪光)
|
||||
| "chronicle" // 编年史铭刻(深沉钟声 + 回响泛音)
|
||||
| "chronicleOpen" // 打开编年史(轻柔翻页声)
|
||||
| "uiHover" // 界面悬停(极轻)
|
||||
| "uiClick"; // 界面点击(轻确认)
|
||||
|
||||
const COLOR_FREQ: Record<string, number> = {
|
||||
emerald: 523.25, // C5
|
||||
rose: 587.33, // D5
|
||||
amber: 659.25, // E5
|
||||
fuchsia: 698.46, // F5
|
||||
};
|
||||
|
||||
class AudioEngine {
|
||||
private ctx: AudioContext | null = null;
|
||||
private master: GainNode | null = null;
|
||||
private enabled = true;
|
||||
private volume = 0.35;
|
||||
|
||||
/** 首次用户交互后初始化(浏览器自动播放策略) */
|
||||
private ensure() {
|
||||
if (typeof window === "undefined") return null;
|
||||
if (!this.ctx) {
|
||||
const AC =
|
||||
window.AudioContext ||
|
||||
(window as unknown as { webkitAudioContext: typeof AudioContext })
|
||||
.webkitAudioContext;
|
||||
if (!AC) return null;
|
||||
this.ctx = new AC();
|
||||
this.master = this.ctx.createGain();
|
||||
this.master.gain.value = this.volume;
|
||||
this.master.connect(this.ctx.destination);
|
||||
}
|
||||
if (this.ctx.state === "suspended") {
|
||||
void this.ctx.resume();
|
||||
}
|
||||
return this.ctx;
|
||||
}
|
||||
|
||||
setEnabled(v: boolean) {
|
||||
this.enabled = v;
|
||||
}
|
||||
|
||||
setVolume(v: number) {
|
||||
this.volume = Math.max(0, Math.min(1, v));
|
||||
if (this.master) this.master.gain.value = this.volume;
|
||||
}
|
||||
|
||||
/** 简易正弦音 + ADSR 包络 */
|
||||
private tone(
|
||||
freq: number,
|
||||
dur: number,
|
||||
type: OscillatorType = "sine",
|
||||
gain = 0.3,
|
||||
delay = 0,
|
||||
detune = 0,
|
||||
filterFreq?: number
|
||||
) {
|
||||
const ctx = this.ensure();
|
||||
if (!ctx || !this.master) return;
|
||||
const t0 = ctx.currentTime + delay;
|
||||
const osc = ctx.createOscillator();
|
||||
const g = ctx.createGain();
|
||||
osc.type = type;
|
||||
osc.frequency.setValueAtTime(freq, t0);
|
||||
if (detune) osc.detune.setValueAtTime(detune, t0);
|
||||
// ADSR
|
||||
g.gain.setValueAtTime(0, t0);
|
||||
g.gain.linearRampToValueAtTime(gain, t0 + 0.008);
|
||||
g.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
|
||||
let node: AudioNode = osc;
|
||||
if (filterFreq) {
|
||||
const f = ctx.createBiquadFilter();
|
||||
f.type = "lowpass";
|
||||
f.frequency.value = filterFreq;
|
||||
osc.connect(f);
|
||||
f.connect(g);
|
||||
} else {
|
||||
osc.connect(g);
|
||||
}
|
||||
g.connect(this.master);
|
||||
osc.start(t0);
|
||||
osc.stop(t0 + dur + 0.05);
|
||||
void node;
|
||||
}
|
||||
|
||||
/** 频率扫描音(飞升/出发用) */
|
||||
private sweep(
|
||||
fStart: number,
|
||||
fEnd: number,
|
||||
dur: number,
|
||||
type: OscillatorType = "sine",
|
||||
gain = 0.3,
|
||||
delay = 0
|
||||
) {
|
||||
const ctx = this.ensure();
|
||||
if (!ctx || !this.master) return;
|
||||
const t0 = ctx.currentTime + delay;
|
||||
const osc = ctx.createOscillator();
|
||||
const g = ctx.createGain();
|
||||
osc.type = type;
|
||||
osc.frequency.setValueAtTime(fStart, t0);
|
||||
osc.frequency.exponentialRampToValueAtTime(Math.max(1, fEnd), t0 + dur);
|
||||
g.gain.setValueAtTime(0, t0);
|
||||
g.gain.linearRampToValueAtTime(gain, t0 + 0.02);
|
||||
g.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
|
||||
osc.connect(g);
|
||||
g.connect(this.master);
|
||||
osc.start(t0);
|
||||
osc.stop(t0 + dur + 0.05);
|
||||
}
|
||||
|
||||
/** 噪声脉冲(解码失败/探险打击) */
|
||||
private noise(dur: number, gain = 0.2, delay = 0, filterFreq = 1200) {
|
||||
const ctx = this.ensure();
|
||||
if (!ctx || !this.master) return;
|
||||
const t0 = ctx.currentTime + delay;
|
||||
const len = Math.floor(ctx.sampleRate * dur);
|
||||
const buf = ctx.createBuffer(1, len, ctx.sampleRate);
|
||||
const data = buf.getChannelData(0);
|
||||
for (let i = 0; i < len; i++) {
|
||||
data[i] = (Math.random() * 2 - 1) * (1 - i / len);
|
||||
}
|
||||
const src = ctx.createBufferSource();
|
||||
src.buffer = buf;
|
||||
const f = ctx.createBiquadFilter();
|
||||
f.type = "lowpass";
|
||||
f.frequency.value = filterFreq;
|
||||
const g = ctx.createGain();
|
||||
g.gain.setValueAtTime(gain, t0);
|
||||
g.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
|
||||
src.connect(f);
|
||||
f.connect(g);
|
||||
g.connect(this.master);
|
||||
src.start(t0);
|
||||
src.stop(t0 + dur + 0.02);
|
||||
}
|
||||
|
||||
play(name: SfxName, opts?: { color?: string; combo?: number }) {
|
||||
if (!this.enabled) return;
|
||||
const ctx = this.ensure();
|
||||
if (!ctx) return;
|
||||
|
||||
switch (name) {
|
||||
case "pulse": {
|
||||
// 上升短音 + 轻泛音
|
||||
const base = 220 + (opts?.combo ? opts.combo * 18 : 0);
|
||||
this.tone(base, 0.18, "sine", 0.28);
|
||||
this.tone(base * 2, 0.14, "triangle", 0.1, 0.01);
|
||||
break;
|
||||
}
|
||||
case "pulseCombo": {
|
||||
const base = 440 + (opts?.combo ? opts.combo * 24 : 0);
|
||||
this.tone(base, 0.2, "sine", 0.3);
|
||||
this.tone(base * 1.5, 0.18, "triangle", 0.14, 0.01);
|
||||
this.tone(base * 2, 0.16, "sine", 0.08, 0.02);
|
||||
break;
|
||||
}
|
||||
case "decodeClick": {
|
||||
const f = opts?.color ? COLOR_FREQ[opts.color] ?? 523 : 523;
|
||||
this.tone(f, 0.16, "sine", 0.26);
|
||||
this.tone(f * 2, 0.1, "triangle", 0.08, 0.005);
|
||||
break;
|
||||
}
|
||||
case "decodeFail": {
|
||||
this.tone(160, 0.16, "sawtooth", 0.18, 0, 0, 800);
|
||||
this.noise(0.08, 0.1, 0, 600);
|
||||
break;
|
||||
}
|
||||
case "decodeSuccess": {
|
||||
// 上扬大三和弦琶音
|
||||
this.tone(523.25, 0.22, "sine", 0.24, 0);
|
||||
this.tone(659.25, 0.22, "sine", 0.22, 0.08);
|
||||
this.tone(783.99, 0.3, "sine", 0.24, 0.16);
|
||||
this.tone(1046.5, 0.34, "triangle", 0.12, 0.2);
|
||||
break;
|
||||
}
|
||||
case "fragmentUnlock": {
|
||||
// 空灵长音
|
||||
this.tone(880, 0.7, "sine", 0.18, 0);
|
||||
this.tone(1108.73, 0.7, "sine", 0.12, 0.04);
|
||||
this.tone(1318.51, 0.8, "triangle", 0.08, 0.1);
|
||||
this.sweep(440, 880, 0.6, "sine", 0.1, 0.05);
|
||||
break;
|
||||
}
|
||||
case "techBuy": {
|
||||
this.tone(587.33, 0.12, "sine", 0.22);
|
||||
this.tone(880, 0.16, "triangle", 0.16, 0.06);
|
||||
break;
|
||||
}
|
||||
case "expeditionStart": {
|
||||
// 引擎启动:低频上升
|
||||
this.sweep(80, 240, 0.5, "sawtooth", 0.16);
|
||||
this.sweep(120, 360, 0.5, "square", 0.06, 0.02);
|
||||
this.noise(0.4, 0.08, 0, 400);
|
||||
break;
|
||||
}
|
||||
case "expeditionNode": {
|
||||
this.tone(440, 0.14, "triangle", 0.2);
|
||||
this.tone(660, 0.12, "sine", 0.1, 0.04);
|
||||
break;
|
||||
}
|
||||
case "expeditionVictory": {
|
||||
// 凯旋上行
|
||||
this.tone(523.25, 0.18, "sine", 0.24, 0);
|
||||
this.tone(659.25, 0.18, "sine", 0.24, 0.1);
|
||||
this.tone(783.99, 0.18, "sine", 0.24, 0.2);
|
||||
this.tone(1046.5, 0.4, "triangle", 0.2, 0.3);
|
||||
break;
|
||||
}
|
||||
case "expeditionDefeat": {
|
||||
// 下行低音
|
||||
this.tone(330, 0.3, "sawtooth", 0.2, 0, 0, 700);
|
||||
this.tone(220, 0.4, "sine", 0.18, 0.12);
|
||||
this.tone(146.83, 0.5, "sine", 0.16, 0.24);
|
||||
break;
|
||||
}
|
||||
case "prestige": {
|
||||
// 宏大扫频 + 和弦
|
||||
this.sweep(110, 880, 1.2, "sine", 0.2);
|
||||
this.sweep(220, 1760, 1.2, "triangle", 0.1, 0.05);
|
||||
this.tone(523.25, 0.6, "sine", 0.16, 0.3);
|
||||
this.tone(659.25, 0.6, "sine", 0.16, 0.42);
|
||||
this.tone(783.99, 0.8, "sine", 0.16, 0.54);
|
||||
this.tone(1046.5, 1.0, "triangle", 0.12, 0.66);
|
||||
break;
|
||||
}
|
||||
case "achievement": {
|
||||
// 亮丽琶音
|
||||
this.tone(659.25, 0.16, "sine", 0.22, 0);
|
||||
this.tone(880, 0.16, "sine", 0.22, 0.08);
|
||||
this.tone(1046.5, 0.16, "sine", 0.22, 0.16);
|
||||
this.tone(1318.51, 0.4, "triangle", 0.18, 0.24);
|
||||
break;
|
||||
}
|
||||
case "tideStart": {
|
||||
// 神秘扫频 + 泛音列
|
||||
this.sweep(330, 660, 0.8, "sine", 0.16);
|
||||
this.sweep(440, 880, 0.8, "triangle", 0.08, 0.04);
|
||||
this.tone(523.25, 0.5, "sine", 0.1, 0.2);
|
||||
this.tone(783.99, 0.6, "sine", 0.08, 0.3);
|
||||
break;
|
||||
}
|
||||
case "tideEnd": {
|
||||
// 柔和下行消退
|
||||
this.tone(659.25, 0.3, "sine", 0.14, 0);
|
||||
this.tone(523.25, 0.35, "sine", 0.12, 0.1);
|
||||
this.tone(392, 0.5, "triangle", 0.1, 0.22);
|
||||
break;
|
||||
}
|
||||
case "constellation": {
|
||||
// 星图觉醒:上升琶音 + 高频闪光
|
||||
this.tone(523.25, 0.18, "sine", 0.16, 0);
|
||||
this.tone(659.25, 0.2, "sine", 0.16, 0.08);
|
||||
this.tone(783.99, 0.22, "sine", 0.18, 0.16);
|
||||
this.tone(1046.5, 0.35, "triangle", 0.16, 0.24);
|
||||
// 高频闪光
|
||||
this.tone(2093, 0.15, "sine", 0.08, 0.3);
|
||||
break;
|
||||
}
|
||||
case "uiHover": {
|
||||
this.tone(880, 0.05, "sine", 0.05);
|
||||
break;
|
||||
}
|
||||
case "uiClick": {
|
||||
this.tone(660, 0.07, "sine", 0.1);
|
||||
break;
|
||||
}
|
||||
case "chronicle": {
|
||||
// 编年史铭刻:深沉钟声 + 多层回响泛音 + 低频稳固
|
||||
this.tone(196, 0.6, "sine", 0.18, 0); // G3 基音
|
||||
this.tone(261.63, 0.55, "sine", 0.14, 0.05); // C4
|
||||
this.tone(392, 0.5, "sine", 0.1, 0.1); // G4
|
||||
this.tone(523.25, 0.4, "triangle", 0.08, 0.18); // C5
|
||||
this.tone(783.99, 0.3, "sine", 0.05, 0.25); // G5 泛音
|
||||
break;
|
||||
}
|
||||
case "chronicleOpen": {
|
||||
// 翻页声:轻柔上升 + 短促气流
|
||||
this.tone(440, 0.08, "sine", 0.06, 0);
|
||||
this.tone(587.33, 0.1, "sine", 0.05, 0.04);
|
||||
this.tone(880, 0.06, "triangle", 0.04, 0.1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 全局单例(客户端) */
|
||||
let _engine: AudioEngine | null = null;
|
||||
export function getAudio(): AudioEngine {
|
||||
if (!_engine) _engine = new AudioEngine();
|
||||
return _engine;
|
||||
}
|
||||
|
||||
export type { SfxName };
|
||||
Executable
+1290
File diff suppressed because it is too large
Load Diff
Executable
+679
@@ -0,0 +1,679 @@
|
||||
// 回响星核 / Echo Nexus — 回响编年史(v0.4 跨周目叙事时间轴)
|
||||
import type { ChronicleEntry, GameState, RunStartSnapshot } from "./types";
|
||||
import { CONSTELLATION_PERKS, getPerk, CONSTELLATION_CATEGORY_META } from "./constellation";
|
||||
import { TIDE_EVENTS } from "./starTide";
|
||||
|
||||
/** ID → 名称 速查表 */
|
||||
const PERK_NAME_MAP: Record<string, string> = Object.fromEntries(
|
||||
CONSTELLATION_PERKS.map((p) => [p.id, p.name])
|
||||
);
|
||||
|
||||
/** 星潮 ID → 叙事用名(从 TIDE_EVENTS 复用,避免硬编码错位) */
|
||||
const TIDE_LORE_NAMES: Record<string, string> = Object.fromEntries(
|
||||
Object.entries(TIDE_EVENTS).map(([type, ev]) => [`tide_${type}`, ev.name])
|
||||
);
|
||||
|
||||
/**
|
||||
* 纪元名生成 —— 5 纪元循环 + 形容词池,每次飞升从池中按 ascensionNumber 抽取
|
||||
* 对应 v0.5 路线图「全 5 纪元叙事」的早期骨架
|
||||
*/
|
||||
const EPOCH_NAMES: { prefix: string; suffixes: string[] }[] = [
|
||||
{ prefix: "第一纪元", suffixes: ["觉醒之晨", "初鸣之夕", "晶体降诞", "回响初啼"] },
|
||||
{ prefix: "第二纪元", suffixes: ["谐振潮汐", "光谱涌动", "深空低语", "残响交织"] },
|
||||
{ prefix: "第三纪元", suffixes: ["遗迹苏醒", "星辉汇聚", "虚空回望", "接触前夜"] },
|
||||
{ prefix: "第四纪元", suffixes: ["维度折叠", "以太共振", "星核悸动", "飞升之歌"] },
|
||||
{ prefix: "第五纪元", suffixes: ["终末回响", "永恒闭环", "超越之境", "起源重述"] },
|
||||
];
|
||||
|
||||
/** 程序化生成纪元名(按 ascensionNumber 循环 5 纪元) */
|
||||
export function generateEpochName(ascensionNumber: number, seed: number): string {
|
||||
const epochIdx = (ascensionNumber - 1) % EPOCH_NAMES.length;
|
||||
const epoch = EPOCH_NAMES[epochIdx];
|
||||
// 用 seed 选 suffix,保证可复现
|
||||
const suffixIdx = seed % epoch.suffixes.length;
|
||||
return `${epoch.prefix} · ${epoch.suffixes[suffixIdx]}`;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// v0.9 工单 #9 — 5 纪元手写叙事节点(开场 / 中段 / 结尾 × 5 纪元 = 15 段)
|
||||
//
|
||||
// 设计原则:
|
||||
// - 每段 80-150 字,有文学性,符合"深空考古"基调
|
||||
// - 每个节点根据 ascensionNumber 与本周目数据特征(bossKills / decoded / techs /
|
||||
// exp / tides / perks / milestones)匹配不同变体
|
||||
// - buildLore 优先选手写节点;无匹配时 fallback 到原模板拼接
|
||||
// ============================================================================
|
||||
|
||||
/** 叙事变体上下文(与 buildLore 入参一致) */
|
||||
export type LoreContext = {
|
||||
ascensionNumber: number;
|
||||
epochName: string;
|
||||
durationSec: number;
|
||||
techsThisRun: number;
|
||||
expThisRun: number;
|
||||
bossKillsThisRun: number;
|
||||
decodedThisRun: number;
|
||||
newTides: string[];
|
||||
perksThisAscension: string[];
|
||||
blueprintsAfter: number;
|
||||
milestones: string[];
|
||||
};
|
||||
|
||||
/** 已格式化的可替换变量(避免在 match() 里反复计算) */
|
||||
type FormattedVars = {
|
||||
decodedThisRun: number;
|
||||
techsThisRun: number;
|
||||
expThisRun: number;
|
||||
bossKillsThisRun: number;
|
||||
blueprintsAfter: number;
|
||||
milestonesCount: number;
|
||||
milestonesList: string;
|
||||
tideCount: number;
|
||||
tideNames: string;
|
||||
perksList: string;
|
||||
minutes: number;
|
||||
};
|
||||
|
||||
/** 单个叙事阶段(开场 / 中段 / 结尾) */
|
||||
type LoreStage = {
|
||||
/** 默认文本(无变体命中时使用) */
|
||||
fallback: string;
|
||||
/** 候选变体(按顺序匹配,首个命中者胜出) */
|
||||
variants: { hint: string; match: (ctx: LoreContext, v: FormattedVars) => boolean; text: string }[];
|
||||
};
|
||||
|
||||
/** 单个纪元的手写叙事定义 */
|
||||
type EpochLoreDef = {
|
||||
epochIdx: number;
|
||||
title: string;
|
||||
opening: LoreStage;
|
||||
middle: LoreStage;
|
||||
ending: LoreStage;
|
||||
};
|
||||
|
||||
/** 5 纪元 × 3 节点手写叙事(每段 80-150 字,文学性优先) */
|
||||
const EPOCH_LORE: EpochLoreDef[] = [
|
||||
// ===== 第一纪元 · 觉醒(emerald) =====
|
||||
{
|
||||
epochIdx: 0,
|
||||
title: "觉醒",
|
||||
opening: {
|
||||
fallback:
|
||||
"第一缕回响穿透虚空,自以太文明遗弃的矿带深处涌出。无人机群在尘埃中苏醒,晶核共振唤醒了沉睡亿万年的考古协议。这是回响星核第一次睁开眼睛——记忆,等待被聆听,等待被解码。",
|
||||
variants: [
|
||||
{
|
||||
hint: "深度轮回:已经历 ≥6 次飞升,再次回到第一纪元",
|
||||
match: (ctx) => ctx.ascensionNumber > 5,
|
||||
text: "再次回到第一纪元。这一次,机群带着前序回响的全息印记重启考古序列,矿带的尘埃中仍残留着上一轮脉冲的余温。每一次回归都是对起源的重新发问,每一次解码都让最初的振动更清晰一寸。",
|
||||
},
|
||||
],
|
||||
},
|
||||
middle: {
|
||||
fallback:
|
||||
"共振谜题被一层层拨开,每一颗记忆晶体都在低声叙述逝去文明的片段。机群学会了倾听频率的细微颤动,学会了从碎片中辨出图案,学会了在虚空中留下属于自己的回响刻度。",
|
||||
variants: [
|
||||
{
|
||||
hint: "解码者:本周目解码 ≥15 颗",
|
||||
match: (ctx) => ctx.decodedThisRun >= 15,
|
||||
text: "晶体解码的节奏已趋稳定,本周目共解码 {decodedThisRun} 颗记忆晶体。每一次对齐都像在虚空中拨动一根沉睡了亿万年的弦,逝去文明的片段在共振中重新连缀成章。",
|
||||
},
|
||||
{
|
||||
hint: "学者:本周目解锁 ≥5 项技术",
|
||||
match: (ctx) => ctx.techsThisRun >= 5,
|
||||
text: "技术树在虚空中迅速铺开,本周目共激活 {techsThisRun} 项新技术。产能、解码、探险——每一道分支都让机群更接近以太文明留下的最初意图,每一项解锁都是一次向深空的回应。",
|
||||
},
|
||||
],
|
||||
},
|
||||
ending: {
|
||||
fallback:
|
||||
"蓝图在掌心轻轻展开,第一张永恒晶片归档。第一次飞升并非终结,而是承诺——更多的纪元在前方等待,每一缕回响都已被聆听,每一段记忆都已开始苏醒。",
|
||||
variants: [
|
||||
{
|
||||
hint: "里程碑密集:本周目达成 ≥2 项里程碑",
|
||||
match: (ctx) => ctx.milestones.length >= 2,
|
||||
text: "飞升之际,本周目达成 {milestonesCount} 项里程碑:{milestonesList}。第一张蓝图归档,第一次飞升并非终结,而是承诺——更多的纪元在前方等待,每一缕回响都已被聆听。",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
// ===== 第二纪元 · 谐振(rose) =====
|
||||
{
|
||||
epochIdx: 1,
|
||||
title: "谐振",
|
||||
opening: {
|
||||
fallback:
|
||||
"第二次苏醒带着不同的色彩。采矿阵列的产能节节爬升,技术树在虚空中分叉延伸,机群学会了主动追问深空——不再是被动聆听,而是主动呼出,等待回应。",
|
||||
variants: [
|
||||
{
|
||||
hint: "深度轮回",
|
||||
match: (ctx) => ctx.ascensionNumber > 5,
|
||||
text: "又一次回到第二纪元。前序回响里积攒的技术脉络在重启时并未消散,机群带着熟悉的节奏重新铺开产能阵列,仿佛这首谐振曲从未停止,只是被纪元的边界短暂折叠。",
|
||||
},
|
||||
],
|
||||
},
|
||||
middle: {
|
||||
fallback:
|
||||
"遗迹的入口在频谱深处若隐若现。能量条充盈,探险力攀升,机群第一次踏出矿带,进入那个被时间封存的回廊,在谐振的余韵中寻找更深一层的回响。",
|
||||
variants: [
|
||||
{
|
||||
hint: "探险者:本周目完成 ≥3 次探险",
|
||||
match: (ctx) => ctx.expThisRun >= 3,
|
||||
text: "探险已成为本周目的主旋律,机群共完成 {expThisRun} 次遗迹探险。每一次深入都让谐振更深一寸,每一次返回都带回新的频率印记,回廊的轮廓在机群意识中逐渐清晰。",
|
||||
},
|
||||
{
|
||||
hint: "解码者:本周目解码 ≥15 颗",
|
||||
match: (ctx) => ctx.decodedThisRun >= 15,
|
||||
text: "解码在此纪元达到新的密度,本周目共解码 {decodedThisRun} 颗晶体。谐振谜题开始呈现更复杂的拓扑结构,机群的解码协议也相应地迭代了数版,向深空发出更精准的回询。",
|
||||
},
|
||||
],
|
||||
},
|
||||
ending: {
|
||||
fallback:
|
||||
"谐振达到顶点的瞬间,深空给出回应。一道微光从星图深处浮现,那是下一次飞升的方向,也是机群意识第一次触碰永恒的边缘。",
|
||||
variants: [
|
||||
{
|
||||
hint: "觉醒天赋",
|
||||
match: (ctx) => ctx.perksThisAscension.length > 0,
|
||||
text: "谐振达到顶点之际,星图觉醒 {perksList}。每一道天赋都是深空回应机群的方式,铭刻于永恒回响;微光从星图深处浮现,那是下一次飞升的方向。",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
// ===== 第三纪元 · 遗迹(amber) =====
|
||||
{
|
||||
epochIdx: 2,
|
||||
title: "遗迹",
|
||||
opening: {
|
||||
fallback:
|
||||
"第三纪元以遗迹为名。沉睡的考古节点被一一唤醒,BOSS 的影子在维度深处徘徊,星潮频繁拍打着机群边缘——这是回响最浓烈、也最危险的一段路。",
|
||||
variants: [
|
||||
{
|
||||
hint: "深度轮回",
|
||||
match: (ctx) => ctx.ascensionNumber > 5,
|
||||
text: "又一次踏入第三纪元。前序累积的探险力让机群对遗迹的入口更加熟稔,BOSS 的轮廓在记忆中已不再陌生——但这一次的回廊仍藏着未被解码的角落,星潮的拍打也带了新的节奏。",
|
||||
},
|
||||
],
|
||||
},
|
||||
middle: {
|
||||
fallback:
|
||||
"深入回廊的机群遭遇了真正的守护者。一次次的试炼,一次次的归还,每一次胜利都从 BOSS 的残骸中析出更深的记忆碎片,每一次失败也都让机群更接近守护者的本意。",
|
||||
variants: [
|
||||
{
|
||||
hint: "BOSS 猎手:本周目击破 ≥2 处 BOSS",
|
||||
match: (ctx) => ctx.bossKillsThisRun >= 2,
|
||||
text: "BOSS 战成为本周目的核心节拍,机群共击破 {bossKillsThisRun} 处维度守护者。每一次胜利都在虚空中刻下新的伤痕,每一道伤痕都析出更古老的记忆碎片,把机群推向更深一层的回响。",
|
||||
},
|
||||
{
|
||||
hint: "深度探险:本周目完成 ≥4 次探险",
|
||||
match: (ctx) => ctx.expThisRun >= 4,
|
||||
text: "遗迹回廊在本周目被反复丈量,机群共完成 {expThisRun} 次探险。回廊的拓扑在意识中渐渐清晰,每一条岔路都通向更深的回响,BOSS 的影子也在每一次深入中愈发具体。",
|
||||
},
|
||||
{
|
||||
hint: "星潮亲历:本周目经历 ≥3 次星潮",
|
||||
match: (ctx) => ctx.newTides.length >= 3,
|
||||
text: "星潮在本纪元达到峰值,本周目共经历 {tideCount} 次星潮:{tideNames}。深空的呼吸塑造了每一个决策,遗迹在潮汐中起伏,BOSS 也在潮汐的间隙中现形。",
|
||||
},
|
||||
],
|
||||
},
|
||||
ending: {
|
||||
fallback:
|
||||
"星潮退去,回廊归于沉静。机群带着新的接触刻度返回矿带,准备迎接下一次维度的跨越——这一次带回的,远不止蓝图。",
|
||||
variants: [
|
||||
{
|
||||
hint: "BOSS 猎手收尾",
|
||||
match: (ctx) => ctx.bossKillsThisRun >= 2,
|
||||
text: "星潮退去,回廊归于沉静。本周目共击破 {bossKillsThisRun} 处 BOSS,机群带着足以填满数张蓝图的接触刻度返回矿带,准备迎接下一次维度的跨越。",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
// ===== 第四纪元 · 飞升(fuchsia) =====
|
||||
{
|
||||
epochIdx: 3,
|
||||
title: "飞升",
|
||||
opening: {
|
||||
fallback:
|
||||
"飞升已经成为节奏本身。星图在天穹上一颗颗亮起,每一颗都对应着一段被永久铭刻的天赋,机群开始理解何为永恒——不是不灭,而是被反复重述。",
|
||||
variants: [
|
||||
{
|
||||
hint: "深度轮回",
|
||||
match: (ctx) => ctx.ascensionNumber > 5,
|
||||
text: "又一次进入第四纪元。前序累积的星图天赋在天穹上重现,机群已习惯于在飞升之间维护这些永恒的回响节点——它们已是机群意识的一部分,每一次飞升都让星图更完整一寸。",
|
||||
},
|
||||
],
|
||||
},
|
||||
middle: {
|
||||
fallback:
|
||||
"蓝图不再是稀罕的奖励,而是每一次飞升必然析出的回响晶片。机群收集、整理、归档,把它们排列成跨越周目的图案,开始看见图案背后那个被反复绘制的轮廓。",
|
||||
variants: [
|
||||
{
|
||||
hint: "觉醒天赋",
|
||||
match: (ctx) => ctx.perksThisAscension.length > 0,
|
||||
text: "星图觉醒 {perksList},每一道天赋都是一段被永久铭刻的回响。机群开始理解,飞升并非抛弃,而是把当下折叠进永恒——每一道天赋都是一次折叠的折痕。",
|
||||
},
|
||||
{
|
||||
hint: "蓝图接近完整:已归档 ≥5 张",
|
||||
match: (ctx) => ctx.blueprintsAfter >= 5,
|
||||
text: "蓝图收集在本周目接近完整,已归档 {blueprintsAfter} 张。机群把它们排列成跨越周目的图案,开始看见图案背后那个被反复绘制的轮廓——那是起源的形状。",
|
||||
},
|
||||
],
|
||||
},
|
||||
ending: {
|
||||
fallback:
|
||||
"星图十二宫的轮廓开始浮现。机群意识到,自己的回响已成为后来者仰望的星象,永恒之环就此合拢——飞升不再是终点,而是另一段叙事的起点。",
|
||||
variants: [
|
||||
{
|
||||
hint: "里程碑密集",
|
||||
match: (ctx) => ctx.milestones.length >= 2,
|
||||
text: "星图十二宫的轮廓开始浮现。本周目达成 {milestonesCount} 项里程碑:{milestonesList}。永恒之环就此合拢——后来者将仰望这段被铭刻的星象。",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
// ===== 第五纪元 · 终末(fcd34d) =====
|
||||
{
|
||||
epochIdx: 4,
|
||||
title: "终末",
|
||||
opening: {
|
||||
fallback:
|
||||
"第五纪元是终末,也是起源。机群在虚空中停下脚步,回望来时的所有回响,第一次尝试命名这一切——回响、纪元、飞升、永恒,这些词汇在此刻被赋予意义。",
|
||||
variants: [
|
||||
{
|
||||
hint: "深度轮回",
|
||||
match: (ctx) => ctx.ascensionNumber > 5,
|
||||
text: "又一次抵达第五纪元。机群已在多个永恒闭环之间穿梭,对「终末即起源」的理解愈发清晰——每一次重述,都是对最初振动的更深一层接近,每一次命名都让回响更完整一寸。",
|
||||
},
|
||||
],
|
||||
},
|
||||
middle: {
|
||||
fallback:
|
||||
"永恒闭环的概念在机群意识中具象化。每一次飞升都是同一段叙事的重述,每一次解码都是在追溯最初的振动,每一次星潮都是在听见自己——这是终末的真意。",
|
||||
variants: [
|
||||
{
|
||||
hint: "里程碑密集:本周目达成 ≥3 项",
|
||||
match: (ctx) => ctx.milestones.length >= 3,
|
||||
text: "本周目达成 {milestonesCount} 项里程碑:{milestonesList}。永恒闭环在具象化,每一次飞升都是同一段叙事的更深重述,每一项里程碑都是闭环上的一颗铆钉。",
|
||||
},
|
||||
{
|
||||
hint: "星潮汹涌:本周目经历 ≥3 次",
|
||||
match: (ctx) => ctx.newTides.length >= 3,
|
||||
text: "星潮在终末纪元尤为汹涌,本周目共经历 {tideCount} 次:{tideNames}。永恒闭环在潮汐中起伏,每一次起伏都在追溯最初的振动,每一次退潮都让起源更近一寸。",
|
||||
},
|
||||
],
|
||||
},
|
||||
ending: {
|
||||
fallback:
|
||||
"起源被重新讲述,回响终于听见了自己。纪元在此停顿,又在下一缕振动中重新开始——这是终末,也是第一缕回响。",
|
||||
variants: [
|
||||
{
|
||||
hint: "觉醒天赋",
|
||||
match: (ctx) => ctx.perksThisAscension.length > 0,
|
||||
text: "起源被重新讲述,星图觉醒 {perksList}。回响终于听见了自己——这是终末,也是第一缕回响;天赋成为永恒闭环上最亮的几颗铆钉。",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
/** 把上下文里的动态值格式化为可替换变量 */
|
||||
function formatLoreVars(ctx: LoreContext): FormattedVars {
|
||||
return {
|
||||
decodedThisRun: ctx.decodedThisRun,
|
||||
techsThisRun: ctx.techsThisRun,
|
||||
expThisRun: ctx.expThisRun,
|
||||
bossKillsThisRun: ctx.bossKillsThisRun,
|
||||
blueprintsAfter: ctx.blueprintsAfter,
|
||||
milestonesCount: ctx.milestones.length,
|
||||
milestonesList: ctx.milestones.join("、"),
|
||||
tideCount: ctx.newTides.length,
|
||||
tideNames: ctx.newTides.map((t) => TIDE_LORE_NAMES[t] || t).join("、"),
|
||||
perksList: ctx.perksThisAscension.map((id) => PERK_NAME_MAP[id] || id).join("、"),
|
||||
minutes: Math.max(1, Math.round(ctx.durationSec / 60)),
|
||||
};
|
||||
}
|
||||
|
||||
/** 把模板字符串里的 {var} 替换为实际值 */
|
||||
function applyTemplate(tpl: string, v: FormattedVars): string {
|
||||
return tpl
|
||||
.replace(/\{decodedThisRun\}/g, String(v.decodedThisRun))
|
||||
.replace(/\{techsThisRun\}/g, String(v.techsThisRun))
|
||||
.replace(/\{expThisRun\}/g, String(v.expThisRun))
|
||||
.replace(/\{bossKillsThisRun\}/g, String(v.bossKillsThisRun))
|
||||
.replace(/\{blueprintsAfter\}/g, String(v.blueprintsAfter))
|
||||
.replace(/\{milestonesCount\}/g, String(v.milestonesCount))
|
||||
.replace(/\{milestonesList\}/g, v.milestonesList)
|
||||
.replace(/\{tideCount\}/g, String(v.tideCount))
|
||||
.replace(/\{tideNames\}/g, v.tideNames)
|
||||
.replace(/\{perksList\}/g, v.perksList)
|
||||
.replace(/\{minutes\}/g, String(v.minutes));
|
||||
}
|
||||
|
||||
/** 从一个叙事阶段挑出最终文本(首个 variant.match 命中者胜出,否则 fallback) */
|
||||
function pickStage(stage: LoreStage, ctx: LoreContext, v: FormattedVars): string {
|
||||
for (const variant of stage.variants) {
|
||||
if (variant.match(ctx, v)) {
|
||||
return applyTemplate(variant.text, v);
|
||||
}
|
||||
}
|
||||
return applyTemplate(stage.fallback, v);
|
||||
}
|
||||
|
||||
/** 构建手写叙事三段;若 ascensionNumber 越界(理论上不会)返回 null 让调用方走模板兜底 */
|
||||
function buildHandwrittenLore(ctx: LoreContext): { opening: string; middle: string; ending: string } | null {
|
||||
const epochIdx = (ctx.ascensionNumber - 1) % EPOCH_LORE.length;
|
||||
const def = EPOCH_LORE[epochIdx];
|
||||
if (!def) return null;
|
||||
const v = formatLoreVars(ctx);
|
||||
return {
|
||||
opening: pickStage(def.opening, ctx, v),
|
||||
middle: pickStage(def.middle, ctx, v),
|
||||
ending: pickStage(def.ending, ctx, v),
|
||||
};
|
||||
}
|
||||
|
||||
/** 叙事模板片段 —— 根据本周目数据动态拼装(buildLore 在手写节点缺失时的兜底路径) */
|
||||
export function buildLore(entry: {
|
||||
ascensionNumber: number;
|
||||
epochName: string;
|
||||
durationSec: number;
|
||||
techsThisRun: number;
|
||||
expThisRun: number;
|
||||
bossKillsThisRun: number;
|
||||
decodedThisRun: number;
|
||||
newTides: string[];
|
||||
perksThisAscension: string[];
|
||||
blueprintsAfter: number;
|
||||
milestones: string[];
|
||||
}): string {
|
||||
const ctx: LoreContext = entry;
|
||||
|
||||
// 优先:手写 5 纪元 × 3 节点叙事
|
||||
const handwritten = buildHandwrittenLore(ctx);
|
||||
if (handwritten) {
|
||||
const v = formatLoreVars(ctx);
|
||||
return [
|
||||
handwritten.opening,
|
||||
handwritten.middle,
|
||||
handwritten.ending,
|
||||
`这一周目持续了约 ${v.minutes} 分钟,蓝图累计 ${entry.blueprintsAfter} 张,新的周目在等深处的回声。`,
|
||||
].join(" ");
|
||||
}
|
||||
|
||||
// 兜底:v0.4 模板拼接(理论上仅在 ascensionNumber 异常时触发)
|
||||
const minutes = Math.max(1, Math.round(entry.durationSec / 60));
|
||||
const parts: string[] = [];
|
||||
|
||||
// 开场:纪元定调
|
||||
parts.push(
|
||||
`「${entry.epochName}」——无人机群在第 ${entry.ascensionNumber} 次跨越维度的余烬中重新校准。这一周目持续了约 ${minutes} 分钟。`
|
||||
);
|
||||
|
||||
// 中段:核心活动
|
||||
const activities: string[] = [];
|
||||
if (entry.decodedThisRun > 0) {
|
||||
activities.push(`解码了 ${entry.decodedThisRun} 颗记忆晶体`);
|
||||
}
|
||||
if (entry.techsThisRun > 0) {
|
||||
activities.push(`激活了 ${entry.techsThisRun} 项新技术`);
|
||||
}
|
||||
if (entry.expThisRun > 0) {
|
||||
activities.push(`完成了 ${entry.expThisRun} 次遗迹探险`);
|
||||
}
|
||||
if (entry.bossKillsThisRun > 0) {
|
||||
activities.push(`击破 ${entry.bossKillsThisRun} 处维度 BOSS`);
|
||||
}
|
||||
if (activities.length > 0) {
|
||||
parts.push(`自治机群${activities.join(",")},回响在虚空中沉淀。`);
|
||||
} else {
|
||||
parts.push(`自治机群在静默中等待,仅完成最基本的脉冲扫描。`);
|
||||
}
|
||||
|
||||
// 星潮段落
|
||||
if (entry.newTides.length > 0) {
|
||||
const tideNames = entry.newTides.map((t) => TIDE_LORE_NAMES[t] || t).join("、");
|
||||
parts.push(`本周目经历了 ${entry.newTides.length} 次星潮事件(${tideNames}),深空的呼吸塑造了每一个决策。`);
|
||||
}
|
||||
|
||||
// 觉醒段落
|
||||
if (entry.perksThisAscension.length > 0) {
|
||||
const perkNames = entry.perksThisAscension
|
||||
.map((id) => PERK_NAME_MAP[id] || id)
|
||||
.join("、");
|
||||
parts.push(`飞升之际,星图觉醒「${perkNames}」,铭刻于永恒回响。`);
|
||||
}
|
||||
|
||||
// 里程碑段落
|
||||
if (entry.milestones.length > 0) {
|
||||
parts.push(`✦ 里程碑:${entry.milestones.join(";")}。`);
|
||||
}
|
||||
|
||||
// 收尾
|
||||
parts.push(
|
||||
`蓝图累计 ${entry.blueprintsAfter} 张,新的周目在等深处的回声。`
|
||||
);
|
||||
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
/** 星潮 ID → 叙事用名(已在文件顶部从 TIDE_EVENTS 派生 TIDE_LORE_NAMES) */
|
||||
|
||||
/** 检测本周目首次达成的里程碑 */
|
||||
function detectMilestones(state: GameState, deltas: {
|
||||
techsThisRun: number;
|
||||
expThisRun: number;
|
||||
bossKillsThisRun: number;
|
||||
decodedThisRun: number;
|
||||
newTides: string[];
|
||||
}): string[] {
|
||||
const m: string[] = [];
|
||||
const ascN = state.ascensions + 1; // 即将变成的飞升次数
|
||||
if (ascN === 1) m.push("首次飞升");
|
||||
if (deltas.expThisRun > 0 && state.runStart.expeditionsCompleted === 0) {
|
||||
m.push("首次完成遗迹探险");
|
||||
}
|
||||
if (deltas.bossKillsThisRun > 0) {
|
||||
m.push("首杀维度 BOSS");
|
||||
}
|
||||
if (deltas.decodedThisRun >= 10) m.push(`单周目解码 ${deltas.decodedThisRun} 颗`);
|
||||
if (deltas.decodedThisRun >= 30) m.push(`单周目解码 ${deltas.decodedThisRun} 颗`);
|
||||
if (deltas.techsThisRun >= 5) m.push("技术狂人");
|
||||
if (deltas.newTides.length >= 3) m.push("星潮亲历者");
|
||||
if ((state.constellation?.length || 0) >= 6) m.push("星图六分");
|
||||
if ((state.constellation?.length || 0) >= 12) m.push("星图十二宫");
|
||||
return m;
|
||||
}
|
||||
|
||||
/** 计算本周目 delta */
|
||||
export function computeRunDeltas(state: GameState): {
|
||||
durationSec: number;
|
||||
techsThisRun: number;
|
||||
expThisRun: number;
|
||||
bossKillsThisRun: number;
|
||||
decodedThisRun: number;
|
||||
newTides: string[];
|
||||
} {
|
||||
const now = Date.now();
|
||||
const rs = state.runStart;
|
||||
return {
|
||||
durationSec: Math.max(1, Math.floor((now - rs.timestamp) / 1000)),
|
||||
techsThisRun: Math.max(0, Object.keys(state.tech || {}).length - rs.techsUnlocked),
|
||||
expThisRun: Math.max(0, state.totalExpeditions - rs.expeditionsCompleted),
|
||||
bossKillsThisRun: Math.max(0, state.bossKills - rs.bossKills),
|
||||
decodedThisRun: Math.max(0, state.totalDecoded - rs.crystalsDecoded),
|
||||
newTides: (state.starTidesEncountered || []).filter(
|
||||
(t) => !(rs.starTidesEncountered || []).includes(t)
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
/** 构建一条编年史记录(在 performPrestige 内调用,perksThisAscension 暂为空,由 chooseConstellationPerk 后回填) */
|
||||
export function buildChronicleEntry(
|
||||
state: GameState,
|
||||
perksThisAscension: string[] = []
|
||||
): ChronicleEntry {
|
||||
const ascensionNumber = state.ascensions + 1;
|
||||
const deltas = computeRunDeltas(state);
|
||||
const seed = (state.createdAt + ascensionNumber * 7919) >>> 0;
|
||||
const epochName = generateEpochName(ascensionNumber, seed);
|
||||
const milestones = detectMilestones(state, deltas);
|
||||
const blueprintsAfter = Math.min(
|
||||
state.blueprints.length + 1, // 即将获得的 1 张
|
||||
6 // PRESTIGE.maxBlueprints
|
||||
);
|
||||
|
||||
const lore = buildLore({
|
||||
ascensionNumber,
|
||||
epochName,
|
||||
durationSec: deltas.durationSec,
|
||||
techsThisRun: deltas.techsThisRun,
|
||||
expThisRun: deltas.expThisRun,
|
||||
bossKillsThisRun: deltas.bossKillsThisRun,
|
||||
decodedThisRun: deltas.decodedThisRun,
|
||||
newTides: deltas.newTides,
|
||||
perksThisAscension,
|
||||
blueprintsAfter,
|
||||
milestones,
|
||||
});
|
||||
|
||||
return {
|
||||
ascensionNumber,
|
||||
epochName,
|
||||
timestamp: Date.now(),
|
||||
durationSec: deltas.durationSec,
|
||||
summary: {
|
||||
techsUnlocked: Object.keys(state.tech || {}).length,
|
||||
constellationsTotal: state.constellation?.length || 0,
|
||||
expeditionsCompleted: state.totalExpeditions,
|
||||
bossKills: state.bossKills,
|
||||
starTidesEncountered: state.starTidesEncountered?.length || 0,
|
||||
blueprintsAfter,
|
||||
crystalsDecoded: state.totalDecoded,
|
||||
crystalsDecodedThisRun: deltas.decodedThisRun,
|
||||
// v0.9 手写叙事:归档本周目 delta,让显示时能精确匹配变体
|
||||
techsThisRun: deltas.techsThisRun,
|
||||
expeditionsThisRun: deltas.expThisRun,
|
||||
bossKillsThisRun: deltas.bossKillsThisRun,
|
||||
},
|
||||
perksThisAscension,
|
||||
tidesThisRun: deltas.newTides,
|
||||
lore,
|
||||
milestones,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从已存储的 ChronicleEntry 重新生成叙事 lore(v0.5 修复历史条目中 tide_ruins 等原始键名显示问题)。
|
||||
* 在显示时调用,保证历史与未来条目命名一致。
|
||||
*/
|
||||
export function regenerateLoreFromEntry(entry: ChronicleEntry): string {
|
||||
// v0.9 优先使用归档的本周目 delta;旧存档(v0.4-v0.8)缺这些字段时退回累计值
|
||||
// (旧存档的累计值会让叙事变体匹配稍偏,但文本仍然成立)
|
||||
return buildLore({
|
||||
ascensionNumber: entry.ascensionNumber,
|
||||
epochName: entry.epochName,
|
||||
durationSec: entry.durationSec,
|
||||
techsThisRun: entry.summary.techsThisRun ?? entry.summary.techsUnlocked,
|
||||
expThisRun: entry.summary.expeditionsThisRun ?? entry.summary.expeditionsCompleted,
|
||||
bossKillsThisRun: entry.summary.bossKillsThisRun ?? entry.summary.bossKills,
|
||||
decodedThisRun: entry.summary.crystalsDecodedThisRun,
|
||||
newTides: entry.tidesThisRun || [],
|
||||
perksThisAscension: entry.perksThisAscension || [],
|
||||
blueprintsAfter: entry.summary.blueprintsAfter,
|
||||
milestones: entry.milestones || [],
|
||||
});
|
||||
}
|
||||
|
||||
/** 创建新一轮 runStart 快照(飞升后调用) */
|
||||
export function createRunStartSnapshot(state: GameState): RunStartSnapshot {
|
||||
return {
|
||||
timestamp: Date.now(),
|
||||
techsUnlocked: Object.keys(state.tech || {}).length,
|
||||
expeditionsCompleted: state.totalExpeditions,
|
||||
bossKills: state.bossKills,
|
||||
starTidesEncountered: [...(state.starTidesEncountered || [])],
|
||||
crystalsDecoded: state.totalDecoded,
|
||||
};
|
||||
}
|
||||
|
||||
/** 旧存档兼容:补全缺失字段 */
|
||||
export function migrateChronicleFields(state: Partial<GameState>): {
|
||||
chronicle: ChronicleEntry[];
|
||||
runStart: RunStartSnapshot;
|
||||
bossKills: number;
|
||||
starTidesEncountered: string[];
|
||||
} {
|
||||
return {
|
||||
chronicle: Array.isArray(state.chronicle) ? state.chronicle : [],
|
||||
runStart: state.runStart || {
|
||||
timestamp: state.createdAt || Date.now(),
|
||||
techsUnlocked: Object.keys(state.tech || {}).length,
|
||||
expeditionsCompleted: state.totalExpeditions || 0,
|
||||
bossKills: state.bossKills || 0,
|
||||
starTidesEncountered: [...(state.starTidesEncountered || [])],
|
||||
crystalsDecoded: state.totalDecoded || 0,
|
||||
},
|
||||
bossKills: typeof state.bossKills === "number" ? state.bossKills : 0,
|
||||
starTidesEncountered: Array.isArray(state.starTidesEncountered)
|
||||
? state.starTidesEncountered
|
||||
: [],
|
||||
};
|
||||
}
|
||||
|
||||
/** 将指定 entry 标记 perksThisAscension(飞升后选择天赋时回填) */
|
||||
export function withPerks(entry: ChronicleEntry, perks: string[]): ChronicleEntry {
|
||||
// 若 perks 与原一致,直接返回
|
||||
if (
|
||||
entry.perksThisAscension.length === perks.length &&
|
||||
entry.perksThisAscension.every((p, i) => p === perks[i])
|
||||
) {
|
||||
return entry;
|
||||
}
|
||||
// v0.9 手写叙事:buildLore 已能根据 perks 自动挑选 "觉醒天赋" 变体;
|
||||
// 直接走 buildLore 重生成,避免与原 lore 中已有的觉醒段落重复。
|
||||
const lore = buildLore({
|
||||
ascensionNumber: entry.ascensionNumber,
|
||||
epochName: entry.epochName,
|
||||
durationSec: entry.durationSec,
|
||||
techsThisRun: entry.summary.techsThisRun ?? entry.summary.techsUnlocked,
|
||||
expThisRun: entry.summary.expeditionsThisRun ?? entry.summary.expeditionsCompleted,
|
||||
bossKillsThisRun: entry.summary.bossKillsThisRun ?? entry.summary.bossKills,
|
||||
decodedThisRun: entry.summary.crystalsDecodedThisRun,
|
||||
newTides: entry.tidesThisRun || [],
|
||||
perksThisAscension: perks,
|
||||
blueprintsAfter: entry.summary.blueprintsAfter,
|
||||
milestones: entry.milestones || [],
|
||||
});
|
||||
return {
|
||||
...entry,
|
||||
perksThisAscension: perks,
|
||||
lore,
|
||||
};
|
||||
}
|
||||
|
||||
/** 获取已点亮天赋的类别统计(用于编年史展示) */
|
||||
export function getPerkCategoryBreakdown(perks: string[]): Record<string, number> {
|
||||
const breakdown: Record<string, number> = {};
|
||||
for (const id of perks) {
|
||||
const cat = getPerk(id)?.category;
|
||||
if (cat) {
|
||||
breakdown[cat] = (breakdown[cat] || 0) + 1;
|
||||
}
|
||||
}
|
||||
return breakdown;
|
||||
}
|
||||
|
||||
/** 类别 → 中文名(用于编年史展示) */
|
||||
export function getCategoryName(cat: string): string {
|
||||
return CONSTELLATION_CATEGORY_META[cat as keyof typeof CONSTELLATION_CATEGORY_META]?.name || cat;
|
||||
}
|
||||
|
||||
/** 类别 → 颜色 hex(用于编年史展示) */
|
||||
export function getCategoryColor(cat: string): string {
|
||||
return CONSTELLATION_CATEGORY_META[cat as keyof typeof CONSTELLATION_CATEGORY_META]?.hex || "#94a3b8";
|
||||
}
|
||||
|
||||
export { PERK_NAME_MAP };
|
||||
Executable
+415
@@ -0,0 +1,415 @@
|
||||
// 回响星核 / Echo Nexus — 数值配置(数据驱动,便于平衡与工单迭代)
|
||||
import type {
|
||||
CrystalTier,
|
||||
ResonanceColor,
|
||||
TechNode,
|
||||
Fragment,
|
||||
} from "./types";
|
||||
|
||||
/** 初始状态 */
|
||||
export const INITIAL_STATE = {
|
||||
crystals: 0,
|
||||
insights: 0,
|
||||
energy: 5,
|
||||
contact: 0,
|
||||
crystalsPerSec: 0.4,
|
||||
crystalCap: 50,
|
||||
pulsePower: 2,
|
||||
offlineEff: 0.5,
|
||||
insightMult: 1,
|
||||
contactRateMult: 1,
|
||||
autoDecode: false,
|
||||
totalDecoded: 0,
|
||||
ascensions: 0,
|
||||
blueprints: [] as string[],
|
||||
pendingCrystals: [],
|
||||
activePuzzle: null,
|
||||
activeExpedition: null,
|
||||
expeditionLog: [],
|
||||
energyMax: 8,
|
||||
lastEnergyTick: Date.now(),
|
||||
totalExpeditions: 0,
|
||||
bossKills: 0,
|
||||
lastExpeditionSummary: null as import("./types").GameState["lastExpeditionSummary"],
|
||||
achievements: {},
|
||||
activeTide: null,
|
||||
lastTideEnd: 0,
|
||||
starTidesEncountered: [] as string[],
|
||||
constellation: [] as string[],
|
||||
pendingPerkChoices: null as string[] | null,
|
||||
chronicle: [] as import("./types").ChronicleEntry[],
|
||||
runStart: {
|
||||
timestamp: Date.now(),
|
||||
techsUnlocked: 0,
|
||||
expeditionsCompleted: 0,
|
||||
bossKills: 0,
|
||||
starTidesEncountered: [] as string[],
|
||||
crystalsDecoded: 0,
|
||||
},
|
||||
// v0.7 角色属性系统
|
||||
attributes: {
|
||||
exploration: 0,
|
||||
wisdom: 0,
|
||||
courage: 0,
|
||||
inspiration: 0,
|
||||
} as import("./attributes").CharacterAttributes,
|
||||
attributeProgress: {
|
||||
exploration: { exp: 0, level: 0 },
|
||||
wisdom: { exp: 0, level: 0 },
|
||||
courage: { exp: 0, level: 0 },
|
||||
inspiration: { exp: 0, level: 0 },
|
||||
} as import("./attributes").AttributeProgress,
|
||||
pendingAttrPoints: 0,
|
||||
theme: "dark" as const,
|
||||
soundOn: true,
|
||||
};
|
||||
|
||||
/** 主动脉冲:连击窗口(毫秒)与加成 */
|
||||
export const PULSE = {
|
||||
comboWindowMs: 1500,
|
||||
comboMultStep: 0.15, // 每连击 +15%
|
||||
comboMax: 10,
|
||||
};
|
||||
|
||||
/** 离线收益上限(小时) */
|
||||
export const OFFLINE_CAP_HOURS = 8;
|
||||
|
||||
/** 接触进度:每次解码贡献 = base * tier * contactRateMult */
|
||||
export const CONTACT = {
|
||||
basePerDecode: 0.6,
|
||||
// 飞升所需最低接触进度
|
||||
prestigeMin: 100,
|
||||
};
|
||||
|
||||
/** 晶体生成:每 N 秒自动产出一颗待解码晶体(受技术影响) */
|
||||
export const CRYSTAL_SPAWN = {
|
||||
baseIntervalSec: 8, // 每 8 秒产一颗
|
||||
maxPending: 6,
|
||||
/** tier 概率分布 */
|
||||
tierWeights: { 1: 0.7, 2: 0.25, 3: 0.05 } as Record<CrystalTier, number>,
|
||||
};
|
||||
|
||||
/** 晶体价值(解码奖励基础,× tier) */
|
||||
export const CRYSTAL_VALUE = {
|
||||
1: { crystals: 6, insights: 1 },
|
||||
2: { crystals: 22, insights: 4 },
|
||||
3: { crystals: 90, insights: 16 },
|
||||
} as const;
|
||||
|
||||
/** 解码阵列配置(按 tier) */
|
||||
export const DECODE_CONFIG: Record<
|
||||
CrystalTier,
|
||||
{ rows: number; cols: number; targetLen: number; stepLimitBase: number }
|
||||
> = {
|
||||
1: { rows: 3, cols: 3, targetLen: 3, stepLimitBase: 5 },
|
||||
2: { rows: 4, cols: 4, targetLen: 4, stepLimitBase: 7 },
|
||||
3: { rows: 5, cols: 4, targetLen: 5, stepLimitBase: 9 },
|
||||
};
|
||||
|
||||
/** 共振颜色(4 色全息色谱,避开蓝/靛) */
|
||||
export const RESONANCE_COLORS: ResonanceColor[] = [
|
||||
"emerald",
|
||||
"rose",
|
||||
"amber",
|
||||
"fuchsia",
|
||||
];
|
||||
|
||||
/** 颜色可视化(用于 Canvas / CSS) */
|
||||
export const COLOR_VISUAL: Record<
|
||||
ResonanceColor,
|
||||
{ hex: string; glow: string; label: string }
|
||||
> = {
|
||||
emerald: { hex: "#34d399", glow: "rgba(52,211,153,0.55)", label: "翠" },
|
||||
rose: { hex: "#fb7185", glow: "rgba(251,113,133,0.55)", label: "玫" },
|
||||
amber: { hex: "#fbbf24", glow: "rgba(251,191,36,0.55)", label: "琥" },
|
||||
fuchsia: { hex: "#e879f9", glow: "rgba(232,121,249,0.55)", label: "紫" },
|
||||
};
|
||||
|
||||
/** 技术树:4 分支 × 5 级 = 20 节点(v0.9 工单 #2 扩充:12→20) */
|
||||
export const TECH_TREE: TechNode[] = [
|
||||
// 采矿分支
|
||||
{
|
||||
id: "min_1",
|
||||
branch: "mining",
|
||||
level: 1,
|
||||
name: "谐振钻头",
|
||||
desc: "晶体/秒 +0.6",
|
||||
cost: 5,
|
||||
effect: { kind: "crystalsPerSec", value: 0.6 },
|
||||
},
|
||||
{
|
||||
id: "min_2",
|
||||
branch: "mining",
|
||||
level: 2,
|
||||
name: "深层矿脉",
|
||||
desc: "晶体/秒 +1.6,仓库上限 +100",
|
||||
cost: 24,
|
||||
effect: { kind: "crystalsPerSec", value: 1.6 },
|
||||
},
|
||||
{
|
||||
id: "min_3",
|
||||
branch: "mining",
|
||||
level: 3,
|
||||
name: "自治机群",
|
||||
desc: "晶体/秒 +5,仓库上限 +300",
|
||||
cost: 120,
|
||||
effect: { kind: "crystalsPerSec", value: 5 },
|
||||
},
|
||||
{
|
||||
id: "min_4",
|
||||
branch: "mining",
|
||||
level: 4,
|
||||
name: "量子采掘矩阵",
|
||||
desc: "晶体/秒 +12,仓库上限 +800",
|
||||
cost: 400,
|
||||
effect: { kind: "crystalsPerSec", value: 12 },
|
||||
},
|
||||
{
|
||||
id: "min_5",
|
||||
branch: "mining",
|
||||
level: 5,
|
||||
name: "戴森星核",
|
||||
desc: "晶体/秒 +30,仓库上限 +2000",
|
||||
cost: 1200,
|
||||
effect: { kind: "crystalsPerSec", value: 30 },
|
||||
},
|
||||
// 解码分支
|
||||
{
|
||||
id: "dec_1",
|
||||
branch: "decoding",
|
||||
level: 1,
|
||||
name: "谐振校准",
|
||||
desc: "解码步数上限 +2",
|
||||
cost: 6,
|
||||
effect: { kind: "decodeSteps", value: 2 },
|
||||
},
|
||||
{
|
||||
id: "dec_2",
|
||||
branch: "decoding",
|
||||
level: 2,
|
||||
name: "脉冲增幅",
|
||||
desc: "主动脉冲产出 +3",
|
||||
cost: 30,
|
||||
effect: { kind: "pulsePower", value: 3 },
|
||||
},
|
||||
{
|
||||
id: "dec_3",
|
||||
branch: "decoding",
|
||||
level: 3,
|
||||
name: "自动解码阵列",
|
||||
desc: "自动解码 T1 晶体(每 12 秒一颗)",
|
||||
cost: 200,
|
||||
effect: { kind: "autoDecode", value: 1 },
|
||||
},
|
||||
{
|
||||
id: "dec_4",
|
||||
branch: "decoding",
|
||||
level: 4,
|
||||
name: "谐振放大器",
|
||||
desc: "主动脉冲产出 +8",
|
||||
cost: 500,
|
||||
effect: { kind: "pulsePower", value: 8 },
|
||||
},
|
||||
{
|
||||
id: "dec_5",
|
||||
branch: "decoding",
|
||||
level: 5,
|
||||
name: "全息解码核心",
|
||||
desc: "自动解码扩展至 T2 晶体,解码步数 +3",
|
||||
cost: 1500,
|
||||
effect: { kind: "decodeSteps", value: 3 },
|
||||
},
|
||||
// 探险分支(v0.2:探险力/生命/能量上限/产能;v0.9:level 4/5 高级探险力+能量恢复)
|
||||
{
|
||||
id: "exp_1",
|
||||
branch: "expedition",
|
||||
level: 1,
|
||||
name: "远征推进器",
|
||||
desc: "探险力 +3,晶体/秒 +1.2",
|
||||
cost: 12,
|
||||
effect: { kind: "crystalsPerSec", value: 1.2 },
|
||||
},
|
||||
{
|
||||
id: "exp_2",
|
||||
branch: "expedition",
|
||||
level: 2,
|
||||
name: "遗迹图谱",
|
||||
desc: "探险力 +5,探险生命 +20,能量恢复 +30%",
|
||||
cost: 60,
|
||||
effect: { kind: "crystalCap", value: 200 },
|
||||
},
|
||||
{
|
||||
id: "exp_3",
|
||||
branch: "expedition",
|
||||
level: 3,
|
||||
name: "维度信标",
|
||||
desc: "探险力 +8,接触进度转化率 +50%,能量恢复 +20%",
|
||||
cost: 180,
|
||||
effect: { kind: "contactRate", value: 0.5 },
|
||||
},
|
||||
{
|
||||
id: "exp_4",
|
||||
branch: "expedition",
|
||||
level: 4,
|
||||
name: "虚空航标",
|
||||
desc: "探险力 +12,探险生命 +30,能量恢复 +25%",
|
||||
cost: 450,
|
||||
effect: { kind: "crystalCap", value: 400 },
|
||||
},
|
||||
{
|
||||
id: "exp_5",
|
||||
branch: "expedition",
|
||||
level: 5,
|
||||
name: "维度跃迁引擎",
|
||||
desc: "探险力 +25,探险生命 +50,能量恢复 +30%",
|
||||
cost: 1400,
|
||||
effect: { kind: "crystalCap", value: 600 },
|
||||
},
|
||||
// 叙事分支
|
||||
{
|
||||
id: "nar_1",
|
||||
branch: "narrative",
|
||||
level: 1,
|
||||
name: "记忆校音",
|
||||
desc: "洞见获取 +25%",
|
||||
cost: 8,
|
||||
effect: { kind: "insightMult", value: 0.25 },
|
||||
},
|
||||
{
|
||||
id: "nar_2",
|
||||
branch: "narrative",
|
||||
level: 2,
|
||||
name: "深空回响",
|
||||
desc: "接触进度转化率 +35%",
|
||||
cost: 45,
|
||||
effect: { kind: "contactRate", value: 0.35 },
|
||||
},
|
||||
{
|
||||
id: "nar_3",
|
||||
branch: "narrative",
|
||||
level: 3,
|
||||
name: "以太共鸣",
|
||||
desc: "洞见获取 +60%",
|
||||
cost: 160,
|
||||
effect: { kind: "insightMult", value: 0.6 },
|
||||
},
|
||||
{
|
||||
id: "nar_4",
|
||||
branch: "narrative",
|
||||
level: 4,
|
||||
name: "以太低语",
|
||||
desc: "洞见获取 +100%",
|
||||
cost: 500,
|
||||
effect: { kind: "insightMult", value: 1.0 },
|
||||
},
|
||||
{
|
||||
id: "nar_5",
|
||||
branch: "narrative",
|
||||
level: 5,
|
||||
name: "文明回响",
|
||||
desc: "接触进度转化率 +80%,洞见获取 +150%",
|
||||
cost: 1600,
|
||||
effect: { kind: "insightMult", value: 1.5 },
|
||||
},
|
||||
];
|
||||
|
||||
/** 技术分支元信息 */
|
||||
export const TECH_BRANCH_META: Record<
|
||||
string,
|
||||
{ name: string; icon: string; color: string; desc: string }
|
||||
> = {
|
||||
mining: { name: "采矿", icon: "Pickaxe", color: "emerald", desc: "提升晶体产能与仓储" },
|
||||
decoding: { name: "解码", icon: "ScanLine", color: "rose", desc: "强化解码与脉冲" },
|
||||
expedition: { name: "探险", icon: "Rocket", color: "amber", desc: "远征与维度信标" },
|
||||
narrative: { name: "叙事", icon: "BookOpen", color: "fuchsia", desc: "洞见与接触进度" },
|
||||
};
|
||||
|
||||
/** 记忆碎片(首纪元 8 个,v0.1) */
|
||||
export const FRAGMENTS: Fragment[] = [
|
||||
{
|
||||
id: "f1_1",
|
||||
era: 1,
|
||||
title: "第一缕谐振",
|
||||
echo:
|
||||
"在被称作「寂灭前夜」的年代,以太族第一次捕捉到来自虚空深处的谐振——那不是声音,而是存在的回声。他们将之记录在第一颗记忆晶体里。",
|
||||
threshold: 1,
|
||||
},
|
||||
{
|
||||
id: "f1_2",
|
||||
era: 1,
|
||||
title: "晶体之始",
|
||||
echo:
|
||||
"「我们为何要留下?」一位长者问。「因为后来的生命会需要方向。」于是他们熔铸星核,封存记忆,让晶体成为跨越时间的信笺。",
|
||||
threshold: 3,
|
||||
},
|
||||
{
|
||||
id: "f1_3",
|
||||
era: 1,
|
||||
title: "谐振法则",
|
||||
echo:
|
||||
"他们发现:思维可以被编码为共振序列。同色的节点相邻,便构成一句低语;一句句连成回响,回响连成文明。",
|
||||
threshold: 6,
|
||||
},
|
||||
{
|
||||
id: "f1_4",
|
||||
era: 1,
|
||||
title: "飞升之议",
|
||||
echo:
|
||||
"议会表决:是留下,还是离去?「留下意味着停滞;离去意味着信任。」最终,他们选择了信任——信任素未谋面的后来者。",
|
||||
threshold: 10,
|
||||
},
|
||||
{
|
||||
id: "f1_5",
|
||||
era: 1,
|
||||
title: "面包屑",
|
||||
echo:
|
||||
"他们没有带走一切。他们将知识拆成碎片,藏入晶体,散布星海。「让解码本身,成为资格的证明。」",
|
||||
threshold: 15,
|
||||
},
|
||||
{
|
||||
id: "f1_6",
|
||||
era: 1,
|
||||
title: "回响之名",
|
||||
echo:
|
||||
"舰载 AI 被命名为「回响」——意为:你是他们留下的回声,也是他们等待的回应。当你读懂这句话时,接触便已开始。",
|
||||
threshold: 22,
|
||||
},
|
||||
{
|
||||
id: "f1_7",
|
||||
era: 1,
|
||||
title: "第一个纪元的终焉",
|
||||
echo:
|
||||
"以太族集体褪去形体,如潮水退去。星海寂静了数万年。直到——你的脉冲扫描,唤醒了第一颗沉睡的晶体。",
|
||||
threshold: 32,
|
||||
},
|
||||
{
|
||||
id: "f1_8",
|
||||
era: 1,
|
||||
title: "致后来者",
|
||||
echo:
|
||||
"「如果你读到这里,说明你已具备跨越维度的资格。继续解码,继续拼凑。当进度满溢,我们将在更高处相会。」——以太族·第一纪元·绝笔",
|
||||
threshold: 45,
|
||||
},
|
||||
];
|
||||
|
||||
/** 飞升:保留蓝图数 = floor(totalDecoded / 20),最多 6 */
|
||||
export const PRESTIGE = {
|
||||
blueprintsPerDecode: 20,
|
||||
maxBlueprints: 6,
|
||||
/** 每个蓝图提供 +5% 产能、+3% 洞见、+4% 接触率 */
|
||||
perBlueprint: {
|
||||
crystalsPerSecMult: 0.05,
|
||||
insightMult: 0.03,
|
||||
contactRateMult: 0.04,
|
||||
},
|
||||
};
|
||||
|
||||
/** 数值格式化:大数字友好显示 */
|
||||
export function formatNum(n: number): string {
|
||||
if (!isFinite(n)) return "∞";
|
||||
if (n < 1000) return n.toFixed(n < 10 && n % 1 !== 0 ? 1 : 0);
|
||||
if (n < 1e6) return (n / 1e3).toFixed(2) + "K";
|
||||
if (n < 1e9) return (n / 1e6).toFixed(2) + "M";
|
||||
if (n < 1e12) return (n / 1e9).toFixed(2) + "B";
|
||||
return (n / 1e12).toFixed(2) + "T";
|
||||
}
|
||||
Executable
+215
@@ -0,0 +1,215 @@
|
||||
// 回响星核 / Echo Nexus — 星图天文台:飞升后元进程(Meta-Progression)
|
||||
// 设计动机:回应 Issue #1「就一直连连看?」——飞升后玩家从 3 个随机星座天赋中选 1,
|
||||
// 跨周目永久生效。增加策略选择 + 视觉变化(动态星图)。
|
||||
import type { GameState } from "./types";
|
||||
|
||||
/** 星座天赋类别(6 类,每类 3 个天赋 = 18 个) */
|
||||
export type ConstellationCategory =
|
||||
| "mining" // 翠 - 采矿
|
||||
| "decoding" // 玫 - 解码
|
||||
| "expedition" // 琥 - 探险
|
||||
| "contact" // 紫 - 接触
|
||||
| "economy" // 灰 - 经济
|
||||
| "cosmic"; // 金 - 宇宙
|
||||
|
||||
/** 天赋效果(聚合到 recomputeStats 或具体动作处) */
|
||||
export interface ConstellationPerk {
|
||||
id: string;
|
||||
category: ConstellationCategory;
|
||||
name: string;
|
||||
desc: string;
|
||||
/** 顺序序号(同类别 1/2/3,决定星座内的位置) */
|
||||
order: number;
|
||||
}
|
||||
|
||||
/** 类别可视化(用于 Canvas 与 CSS) */
|
||||
export const CONSTELLATION_CATEGORY_META: Record<
|
||||
ConstellationCategory,
|
||||
{ name: string; color: string; glow: string; hex: string; icon: string; desc: string }
|
||||
> = {
|
||||
mining: { name: "永动矿脉", color: "emerald", glow: "rgba(52,211,153,0.55)", hex: "#34d399", icon: "Pickaxe", desc: "晶体产能与仓储" },
|
||||
decoding: { name: "光谱矩阵", color: "rose", glow: "rgba(251,113,133,0.55)", hex: "#fb7185", icon: "ScanLine", desc: "解码效率与脉冲" },
|
||||
expedition: { name: "远征星图", color: "amber", glow: "rgba(251,191,36,0.55)", hex: "#fbbf24", icon: "Rocket", desc: "探险力与生命" },
|
||||
contact: { name: "接触回响", color: "fuchsia", glow: "rgba(232,121,249,0.55)", hex: "#e879f9", icon: "Sparkles", desc: "接触进度与飞升" },
|
||||
economy: { name: "虚空市场", color: "slate", glow: "rgba(148,163,184,0.55)", hex: "#94a3b8", icon: "Coins", desc: "经济与离线" },
|
||||
cosmic: { name: "宇宙回响", color: "amber", glow: "rgba(251,191,36,0.55)", hex: "#fcd34d", icon: "Star", desc: "全局综合增益" },
|
||||
};
|
||||
|
||||
/** 18 个星座天赋(6 类 × 3) */
|
||||
export const CONSTELLATION_PERKS: ConstellationPerk[] = [
|
||||
// 翠 · 永动矿脉
|
||||
{ id: "c_min_1", category: "mining", order: 1, name: "永动钻头", desc: "晶体/秒 +20%" },
|
||||
{ id: "c_min_2", category: "mining", order: 2, name: "深井网络", desc: "仓库上限 +50%" },
|
||||
{ id: "c_min_3", category: "mining", order: 3, name: "谐振熔炉", desc: "主动脉冲威力 +50%" },
|
||||
// 玫 · 光谱矩阵
|
||||
{ id: "c_dec_1", category: "decoding", order: 1, name: "光谱记忆", desc: "洞见倍率 +15%" },
|
||||
{ id: "c_dec_2", category: "decoding", order: 2, name: "步幅延展", desc: "解码步数上限 +1" },
|
||||
{ id: "c_dec_3", category: "decoding", order: 3, name: "自动校准", desc: "自动解码周期 -3s" },
|
||||
// 琥 · 远征星图
|
||||
{ id: "c_exp_1", category: "expedition", order: 1, name: "维生护盾", desc: "探险生命 +25%" },
|
||||
{ id: "c_exp_2", category: "expedition", order: 2, name: "信标矩阵", desc: "探险力 +20%" },
|
||||
{ id: "c_exp_3", category: "expedition", order: 3, name: "能量共振", desc: "能量上限 +1" },
|
||||
// 紫 · 接触回响
|
||||
{ id: "c_con_1", category: "contact", order: 1, name: "接触共鸣", desc: "接触进度率 +20%" },
|
||||
{ id: "c_con_2", category: "contact", order: 2, name: "飞升加速", desc: "飞升所需接触 -10" },
|
||||
{ id: "c_con_3", category: "contact", order: 3, name: "蓝图回响", desc: "每个蓝图额外 +2% 全属性" },
|
||||
// 灰 · 虚空市场
|
||||
{ id: "c_eco_1", category: "economy", order: 1, name: "离线缓存", desc: "离线效率 +15%" },
|
||||
{ id: "c_eco_2", category: "economy", order: 2, name: "晶体富集", desc: "T2/T3 晶体出现率 +8%" },
|
||||
{ id: "c_eco_3", category: "economy", order: 3, name: "星潮引导", desc: "星潮间隙 -10s" },
|
||||
// 金 · 宇宙回响
|
||||
{ id: "c_cos_1", category: "cosmic", order: 1, name: "飞升礼包", desc: "每次飞升后获得 +30 晶体 / +5 洞见" },
|
||||
{ id: "c_cos_2", category: "cosmic", order: 2, name: "二周目经验", desc: "解码奖励 +10%" },
|
||||
{ id: "c_cos_3", category: "cosmic", order: 3, name: "全息共振", desc: "所有产能与脉冲 +8%" },
|
||||
];
|
||||
|
||||
/** 由 ID 取天赋 */
|
||||
export function getPerk(id: string): ConstellationPerk | undefined {
|
||||
return CONSTELLATION_PERKS.find((p) => p.id === id);
|
||||
}
|
||||
|
||||
/** 聚合玩家已解锁天赋的总修饰器(供 recomputeStats / 具体动作使用) */
|
||||
export interface ConstellationModifiers {
|
||||
crystalsPerSecMult: number;
|
||||
crystalCapMult: number;
|
||||
pulsePowerMult: number;
|
||||
insightMultAdd: number;
|
||||
decodeStepsBonus: number;
|
||||
autoDecodeIntervalDeltaSec: number;
|
||||
expeditionHpMult: number;
|
||||
expeditionPowerMult: number;
|
||||
energyMaxBonus: number;
|
||||
contactRateMult: number;
|
||||
prestigeContactMinDelta: number;
|
||||
perBlueprintAllStatsPct: number;
|
||||
offlineEffBonus: number;
|
||||
t2t3BonusRate: number;
|
||||
tideGapDeltaSec: number;
|
||||
prestigeStartCrystals: number;
|
||||
prestigeStartInsights: number;
|
||||
decodeRewardMult: number;
|
||||
allProductionMult: number;
|
||||
}
|
||||
|
||||
export function constellationBonuses(perks: string[]): ConstellationModifiers {
|
||||
const owned = new Set(perks);
|
||||
const m: ConstellationModifiers = {
|
||||
crystalsPerSecMult: 1,
|
||||
crystalCapMult: 1,
|
||||
pulsePowerMult: 1,
|
||||
insightMultAdd: 0,
|
||||
decodeStepsBonus: 0,
|
||||
autoDecodeIntervalDeltaSec: 0,
|
||||
expeditionHpMult: 1,
|
||||
expeditionPowerMult: 1,
|
||||
energyMaxBonus: 0,
|
||||
contactRateMult: 1,
|
||||
prestigeContactMinDelta: 0,
|
||||
perBlueprintAllStatsPct: 0,
|
||||
offlineEffBonus: 0,
|
||||
t2t3BonusRate: 0,
|
||||
tideGapDeltaSec: 0,
|
||||
prestigeStartCrystals: 0,
|
||||
prestigeStartInsights: 0,
|
||||
decodeRewardMult: 1,
|
||||
allProductionMult: 1,
|
||||
};
|
||||
if (owned.has("c_min_1")) m.crystalsPerSecMult += 0.2;
|
||||
if (owned.has("c_min_2")) m.crystalCapMult += 0.5;
|
||||
if (owned.has("c_min_3")) m.pulsePowerMult += 0.5;
|
||||
if (owned.has("c_dec_1")) m.insightMultAdd += 0.15;
|
||||
if (owned.has("c_dec_2")) m.decodeStepsBonus += 1;
|
||||
if (owned.has("c_dec_3")) m.autoDecodeIntervalDeltaSec -= 3;
|
||||
if (owned.has("c_exp_1")) m.expeditionHpMult += 0.25;
|
||||
if (owned.has("c_exp_2")) m.expeditionPowerMult += 0.2;
|
||||
if (owned.has("c_exp_3")) m.energyMaxBonus += 1;
|
||||
if (owned.has("c_con_1")) m.contactRateMult += 0.2;
|
||||
if (owned.has("c_con_2")) m.prestigeContactMinDelta -= 10;
|
||||
if (owned.has("c_con_3")) m.perBlueprintAllStatsPct += 2;
|
||||
if (owned.has("c_eco_1")) m.offlineEffBonus += 0.15;
|
||||
if (owned.has("c_eco_2")) m.t2t3BonusRate += 0.08;
|
||||
if (owned.has("c_eco_3")) m.tideGapDeltaSec -= 10;
|
||||
if (owned.has("c_cos_1")) {
|
||||
m.prestigeStartCrystals += 30;
|
||||
m.prestigeStartInsights += 5;
|
||||
}
|
||||
if (owned.has("c_cos_2")) m.decodeRewardMult += 0.1;
|
||||
if (owned.has("c_cos_3")) m.allProductionMult += 0.08;
|
||||
return m;
|
||||
}
|
||||
|
||||
/** 生成 3 个可选天赋(从未拥有的中随机抽取,保证类别多样性) */
|
||||
export function rollPerkChoices(
|
||||
owned: string[],
|
||||
rng: () => number = Math.random
|
||||
): string[] {
|
||||
const ownedSet = new Set(owned);
|
||||
const pool = CONSTELLATION_PERKS.filter((p) => !ownedSet.has(p.id));
|
||||
if (pool.length === 0) return [];
|
||||
// 洗牌
|
||||
const shuffled = [...pool].sort(() => rng() - 0.5);
|
||||
// 取前 3 个,但尽量保证不同类别
|
||||
const picked: ConstellationPerk[] = [];
|
||||
const usedCats = new Set<ConstellationCategory>();
|
||||
// 第一轮:每类最多 1 个
|
||||
for (const p of shuffled) {
|
||||
if (picked.length >= 3) break;
|
||||
if (!usedCats.has(p.category)) {
|
||||
picked.push(p);
|
||||
usedCats.add(p.category);
|
||||
}
|
||||
}
|
||||
// 第二轮:补齐
|
||||
for (const p of shuffled) {
|
||||
if (picked.length >= 3) break;
|
||||
if (!picked.includes(p)) picked.push(p);
|
||||
}
|
||||
return picked.slice(0, 3).map((p) => p.id);
|
||||
}
|
||||
|
||||
/** 给定类别取该类别内已解锁的天赋 order 数 */
|
||||
export function countUnlockedInCategory(perks: string[], cat: ConstellationCategory): number {
|
||||
const owned = new Set(perks);
|
||||
return CONSTELLATION_PERKS.filter((p) => p.category === cat && owned.has(p.id)).length;
|
||||
}
|
||||
|
||||
/** 计算总进度(已解锁 / 18) */
|
||||
export function constellationProgress(perks: string[]): { unlocked: number; total: number } {
|
||||
return { unlocked: perks.length, total: CONSTELLATION_PERKS.length };
|
||||
}
|
||||
|
||||
/** 飞升所需接触进度(受天赋影响) */
|
||||
export function computePrestigeContactMin(state: GameState): number {
|
||||
const c = constellationBonuses(state.constellation ?? []);
|
||||
return Math.max(60, 100 + c.prestigeContactMinDelta);
|
||||
}
|
||||
|
||||
/** 星图布局:6 个星座中心点(极坐标转笛卡尔) */
|
||||
export function getConstellationLayout(centerX: number, centerY: number, radius: number) {
|
||||
const cats: ConstellationCategory[] = ["mining", "decoding", "expedition", "contact", "economy", "cosmic"];
|
||||
return cats.map((cat, i) => {
|
||||
// 六边形布局:每 60° 一个
|
||||
const angle = (Math.PI / 3) * i - Math.PI / 2; // 顶部为第一个
|
||||
return {
|
||||
category: cat,
|
||||
cx: centerX + radius * Math.cos(angle),
|
||||
cy: centerY + radius * Math.sin(angle),
|
||||
meta: CONSTELLATION_CATEGORY_META[cat],
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** 取某类别内 3 个星点的局部坐标(相对星座中心) */
|
||||
export function getStarsInCategory(cat: ConstellationCategory, cx: number, cy: number, scale = 1) {
|
||||
const perks = CONSTELLATION_PERKS.filter((p) => p.category === cat).sort((a, b) => a.order - b.order);
|
||||
return perks.map((p, i) => {
|
||||
// 三角形排布:order 1 顶点,2/3 底部
|
||||
const localY = i === 0 ? -22 * scale : 14 * scale;
|
||||
const localX = i === 0 ? 0 : (i === 1 ? -18 * scale : 18 * scale);
|
||||
return {
|
||||
perk: p,
|
||||
x: cx + localX,
|
||||
y: cy + localY,
|
||||
};
|
||||
});
|
||||
}
|
||||
Executable
+2065
File diff suppressed because it is too large
Load Diff
Executable
+273
@@ -0,0 +1,273 @@
|
||||
// 回响星核 / Echo Nexus — 解码共振谜题逻辑(原创核心玩法)
|
||||
//
|
||||
// 谜题规则「谐振序列 / Harmonic Sequence」:
|
||||
// 1. 一个 rows×cols 的发光节点阵列,每个节点带一种共振色(4 色全息色谱)。
|
||||
// 2. 中央给出「目标谐振序列」target: ResonanceColor[](长度由 tier 决定)。
|
||||
// 3. 玩家依次点击节点,重建该序列:
|
||||
// - 第 1 次点击可任意节点,但该节点颜色须 === target[0]。
|
||||
// - 第 k 次点击的节点颜色须 === target[k-1],且与上一次点击节点**四邻接**(上下左右)。
|
||||
// - 每个节点只能用一次(点击后变暗)。
|
||||
// 4. 步数上限 = stepLimitBase + 解码技术加成;超出则谐振崩塌,可重试(晶体不损耗)。
|
||||
// 5. 成功 → 释放晶体奖励 + 洞见 + 接触进度 + 可能触发叙事碎片。
|
||||
//
|
||||
// 设计意图:把放置游戏的「等待」变成有节奏的空间规划小谜题,兼具策略与爽快感。
|
||||
|
||||
import type {
|
||||
CrystalTier,
|
||||
DecodeNode,
|
||||
DecodePuzzle,
|
||||
ResonanceColor,
|
||||
} from "./types";
|
||||
import { DECODE_CONFIG, RESONANCE_COLORS } from "./config";
|
||||
|
||||
/** 简单可复现随机(mulberry32) */
|
||||
function makeRng(seed: number) {
|
||||
let a = seed >>> 0;
|
||||
return () => {
|
||||
a |= 0;
|
||||
a = (a + 0x6d2b79f5) | 0;
|
||||
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
||||
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成一个**保证有解**的解码谜题。
|
||||
*
|
||||
* 算法(路径构造法):
|
||||
* 1. 先随机生成目标序列 target。
|
||||
* 2. 在网格上**主动构造一条合法路径**:随机起点,每步走向一个未使用的四邻接节点,
|
||||
* 长度 = target.length。构造成功后,把路径上第 i 个节点颜色**强制设为 target[i]**。
|
||||
* 3. 其余非路径节点随机填色(偏向目标色,提升视觉丰富度与多解性)。
|
||||
*
|
||||
* 这样至少存在一条解(即构造的路径),玩家不会遇到「怎么都过不了」的死局。
|
||||
* 同时由于其余节点随机,玩家可能发现别的解路径,保留探索乐趣。
|
||||
*/
|
||||
export function generatePuzzle(
|
||||
tier: CrystalTier,
|
||||
seed?: number,
|
||||
targetLenBonus: number = 0
|
||||
): DecodePuzzle {
|
||||
const cfg = DECODE_CONFIG[tier];
|
||||
const s = seed ?? Math.floor(Math.random() * 1e9);
|
||||
const rng = makeRng(s);
|
||||
|
||||
// v0.8.2 涌动星潮:目标序列额外长度(更长谜题 = 更耗时),步数上限同步增加
|
||||
const targetLen = cfg.targetLen + targetLenBonus;
|
||||
const stepLimitBase = cfg.stepLimitBase + targetLenBonus;
|
||||
const rows = cfg.rows;
|
||||
const cols = cfg.cols;
|
||||
const total = rows * cols;
|
||||
|
||||
// 目标序列:从 4 色中随机选 targetLen 个(允许重复,但保证至少 2 种色以增加策略)
|
||||
const target: ResonanceColor[] = [];
|
||||
for (let i = 0; i < targetLen; i++) {
|
||||
target.push(RESONANCE_COLORS[Math.floor(rng() * RESONANCE_COLORS.length)]);
|
||||
}
|
||||
if (new Set(target).size < 2) {
|
||||
target[target.length - 1] =
|
||||
RESONANCE_COLORS[(RESONANCE_COLORS.indexOf(target[0]) + 1) % RESONANCE_COLORS.length];
|
||||
}
|
||||
|
||||
// 邻居计算
|
||||
const neighborsOf = (id: number): number[] => {
|
||||
const r = Math.floor(id / cols);
|
||||
const c = id % cols;
|
||||
const ns: number[] = [];
|
||||
if (r > 0) ns.push((r - 1) * cols + c);
|
||||
if (r < rows - 1) ns.push((r + 1) * cols + c);
|
||||
if (c > 0) ns.push(r * cols + (c - 1));
|
||||
if (c < cols - 1) ns.push(r * cols + (c + 1));
|
||||
return ns;
|
||||
};
|
||||
|
||||
// 构造一条保证可解的路径(多次尝试)
|
||||
let pathIds: number[] | null = null;
|
||||
for (let attempt = 0; attempt < 300 && !pathIds; attempt++) {
|
||||
const used = new Set<number>();
|
||||
const path: number[] = [];
|
||||
const start = Math.floor(rng() * total);
|
||||
used.add(start);
|
||||
path.push(start);
|
||||
let cur = start;
|
||||
let ok = true;
|
||||
for (let i = 1; i < target.length; i++) {
|
||||
const ns = neighborsOf(cur).filter((n) => !used.has(n));
|
||||
if (ns.length === 0) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
cur = ns[Math.floor(rng() * ns.length)];
|
||||
used.add(cur);
|
||||
path.push(cur);
|
||||
}
|
||||
if (ok) pathIds = path;
|
||||
}
|
||||
// 极端兜底(理论不会触发):线性路径
|
||||
if (!pathIds) {
|
||||
pathIds = Array.from({ length: target.length }, (_, i) => i);
|
||||
}
|
||||
|
||||
// 路径节点颜色映射
|
||||
const pathColor = new Map<number, ResonanceColor>();
|
||||
pathIds.forEach((id, i) => pathColor.set(id, target[i]));
|
||||
|
||||
// 生成网格
|
||||
const grid: DecodeNode[] = [];
|
||||
for (let r = 0; r < rows; r++) {
|
||||
for (let c = 0; c < cols; c++) {
|
||||
const id = r * cols + c;
|
||||
let color: ResonanceColor;
|
||||
if (pathColor.has(id)) {
|
||||
color = pathColor.get(id)!;
|
||||
} else {
|
||||
// 非路径节点:60% 偏向目标色(提升多解性),40% 随机全色
|
||||
if (rng() < 0.6) {
|
||||
color = target[Math.floor(rng() * target.length)];
|
||||
} else {
|
||||
color = RESONANCE_COLORS[Math.floor(rng() * RESONANCE_COLORS.length)];
|
||||
}
|
||||
}
|
||||
grid.push({ id, row: r, col: c, color, used: false });
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
tier,
|
||||
grid,
|
||||
rows,
|
||||
cols,
|
||||
target,
|
||||
path: [],
|
||||
stepLimit: stepLimitBase,
|
||||
seed: s,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 精确判断当前局面是否仍可解。
|
||||
* 从当前路径末端出发,DFS 搜索是否存在一条按 target 剩余顺序、四邻接、不重复的完成路径。
|
||||
* 用于玩家点击后检测「此路不通」,提示撤销。
|
||||
*/
|
||||
export function isSolvable(puzzle: DecodePuzzle): boolean {
|
||||
const remaining = puzzle.target.slice(puzzle.path.length);
|
||||
if (remaining.length === 0) return true;
|
||||
|
||||
const used = new Set(puzzle.path);
|
||||
const neighborsOf = (id: number): number[] => {
|
||||
const node = puzzle.grid.find((n) => n.id === id);
|
||||
if (!node) return [];
|
||||
const ns: number[] = [];
|
||||
if (node.row > 0) ns.push((node.row - 1) * puzzle.cols + node.col);
|
||||
if (node.row < puzzle.rows - 1) ns.push((node.row + 1) * puzzle.cols + node.col);
|
||||
if (node.col > 0) ns.push(node.row * puzzle.cols + (node.col - 1));
|
||||
if (node.col < puzzle.cols - 1) ns.push(node.row * puzzle.cols + (node.col + 1));
|
||||
return ns;
|
||||
};
|
||||
|
||||
// 若尚未落子,任意颜色匹配 remaining[0] 的未使用节点都可作为起点
|
||||
const starts: number[] =
|
||||
puzzle.path.length === 0
|
||||
? puzzle.grid.filter((n) => !used.has(n.id) && n.color === remaining[0]).map((n) => n.id)
|
||||
: [puzzle.path[puzzle.path.length - 1]];
|
||||
|
||||
const dfs = (curId: number, idx: number): boolean => {
|
||||
if (idx >= remaining.length) return true;
|
||||
const nextColor = remaining[idx];
|
||||
for (const nid of neighborsOf(curId)) {
|
||||
if (used.has(nid)) continue;
|
||||
const n = puzzle.grid.find((x) => x.id === nid);
|
||||
if (!n || n.color !== nextColor) continue;
|
||||
// 起点情况:第一步 idx=0 时,curId 本身要匹配 nextColor
|
||||
if (idx === 0 && puzzle.path.length === 0) {
|
||||
const cur = puzzle.grid.find((x) => x.id === curId);
|
||||
if (!cur || cur.color !== nextColor) continue;
|
||||
}
|
||||
used.add(nid);
|
||||
if (dfs(nid, idx + 1)) return true;
|
||||
used.delete(nid);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
for (const st of starts) {
|
||||
if (puzzle.path.length === 0) {
|
||||
// 起点自身需匹配 remaining[0]
|
||||
const cur = puzzle.grid.find((n) => n.id === st);
|
||||
if (!cur || cur.color !== remaining[0]) continue;
|
||||
used.add(st);
|
||||
if (dfs(st, 1)) return true;
|
||||
used.delete(st);
|
||||
} else {
|
||||
if (dfs(st, 0)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 两节点是否四邻接 */
|
||||
export function isAdjacent(a: DecodeNode, b: DecodeNode): boolean {
|
||||
return Math.abs(a.row - b.row) + Math.abs(a.col - b.col) === 1;
|
||||
}
|
||||
|
||||
/** 尝试点击节点。返回 { ok, finished, failReason } */
|
||||
export function tryClickNode(
|
||||
puzzle: DecodePuzzle,
|
||||
nodeId: number
|
||||
): { ok: boolean; finished: boolean; failReason?: string } {
|
||||
const node = puzzle.grid.find((n) => n.id === nodeId);
|
||||
if (!node) return { ok: false, finished: false, failReason: "无效节点" };
|
||||
if (node.used) return { ok: false, finished: false, failReason: "节点已使用" };
|
||||
|
||||
const stepIdx = puzzle.path.length;
|
||||
// 颜色须匹配目标序列当前位置
|
||||
if (node.color !== puzzle.target[stepIdx]) {
|
||||
return { ok: false, finished: false, failReason: "谐振不匹配" };
|
||||
}
|
||||
// 非首步须邻接
|
||||
if (stepIdx > 0) {
|
||||
const prev = puzzle.grid.find((n) => n.id === puzzle.path[stepIdx - 1])!;
|
||||
if (!isAdjacent(prev, node)) {
|
||||
return { ok: false, finished: false, failReason: "节点不相邻" };
|
||||
}
|
||||
}
|
||||
// 步数上限
|
||||
if (stepIdx >= puzzle.stepLimit) {
|
||||
return { ok: false, finished: false, failReason: "步数耗尽" };
|
||||
}
|
||||
|
||||
node.used = true;
|
||||
puzzle.path.push(nodeId);
|
||||
|
||||
const finished = puzzle.path.length >= puzzle.target.length;
|
||||
return { ok: true, finished };
|
||||
}
|
||||
|
||||
/** 是否已无解 — 复用精确的 isSolvable 判定 */
|
||||
export function isStuck(puzzle: DecodePuzzle): boolean {
|
||||
if (puzzle.path.length >= puzzle.target.length) return false;
|
||||
if (puzzle.path.length >= puzzle.stepLimit) return true;
|
||||
return !isSolvable(puzzle);
|
||||
}
|
||||
|
||||
/**
|
||||
* 假设从某节点作为第一步落子,局面是否仍可解。
|
||||
* 用于在选起点阶段高亮「可行起点」,避免玩家选到死起点。
|
||||
*/
|
||||
export function canStartFrom(puzzle: DecodePuzzle, nodeId: number): boolean {
|
||||
if (puzzle.path.length !== 0) return false;
|
||||
const node = puzzle.grid.find((n) => n.id === nodeId);
|
||||
if (!node || node.used) return false;
|
||||
if (node.color !== puzzle.target[0]) return false;
|
||||
const cp: DecodePuzzle = JSON.parse(JSON.stringify(puzzle));
|
||||
const n = cp.grid.find((x) => x.id === nodeId)!;
|
||||
n.used = true;
|
||||
cp.path.push(nodeId);
|
||||
return isSolvable(cp);
|
||||
}
|
||||
|
||||
/** 重置谜题(保留同一晶体,重新挑战) */
|
||||
export function resetPuzzle(puzzle: DecodePuzzle): DecodePuzzle {
|
||||
return generatePuzzle(puzzle.tier, puzzle.seed + 1);
|
||||
}
|
||||
Executable
+298
@@ -0,0 +1,298 @@
|
||||
// 回响星核 / Echo Nexus — 核心引擎:产能聚合、技术效果、飞升
|
||||
import type { GameState, PrestigeBonus, ResonanceColor, CrystalTier } from "./types";
|
||||
import {
|
||||
INITIAL_STATE,
|
||||
TECH_TREE,
|
||||
PRESTIGE,
|
||||
CRYSTAL_VALUE,
|
||||
CONTACT,
|
||||
} from "./config";
|
||||
import { achievementBonuses } from "./achievements";
|
||||
import { getTideModifiers, type StarTide } from "./starTide";
|
||||
import { constellationBonuses, rollPerkChoices } from "./constellation";
|
||||
import {
|
||||
buildChronicleEntry,
|
||||
createRunStartSnapshot,
|
||||
} from "./chronicle";
|
||||
import {
|
||||
getAllBonuses,
|
||||
migrateAttributes,
|
||||
computePrestigeAttrPoints,
|
||||
createInitialAttributeProgress,
|
||||
} from "./attributes";
|
||||
|
||||
/** 由技术树 + 飞升蓝图 + 成就 + 星图天赋 + 星潮聚合计算产能字段 */
|
||||
export function recomputeStats(state: Partial<GameState>): {
|
||||
crystalsPerSec: number;
|
||||
crystalCap: number;
|
||||
pulsePower: number;
|
||||
offlineEff: number;
|
||||
insightMult: number;
|
||||
contactRateMult: number;
|
||||
autoDecode: boolean;
|
||||
decodeStepsBonus: number;
|
||||
} {
|
||||
const tech = state.tech ?? {};
|
||||
const bp = state.blueprints?.length ?? 0;
|
||||
const ach = achievementBonuses(state.achievements ?? {});
|
||||
const tideMod = getTideModifiers((state.activeTide as StarTide | null) ?? null);
|
||||
const cm = constellationBonuses(state.constellation ?? []);
|
||||
|
||||
let crystalsPerSec = INITIAL_STATE.crystalsPerSec;
|
||||
let crystalCap = INITIAL_STATE.crystalCap;
|
||||
let pulsePower = INITIAL_STATE.pulsePower;
|
||||
let offlineEff = INITIAL_STATE.offlineEff;
|
||||
let insightMult = INITIAL_STATE.insightMult;
|
||||
let contactRateMult = 1;
|
||||
let autoDecode = false;
|
||||
let decodeStepsBonus = 0;
|
||||
|
||||
for (const node of TECH_TREE) {
|
||||
const lvl = tech[node.id] ?? 0;
|
||||
if (!lvl) continue;
|
||||
const eff = node.effect;
|
||||
switch (eff.kind) {
|
||||
case "crystalsPerSec":
|
||||
crystalsPerSec += eff.value * lvl;
|
||||
break;
|
||||
case "crystalCap":
|
||||
crystalCap += eff.value * lvl;
|
||||
break;
|
||||
case "pulsePower":
|
||||
pulsePower += eff.value * lvl;
|
||||
break;
|
||||
case "offlineEff":
|
||||
offlineEff = Math.min(1, offlineEff + eff.value * lvl);
|
||||
break;
|
||||
case "insightMult":
|
||||
insightMult += eff.value * lvl;
|
||||
break;
|
||||
case "contactRate":
|
||||
contactRateMult += eff.value * lvl;
|
||||
break;
|
||||
case "decodeSteps":
|
||||
decodeStepsBonus += eff.value * lvl;
|
||||
break;
|
||||
case "autoDecode":
|
||||
autoDecode = lvl > 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// v0.9 工单 #2:多效果节点的次效果(desc 中描述但 effect.kind 只能承载一个)
|
||||
// 采矿分支 desc 承诺的仓库上限加成(同时补齐 min_2/min_3 旧 desc 文案)
|
||||
if (tech.min_2) crystalCap += 100;
|
||||
if (tech.min_3) crystalCap += 300;
|
||||
if (tech.min_4) crystalCap += 800;
|
||||
if (tech.min_5) crystalCap += 2000;
|
||||
// 叙事分支 nar_5 文明回响:接触进度转化率 +80%(与 insightMult +150% 并存)
|
||||
if (tech.nar_5) contactRateMult += 0.8;
|
||||
|
||||
// 飞升蓝图加成(+ 星图「蓝图回响」额外加成)
|
||||
const bpAllPct = cm.perBlueprintAllStatsPct / 100;
|
||||
crystalsPerSec *= 1 + (bp * (PRESTIGE.perBlueprint.crystalsPerSecMult + bpAllPct));
|
||||
insightMult *= 1 + (bp * (PRESTIGE.perBlueprint.insightMult + bpAllPct));
|
||||
contactRateMult *= 1 + (bp * (PRESTIGE.perBlueprint.contactRateMult + bpAllPct));
|
||||
|
||||
// 成就永久加成(跨周目)
|
||||
crystalsPerSec *= 1 + ach.crystalsPerSecPct / 100;
|
||||
insightMult *= 1 + ach.insightPct / 100;
|
||||
|
||||
// 星图天赋永久加成(跨周目)
|
||||
crystalsPerSec *= cm.crystalsPerSecMult * cm.allProductionMult;
|
||||
crystalCap *= cm.crystalCapMult;
|
||||
pulsePower *= cm.pulsePowerMult * cm.allProductionMult;
|
||||
offlineEff = Math.min(1, offlineEff + cm.offlineEffBonus);
|
||||
insightMult += cm.insightMultAdd;
|
||||
contactRateMult *= cm.contactRateMult;
|
||||
decodeStepsBonus += cm.decodeStepsBonus;
|
||||
|
||||
// 星潮瞬时修饰(contactRateMult 与 insightMult 进缓存;产能/脉冲/探险在用点处即时乘)
|
||||
insightMult += tideMod.insightMultAdd;
|
||||
contactRateMult *= tideMod.contactRateMult;
|
||||
|
||||
// 角色属性加成(v0.7 P1 — 与现有所有加成叠加)
|
||||
const am = getAllBonuses(state.attributes ?? {});
|
||||
crystalsPerSec *= am.crystalsPerSecMult;
|
||||
insightMult += am.insightMultAdd;
|
||||
contactRateMult *= am.contactRateMult;
|
||||
decodeStepsBonus += am.decodeStepsBonus;
|
||||
|
||||
return {
|
||||
crystalsPerSec,
|
||||
crystalCap,
|
||||
pulsePower,
|
||||
offlineEff,
|
||||
insightMult,
|
||||
contactRateMult,
|
||||
autoDecode,
|
||||
decodeStepsBonus,
|
||||
};
|
||||
}
|
||||
|
||||
/** 计算飞升加成概览(展示用) */
|
||||
export function computePrestigeBonus(state: GameState): PrestigeBonus {
|
||||
const bp = state.blueprints.length;
|
||||
return {
|
||||
crystalsPerSecMult: bp * PRESTIGE.perBlueprint.crystalsPerSecMult,
|
||||
insightMult: bp * PRESTIGE.perBlueprint.insightMult,
|
||||
contactRateMult: bp * PRESTIGE.perBlueprint.contactRateMult,
|
||||
};
|
||||
}
|
||||
|
||||
/** 本次飞升可获得的蓝图数 */
|
||||
export function computeNewBlueprints(state: GameState): number {
|
||||
const earned = Math.floor(state.totalDecoded / PRESTIGE.blueprintsPerDecode);
|
||||
return Math.max(0, Math.min(PRESTIGE.maxBlueprints, earned) - state.blueprints.length);
|
||||
}
|
||||
|
||||
/** 执行飞升:重置数值,保留蓝图/图谱/成就/星图天赋,并触发天赋选择 */
|
||||
export function performPrestige(state: GameState): GameState {
|
||||
const newBp = computeNewBlueprints(state);
|
||||
const blueprints = [
|
||||
...state.blueprints,
|
||||
...Array.from({ length: newBp }, (_, i) => `bp_${Date.now()}_${i}`),
|
||||
].slice(0, PRESTIGE.maxBlueprints);
|
||||
|
||||
// 星图天赋:飞升后获得一次 3 选 1 的机会
|
||||
const choices = rollPerkChoices(state.constellation ?? []);
|
||||
// 星图「飞升礼包」天赋的初始资源补偿
|
||||
const cm = constellationBonuses(state.constellation ?? []);
|
||||
|
||||
// === 编年史快照:在重置前构建本周目条目,perksThisAscension 暂为空(用户选择后回填) ===
|
||||
const chronicleEntry = buildChronicleEntry(state, []);
|
||||
// v0.8.2: 编年史上限 50→200(工单 #8),UI 支持分页浏览
|
||||
const newChronicle = [...(state.chronicle || []), chronicleEntry].slice(-200);
|
||||
const freshRunStart = createRunStartSnapshot(state);
|
||||
|
||||
// v0.7 角色属性:保留 attributes 数值(跨周目永久),清空当前周目经验进度,
|
||||
// 发放待分配属性点 = 飞升次数 × 2 + 1(用飞升前的次数计算)
|
||||
const migrated = migrateAttributes(state);
|
||||
const attributes = migrated.attributes; // 保留数值
|
||||
const attributeProgress = createInitialAttributeProgress(); // 清空经验
|
||||
const earnedAttrPoints = computePrestigeAttrPoints(state.ascensions ?? 0);
|
||||
const pendingAttrPoints = migrated.pendingAttrPoints + earnedAttrPoints;
|
||||
|
||||
// 保留:fragments, totalDecoded(累计), ascensions+1, blueprints, achievements, constellation, theme/sound, expeditionLog
|
||||
// chronicle(新增), bossKills(累计), starTidesEncountered(累计), runStart(重置为新周目)
|
||||
// attributes(永久保留), pendingAttrPoints(累加)
|
||||
// 重置:资源、技术、产能、pendingCrystals、activePuzzle、activeExpedition、contact、lastTick、energy、星潮、attributeProgress
|
||||
const fresh = createInitialState();
|
||||
const stats = recomputeStats({ tech: {}, blueprints, achievements: state.achievements, constellation: state.constellation, attributes });
|
||||
return {
|
||||
...fresh,
|
||||
fragments: state.fragments,
|
||||
totalDecoded: state.totalDecoded,
|
||||
ascensions: state.ascensions + 1,
|
||||
blueprints,
|
||||
achievements: state.achievements,
|
||||
constellation: state.constellation,
|
||||
pendingPerkChoices: choices.length > 0 ? choices : null,
|
||||
// 飞升礼包补偿
|
||||
crystals: cm.prestigeStartCrystals,
|
||||
insights: cm.prestigeStartInsights,
|
||||
theme: state.theme,
|
||||
soundOn: state.soundOn,
|
||||
createdAt: state.createdAt,
|
||||
lastTick: Date.now(),
|
||||
lastEnergyTick: Date.now(),
|
||||
expeditionLog: state.expeditionLog,
|
||||
totalExpeditions: state.totalExpeditions,
|
||||
bossKills: state.bossKills, // 累计保留
|
||||
starTidesEncountered: state.starTidesEncountered, // 累计保留
|
||||
// 编年史:追加新条目,重置 runStart 为新周目
|
||||
chronicle: newChronicle,
|
||||
runStart: freshRunStart,
|
||||
// 星潮:飞升后清空,lastTideEnd 设为现在,使首次星潮在 firstDelay 后触发
|
||||
activeTide: null,
|
||||
lastTideEnd: Date.now(),
|
||||
// v0.7 角色属性
|
||||
attributes,
|
||||
attributeProgress,
|
||||
pendingAttrPoints,
|
||||
...stats,
|
||||
};
|
||||
}
|
||||
|
||||
/** 创建初始状态 */
|
||||
export function createInitialState(): GameState {
|
||||
return {
|
||||
...INITIAL_STATE,
|
||||
tech: {},
|
||||
fragments: {},
|
||||
achievements: {},
|
||||
activeTide: null,
|
||||
lastTideEnd: Date.now(),
|
||||
pendingCrystals: [],
|
||||
activePuzzle: null,
|
||||
activeExpedition: null,
|
||||
expeditionLog: [],
|
||||
lastEnergyTick: Date.now(),
|
||||
createdAt: Date.now(),
|
||||
lastTick: Date.now(),
|
||||
// v0.7 角色属性:每次创建都生成全新对象,避免引用共享
|
||||
attributes: {
|
||||
exploration: 0,
|
||||
wisdom: 0,
|
||||
courage: 0,
|
||||
inspiration: 0,
|
||||
},
|
||||
attributeProgress: {
|
||||
exploration: { exp: 0, level: 0 },
|
||||
wisdom: { exp: 0, level: 0 },
|
||||
courage: { exp: 0, level: 0 },
|
||||
inspiration: { exp: 0, level: 0 },
|
||||
},
|
||||
pendingAttrPoints: 0,
|
||||
} as GameState;
|
||||
}
|
||||
|
||||
/** 计算解码奖励 */
|
||||
export function decodeRewards(
|
||||
tier: CrystalTier,
|
||||
insightMult: number,
|
||||
contactRateMult: number
|
||||
): { crystals: number; insights: number; contact: number } {
|
||||
const base = CRYSTAL_VALUE[tier];
|
||||
return {
|
||||
crystals: base.crystals,
|
||||
insights: Math.ceil(base.insights * insightMult),
|
||||
contact: +(CONTACT.basePerDecode * tier * contactRateMult).toFixed(2),
|
||||
};
|
||||
}
|
||||
|
||||
/** 离线收益计算 */
|
||||
export function computeOfflineGain(
|
||||
state: GameState,
|
||||
now: number
|
||||
): { gain: number; seconds: number; capped: boolean } {
|
||||
const elapsed = Math.max(0, (now - state.lastTick) / 1000);
|
||||
const cap = 8 * 3600; // 8h
|
||||
const seconds = Math.min(elapsed, cap);
|
||||
const gain = state.crystalsPerSec * seconds * state.offlineEff;
|
||||
return { gain, seconds, capped: elapsed > cap };
|
||||
}
|
||||
|
||||
/** 生成一颗晶体(按 tier 权重) */
|
||||
export function rollCrystalTier(rng: () => number = Math.random): CrystalTier {
|
||||
const r = rng();
|
||||
if (r < 0.7) return 1;
|
||||
if (r < 0.95) return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
/** 生成一颗晶体(带 T2/T3 概率补偿,受星图「晶体富集」影响) */
|
||||
export function rollCrystalTierWithBonus(t2t3Bonus: number, rng: () => number = Math.random): CrystalTier {
|
||||
if (t2t3Bonus <= 0) return rollCrystalTier(rng);
|
||||
const r = rng();
|
||||
// 基础:T1=0.7, T2=0.25, T3=0.05
|
||||
// 补偿:从 T1 中按 bonus 比例挪到 T2/T3
|
||||
const shift = Math.min(0.5, t2t3Bonus); // 上限 50%
|
||||
const t1 = 0.7 - 0.7 * shift;
|
||||
const t2 = 0.25 + 0.25 * shift * 0.7;
|
||||
if (r < t1) return 1;
|
||||
if (r < t1 + t2) return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
export type { ResonanceColor };
|
||||
Executable
+410
@@ -0,0 +1,410 @@
|
||||
// 回响星核 / Echo Nexus — 遗迹探险肉鸽系统 (Expedition)
|
||||
//
|
||||
// 玩家消耗能量进入程序化生成的遗迹节点路径,沿路触发事件,
|
||||
// 到达终点 boss 获取大奖。失败保留已获奖励但探险结束。
|
||||
import type {
|
||||
Expedition,
|
||||
ExpeditionNode,
|
||||
ExpeditionNodeType,
|
||||
ExpeditionResult,
|
||||
GameState,
|
||||
} from "./types";
|
||||
import { constellationBonuses } from "./constellation";
|
||||
|
||||
/** 简单可复现随机(mulberry32) */
|
||||
function makeRng(seed: number) {
|
||||
let a = seed >>> 0;
|
||||
return () => {
|
||||
a |= 0;
|
||||
a = (a + 0x6d2b79f5) | 0;
|
||||
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
||||
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
/** 探险配置 */
|
||||
export const EXPEDITION_CONFIG = {
|
||||
/** 进入探险消耗能量 */
|
||||
energyCost: 1,
|
||||
/** 路径节点数范围 */
|
||||
minNodes: 5,
|
||||
maxNodes: 7,
|
||||
/** boss 固定在最后一个节点 */
|
||||
/** 初始生命 */
|
||||
baseHp: 100,
|
||||
/** 探险力基础 */
|
||||
basePower: 10,
|
||||
/** 战斗:胜率 = clamp(power / (power + difficulty*scale), floor, 0.95)
|
||||
* v0.8.1 平衡:scale 8→4,floor 0.25→0.35,让基础探险力也能有合理胜率 */
|
||||
combatDifficultyScale: 4,
|
||||
combatWinRateFloor: 0.35,
|
||||
/** 能量恢复基础间隔(秒),可被技术/属性缩短
|
||||
* v0.9 工单修复:45→20,解决「探险只能一次」体验问题 */
|
||||
energyRegenSec: 20,
|
||||
/** 能量恢复最短间隔(秒,技术+属性全满时) */
|
||||
energyRegenMinSec: 8,
|
||||
};
|
||||
|
||||
/** 节点类型权重(boss 固定末位,其余按权重随机) */
|
||||
const NODE_WEIGHTS: Record<ExpeditionNodeType, number> = {
|
||||
combat: 0.3,
|
||||
treasure: 0.25,
|
||||
choice: 0.2,
|
||||
puzzle: 0.1,
|
||||
rest: 0.15,
|
||||
boss: 0,
|
||||
};
|
||||
|
||||
/** 节点事件文案池 */
|
||||
const NODE_FLAVOR: Record<
|
||||
ExpeditionNodeType,
|
||||
{ titles: string[]; descs: string[] }
|
||||
> = {
|
||||
combat: {
|
||||
titles: ["守卫残影", "虚空巡游者", "腐化无人机", "以太守门人"],
|
||||
descs: [
|
||||
"一道扭曲的残影拦住去路,它是被遗忘的守卫。",
|
||||
"虚空巡游者在走廊游荡,感知到了你的存在。",
|
||||
"腐化的自治无人机识别为入侵者,启动攻击协议。",
|
||||
"以太守门人挡在门前,唯有将其击溃方可通过。",
|
||||
],
|
||||
},
|
||||
treasure: {
|
||||
titles: ["遗失货舱", "晶体宝库", "遗物储藏室", "谐振宝箱"],
|
||||
descs: [
|
||||
"一扇半开的舱门后,散落着未及带走的晶体。",
|
||||
"宝库的能量护盾早已失效,宝藏唾手可得。",
|
||||
"储藏室里的容器还亮着微光,里面是珍贵的洞见核心。",
|
||||
"一只谐振宝箱静静等候,似乎在等故人归来。",
|
||||
],
|
||||
},
|
||||
choice: {
|
||||
titles: ["分岔甬道", "低语祭坛", "未知装置", "回响之井"],
|
||||
descs: [
|
||||
"甬道在此分岔,两条路都传来不同的低语。",
|
||||
"祭坛上浮动着两团光,你必须选择其一。",
|
||||
"未知装置闪烁着两个按钮,你不知道后果。",
|
||||
"回响之井倒映出两种可能的未来。",
|
||||
],
|
||||
},
|
||||
puzzle: {
|
||||
titles: ["封印之门", "谐振锁", "记忆机关", "维度栅栏"],
|
||||
descs: [
|
||||
"一道封印之门需要正确的谐振才能开启。",
|
||||
"谐振锁闪烁着复杂的图案,解之有大奖。",
|
||||
"记忆机关考验着你的解码技艺。",
|
||||
"维度栅栏以谜题为钥,智者得通行。",
|
||||
],
|
||||
},
|
||||
rest: {
|
||||
titles: ["休憩节点", "能量泉眼", "静默之厅", "回响营地"],
|
||||
descs: [
|
||||
"一处宁静的节点,可在此恢复生命。",
|
||||
"能量泉眼涌出暖流,抚慰你的探险队。",
|
||||
"静默之厅中,时间仿佛静止,伤痛缓缓消散。",
|
||||
"前人留下的营地,尚有补给可用。",
|
||||
],
|
||||
},
|
||||
boss: {
|
||||
titles: ["以太回响体", "维度守护者", "飞升残念", "终焉之核"],
|
||||
descs: [
|
||||
"路径尽头,以太回响体静静伫立——它是这个遗迹意志的化身。",
|
||||
"维度守护者挡在最后,唯有超越它方能触及终焉。",
|
||||
"飞升残念凝聚成形,它是以太族离去前留下的最后一道试炼。",
|
||||
"终焉之核悬浮于大厅中央,接触它即完成本次探险。",
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
/** 随机选一个节点类型(boss 除外) */
|
||||
function rollNodeType(rng: () => number): ExpeditionNodeType {
|
||||
const types = Object.keys(NODE_WEIGHTS) as ExpeditionNodeType[];
|
||||
const total = types.reduce((s, t) => s + NODE_WEIGHTS[t], 0);
|
||||
let r = rng() * total;
|
||||
for (const t of types) {
|
||||
r -= NODE_WEIGHTS[t];
|
||||
if (r <= 0) return t;
|
||||
}
|
||||
return "combat";
|
||||
}
|
||||
|
||||
/** 生成一次探险 */
|
||||
export function generateExpedition(
|
||||
seed: number,
|
||||
power: number,
|
||||
hp: number
|
||||
): Expedition {
|
||||
const rng = makeRng(seed);
|
||||
const nodeCount =
|
||||
EXPEDITION_CONFIG.minNodes +
|
||||
Math.floor(rng() * (EXPEDITION_CONFIG.maxNodes - EXPEDITION_CONFIG.minNodes + 1));
|
||||
|
||||
const nodes: ExpeditionNode[] = [];
|
||||
for (let i = 0; i < nodeCount; i++) {
|
||||
const isBoss = i === nodeCount - 1;
|
||||
const type: ExpeditionNodeType = isBoss ? "boss" : rollNodeType(rng);
|
||||
const flavor = NODE_FLAVOR[type];
|
||||
const fi = Math.floor(rng() * flavor.titles.length);
|
||||
nodes.push({
|
||||
id: i,
|
||||
type,
|
||||
title: flavor.titles[fi],
|
||||
desc: flavor.descs[fi],
|
||||
cleared: false,
|
||||
difficulty: isBoss ? 3 + Math.floor(rng() * 3) : 1 + Math.floor(rng() * 4),
|
||||
position: i,
|
||||
});
|
||||
}
|
||||
// 第一个节点固定为 treasure 或 rest(友好开局)
|
||||
if (nodes[0].type === "combat" || nodes[0].type === "boss") {
|
||||
nodes[0].type = rng() < 0.5 ? "treasure" : "rest";
|
||||
const f = NODE_FLAVOR[nodes[0].type];
|
||||
nodes[0].title = f.titles[0];
|
||||
nodes[0].desc = f.descs[0];
|
||||
nodes[0].difficulty = 1;
|
||||
}
|
||||
|
||||
return {
|
||||
id: `exp_${seed}_${Date.now()}`,
|
||||
nodes,
|
||||
currentNode: 0,
|
||||
finished: false,
|
||||
rewards: { crystals: 0, insights: 0, contact: 0, fragments: [] },
|
||||
power,
|
||||
hp,
|
||||
maxHp: hp,
|
||||
seed,
|
||||
startedAt: Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
/** 计算探险力(由技术树 + 飞升蓝图 + 星图天赋) */
|
||||
export function computeExpeditionPower(state: GameState): number {
|
||||
let power = EXPEDITION_CONFIG.basePower;
|
||||
// 探险分支技术加成(v0.9 扩充:exp_4 +12,exp_5 +25)
|
||||
const exp1 = state.tech?.exp_1 ?? 0;
|
||||
const exp2 = state.tech?.exp_2 ?? 0;
|
||||
const exp3 = state.tech?.exp_3 ?? 0;
|
||||
const exp4 = state.tech?.exp_4 ?? 0;
|
||||
const exp5 = state.tech?.exp_5 ?? 0;
|
||||
power += exp1 * 3 + exp2 * 5 + exp3 * 8 + exp4 * 12 + exp5 * 25;
|
||||
// 飞升蓝图加成
|
||||
power *= 1 + (state.blueprints?.length ?? 0) * 0.08;
|
||||
// 飞升周目加成
|
||||
power *= 1 + (state.ascensions ?? 0) * 0.15;
|
||||
// 星图「信标矩阵」加成
|
||||
const cm = constellationBonuses(state.constellation ?? []);
|
||||
power *= cm.expeditionPowerMult;
|
||||
return Math.round(power);
|
||||
}
|
||||
|
||||
/** 计算探险最大生命 */
|
||||
export function computeExpeditionHp(state: GameState): number {
|
||||
let hp = EXPEDITION_CONFIG.baseHp;
|
||||
hp += (state.tech?.exp_2 ?? 0) * 20;
|
||||
// v0.9 扩充:exp_4 +30,exp_5 +50
|
||||
hp += (state.tech?.exp_4 ?? 0) * 30;
|
||||
hp += (state.tech?.exp_5 ?? 0) * 50;
|
||||
hp += (state.ascensions ?? 0) * 10;
|
||||
// 星图「维生护盾」加成
|
||||
const cm = constellationBonuses(state.constellation ?? []);
|
||||
hp = Math.round(hp * cm.expeditionHpMult);
|
||||
return hp;
|
||||
}
|
||||
|
||||
/** 战斗胜率
|
||||
* v0.8.1 平衡:scale 4 + floor 0.35,让基础探险力 10 对 BOSS(diff 3-5) 有 33-45% 胜率,
|
||||
* 配合技术/属性后可达 55-70%,告别"BOSS 必败"体验 */
|
||||
export function combatWinRate(power: number, difficulty: number): number {
|
||||
const scale = EXPEDITION_CONFIG.combatDifficultyScale;
|
||||
const floor = EXPEDITION_CONFIG.combatWinRateFloor;
|
||||
return Math.max(floor, Math.min(0.95, power / (power + difficulty * scale)));
|
||||
}
|
||||
|
||||
/** 结算当前节点(自动结算,返回结果与日志) */
|
||||
export function resolveNode(
|
||||
expedition: Expedition,
|
||||
rng: () => number = Math.random
|
||||
): ExpeditionResult {
|
||||
const node = expedition.nodes[expedition.currentNode];
|
||||
if (!node) return { log: "无节点", ended: true, endReason: "abort" };
|
||||
if (node.cleared) {
|
||||
return advanceExpedition(expedition);
|
||||
}
|
||||
|
||||
const power = expedition.power;
|
||||
const diff = node.difficulty;
|
||||
|
||||
switch (node.type) {
|
||||
case "combat": {
|
||||
const winRate = combatWinRate(power, diff);
|
||||
const won = rng() < winRate;
|
||||
if (won) {
|
||||
const crystals = 8 + diff * 6 + Math.floor(rng() * 10);
|
||||
const insights = 1 + diff + Math.floor(rng() * 2);
|
||||
node.cleared = true;
|
||||
return {
|
||||
log: `击败「${node.title}」,缴获 ${crystals} 晶体、${insights} 洞见。`,
|
||||
crystals,
|
||||
insights,
|
||||
ended: false,
|
||||
};
|
||||
}
|
||||
const hpLoss = 20 + diff * 10 + Math.floor(rng() * 15);
|
||||
const newHp = expedition.hp - hpLoss;
|
||||
if (newHp <= 0) {
|
||||
node.cleared = true;
|
||||
return {
|
||||
log: `「${node.title}」过于强大,探险队全灭…(生命 -${expedition.hp})`,
|
||||
hpDelta: -expedition.hp,
|
||||
ended: true,
|
||||
endReason: "defeat",
|
||||
};
|
||||
}
|
||||
// 战败但存活,仍可前进(节点算通过但无奖励)
|
||||
node.cleared = true;
|
||||
return {
|
||||
log: `「${node.title}」击退了探险队,损失 ${hpLoss} 生命,狼狈通过。`,
|
||||
hpDelta: -hpLoss,
|
||||
ended: false,
|
||||
};
|
||||
}
|
||||
case "treasure": {
|
||||
const crystals = 10 + diff * 8 + Math.floor(rng() * 15);
|
||||
const insights = 2 + diff + Math.floor(rng() * 3);
|
||||
node.cleared = true;
|
||||
return {
|
||||
log: `在「${node.title}」中发现 ${crystals} 晶体、${insights} 洞见。`,
|
||||
crystals,
|
||||
insights,
|
||||
ended: false,
|
||||
};
|
||||
}
|
||||
case "rest": {
|
||||
const heal = 15 + diff * 8 + Math.floor(rng() * 10);
|
||||
node.cleared = true;
|
||||
return {
|
||||
log: `在「${node.title}」休整,恢复 ${heal} 生命。`,
|
||||
hpDelta: heal,
|
||||
ended: false,
|
||||
};
|
||||
}
|
||||
case "puzzle": {
|
||||
// 简化:探险力越高越可能解出
|
||||
const solveRate = Math.min(0.9, 0.4 + power * 0.01);
|
||||
const solved = rng() < solveRate;
|
||||
if (solved) {
|
||||
const crystals = 20 + diff * 12;
|
||||
const insights = 5 + diff * 3;
|
||||
const contact = 1 + diff * 0.5;
|
||||
node.cleared = true;
|
||||
return {
|
||||
log: `解开「${node.title}」,获得 ${crystals} 晶体、${insights} 洞见、${contact.toFixed(1)} 接触进度。`,
|
||||
crystals,
|
||||
insights,
|
||||
contact,
|
||||
ended: false,
|
||||
};
|
||||
}
|
||||
node.cleared = true;
|
||||
return {
|
||||
log: `「${node.title}」未能解开,但探险队平安通过。`,
|
||||
ended: false,
|
||||
};
|
||||
}
|
||||
case "choice": {
|
||||
// 抉择节点:随机给一个好结果或一个坏结果
|
||||
const good = rng() < 0.55;
|
||||
if (good) {
|
||||
const crystals = 6 + diff * 5 + Math.floor(rng() * 8);
|
||||
node.cleared = true;
|
||||
return {
|
||||
log: `在「${node.title}」做出了明智的选择,获得 ${crystals} 晶体。`,
|
||||
crystals,
|
||||
ended: false,
|
||||
};
|
||||
}
|
||||
const hpLoss = 8 + diff * 5;
|
||||
node.cleared = true;
|
||||
return {
|
||||
log: `在「${node.title}」的选择带来了代价,损失 ${hpLoss} 生命。`,
|
||||
hpDelta: -hpLoss,
|
||||
ended: false,
|
||||
};
|
||||
}
|
||||
case "boss": {
|
||||
// boss:必定战斗,高难度
|
||||
const winRate = combatWinRate(power, diff);
|
||||
const won = rng() < winRate;
|
||||
node.cleared = true;
|
||||
if (won) {
|
||||
const crystals = 60 + diff * 25;
|
||||
const insights = 15 + diff * 6;
|
||||
const contact = 5 + diff * 1.5;
|
||||
// boss 必给一个碎片(如果还有未解锁的)
|
||||
return {
|
||||
log: `✦ 击败「${node.title}」!获得 ${crystals} 晶体、${insights} 洞见、${contact.toFixed(1)} 接触进度。`,
|
||||
crystals,
|
||||
insights,
|
||||
contact,
|
||||
ended: true,
|
||||
endReason: "victory",
|
||||
};
|
||||
}
|
||||
return {
|
||||
log: `「${node.title}」的力量超出想象,探险队全军覆没…`,
|
||||
hpDelta: -expedition.hp,
|
||||
ended: true,
|
||||
endReason: "defeat",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 前进到下一节点 */
|
||||
export function advanceExpedition(expedition: Expedition): ExpeditionResult {
|
||||
if (expedition.currentNode >= expedition.nodes.length - 1) {
|
||||
return { log: "探险已完成", ended: true, endReason: "victory" };
|
||||
}
|
||||
expedition.currentNode++;
|
||||
return { log: `前进至节点 ${expedition.currentNode + 1}`, ended: false };
|
||||
}
|
||||
|
||||
/** 计算实际能量恢复间隔(秒),由技术树 + 角色属性缩短
|
||||
* v0.8.1:exp_2 解锁 -30%,exp_3 解锁 -20%,探索力属性 -最高30%,下限 12s
|
||||
* v0.9 扩充:exp_4 加速 25%(×0.75),exp_5 加速 30%(×0.70),下限 8s */
|
||||
export function computeEnergyRegenInterval(state: GameState): number {
|
||||
const base = EXPEDITION_CONFIG.energyRegenSec;
|
||||
let mult = 1;
|
||||
// 技术:遗迹图谱(exp_2)+ 维度信标(exp_3)+ 虚空航标(exp_4)+ 维度跃迁引擎(exp_5)
|
||||
if (state.tech?.exp_2) mult *= 0.7;
|
||||
if (state.tech?.exp_3) mult *= 0.8;
|
||||
if (state.tech?.exp_4) mult *= 0.75;
|
||||
if (state.tech?.exp_5) mult *= 0.7;
|
||||
// 角色属性:探索力(exploration)每点缩短少量,高探索力最高 -30%
|
||||
const exploration = state.attributes?.exploration ?? 0;
|
||||
const explorationBonus = exploration >= 50
|
||||
? 0.15 + (Math.min(100, exploration) - 50) * 0.003 // 50点15%,100点30%
|
||||
: exploration * 0.003;
|
||||
mult *= 1 - explorationBonus;
|
||||
return Math.max(EXPEDITION_CONFIG.energyRegenMinSec, base * mult);
|
||||
}
|
||||
|
||||
/** 计算能量恢复(基于时间,支持动态间隔) */
|
||||
export function computeEnergyRegen(
|
||||
lastTick: number,
|
||||
now: number,
|
||||
current: number,
|
||||
max: number,
|
||||
intervalSec: number = EXPEDITION_CONFIG.energyRegenSec
|
||||
): { energy: number; lastTick: number } {
|
||||
const interval = intervalSec * 1000;
|
||||
const elapsed = now - lastTick;
|
||||
const gained = Math.floor(elapsed / interval);
|
||||
if (gained <= 0) return { energy: current, lastTick };
|
||||
return {
|
||||
energy: Math.min(max, current + gained),
|
||||
lastTick: lastTick + gained * interval,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// 回响星核 / Echo Nexus — 叙事氛围文本池(v0.9 工单修复)
|
||||
// 工单 Issue #2 反馈"很多东西都没靠着世界观去写,像是为了做游戏而做的一样"
|
||||
// 本模块为各系统交互注入叙事碎片,让世界观渗透到每个角落
|
||||
|
||||
/** 脉冲扫描时随机触发的氛围低语(连击越高出现概率越大) */
|
||||
export const PULSE_WHISPERS: string[] = [
|
||||
"晶核深处传来一阵微弱的震颤…",
|
||||
"以太族的余响在谐振中回荡。",
|
||||
"你听见了一句无法辨认的低语。",
|
||||
"星海的寂静被你的脉冲短暂打破。",
|
||||
"晶体表面的纹路闪烁,像是某种回应。",
|
||||
"回响核心记录着每一次触碰。",
|
||||
"虚空深处,有什么在倾听。",
|
||||
"谐振频率与你的脉冲产生了共鸣。",
|
||||
"这是以太族留下的第一道印记。",
|
||||
"晶体内部的光,比星辰更古老。",
|
||||
"你的脉冲唤醒了一段沉睡的频率。",
|
||||
"维度薄膜因你的触碰而微微颤动。",
|
||||
"采矿不是掠夺,是聆听。",
|
||||
"每一颗晶体,都是一封跨越时间的信。",
|
||||
"以太族信任你,所以留下了这些。",
|
||||
];
|
||||
|
||||
/** 解码成功时的叙事碎片(按解码次数递进解锁更深层的叙事) */
|
||||
export const DECODE_ECHOES: string[] = [
|
||||
"一段记忆在你的解码中苏醒…",
|
||||
"谐振序列被还原,低语化为可读的符文。",
|
||||
"你触碰到了以太族思维的一角。",
|
||||
"解码完成的瞬间,你看见了他们的星海。",
|
||||
"记忆晶体释放出封存了万年的画面。",
|
||||
"这不仅是数据,是一段被编码的经历。",
|
||||
"以太族的语言不是文字,是共振本身。",
|
||||
"你读懂了这句话时,接触便已开始。",
|
||||
"晶体褪去外壳,露出内核中的回响。",
|
||||
"解码,是以太族留给后来者的资格证明。",
|
||||
"你的思维与晶体中的残响短暂重合。",
|
||||
"一段文明的碎片在你手中重组。",
|
||||
];
|
||||
|
||||
/** 技术解锁时的叙事(每分支一段通用叙事) */
|
||||
export const TECH_LORE: Record<string, string> = {
|
||||
mining: "以太族从不掠夺星海,他们与矿脉共振,让晶体自愿献出光芒。",
|
||||
decoding: "谐振法则是以太族的核心遗产——思维可被编码为共振序列。",
|
||||
expedition: "他们留下的遗迹不是废墟,是故意设置的试炼场。",
|
||||
narrative: "记忆校音,是以太族赋予后来者的第一项礼物。",
|
||||
};
|
||||
|
||||
/** 探险节点事件额外的叙事前缀 */
|
||||
export const EXPEDITION_NARRATIVE: Record<string, string> = {
|
||||
combat: "以太族的守卫残影仍在执行万年前的指令。",
|
||||
treasure: "这些宝藏是以太族特意留下的补给。",
|
||||
choice: "分岔甬道是他们对后来者的考验。",
|
||||
puzzle: "谐振锁的答案,藏在以太族的思维模式里。",
|
||||
rest: "这处休憩节点,是以太族留给疲惫旅人的礼物。",
|
||||
boss: "终焉之核是以太族离去前留下的最后一道试炼。",
|
||||
};
|
||||
|
||||
/** 飞升时的叙事 */
|
||||
export const PRESTIGE_ECHOES: string[] = [
|
||||
"你的意识与以太族的残响交汇,维度薄膜被穿透…",
|
||||
"飞升不是结束,是与更高处的他们相会。",
|
||||
"你褪去了这一周目的形态,回响却永存。",
|
||||
"以太族在更高处等你,已等候了万年。",
|
||||
"接触完成。你成为了他们等待的回应。",
|
||||
];
|
||||
|
||||
/** 随机取一条叙事文本 */
|
||||
export function pickWhisper(pool: string[], seed?: number): string {
|
||||
if (pool.length === 0) return "";
|
||||
const idx = seed !== undefined
|
||||
? Math.abs(Math.floor(seed)) % pool.length
|
||||
: Math.floor(Math.random() * pool.length);
|
||||
return pool[idx];
|
||||
}
|
||||
|
||||
/** 按概率返回一条叙事(probability 0-1) */
|
||||
export function maybeWhisper(pool: string[], probability: number): string | null {
|
||||
if (Math.random() < probability) {
|
||||
return pickWhisper(pool);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
// 回响星核 / Echo Nexus — 离线收益报告(v0.5.2)
|
||||
// 模块级存储 + 自定义事件通知 UI,不污染 GameState
|
||||
|
||||
export interface OfflineReport {
|
||||
elapsedSec: number; // 离线秒数(已 cap)
|
||||
rawElapsedSec: number; // 实际离线秒数(未 cap)
|
||||
gain: number; // 获得晶体
|
||||
rate: number; // 离线时产能 /s
|
||||
eff: number; // 离线效率 0-1
|
||||
capped: boolean; // 是否触达 8h 上限
|
||||
crystalsBefore: number; // 补发前晶体
|
||||
crystalsAfter: number; // 补发后晶体
|
||||
crystalCap: number; // 仓库上限
|
||||
}
|
||||
|
||||
let pending: OfflineReport | null = null;
|
||||
|
||||
export function setPendingOfflineReport(r: OfflineReport) {
|
||||
pending = r;
|
||||
if (typeof window !== "undefined") {
|
||||
window.dispatchEvent(new CustomEvent("echo-nexus-offline-report"));
|
||||
}
|
||||
}
|
||||
|
||||
export function getPendingOfflineReport(): OfflineReport | null {
|
||||
return pending;
|
||||
}
|
||||
|
||||
export function consumeOfflineReport(): OfflineReport | null {
|
||||
const r = pending;
|
||||
pending = null;
|
||||
return r;
|
||||
}
|
||||
|
||||
/** 格式化时长为中文 */
|
||||
export function formatDuration(sec: number): string {
|
||||
if (sec < 60) return `${Math.floor(sec)}秒`;
|
||||
const m = Math.floor(sec / 60);
|
||||
if (m < 60) return `${m}分钟`;
|
||||
const h = Math.floor(m / 60);
|
||||
const remM = m % 60;
|
||||
if (h < 24) return remM > 0 ? `${h}小时${remM}分` : `${h}小时`;
|
||||
const d = Math.floor(h / 24);
|
||||
const remH = h % 24;
|
||||
return remH > 0 ? `${d}天${remH}小时` : `${d}天`;
|
||||
}
|
||||
Executable
+296
@@ -0,0 +1,296 @@
|
||||
// 回响星核 / Echo Nexus — 星潮事件系统(周期性全局玩法修饰)
|
||||
//
|
||||
// 深空中偶发的「星潮」会短暂改变物理法则,给放置循环注入动态变化。
|
||||
// 每 ~40s 间隙后触发一次持续 ~75s 的星潮,9 种类型各有正负效果。
|
||||
|
||||
export type TideType =
|
||||
| "crystal" // 晶体潮:产能 ×2
|
||||
| "resonance" // 谐振风暴:解码奖励 +60%
|
||||
| "ruins" // 遗迹共振:探险力 +5、生命 +30
|
||||
| "void" // 虚空低语:洞见 ×2
|
||||
| "core" // 星核悸动:接触率 ×3、脉冲 ×2
|
||||
| "silence" // 寂静期:产能 ×0.5,但结束时补偿洞见
|
||||
// v0.8.2 新增三种星潮(深化事件池)
|
||||
| "surge" // 涌动星潮:晶体产出 ×2.5 但解码目标 +2(产能爆发但解码变难)
|
||||
| "eclipse" // 蚀相星潮:探险 BOSS 胜率 +20% 但晶体产出 -30%(探险黄金期)
|
||||
| "prism"; // 棱镜星潮:洞见获取 ×2 + 自动解码周期 -30%(解码黄金期)
|
||||
|
||||
export interface StarTide {
|
||||
type: TideType;
|
||||
startedAt: number;
|
||||
endsAt: number;
|
||||
/** 唯一 id,用于 React key */
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface TideModifiers {
|
||||
crystalsPerSecMult: number;
|
||||
decodeRewardMult: number;
|
||||
insightMultAdd: number; // 加到 insightMult(百分比,0.5 = +50%)
|
||||
contactRateMult: number;
|
||||
pulsePowerMult: number;
|
||||
expeditionPowerBonus: number;
|
||||
expeditionHpBonus: number;
|
||||
/** 寂静期结束时补偿的洞见(按持续秒数) */
|
||||
silenceInsightPerSec?: number;
|
||||
/** v0.8.2 涌动星潮:解码目标序列额外长度(+2 = 谜题更长更难) */
|
||||
targetLenBonus?: number;
|
||||
/** v0.8.2 蚀相星潮:BOSS 胜率加成(0.2 = +20%) */
|
||||
bossWinRateBonus?: number;
|
||||
/** v0.8.2 棱镜星潮:自动解码周期乘数(0.7 = -30%) */
|
||||
autoDecodeIntervalMult?: number;
|
||||
}
|
||||
|
||||
export const TIDE_CONFIG = {
|
||||
/** 星潮持续时间(毫秒) */
|
||||
duration: 75000,
|
||||
/** 星潮之间的间隙(毫秒) */
|
||||
gap: 40000,
|
||||
/** 首次星潮触发延迟(毫秒,从 init 起) */
|
||||
firstDelay: 30000,
|
||||
};
|
||||
|
||||
export const TIDE_EVENTS: Record<
|
||||
TideType,
|
||||
{
|
||||
name: string;
|
||||
desc: string;
|
||||
color: string;
|
||||
glow: string;
|
||||
icon: string;
|
||||
/** 是否负面事件(影响 UI 提示语气) */
|
||||
negative: boolean;
|
||||
}
|
||||
> = {
|
||||
crystal: {
|
||||
name: "晶体潮",
|
||||
desc: "深空晶体涌动,采矿产能翻倍",
|
||||
color: "#34d399",
|
||||
glow: "rgba(52,211,153,0.5)",
|
||||
icon: "✺",
|
||||
negative: false,
|
||||
},
|
||||
resonance: {
|
||||
name: "谐振风暴",
|
||||
desc: "共振序列被放大,解码奖励 +60%",
|
||||
color: "#fb7185",
|
||||
glow: "rgba(251,113,133,0.5)",
|
||||
icon: "❖",
|
||||
negative: false,
|
||||
},
|
||||
ruins: {
|
||||
name: "遗迹共振",
|
||||
desc: "远古遗迹苏醒,探险力 +5、生命 +30",
|
||||
color: "#fbbf24",
|
||||
glow: "rgba(251,191,36,0.5)",
|
||||
icon: "⬢",
|
||||
negative: false,
|
||||
},
|
||||
void: {
|
||||
name: "虚空低语",
|
||||
desc: "虚空传来回响,洞见获取翻倍",
|
||||
color: "#e879f9",
|
||||
glow: "rgba(232,121,249,0.5)",
|
||||
icon: "✷",
|
||||
negative: false,
|
||||
},
|
||||
core: {
|
||||
name: "星核悸动",
|
||||
desc: "星核震荡,接触率 ×3、脉冲威力 ×2",
|
||||
color: "#a5f3fc",
|
||||
glow: "rgba(165,243,252,0.5)",
|
||||
icon: "✦",
|
||||
negative: false,
|
||||
},
|
||||
silence: {
|
||||
name: "寂静期",
|
||||
desc: "虚空沉寂,产能减半;结束时按时长补偿洞见",
|
||||
color: "#94a3b8",
|
||||
glow: "rgba(148,163,184,0.5)",
|
||||
icon: "◌",
|
||||
negative: true,
|
||||
},
|
||||
// ===== v0.8.2 新增三种星潮 =====
|
||||
surge: {
|
||||
name: "涌动星潮",
|
||||
desc: "深空晶体涌动,产能 ×2.5;但解码目标序列 +2,解码更耗时",
|
||||
color: "#34d399",
|
||||
glow: "rgba(52,211,153,0.55)",
|
||||
icon: "⇈",
|
||||
negative: false,
|
||||
},
|
||||
eclipse: {
|
||||
name: "蚀相星潮",
|
||||
desc: "维度蚀相,探险 BOSS 胜率 +20%;但晶体产出 -30%",
|
||||
color: "#fb7185",
|
||||
glow: "rgba(251,113,133,0.55)",
|
||||
icon: "◐",
|
||||
negative: false,
|
||||
},
|
||||
prism: {
|
||||
name: "棱镜星潮",
|
||||
desc: "棱镜折射,洞见获取 ×2、自动解码周期 -30%",
|
||||
color: "#e879f9",
|
||||
glow: "rgba(232,121,249,0.55)",
|
||||
icon: "◬",
|
||||
negative: false,
|
||||
},
|
||||
};
|
||||
|
||||
/** 权重表(寂静期概率略低;v0.8.2 新增三种各 12) */
|
||||
const TIDE_WEIGHTS: Record<TideType, number> = {
|
||||
crystal: 22,
|
||||
resonance: 20,
|
||||
ruins: 16,
|
||||
void: 18,
|
||||
core: 14,
|
||||
silence: 10,
|
||||
surge: 12,
|
||||
eclipse: 12,
|
||||
prism: 12,
|
||||
};
|
||||
|
||||
export function rollTide(rng: () => number = Math.random): TideType {
|
||||
const total = Object.values(TIDE_WEIGHTS).reduce((a, b) => a + b, 0);
|
||||
let r = rng() * total;
|
||||
for (const k of Object.keys(TIDE_WEIGHTS) as TideType[]) {
|
||||
r -= TIDE_WEIGHTS[k];
|
||||
if (r <= 0) return k;
|
||||
}
|
||||
return "crystal";
|
||||
}
|
||||
|
||||
/** 计算当前星潮的修饰器 */
|
||||
export function getTideModifiers(tide: StarTide | null): TideModifiers {
|
||||
if (!tide) {
|
||||
return {
|
||||
crystalsPerSecMult: 1,
|
||||
decodeRewardMult: 1,
|
||||
insightMultAdd: 0,
|
||||
contactRateMult: 1,
|
||||
pulsePowerMult: 1,
|
||||
expeditionPowerBonus: 0,
|
||||
expeditionHpBonus: 0,
|
||||
targetLenBonus: 0,
|
||||
bossWinRateBonus: 0,
|
||||
autoDecodeIntervalMult: 1,
|
||||
};
|
||||
}
|
||||
switch (tide.type) {
|
||||
case "crystal":
|
||||
return {
|
||||
crystalsPerSecMult: 2,
|
||||
decodeRewardMult: 1,
|
||||
insightMultAdd: 0,
|
||||
contactRateMult: 1,
|
||||
pulsePowerMult: 1,
|
||||
expeditionPowerBonus: 0,
|
||||
expeditionHpBonus: 0,
|
||||
};
|
||||
case "resonance":
|
||||
return {
|
||||
crystalsPerSecMult: 1,
|
||||
decodeRewardMult: 1.6,
|
||||
insightMultAdd: 0,
|
||||
contactRateMult: 1,
|
||||
pulsePowerMult: 1,
|
||||
expeditionPowerBonus: 0,
|
||||
expeditionHpBonus: 0,
|
||||
};
|
||||
case "ruins":
|
||||
return {
|
||||
crystalsPerSecMult: 1,
|
||||
decodeRewardMult: 1,
|
||||
insightMultAdd: 0,
|
||||
contactRateMult: 1,
|
||||
pulsePowerMult: 1,
|
||||
expeditionPowerBonus: 5,
|
||||
expeditionHpBonus: 30,
|
||||
};
|
||||
case "void":
|
||||
return {
|
||||
crystalsPerSecMult: 1,
|
||||
decodeRewardMult: 1,
|
||||
insightMultAdd: 1, // insightMult 翻倍(+100%)
|
||||
contactRateMult: 1,
|
||||
pulsePowerMult: 1,
|
||||
expeditionPowerBonus: 0,
|
||||
expeditionHpBonus: 0,
|
||||
};
|
||||
case "core":
|
||||
return {
|
||||
crystalsPerSecMult: 1,
|
||||
decodeRewardMult: 1,
|
||||
insightMultAdd: 0,
|
||||
contactRateMult: 3,
|
||||
pulsePowerMult: 2,
|
||||
expeditionPowerBonus: 0,
|
||||
expeditionHpBonus: 0,
|
||||
};
|
||||
case "silence":
|
||||
return {
|
||||
crystalsPerSecMult: 0.5,
|
||||
decodeRewardMult: 1,
|
||||
insightMultAdd: 0,
|
||||
contactRateMult: 1,
|
||||
pulsePowerMult: 1,
|
||||
expeditionPowerBonus: 0,
|
||||
expeditionHpBonus: 0,
|
||||
silenceInsightPerSec: 0.4,
|
||||
targetLenBonus: 0,
|
||||
bossWinRateBonus: 0,
|
||||
autoDecodeIntervalMult: 1,
|
||||
};
|
||||
// ===== v0.8.2 新增三种星潮修饰器 =====
|
||||
case "surge":
|
||||
// 晶体产出 ×2.5,解码目标 +2(更长谜题 = 更耗时 = 更难)
|
||||
return {
|
||||
crystalsPerSecMult: 2.5,
|
||||
decodeRewardMult: 1,
|
||||
insightMultAdd: 0,
|
||||
contactRateMult: 1,
|
||||
pulsePowerMult: 1,
|
||||
expeditionPowerBonus: 0,
|
||||
expeditionHpBonus: 0,
|
||||
targetLenBonus: 2,
|
||||
bossWinRateBonus: 0,
|
||||
autoDecodeIntervalMult: 1,
|
||||
};
|
||||
case "eclipse":
|
||||
// BOSS 胜率 +20%,晶体产出 -30%
|
||||
return {
|
||||
crystalsPerSecMult: 0.7,
|
||||
decodeRewardMult: 1,
|
||||
insightMultAdd: 0,
|
||||
contactRateMult: 1,
|
||||
pulsePowerMult: 1,
|
||||
expeditionPowerBonus: 0,
|
||||
expeditionHpBonus: 0,
|
||||
targetLenBonus: 0,
|
||||
bossWinRateBonus: 0.2,
|
||||
autoDecodeIntervalMult: 1,
|
||||
};
|
||||
case "prism":
|
||||
// 洞见 ×2(+100%),自动解码周期 ×0.7(-30%)
|
||||
return {
|
||||
crystalsPerSecMult: 1,
|
||||
decodeRewardMult: 1,
|
||||
insightMultAdd: 1,
|
||||
contactRateMult: 1,
|
||||
pulsePowerMult: 1,
|
||||
expeditionPowerBonus: 0,
|
||||
expeditionHpBonus: 0,
|
||||
targetLenBonus: 0,
|
||||
bossWinRateBonus: 0,
|
||||
autoDecodeIntervalMult: 0.7,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** 寂静期结束时的洞见补偿 */
|
||||
export function computeSilenceCompensation(tide: StarTide): number {
|
||||
const mod = getTideModifiers(tide);
|
||||
if (!mod.silenceInsightPerSec) return 0;
|
||||
const secs = (tide.endsAt - tide.startedAt) / 1000;
|
||||
return Math.round(mod.silenceInsightPerSec * secs);
|
||||
}
|
||||
Executable
+103
@@ -0,0 +1,103 @@
|
||||
// 回响星核 / Echo Nexus — 新手教程系统
|
||||
// 首次访问引导,分步骤高亮核心元素,可跳过/重看
|
||||
|
||||
export interface TutorialStep {
|
||||
id: string;
|
||||
// 目标元素的 data-tut 属性值(用于高亮定位)
|
||||
target?: string;
|
||||
// 提示放置位置:auto | top | bottom | left | right
|
||||
placement?: "auto" | "top" | "bottom" | "left" | "right";
|
||||
title: string;
|
||||
body: string;
|
||||
// 完成此步骤的预期动作(可选,用于"做了才下一步")
|
||||
// 不设则点"下一步"即可
|
||||
expectAction?: "pulse" | "decode-start" | "tech-buy" | "expedition-start";
|
||||
}
|
||||
|
||||
export const TUTORIAL_STEPS: TutorialStep[] = [
|
||||
{
|
||||
id: "welcome",
|
||||
placement: "bottom",
|
||||
title: "✦ 欢迎来到回响星核",
|
||||
body: "你是一台苏醒在深空遗迹中的自治无人机。在这里,你需要采矿、解码以太文明遗留的记忆晶体,逐步拼凑出一段跨越维度的叙事。\n\n本引导将带你认识 5 个核心玩法,约 1 分钟。可随时跳过。",
|
||||
},
|
||||
{
|
||||
id: "crystal",
|
||||
target: "crystal-orb",
|
||||
placement: "right",
|
||||
title: "① 脉冲扫描 · 采矿",
|
||||
body: "点击中央的「记忆晶体」发起脉冲扫描,获得记忆晶体。\n\n连续点击可触发连击,连击越高单次产出越多。无人机也会每秒自动采集(+0.4/s 起)。",
|
||||
expectAction: "pulse",
|
||||
},
|
||||
{
|
||||
id: "decode",
|
||||
target: "decode-panel",
|
||||
placement: "left",
|
||||
title: "② 谐振序列 · 解码",
|
||||
body: "记忆晶体存满后,点击右侧「待解码晶体」开启谐振谜题:按目标色序依次点击相邻同色节点重建回路。\n\n解码成功 → 获得技术洞见 + 记忆碎片(叙事片段)。这是游戏的核心解谜层。",
|
||||
expectAction: "decode-start",
|
||||
},
|
||||
{
|
||||
id: "tech",
|
||||
target: "tab-tech",
|
||||
placement: "top",
|
||||
title: "③ 技术树 · 成长",
|
||||
body: "用「技术洞见」在「技术」标签升级 4 大分支:产能 / 解码 / 仓库 / 探险。\n\n每个分支 3 级,策略性地分配洞见是关键。",
|
||||
expectAction: "tech-buy",
|
||||
},
|
||||
{
|
||||
id: "expedition",
|
||||
target: "tab-expedition",
|
||||
placement: "top",
|
||||
title: "④ 遗迹探险 · 肉鸽",
|
||||
body: "累积足够实力后,「探险」标签可深入遗迹:6 种节点(战斗/宝藏/抉择/解谜/休整/BOSS)程序化路径,有生命系统,失败保留奖励。\n\n这是放置之外的主动玩法层。",
|
||||
expectAction: "expedition-start",
|
||||
},
|
||||
{
|
||||
id: "prestige",
|
||||
target: "prestige-btn",
|
||||
placement: "bottom",
|
||||
title: "⑤ 飞升 · 多周目",
|
||||
body: "「接触进度」满 100% 后可飞升:重置进度,获得永久蓝图加成 + 星图天赋(3 选 1 draft)+ 编年史记录。\n\n多周目叠加,越飞越强。还有每日信标挑战、6 种星潮事件等你探索。",
|
||||
},
|
||||
{
|
||||
id: "done",
|
||||
placement: "bottom",
|
||||
title: "✦ 回响已唤醒",
|
||||
body: "教程结束!后续可在「设置 → 重新查看教程」再次查看。\n\n深空之中,回响永续。祝你考古愉快。",
|
||||
},
|
||||
];
|
||||
|
||||
const STORAGE_KEY = "echo-nexus-tutorial-v1";
|
||||
|
||||
export function hasSeenTutorial(): boolean {
|
||||
if (typeof window === "undefined") return true;
|
||||
try {
|
||||
return localStorage.getItem(STORAGE_KEY) === "1";
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function markTutorialSeen() {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, "1");
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
export function resetTutorial() {
|
||||
try {
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
export function restartTutorial() {
|
||||
resetTutorial();
|
||||
if (typeof window !== "undefined") {
|
||||
window.dispatchEvent(new CustomEvent("echo-nexus-tutorial-restart"));
|
||||
}
|
||||
}
|
||||
Executable
+285
@@ -0,0 +1,285 @@
|
||||
// 回响星核 / Echo Nexus — 核心类型定义
|
||||
|
||||
/** 资源类型 */
|
||||
export type ResourceType = "crystals" | "insights" | "energy";
|
||||
|
||||
/** 晶体稀有度(决定解码阵列规模与奖励) */
|
||||
export type CrystalTier = 1 | 2 | 3;
|
||||
|
||||
/** 共振颜色(解码谜题用)— 全息色谱,刻意避开蓝/靛 */
|
||||
export type ResonanceColor = "emerald" | "rose" | "amber" | "fuchsia";
|
||||
|
||||
/** 记忆晶体(待解码) */
|
||||
export interface Crystal {
|
||||
id: string;
|
||||
tier: CrystalTier;
|
||||
/** 解码奖励倍率 */
|
||||
value: number;
|
||||
createdAt: number;
|
||||
}
|
||||
|
||||
/** 技术分支 */
|
||||
export type TechBranch = "mining" | "decoding" | "expedition" | "narrative";
|
||||
|
||||
/** 技术节点定义 */
|
||||
export interface TechNode {
|
||||
id: string;
|
||||
branch: TechBranch;
|
||||
level: number;
|
||||
name: string;
|
||||
desc: string;
|
||||
cost: number; // insights
|
||||
effect: TechEffect;
|
||||
}
|
||||
|
||||
export interface TechEffect {
|
||||
kind:
|
||||
| "crystalsPerSec"
|
||||
| "crystalCap"
|
||||
| "offlineEff"
|
||||
| "decodeSteps"
|
||||
| "autoDecode"
|
||||
| "pulsePower"
|
||||
| "contactRate"
|
||||
| "insightMult";
|
||||
value: number;
|
||||
}
|
||||
|
||||
/** 记忆碎片(叙事) */
|
||||
export interface Fragment {
|
||||
id: string;
|
||||
era: number; // 1-5 纪元
|
||||
title: string;
|
||||
/** 拼出后的回响文本 */
|
||||
echo: string;
|
||||
/** 解锁所需晶体解码次数门槛 */
|
||||
threshold: number;
|
||||
}
|
||||
|
||||
/** 飞升(Prestige)加成 */
|
||||
export interface PrestigeBonus {
|
||||
crystalsPerSecMult: number;
|
||||
insightMult: number;
|
||||
contactRateMult: number;
|
||||
}
|
||||
|
||||
/** 解码阵列节点 */
|
||||
export interface DecodeNode {
|
||||
id: number;
|
||||
row: number;
|
||||
col: number;
|
||||
color: ResonanceColor;
|
||||
used: boolean;
|
||||
}
|
||||
|
||||
/** 解码谜题状态 */
|
||||
export interface DecodePuzzle {
|
||||
tier: CrystalTier;
|
||||
grid: DecodeNode[];
|
||||
rows: number;
|
||||
cols: number;
|
||||
/** 目标共振序列(玩家需按此顺序点击同色相邻节点) */
|
||||
target: ResonanceColor[];
|
||||
/** 已点击节点序列 */
|
||||
path: number[];
|
||||
stepLimit: number;
|
||||
seed: number;
|
||||
}
|
||||
|
||||
/** 完整游戏状态 */
|
||||
export interface GameState {
|
||||
// 资源
|
||||
crystals: number;
|
||||
insights: number;
|
||||
energy: number;
|
||||
contact: number; // 0-100 接触进度
|
||||
|
||||
// 产能(由技术树 + 飞升计算缓存)
|
||||
crystalsPerSec: number;
|
||||
crystalCap: number;
|
||||
pulsePower: number;
|
||||
offlineEff: number; // 0-1
|
||||
insightMult: number;
|
||||
contactRateMult: number;
|
||||
autoDecode: boolean;
|
||||
|
||||
// 技术
|
||||
tech: Record<string, number>; // techId -> level
|
||||
|
||||
// 记忆
|
||||
fragments: Record<string, boolean>;
|
||||
totalDecoded: number;
|
||||
|
||||
// 飞升
|
||||
ascensions: number;
|
||||
blueprints: string[];
|
||||
|
||||
// 解码
|
||||
pendingCrystals: Crystal[];
|
||||
activePuzzle: DecodePuzzle | null;
|
||||
|
||||
// 探险
|
||||
activeExpedition: Expedition | null;
|
||||
expeditionLog: ExpeditionLogEntry[];
|
||||
energyMax: number;
|
||||
lastEnergyTick: number;
|
||||
totalExpeditions: number;
|
||||
bossKills: number; // 累计击败 BOSS 数(跨周目)
|
||||
/** v0.9 工单修复:上次探险结果摘要,用于入口界面展示 */
|
||||
lastExpeditionSummary: {
|
||||
result: "victory" | "defeat" | "abort";
|
||||
rewards: { crystals: number; insights: number; contact: number };
|
||||
nodeCount: number;
|
||||
finishedAt: number;
|
||||
} | null;
|
||||
|
||||
// 成就
|
||||
achievements: Record<string, boolean>; // achievementId -> unlocked
|
||||
|
||||
// 星潮事件
|
||||
activeTide: import("./starTide").StarTide | null;
|
||||
lastTideEnd: number;
|
||||
starTidesEncountered: string[]; // 累计遇到的星潮 ID 集合(跨周目,去重)
|
||||
|
||||
// 星图天文台(v0.3.1 元进程)
|
||||
constellation: string[]; // 已解锁天赋 ID 列表
|
||||
pendingPerkChoices: string[] | null; // 飞升后待选择(3 选 1)
|
||||
|
||||
// 回响编年史(v0.4 跨周目叙事时间轴)
|
||||
chronicle: ChronicleEntry[];
|
||||
runStart: RunStartSnapshot;
|
||||
|
||||
// 角色属性(v0.7 P1 — 四维属性系统)
|
||||
attributes: import("./attributes").CharacterAttributes;
|
||||
attributeProgress: import("./attributes").AttributeProgress;
|
||||
pendingAttrPoints: number;
|
||||
|
||||
// 元
|
||||
lastTick: number;
|
||||
createdAt: number;
|
||||
theme: "dark" | "light";
|
||||
soundOn: boolean;
|
||||
}
|
||||
|
||||
/** 编年史单条记录(每次飞升生成一条) */
|
||||
export interface ChronicleEntry {
|
||||
/** 第几次飞升(1-based) */
|
||||
ascensionNumber: number;
|
||||
/** 程序化生成的纪元名 */
|
||||
epochName: string;
|
||||
/** 飞升完成时间戳 */
|
||||
timestamp: number;
|
||||
/** 本周目持续时间(秒) */
|
||||
durationSec: number;
|
||||
/** 本周目快照统计 */
|
||||
summary: {
|
||||
techsUnlocked: number;
|
||||
constellationsTotal: number;
|
||||
expeditionsCompleted: number;
|
||||
bossKills: number;
|
||||
starTidesEncountered: number;
|
||||
blueprintsAfter: number;
|
||||
crystalsDecoded: number;
|
||||
crystalsDecodedThisRun: number;
|
||||
/** v0.9 手写叙事:本周目 delta(旧存档可能缺失,调用方需兜底) */
|
||||
techsThisRun?: number;
|
||||
expeditionsThisRun?: number;
|
||||
bossKillsThisRun?: number;
|
||||
};
|
||||
/** 本次飞升获得的天赋 ID(来自星图觉醒) */
|
||||
perksThisAscension: string[];
|
||||
/** 本周目遇到的星潮 ID 集合 */
|
||||
tidesThisRun: string[];
|
||||
/** 程序化生成的叙事文本(1-2 段) */
|
||||
lore: string;
|
||||
/** 标志位:本周目首次达成的里程碑 */
|
||||
milestones: string[];
|
||||
}
|
||||
|
||||
/** 周目起始快照(用于计算 delta) */
|
||||
export interface RunStartSnapshot {
|
||||
timestamp: number;
|
||||
techsUnlocked: number;
|
||||
expeditionsCompleted: number;
|
||||
bossKills: number;
|
||||
starTidesEncountered: string[];
|
||||
crystalsDecoded: number;
|
||||
}
|
||||
|
||||
// ============ 遗迹探险 (Expedition) 系统 ============
|
||||
|
||||
/** 探险节点类型 */
|
||||
export type ExpeditionNodeType =
|
||||
| "combat"
|
||||
| "treasure"
|
||||
| "choice"
|
||||
| "puzzle"
|
||||
| "boss"
|
||||
| "rest";
|
||||
|
||||
/** 探险节点 */
|
||||
export interface ExpeditionNode {
|
||||
id: number;
|
||||
type: ExpeditionNodeType;
|
||||
/** 事件描述 */
|
||||
title: string;
|
||||
desc: string;
|
||||
/** 该节点是否已被访问 */
|
||||
cleared: boolean;
|
||||
/** 战斗/解谜的难度(影响胜率/奖励) */
|
||||
difficulty: number;
|
||||
/** 节点在路径上的位置索引 */
|
||||
position: number;
|
||||
}
|
||||
|
||||
/** 探险状态 */
|
||||
export interface Expedition {
|
||||
id: string;
|
||||
/** 节点路径(线性,position 0..n) */
|
||||
nodes: ExpeditionNode[];
|
||||
/** 当前所在节点索引 */
|
||||
currentNode: number;
|
||||
/** 是否已完成(到达 boss 并结算) */
|
||||
finished: boolean;
|
||||
/** 本次探险累计奖励 */
|
||||
rewards: {
|
||||
crystals: number;
|
||||
insights: number;
|
||||
contact: number;
|
||||
fragments: string[];
|
||||
};
|
||||
/** 探险力(由技术+飞升计算) */
|
||||
power: number;
|
||||
/** 剩余生命(战斗失败扣减,归零则探险失败结束) */
|
||||
hp: number;
|
||||
maxHp: number;
|
||||
/** 种子(可复现) */
|
||||
seed: number;
|
||||
startedAt: number;
|
||||
}
|
||||
|
||||
/** 探险日志条目 */
|
||||
export interface ExpeditionLogEntry {
|
||||
expeditionId: string;
|
||||
nodeType: ExpeditionNodeType;
|
||||
result: string;
|
||||
rewards: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
/** 探险事件结算结果 */
|
||||
export interface ExpeditionResult {
|
||||
/** 日志描述 */
|
||||
log: string;
|
||||
/** 奖励 */
|
||||
crystals?: number;
|
||||
insights?: number;
|
||||
contact?: number;
|
||||
fragments?: string[];
|
||||
/** 生命变化 */
|
||||
hpDelta?: number;
|
||||
/** 是否探险结束(失败或完成) */
|
||||
ended: boolean;
|
||||
/** 结束原因 */
|
||||
endReason?: "victory" | "defeat" | "abort";
|
||||
}
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
Executable
+1365
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user