Commit 9b77151a authored by Chunchi Che's avatar Chunchi Che

udpate fetchSelectHintMeta

parent 7350658f
Pipeline #21069 failed with stages
in 10 minutes and 51 seconds
import { createAsyncThunk, ActionReducerMapBuilder } from "@reduxjs/toolkit"; import { createAsyncThunk, ActionReducerMapBuilder } from "@reduxjs/toolkit";
import { DuelState } from "./mod"; import { DuelState } from "./mod";
import { RootState } from "../../store"; import { RootState } from "../../store";
import { fetchStrings } from "../../api/strings"; import { fetchStrings, getStrings } from "../../api/strings";
import { fetchCard } from "../../api/cards";
import { judgeSelf } from "./util"; import { judgeSelf } from "./util";
export interface HintState { export interface HintState {
code: number; code: number;
msg?: string; msg?: string;
esSelectHint?: string;
} }
export const fetchCommonHintMeta = createAsyncThunk( export const fetchCommonHintMeta = createAsyncThunk(
...@@ -23,13 +23,13 @@ export const fetchCommonHintMeta = createAsyncThunk( ...@@ -23,13 +23,13 @@ export const fetchCommonHintMeta = createAsyncThunk(
} }
); );
export const fetchSelectPlaceHintMeta = createAsyncThunk( export const fetchSelectHintMeta = createAsyncThunk(
"duel/fetchSelectPlaceHintMeta", "duel/fetchSelectPlaceHintMeta",
async (param: [number, number]) => { async (param: [number, number]) => {
const player = param[0]; const player = param[0];
const hintData = param[1]; const hintData = param[1];
const hintMeta = (await fetchCard(hintData, true)).text.name || "[?]"; const hintMeta = await getStrings(hintData);
const response: [number, string] = [player, hintMeta]; const response: [number, string] = [player, hintMeta];
return response; return response;
...@@ -57,7 +57,7 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -57,7 +57,7 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
} }
}); });
builder.addCase(fetchSelectPlaceHintMeta.pending, (state, action) => { builder.addCase(fetchSelectHintMeta.pending, (state, action) => {
const player = action.meta.arg[0]; const player = action.meta.arg[0];
const code = action.meta.arg[1]; const code = action.meta.arg[1];
...@@ -67,18 +67,13 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -67,18 +67,13 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => {
state.opHint = { code }; state.opHint = { code };
} }
}); });
builder.addCase(fetchSelectPlaceHintMeta.fulfilled, (state, action) => { builder.addCase(fetchSelectHintMeta.fulfilled, (state, action) => {
const player = action.payload[0]; const player = action.payload[0];
const hintMeta = action.payload[1]; const hintMsg = action.payload[1];
// TODO: 国际化文案
const hintMsg = judgeSelf(player, state)
? `请为我方的<${hintMeta}>选择位置`
: `请为对方的<${hintMeta}>选择位置`;
const hint = judgeSelf(player, state) ? state.meHint : state.opHint; const hint = judgeSelf(player, state) ? state.meHint : state.opHint;
if (hint) { if (hint) {
hint.msg = hintMsg; hint.esSelectHint = hintMsg;
} }
}); });
}; };
......
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