Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure trigger_ability spends resource costs #64

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
- `ready_no_cost` and `trigger_no_cost` have been added to `Abilitylike`
- when working with multiple resource pools, you should pass in `NullPool` as the type argument for `AbilityState`

## Bugs (0.9)

- `Actionlike::trigger` and friends now expends resource costs correctly
- if you were working around this bug, remember to remove your workaround to avoid double-spending!

## Version 0.8

- now supports Bevy 0.14
Expand Down
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ pub fn trigger_ability<P: Pool>(
ability_ready(
charges.as_deref(),
cooldown.as_deref(),
pool.map(|p| &*p),
pool.as_deref(),
cost,
)?;

Expand All @@ -241,6 +241,14 @@ pub fn trigger_ability<P: Pool>(
cooldown.trigger()?;
}

if let Some(pool) = pool {
if let Some(cost) = cost {
let _pool_result = pool.expend(cost);
// This is good to check, but panics in release mode are miserable
debug_assert!(_pool_result.is_ok());
}
}

Ok(())
}

Expand Down
Loading