Commit b5ea98a8 authored by Chunchi Che's avatar Chunchi Che

extract genCard

parent ad0a228f
Pipeline #23323 passed with stages
in 13 minutes and 5 seconds
import { ygopro } from "@/api";
type MsgReloadField = ygopro.StocGameMessage.MsgReloadField;
export default (_field: MsgReloadField) => {
// TODO: 断线重连比较复杂,先留着后面时实现
};
export default (_field: MsgReloadField) => {};
import { flatten } from "lodash-es";
import { v4 as v4uuid } from "uuid";
import { proxy } from "valtio";
import { subscribeKey } from "valtio/utils";
import PlayerType = ygopro.StocGameMessage.MsgStart.PlayerType;
import { fetchCard, ygopro } from "@/api";
import { ygopro } from "@/api";
import { useConfig } from "@/config";
import { sleep } from "@/infra";
import {
cardStore,
CardType,
matStore,
RoomStage,
roomStore,
......@@ -16,6 +13,8 @@ import {
sideStore,
} from "@/stores";
import { replayStart } from "@/ui/Match/ReplayModal";
import { genCard } from "../utils";
const TOKEN_SIZE = 13; // 每人场上最多就只可能有13个token
export default async (start: ygopro.StocGameMessage.MsgStart) => {
......@@ -101,13 +100,3 @@ export default async (start: ygopro.StocGameMessage.MsgStart) => {
// 否则在和AI对战时,由于后端给传给前端的`MSG`频率太高,会导致一些问题。
await sleep(useConfig().startDelay);
};
// 自动从code推断出occupant
const genCard = (o: CardType) => {
const t = proxy(o);
subscribeKey(t, "code", async (code) => {
const meta = fetchCard(code ?? 0);
t.meta = meta;
});
return t;
};
......@@ -17,7 +17,10 @@ export default async (updateData: MsgUpdateData) => {
// 目前只更新以下字段
if (action?.code >= 0) {
const newMeta = fetchCard(action.code);
target.code = action.code;
if (target.code !== action.code) {
// 这个if判断一定要有,不然会触发`genCard`里面的事件
target.code = action.code;
}
target.meta = newMeta;
}
......
import { proxy } from "valtio";
import { subscribeKey } from "valtio/utils";
import { fetchCard } from "@/api";
import { CardType } from "@/stores";
// 自动从code推断出meta
export const genCard = (card: CardType) => {
const t = proxy(card);
subscribeKey(t, "code", (code) => {
const meta = fetchCard(code);
t.meta = meta;
});
return t;
};
export * from "./fetchCheckCardMeta";
export * from "./genCard";
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