fix(know-your-world): normalize accented letters for keyboard input
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 <noreply@anthropic.com>
This commit is contained in:
parent
77033f0b22
commit
b27856e9fc
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue