Commit a6668f06 authored by Chunchi Che's avatar Chunchi Che

update hint

parent 359b0289
Pipeline #21094 failed with stages
in 2 minutes and 35 seconds
......@@ -4,13 +4,38 @@ import { RootState } from "../../store";
import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "../../api/strings";
import { judgeSelf } from "./util";
import { fetchCard } from "../../api/cards";
import { DuelReducer } from "./generic";
export interface HintState {
code: number;
msg?: string;
esHint?: string;
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 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]) => {
......@@ -26,24 +51,31 @@ export const fetchCommonHintMeta = createAsyncThunk(
export const fetchSelectHintMeta = createAsyncThunk(
"duel/fetchSelectHintMeta",
async (param: [number, number]) => {
const player = param[0];
const hintData = param[1];
async (param: {
player: number;
selectHintData: number;
esHint?: string;
}) => {
const player = param.player;
const selectHintData = param.selectHintData;
let hintMeta = "";
if (hintData > DESCRIPTION_LIMIT) {
let selectHintMeta = "";
if (selectHintData > DESCRIPTION_LIMIT) {
// 针对`MSG_SELECT_PLACE`的特化逻辑
const cardMeta = await fetchCard(hintData, true);
hintMeta = fetchStrings("!system", 569).replace(
const cardMeta = await fetchCard(selectHintData, true);
selectHintMeta = fetchStrings("!system", 569).replace(
"[%ls]",
cardMeta.text.name || "[?]"
);
} else {
hintMeta = await getStrings(hintData);
selectHintMeta = await getStrings(selectHintData);
}
const response: [number, string] = [player, hintMeta];
return response;
return {
player,
selectHintMeta,
esHint: param.esHint,
};
}
);
......@@ -69,26 +101,27 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
});
builder.addCase(fetchSelectHintMeta.pending, (state, action) => {
const player = action.meta.arg[0];
const code = action.meta.arg[1];
const player = action.meta.arg.player;
const code = action.meta.arg.selectHintData;
if (judgeSelf(player, state)) {
state.meHint = { code };
} else {
state.opHint = { code };
const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
if (hint) {
hint.code = code;
}
});
builder.addCase(fetchSelectHintMeta.fulfilled, (state, action) => {
const player = action.payload[0];
let hintMsg = action.payload[1];
const player = action.payload.player;
const selectHintMsg = action.payload.selectHintMeta;
const esHint = action.payload.esHint;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
if (hint) {
if (hint.code > DESCRIPTION_LIMIT) {
// 针对`MSG_SELECT_PLACE`的特化逻辑
hint.msg = hintMsg;
hint.msg = selectHintMsg;
} else {
hint.esSelectHint = hintMsg;
hint.esSelectHint = selectHintMsg;
if (esHint) hint.esHint = esHint;
}
}
});
......
......@@ -23,7 +23,7 @@ import {
setEnableEpImpl,
} from "./phaseSlice";
import { RootState } from "../../store";
import { HintState, hintCase } from "./hintSlice";
import { HintState, hintCase, initHintImpl, setEsHintImpl } from "./hintSlice";
import {
ModalState,
setCardModalIsOpenImpl,
......@@ -296,6 +296,10 @@ const duelSlice = createSlice({
setSortCardModalIsOpen: setSortCardModalIsOpenImpl,
resetSortCardModal: resetSortCardModalImpl,
// 提示相关`Reducer`
initHint: initHintImpl,
setEsHint: setEsHintImpl,
// 通用的`Reducer`
clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl,
clearAllPlaceInteractivities: clearAllPlaceInteractivitiesImpl,
......@@ -413,6 +417,8 @@ export const {
clearCheckCounter,
setSortCardModalIsOpen,
resetSortCardModal,
initHint,
setEsHint,
} = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null;
......
......@@ -15,7 +15,7 @@ export default (hint: MsgHint, dispatch: AppDispatch) => {
break;
}
case MsgHint.HintType.HINT_SELECTMSG: {
dispatch(fetchSelectHintMeta([player, hint.hint_data]));
dispatch(fetchSelectHintMeta({ player, selectHintData: hint.hint_data }));
break;
}
default: {
......
......@@ -84,7 +84,12 @@ export default (selectChain: MsgSelectChain, dispatch: AppDispatch) => {
})
);
}
dispatch(fetchSelectHintMeta([player, 203]));
dispatch(
fetchSelectHintMeta({
player,
selectHintData: 203,
})
);
dispatch(setCheckCardModalIsOpen(true));
......
......@@ -8,6 +8,7 @@ import {
initCemetery,
initDeck,
initExclusion,
initHint,
} from "../../reducers/duel/mod";
export default (
......@@ -45,4 +46,6 @@ export default (
dispatch(initDeck({ player: 1, deskSize: start.deckSize2 }));
dispatch(initExclusion(0));
dispatch(initExclusion(1));
dispatch(initHint(0));
dispatch(initHint(1));
};
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