From 05769c988c527f843acccd271a643e84bddc24bf Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 14 Apr 2024 23:57:58 +0200 Subject: [PATCH] implement "if: ~value:" to negate it. ("!" doesnt work for YAML reasons) --- src/chats/serenity.yaml | 4 +++- src/var.rs | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/chats/serenity.yaml b/src/chats/serenity.yaml index fda5634..d54540f 100644 --- a/src/chats/serenity.yaml +++ b/src/chats/serenity.yaml @@ -180,11 +180,13 @@ - Please find yourself a cozy place to drift. - Do you have a 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. - But I can't get overworked, can I? - I'm running this joint all by myself, after all. - Apart of good ol' Clippy. + - set: $reservation - goto: reservation - No reservation. Can I still buy something?: - '"Buy"? Ah, this old earth thing.' diff --git a/src/var.rs b/src/var.rs index 69f7bd1..35d8552 100644 --- a/src/var.rs +++ b/src/var.rs @@ -10,6 +10,7 @@ pub const TOKEN_GREATER_THAN: &str = ">"; pub const TOKEN_LESS_THAN: &str = "<"; pub const TOKEN_GREATER_EQUALS: &str = ">="; pub const TOKEN_LESS_EQUALS: &str = "<="; +pub const TOKEN_NEGATE: &str = "~"; pub const DEFAULT_CHAT_SPEED: f32 = 10.0; @@ -297,13 +298,18 @@ impl GameVars { // Got something like "if $somevar:". // Check whether the variable evaluates to true. let part = parts[0]; + let (part, negate) = if part.starts_with(TOKEN_NEGATE) { + (&part[1..], true) + } else { + (part, false) + }; if part.contains(SCOPE_SEPARATOR) { let part = Self::normalize_varname(scope, part); let value_bool = self.getb(part.as_str()); - return value_bool; + return value_bool ^ negate; } else { - return Self::evaluate_str_as_bool(part); + return Self::evaluate_str_as_bool(part) ^ negate; } } else if parts.len() == 2 {