Crates.io | game_stat |
lib.rs | game_stat |
version | 0.2.2 |
source | src |
created_at | 2022-03-13 17:16:05.661371 |
updated_at | 2023-05-29 19:42:47.495889 |
description | a library for handling stats that can change with modifiers, most commonly seen in games |
homepage | |
repository | https://github.com/TanTanDev/game_stat.git |
max_upload_size | |
id | 549293 |
size | 52,630 |
game_stat
is a small Rust library for handling stats that can change with modifiers. Equipped an epic sword? Then your attack stats could increase by 40. Received a debuff? Your movement speed could decrease by 50%.
let mut armor_stat: Stat<2> = Stat::new(10f32);
{
let _modifier_handle = armor_stat.add_modifier(StatModifier::Flat(5f32));
println!("armor_stat is: {} it should be 15!", armor_stat.value());
}
println!("armor_stat is: {}, It should be 10!", armor_stat.value());
Stat<2>
This library uses TinyVec internally to hold modifiers (for optimization). A value of 2 means we can hold 2 modifiers on the stack, if exceeded we'll internally move them to the heap.armor_stat.value()
returns our stat value based on what modifiers are active._modifier_handle
exists, which is why our value goes back to 10 when it gets dropped from the stack.stat.remove_modifier()
. This library has no such feature, instead a modifier is valid as long as a handle to it exists. It's a cool idea, but I don't know yet if this design choice will be practical.stat.add_modifier_with_order()
instead of stat.add_modifier()
.No major project has been completed with this yet.
I'm not sure of it's stability/performance, considering I'm internally using mutex with sync
feature enabled, and interior mutability.
I'm currently testing this library for a tower defence game. Time will tell :)
gamestat is free and open source! All code in this repository is dual-licensed under either:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.