From b27856e9fc4f339f50c148b6f0adbdb3c0b93140 Mon Sep 17 00:00:00 2001 From: Thomas Hallock Date: Sun, 30 Nov 2025 19:26:48 -0600 Subject: [PATCH] fix(know-your-world): normalize accented letters for keyboard input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added normalizeToBaseLetter() function that converts accented characters to their base ASCII equivalents (e.g., 'é' → 'e', 'ñ' → 'n', 'ç' → 'c'). This allows users to type region names like "Côte d'Ivoire" or "São Tomé" using a regular keyboard without needing to input accented characters. Applied to both physical keyboard and virtual keyboard handlers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../components/GameInfoPanel.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/web/src/arcade-games/know-your-world/components/GameInfoPanel.tsx b/apps/web/src/arcade-games/know-your-world/components/GameInfoPanel.tsx index ec8ffebe..a2ca7c1d 100644 --- a/apps/web/src/arcade-games/know-your-world/components/GameInfoPanel.tsx +++ b/apps/web/src/arcade-games/know-your-world/components/GameInfoPanel.tsx @@ -33,6 +33,18 @@ const NAME_ATTENTION_DURATION = 3000 // React-spring config for smooth takeover transitions const TAKEOVER_ANIMATION_CONFIG = { tension: 170, friction: 20 } +/** + * Normalize accented characters to their base ASCII letters. + * e.g., 'é' → 'e', 'ñ' → 'n', 'ü' → 'u', 'ç' → 'c' + * Uses Unicode NFD normalization to decompose characters, then strips diacritical marks. + */ +function normalizeToBaseLetter(char: string): string { + return char + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') + .toLowerCase() +} + // Helper to get hot/cold feedback emoji (matches MapRenderer's getHotColdEmoji) function getHotColdEmoji(type: FeedbackType | null | undefined): string { if (!type) return '🔥' @@ -335,7 +347,9 @@ export function GameInfoPanel({ return // No more letters to confirm } - const expectedLetter = letterInfo.char.toLowerCase() + // Normalize accented letters to base ASCII (e.g., 'é' → 'e', 'ñ' → 'n') + // so users can type region names like "Côte d'Ivoire" or "São Tomé" with a regular keyboard + const expectedLetter = normalizeToBaseLetter(letterInfo.char) const pressedLetter = e.key.toLowerCase() // Only accept single character keys (letters only, no space needed since we skip spaces) @@ -681,7 +695,8 @@ export function GameInfoPanel({ const letterInfo = getNthNonSpaceLetter(currentRegionName, nextLetterIndex) if (!letterInfo) return - const expectedLetter = letterInfo.char.toLowerCase() + // Normalize accented letters to base ASCII (e.g., 'é' → 'e', 'ñ' → 'n') + const expectedLetter = normalizeToBaseLetter(letterInfo.char) const pressedLetter = letter.toLowerCase() if (pressedLetter === expectedLetter) {