|
|
@ -1,5 +1,5 @@
|
|
|
|
import * as React from 'react';
|
|
|
|
import * as React from 'react';
|
|
|
|
import { Outlet, useParams } from "react-router-dom";
|
|
|
|
import { Outlet, useParams, useSearchParams } from "react-router-dom";
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
|
|
|
|
|
|
|
import '@fontsource/roboto/300.css';
|
|
|
|
import '@fontsource/roboto/300.css';
|
|
|
@ -11,13 +11,14 @@ import './css/reset.css';
|
|
|
|
import './css/app.css';
|
|
|
|
import './css/app.css';
|
|
|
|
import { PageContext, PreferencesContext} from './components/infoview/context';
|
|
|
|
import { PageContext, PreferencesContext} from './components/infoview/context';
|
|
|
|
import UsePreferences from "./state/hooks/use_preferences"
|
|
|
|
import UsePreferences from "./state/hooks/use_preferences"
|
|
|
|
import i18n from './i18n';
|
|
|
|
|
|
|
|
import { Navigation } from './components/navigation';
|
|
|
|
import { Navigation } from './components/navigation';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { changeTypewriterMode, selectOpenedIntro, selectTypewriterMode } from './state/progress';
|
|
|
|
import { changeTypewriterMode, selectOpenedIntro, selectTypewriterMode } from './state/progress';
|
|
|
|
import { useAppDispatch } from './hooks';
|
|
|
|
import { useAppDispatch } from './hooks';
|
|
|
|
import { Popup, PopupContext } from './components/popup/popup';
|
|
|
|
import { Popup, PopupContext } from './components/popup/popup';
|
|
|
|
import { useGetGameInfoQuery } from './state/api';
|
|
|
|
import { useGetGameInfoQuery } from './state/api';
|
|
|
|
|
|
|
|
import lean4gameConfig from './config.json'
|
|
|
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
|
|
|
|
export const GameIdContext = React.createContext<{
|
|
|
|
export const GameIdContext = React.createContext<{
|
|
|
|
gameId: string,
|
|
|
|
gameId: string,
|
|
|
@ -25,6 +26,7 @@ export const GameIdContext = React.createContext<{
|
|
|
|
levelId: number|null}>({gameId: null, worldId: null, levelId: null});
|
|
|
|
levelId: number|null}>({gameId: null, worldId: null, levelId: null});
|
|
|
|
|
|
|
|
|
|
|
|
function App() {
|
|
|
|
function App() {
|
|
|
|
|
|
|
|
let { t, i18n } = useTranslation()
|
|
|
|
|
|
|
|
|
|
|
|
const params = useParams()
|
|
|
|
const params = useParams()
|
|
|
|
const gameId = (params.owner && params.repo) ? "g/" + params.owner + "/" + params.repo : null
|
|
|
|
const gameId = (params.owner && params.repo) ? "g/" + params.owner + "/" + params.repo : null
|
|
|
@ -41,16 +43,39 @@ function App() {
|
|
|
|
const [page, setPage] = useState(0)
|
|
|
|
const [page, setPage] = useState(0)
|
|
|
|
const [popupContent, setPopupContent] = useState(null)
|
|
|
|
const [popupContent, setPopupContent] = useState(null)
|
|
|
|
const gameInfo = useGetGameInfoQuery({game: gameId})
|
|
|
|
const gameInfo = useGetGameInfoQuery({game: gameId})
|
|
|
|
|
|
|
|
const [searchParams, setSearchParams] = useSearchParams()
|
|
|
|
|
|
|
|
|
|
|
|
const openedIntro = useSelector(selectOpenedIntro(gameId))
|
|
|
|
const openedIntro = useSelector(selectOpenedIntro(gameId))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// mobile only: game intro should only be shown once and skipped afterwards
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (openedIntro && !worldId && page == 0) {
|
|
|
|
if (openedIntro && !worldId && page == 0) {
|
|
|
|
setPage(1)
|
|
|
|
setPage(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [openedIntro])
|
|
|
|
}, [openedIntro])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// option to pass language as `?lang=de` in the URL
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
let urlLang = searchParams.get("lang")
|
|
|
|
|
|
|
|
let availableLangs = gameInfo.data?.tile?.languages
|
|
|
|
|
|
|
|
if (gameId) {
|
|
|
|
|
|
|
|
if (availableLangs?.includes(urlLang)) {
|
|
|
|
|
|
|
|
setLanguage(urlLang)
|
|
|
|
|
|
|
|
// Delete the search param as we processed it.
|
|
|
|
|
|
|
|
searchParams.delete('lang')
|
|
|
|
|
|
|
|
setSearchParams(searchParams)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (urlLang in lean4gameConfig.newLanguages) {
|
|
|
|
|
|
|
|
setLanguage(urlLang)
|
|
|
|
|
|
|
|
// Delete the search param as we processed it.
|
|
|
|
|
|
|
|
searchParams.delete('lang')
|
|
|
|
|
|
|
|
setSearchParams(searchParams)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, [gameId, gameInfo.data?.tile?.languages])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set the correct language
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
let availableLangs = gameInfo.data?.tile?.languages
|
|
|
|
let availableLangs = gameInfo.data?.tile?.languages
|
|
|
|
if (gameId && availableLangs?.length > 0 && !(availableLangs.includes(language))) {
|
|
|
|
if (gameId && availableLangs?.length > 0 && !(availableLangs.includes(language))) {
|
|
|
|