From 0c622f28abd45d2a85d67b1f90dc923367994663 Mon Sep 17 00:00:00 2001 From: yuni Date: Wed, 12 Jun 2024 00:58:38 +0200 Subject: [PATCH] add debugging code to GameVar::evaluate_condition() --- src/var.rs | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/var.rs b/src/var.rs index 6f822a2..491b5a2 100644 --- a/src/var.rs +++ b/src/var.rs @@ -506,7 +506,7 @@ pub fn load_prefs() -> Preferences { } } -#[derive(Resource)] +#[derive(Resource, Debug)] pub struct GameVars { pub db: HashMap, } @@ -612,31 +612,51 @@ impl GameVars { // Check whether the two are identical. let mut left: String = parts[0].to_string(); if left.contains(SCOPE_SEPARATOR) { - left = self - .get(Self::normalize_varname(scope, left.as_str()).as_str()) - .unwrap_or("".to_string()); + let key = Self::normalize_varname(scope, left.as_str()); + let value = self.get(key.as_str()); + left = if let Some(value) = value { + value + } else { + warn!("Couldn't find variable `{key}` on left hand side of a condition"); + "".to_string() + }; } let mut right: String = parts[1].to_string(); if right.contains(SCOPE_SEPARATOR) { - right = self - .get(Self::normalize_varname(scope, right.as_str()).as_str()) - .unwrap_or("".to_string()); + let key = Self::normalize_varname(scope, right.as_str()); + let value = self.get(key.as_str()); + right = if let Some(value) = value { + value + } else { + warn!("Couldn't find variable `{key}` on right hand side of a condition"); + "".to_string() + }; } return left == right; } else { // Got something like "if $something != somethingelse bla bla" let mut left: String = parts[0].to_string(); if left.contains(SCOPE_SEPARATOR) { - left = self - .get(Self::normalize_varname(scope, left.as_str()).as_str()) - .unwrap_or("".to_string()); + let key = Self::normalize_varname(scope, left.as_str()); + let value = self.get(key.as_str()); + left = if let Some(value) = value { + value + } else { + warn!("Couldn't find variable `{key}` on left hand side of a condition"); + "".to_string() + }; } let mut right: String = parts[2..parts.len()].join(" ").to_string(); if right.contains(SCOPE_SEPARATOR) { - right = self - .get(Self::normalize_varname(scope, right.as_str()).as_str()) - .unwrap_or("".to_string()); + let key = Self::normalize_varname(scope, right.as_str()); + let value = self.get(key.as_str()); + right = if let Some(value) = value { + value + } else { + warn!("Couldn't find variable `{key}` on right hand side of a condition"); + "".to_string() + }; } let floats = (left.parse::(), right.parse::()); let operator: &str = parts[1];