From 3e4dbb0a345be43f7ec41370c8561a0e17955094 Mon Sep 17 00:00:00 2001 From: Zerthox Date: Tue, 23 Jul 2024 19:32:13 +0200 Subject: [PATCH] Ignore resources with 0 max --- src/trigger/progress/active.rs | 12 +++++++++--- src/trigger/progress/source.rs | 10 +++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/trigger/progress/active.rs b/src/trigger/progress/active.rs index ab2e810..db50360 100644 --- a/src/trigger/progress/active.rs +++ b/src/trigger/progress/active.rs @@ -111,8 +111,14 @@ impl From<&Buff> for ProgressActive { } } -impl From for ProgressActive { - fn from(resource: Resource) -> Self { - Self::Resource(resource) +impl TryFrom for ProgressActive { + type Error = (); + + fn try_from(resource: Resource) -> Result { + if resource.max != 0 { + Ok(Self::Resource(resource)) + } else { + Err(()) + } } } diff --git a/src/trigger/progress/source.rs b/src/trigger/progress/source.rs index 44fcaf1..13a18f0 100644 --- a/src/trigger/progress/source.rs +++ b/src/trigger/progress/source.rs @@ -52,7 +52,7 @@ impl ProgressSource { pub fn progress(&self, ctx: &Context) -> Option { match self { - Self::None => Some(Resource { current: 1, max: 1 }.into()), + Self::None => Some(ProgressActive::Resource(Resource { current: 1, max: 1 })), Self::Buff(id) => ctx.buff(*id).map(Into::into), Self::AnyBuff(ids) => { let mut stacks = 0; @@ -71,10 +71,10 @@ impl ProgressSource { runout, }) } - Self::Health => ctx.resources().map(|res| res.health.clone().into()), - Self::Barrier => ctx.resources().map(|res| res.barrier.clone().into()), - Self::PrimaryResource => ctx.resources().map(|res| res.primary.clone().into()), - Self::SecondaryResource => ctx.resources().map(|res| res.secondary.clone().into()), + Self::Health => ctx.resources()?.health.clone().try_into().ok(), + Self::Barrier => ctx.resources()?.barrier.clone().try_into().ok(), + Self::PrimaryResource => ctx.resources()?.primary.clone().try_into().ok(), + Self::SecondaryResource => ctx.resources()?.secondary.clone().try_into().ok(), } }