cargo fmt
This commit is contained in:
parent
ed11799bf5
commit
c4eece7ffd
8 changed files with 113 additions and 53 deletions
27
src/room.rs
27
src/room.rs
|
@ -11,10 +11,10 @@
|
|||
use crate::database::{Database, DatabaseCreationError, DatabaseSettings};
|
||||
use crate::dictionary::lookup;
|
||||
use crate::response::MessageResponseData;
|
||||
use crate::utils::{get_starting_mora, get_final_mora};
|
||||
use crate::utils::{get_final_mora, get_starting_mora};
|
||||
use crate::word::Word;
|
||||
|
||||
use wana_kana::{IsJapaneseStr, ConvertJapanese};
|
||||
use wana_kana::{ConvertJapanese, IsJapaneseStr};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RoomSettings {
|
||||
|
@ -41,11 +41,16 @@ impl Room {
|
|||
}
|
||||
|
||||
pub fn get_history(&self) -> rusqlite::Result<Vec<Word>> {
|
||||
self.database.load_words_before(self.database.last_word_id + 1)
|
||||
self.database
|
||||
.load_words_before(self.database.last_word_id + 1)
|
||||
}
|
||||
|
||||
// Err(&str) will be converted to MessageResponseData::Error
|
||||
pub fn handle_query(&mut self, query: &str, client_id: u64) -> Result<MessageResponseData, &str> {
|
||||
pub fn handle_query(
|
||||
&mut self,
|
||||
query: &str,
|
||||
client_id: u64,
|
||||
) -> Result<MessageResponseData, &str> {
|
||||
// Ensure query isn't from last player
|
||||
if Some(client_id) == self.last_client_id {
|
||||
return Err("It's not your turn!");
|
||||
|
@ -70,9 +75,19 @@ impl Room {
|
|||
// Send result
|
||||
match dictionary_result {
|
||||
Some(entry) => {
|
||||
if entry.reading.chars().last().unwrap().to_string().to_hiragana() == "ん" {
|
||||
if entry
|
||||
.reading
|
||||
.chars()
|
||||
.last()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.to_hiragana()
|
||||
== "ん"
|
||||
{
|
||||
Err("Can't end with ん!")
|
||||
} else if self.next_mora.is_none() || get_starting_mora(&entry.reading).eq(self.next_mora.as_deref().unwrap()) {
|
||||
} else if self.next_mora.is_none()
|
||||
|| get_starting_mora(&entry.reading).eq(self.next_mora.as_deref().unwrap())
|
||||
{
|
||||
let word: Word = entry.clone().into();
|
||||
self.next_mora = Some(get_final_mora(&word.reading));
|
||||
self.database.add_word(&word).unwrap(); // TODO: replace .unwrap() with ?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue