Commit 5c851ecc authored by Chunchi Che's avatar Chunchi Che

Merge branch 'fix/select_yes_no' into 'main'

handle select_yes_no

See merge request !150
parents 7fcc5c00 959654f5
import axios from "axios"; import axios from "axios";
import NeosConfig from "../../neos.config.json"; import NeosConfig from "../../neos.config.json";
import { getCardStr, fetchCard } from "./cards";
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;
...@@ -16,3 +19,14 @@ export async function initStrings() { ...@@ -16,3 +19,14 @@ export async function initStrings() {
export function fetchStrings(region: string, id: number): string { export function fetchStrings(region: string, id: number): string {
return localStorage.getItem(`${region}_${id}`) || ""; return localStorage.getItem(`${region}_${id}`) || "";
} }
export async function getStrings(description: number): Promise<string> {
if (description < DESCRIPTION_LIMIT) {
return fetchStrings("!system", description);
} else {
const code = description >> 4;
const index = description & 0xf;
return getCardStr(await fetchCard(code, true), index) || "";
}
}
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
} from "@reduxjs/toolkit"; } from "@reduxjs/toolkit";
import { CardMeta, fetchCard } from "../../../api/cards"; import { CardMeta, fetchCard } from "../../../api/cards";
import { ygopro } from "../../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../../api/ocgcore/idl/ocgcore";
import { fetchStrings } from "../../../api/strings"; import { fetchStrings, getStrings } from "../../../api/strings";
import { RootState } from "../../../store"; import { RootState } from "../../../store";
import { DuelState } from "../mod"; import { DuelState } from "../mod";
...@@ -39,10 +39,20 @@ export const fetchYesNoMeta = createAsyncThunk( ...@@ -39,10 +39,20 @@ export const fetchYesNoMeta = createAsyncThunk(
} }
); );
export const fetchYesNoMetaWithEffecDesc = createAsyncThunk(
"duel/fetchYesNoMetaWithEffecDesc",
async (effectDesc: number) => {
return getStrings(effectDesc);
}
);
export const YesNoModalCase = (builder: ActionReducerMapBuilder<DuelState>) => { export const YesNoModalCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchYesNoMeta.fulfilled, (state, action) => { builder.addCase(fetchYesNoMeta.fulfilled, (state, action) => {
state.modalState.yesNoModal.msg = action.payload; state.modalState.yesNoModal.msg = action.payload;
}); });
builder.addCase(fetchYesNoMetaWithEffecDesc.fulfilled, (state, action) => {
state.modalState.yesNoModal.msg = action.payload;
});
}; };
export const selectYesNoModalIsOpen = (state: RootState) => export const selectYesNoModalIsOpen = (state: RootState) =>
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { setYesNoModalIsOpen } from "../../reducers/duel/mod";
import { fetchYesNoMetaWithEffecDesc } from "../../reducers/duel/modal/yesNoModalSlice";
import { AppDispatch } from "../../store"; import { AppDispatch } from "../../store";
import MsgSelectYesNo = ygopro.StocGameMessage.MsgSelectYesNo; import MsgSelectYesNo = ygopro.StocGameMessage.MsgSelectYesNo;
...@@ -6,5 +8,6 @@ export default (selectYesNo: MsgSelectYesNo, dispatch: AppDispatch) => { ...@@ -6,5 +8,6 @@ export default (selectYesNo: MsgSelectYesNo, dispatch: AppDispatch) => {
const player = selectYesNo.player; const player = selectYesNo.player;
const effect_description = selectYesNo.effect_description; const effect_description = selectYesNo.effect_description;
console.log(`effect_description: ${effect_description}`); dispatch(fetchYesNoMetaWithEffecDesc(effect_description));
dispatch(setYesNoModalIsOpen(true));
}; };
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