diff --git a/package.json b/package.json index 4adbe7b6..f0cc07e5 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "@fluentui/svg-icons": "^1.1.272", "@fontsource-variable/inter": "^5.1.1", "@fontsource/flow-rounded": "^5.1.1", + "@total-typescript/ts-reset": "^0.6.1", "expressive-code": "^0.41.2", "import-meta-resolve": "^4.1.0", "mime": "^4.0.6", diff --git a/src/app.d.ts b/src/app.d.ts index 863a66c4..15a48a9a 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -3,6 +3,7 @@ import type { TranslationFunctions, Locales } from "$lib/i18n/i18n-types" import type { User } from "$lib/api/user" +import "@total-typescript/ts-reset" declare global { namespace App { diff --git a/src/lib/api/card.ts b/src/lib/api/card.ts index a6aa0212..c85cd7ff 100644 --- a/src/lib/api/card.ts +++ b/src/lib/api/card.ts @@ -1,7 +1,7 @@ import { z } from "zod" import type { Parser } from "." import { Json, String } from "./utility/responses" -import { games } from "$lib/app/formatting" +import { games, type Game } from "$lib/app/formatting" export interface Card { luid: string @@ -16,9 +16,9 @@ export interface GameCard { name: string rating: number } -export type CardUserGames = Record +export type CardUserGames = Record -export function getAvailableGame(cardUserGames: CardUserGames, active?: string, target?: string) { +export function getAvailableGame(cardUserGames: CardUserGames, active?: Game, target?: Game) { if (target && cardUserGames[target]) return target if (active && cardUserGames[active]) return active return Object.keys(cardUserGames).find( @@ -41,7 +41,7 @@ const Routes = { username: z.string() }) }, - response: Json<{ game: string }>() + response: Json<{ game: Game }>() }, link: { authenticated: true, diff --git a/src/lib/api/settings.ts b/src/lib/api/settings.ts index a0e12a01..a8ab3d78 100644 --- a/src/lib/api/settings.ts +++ b/src/lib/api/settings.ts @@ -1,11 +1,12 @@ import { z } from "zod" import type { Parser } from "." import { Json } from "./utility/responses" +import type { Game } from "$lib/app/formatting" export interface Setting { key: string type: "String" | "Boolean" - game: string + game: Game value?: boolean | string } @@ -19,14 +20,14 @@ export const userVisibleSettings: Array = [ "waccaAlwaysVip", "waccaInfiniteWp" ] -export const userSettingMatches: Record> = { +export const userSettingMatches: Record = { chu3: ["chu3", "chu3-matching"], mai2: ["general", "mai2"], wacca: ["general", "wacca"], ongeki: ["ongeki"] } -export function settingMatches(selectedGame: string, setting: Setting) { +export function settingMatches(selectedGame: Game, setting: Setting) { return ( userSettingMatches[selectedGame].includes(setting.game) && userVisibleSettings.includes(setting.key) diff --git a/src/lib/app/assets.ts b/src/lib/app/assets.ts index c268759c..6bcb8374 100644 --- a/src/lib/app/assets.ts +++ b/src/lib/app/assets.ts @@ -1,7 +1,9 @@ +import type { Game } from "./formatting" + export function getProfilePictureUrl(profilePicture: string) { return `/net/asset/net/portrait/${profilePicture}` } -export function getMusicJacket(game: string, musicId: number) { +export function getMusicJacket(game: Game, musicId: number) { // Removing any characters at the beginning if 4+ characters long seems to fix the thumbnail resolving for some reason on mai return `/net/data/${game}/song/${musicId.toString().substring(musicId.toString().length - 4)}/jacket`; } \ No newline at end of file diff --git a/src/lib/app/formatting.ts b/src/lib/app/formatting.ts index ef9fb87a..bb46c841 100644 --- a/src/lib/app/formatting.ts +++ b/src/lib/app/formatting.ts @@ -24,7 +24,7 @@ export function fromSegacode(name: string) { export function formatWithCommas(number: number) { return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") } -export function formatRatingForGame(game: string, rating: number) { +export function formatRatingForGame(game: Game, rating: number) { switch (game) { case "chu3": return (rating / 100).toFixed(2) diff --git a/src/lib/components/Navigator.svelte b/src/lib/components/Navigator.svelte index d37b7440..a5ab7925 100644 --- a/src/lib/components/Navigator.svelte +++ b/src/lib/components/Navigator.svelte @@ -20,13 +20,13 @@ import type { CardUserGames } from "$lib/api/card" import type { User } from "$lib/api/user" import SignedOutCard from "./generic/SignedOutCard.svelte" - import { games } from "$lib/app/formatting" + import { games, type Game } from "$lib/app/formatting" import NavButton from "./NavButton.svelte" interface Props { user?: User cardUserGames?: CardUserGames - activeGame?: string + activeGame?: Game } let { cardUserGames, user, activeGame = $bindable() }: Props = $props() diff --git a/src/lib/components/generic/ProfileCard.svelte b/src/lib/components/generic/ProfileCard.svelte index 7e38a2bc..cb7d1263 100644 --- a/src/lib/components/generic/ProfileCard.svelte +++ b/src/lib/components/generic/ProfileCard.svelte @@ -9,17 +9,16 @@ Do NOT pass in values that are not of the CURRENT USER or it will NOT work prope import { LL } from "$lib/i18n/i18n-svelte"; import { getAvailableGames, type CardUserGames } from "$lib/api/card" - import { games, formatRatingForGame, fromSegacode } from "$lib/app/formatting"; + import { games, formatRatingForGame, fromSegacode, type Game } from "$lib/app/formatting"; import { enhance } from "$app/forms" import { page } from "$app/state" import { getContext } from "svelte" import type { User } from "$lib/api/user" import Loader from "$lib/app/loader.svelte" import { getProfilePictureUrl } from "$lib/app/assets" - export interface Props { cardUserGames: CardUserGames, - activeGame?: string, + activeGame?: Game, user: User } let { cardUserGames, activeGame = $bindable(), user }: Props = $props(); @@ -78,7 +77,7 @@ Do NOT pass in values that are not of the CURRENT USER or it will NOT work prope {#each available_games as game}