Commit 68184e77 authored by Chunchi Che's avatar Chunchi Che

fix

parent d8c00bb9
Pipeline #21066 passed with stages
in 19 minutes and 25 seconds
......@@ -6,7 +6,7 @@ import {
} from "@reduxjs/toolkit";
import { RootState } from "../../../store";
import { DuelState } from "../mod";
import { findCardByLocation, judgeSelf } from "../util";
import { cmpCardLocation, findCardByLocation, judgeSelf } from "../util";
import { fetchCard, getCardStr } from "../../../api/cards";
import { ygopro } from "../../../api/ocgcore/idl/ocgcore";
......@@ -65,17 +65,11 @@ export const fetchCheckCardMeta = createAsyncThunk(
}) => {
// FIXME: 这里如果传的`controler`如果是对手,对应的`code`会为零,这时候就无法更新对应的`Meta`信息了,后续需要修复。`fetchCheckCardMetaV2`和`fetchCheckCardMetaV3`同理
const meta = await fetchCard(param.option.code, true);
const effectDesc = param.option.effectDescCode
? getCardStr(meta, param.option.effectDescCode & 0xf)
: undefined;
const response = {
controler: param.option.location.controler,
tagName: param.tagName,
meta: {
code: meta.id,
name: meta.text.name,
desc: meta.text.desc,
effectDesc,
option: {
meta,
location: param.option.location.toObject(),
},
};
......@@ -91,6 +85,7 @@ export const checkCardModalCase = (
const code = action.meta.arg.option.code;
const location = action.meta.arg.option.location;
const controler = location.controler;
const effectDescCode = action.meta.arg.option.effectDescCode;
const response = action.meta.arg.option.response;
const combinedTagName = judgeSelf(controler, state)
......@@ -101,23 +96,29 @@ export const checkCardModalCase = (
code != 0 ? code : findCardByLocation(state, location)?.occupant?.id || 0;
if (newID) {
const newOption = {
meta: { id: code, data: {}, text: {} },
location: location.toObject(),
effectDescCode,
response,
};
for (const tag of state.modalState.checkCardModal.tags) {
if (tag.tagName === combinedTagName) {
tag.options.push({ code: newID, response });
tag.options.push(newOption);
return;
}
}
state.modalState.checkCardModal.tags.push({
tagName: combinedTagName,
options: [{ code: newID, response }],
options: [newOption],
});
}
});
builder.addCase(fetchCheckCardMeta.fulfilled, (state, action) => {
const controler = action.payload.controler;
const tagName = action.payload.tagName;
const meta = action.payload.meta;
const option = action.payload.option;
const controler = option.location.controler!;
const combinedTagName = judgeSelf(controler, state)
? `我方的${tagName}`
......@@ -125,11 +126,18 @@ export const checkCardModalCase = (
for (const tag of state.modalState.checkCardModal.tags) {
if (tag.tagName === combinedTagName) {
for (const option of tag.options) {
if (option.code == meta.code) {
option.name = meta.name;
option.desc = meta.desc;
option.effectDesc = meta.effectDesc;
for (const old of tag.options) {
if (
option.meta.id == old.meta.id &&
cmpCardLocation(option.location, old.location)
) {
old.meta = option.meta;
const effectDescCode = old.effectDescCode;
const effectDesc = effectDescCode
? getCardStr(old.meta, effectDescCode & 0xf)
: undefined;
old.effectDesc = effectDesc;
}
}
}
......
import { CardMeta } from "../../../api/cards";
import { ygopro } from "../../../api/ocgcore/idl/ocgcore";
type CardLocation = ReturnType<typeof ygopro.CardLocation.prototype.toObject>;
export interface ModalState {
// 卡牌弹窗
......@@ -28,9 +29,9 @@ export interface ModalState {
tags: {
tagName: string;
options: {
code: number;
name?: string;
desc?: string;
meta: CardMeta;
location?: CardLocation;
effectDescCode?: number;
effectDesc?: string;
response: number;
}[];
......
......@@ -8,6 +8,10 @@ import { Draft } from "@reduxjs/toolkit";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { CardState } from "./generic";
type Location =
| ygopro.CardLocation
| ReturnType<typeof ygopro.CardLocation.prototype.toObject>;
/*
* 通过`player`和`selfType`判断是应该处理自己还是对手
* */
......@@ -29,9 +33,7 @@ export function judgeSelf(player: number, state: Draft<DuelState>): boolean {
* 通过`controler`,`zone`和`sequence`获取卡牌状态*/
export function findCardByLocation(
state: Draft<DuelState>,
location:
| ygopro.CardLocation
| ReturnType<typeof ygopro.CardLocation.prototype.toObject>
location: Location
): CardState | undefined {
const controler = location.controler!;
const zone = location.location;
......@@ -73,3 +75,19 @@ export function findCardByLocation(
}
}
}
export function cmpCardLocation(
left: Location,
right?: Location,
strict?: boolean
): boolean {
if (strict) {
return JSON.stringify(left) === JSON.stringify(right);
} else {
return (
left.controler === right?.controler &&
left.location === right?.location &&
left.sequence === right?.sequence
);
}
}
......@@ -111,13 +111,13 @@ const CheckCardModal = () => {
<Col span={4} key={idx}>
<HoverCheckCard
hoverContent={option.effectDesc}
title={option.name}
description={option.desc}
title={option.meta.text.name}
description={option.meta.text.desc}
style={{ width: 120 }}
cover={
<img
alt={option.code.toString()}
src={`${NeosConfig.cardImgUrl}/${option.code}.jpg`}
alt={option.meta.id.toString()}
src={`${NeosConfig.cardImgUrl}/${option.meta.id}.jpg`}
style={{ width: 100 }}
/>
}
......
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