From e9cf9167d6b68be9dff3a0e9e751165719caa523 Mon Sep 17 00:00:00 2001 From: Devin Spikowski Date: Fri, 22 Nov 2024 22:32:22 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20preview=20invalid=20words=20o?= =?UTF-8?q?ption,=20closes=20#26?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Options.svelte | 5 +++++ src/lib/board.ts | 13 ++++++------- src/lib/translations/en/main.json | 1 + src/store/app.ts | 4 ++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/components/Options.svelte b/src/components/Options.svelte index 3434696..fe8c5d7 100644 --- a/src/components/Options.svelte +++ b/src/components/Options.svelte @@ -55,6 +55,11 @@ label: 'main.options.show_all_hints', click: toggle(showAllHints), }, + { + bind: store.previewInvalidWords, + label: 'main.options.preview_invalid_words', + click: toggle(store.previewInvalidWords), + }, { bind: store.swapEnterBackspace, label: 'main.options.swap_enter_backspace', diff --git a/src/lib/board.ts b/src/lib/board.ts index dee39bb..37ffa68 100644 --- a/src/lib/board.ts +++ b/src/lib/board.ts @@ -29,7 +29,7 @@ export function resetGuess() { store.notEnoughLetters.set(false) } -export function typeLetter(letter: string) { +export async function typeLetter(letter: string) { if (get(store.gameFinished)) return loadDictionary().catch((_) => { showError(get(t)('main.messages.need_reload'), () => {}, 8000) @@ -55,12 +55,10 @@ export function typeLetter(letter: string) { if (letter || _currentTile < WORD_LENGTH - 1) { store.currentTile.update((ct) => ct + 1) const typedWord = getBoardRowString(get(store.boardContent)[_currentRow]) - if (typedWord.length === WORD_LENGTH) { - loadDictionary().then(async () => { - if (typedWord !== get(store.answer) && !(await isValidWord(typedWord))) { - store.invalidWordPreview.set(true) - } - }) + if (typedWord.length === WORD_LENGTH && get(store.previewInvalidWords)) { + if (typedWord !== get(store.answer) && !(await isValidWord(typedWord))) { + store.invalidWordPreview.set(true) + } } } } @@ -116,6 +114,7 @@ export async function submitRow() { } if (submittedWord !== get(store.answer) && !validWord) { store.invalidWord.set(true) + store.invalidWordPreview.set(true) showError(get(t)('main.messages.invalid_word'), () => store.invalidWord.set(false)) submitting = false return diff --git a/src/lib/translations/en/main.json b/src/lib/translations/en/main.json index 4e618f6..0210897 100644 --- a/src/lib/translations/en/main.json +++ b/src/lib/translations/en/main.json @@ -79,6 +79,7 @@ "hard_mode": "Hard mode", "high_contrast_mode": "High contrast mode", "show_all_hints": "Show all hints in row", + "preview_invalid_words": "Preview invalid words", "swap_enter_backspace": "Swap Enter/Backspace keys", "alphabetic": "Alphabetic", "alphabetic_reversed": "Alphabetic (reversed)", diff --git a/src/store/app.ts b/src/store/app.ts index 47edeee..a7f914a 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -15,6 +15,10 @@ export const openScreen: Writable = export const highContrast: Writable = storageWritable('wp-highContrast', false) export const showAllHints: Writable = storageWritable('wp-showAllHints', false) +export const previewInvalidWords: Writable = storageWritable( + 'wp-previewInvalidWords', + true +) export const swapEnterBackspace: Writable = storageWritable( 'wp-swapEnterBackspace', false