diff --git a/pixlib_parser/src/runner/classes/behavior.rs b/pixlib_parser/src/runner/classes/behavior.rs index bfc4d43..6574eb1 100644 --- a/pixlib_parser/src/runner/classes/behavior.rs +++ b/pixlib_parser/src/runner/classes/behavior.rs @@ -286,7 +286,7 @@ impl BehaviorState { CnvContent::ComplexCondition(c) => c, _ => return Err(RunnerError::ExpectedConditionObject.into()), }; - if !condition.check()? { + if !condition.check(Some(context.clone()))? { return Ok(CnvValue::Null); } } diff --git a/pixlib_parser/src/runner/classes/complexcondition.rs b/pixlib_parser/src/runner/classes/complexcondition.rs index fb8b801..a7faaf8 100644 --- a/pixlib_parser/src/runner/classes/complexcondition.rs +++ b/pixlib_parser/src/runner/classes/complexcondition.rs @@ -71,8 +71,13 @@ impl ComplexCondition { } impl GeneralCondition for ComplexCondition { - fn check(&self) -> anyhow::Result { - let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); + fn check(&self, context: Option) -> anyhow::Result { + let context = context + .map(|c| c.with_current_object(self.parent.clone())) + .unwrap_or(RunnerContext::new_minimal( + &self.parent.parent.runner, + &self.parent, + )); self.state.borrow().check(context) } } @@ -191,17 +196,17 @@ impl ComplexConditionState { }; let result = match complex_condition.operator { ComplexConditionOperator::And => { - if !left.check()? { + if !left.check(Some(context.clone()))? { Ok(false) } else { - Ok(right.check()?) + Ok(right.check(Some(context.clone()))?) } } ComplexConditionOperator::Or => { - if left.check()? { + if left.check(Some(context.clone()))? { Ok(true) } else { - Ok(right.check()?) + Ok(right.check(Some(context.clone()))?) } } }; diff --git a/pixlib_parser/src/runner/classes/condition.rs b/pixlib_parser/src/runner/classes/condition.rs index a398c40..2375895 100644 --- a/pixlib_parser/src/runner/classes/condition.rs +++ b/pixlib_parser/src/runner/classes/condition.rs @@ -74,8 +74,13 @@ impl Condition { } impl GeneralCondition for Condition { - fn check(&self) -> anyhow::Result { - let context = RunnerContext::new_minimal(&self.parent.parent.runner, &self.parent); + fn check(&self, context: Option) -> anyhow::Result { + let context = context + .map(|c| c.with_current_object(self.parent.clone())) + .unwrap_or(RunnerContext::new_minimal( + &self.parent.parent.runner, + &self.parent, + )); self.state.borrow().check(context) } } diff --git a/pixlib_parser/src/runner/classes/mod.rs b/pixlib_parser/src/runner/classes/mod.rs index 27228be..31d48a3 100644 --- a/pixlib_parser/src/runner/classes/mod.rs +++ b/pixlib_parser/src/runner/classes/mod.rs @@ -111,7 +111,7 @@ impl CnvTypeFactory { } pub trait GeneralCondition { - fn check(&self) -> anyhow::Result; + fn check(&self, context: Option) -> anyhow::Result; } pub trait GeneralGraphics {