add debugging code to GameVar::evaluate_condition()

This commit is contained in:
yuni 2024-06-12 00:58:38 +02:00
parent 625bf21c84
commit 0c622f28ab

View file

@ -506,7 +506,7 @@ pub fn load_prefs() -> Preferences {
} }
} }
#[derive(Resource)] #[derive(Resource, Debug)]
pub struct GameVars { pub struct GameVars {
pub db: HashMap<String, String>, pub db: HashMap<String, String>,
} }
@ -612,31 +612,51 @@ impl GameVars {
// Check whether the two are identical. // Check whether the two are identical.
let mut left: String = parts[0].to_string(); let mut left: String = parts[0].to_string();
if left.contains(SCOPE_SEPARATOR) { if left.contains(SCOPE_SEPARATOR) {
left = self let key = Self::normalize_varname(scope, left.as_str());
.get(Self::normalize_varname(scope, left.as_str()).as_str()) let value = self.get(key.as_str());
.unwrap_or("".to_string()); 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(); let mut right: String = parts[1].to_string();
if right.contains(SCOPE_SEPARATOR) { if right.contains(SCOPE_SEPARATOR) {
right = self let key = Self::normalize_varname(scope, right.as_str());
.get(Self::normalize_varname(scope, right.as_str()).as_str()) let value = self.get(key.as_str());
.unwrap_or("".to_string()); 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; return left == right;
} else { } else {
// Got something like "if $something != somethingelse bla bla" // Got something like "if $something != somethingelse bla bla"
let mut left: String = parts[0].to_string(); let mut left: String = parts[0].to_string();
if left.contains(SCOPE_SEPARATOR) { if left.contains(SCOPE_SEPARATOR) {
left = self let key = Self::normalize_varname(scope, left.as_str());
.get(Self::normalize_varname(scope, left.as_str()).as_str()) let value = self.get(key.as_str());
.unwrap_or("".to_string()); 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(); let mut right: String = parts[2..parts.len()].join(" ").to_string();
if right.contains(SCOPE_SEPARATOR) { if right.contains(SCOPE_SEPARATOR) {
right = self let key = Self::normalize_varname(scope, right.as_str());
.get(Self::normalize_varname(scope, right.as_str()).as_str()) let value = self.get(key.as_str());
.unwrap_or("".to_string()); 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::<f64>(), right.parse::<f64>()); let floats = (left.parse::<f64>(), right.parse::<f64>());
let operator: &str = parts[1]; let operator: &str = parts[1];