Commit d65485b1 authored by timel's avatar timel

refactor: store

parent 91b5fbdc
...@@ -6,8 +6,8 @@ import { subscribeKey } from "valtio/utils"; ...@@ -6,8 +6,8 @@ import { subscribeKey } from "valtio/utils";
import { fetchCard, ygopro } from "@/api"; import { fetchCard, ygopro } from "@/api";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { sleep } from "@/infra"; import { sleep } from "@/infra";
import { cardStore, CardType, store } from "@/stores"; import { cardStore, CardType, matStore } from "@/stores";
const { matStore } = store;
const TOKEN_SIZE = 13; // 每人场上最多就只可能有13个token const TOKEN_SIZE = 13; // 每人场上最多就只可能有13个token
export default async (start: ygopro.StocGameMessage.MsgStart) => { export default async (start: ygopro.StocGameMessage.MsgStart) => {
......
...@@ -7,7 +7,6 @@ export * from "./methods"; ...@@ -7,7 +7,6 @@ export * from "./methods";
export * from "./moraStore"; export * from "./moraStore";
export * from "./placeStore"; export * from "./placeStore";
import { proxy } from "valtio";
import { devtools } from "valtio/utils"; import { devtools } from "valtio/utils";
import { cardStore } from "./cardStore"; import { cardStore } from "./cardStore";
...@@ -18,14 +17,10 @@ import { messageStore } from "./messageStore"; ...@@ -18,14 +17,10 @@ import { messageStore } from "./messageStore";
import { moraStore } from "./moraStore"; import { moraStore } from "./moraStore";
import { placeStore } from "./placeStore"; import { placeStore } from "./placeStore";
export const store = proxy({ devtools(chatStore, { name: "chat store", enabled: true });
chatStore, devtools(joinStore, { name: "join store", enabled: true });
joinStore, devtools(moraStore, { name: "mora store", enabled: true });
moraStore, devtools(matStore, { name: "mat store", enabled: true });
matStore, // 决斗盘 devtools(messageStore, { name: "message store", enabled: true });
messageStore, // 决斗的信息,包括模态框 devtools(cardStore, { name: "card store", enabled: true });
cardStore, devtools(placeStore, { name: "place store", enabled: true });
placeStore,
});
devtools(store, { name: "valtio store", enabled: true });
...@@ -94,7 +94,7 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => { ...@@ -94,7 +94,7 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => {
useEffect(() => { useEffect(() => {
setHighlight(!!snap.idleInteractivities.length); setHighlight(!!snap.idleInteractivities.length);
}, [snap.idleInteractivities]); }, [snap.idleInteractivities.length]);
return ( return (
<animated.div <animated.div
......
...@@ -30,7 +30,7 @@ import { DeckManager, fetchDeck, type IDeck } from "@/api/deck"; ...@@ -30,7 +30,7 @@ import { DeckManager, fetchDeck, type IDeck } from "@/api/deck";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import socketMiddleWare, { socketCmd } from "@/middleware/socket"; import socketMiddleWare, { socketCmd } from "@/middleware/socket";
import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite"; import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite";
import { store } from "@/stores"; import { chatStore, joinStore, matStore, moraStore } from "@/stores";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
...@@ -42,8 +42,10 @@ const { ...@@ -42,8 +42,10 @@ const {
} = useConfig(); } = useConfig();
const WaitRoom = () => { const WaitRoom = () => {
const state = store; const snapJoin = useSnapshot(joinStore);
const snap = useSnapshot(state); const snapChat = useSnapshot(chatStore);
const snapMat = useSnapshot(matStore);
const snapMora = useSnapshot(moraStore);
const params = useParams<{ const params = useParams<{
player?: string; player?: string;
passWd?: string; passWd?: string;
...@@ -89,12 +91,12 @@ const WaitRoom = () => { ...@@ -89,12 +91,12 @@ const WaitRoom = () => {
const [api, contextHolder] = notification.useNotification(); const [api, contextHolder] = notification.useNotification();
const joined = snap.joinStore.value; const joined = snapJoin.value;
const chat = snap.chatStore.message; const chat = snapChat.message;
const isHost = snap.matStore.isHost; const isHost = snapMat.isHost;
const player0 = snap.matStore.player[0]; const player0 = snapMat.player[0];
const player1 = snap.matStore.player[1]; const player1 = snapMat.player[1];
const duelStart = snap.moraStore.duelStart; const duelStart = snapMora.duelStart;
// FIXME: 这些数据应该从`store`中获取 // FIXME: 这些数据应该从`store`中获取
// TODO: 云卡组 // TODO: 云卡组
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment