Skip to content

Commit

Permalink
Make sure trigger_ability spends resource costs (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile authored Sep 4, 2024
1 parent a83bb0a commit 45907c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit 45907c9

Please sign in to comment.