diff --git a/src/ps/games/snakesladders/constants.ts b/src/ps/games/snakesladders/constants.ts index 50af1b9..38c7a36 100644 --- a/src/ps/games/snakesladders/constants.ts +++ b/src/ps/games/snakesladders/constants.ts @@ -1,3 +1,5 @@ -import type { Hex } from '@/utils/color'; +import { StringToHex } from '@/utils/color'; -export const TOKEN_COLORS = ['#ff0000', '#ff8000', '#ffff00', '#00ff00', '#00ffff', '#0000ff', '#9e00ff', '#ff00ff'] as Hex[]; +export const TOKEN_COLORS = ['#ff0000', '#ff8000', '#ffff00', '#00ff00', '#00ffff', '#0000ff', '#9e00ff', '#ff00ff'].map( + color => StringToHex(color)! +); diff --git a/src/utils/color.ts b/src/utils/color.ts index b745c40..d832ada 100644 --- a/src/utils/color.ts +++ b/src/utils/color.ts @@ -106,7 +106,7 @@ export function normalizeHue(hue: number): number { export function StringToHex(hex: string): Hex | null { const hexVal = hex.replace(/^#/, ''); if (![3, 4, 6, 8].includes(hexVal.length)) return null; - if (/^[0-9a-f]+$/i.test(hexVal)) return hex as Hex; + if (/^[0-9a-f]+$/i.test(hexVal)) return hexVal as Hex; return null; } @@ -125,7 +125,7 @@ export function HexToRgb(hex: Hex): Rgb { } export function RgbToHex({ R, G, B, a }: Rgb): Hex { - return `#${[R, G, B, ...(a! < 1 ? [Math.round(a! * 255)] : [])] + return `${[R, G, B, ...(a! < 1 ? [Math.round(a! * 255)] : [])] .map(n => (Number.isNaN(n) ? 10 : Math.round(Math.min(Math.max(n, 0), 255))).toString(16).padStart(2, '0')) .join('')}` as Hex; }