WIP stack-based conversation position
This commit is contained in:
parent
ef9d9c8fcc
commit
57f0e94bc6
35
src/chat.rs
35
src/chat.rs
|
@ -54,7 +54,7 @@ impl Plugin for ChatPlugin {
|
|||
#[derive(Component)]
|
||||
pub struct Chat {
|
||||
pub id: usize,
|
||||
pub position: usize,
|
||||
pub position: Vec<usize>,
|
||||
pub timer: f64,
|
||||
pub talker: Talker,
|
||||
}
|
||||
|
@ -110,6 +110,21 @@ impl ChatDB {
|
|||
return None;
|
||||
}
|
||||
|
||||
// returns false if the advanced pointer is out of bounds
|
||||
fn advance_pointer(&self, chat: &mut Chat) -> bool {
|
||||
chat.position[0] += 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
fn pointer_lookahead(&self, position: &mut Vec<usize>) {
|
||||
let index = position.len() - 1;
|
||||
position[index] += 1;
|
||||
}
|
||||
|
||||
fn at(&self, id: usize, position: Vec<usize>) -> Option<Yaml> {
|
||||
return None;
|
||||
}
|
||||
|
||||
pub fn advance_chat(&self, chat: &mut Chat, event: &mut EventWriter<ChatEvent>) {
|
||||
event.send(ChatEvent::DespawnAllChoices);
|
||||
let conv = &self.0[chat.id].as_vec();
|
||||
|
@ -120,34 +135,34 @@ impl ChatDB {
|
|||
|
||||
// Handle next entry in the chat list
|
||||
let mut is_skipping_through = false;
|
||||
chat.position += 1;
|
||||
if chat.position >= conv.len() {
|
||||
if !self.advance_pointer(chat) {
|
||||
event.send(ChatEvent::SpawnMessage("Disconnected.".to_string()));
|
||||
event.send(ChatEvent::DespawnAllChats);
|
||||
return;
|
||||
}
|
||||
else if let Some(_) = self.search_choice(&conv[chat.position]) {
|
||||
else if let Some(_) = self.search_choice(&conv[chat.position[0]]) {
|
||||
is_skipping_through = true;
|
||||
}
|
||||
else if let Some(message) = conv[chat.position].as_str() {
|
||||
else if let Some(message) = conv[chat.position[0]].as_str() {
|
||||
event.send(ChatEvent::SpawnMessage(message.to_string()));
|
||||
}
|
||||
|
||||
// Check if the immediately following entries are choices
|
||||
let mut pos = chat.position + 1;
|
||||
let mut pos = chat.position.clone();
|
||||
self.pointer_lookahead(&mut pos);
|
||||
let mut key: usize = 0;
|
||||
loop {
|
||||
if is_skipping_through || pos >= conv.len() {
|
||||
if is_skipping_through || pos[0] >= conv.len() {
|
||||
break;
|
||||
}
|
||||
if let Some(choice) = self.search_choice(&conv[pos]) {
|
||||
if let Some(choice) = self.search_choice(&conv[pos[0]]) {
|
||||
event.send(ChatEvent::SpawnChoice(choice, key));
|
||||
key += 1;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
pos += 1;
|
||||
self.pointer_lookahead(&mut pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +217,7 @@ pub fn handle_new_conversations(
|
|||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Ping));
|
||||
let mut chat = Chat {
|
||||
id: chat_id,
|
||||
position: 0,
|
||||
position: vec![0],
|
||||
timer: time.elapsed_seconds_f64(),
|
||||
talker: event.talker.clone(),
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue