implement "if: ~value:" to negate it. ("!" doesnt work for YAML reasons)
This commit is contained in:
parent
27ada34377
commit
05769c988c
|
@ -180,11 +180,13 @@
|
||||||
- Please find yourself a cozy place to drift.
|
- Please find yourself a cozy place to drift.
|
||||||
- Do you have a reservation?
|
- Do you have a reservation?
|
||||||
- label: reservation
|
- label: reservation
|
||||||
- Reservation? Is there not enough space for everybody?:
|
- if: ~$reservation
|
||||||
|
Reservation? Is there not enough space for everybody?:
|
||||||
- Ah, space there is.
|
- Ah, space there is.
|
||||||
- But I can't get overworked, can I?
|
- But I can't get overworked, can I?
|
||||||
- I'm running this joint all by myself, after all.
|
- I'm running this joint all by myself, after all.
|
||||||
- Apart of good ol' Clippy.
|
- Apart of good ol' Clippy.
|
||||||
|
- set: $reservation
|
||||||
- goto: reservation
|
- goto: reservation
|
||||||
- No reservation. Can I still buy something?:
|
- No reservation. Can I still buy something?:
|
||||||
- '"Buy"? Ah, this old earth thing.'
|
- '"Buy"? Ah, this old earth thing.'
|
||||||
|
|
10
src/var.rs
10
src/var.rs
|
@ -10,6 +10,7 @@ pub const TOKEN_GREATER_THAN: &str = ">";
|
||||||
pub const TOKEN_LESS_THAN: &str = "<";
|
pub const TOKEN_LESS_THAN: &str = "<";
|
||||||
pub const TOKEN_GREATER_EQUALS: &str = ">=";
|
pub const TOKEN_GREATER_EQUALS: &str = ">=";
|
||||||
pub const TOKEN_LESS_EQUALS: &str = "<=";
|
pub const TOKEN_LESS_EQUALS: &str = "<=";
|
||||||
|
pub const TOKEN_NEGATE: &str = "~";
|
||||||
|
|
||||||
pub const DEFAULT_CHAT_SPEED: f32 = 10.0;
|
pub const DEFAULT_CHAT_SPEED: f32 = 10.0;
|
||||||
|
|
||||||
|
@ -297,13 +298,18 @@ impl GameVars {
|
||||||
// Got something like "if $somevar:".
|
// Got something like "if $somevar:".
|
||||||
// Check whether the variable evaluates to true.
|
// Check whether the variable evaluates to true.
|
||||||
let part = parts[0];
|
let part = parts[0];
|
||||||
|
let (part, negate) = if part.starts_with(TOKEN_NEGATE) {
|
||||||
|
(&part[1..], true)
|
||||||
|
} else {
|
||||||
|
(part, false)
|
||||||
|
};
|
||||||
if part.contains(SCOPE_SEPARATOR) {
|
if part.contains(SCOPE_SEPARATOR) {
|
||||||
let part = Self::normalize_varname(scope, part);
|
let part = Self::normalize_varname(scope, part);
|
||||||
let value_bool = self.getb(part.as_str());
|
let value_bool = self.getb(part.as_str());
|
||||||
return value_bool;
|
return value_bool ^ negate;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return Self::evaluate_str_as_bool(part);
|
return Self::evaluate_str_as_bool(part) ^ negate;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if parts.len() == 2 {
|
} else if parts.len() == 2 {
|
||||||
|
|
Loading…
Reference in a new issue