cleanup, fixes
This commit is contained in:
parent
5bc76a3e2f
commit
cc72fa1b31
53
src/chat.rs
53
src/chat.rs
|
@ -122,13 +122,13 @@ impl ChatDB {
|
||||||
// - `{"goto": "foo"}`
|
// - `{"goto": "foo"}`
|
||||||
fn search_choice(&self, yaml: Option<&Value>) -> Option<(String, Value)> {
|
fn search_choice(&self, yaml: Option<&Value>) -> Option<(String, Value)> {
|
||||||
let non_choice_tokens = NON_CHOICE_TOKENS.to_vec();
|
let non_choice_tokens = NON_CHOICE_TOKENS.to_vec();
|
||||||
if let Some(Value::Mapping(hash)) = yaml {
|
if let Some(Value::Mapping(map)) = yaml {
|
||||||
for key in hash.keys() {
|
for key in map.keys() {
|
||||||
if let Value::String(key) = key {
|
if let Value::String(key) = key {
|
||||||
if non_choice_tokens.contains(&key.as_str()) {
|
if non_choice_tokens.contains(&key.as_str()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return Some((key.into(), hash[key].clone()));
|
return Some((key.into(), map[key].clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,12 +168,6 @@ impl ChatDB {
|
||||||
return popped;
|
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.
|
// Returns the Value at the given ID/position, as-is.
|
||||||
// If it's a choice, it returns the entire {"choice text": [...]} mapping.
|
// If it's a choice, it returns the entire {"choice text": [...]} mapping.
|
||||||
fn at(&self, id: usize, position: &Vec<usize>) -> Option<Value> {
|
fn at(&self, id: usize, position: &Vec<usize>) -> Option<Value> {
|
||||||
|
@ -216,17 +210,11 @@ impl ChatDB {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_value(&self, chat: &mut Chat, event: &mut EventWriter<ChatEvent>) {
|
pub fn process_yaml_entry(
|
||||||
}
|
&self,
|
||||||
|
chat: &mut Chat,
|
||||||
pub fn advance_chat(&self, chat: &mut Chat, event: &mut EventWriter<ChatEvent>) {
|
event: &mut EventWriter<ChatEvent>,
|
||||||
event.send(ChatEvent::DespawnAllChoices);
|
) -> bool {
|
||||||
let conv = &self.0.get(chat.id);
|
|
||||||
if conv.is_none() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle this entry in the chat list
|
|
||||||
let current_item = self.at(chat.id, &chat.position);
|
let current_item = self.at(chat.id, &chat.position);
|
||||||
let mut add_choices = true;
|
let mut add_choices = true;
|
||||||
match current_item {
|
match current_item {
|
||||||
|
@ -239,13 +227,23 @@ impl ChatDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
if chat.position.len() == 0 {
|
||||||
event.send(ChatEvent::SpawnMessage("Disconnected.".to_string()));
|
event.send(ChatEvent::SpawnMessage("Disconnected.".to_string()));
|
||||||
event.send(ChatEvent::DespawnAllChats);
|
event.send(ChatEvent::DespawnAllChats);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Can't handle YAML value {current_item:?}");
|
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
|
// Move on to next entry
|
||||||
let mut finished_branch = self.advance_pointer(chat);
|
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.");
|
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(
|
pub fn handle_new_conversations(
|
||||||
|
|
|
@ -17,9 +17,6 @@
|
||||||
|
|
||||||
|
|
||||||
- chat: Icarus
|
- chat: Icarus
|
||||||
- if talkcount > 0:
|
|
||||||
- "Oh, hi again! How are you?"
|
|
||||||
- goto: howru
|
|
||||||
- Oh hey, you're awake!
|
- Oh hey, you're awake!
|
||||||
- I found you drifting out cold, and thought, I better watch over you.
|
- 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.
|
- Took us here behind that moonlet, to shield you from the micros.
|
||||||
|
|
Loading…
Reference in a new issue