From 3d22643afc22906420dae32a0c1f38c24ee4ff5f Mon Sep 17 00:00:00 2001 From: Zerthox Date: Fri, 9 Aug 2024 15:28:27 +0200 Subject: [PATCH] Debug filter trigger states --- src/elements/common.rs | 1 - src/elements/element/mod.rs | 1 + src/trigger/filter.rs | 10 +++++++++- src/trigger/memo.rs | 5 +++++ src/trigger/player/mod.rs | 12 ++++++++++-- src/trigger/player/traits.rs | 4 ++++ 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/elements/common.rs b/src/elements/common.rs index 8ac5eeb..cb539de 100644 --- a/src/elements/common.rs +++ b/src/elements/common.rs @@ -228,7 +228,6 @@ impl RenderOptions for Common { impl RenderDebug for Common { fn render_debug(&mut self, ui: &Ui) { ui.text(format!("Id: {}", self.id)); - debug_optional(ui, "Trigger", self.trigger.active()); } } diff --git a/src/elements/element/mod.rs b/src/elements/element/mod.rs index 2fed1c1..6f107bd 100644 --- a/src/elements/element/mod.rs +++ b/src/elements/element/mod.rs @@ -192,6 +192,7 @@ impl Element { impl RenderDebug for Element { fn render_debug(&mut self, ui: &Ui) { self.common.render_debug(ui); + self.filter.render_debug(ui); self.kind.render_debug(ui); } } diff --git a/src/trigger/filter.rs b/src/trigger/filter.rs index 6ca4552..32dd183 100644 --- a/src/trigger/filter.rs +++ b/src/trigger/filter.rs @@ -1,8 +1,9 @@ use super::{map_old::MapTriggerOld, memo::Memo, MapTrigger, PlayerTrigger, Trigger}; use crate::{ context::{Context, ContextUpdate, EditState}, + render_util::debug_optional, serde_migrate::migrate, - traits::RenderOptions, + traits::{RenderDebug, RenderOptions}, }; use nexus::imgui::Ui; use serde::{Deserialize, Serialize}; @@ -44,3 +45,10 @@ impl RenderOptions for FilterTrigger { } } } + +impl RenderDebug for FilterTrigger { + fn render_debug(&mut self, ui: &Ui) { + ui.text(format!("Trait filter: {}", self.player.traits.memo())); + debug_optional(ui, "Map filter:", self.map.get()); + } +} diff --git a/src/trigger/memo.rs b/src/trigger/memo.rs index a0dcf6c..89a14de 100644 --- a/src/trigger/memo.rs +++ b/src/trigger/memo.rs @@ -38,6 +38,11 @@ where } } + /// Retrieves the memoized state, if initialized. + pub fn get(&self) -> Option { + self.cache + } + /// Clears the memoized state. pub fn clear(&mut self) { self.cache = None; diff --git a/src/trigger/player/mod.rs b/src/trigger/player/mod.rs index 0590db1..fbf6d76 100644 --- a/src/trigger/player/mod.rs +++ b/src/trigger/player/mod.rs @@ -43,14 +43,22 @@ impl PlayerTrigger { } } } + + pub fn specs_active(&self, ctx: &Context) -> bool { + check_bitflags_optional(self.specs, ctx.player.spec.ok()) + } + + pub fn mounts_active(&self, ctx: &Context) -> bool { + check_bitflags_optional(self.mounts, ctx.player.mount.ok()) + } } impl Trigger for PlayerTrigger { fn is_active(&mut self, ctx: &Context) -> bool { self.traits.is_active(ctx) && self.combat.is_active(ctx) - && check_bitflags_optional(self.specs, ctx.player.spec.ok()) - && check_bitflags_optional(self.mounts, ctx.player.mount.ok()) + && self.specs_active(ctx) + && self.mounts_active(ctx) } } diff --git a/src/trigger/player/traits.rs b/src/trigger/player/traits.rs index 0ea8bd0..3e45c3e 100644 --- a/src/trigger/player/traits.rs +++ b/src/trigger/player/traits.rs @@ -26,6 +26,10 @@ impl TraitTrigger { false }; } + + pub fn memo(&self) -> bool { + self.memo + } } impl Trigger for TraitTrigger {