Skip to content

Commit

Permalink
Debug filter trigger states
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Aug 9, 2024
1 parent ba8a919 commit 3d22643
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/elements/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
1 change: 1 addition & 0 deletions src/elements/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/trigger/filter.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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());
}
}
5 changes: 5 additions & 0 deletions src/trigger/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ where
}
}

/// Retrieves the memoized state, if initialized.
pub fn get(&self) -> Option<bool> {
self.cache
}

/// Clears the memoized state.
pub fn clear(&mut self) {
self.cache = None;
Expand Down
12 changes: 10 additions & 2 deletions src/trigger/player/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/trigger/player/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ impl TraitTrigger {
false
};
}

pub fn memo(&self) -> bool {
self.memo
}
}

impl Trigger for TraitTrigger {
Expand Down

0 comments on commit 3d22643

Please sign in to comment.