From cc72fa1b3166bcae305e30a622dd5f6be8e9c2ee Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 13 Apr 2024 21:07:51 +0200 Subject: [PATCH] cleanup, fixes --- src/chat.rs | 57 +++++++++++++++-------------------------- src/chats/serenity.yaml | 3 --- 2 files changed, 20 insertions(+), 40 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 735d0da..2c7e16e 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -122,13 +122,13 @@ impl ChatDB { // - `{"goto": "foo"}` fn search_choice(&self, yaml: Option<&Value>) -> Option<(String, Value)> { let non_choice_tokens = NON_CHOICE_TOKENS.to_vec(); - if let Some(Value::Mapping(hash)) = yaml { - for key in hash.keys() { + if let Some(Value::Mapping(map)) = yaml { + for key in map.keys() { if let Value::String(key) = key { if non_choice_tokens.contains(&key.as_str()) { continue; } - return Some((key.into(), hash[key].clone())); + return Some((key.into(), map[key].clone())); } } } @@ -168,12 +168,6 @@ impl ChatDB { return popped; } - // Note that this (intentionally) may result in a pointer that's out of bounds. - fn pointer_lookahead(&self, position: &mut Vec) { - let index = position.len() - 1; - position[index] += 1; - } - // Returns the Value at the given ID/position, as-is. // If it's a choice, it returns the entire {"choice text": [...]} mapping. fn at(&self, id: usize, position: &Vec) -> Option { @@ -216,17 +210,11 @@ impl ChatDB { return result; } - pub fn process_value(&self, chat: &mut Chat, event: &mut EventWriter) { - } - - pub fn advance_chat(&self, chat: &mut Chat, event: &mut EventWriter) { - event.send(ChatEvent::DespawnAllChoices); - let conv = &self.0.get(chat.id); - if conv.is_none() { - return; - } - - // Handle this entry in the chat list + pub fn process_yaml_entry( + &self, + chat: &mut Chat, + event: &mut EventWriter, + ) -> bool { let current_item = self.at(chat.id, &chat.position); let mut add_choices = true; match current_item { @@ -239,13 +227,23 @@ impl ChatDB { } } None => { - event.send(ChatEvent::SpawnMessage("Disconnected.".to_string())); - event.send(ChatEvent::DespawnAllChats); + if chat.position.len() == 0 { + event.send(ChatEvent::SpawnMessage("Disconnected.".to_string())); + event.send(ChatEvent::DespawnAllChats); + } } _ => { error!("Can't handle YAML value {current_item:?}"); } } + return add_choices; + } + + pub fn advance_chat(&self, chat: &mut Chat, event: &mut EventWriter) { + event.send(ChatEvent::DespawnAllChoices); + + // Handle this entry in the chat list + let add_choices = self.process_yaml_entry(chat, event); // Move on to next entry let mut finished_branch = self.advance_pointer(chat); @@ -297,21 +295,6 @@ pub fn load_chats(mut chatdb: ResMut) { error!("Could not load chat definitions. Validate files in `src/chats/` path."); } } -// let mut chat = Chat { -// id: 2, -// position: vec![0], -// timer: 0.0, -// talker: Talker { -// conv_id: "Icarus".to_string(), -// name: None, -// pronoun: None, -// talking_speed: 1.0, -// } -// }; - dbg!(chatdb.at(2, &vec![0])); - dbg!(chatdb.at(2, &vec![1])); - dbg!(chatdb.at(2, &vec![2])); - dbg!(chatdb.at(2, &vec![3])); } pub fn handle_new_conversations( diff --git a/src/chats/serenity.yaml b/src/chats/serenity.yaml index b5d62ea..ea56a93 100644 --- a/src/chats/serenity.yaml +++ b/src/chats/serenity.yaml @@ -17,9 +17,6 @@ - chat: Icarus -- if talkcount > 0: - - "Oh, hi again! How are you?" - - goto: howru - Oh hey, you're awake! - I found you drifting out cold, and thought, I better watch over you. - Took us here behind that moonlet, to shield you from the micros.