This commit is contained in:
CutieCat2804 2024-10-18 17:21:50 +02:00
commit a5f9ba865d
11 changed files with 31 additions and 22 deletions

View File

@ -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 { Button } from "./components/Button";
import { motion } from "framer-motion"; import { motion } from "framer-motion";
import { import {

View File

@ -1,6 +1,6 @@
import { atom } from "jotai"; import { atom } from "jotai";
import { atomWithStorage } from "jotai/utils"; import { atomWithStorage } from "jotai/utils";
import { FeedItem } from "./components/Feed/FeedItem"; import type { FeedItem } from "./components/Feed/FeedItem";
export const gameIdAtom = atom<string | undefined>(undefined); export const gameIdAtom = atom<string | undefined>(undefined);
export const loginTokenAtom = atomWithStorage<string | undefined>( export const loginTokenAtom = atomWithStorage<string | undefined>(

View File

@ -1,8 +1,8 @@
import { motion } from "framer-motion"; import { motion } from "framer-motion";
import { PropsWithChildren } from "react"; import type { PropsWithChildren } from "react";
import { formatTimeSpan } from "../../../shared/time"; import { formatTimeSpan } from "../../../shared/time";
import GemsIcon from "../GemIcon"; import GemsIcon from "../GemIcon";
import { Rarity as RarityType } from "../../../shared/lootboxes"; import type { Rarity as RarityType } from "../../../shared/lootboxes";
import { Rarity } from "../Rarity"; import { Rarity } from "../Rarity";
import { themes } from "../../themes"; import { themes } from "../../themes";

View File

@ -1,5 +1,5 @@
import { Link } from "wouter"; import { Link } from "wouter";
import { ServerGame } from "../../shared/game"; import type { ServerGame } from "../../shared/game";
import { formatRelativeTime, formatTimeSpan } from "../../shared/time"; import { formatRelativeTime, formatTimeSpan } from "../../shared/time";
import { Button } from "./Button"; import { Button } from "./Button";

View File

@ -1,5 +1,5 @@
import * as PopoverPrimitive from "@radix-ui/react-popover"; import * as PopoverPrimitive from "@radix-ui/react-popover";
import { forwardRef, PropsWithChildren } from "react"; import { forwardRef, type PropsWithChildren } from "react";
import { cn } from "../lib/utils"; import { cn } from "../lib/utils";
const Popover = PopoverPrimitive.Root; const Popover = PopoverPrimitive.Root;

View File

@ -1,4 +1,4 @@
import { PropsWithChildren } from "react"; import type { PropsWithChildren } from "react";
import { cn } from "../lib/utils"; import { cn } from "../lib/utils";
import { rarities } from "../../shared/lootboxes"; import { rarities } from "../../shared/lootboxes";

View File

@ -1,6 +1,9 @@
import React from "react"; import React from "react";
import type { Application } from "pixi.js"; 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 { PixiComponent, useApp } from "@pixi/react";
import { BaseTexture, SCALE_MODES } from "pixi.js"; import { BaseTexture, SCALE_MODES } from "pixi.js";
BaseTexture.defaultOptions.scaleMode = SCALE_MODES.NEAREST; BaseTexture.defaultOptions.scaleMode = SCALE_MODES.NEAREST;

View File

@ -41,6 +41,20 @@ export type LoadedTheme = Record<
size: number; 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) => { export const useTheme = (theme: Theme) => {
const [loadedTheme, setLoadedTheme] = useState<LoadedTheme | undefined>( const [loadedTheme, setLoadedTheme] = useState<LoadedTheme | undefined>(
undefined, undefined,

View File

@ -1,17 +1,11 @@
import type { Theme } from "./Theme"; import { even, type Theme } from "./Theme";
export const techiesDireTheme: Theme = { export const techiesDireTheme: Theme = {
size: 32, size: 32,
mine: [ mine: even(
{ () => import("../assets/themes/techies/dire/mine-1.png"),
weight: 0.5, () => import("../assets/themes/techies/dire/mine-2.png"),
sprite: () => import("../assets/themes/techies/dire/mine-1.png"), ),
},
{
weight: 0.5,
sprite: () => import("../assets/themes/techies/dire/mine-2.png"),
},
],
tile: () => import("../assets/themes/techies/dire/tile-1.png"), tile: () => import("../assets/themes/techies/dire/tile-1.png"),
revealed: () => import("../assets/themes/techies/dire/revealed.png"), revealed: () => import("../assets/themes/techies/dire/revealed.png"),
flag: () => import("../assets/themes/techies/flag.png"), flag: () => import("../assets/themes/techies/flag.png"),

View File

@ -1,4 +1,4 @@
import { ReactNode } from "react"; import type { ReactNode } from "react";
import { Switch } from "../../components/Switch"; import { Switch } from "../../components/Switch";
import { useWSMutation, useWSQuery } from "../../hooks"; import { useWSMutation, useWSQuery } from "../../hooks";

View File

@ -24,7 +24,6 @@ const createWSClient = () => {
let ws = new WebSocket(connectionString); let ws = new WebSocket(connectionString);
let reconnectAttempts = 0; let reconnectAttempts = 0;
const maxReconnectAttempts = 5; const maxReconnectAttempts = 5;
let isAuthenticated = false;
const connect = () => { const connect = () => {
ws = new WebSocket(connectionString); ws = new WebSocket(connectionString);
@ -35,7 +34,6 @@ const createWSClient = () => {
if (token) { if (token) {
try { try {
await dispatch("user.loginWithToken", { token: JSON.parse(token) }); await dispatch("user.loginWithToken", { token: JSON.parse(token) });
isAuthenticated = true;
} catch (e) { } catch (e) {
console.error("Re-authentication failed", e); console.error("Re-authentication failed", e);
} }