Commit 359b0289 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/hint' into 'main'

Feat/hint

See merge request mycard/Neos!162
parents 7350658f c39108a1
Pipeline #21084 passed with stages
in 43 minutes and 24 seconds
...@@ -2,7 +2,7 @@ import axios from "axios"; ...@@ -2,7 +2,7 @@ import axios from "axios";
import NeosConfig from "../../neos.config.json"; import NeosConfig from "../../neos.config.json";
import { getCardStr, fetchCard } from "./cards"; import { getCardStr, fetchCard } from "./cards";
const DESCRIPTION_LIMIT = 10000; export const DESCRIPTION_LIMIT = 10000;
export async function initStrings() { export async function initStrings() {
const strings = (await axios.get<string>(NeosConfig.stringsUrl)).data; const strings = (await axios.get<string>(NeosConfig.stringsUrl)).data;
......
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 { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "../../api/strings";
import { fetchCard } from "../../api/cards";
import { judgeSelf } from "./util"; import { judgeSelf } from "./util";
import { fetchCard } from "../../api/cards";
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,15 +24,25 @@ export const fetchCommonHintMeta = createAsyncThunk( ...@@ -23,15 +24,25 @@ export const fetchCommonHintMeta = createAsyncThunk(
} }
); );
export const fetchSelectPlaceHintMeta = createAsyncThunk( export const fetchSelectHintMeta = createAsyncThunk(
"duel/fetchSelectPlaceHintMeta", "duel/fetchSelectHintMeta",
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 || "[?]"; let hintMeta = "";
const response: [number, string] = [player, hintMeta]; if (hintData > DESCRIPTION_LIMIT) {
// 针对`MSG_SELECT_PLACE`的特化逻辑
const cardMeta = await fetchCard(hintData, true);
hintMeta = fetchStrings("!system", 569).replace(
"[%ls]",
cardMeta.text.name || "[?]"
);
} else {
hintMeta = await getStrings(hintData);
}
const response: [number, string] = [player, hintMeta];
return response; return response;
} }
); );
...@@ -57,7 +68,7 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -57,7 +68,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 +78,18 @@ export const hintCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -67,18 +78,18 @@ 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]; let 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; if (hint.code > DESCRIPTION_LIMIT) {
// 针对`MSG_SELECT_PLACE`的特化逻辑
hint.msg = hintMsg;
} else {
hint.esSelectHint = hintMsg;
}
} }
}); });
}; };
......
...@@ -2,7 +2,7 @@ import { ygopro } from "../../api/ocgcore/idl/ocgcore"; ...@@ -2,7 +2,7 @@ import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store"; import { AppDispatch } from "../../store";
import { import {
fetchCommonHintMeta, fetchCommonHintMeta,
fetchSelectPlaceHintMeta, fetchSelectHintMeta,
} from "../../reducers/duel/hintSlice"; } from "../../reducers/duel/hintSlice";
import MsgHint = ygopro.StocGameMessage.MsgHint; import MsgHint = ygopro.StocGameMessage.MsgHint;
...@@ -15,7 +15,7 @@ export default (hint: MsgHint, dispatch: AppDispatch) => { ...@@ -15,7 +15,7 @@ export default (hint: MsgHint, dispatch: AppDispatch) => {
break; break;
} }
case MsgHint.HintType.HINT_SELECTMSG: { case MsgHint.HintType.HINT_SELECTMSG: {
dispatch(fetchSelectPlaceHintMeta([player, hint.hint_data])); dispatch(fetchSelectHintMeta([player, hint.hint_data]));
break; break;
} }
default: { default: {
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { sendSelectChainResponse } from "../../api/ocgcore/ocgHelper"; import { sendSelectChainResponse } from "../../api/ocgcore/ocgHelper";
import { fetchSelectHintMeta } from "../../reducers/duel/hintSlice";
import { import {
setCheckCardMOdalCancelAble, setCheckCardMOdalCancelAble,
setCheckCardModalCancelResponse, setCheckCardModalCancelResponse,
...@@ -83,6 +84,7 @@ export default (selectChain: MsgSelectChain, dispatch: AppDispatch) => { ...@@ -83,6 +84,7 @@ export default (selectChain: MsgSelectChain, dispatch: AppDispatch) => {
}) })
); );
} }
dispatch(fetchSelectHintMeta([player, 203]));
dispatch(setCheckCardModalIsOpen(true)); dispatch(setCheckCardModalIsOpen(true));
......
...@@ -22,6 +22,7 @@ import { ...@@ -22,6 +22,7 @@ import {
import { ThunderboltOutlined } from "@ant-design/icons"; import { ThunderboltOutlined } from "@ant-design/icons";
import NeosConfig from "../../../neos.config.json"; import NeosConfig from "../../../neos.config.json";
import DragModal from "./dragModal"; import DragModal from "./dragModal";
import { selectMeHint } from "../../reducers/duel/hintSlice";
const CheckCardModal = () => { const CheckCardModal = () => {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -33,6 +34,7 @@ const CheckCardModal = () => { ...@@ -33,6 +34,7 @@ const CheckCardModal = () => {
const cancelResponse = useAppSelector(selectCheckCardModalCacnelResponse); const cancelResponse = useAppSelector(selectCheckCardModalCacnelResponse);
const [response, setResponse] = useState<number[]>([]); const [response, setResponse] = useState<number[]>([]);
const defaultValue: number[] = []; const defaultValue: number[] = [];
const selectHint = useAppSelector(selectMeHint)?.esSelectHint || "请选择卡片";
// TODO: 这里可以考虑更好地封装 // TODO: 这里可以考虑更好地封装
const sendResponseHandler = ( const sendResponseHandler = (
...@@ -55,7 +57,7 @@ const CheckCardModal = () => { ...@@ -55,7 +57,7 @@ const CheckCardModal = () => {
return ( return (
<DragModal <DragModal
title={`请选择${min}到${max}张卡片`} title={`${selectHint} ${min}-${max}`}
open={isOpen} open={isOpen}
closable={false} closable={false}
footer={ footer={
......
...@@ -20,6 +20,7 @@ import { ...@@ -20,6 +20,7 @@ import {
} from "../../reducers/duel/mod"; } from "../../reducers/duel/mod";
import NeosConfig from "../../../neos.config.json"; import NeosConfig from "../../../neos.config.json";
import DragModal from "./dragModal"; import DragModal from "./dragModal";
import { selectMeHint } from "../../reducers/duel/hintSlice";
const CheckCardModalV2 = () => { const CheckCardModalV2 = () => {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -32,6 +33,7 @@ const CheckCardModalV2 = () => { ...@@ -32,6 +33,7 @@ const CheckCardModalV2 = () => {
); );
const selectedOptions = useAppSelector(selectCheckCardModalV2SelectedOptions); const selectedOptions = useAppSelector(selectCheckCardModalV2SelectedOptions);
const responseable = useAppSelector(selectCheckCardModalV2ResponseAble); const responseable = useAppSelector(selectCheckCardModalV2ResponseAble);
const selectHint = useAppSelector(selectMeHint)?.esSelectHint || "请选择卡片";
const onFinish = () => { const onFinish = () => {
sendSelectUnselectCardResponse({ cancel_or_finish: true }); sendSelectUnselectCardResponse({ cancel_or_finish: true });
...@@ -46,7 +48,7 @@ const CheckCardModalV2 = () => { ...@@ -46,7 +48,7 @@ const CheckCardModalV2 = () => {
return ( return (
<DragModal <DragModal
title={`请选择未选择的卡片,最少${min}张,最多${max}张`} title={`${selectHint} ${min}-${max}`}
open={isOpen} open={isOpen}
closable={false} closable={false}
footer={ footer={
......
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
import NeosConfig from "../../../neos.config.json"; import NeosConfig from "../../../neos.config.json";
import { selectCheckCardModalV3 } from "../../reducers/duel/modal/checkCardModalV3Slice"; import { selectCheckCardModalV3 } from "../../reducers/duel/modal/checkCardModalV3Slice";
import DragModal from "./dragModal"; import DragModal from "./dragModal";
import { selectMeHint } from "../../reducers/duel/hintSlice";
const CheckCardModalV3 = () => { const CheckCardModalV3 = () => {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -32,6 +33,7 @@ const CheckCardModalV3 = () => { ...@@ -32,6 +33,7 @@ const CheckCardModalV3 = () => {
.concat(selectedOptions) .concat(selectedOptions)
.map((option) => option.level2) .map((option) => option.level2)
.reduce((sum, current) => sum + current, 0); .reduce((sum, current) => sum + current, 0);
const selectHint = useAppSelector(selectMeHint)?.esSelectHint || "请选择卡片";
const responseable = const responseable =
(overflow (overflow
...@@ -50,7 +52,7 @@ const CheckCardModalV3 = () => { ...@@ -50,7 +52,7 @@ const CheckCardModalV3 = () => {
return ( return (
<DragModal <DragModal
title={`请选择卡片,最少${min}张,最多${max}张`} title={`${selectHint} ${min}-${max}`}
open={isOpen} open={isOpen}
closable={false} closable={false}
footer={ footer={
......
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