Commit 4f4677b7 authored by timel's avatar timel

feat: add region enum

parent 0dec9f9e
Pipeline #22920 passed with stages
in 12 minutes and 44 seconds
......@@ -19,13 +19,19 @@ export async function initStrings() {
}
}
export function fetchStrings(region: string, id: string | number): string {
export enum Region {
System = "!system",
Victory = "!victory",
Counter = "!counter",
}
export function fetchStrings(region: Region, id: string | number): string {
return localStorage.getItem(`${region}_${id}`) || "";
}
export async function getStrings(description: number): Promise<string> {
if (description < DESCRIPTION_LIMIT) {
return fetchStrings("!system", description);
return fetchStrings(Region.System, description);
} else {
const code = description >> 4;
const index = description & 0xf;
......
import { fetchCard, fetchStrings, ygopro } from "@/api";
import { fetchCard, fetchStrings, Region, ygopro } from "@/api";
import { displayAnnounceModal } from "@/ui/Duel/Message";
import MsgAnnounce = ygopro.StocGameMessage.MsgAnnounce;
......@@ -16,9 +16,9 @@ export default async (announce: MsgAnnounce) => {
case MsgAnnounce.AnnounceType.RACE: {
await displayAnnounceModal({
min,
title: fetchStrings("!system", 563),
title: fetchStrings(Region.System, 563),
options: announce.options.map((option) => ({
info: fetchStrings("!system", 1200 + option.code),
info: fetchStrings(Region.System, 1200 + option.code),
response: option.response,
})),
});
......@@ -28,9 +28,9 @@ export default async (announce: MsgAnnounce) => {
case MsgAnnounce.AnnounceType.Attribute: {
await displayAnnounceModal({
min,
title: fetchStrings("!system", 562),
title: fetchStrings(Region.System, 562),
options: announce.options.map((option) => ({
info: fetchStrings("!system", 1010 + option.code),
info: fetchStrings(Region.System, 1010 + option.code),
response: option.response,
})),
});
......@@ -50,7 +50,7 @@ export default async (announce: MsgAnnounce) => {
}
await displayAnnounceModal({
min,
title: fetchStrings("!system", 564),
title: fetchStrings(Region.System, 564),
options,
});
......@@ -59,7 +59,7 @@ export default async (announce: MsgAnnounce) => {
case MsgAnnounce.AnnounceType.Number: {
await displayAnnounceModal({
min,
title: fetchStrings("!system", 565),
title: fetchStrings(Region.System, 565),
options: announce.options.map((option) => ({
info: option.code.toString(),
response: option.response,
......
import { fetchStrings, ygopro } from "@/api";
import { fetchStrings, Region, type ygopro } from "@/api";
import { CardMeta, fetchCard } from "@/api/cards";
import { displayYesNoModal } from "@/ui/Duel/Message";
......@@ -19,7 +19,7 @@ export default async (selectEffectYn: MsgSelectEffectYn) => {
) => {
const desc1 = desc.replace(
`[%ls]`,
fetchStrings("!system", cardLocation.zone + 1000)
fetchStrings(Region.System, cardLocation.zone + 1000)
);
const desc2 = desc1.replace(`[%ls]`, cardMeta.text.name || "[?]");
return desc2;
......@@ -31,7 +31,7 @@ export default async (selectEffectYn: MsgSelectEffectYn) => {
// TODO: 国际化文案
const desc = fetchStrings("!system", effect_description);
const desc = fetchStrings(Region.System, effect_description);
const meta = await fetchCard(code);
await displayYesNoModal(textGenerator(desc, meta, location));
};
import { fetchCard, fetchStrings, getCardStr, ygopro } from "@/api";
import MsgSelectOption = ygopro.StocGameMessage.MsgSelectOption;
import {
fetchCard,
fetchStrings,
getCardStr,
Region,
type ygopro,
} from "@/api";
import { displayOptionModal } from "@/ui/Duel/Message";
export default async (selectOption: MsgSelectOption) => {
export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => {
const options = selectOption.options;
await displayOptionModal(
fetchStrings("!system", 556),
fetchStrings(Region.System, 556),
await Promise.all(
options.map(async ({ code, response }) => {
const meta = await fetchCard(code >> 4);
......
import { fetchStrings, ygopro } from "@/api";
import { fetchStrings, Region, ygopro } from "@/api";
import { sleep } from "@/infra";
import { matStore } from "@/stores";
import MsgToss = ygopro.StocGameMessage.MsgToss;
......@@ -7,16 +7,16 @@ export default async (toss: MsgToss) => {
const player = toss.player;
const tossType = toss.toss_type;
const prefix = fetchStrings("!system", matStore.isMe(player) ? 102 : 103);
const prefix = fetchStrings(Region.System, matStore.isMe(player) ? 102 : 103);
for (const x of toss.res) {
if (tossType === MsgToss.TossType.DICE) {
matStore.tossResult = prefix + fetchStrings("!system", 1624) + x;
matStore.tossResult = prefix + fetchStrings(Region.System, 1624) + x;
} else if (tossType === MsgToss.TossType.COIN) {
matStore.tossResult =
prefix +
fetchStrings("!system", 1623) +
fetchStrings("!system", 61 - x);
fetchStrings(Region.System, 1623) +
fetchStrings(Region.System, 61 - x);
} else {
console.log(`Unknown tossType = ${tossType}`);
}
......
import { fetchStrings, ygopro } from "@/api";
import { fetchStrings, Region, ygopro } from "@/api";
import { matStore } from "@/stores";
import { displayEndModal } from "@/ui/Duel/Message";
import MsgWin = ygopro.StocGameMessage.MsgWin;
......@@ -8,6 +8,6 @@ export default async (win: MsgWin) => {
await displayEndModal(
matStore.isMe(win_player),
fetchStrings("!victory", `0x${reason.toString(16)}`)
fetchStrings(Region.Victory, `0x${reason.toString(16)}`)
);
};
import type { ygopro } from "@/api";
import { Region, type ygopro } from "@/api";
import { DESCRIPTION_LIMIT, fetchStrings, getStrings } from "@/api";
import { fetchCard } from "@/api/cards";
import { cardStore } from "@/stores/cardStore";
......@@ -9,7 +9,7 @@ const { hint } = matStore;
export const fetchCommonHintMeta = (code: number) => {
hint.code = code;
hint.msg = fetchStrings("!system", code);
hint.msg = fetchStrings(Region.System, code);
};
export const fetchSelectHintMeta = async ({
......@@ -23,7 +23,7 @@ export const fetchSelectHintMeta = async ({
if (selectHintData > DESCRIPTION_LIMIT) {
// 针对`MSG_SELECT_PLACE`的特化逻辑
const cardMeta = await fetchCard(selectHintData);
selectHintMeta = fetchStrings("!system", 569).replace(
selectHintMeta = fetchStrings(Region.System, 569).replace(
"[%ls]",
cardMeta.text.name || "[?]"
);
......@@ -53,7 +53,7 @@ export const fetchEsHintMeta = async ({
const newOriginMsg =
typeof originMsg === "string"
? originMsg
: fetchStrings("!system", originMsg);
: fetchStrings(Region.System, originMsg);
const cardMeta = cardID ? await fetchCard(cardID) : undefined;
......
......@@ -3,7 +3,7 @@ import { Divider, Drawer, Space, Tag } from "antd";
import React from "react";
import { proxy, useSnapshot } from "valtio";
import { type CardMeta, fetchStrings } from "@/api";
import { type CardMeta, fetchStrings, Region } from "@/api";
import { YgoCard } from "@/ui/Shared";
import {
......@@ -99,13 +99,16 @@ const AttLine = (props: {
attribute?: number;
}) => {
const race = props.race
? fetchStrings("!system", Race2StringCodeMap.get(props.race) || 0)
? fetchStrings(Region.System, Race2StringCodeMap.get(props.race) || 0)
: undefined;
const attribute = props.attribute
? fetchStrings("!system", Attribute2StringCodeMap.get(props.attribute) || 0)
? fetchStrings(
Region.System,
Attribute2StringCodeMap.get(props.attribute) || 0
)
: undefined;
const types = props.types
.map((t) => fetchStrings("!system", Type2StringCodeMap.get(t) || 0))
.map((t) => fetchStrings(Region.System, Type2StringCodeMap.get(t) || 0))
.join("/");
return (
<div className={styles.attline}>
......@@ -135,7 +138,7 @@ const _CounterLine = (props: { counters: { [type: number]: number } }) => {
for (const counterType in props.counters) {
const count = props.counters[counterType];
if (count > 0) {
const counterStr = fetchStrings("!counter", `0x${counterType}`);
const counterStr = fetchStrings(Region.Counter, `0x${counterType}`);
counters.push(`${counterStr}: ${count}`);
}
}
......
......@@ -4,7 +4,7 @@ import { Button, Card, Col, InputNumber, Row } from "antd";
import React, { useState } from "react";
import { proxy, useSnapshot } from "valtio";
import { fetchStrings, sendSelectCounterResponse } from "@/api";
import { fetchStrings, Region, sendSelectCounterResponse } from "@/api";
import { useConfig } from "@/config";
import { NeosModal } from "./NeosModal";
......@@ -33,7 +33,7 @@ export const CheckCounterModal = () => {
const min = snapCheckCounterModal.min || 0;
const options = snapCheckCounterModal.options;
const counterName = fetchStrings(
"!counter",
Region.Counter,
`0x${snapCheckCounterModal.counterType!}`
); // FIXME: 这里转十六进制的逻辑有问题
......
......@@ -2,7 +2,7 @@ import React, { CSSProperties } from "react";
import { useNavigate } from "react-router-dom";
import { proxy, useSnapshot } from "valtio";
import { fetchStrings } from "@/api";
import { fetchStrings, Region } from "@/api";
import { matStore, replayStore, resetUniverse } from "@/stores";
import { NeosModal } from "../NeosModal";
......@@ -34,7 +34,7 @@ export const EndModal: React.FC = () => {
return (
<NeosModal
title={fetchStrings("!system", 1500)}
title={fetchStrings(Region.System, 1500)}
open={isOpen}
onOk={() => {
if (!isReplay) {
......@@ -70,7 +70,7 @@ export const EndModal: React.FC = () => {
{isWin ? "Win" : "Defeated"}
</p>
<p className={styles.reason}>{reason}</p>
{isReplay ? <></> : <p>{fetchStrings("!system", 1340)}</p>}
{isReplay ? <></> : <p>{fetchStrings(Region.System, 1340)}</p>}
</div>
</NeosModal>
);
......
......@@ -2,7 +2,7 @@ import { message, notification } from "antd";
import React, { useEffect } from "react";
import { useSnapshot } from "valtio";
import { fetchStrings } from "@/api";
import { fetchStrings, Region } from "@/api";
import { Phase2StringCodeMap } from "@/common";
import { useConfig } from "@/config";
import { HandResult, matStore } from "@/stores";
......@@ -70,7 +70,7 @@ export const HintNotification = () => {
useEffect(() => {
if (currentPhase) {
const message = fetchStrings(
"!system",
Region.System,
Phase2StringCodeMap.get(currentPhase) ?? 0
);
notify.open({
......@@ -101,7 +101,7 @@ export const showWaiting = (open: boolean) => {
if (!isWaiting) {
globalMsgApi?.open({
type: "loading",
content: fetchStrings("!system", 1390),
content: fetchStrings(Region.System, 1390),
key: waitingKey,
className: styles["message"],
duration: 0,
......
......@@ -7,6 +7,7 @@ import {
type CardMeta,
fetchStrings,
getCardStr,
Region,
sendSelectIdleCmdResponse,
sendSelectOptionResponse,
} from "@/api";
......@@ -90,6 +91,6 @@ export const handleEffectActivation = async (
response: effect.response,
};
});
await displayOptionModal(fetchStrings("!system", 556), options); // 主动发动效果,所以不需要await,但是以后可能要留心
await displayOptionModal(fetchStrings(Region.System, 556), options); // 主动发动效果,所以不需要await,但是以后可能要留心
}
};
......@@ -3,7 +3,7 @@ import { Button, Card, Segmented, Space, Tooltip } from "antd";
import { useEffect, useState } from "react";
import { INTERNAL_Snapshot as Snapshot, useSnapshot } from "valtio";
import type { CardMeta, ygopro } from "@/api";
import { type CardMeta, Region, type ygopro } from "@/api";
import { fetchStrings } from "@/api";
import { CardType, matStore } from "@/stores";
import { YgoCard } from "@/ui/Shared";
......@@ -81,7 +81,7 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
const zoneOptions = grouped.map((x) => ({
value: x[0],
label: fetchStrings("!system", x[0] + 1000),
label: fetchStrings(Region.System, x[0] + 1000),
}));
const [selectedZone, setSelectedZone] = useState(zoneOptions[0]?.value);
......@@ -91,7 +91,7 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
}, [selectables]);
const [submitText, finishText, cancelText] = [1211, 1296, 1295].map((n) =>
fetchStrings("!system", n)
fetchStrings(Region.System, n)
);
return (
......@@ -172,7 +172,7 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
<p>
<span>
{/* TODO: 这里的字体可以调整下 */}
{selecteds.length > 0 ? fetchStrings("!system", 212) : ""}
{selecteds.length > 0 ? fetchStrings(Region.System, 212) : ""}
</span>
</p>
<div className={styles["check-group"]}>
......
......@@ -4,7 +4,7 @@ import classnames from "classnames";
import React, { type CSSProperties, useEffect, useRef, useState } from "react";
import { useSnapshot } from "valtio";
import type { CardMeta } from "@/api";
import { type CardMeta, Region } from "@/api";
import {
fetchStrings,
getCardStr,
......@@ -353,7 +353,7 @@ const handleEffectActivation = (
response: effect.response,
};
});
displayOptionModal(fetchStrings("!system", 556), options); // 主动发动效果,所以不需要await,但是以后可能要留心
displayOptionModal(fetchStrings(Region.System, 556), options); // 主动发动效果,所以不需要await,但是以后可能要留心
}
};
......
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