Better settings

This commit is contained in:
Tobias Berger 2021-09-30 11:10:48 +02:00
parent 7b4be2f1e2
commit 126f918082
7 changed files with 224 additions and 95 deletions

View file

@ -37,12 +37,18 @@
root = document.documentElement; root = document.documentElement;
SharkGame.Settings.subscribe((settings) => { SharkGame.Settings.subscribe((settings) => {
root.classList.toggle("no-theme", !settings.enableThemes.current); root.classList.toggle(
settings.theme.options.forEach((theme) => { "no-theme",
root.classList.toggle(theme, theme === settings.theme.current); !settings.appearance.enableThemes.current
);
settings.appearance.theme.options.forEach((theme) => {
root.classList.toggle(
theme,
theme === settings.appearance.theme.current
);
}); });
if (settings.updateCheck.current && updateInterval === undefined) { if (settings.other.updateCheck.current && updateInterval === undefined) {
updateInterval = setInterval(async () => { updateInterval = setInterval(async () => {
if ( if (
CURRENT_HASH !== undefined && CURRENT_HASH !== undefined &&
@ -52,7 +58,7 @@
} }
}, 6 * 60 * 1000); }, 6 * 60 * 1000);
} else if ( } else if (
!settings.updateCheck.current && !settings.other.updateCheck.current &&
updateInterval !== undefined updateInterval !== undefined
) { ) {
clearInterval(updateInterval); clearInterval(updateInterval);

View file

@ -53,6 +53,11 @@
padding: 16px; padding: 16px;
background: var(--color-darker); background: var(--color-darker);
pointer-events: auto; pointer-events: auto;
max-width: 80%;
max-height: 80%;
overflow-y: auto;
} }
} }
</style> </style>

View file

@ -1,75 +1,82 @@
<script lang="ts"> <script lang="ts">
import type { Writable } from "svelte/store";
import type { Settings } from "../../shark/Settings"; import type { Settings } from "../../shark/Settings";
import BaseModal from "./BaseModal.svelte"; import BaseModal from "./BaseModal.svelte";
export let isOpen: boolean; export let isOpen: boolean;
type SettingsUnkownOptions = typeof Settings extends Writable<infer X>
? Writable<
Record<
keyof X,
Omit<X[keyof X], "options" | "current"> & {
current: unknown;
options: readonly unknown[];
}
>
>
: never;
export let settings: typeof Settings; export let settings: typeof Settings;
$: usableSettings = settings as SettingsUnkownOptions;
</script> </script>
<BaseModal {isOpen}> <BaseModal {isOpen}>
<table id="settings-modal"> <div id="settings-modal">
<colgroup> {#each Object.entries($settings) as [categoryName, categorySettings]}
<col style="text-align: left;" /> <h4>{categoryName.toUpperCase()}</h4>
<col /> <div class="settings-category" id={`settings-category-${categoryName}`}>
</colgroup> {#each Object.entries(categorySettings) as [settingId, setting] (settingId)}
<tbody> <div
{#each Object.entries($usableSettings) as [settingName, setting] (settingName)} class="settings-row"
<tr> id={`settings-row-${categoryName}-${settingId}`}
<td> >
{setting.name}<br /> <div
<span class="setting-description">({setting.description}) </span> class="settings-description"
</td> id={`settings-description-${categoryName}-${settingId}`}
{#each setting.options as option} >
<td {setting.name}<br />
><button <span class="settings-small-description"
>({setting.description})</span
>
</div>
{#each setting.options as option}<button
disabled={setting.current === option} disabled={setting.current === option}
on:click={() => { on:click={() => {
setting.current = option; setting.current = option;
}}>{option}</button }}>{option}</button
></td >
> {/each}
{/each} </div>
</tr> {/each}
{/each}</tbody </div>
> {/each}
</table> </div>
</BaseModal> </BaseModal>
<style lang="scss"> <style lang="scss">
#settings-modal { #settings-modal {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
max-width: 100%;
max-height: 100%;
> tbody > tr { user-select: none;
> td:nth-child(1) { overflow-y: scroll;
text-align: left; overflow-wrap: break-word;
> .setting-description { > .settings-category {
color: var(--color-lighter); width: auto;
font-size: 80%;
display: flex;
flex-direction: column;
> .settings-row {
display: inline-flex;
flex-direction: row;
align-items: center;
> .settings-description {
text-align: left;
width: 20em;
> .settings-small-description {
color: var(--color-lighter);
font-size: 80%;
}
}
> button {
font-size: 1em;
width: 7em;
height: 2em;
} }
}
> td > button {
font-size: 1em;
width: 6.5em;
height: 2em;
} }
} }
} }

View file

@ -21,7 +21,7 @@
let logLength: number; let logLength: number;
game.Settings.subscribe((settings) => { game.Settings.subscribe((settings) => {
logLength = settings.logLength.current; logLength = settings.layout.logLength.current;
}); });
</script> </script>
@ -81,7 +81,7 @@
padding: 0; padding: 0;
// Subtract footer and header size (and footer padding) // Subtract footer and header size (and footer padding)
height: calc(100% - 2em - 2em - 2px); height: calc(100% - 2em - 2em - 4px);
overflow-y: hidden; overflow-y: hidden;

View file

@ -10,7 +10,7 @@ export class Log extends StaticClass {
static init(): void { static init(): void {
Settings.subscribe((settings) => { Settings.subscribe((settings) => {
Log.#maxLogLength = Math.max(...settings.logLength.options); Log.#maxLogLength = Math.max(...settings.layout.logLength.options);
})(); })();
} }

View file

@ -3,45 +3,154 @@
import { writable } from "svelte/store"; import { writable } from "svelte/store";
export const Settings = writable({ export const Settings = writable({
logLength: { layout: {
current: 30, logLength: {
defaultValue: 30 as const, current: 30,
name: "Max Log Messages" as const, defaultValue: 30 as const,
description: "Max number of messages kept in the log." as const, name: "Log Messages" as const,
category: "LAYOUT" as const, description: "The number of messages shown in the log" as const,
options: [5, 10, 15, 20, 30, 60] as const, options: [5, 10, 15, 20, 30, 60] as const,
},
}, },
enableThemes: { appearance: {
current: true, enableThemes: {
defaultValue: true as const, current: true,
name: "Enable Planet-dependent Styles" as const, defaultValue: true as const,
description: "Should page colors change for different planets?" as const, name: "Enable Planet-dependent Styles" as const,
options: [true, false] as const, description:
category: "APPEARANCE" as const, "Whether page colors should change for different planets" as const,
options: [true, false] as const,
},
theme: {
current: "marine",
defaultValue: "marine" as const,
name: "Currently enabled theme" as const,
description:
"Only applied if planet-dependent styles are enabled" as const,
options: [
"abandoned",
"chaotic",
"frigid",
"haven",
"marine",
"shrouded",
"tempestuous",
"violent",
],
},
}, },
theme: { other: {
current: "marine", updateCheck: {
defaultValue: "marine" as const, current: true,
name: "Currently enabled theme" as const, defaultValue: true as const,
description: "Changes the colors of the game" as const, name: "Check for updates" as const,
options: [ description: "Whether to notify you of new updates" as const,
"abandoned", options: [true, false] as const,
"chaotic", },
"frigid",
"haven",
"marine",
"shrouded",
"tempestuous",
"violent",
],
category: "APPEARANCE" as const,
}, },
updateCheck: { // To test scrolling of the settings modal (gonna use them to test saving later, too)
current: true, nil: {
defaultValue: true as const, nil1: {
name: "Check for updates" as const, defaultValue: true as const,
description: "Whether to notify you of new updates." as const, name: "placeholder" as const,
category: "OTHER" as const, description: "placeholder." as const,
options: [true, false] as const, options: [true, false] as const,
},
nil2: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil3: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil4: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil5: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil6: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil7: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil8: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil9: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil10: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil11: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil12: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil13: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil14: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil15: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil16: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
nil17: {
defaultValue: true as const,
name: "placeholder" as const,
description: "placeholder." as const,
options: [true, false] as const,
},
}, },
}); });

View file

@ -62,8 +62,10 @@ export class SharkGame extends StaticClass {
static init(): void { static init(): void {
Settings.update((settings) => { Settings.update((settings) => {
for (const setting of Object.values(settings)) { for (const settingsCategory of Object.values(settings)) {
setting.current = setting.defaultValue; for (const setting of Object.values(settingsCategory)) {
setting.current = setting.defaultValue;
}
} }
return settings; return settings;
}); });