Skip to content

Commit

Permalink
Ignore resources with 0 max
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Jul 23, 2024
1 parent f1a7297 commit 3e4dbb0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/trigger/progress/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ impl From<&Buff> for ProgressActive {
}
}

impl From<Resource> for ProgressActive {
fn from(resource: Resource) -> Self {
Self::Resource(resource)
impl TryFrom<Resource> for ProgressActive {
type Error = ();

fn try_from(resource: Resource) -> Result<Self, Self::Error> {
if resource.max != 0 {
Ok(Self::Resource(resource))
} else {
Err(())
}
}
}
10 changes: 5 additions & 5 deletions src/trigger/progress/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl ProgressSource {

pub fn progress(&self, ctx: &Context) -> Option<ProgressActive> {
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;
Expand All @@ -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(),
}
}

Expand Down

0 comments on commit 3e4dbb0

Please sign in to comment.