Skip to content

Commit 8d68125

Browse files
committed
fix: fix pause processing for better mobile support
1 parent 3a4c029 commit 8d68125

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

apps/player/src/app/init.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function init(): Promise<void> {
8080
if (toRun) {
8181
goToGame(toRun);
8282
} else {
83-
await processLocationChange(window.location.search, { paused: false });
83+
await processLocationChange(window.location.search);
8484
}
8585
baseInit$.set(true);
8686
}

libs/game-shelf/src/game-shelf.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,27 @@ export const gameSourceMap$ = atom((get) => {
7171
});
7272

7373
history.listen(({ location }) => {
74-
processLocationChange(location.search, location.state as Record<string, unknown> | null);
74+
processLocationChange(location.search);
7575
});
7676

77-
export async function processLocationChange(location: string, state: Record<string, unknown> | null): Promise<void> {
78-
if (state) {
79-
if (state.paused) {
80-
onOpenPauseScreen();
81-
} else {
82-
onClosePauseScreen();
83-
}
84-
}
77+
export async function processLocationChange(location: string): Promise<void> {
8578
const search = new URLSearchParams(location);
8679
const game_id = search.get('run');
8780
if (game_id) {
88-
if (currentGame$.value?.id === game_id) return;
81+
if (currentGame$.value?.id === game_id) {
82+
if (search.has('pause')) {
83+
onOpenPauseScreen();
84+
} else {
85+
onClosePauseScreen();
86+
}
87+
return;
88+
}
8989
await initDeferred$.value.promise;
9090
const descriptor = games$.value[game_id];
9191
await runGame(descriptor);
92+
if (search.has('pause')) {
93+
onOpenPauseScreen();
94+
}
9295
currentMode$.set('game');
9396
} else if (search.has('catalog')) {
9497
if (currentGameEntry$.value) stopCurrentGame();

libs/game-state/src/pause-screen.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,26 @@ export const isPauseScreenVisible$ = atom(false);
77
export const pauseScreenCurrentPanel$ = atom('credits');
88

99
export function openPauseScreen(): void {
10-
history.push(
11-
{
12-
search: history.location.search,
13-
},
14-
{
15-
paused: true,
16-
},
17-
);
10+
const search = new URLSearchParams(history.location.search);
11+
search.set('pause', 'true');
12+
history.push({
13+
search: search.toString(),
14+
});
1815
}
1916

2017
export function onOpenPauseScreen(): void {
2118
isPauseScreenVisible$.set(true);
2219
}
2320

2421
export function closePauseScreen(): void {
25-
history.back();
22+
if (window.history.length > 1) {
23+
return history.back();
24+
}
25+
const search = new URLSearchParams(history.location.search);
26+
search.delete('pause');
27+
history.push({
28+
search: search.toString(),
29+
});
2630
}
2731

2832
export function onClosePauseScreen(): void {

0 commit comments

Comments
 (0)