From 87e923892310d4e8e5cc9cab434842057c5c970e Mon Sep 17 00:00:00 2001 From: MasterGordon Date: Fri, 18 Oct 2024 17:13:36 +0200 Subject: [PATCH 1/2] added helpers --- src/themes/Theme.ts | 14 ++++++++++++++ src/themes/techies-dire.ts | 16 +++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/themes/Theme.ts b/src/themes/Theme.ts index f5c739d..4315998 100644 --- a/src/themes/Theme.ts +++ b/src/themes/Theme.ts @@ -41,6 +41,20 @@ export type LoadedTheme = Record< size: number; }; +export const even = (...sprites: LazySprite[]): WeightedLazySprites[] => { + return sprites.map((sprite) => ({ weight: 0.5, sprite })); +}; + +export const mainWithSpecials = ( + ...sprites: LazySprite[] +): WeightedLazySprites[] => { + const [main, ...specials] = sprites; + return [ + { weight: 1, sprite: main }, + ...specials.map((sprite) => ({ weight: 0.05, sprite })), + ]; +}; + export const useTheme = (theme: Theme) => { const [loadedTheme, setLoadedTheme] = useState( undefined, diff --git a/src/themes/techies-dire.ts b/src/themes/techies-dire.ts index 627163e..8f399d9 100644 --- a/src/themes/techies-dire.ts +++ b/src/themes/techies-dire.ts @@ -1,17 +1,11 @@ -import type { Theme } from "./Theme"; +import { even, type Theme } from "./Theme"; export const techiesDireTheme: Theme = { size: 32, - mine: [ - { - weight: 0.5, - sprite: () => import("../assets/themes/techies/dire/mine-1.png"), - }, - { - weight: 0.5, - sprite: () => import("../assets/themes/techies/dire/mine-2.png"), - }, - ], + mine: even( + () => import("../assets/themes/techies/dire/mine-1.png"), + () => import("../assets/themes/techies/dire/mine-2.png"), + ), tile: () => import("../assets/themes/techies/dire/tile-1.png"), revealed: () => import("../assets/themes/techies/dire/revealed.png"), flag: () => import("../assets/themes/techies/flag.png"), From d26f08cd21ee959efb7c3ad16931ae925004da93 Mon Sep 17 00:00:00 2001 From: MasterGordon Date: Fri, 18 Oct 2024 17:16:52 +0200 Subject: [PATCH 2/2] added type imports --- src/Shell.tsx | 2 +- src/atoms.ts | 2 +- src/components/Feed/FeedItem.tsx | 4 ++-- src/components/PastMatch.tsx | 2 +- src/components/Popover.tsx | 2 +- src/components/Rarity.tsx | 2 +- src/components/pixi/PixiViewport.tsx | 5 ++++- src/views/settings/Settings.tsx | 2 +- src/wsClient.ts | 2 -- 9 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Shell.tsx b/src/Shell.tsx index dead12d..33cbcc2 100644 --- a/src/Shell.tsx +++ b/src/Shell.tsx @@ -1,4 +1,4 @@ -import { PropsWithChildren, useEffect, useRef, useState } from "react"; +import { type PropsWithChildren, useEffect, useRef, useState } from "react"; import { Button } from "./components/Button"; import { motion } from "framer-motion"; import { diff --git a/src/atoms.ts b/src/atoms.ts index 6331c7f..7b0749b 100644 --- a/src/atoms.ts +++ b/src/atoms.ts @@ -1,6 +1,6 @@ import { atom } from "jotai"; import { atomWithStorage } from "jotai/utils"; -import { FeedItem } from "./components/Feed/FeedItem"; +import type { FeedItem } from "./components/Feed/FeedItem"; export const gameIdAtom = atom(undefined); export const loginTokenAtom = atomWithStorage( diff --git a/src/components/Feed/FeedItem.tsx b/src/components/Feed/FeedItem.tsx index aa72434..1d99dc0 100644 --- a/src/components/Feed/FeedItem.tsx +++ b/src/components/Feed/FeedItem.tsx @@ -1,8 +1,8 @@ import { motion } from "framer-motion"; -import { PropsWithChildren } from "react"; +import type { PropsWithChildren } from "react"; import { formatTimeSpan } from "../../../shared/time"; import GemsIcon from "../GemIcon"; -import { Rarity as RarityType } from "../../../shared/lootboxes"; +import type { Rarity as RarityType } from "../../../shared/lootboxes"; import { Rarity } from "../Rarity"; import { themes } from "../../themes"; diff --git a/src/components/PastMatch.tsx b/src/components/PastMatch.tsx index 43a446c..6eafdfe 100644 --- a/src/components/PastMatch.tsx +++ b/src/components/PastMatch.tsx @@ -1,5 +1,5 @@ import { Link } from "wouter"; -import { ServerGame } from "../../shared/game"; +import type { ServerGame } from "../../shared/game"; import { formatRelativeTime, formatTimeSpan } from "../../shared/time"; import { Button } from "./Button"; diff --git a/src/components/Popover.tsx b/src/components/Popover.tsx index fe5daa2..be7a020 100644 --- a/src/components/Popover.tsx +++ b/src/components/Popover.tsx @@ -1,5 +1,5 @@ import * as PopoverPrimitive from "@radix-ui/react-popover"; -import { forwardRef, PropsWithChildren } from "react"; +import { forwardRef, type PropsWithChildren } from "react"; import { cn } from "../lib/utils"; const Popover = PopoverPrimitive.Root; diff --git a/src/components/Rarity.tsx b/src/components/Rarity.tsx index 4e19d4b..8aa6d08 100644 --- a/src/components/Rarity.tsx +++ b/src/components/Rarity.tsx @@ -1,4 +1,4 @@ -import { PropsWithChildren } from "react"; +import type { PropsWithChildren } from "react"; import { cn } from "../lib/utils"; import { rarities } from "../../shared/lootboxes"; diff --git a/src/components/pixi/PixiViewport.tsx b/src/components/pixi/PixiViewport.tsx index 2822e25..31a1530 100644 --- a/src/components/pixi/PixiViewport.tsx +++ b/src/components/pixi/PixiViewport.tsx @@ -1,6 +1,9 @@ import React from "react"; import type { Application } from "pixi.js"; -import { IClampZoomOptions, Viewport as PixiViewport } from "pixi-viewport"; +import { + type IClampZoomOptions, + Viewport as PixiViewport, +} from "pixi-viewport"; import { PixiComponent, useApp } from "@pixi/react"; import { BaseTexture, SCALE_MODES } from "pixi.js"; BaseTexture.defaultOptions.scaleMode = SCALE_MODES.NEAREST; diff --git a/src/views/settings/Settings.tsx b/src/views/settings/Settings.tsx index 878073f..61d5cd7 100644 --- a/src/views/settings/Settings.tsx +++ b/src/views/settings/Settings.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from "react"; +import type { ReactNode } from "react"; import { Switch } from "../../components/Switch"; import { useWSMutation, useWSQuery } from "../../hooks"; diff --git a/src/wsClient.ts b/src/wsClient.ts index ce4293e..7678e02 100644 --- a/src/wsClient.ts +++ b/src/wsClient.ts @@ -24,7 +24,6 @@ const createWSClient = () => { let ws = new WebSocket(connectionString); let reconnectAttempts = 0; const maxReconnectAttempts = 5; - let isAuthenticated = false; const connect = () => { ws = new WebSocket(connectionString); @@ -35,7 +34,6 @@ const createWSClient = () => { if (token) { try { await dispatch("user.loginWithToken", { token: JSON.parse(token) }); - isAuthenticated = true; } catch (e) { console.error("Re-authentication failed", e); }