implement "inlined" conditions (like - if $x > 4:
)
This commit is contained in:
parent
011938cadf
commit
d21f8b4b09
29
src/chat.rs
29
src/chat.rs
|
@ -27,6 +27,7 @@ pub const TOKEN_NOWAIT: &str = "nowait";
|
||||||
|
|
||||||
pub const TOKEN_INCLUDE: &str = "include";
|
pub const TOKEN_INCLUDE: &str = "include";
|
||||||
pub const TOKEN_GOTO_EXIT: &str = "EXIT";
|
pub const TOKEN_GOTO_EXIT: &str = "EXIT";
|
||||||
|
pub const TOKEN_IF_INLINE: &str = "if "; // for lines like `- if foo:`
|
||||||
|
|
||||||
pub const DEFAULT_SOUND: &str = "chat";
|
pub const DEFAULT_SOUND: &str = "chat";
|
||||||
pub const MAX_BRANCH_DEPTH: usize = 64;
|
pub const MAX_BRANCH_DEPTH: usize = 64;
|
||||||
|
@ -242,6 +243,9 @@ impl ChatDB {
|
||||||
if non_choice_tokens.contains(&key.as_str()) {
|
if non_choice_tokens.contains(&key.as_str()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if key.as_str().starts_with(TOKEN_IF_INLINE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
result = Some((key.into(), map[key].clone(), nowait));
|
result = Some((key.into(), map[key].clone(), nowait));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -354,16 +358,12 @@ impl ChatDB {
|
||||||
result = Some(Value::String(value_string.into()));
|
result = Some(Value::String(value_string.into()));
|
||||||
}
|
}
|
||||||
Some(Value::Mapping(mapping)) => {
|
Some(Value::Mapping(mapping)) => {
|
||||||
if let Some(branch) = mapping.get(TOKEN_THEN) {
|
result = Some(Value::Mapping(mapping.clone()));
|
||||||
result = Some(Value::Mapping(mapping.clone()));
|
for value in mapping.values() {
|
||||||
next_pointer = Some(branch.clone());
|
if let Some(list) = value.as_sequence() {
|
||||||
}
|
next_pointer = Some(Value::Sequence(list.clone()));
|
||||||
else if let Some((_choicetext, subconversation, _)) = self.search_choice(value) {
|
break;
|
||||||
result = Some(Value::Mapping(mapping.clone()));
|
}
|
||||||
next_pointer = Some(subconversation);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = Some(Value::Mapping(mapping.clone()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -447,6 +447,15 @@ impl ChatDB {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(key) = key {
|
||||||
|
if key.starts_with(TOKEN_IF_INLINE) {
|
||||||
|
let condition: &str = &key[TOKEN_IF_INLINE.len()..];
|
||||||
|
let mut pos = chat.position.clone();
|
||||||
|
pos.push(0);
|
||||||
|
event.send(ChatEvent::GotoIf(condition.into(), pos));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second pass
|
// Second pass
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
|
|
||||||
|
|
||||||
- chat: Icarus
|
- chat: Icarus
|
||||||
- if: $met
|
- if $met:
|
||||||
then:
|
|
||||||
- Oh hey, you're back!
|
- Oh hey, you're back!
|
||||||
- How are you doing?
|
- How are you doing?
|
||||||
- goto: howru
|
- goto: howru
|
||||||
|
|
Loading…
Reference in a new issue