Commit 4bb4fe41 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/deprecate/neos-rs' into 'main'

Feat/deprecate/neos rs

See merge request mycard/Neos!96
parents eb9ace2e 40cc2454
Pipeline #19942 passed with stages
in 5 minutes and 28 seconds
import axios from "axios";
export async function initStrings() {
const strings = (
await axios.get<string>(`ygopro-database/locales/zh-CN/strings.conf`)
).data;
const lineIter = strings.split("\n");
for (const line of lineIter) {
if (!line.startsWith("#") && line !== "") {
let [region, code, value] = line.split(" ", 3);
localStorage.setItem(`${region}_${code}`, value);
}
}
}
export async function fetchStrings(
region: string,
id: number
id: number,
local?: boolean
): Promise<string> {
if (local) {
return localStorage.getItem(`${region}_${id}`) || "";
}
return (
await axios.get<string>(`http://localhost:3030/strings/${region}_${id}`)
).data;
......
......@@ -16,7 +16,7 @@ export const fetchCommonHintMeta = createAsyncThunk(
const player = param[0];
const hintData = param[1];
const hintMeta = await fetchStrings("!system", hintData);
const hintMeta = await fetchStrings("!system", hintData, true);
const response: [number, string] = [player, hintMeta];
return response;
......
......@@ -31,7 +31,7 @@ export const fetchYesNoMeta = createAsyncThunk(
cardLocation: ygopro.CardLocation
) => string;
}) => {
const desc = await fetchStrings("!system", param.descCode);
const desc = await fetchStrings("!system", param.descCode, true);
const meta = await fetchCard(param.code, true);
// TODO: 国际化文案
......
import React from "react";
import React, { useEffect, useRef } from "react";
import { Engine, Scene } from "react-babylonjs";
import { ReactReduxContext, Provider } from "react-redux";
import * as BABYLON from "@babylonjs/core";
......@@ -20,9 +20,26 @@ import OptionModal from "./optionModal";
import Phase from "./phase";
import CheckCardModalV2 from "./checkCardModalV2";
import ExtraDeck from "./extraDeck";
import { initStrings } from "../../api/strings";
// Ref: https://github.com/brianzinn/react-babylonjs/issues/126
const NeosDuel = () => (
const NeosDuel = () => {
// 应该用更优雅的方式处理`useEffect`执行两次的问题
const initialRender = useRef(true);
useEffect(() => {
const init = async () => {
await initStrings();
};
if (initialRender.current) {
initialRender.current = false;
return;
}
init();
}, []);
return (
<>
<ReactReduxContext.Consumer>
{({ store }) => (
......@@ -56,7 +73,8 @@ const NeosDuel = () => (
<OptionModal />
<CheckCardModalV2 />
</>
);
);
};
const Camera = () => (
<freeCamera
......
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