Get rooms working
This commit is contained in:
parent
c4eece7ffd
commit
85cc6c2f35
9 changed files with 266 additions and 143 deletions
10
src/room.rs
10
src/room.rs
|
@ -16,12 +16,13 @@ use crate::word::Word;
|
|||
|
||||
use wana_kana::{ConvertJapanese, IsJapaneseStr};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RoomSettings {
|
||||
pub name: String,
|
||||
pub database_settings: DatabaseSettings,
|
||||
}
|
||||
|
||||
pub struct Room {
|
||||
name: String,
|
||||
database: Database,
|
||||
next_mora: Option<String>,
|
||||
last_client_id: Option<u64>,
|
||||
|
@ -30,12 +31,17 @@ pub struct Room {
|
|||
impl Room {
|
||||
pub fn new(settings: RoomSettings) -> Result<Self, DatabaseCreationError> {
|
||||
Ok(Self {
|
||||
name: settings.name,
|
||||
database: Database::new(settings.database_settings)?,
|
||||
next_mora: None,
|
||||
last_client_id: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
pub fn next_mora(&self) -> &Option<String> {
|
||||
&self.next_mora
|
||||
}
|
||||
|
@ -88,7 +94,7 @@ impl Room {
|
|||
} 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();
|
||||
let word: Word = entry.into();
|
||||
self.next_mora = Some(get_final_mora(&word.reading));
|
||||
self.database.add_word(&word).unwrap(); // TODO: replace .unwrap() with ?
|
||||
self.last_client_id = Some(client_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue