Commit c3751b96 authored by Chunchi Che's avatar Chunchi Che

udpate hintSlice

parent 0ac4295b
Pipeline #21102 failed with stages
in 3 minutes and 16 seconds
......@@ -2,9 +2,10 @@ import { createAsyncThunk, ActionReducerMapBuilder } from "@reduxjs/toolkit";
import { DuelState } from "./mod";
import { RootState } from "../../store";
import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "../../api/strings";
import { judgeSelf } from "./util";
import { findCardByLocation, judgeSelf } from "./util";
import { fetchCard } from "../../api/cards";
import { DuelReducer } from "./generic";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
export interface HintState {
code: number;
......@@ -23,19 +24,6 @@ export const initHintImpl: DuelReducer<number> = (state, action) => {
}
};
export const setEsHintImpl: DuelReducer<{ player: number; esHint: string }> = (
state,
action
) => {
const player = action.payload.player;
const esHint = action.payload.esHint;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
if (hint) {
hint.esHint = esHint;
}
};
export const fetchCommonHintMeta = createAsyncThunk(
"duel/fetchCommonHintMeta",
async (param: [number, number]) => {
......@@ -79,6 +67,32 @@ 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
: fetchStrings("!system", param.originMsg);
const location = param.location;
if (param.cardID) {
const cardMeta = await fetchCard(param.cardID);
return { player, originMsg, cardMeta, location };
} else {
return { player, originMsg, location };
}
}
);
export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchCommonHintMeta.pending, (state, action) => {
const player = action.meta.arg[0];
......@@ -125,6 +139,30 @@ 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;
if (hint) {
let esHint = originMsg;
if (cardMeta?.text.name) {
esHint = originMsg.replace("[?]", cardMeta.text.name);
}
if (location) {
const fieldMeta = findCardByLocation(state, location);
if (fieldMeta?.occupant?.text.name) {
esHint = originMsg.replace("[?]", fieldMeta.occupant.text.name);
}
}
hint.esHint = esHint;
}
});
};
export const selectMeHint = (state: RootState) => state.duel.meHint;
......
......@@ -23,7 +23,7 @@ import {
setEnableEpImpl,
} from "./phaseSlice";
import { RootState } from "../../store";
import { HintState, hintCase, initHintImpl, setEsHintImpl } from "./hintSlice";
import { HintState, hintCase, initHintImpl } from "./hintSlice";
import {
ModalState,
setCardModalIsOpenImpl,
......@@ -298,7 +298,6 @@ const duelSlice = createSlice({
// 提示相关`Reducer`
initHint: initHintImpl,
setEsHint: setEsHintImpl,
// 通用的`Reducer`
clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl,
......@@ -418,7 +417,6 @@ export const {
setSortCardModalIsOpen,
resetSortCardModal,
initHint,
setEsHint,
} = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null;
......
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