WIP if-branches in chats
This commit is contained in:
parent
5df3f66ea6
commit
b4ff95c3be
20
src/chat.rs
20
src/chat.rs
|
@ -18,6 +18,7 @@ pub const TOKEN_WARN: &str = "warn";
|
|||
pub const TOKEN_SLEEP: &str = "sleep";
|
||||
pub const TOKEN_SET: &str = "set";
|
||||
pub const TOKEN_IF: &str = "if";
|
||||
pub const TOKEN_THEN: &str = "then";
|
||||
pub const TOKEN_GOTO: &str = "goto";
|
||||
pub const TOKEN_LABEL: &str = "label";
|
||||
pub const TOKEN_SCRIPT: &str = "script";
|
||||
|
@ -43,6 +44,7 @@ pub const NON_CHOICE_TOKENS: &[&str] = &[
|
|||
TOKEN_SLEEP,
|
||||
TOKEN_SET,
|
||||
TOKEN_IF,
|
||||
TOKEN_THEN,
|
||||
TOKEN_GOTO,
|
||||
TOKEN_LABEL,
|
||||
TOKEN_SCRIPT,
|
||||
|
@ -118,6 +120,7 @@ pub enum ChatEvent {
|
|||
RunScript(String),
|
||||
SleepSeconds(f64),
|
||||
SetVariable(String),
|
||||
GotoIf(String, ChatPos),
|
||||
}
|
||||
|
||||
// This is the only place where any YAML interaction should be happening.
|
||||
|
@ -351,7 +354,11 @@ impl ChatDB {
|
|||
result = Some(Value::String(value_string.into()));
|
||||
}
|
||||
Some(Value::Mapping(mapping)) => {
|
||||
if let Some((_choicetext, subconversation, _)) = self.search_choice(value) {
|
||||
if let Some(branch) = mapping.get(TOKEN_THEN) {
|
||||
result = Some(Value::Mapping(mapping.clone()));
|
||||
next_pointer = Some(branch.clone());
|
||||
}
|
||||
else if let Some((_choicetext, subconversation, _)) = self.search_choice(value) {
|
||||
result = Some(Value::Mapping(mapping.clone()));
|
||||
next_pointer = Some(subconversation);
|
||||
}
|
||||
|
@ -430,7 +437,11 @@ impl ChatDB {
|
|||
for (key, value) in &map {
|
||||
let key = key.as_str();
|
||||
match (key, value) {
|
||||
(Some(TOKEN_IF), _) => {} // TODO
|
||||
(Some(TOKEN_IF), Value::String(condition)) => {
|
||||
let mut pos = chat.position.clone();
|
||||
pos.push(0);
|
||||
event.send(ChatEvent::GotoIf(condition.into(), pos));
|
||||
}
|
||||
(Some(TOKEN_SOUND), Value::String(sound_name)) => {
|
||||
sound = sound_name.clone();
|
||||
}
|
||||
|
@ -667,6 +678,11 @@ pub fn handle_chat_events(
|
|||
vars.set_in_scope(&chat.talker.actor_id, string, "".into());
|
||||
}
|
||||
}
|
||||
ChatEvent::GotoIf(condition, goto) => {
|
||||
if condition != "" {
|
||||
chat.position = goto.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,14 @@
|
|||
|
||||
|
||||
- chat: Icarus
|
||||
- if:
|
||||
then:
|
||||
- Oh hey, you're back!
|
||||
- Nice to see you again!
|
||||
- goto: back
|
||||
- Oh hey, you're awake!
|
||||
- set: talked_before
|
||||
- label: back
|
||||
- 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.
|
||||
- Thank you!:
|
||||
|
|
Loading…
Reference in a new issue