Skip to content

Commit a311e64

Browse files
committed
Merge remote-tracking branch 'origin/main' into dot-font
2 parents dfe01bb + e036c11 commit a311e64

File tree

9 files changed

+150
-179
lines changed

9 files changed

+150
-179
lines changed

routes/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
<a href="/game?stage=8">Stage 8</a>
1414

1515
<p>
16-
<a href="/game?stage=3-1">Stage 3-1</a>
17-
<a href="/game?stage=3-2">Stage 3-2</a>
16+
<a href="/game?stage=3-1">Stage 3-1</a>
17+
<a href="/game?stage=3-2">Stage 3-2</a>
1818
</p>

src/ui-components/Game.svelte

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
<script lang="ts">
2+
// client-only.
3+
24
import { setup } from "@/main.ts";
35
import type { UIInfo } from "@/public-types.ts";
46
import type { StageDefinition } from "@/stages.ts";
57
import Ability from "@/ui-components/Ability.svelte";
68
import Key from "@/ui-components/Key.svelte";
79
import { onDestroy } from "svelte";
8-
import GameOverMenu from "./GameOverMenu.svelte";
9-
import GoalMenu from "./GoalMenu.svelte";
10-
// client-only.
11-
import PauseMenu from "./PauseMenu.svelte";
10+
import GameOverMenu from "./menu/GameOverMenu.svelte";
11+
import GoalMenu from "./menu/GoalMenu.svelte";
12+
import PauseMenu from "./menu/PauseMenu.svelte";
1213
13-
type Props = { stageNum: string; stage: StageDefinition; stageNames: string[] };
14+
type Props = {
15+
stageNum: string;
16+
stage: StageDefinition;
17+
stageNames: string[];
18+
};
1419
const { stageNum, stage, stageNames }: Props = $props();
1520
let container: HTMLElement | null = $state(null);
1621
@@ -40,6 +45,7 @@ const nextStage = $derived(
4045
$effect(() => {
4146
if (container) {
4247
setup(container, stage, bindings);
48+
return () => bindings.destroy();
4349
}
4450
});
4551
@@ -59,14 +65,11 @@ onDestroy(() => bindings.destroy());
5965
/>
6066
<GoalMenu
6167
goaled={uiContext.goaled}
62-
nextStage={nextStage}
68+
{nextStage}
6369
reset={() => bindings.reset()}
6470
/>
65-
<GameOverMenu
66-
gameover={uiContext.gameover}
67-
reset={() => bindings.reset()}
68-
/>
69-
<div
71+
<GameOverMenu gameover={uiContext.gameover} reset={() => bindings.reset()} />
72+
<div
7073
class="uiBackground"
7174
style="position: fixed; left: 0; top: 0; right: 0; display: flex; align-items: end; "
7275
>

src/ui-components/GameOverMenu.svelte

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/ui-components/GoalMenu.svelte

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/ui-components/PauseMenu.svelte

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script lang="ts">
2+
import "./menu.css";
3+
4+
type Props = {
5+
gameover: boolean;
6+
reset: () => void;
7+
};
8+
const { gameover, reset }: Props = $props();
9+
let el: HTMLDialogElement;
10+
$effect(() => {
11+
if (gameover) {
12+
el.showModal();
13+
} else {
14+
if (el.open) el.close();
15+
}
16+
});
17+
document.addEventListener("keydown", (ev) => {
18+
if (ev.key === "Escape") ev.preventDefault();
19+
});
20+
</script>
21+
22+
<dialog bind:this={el} class="modal">
23+
<div class="modal-box flex flex-col gap-1">
24+
<h1 class="text-4xl text-center mt-6 mb-2">Game Over</h1>
25+
<p class="text-xl text-center text-gray-500 mb-4">ctrl+Z で戻る</p>
26+
<button
27+
class="btn modal-btn"
28+
onclick={() => {
29+
el.close();
30+
reset();
31+
}}
32+
>
33+
Restart
34+
</button>
35+
<a class="btn modal-btn" href="/">Back to Stage Select</a>
36+
</div>
37+
</dialog>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<script lang="ts">
2+
import { onDestroy } from "svelte";
3+
import "./menu.css";
4+
import { invalidate } from "$app/navigation";
5+
6+
type Props = {
7+
goaled: boolean;
8+
nextStage: string;
9+
reset: () => void;
10+
};
11+
const { goaled, nextStage, reset }: Props = $props();
12+
let el: HTMLDialogElement;
13+
$effect(() => {
14+
if (goaled) {
15+
el.showModal();
16+
} else {
17+
if (el.open) el.close();
18+
}
19+
});
20+
document.addEventListener("keydown", (ev) => {
21+
if (ev.key === "Escape") ev.preventDefault();
22+
});
23+
24+
const nextStageUrl = $derived(`/game?stage=${nextStage}`);
25+
onDestroy(() => {
26+
invalidate(nextStageUrl);
27+
el.close();
28+
});
29+
</script>
30+
31+
<dialog bind:this={el} class="modal">
32+
<div class="modal-box flex flex-col gap-1">
33+
<h1 class="text-4xl text-center my-6">Goal!</h1>
34+
<a class="btn modal-btn" href={nextStageUrl}> Next Stage </a>
35+
<button
36+
class="btn modal-btn"
37+
onclick={() => {
38+
el.close();
39+
reset();
40+
}}
41+
>
42+
Restart
43+
</button>
44+
<a class="btn modal-btn" href="/">Back to Stage Select</a>
45+
</div>
46+
</dialog>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<script lang="ts">
2+
import "./menu.css";
3+
type Props = {
4+
paused: boolean;
5+
alreadyStopped: boolean;
6+
onresume: () => void;
7+
onpause: () => void;
8+
onreset: () => void;
9+
};
10+
let { paused, alreadyStopped, onresume, onpause, onreset }: Props = $props();
11+
let el: HTMLDialogElement;
12+
$effect(() => {
13+
if (paused && !alreadyStopped) {
14+
el.showModal();
15+
} else {
16+
el.close();
17+
}
18+
});
19+
20+
document.addEventListener("keydown", (ev) => {
21+
if (ev.key === "Escape")
22+
if (!paused && !alreadyStopped) {
23+
onpause();
24+
ev.preventDefault();
25+
}
26+
});
27+
</script>
28+
29+
<dialog bind:this={el} onclose={onresume} class="modal">
30+
<div class="modal-box flex flex-col gap-1">
31+
<h1 class="text-4xl text-center my-6">Paused</h1>
32+
<form method="dialog" class="w-full">
33+
<button class="btn modal-btn" type="submit">Resume</button>
34+
</form>
35+
<button class="btn modal-btn" onclick={() => onreset()}>Restart</button>
36+
<a class="btn modal-btn" href="/"> Back to Stage Select </a>
37+
</div>
38+
</dialog>

src/ui-components/menu/menu.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.modal-btn {
2+
width: 100%;
3+
margin-top: 0.5rem;
4+
font-size: 1.5rem;
5+
padding: 0.5rem;
6+
border-radius: 0.5rem;
7+
}
8+
.modal-box {
9+
background: oklch(82.8% 0.189 84.429 / 40%);
10+
backdrop-filter: blur(2px);
11+
padding: 0.75rem 1rem;
12+
border-radius: 0.5rem;
13+
}

0 commit comments

Comments
 (0)