From 0cd3a4037f2e85b01b0c303404fa7ac7a7c0434b Mon Sep 17 00:00:00 2001 From: TanPat Date: Wed, 19 Nov 2025 13:46:13 +0530 Subject: [PATCH 1/3] converted TOKEN_COLORS to Hex[] using StringToHex() function Fixed bug of StringToHex() and RgbToHex() including '#' in the output --- src/ps/games/snakesladders/constants.ts | 3 ++- src/utils/color.ts | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ps/games/snakesladders/constants.ts b/src/ps/games/snakesladders/constants.ts index 50af1b93..eb84d214 100644 --- a/src/ps/games/snakesladders/constants.ts +++ b/src/ps/games/snakesladders/constants.ts @@ -1,3 +1,4 @@ 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 b745c400..7eebda1b 100644 --- a/src/utils/color.ts +++ b/src/utils/color.ts @@ -104,9 +104,9 @@ export function normalizeHue(hue: number): number { // region Conversion Methods 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; + hex = hex.replace(/^#/, ''); + if (![3, 4, 6, 8].includes(hex.length)) return null; + if (/^[0-9a-f]+$/i.test(hex)) return hex 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; } From 21886f01a06399182b75e04b819ca48a34b4cbf2 Mon Sep 17 00:00:00 2001 From: TanPat Date: Wed, 19 Nov 2025 17:34:08 +0530 Subject: [PATCH 2/3] fix: update code to satisfy ESLint rules and improve variable handling --- src/ps/games/snakesladders/constants.ts | 5 +++-- src/utils/color.ts | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ps/games/snakesladders/constants.ts b/src/ps/games/snakesladders/constants.ts index eb84d214..fec31b8c 100644 --- a/src/ps/games/snakesladders/constants.ts +++ b/src/ps/games/snakesladders/constants.ts @@ -1,4 +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'].map(color => StringToHex(color)!); +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 7eebda1b..d832adad 100644 --- a/src/utils/color.ts +++ b/src/utils/color.ts @@ -104,9 +104,9 @@ export function normalizeHue(hue: number): number { // region Conversion Methods export function StringToHex(hex: string): Hex | null { - hex = hex.replace(/^#/, ''); - if (![3, 4, 6, 8].includes(hex.length)) return null; - if (/^[0-9a-f]+$/i.test(hex)) return hex as Hex; + const hexVal = hex.replace(/^#/, ''); + if (![3, 4, 6, 8].includes(hexVal.length)) return null; + if (/^[0-9a-f]+$/i.test(hexVal)) return hexVal as Hex; return null; } From 1e68c9c9d6ff2bbec161dfb36e10bafd2f12850f Mon Sep 17 00:00:00 2001 From: TanPat Date: Wed, 19 Nov 2025 17:47:20 +0530 Subject: [PATCH 3/3] chore: --- src/ps/games/snakesladders/constants.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ps/games/snakesladders/constants.ts b/src/ps/games/snakesladders/constants.ts index fec31b8c..38c7a36e 100644 --- a/src/ps/games/snakesladders/constants.ts +++ b/src/ps/games/snakesladders/constants.ts @@ -1,5 +1,5 @@ -import {StringToHex} from '@/utils/color'; +import { StringToHex } from '@/utils/color'; export const TOKEN_COLORS = ['#ff0000', '#ff8000', '#ffff00', '#00ff00', '#00ffff', '#0000ff', '#9e00ff', '#ff00ff'].map( - color => StringToHex(color)! + color => StringToHex(color)! );