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