cleanup, fixes

This commit is contained in:
yuni 2024-04-13 21:07:51 +02:00
parent 5bc76a3e2f
commit cc72fa1b31
2 changed files with 20 additions and 40 deletions

View file

@ -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<usize>) {
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<usize>) -> Option<Value> {
@ -216,17 +210,11 @@ impl ChatDB {
return result;
}
pub fn process_value(&self, chat: &mut Chat, event: &mut EventWriter<ChatEvent>) {
}
pub fn advance_chat(&self, chat: &mut Chat, event: &mut EventWriter<ChatEvent>) {
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<ChatEvent>,
) -> 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<ChatEvent>) {
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<ChatDB>) {
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(

View file

@ -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.