implement stack-based conversation position
This commit is contained in:
parent
d990726932
commit
e8302833da
25
src/chat.rs
25
src/chat.rs
|
@ -127,7 +127,16 @@ impl ChatDB {
|
|||
|
||||
// returns false if the advanced pointer is out of bounds
|
||||
fn advance_pointer(&self, chat: &mut Chat) -> bool {
|
||||
chat.position[0] += 1;
|
||||
let index = chat.position.len() - 1;
|
||||
chat.position[index] += 1;
|
||||
|
||||
while chat.position.len() > 0 {
|
||||
if let None = self.at(chat.id, &chat.position) {
|
||||
chat.position.pop();
|
||||
}
|
||||
let index = chat.position.len() - 1;
|
||||
chat.position[index] += 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -137,11 +146,19 @@ impl ChatDB {
|
|||
}
|
||||
|
||||
fn at(&self, id: usize, position: &Vec<usize>) -> Option<&Value> {
|
||||
if let Some(Value::Sequence(seq)) = self.0.get(id) {
|
||||
return Some(&seq[position[0]]); // TODO: panic
|
||||
}
|
||||
if position.len() == 0 {
|
||||
return None;
|
||||
}
|
||||
let mut pointer: Option<&Value> = Some(&self.0[id]);
|
||||
for index in position {
|
||||
if let Some(Value::Sequence(seq)) = self.0.get(id) {
|
||||
pointer = Some(&seq[*index]);
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
return pointer;
|
||||
}
|
||||
|
||||
pub fn advance_chat(&self, chat: &mut Chat, event: &mut EventWriter<ChatEvent>) {
|
||||
event.send(ChatEvent::DespawnAllChoices);
|
||||
|
|
Loading…
Reference in a new issue