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