Skip to content

Commit

Permalink
Merge branch 'main' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackRam-oss committed Oct 14, 2024
2 parents 7c3b007 + b8496c3 commit 1212733
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
4 changes: 0 additions & 4 deletions src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { Route, Routes } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';
import { nextStepLoadingState } from './atoms/nextStepLoadingState';
import SkipAutoInterceptor from './interceptors/SkipAutoInterceptor';
import GameSaveScreen from './screens/GameSaveScreen';
import HistoryScreen from './screens/HistoryScreen';
import LoadingScreen from './screens/LoadingScreen';
import MainMenu from './screens/MainMenu';
import SaveLoadAlert from './screens/modals/SaveLoadAlert';
import TextInput from './screens/modals/TextInput';
import NarrationScreen from './screens/NarrationScreen';
import QuickTools from './screens/QuickTools';
Expand Down Expand Up @@ -50,8 +48,6 @@ export default function AppRoutes() {
<Route key={"narration"} path={"/narration"}
element={<>
<HistoryScreen />
<GameSaveScreen />
<SaveLoadAlert />
<QuickTools />
<NarrationScreen
nextOnClick={nextOnClick}
Expand Down
4 changes: 4 additions & 0 deletions src/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import Routes from './AppRoutes';
import ApImports from './Imports';
import EventInterceptor from './interceptors/EventInterceptor';
import GameSaveScreen from './screens/GameSaveScreen';
import SaveLoadAlert from './screens/modals/SaveLoadAlert';
import Settings from './screens/Settings';

export default function Home() {
return (
<ApImports>
<Routes />
<Settings />
<GameSaveScreen />
<SaveLoadAlert />
<EventInterceptor />
</ApImports>
)
Expand Down
5 changes: 5 additions & 0 deletions src/screens/GameSaveScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Pagination, Tooltip, useMediaQuery } from '@mui/material';
import { useQueryClient } from '@tanstack/react-query';
import { useSnackbar } from 'notistack';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import { useRecoilState, useSetRecoilState } from 'recoil';
import { openGameSaveScreenState } from '../atoms/openGameSaveScreenState';
import { saveLoadAlertState } from '../atoms/saveLoadAlertState';
Expand All @@ -29,6 +30,7 @@ export default function GameSaveScreen() {
const navigate = useMyNavigate();
const { enqueueSnackbar } = useSnackbar();
const queryClient = useQueryClient()
let location = useLocation();

return (
<ModalDialogCustom
Expand Down Expand Up @@ -68,6 +70,7 @@ export default function GameSaveScreen() {
<IconButton
size="lg"
onClick={() => { downloadGameSave() }}
disabled={location.pathname == "/"}
>
<DownloadIcon fontSize="large" />
</IconButton>
Expand Down Expand Up @@ -131,6 +134,7 @@ function GameSaveSlot({ saveId, onDelete, onLoad, onOverwriteSave, onSave }: {
data: saveData,
isError,
} = useQuerySaves({ id: saveId })
let location = useLocation();

if (isLoading) {
return (
Expand Down Expand Up @@ -160,6 +164,7 @@ function GameSaveSlot({ saveId, onDelete, onLoad, onOverwriteSave, onSave }: {
width: "100%",
}}
onClick={onSave}
disabled={location.pathname == "/"}
>
<SaveAsIcon sx={{ fontSize: '3rem', opacity: 0.2 }} />
</IconButton>
Expand Down
36 changes: 28 additions & 8 deletions src/screens/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useSetRecoilState } from 'recoil';
import { hideInterfaceState } from '../atoms/hideInterfaceState';
import { openGameSaveScreenState } from '../atoms/openGameSaveScreenState';
import { openSettingsState } from '../atoms/openSettingsState';
import MenuButton from '../components/MenuButton';
import { INTERFACE_DATA_USE_QUEY_KEY } from '../use_query/useQueryInterface';
import useQueryLastSave from '../use_query/useQueryLastSave';
import { useMyNavigate } from '../utilities/navigate-utility';
import { loadGameSaveFromFile } from '../utilities/save-utility';
import { loadSave } from '../utilities/save-utility';

export default function MainMenu() {
const navigate = useMyNavigate();
const setOpenSettings = useSetRecoilState(openSettingsState);
const setHideInterface = useSetRecoilState(hideInterfaceState);
const setGameSaveScreen = useSetRecoilState(openGameSaveScreenState);
const { enqueueSnackbar } = useSnackbar();
const { t } = useTranslation(["interface"]);
const { t: tNarration } = useTranslation(["narration"]);
const queryClient = useQueryClient()
const { data: lastSave = null, isLoading } = useQueryLastSave()

useEffect(() => {
setHideInterface(false)
Expand All @@ -45,6 +49,24 @@ export default function MainMenu() {
animate={"open"}
exit="closed"
>
<MenuButton
onClick={() => {
if (!lastSave) {
return
}
loadSave(lastSave, navigate)
.then(() => queryClient.invalidateQueries({ queryKey: [INTERFACE_DATA_USE_QUEY_KEY] }))
.catch((e) => {
enqueueSnackbar(t("fail_load"), { variant: 'error' })
console.error(e)
})
}}
transitionDelay={0.1}
loading={isLoading}
disabled={!isLoading && !lastSave}
>
{t("continue")}
</MenuButton>
<MenuButton
onClick={() => {
canvas.removeAll()
Expand All @@ -55,21 +77,19 @@ export default function MainMenu() {
notify: (message, variant) => enqueueSnackbar(message, { variant }),
}).then(() => queryClient.invalidateQueries({ queryKey: [INTERFACE_DATA_USE_QUEY_KEY] }))
}}
transitionDelay={0.1}
transitionDelay={0.2}
>
{t("start")}
</MenuButton>
<MenuButton
onClick={() => {
loadGameSaveFromFile(navigate, () => queryClient.invalidateQueries({ queryKey: [INTERFACE_DATA_USE_QUEY_KEY] }))
}}
transitionDelay={0.2}
onClick={() => setGameSaveScreen(true)}
transitionDelay={0.3}
>
{t("load")}
</MenuButton>
<MenuButton
onClick={() => { setOpenSettings(true) }}
transitionDelay={0.3}
onClick={() => setOpenSettings(true)}
transitionDelay={0.4}
>
{t("settings")}
</MenuButton>
Expand Down
9 changes: 6 additions & 3 deletions src/screens/modals/SaveLoadAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ export default function SaveLoadAlert() {
openGameSaveScreen(false)
return true
})
.catch(() => {
.catch((e) => {
enqueueSnackbar(t("fail_load"), { variant: 'error' })
console.error(e)
return false
})
case "delete":
Expand All @@ -98,8 +99,9 @@ export default function SaveLoadAlert() {
enqueueSnackbar(t("success_delete"), { variant: 'success' })
return true
})
.catch(() => {
.catch((e) => {
enqueueSnackbar(t("fail_delete"), { variant: 'error' })
console.error(e)
return false
})
case "save":
Expand All @@ -111,8 +113,9 @@ export default function SaveLoadAlert() {
enqueueSnackbar(t("success_save"), { variant: 'success' })
return true
})
.catch(() => {
.catch((e) => {
enqueueSnackbar(t("fail_save"), { variant: 'error' })
console.error(e)
return false
})
}
Expand Down
1 change: 1 addition & 0 deletions src/values/translations/strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"back": "Back",
"cancel": "Cancel",
"confirm": "Confirm",
"continue": "Continue",
"delete": "Delete",
"dialogues": "Dialogues",
"display": "Display",
Expand Down

0 comments on commit 1212733

Please sign in to comment.