Skip to content

Commit

Permalink
✨ Add preview invalid words option, closes #26
Browse files Browse the repository at this point in the history
  • Loading branch information
vegeta897 committed Nov 23, 2024
1 parent 7a9c3ba commit e9cf916
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/components/Options.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 6 additions & 7 deletions src/lib/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
}
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lib/translations/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
4 changes: 4 additions & 0 deletions src/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const openScreen: Writable<null | 'options' | 'tutorial' | 'stats'> =

export const highContrast: Writable<boolean> = storageWritable('wp-highContrast', false)
export const showAllHints: Writable<boolean> = storageWritable('wp-showAllHints', false)
export const previewInvalidWords: Writable<boolean> = storageWritable(
'wp-previewInvalidWords',
true
)
export const swapEnterBackspace: Writable<boolean> = storageWritable(
'wp-swapEnterBackspace',
false
Expand Down

0 comments on commit e9cf916

Please sign in to comment.