feat(frontend): improves current_status

This commit is contained in:
itsscb 2024-09-06 14:25:55 +02:00
parent e41eeaa890
commit 3c1d4f91b6

View File

@ -83,31 +83,29 @@ impl Game {
pub fn current_status(&self) -> Status {
self.word.as_ref().map_or(Status::New, |_| {
let word_count = self.submitted_words.len();
if self.tries == 0 {
Status::New
} else if self.tries < MAX_TRIES {
if self
match self.tries {
0 => Status::New,
1..MAX_TRIES => self
.submitted_words
.last()
.unwrap()
.iter()
.all(|v| matches!(v, CharStatus::Match(_)))
{
.map_or(Status::InProgress, |words| {
if words.iter().all(|v| matches!(v, CharStatus::Match(_))) {
Status::Win(word_count)
} else {
Status::InProgress
}
} else if self
}),
_ => self
.submitted_words
.last()
.unwrap()
.iter()
.all(|v| matches!(v, CharStatus::Match(_)))
{
.map_or(Status::Lose(word_count), |words| {
if words.iter().all(|v| matches!(v, CharStatus::Match(_))) {
Status::Win(word_count)
} else {
Status::Lose(word_count)
}
}),
}
})
}
}