Split crate into shared logic library and binary crate (#52)

This commit is contained in:
PROMETHIA-27
2025-06-28 16:53:40 -04:00
committed by GitHub
parent 5d00cede94
commit b93c0e4d96
64 changed files with 514 additions and 104 deletions

View File

@@ -0,0 +1,39 @@
use crate::heads::HeadState;
use bevy::prelude::*;
#[derive(Clone, Copy, Debug, PartialEq, Reflect, Default)]
pub struct UiHeadState {
pub head: usize,
pub health: f32,
pub ammo: f32,
pub reloading: Option<f32>,
}
impl UiHeadState {
pub fn damage(&self) -> f32 {
1. - self.health
}
pub fn ammo_used(&self) -> f32 {
1. - self.ammo
}
pub fn reloading(&self) -> Option<f32> {
self.reloading
}
pub(crate) fn new(value: HeadState, time: f32) -> Self {
let reloading = if value.has_ammo() {
None
} else {
Some((time - value.last_use) / value.reload_duration)
};
Self {
head: value.head,
ammo: value.ammo as f32 / value.ammo_max as f32,
health: value.health as f32 / value.health_max as f32,
reloading,
}
}
}