Updates and more

This commit is contained in:
2023-11-03 20:31:27 +01:00
parent b5a54d087b
commit e97e86f9ac
22 changed files with 363 additions and 80 deletions

View File

@@ -0,0 +1,11 @@
<script lang="ts">
import {server} from "./stores/server.ts";
</script>
{#await $server}
{:then data}
{data.players.online}
{:catch error}
Error
{/await}

View File

@@ -0,0 +1,19 @@
<script lang="ts">
import { t } from "astro-i18n"
import {server} from "./stores/server.ts";
function generateVersionString(version: string): string {
let versions = version.split(" ").slice(1)
return `${versions[0].replace(",", "")} - ${versions[versions.length - 1]}`
}
</script>
{#await $server}
<p>{t("status.loading")}</p>
{:then data}
<h2>{t("status.status")}: <span class="text-green-500">{t("status.online")}</span></h2>
<h2>{t("status.players", { count: `${data.players.online}/${data.players.max}`})}</h2>
<h2>{t("status.version", { version: generateVersionString(data.version.name)})}</h2>
{:catch error}
<h1>{t("status.status")}: <span class="text-red-500">{t("status.offline")}</span></h1>
{/await}

View File

@@ -33,7 +33,7 @@ export function cachedFamily<T, K>(normal: K, init: (arg0: T) => Promise<K>): (a
const stores: Map<T, Cached<K>> = new Map();
return (arg: T) => {
if(stores.has(arg)) {
return stores.get(arg);
return stores.get(arg)!!;
} else {
const store = writable<K>(normal);
let first = true;

View File

@@ -0,0 +1,4 @@
import {readable} from "svelte/store";
import type {Readable} from "svelte/store";
export const server = readable(fetch(import.meta.env.PUBLIC_API_SERVER + "/data/server").then(res => res.json()))