Commit bc23ca62 authored by Chunchi Che's avatar Chunchi Che

udpate hintSlice

parent c3751b96
......@@ -2,7 +2,7 @@ import { createAsyncThunk, ActionReducerMapBuilder } from "@reduxjs/toolkit";
import { DuelState } from "./mod";
import { RootState } from "../../store";
import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "../../api/strings";
import { findCardByLocation, judgeSelf } from "./util";
import { findCardByLocation } from "./util";
import { fetchCard } from "../../api/cards";
import { DuelReducer } from "./generic";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
......@@ -14,37 +14,20 @@ export interface HintState {
esSelectHint?: string;
}
export const initHintImpl: DuelReducer<number> = (state, action) => {
const player = action.payload;
if (judgeSelf(player, state)) {
state.meHint = { code: 0 };
} else {
state.opHint = { code: 0 };
}
export const initHintImpl: DuelReducer<void> = (state) => {
state.hint = { code: 0 };
};
export const fetchCommonHintMeta = createAsyncThunk(
"duel/fetchCommonHintMeta",
async (param: [number, number]) => {
const player = param[0];
const hintData = param[1];
const hintMeta = fetchStrings("!system", hintData);
const response: [number, string] = [player, hintMeta];
return response;
async (hintData: number) => {
return fetchStrings("!system", hintData);
}
);
export const fetchSelectHintMeta = createAsyncThunk(
"duel/fetchSelectHintMeta",
async (param: {
player: number;
selectHintData: number;
esHint?: string;
}) => {
const player = param.player;
async (param: { selectHintData: number; esHint?: string }) => {
const selectHintData = param.selectHintData;
let selectHintMeta = "";
......@@ -60,7 +43,6 @@ export const fetchSelectHintMeta = createAsyncThunk(
}
return {
player,
selectHintMeta,
esHint: param.esHint,
};
......@@ -70,12 +52,10 @@ export const fetchSelectHintMeta = createAsyncThunk(
export const fetchEsHintMeta = createAsyncThunk(
"duel/fetchEsHintMeta",
async (param: {
player: number;
originMsg: string | number;
location?: ygopro.CardLocation;
cardID?: number;
}) => {
const player = param.player;
const originMsg =
typeof param.originMsg === "string"
? param.originMsg
......@@ -86,49 +66,41 @@ export const fetchEsHintMeta = createAsyncThunk(
if (param.cardID) {
const cardMeta = await fetchCard(param.cardID);
return { player, originMsg, cardMeta, location };
return { originMsg, cardMeta, location };
} else {
return { player, originMsg, location };
return { originMsg, location };
}
}
);
export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchCommonHintMeta.pending, (state, action) => {
const player = action.meta.arg[0];
const code = action.meta.arg[1];
const code = action.meta.arg;
if (judgeSelf(player, state)) {
state.meHint = { code };
} else {
state.opHint = { code };
if (state.hint) {
state.hint.code = code;
}
});
builder.addCase(fetchCommonHintMeta.fulfilled, (state, action) => {
const player = action.payload[0];
const hintMeta = action.payload[1];
const hintMeta = action.payload;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
if (hint) {
hint.msg = hintMeta;
if (state.hint) {
state.hint.msg = hintMeta;
}
});
builder.addCase(fetchSelectHintMeta.pending, (state, action) => {
const player = action.meta.arg.player;
const code = action.meta.arg.selectHintData;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
if (hint) {
hint.code = code;
if (state.hint) {
state.hint.code = code;
}
});
builder.addCase(fetchSelectHintMeta.fulfilled, (state, action) => {
const player = action.payload.player;
const selectHintMsg = action.payload.selectHintMeta;
const esHint = action.payload.esHint;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
const hint = state.hint;
if (hint) {
if (hint.code > DESCRIPTION_LIMIT) {
// 针对`MSG_SELECT_PLACE`的特化逻辑
......@@ -140,12 +112,11 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
}
});
builder.addCase(fetchEsHintMeta.fulfilled, (state, action) => {
const player = action.payload.player;
const originMsg = action.payload.originMsg;
const cardMeta = action.payload.cardMeta;
const location = action.payload.location;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
const hint = state.hint;
if (hint) {
let esHint = originMsg;
......@@ -165,5 +136,4 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
});
};
export const selectMeHint = (state: RootState) => state.duel.meHint;
export const selectOpHint = (state: RootState) => state.duel.opHint;
export const selectHint = (state: RootState) => state.duel.hint;
......@@ -149,8 +149,7 @@ export interface DuelState {
meTimeLimit?: TimeLimit; // 自己的计时
opTimeLimit?: TimeLimit; // 对手的计时
meHint?: HintState; // 自己的提示
opHint?: HintState; // 对手的提示
hint?: HintState;
currentPlayer?: number; // 当前的操作方
......
......@@ -7,15 +7,14 @@ import {
import MsgHint = ygopro.StocGameMessage.MsgHint;
export default (hint: MsgHint, dispatch: AppDispatch) => {
const player = hint.player;
switch (hint.hint_type) {
case MsgHint.HintType.HINT_EVENT:
case MsgHint.HintType.HINT_MESSAGE: {
dispatch(fetchCommonHintMeta([player, hint.hint_data]));
dispatch(fetchCommonHintMeta(hint.hint_data));
break;
}
case MsgHint.HintType.HINT_SELECTMSG: {
dispatch(fetchSelectHintMeta({ player, selectHintData: hint.hint_data }));
dispatch(fetchSelectHintMeta({ selectHintData: hint.hint_data }));
break;
}
default: {
......
......@@ -86,7 +86,6 @@ export default (selectChain: MsgSelectChain, dispatch: AppDispatch) => {
}
dispatch(
fetchSelectHintMeta({
player,
selectHintData: 203,
})
);
......
......@@ -46,6 +46,5 @@ export default (
dispatch(initDeck({ player: 1, deskSize: start.deckSize2 }));
dispatch(initExclusion(0));
dispatch(initExclusion(1));
dispatch(initHint(0));
dispatch(initHint(1));
dispatch(initHint());
};
......@@ -22,7 +22,7 @@ import {
import { ThunderboltOutlined } from "@ant-design/icons";
import NeosConfig from "../../../neos.config.json";
import DragModal from "./dragModal";
import { selectMeHint } from "../../reducers/duel/hintSlice";
import { selectHint } from "../../reducers/duel/hintSlice";
const CheckCardModal = () => {
const dispatch = store.dispatch;
......@@ -34,7 +34,7 @@ const CheckCardModal = () => {
const cancelResponse = useAppSelector(selectCheckCardModalCacnelResponse);
const [response, setResponse] = useState<number[]>([]);
const defaultValue: number[] = [];
const selectHint = useAppSelector(selectMeHint)?.esSelectHint || "请选择卡片";
const selectHintMsg = useAppSelector(selectHint)?.esSelectHint || "请选择卡片";
// TODO: 这里可以考虑更好地封装
const sendResponseHandler = (
......@@ -57,7 +57,7 @@ const CheckCardModal = () => {
return (
<DragModal
title={`${selectHint} ${min}-${max}`}
title={`${selectHintMsg} ${min}-${max}`}
open={isOpen}
closable={false}
footer={
......
......@@ -20,7 +20,7 @@ import {
} from "../../reducers/duel/mod";
import NeosConfig from "../../../neos.config.json";
import DragModal from "./dragModal";
import { selectMeHint } from "../../reducers/duel/hintSlice";
import { selectHint } from "../../reducers/duel/hintSlice";
const CheckCardModalV2 = () => {
const dispatch = store.dispatch;
......@@ -33,7 +33,7 @@ const CheckCardModalV2 = () => {
);
const selectedOptions = useAppSelector(selectCheckCardModalV2SelectedOptions);
const responseable = useAppSelector(selectCheckCardModalV2ResponseAble);
const selectHint = useAppSelector(selectMeHint)?.esSelectHint || "请选择卡片";
const selectHintMsg = useAppSelector(selectHint)?.esSelectHint || "请选择卡片";
const onFinishOrCancel = () => {
sendSelectUnselectCardResponse({ cancel_or_finish: true });
......@@ -44,7 +44,7 @@ const CheckCardModalV2 = () => {
return (
<DragModal
title={`${selectHint} ${min}-${max}`}
title={`${selectHintMsg} ${min}-${max}`}
open={isOpen}
closable={false}
footer={
......
......@@ -12,7 +12,7 @@ import {
import NeosConfig from "../../../neos.config.json";
import { selectCheckCardModalV3 } from "../../reducers/duel/modal/checkCardModalV3Slice";
import DragModal from "./dragModal";
import { selectMeHint } from "../../reducers/duel/hintSlice";
import { selectHint } from "../../reducers/duel/hintSlice";
const CheckCardModalV3 = () => {
const dispatch = store.dispatch;
......@@ -33,7 +33,7 @@ const CheckCardModalV3 = () => {
.concat(selectedOptions)
.map((option) => option.level2)
.reduce((sum, current) => sum + current, 0);
const selectHint = useAppSelector(selectMeHint)?.esSelectHint || "请选择卡片";
const selectHintMsg = useAppSelector(selectHint)?.esSelectHint || "请选择卡片";
const responseable =
(overflow
......@@ -52,7 +52,7 @@ const CheckCardModalV3 = () => {
return (
<DragModal
title={`${selectHint} ${min}-${max}`}
title={`${selectHintMsg} ${min}-${max}`}
open={isOpen}
closable={false}
footer={
......
import React, { useEffect } from "react";
import { useAppSelector } from "../../hook";
import { selectMeHint, selectOpHint } from "../../reducers/duel/hintSlice";
import { selectHint } from "../../reducers/duel/hintSlice";
import { selectCurrentPhase } from "../../reducers/duel/phaseSlice";
import { notification } from "antd";
import { selectDuelResult, selectWaiting } from "../../reducers/duel/mod";
......@@ -10,8 +10,7 @@ import MsgWin = ygopro.StocGameMessage.MsgWin;
import NeosConfig from "../../../neos.config.json";
const HintNotification = () => {
const meHint = useAppSelector(selectMeHint);
const opHint = useAppSelector(selectOpHint);
const hint = useAppSelector(selectHint);
const currentPhase = useAppSelector(selectCurrentPhase);
const waiting = useAppSelector(selectWaiting);
const result = useAppSelector(selectDuelResult);
......@@ -21,22 +20,13 @@ const HintNotification = () => {
maxCount: NeosConfig.ui.hint.maxCount,
});
useEffect(() => {
if (meHint && meHint.msg) {
if (hint && hint.msg) {
api.info({
message: `<我方>${meHint.msg}`,
placement: "bottom",
});
}
}, [meHint?.msg]);
useEffect(() => {
if (opHint && opHint.msg) {
api.info({
message: `<对方>${opHint.msg}`,
message: `${hint.msg}`,
placement: "top",
});
}
}, [opHint?.msg]);
}, [hint?.msg]);
useEffect(() => {
if (currentPhase) {
......
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