Commit b013068f authored by Chunchi Che's avatar Chunchi Che

fix confirmCards

parent 87cc4ada
import { fetchCard, ygopro } from "@/api"; import { fetchCard, ygopro } from "@/api";
import { sleep } from "@/infra"; import { sleep } from "@/infra";
import { matStore } from "@/stores"; import { cardStore, matStore } from "@/stores";
export default async (confirmCards: ygopro.StocGameMessage.MsgConfirmCards) => { export default async (confirmCards: ygopro.StocGameMessage.MsgConfirmCards) => {
const cards = confirmCards.cards; const cards = confirmCards.cards;
for (const card of cards) { for (const card of cards) {
const target = matStore const target = cardStore.at(card.location, card.controler, card.sequence);
.in(card.location)
.of(card.controler)
.at(card.sequence);
if (target) { if (target) {
// 设置`occupant` // 设置`occupant`
const meta = await fetchCard(card.code); const meta = await fetchCard(card.code);
target.occupant = meta; target.meta = meta;
// 设置`position`,否则会横放 // 设置`position`,否则会横放
target.location.position = ygopro.CardPosition.ATTACK; target.position = ygopro.CardPosition.ATTACK;
// 聚焦1s // 聚焦1s
target.focus = true; target.focus = true;
......
...@@ -93,8 +93,11 @@ export default (start: ygopro.StocGameMessage.MsgStart) => { ...@@ -93,8 +93,11 @@ export default (start: ygopro.StocGameMessage.MsgStart) => {
counters: {}, counters: {},
idleInteractivities: [], idleInteractivities: [],
sequence, sequence,
meta: {
id: 0,
data: {}, data: {},
text: {}, text: {},
},
isToken: !((i + 1) % 3), isToken: !((i + 1) % 3),
overlayMaterials: [], overlayMaterials: [],
position: ygopro.CardPosition.FACEDOWN, position: ygopro.CardPosition.FACEDOWN,
...@@ -117,9 +120,8 @@ export default (start: ygopro.StocGameMessage.MsgStart) => { ...@@ -117,9 +120,8 @@ export default (start: ygopro.StocGameMessage.MsgStart) => {
const genCard = (o: CardType) => { const genCard = (o: CardType) => {
const t = proxy(o); const t = proxy(o);
subscribeKey(t, "code", async (code) => { subscribeKey(t, "code", async (code) => {
const { text, data } = await fetchCard(code ?? 0); const meta = await fetchCard(code ?? 0);
t.text = text; t.meta = meta;
t.data = data;
}); });
return t; return t;
}; };
import { proxy } from "valtio"; import { proxy } from "valtio";
import { CardData, CardText, fetchCard, ygopro } from "@/api"; import { CardMeta, fetchCard, ygopro } from "@/api";
import type { Interactivity } from "./matStore/types"; import type { Interactivity } from "./matStore/types";
...@@ -10,8 +10,7 @@ import type { Interactivity } from "./matStore/types"; ...@@ -10,8 +10,7 @@ import type { Interactivity } from "./matStore/types";
export interface CardType { export interface CardType {
uuid: string; // 一张卡的唯一标识 uuid: string; // 一张卡的唯一标识
code: number; // 卡号 code: number; // 卡号
data: CardData; meta: CardMeta; // 卡片元数据
text: CardText;
controller: number; // 控制这个位置的玩家,0或1 controller: number; // 控制这个位置的玩家,0或1
originController: number; // 在卡组构建之中持有这张卡的玩家,方便reloadField的使用 originController: number; // 在卡组构建之中持有这张卡的玩家,方便reloadField的使用
zone: ygopro.CardZone; // 怪兽区/魔法陷阱区/手牌/卡组/墓地/除外区 zone: ygopro.CardZone; // 怪兽区/魔法陷阱区/手牌/卡组/墓地/除外区
...@@ -65,7 +64,11 @@ class CardStore { ...@@ -65,7 +64,11 @@ class CardStore {
find(location: ygopro.CardLocation): CardType | undefined { find(location: ygopro.CardLocation): CardType | undefined {
return this.at(location.location, location.controler, location.sequence); return this.at(location.location, location.controler, location.sequence);
} }
async setChaining(location: ygopro.CardLocation, code: number, isChaining: boolean): Promise<void> { async setChaining(
location: ygopro.CardLocation,
code: number,
isChaining: boolean
): Promise<void> {
const target = this.find(location); const target = this.find(location);
if (target) { if (target) {
target.chaining = isChaining; target.chaining = isChaining;
...@@ -74,8 +77,7 @@ class CardStore { ...@@ -74,8 +77,7 @@ class CardStore {
// 运行到这里的时候已经和原来的位置对不上了,这时候不设置meta // 运行到这里的时候已经和原来的位置对不上了,这时候不设置meta
const meta = await fetchCard(code); const meta = await fetchCard(code);
target.code = meta.id; target.code = meta.id;
target.data = meta.data; target.meta = meta;
target.text = meta.text;
} }
if (target.zone == ygopro.CardZone.HAND) { if (target.zone == ygopro.CardZone.HAND) {
target.position = isChaining target.position = isChaining
......
...@@ -69,8 +69,8 @@ export const fetchEsHintMeta = async ({ ...@@ -69,8 +69,8 @@ export const fetchEsHintMeta = async ({
location.controler, location.controler,
location.sequence location.sequence
); );
if (fieldMeta?.text.name) { if (fieldMeta?.meta.text.name) {
esHint = esHint.replace("[?]", fieldMeta.text.name); esHint = esHint.replace("[?]", fieldMeta.meta.text.name);
} }
} }
......
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