From 87e923892310d4e8e5cc9cab434842057c5c970e Mon Sep 17 00:00:00 2001 From: MasterGordon Date: Fri, 18 Oct 2024 17:13:36 +0200 Subject: [PATCH] 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"),