WIP choice spawning
This commit is contained in:
parent
1fd0481ec4
commit
9cd1cf19e2
57
src/chat.rs
57
src/chat.rs
|
@ -9,11 +9,30 @@ pub const CHATS: &[&str] = &[
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const TOKEN_CHAT: &str = "chat";
|
pub const TOKEN_CHAT: &str = "chat";
|
||||||
|
pub const TOKEN_SYSTEM: &str = "system";
|
||||||
|
pub const TOKEN_WARN: &str = "warn";
|
||||||
|
pub const TOKEN_SET: &str = "set";
|
||||||
|
pub const TOKEN_IF: &str = "if";
|
||||||
|
pub const TOKEN_GOTO: &str = "goto";
|
||||||
|
pub const TOKEN_LABEL: &str = "label";
|
||||||
|
pub const TOKEN_SCRIPT: &str = "script";
|
||||||
|
//pub const TOKEN_TIMEOUT: &str = "TIMEOUT";
|
||||||
pub const LETTERS_PER_SECOND: f32 = 17.0;
|
pub const LETTERS_PER_SECOND: f32 = 17.0;
|
||||||
pub const TALKER_SPEED_FACTOR: f32 = settings::DEFAULT_CHAT_SPEED / LETTERS_PER_SECOND;
|
pub const TALKER_SPEED_FACTOR: f32 = settings::DEFAULT_CHAT_SPEED / LETTERS_PER_SECOND;
|
||||||
pub const CHAT_SPEED_MIN_LEN: f32 = 40.0;
|
pub const CHAT_SPEED_MIN_LEN: f32 = 40.0;
|
||||||
pub const NAME_FALLBACK: &str = "Unknown";
|
pub const NAME_FALLBACK: &str = "Unknown";
|
||||||
|
|
||||||
|
pub const NON_CHOICE_TOKENS: &[&str] = &[
|
||||||
|
TOKEN_CHAT,
|
||||||
|
TOKEN_SYSTEM,
|
||||||
|
TOKEN_WARN,
|
||||||
|
TOKEN_SET,
|
||||||
|
TOKEN_IF,
|
||||||
|
TOKEN_GOTO,
|
||||||
|
TOKEN_LABEL,
|
||||||
|
TOKEN_SCRIPT,
|
||||||
|
];
|
||||||
|
|
||||||
pub struct ChatPlugin;
|
pub struct ChatPlugin;
|
||||||
impl Plugin for ChatPlugin {
|
impl Plugin for ChatPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
|
@ -70,6 +89,21 @@ impl ChatDB {
|
||||||
return Err(format!("No chat with the conversation ID `{id}` was found."));
|
return Err(format!("No chat with the conversation ID `{id}` was found."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn search_choice(&self, yaml: &Yaml) -> Option<String> {
|
||||||
|
let non_choice_tokens = NON_CHOICE_TOKENS.to_vec();
|
||||||
|
if let Some(hash) = yaml.as_hash() {
|
||||||
|
for key in hash.keys() {
|
||||||
|
if let Yaml::String(key) = key {
|
||||||
|
if non_choice_tokens.contains(&key.as_str()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return Some(key.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn advance_chat(&self, chat: &mut Chat, event: &mut EventWriter<ChatEvent>) {
|
pub fn advance_chat(&self, chat: &mut Chat, event: &mut EventWriter<ChatEvent>) {
|
||||||
event.send(ChatEvent::DespawnAllChoices);
|
event.send(ChatEvent::DespawnAllChoices);
|
||||||
let conv = &self.0[chat.id].as_vec();
|
let conv = &self.0[chat.id].as_vec();
|
||||||
|
@ -77,15 +111,36 @@ impl ChatDB {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let conv = conv.unwrap();
|
let conv = conv.unwrap();
|
||||||
|
|
||||||
|
// Handle next entry in the chat list
|
||||||
|
let mut is_skipping_through = false;
|
||||||
chat.position += 1;
|
chat.position += 1;
|
||||||
if chat.position >= conv.len() {
|
if chat.position >= conv.len() {
|
||||||
event.send(ChatEvent::DisplayMessage("Disconnected.".to_string()));
|
event.send(ChatEvent::DisplayMessage("Disconnected.".to_string()));
|
||||||
event.send(ChatEvent::DespawnAllChats);
|
event.send(ChatEvent::DespawnAllChats);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Some(message) = conv[chat.position].as_str() {
|
else if let Some(_) = self.search_choice(&conv[chat.position]) {
|
||||||
|
is_skipping_through = true;
|
||||||
|
}
|
||||||
|
else if let Some(message) = conv[chat.position].as_str() {
|
||||||
event.send(ChatEvent::DisplayMessage(message.to_string()));
|
event.send(ChatEvent::DisplayMessage(message.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the immediately following entries are choices
|
||||||
|
let mut pos = chat.position + 1;
|
||||||
|
loop {
|
||||||
|
if is_skipping_through || pos >= conv.len() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if let Some(choice) = self.search_choice(&conv[pos]) {
|
||||||
|
event.send(ChatEvent::DisplayMessage(choice));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pos += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,10 @@
|
||||||
- Whatever... I didn't ask for this.:
|
- Whatever... I didn't ask for this.:
|
||||||
- goto: didntask
|
- goto: didntask
|
||||||
- TIMEOUT:
|
- TIMEOUT:
|
||||||
- How are you feeling?
|
|
||||||
- TIMEOUT:
|
- TIMEOUT:
|
||||||
|
|
||||||
|
|
||||||
- How are you feeling?
|
- How are you feeling?
|
||||||
|
|
||||||
|
|
||||||
- label: howru
|
- label: howru
|
||||||
- I feel quite cozy, this space suit feels like a second skin.:
|
- I feel quite cozy, this space suit feels like a second skin.:
|
||||||
- Hah, it does, doesn't it?
|
- Hah, it does, doesn't it?
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
- chat: ClippyTransSerenity
|
- chat: ClippyTransSerenity
|
||||||
- Welcome at StarTrans Cargo Services! You have reached Serenity Station.
|
- Welcome at StarTrans Cargo Services! You have reached Serenity Station.
|
||||||
- "Ready for a trip? Available bus stops: Oscillation Station, Metis Prime Station"
|
- "Ready for a trip? Available bus stops: Oscillation Station, Metis Prime Station"
|
||||||
- set busstop: serenity
|
- set: busstop serenity
|
||||||
- label: startransbusstop
|
- label: startransbusstop
|
||||||
- goto: EXIT
|
- goto: EXIT
|
||||||
- label: interesting
|
- label: interesting
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
- chat: ClippyTransMetis
|
- chat: ClippyTransMetis
|
||||||
- Welcome at StarTrans Cargo Services! You have reached Metis Prime Station.
|
- Welcome at StarTrans Cargo Services! You have reached Metis Prime Station.
|
||||||
- "Ready for a trip? Available bus stops: Oscillation Station, Serenity Station"
|
- "Ready for a trip? Available bus stops: Oscillation Station, Serenity Station"
|
||||||
- set busstop: metis
|
- set: busstop metis
|
||||||
- label: startransbusstop
|
- label: startransbusstop
|
||||||
- goto: EXIT
|
- goto: EXIT
|
||||||
- label: interesting
|
- label: interesting
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
- chat: ClippyTransOscillation
|
- chat: ClippyTransOscillation
|
||||||
- Welcome at StarTrans Cargo Services! You have reached Oscillation Station.
|
- Welcome at StarTrans Cargo Services! You have reached Oscillation Station.
|
||||||
- "Ready for a trip? Available bus stops: Serenity Station, Metis Prime Station"
|
- "Ready for a trip? Available bus stops: Serenity Station, Metis Prime Station"
|
||||||
- set busstop: oscillation
|
- set: busstop oscillation
|
||||||
- label: startransbusstop
|
- label: startransbusstop
|
||||||
- goto: EXIT
|
- goto: EXIT
|
||||||
- label: interesting
|
- label: interesting
|
||||||
|
|
Loading…
Reference in a new issue