- 将包管理器从 pnpm 更改为 bun,提升依赖管理效率。 - 在 index.html 中引入 jQuery 和 videoajax.js,增强页面功能。 - 删除 pnpm-lock.yaml 文件,清理不必要的锁定文件。 - 在多个组件中优化状态管理和访问逻辑,提升用户体验。 - 更新多个页面和组件以支持新的状态管理方式,确保数据一致性。
84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import { create } from "zustand";
|
|
import { persist } from "zustand/middleware";
|
|
import { STORE_NAMES } from "./storeNames";
|
|
|
|
export interface Clue {
|
|
id: string; // 格式: "sunzhongshan/reflection/scene1/clue1"
|
|
name: string; // 线索名称,如 "线索1"
|
|
collected: boolean; // 是否已收集
|
|
collectedAt?: number; // 收集时间戳
|
|
}
|
|
|
|
interface ClueStore {
|
|
clues: Clue[];
|
|
// 收集线索
|
|
collectClue: (id: string, name: string) => void;
|
|
// 检查线索是否已收集
|
|
isClueCollected: (id: string) => boolean;
|
|
// 获取指定场景的所有线索
|
|
getSceneClues: (sceneId: string) => Clue[];
|
|
// 重置指定场景的线索
|
|
resetSceneClues: (sceneId: string) => void;
|
|
// 重置所有线索
|
|
resetAll: () => void;
|
|
}
|
|
|
|
export const useClueStore = create<ClueStore>()(
|
|
persist(
|
|
(set, get) => ({
|
|
clues: [],
|
|
|
|
collectClue: (id: string, name: string) => {
|
|
const { clues } = get();
|
|
const existingClue = clues.find((c) => c.id === id);
|
|
|
|
if (!existingClue) {
|
|
set({
|
|
clues: [
|
|
...clues,
|
|
{
|
|
id,
|
|
name,
|
|
collected: true,
|
|
collectedAt: Date.now(),
|
|
},
|
|
],
|
|
});
|
|
} else if (!existingClue.collected) {
|
|
set({
|
|
clues: clues.map((c) =>
|
|
c.id === id
|
|
? { ...c, collected: true, collectedAt: Date.now() }
|
|
: c
|
|
),
|
|
});
|
|
}
|
|
},
|
|
|
|
isClueCollected: (id: string) => {
|
|
const { clues } = get();
|
|
return clues.some((c) => c.id === id && c.collected);
|
|
},
|
|
|
|
getSceneClues: (sceneId: string) => {
|
|
const { clues } = get();
|
|
return clues.filter((c) => c.id.startsWith(sceneId));
|
|
},
|
|
|
|
resetSceneClues: (sceneId: string) => {
|
|
const { clues } = get();
|
|
set({
|
|
clues: clues.filter((c) => !c.id.startsWith(sceneId)),
|
|
});
|
|
},
|
|
|
|
resetAll: () => {
|
|
set({ clues: [] });
|
|
},
|
|
}),
|
|
{
|
|
name: STORE_NAMES.CLUE, // localStorage key
|
|
}
|
|
)
|
|
);
|