Skip to content

Commit 2fd0a5f

Browse files
committed
Merge branch 'main' into deploy
2 parents dce1ce9 + 059f390 commit 2fd0a5f

13 files changed

Lines changed: 91 additions & 33 deletions

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
"editor.formatOnSave": true,
2626
"prettier.tabWidth": 2,
2727
},
28+
"[json]": {
29+
"editor.defaultFormatter": "vscode.json-language-features",
30+
"editor.formatOnSave": true
31+
},
2832
"prettier.jsxSingleQuote": true,
2933
"prettier.printWidth": 120,
3034
"prettier.useTabs": false,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"publish": "npm run build && firebase deploy"
1313
},
1414
"dependencies": {
15-
"@drincs/pixi-vn": "^1.3.13",
15+
"@drincs/pixi-vn": "^1.3.19",
1616
"@emotion/react": "^11.14.0",
1717
"@emotion/styled": "^11.14.1",
1818
"@mui/icons-material": "^7.3.1",
@@ -68,4 +68,4 @@
6868
"visual-novel",
6969
"vn"
7070
]
71-
}
71+
}

src/hooks/useKeyboardDetector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useCallback } from "react";
44
import { useTranslation } from "react-i18next";
55
import { useLocation } from "react-router-dom";
66
import useGameSaveScreenStore from "../stores/useGameSaveScreenStore";
7-
import { putSaveIntoIndexDB } from "../utils/save-utility";
7+
import { saveGameToIndexDB } from "../utils/save-utility";
88
import useEventListener from "./useKeyDetector";
99
import useQueryLastSave, { LAST_SAVE_USE_QUEY_KEY } from "./useQueryLastSave";
1010
import { SAVES_USE_QUEY_KEY } from "./useQuerySaves";
@@ -26,7 +26,7 @@ export default function useKeyboardDetector() {
2626
console.log("Can't save on home page");
2727
break;
2828
}
29-
putSaveIntoIndexDB()
29+
saveGameToIndexDB()
3030
.then((save) => {
3131
queryClient.setQueryData([SAVES_USE_QUEY_KEY, save.id], save);
3232
queryClient.setQueryData([LAST_SAVE_USE_QUEY_KEY], save);

src/hooks/useMinigame.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { canvas, Layer, PIXI } from "@drincs/pixi-vn";
1+
import { canvas, Layer } from "@drincs/pixi-vn";
2+
import { Container } from "@drincs/pixi-vn/pixi.js";
23
import { useEffect, useRef } from "react";
34
import { CANVAS_MINIGAME_LAYER_NAME } from "../constans";
45

@@ -27,7 +28,7 @@ export default function useMinigame(
2728
useEffect(() => {
2829
// Create the layer and start the game once
2930
loading.current = true;
30-
const layer = canvas.addLayer(CANVAS_MINIGAME_LAYER_NAME, new PIXI.Container());
31+
const layer = canvas.addLayer(CANVAS_MINIGAME_LAYER_NAME, new Container());
3132
if (!layer) {
3233
console.error("Failed to create UI layer for minigame");
3334
return;

src/i18n.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,32 @@ import Backend from "i18next-chained-backend";
33
import resourcesToBackend from "i18next-resources-to-backend";
44
import { initReactI18next } from "react-i18next";
55

6-
const getUserLang = (): string => {
6+
function getUserLang(): string {
77
let userLang: string = navigator.language || "en";
88
return userLang?.toLocaleLowerCase()?.split("-")[0];
9-
};
9+
}
10+
11+
function getLocalesResource(lng: string): Promise<any> {
12+
return import(`./locales/strings_${lng}.json`);
13+
}
14+
15+
function generateResourceToTranslate(lng: string): Promise<any> {
16+
return getLocalesResource(lng);
17+
}
18+
19+
export async function downloadResourceToTranslate() {
20+
const lng = i18n.options.fallbackLng?.toString() || "en";
21+
const data = await generateResourceToTranslate(lng);
22+
const jsonString = JSON.stringify(data);
23+
// download the save data as a JSON file
24+
const blob = new Blob([jsonString], { type: "application/json" });
25+
// download the file
26+
const url = URL.createObjectURL(blob);
27+
const a = document.createElement("a");
28+
a.href = url;
29+
a.download = `strings_${lng}.json`;
30+
a.click();
31+
}
1032

1133
export const useI18n = () => {
1234
if (!i18n.isInitialized) {
@@ -23,7 +45,7 @@ export const useI18n = () => {
2345
backend: {
2446
backends: [
2547
resourcesToBackend(async (lng: string, ns: string) => {
26-
let object = await import(`./locales/strings_${lng}.json`);
48+
let object = await getLocalesResource(lng);
2749
return object[ns];
2850
}),
2951
],

src/locales/strings_en.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"narration": {},
23
"ui": {
34
"allert_error_occurred": "An error occurred, please report it to the developer",
45
"attention": "Attention",
@@ -54,7 +55,7 @@
5455
"theme_mode_description": "Choose between light, dark, or system theme mode.",
5556
"you_sure_to_delete_save": "Are you sure you want to delete this save file?",
5657
"you_sure_to_load_save": "Are you sure you want to load this save file?",
57-
"you_sure_to_return_main_menu": "Are you sure you want to return to the main menu? All unsaved progress will be lost."
58-
},
59-
"narration": {}
58+
"you_sure_to_return_main_menu": "Are you sure you want to return to the main menu? All unsaved progress will be lost.",
59+
"download_locale": "Download File to Translate"
60+
}
6061
}

src/screens/QuickTools.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import useInterfaceStore from "../stores/useInterfaceStore";
1515
import useSettingsScreenStore from "../stores/useSettingsScreenStore";
1616
import useSkipStore from "../stores/useSkipStore";
1717
import useStepStore from "../stores/useStepStore";
18-
import { putSaveIntoIndexDB } from "../utils/save-utility";
18+
import { saveGameToIndexDB } from "../utils/save-utility";
1919

2020
export default function QuickTools() {
2121
const editOpenSettings = useSettingsScreenStore((state) => state.editOpen);
@@ -93,7 +93,7 @@ export default function QuickTools() {
9393
</TextMenuButton>
9494
<TextMenuButton
9595
onClick={() => {
96-
putSaveIntoIndexDB()
96+
saveGameToIndexDB()
9797
.then((save) => {
9898
queryClient.setQueryData([SAVES_USE_QUEY_KEY, save.id], save);
9999
queryClient.setQueryData([LAST_SAVE_USE_QUEY_KEY], save);

src/screens/Settings.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import useEventListener from "../hooks/useKeyDetector";
1717
import useSettingsScreenStore from "../stores/useSettingsScreenStore";
1818
import AutoSettingToggle from "./settings/AutoSettingToggle";
1919
import DialoguesSettings from "./settings/DialoguesSettings";
20+
import DownloadFileToTranslateSettingButton from "./settings/DownloadFileToTranslateSettingButton";
2021
import FullScreenSettings from "./settings/FullScreenSettings";
2122
import HideInterfaceSettingToggle from "./settings/HideInterfaceSettingToggle";
2223
import OpenHistorySettingButton from "./settings/OpenHistorySettingButton";
@@ -89,6 +90,7 @@ export default function Settings() {
8990
<OpenHistorySettingButton />
9091
<SaveLoadSettingButtons />
9192
<HideInterfaceSettingToggle />
93+
<DownloadFileToTranslateSettingButton />
9294
</Box>
9395
</RadioGroup>
9496
</FormControl>

src/screens/modals/SaveLoadAlert.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { INTERFACE_DATA_USE_QUEY_KEY } from "../../hooks/useQueryInterface";
1010
import { LAST_SAVE_USE_QUEY_KEY } from "../../hooks/useQueryLastSave";
1111
import { SAVES_USE_QUEY_KEY } from "../../hooks/useQuerySaves";
1212
import useGameSaveScreenStore from "../../stores/useGameSaveScreenStore";
13-
import { deleteSaveFromIndexDB, loadSave, putSaveIntoIndexDB } from "../../utils/save-utility";
13+
import { deleteSaveFromIndexDB, loadSave, saveGameToIndexDB } from "../../utils/save-utility";
1414

1515
export default function SaveLoadAlert() {
1616
const navigate = useMyNavigate();
@@ -73,7 +73,7 @@ export default function SaveLoadAlert() {
7373
});
7474
case "save":
7575
case "overwrite_save":
76-
return putSaveIntoIndexDB({ id: alertData.data, name: tempSaveName })
76+
return saveGameToIndexDB({ id: alertData.data, name: tempSaveName })
7777
.then((save) => {
7878
queryClient.setQueryData([SAVES_USE_QUEY_KEY, save.id], save);
7979
queryClient.setQueryData([LAST_SAVE_USE_QUEY_KEY], save);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import TranslateIcon from "@mui/icons-material/Translate";
2+
import { Typography } from "@mui/joy";
3+
import { useState } from "react";
4+
import { useTranslation } from "react-i18next";
5+
import SettingButton from "../../components/SettingButton";
6+
import { downloadResourceToTranslate } from "../../i18n";
7+
8+
export default function DownloadFileToTranslateSettingButton() {
9+
const { t } = useTranslation(["ui"]);
10+
const [loading, setLoading] = useState(false);
11+
12+
// Only show this button in development mode
13+
if (import.meta.env.PROD) {
14+
return null;
15+
}
16+
17+
return (
18+
<SettingButton
19+
key={"download_locale"}
20+
onClick={() => {
21+
setLoading(true);
22+
downloadResourceToTranslate()
23+
.then(() => setLoading(false))
24+
.catch(() => setLoading(false));
25+
}}
26+
disabled={loading}
27+
>
28+
<TranslateIcon />
29+
<Typography level='title-md'>{t("download_locale")}</Typography>
30+
</SettingButton>
31+
);
32+
}

0 commit comments

Comments
 (0)