This repository has been archived on 2021-11-08. You can view files and clone it, but cannot push or open issues or pull requests.
svelte-sharg/src/App.svelte

48 lines
1.3 KiB
Svelte
Raw Normal View History

2021-09-26 16:04:20 +02:00
<script lang="ts">
import Footer from "./components/Footer.svelte";
2021-09-26 21:02:02 +02:00
import Header from "./components/Header.svelte";
import Wrapper from "./components/Wrapper.svelte";
import { SharkGame } from "./shark/SharkGame";
2021-10-02 20:56:40 +02:00
import { Modals, closeAllModals } from "svelte-modals";
2021-09-29 22:49:39 +02:00
import { onDestroy, onMount } from "svelte";
import type { Unsubscriber } from "svelte/store";
let root: HTMLElement;
let unsubscribeSettings: Unsubscriber;
onMount(() => {
root = document.documentElement;
2021-09-30 13:49:00 +02:00
SharkGame.Settings.settings.subscribe((settings) => {
2021-09-30 21:26:11 +02:00
root.classList.toggle("no-theme", !settings.appearance.enableThemes.current);
2021-09-30 11:10:48 +02:00
settings.appearance.theme.options.forEach((theme) => {
2021-09-30 21:26:11 +02:00
root.classList.toggle(theme, theme === settings.appearance.theme.current);
2021-09-29 22:49:39 +02:00
});
});
});
onDestroy(() => {
unsubscribeSettings();
});
function handleKeyUp(event: KeyboardEvent) {
if (event.key === "Escape") {
2021-10-02 20:56:40 +02:00
closeAllModals();
2021-09-29 22:49:39 +02:00
}
}
2021-09-26 16:04:20 +02:00
</script>
2021-09-29 22:49:39 +02:00
<svelte:body on:keyup={handleKeyUp} />
<Modals>
2021-10-02 20:56:40 +02:00
<div slot="backdrop" id="modal-backdrop" on:click={closeAllModals} />
2021-09-29 22:49:39 +02:00
</Modals>
2021-10-02 20:12:21 +02:00
{#await SharkGame.initialize()}
Loading...
{:then}
<Header game={SharkGame} title={SharkGame.title} />
<Wrapper game={SharkGame} />
<Footer />
{/await}