Get rooms working

This commit is contained in:
Elnu 2023-05-01 15:00:58 -07:00
parent c4eece7ffd
commit 85cc6c2f35
9 changed files with 266 additions and 143 deletions

View file

@ -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);