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"; ...@@ -2,9 +2,10 @@ import { createAsyncThunk, ActionReducerMapBuilder } from "@reduxjs/toolkit";
import { DuelState } from "./mod"; import { DuelState } from "./mod";
import { RootState } from "../../store"; import { RootState } from "../../store";
import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "../../api/strings"; import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "../../api/strings";
import { judgeSelf } from "./util"; import { findCardByLocation, judgeSelf } from "./util";
import { fetchCard } from "../../api/cards"; import { fetchCard } from "../../api/cards";
import { DuelReducer } from "./generic"; import { DuelReducer } from "./generic";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
export interface HintState { export interface HintState {
code: number; code: number;
...@@ -23,19 +24,6 @@ export const initHintImpl: DuelReducer<number> = (state, action) => { ...@@ -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( export const fetchCommonHintMeta = createAsyncThunk(
"duel/fetchCommonHintMeta", "duel/fetchCommonHintMeta",
async (param: [number, number]) => { async (param: [number, number]) => {
...@@ -79,6 +67,32 @@ export const fetchSelectHintMeta = createAsyncThunk( ...@@ -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>) => { export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchCommonHintMeta.pending, (state, action) => { builder.addCase(fetchCommonHintMeta.pending, (state, action) => {
const player = action.meta.arg[0]; const player = action.meta.arg[0];
...@@ -125,6 +139,30 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -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; export const selectMeHint = (state: RootState) => state.duel.meHint;
......
...@@ -23,7 +23,7 @@ import { ...@@ -23,7 +23,7 @@ import {
setEnableEpImpl, setEnableEpImpl,
} from "./phaseSlice"; } from "./phaseSlice";
import { RootState } from "../../store"; import { RootState } from "../../store";
import { HintState, hintCase, initHintImpl, setEsHintImpl } from "./hintSlice"; import { HintState, hintCase, initHintImpl } from "./hintSlice";
import { import {
ModalState, ModalState,
setCardModalIsOpenImpl, setCardModalIsOpenImpl,
...@@ -298,7 +298,6 @@ const duelSlice = createSlice({ ...@@ -298,7 +298,6 @@ const duelSlice = createSlice({
// 提示相关`Reducer` // 提示相关`Reducer`
initHint: initHintImpl, initHint: initHintImpl,
setEsHint: setEsHintImpl,
// 通用的`Reducer` // 通用的`Reducer`
clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl, clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl,
...@@ -418,7 +417,6 @@ export const { ...@@ -418,7 +417,6 @@ export const {
setSortCardModalIsOpen, setSortCardModalIsOpen,
resetSortCardModal, resetSortCardModal,
initHint, initHint,
setEsHint,
} = duelSlice.actions; } = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => { export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null; 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