fail gracefully on bad gameId #150

This commit is contained in:
Jon Eugster
2024-06-11 01:05:43 +02:00
parent 762c1ef0c4
commit 02d0d57453
2 changed files with 10 additions and 5 deletions
+5
View File
@@ -367,6 +367,11 @@ export function ChatPanel ({visible = true}) {
return <div className={`column chat-panel${visible ? '' : ' hidden'}`}>
<div ref={chatRef} className="chat" >
{ gameInfo.error &&
<div className="message error">
Could not find the game!
</div>
}
<Hints hints={introText} counter={readIntro ? undefined : counter}/>
<Hints hints={chatMessages}/>
{/* {proof?.steps.map((step, i) =>
+5 -5
View File
@@ -148,9 +148,9 @@ export const progressSlice = createSlice({
export function selectLevel(game: string, world: string, level: number) {
return (state) => {
if (!state.progress.games[game?.toLowerCase()]) { return initalLevelProgressState }
if (!state.progress.games[game?.toLowerCase()].data[world]) { return initalLevelProgressState }
if (!state.progress.games[game?.toLowerCase()].data[world][level]) { return initalLevelProgressState }
return state.progress.games[game?.toLowerCase()].data[world][level]
if (!state.progress.games[game?.toLowerCase()]?.data[world]) { return initalLevelProgressState }
if (!state.progress.games[game?.toLowerCase()]?.data[world][level]) { return initalLevelProgressState }
return state.progress.games[game?.toLowerCase()]?.data[world][level]
}
}
@@ -165,7 +165,7 @@ export function selectCode(game: string, world: string, level: number) {
export function selectInventory(game: string) {
return (state) => {
if (!state.progress.games[game?.toLowerCase()]) { return [] }
return state.progress.games[game?.toLowerCase()].inventory
return state.progress.games[game?.toLowerCase()]?.inventory
}
}
@@ -208,7 +208,7 @@ export function selectDifficulty(game: string) {
export function selectReadIntro(game: string, worldId: string) {
return (state) => {
if (worldId) {
return state.progress.games[game?.toLowerCase()].data[worldId]?.readIntro
return state.progress.games[game?.toLowerCase()]?.data[worldId]?.readIntro
}
return state.progress.games[game?.toLowerCase()]?.readIntro
}