generated from 2ndbeam/bevy-template
feat: Added Inventory and Item components
- Moved input tests into nested module - Added inventory tests
This commit is contained in:
parent
957717671a
commit
dab3134f15
4 changed files with 260 additions and 72 deletions
39
src/inventory/mod.rs
Normal file
39
src/inventory/mod.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
pub mod item;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Inventory {
|
||||
pub size: UVec2,
|
||||
}
|
||||
|
||||
impl Inventory {
|
||||
pub fn new(size: UVec2) -> Self {
|
||||
Self { size }
|
||||
}
|
||||
|
||||
pub fn can_fit(
|
||||
&self,
|
||||
item_query: Query<&item::Item>,
|
||||
contained_items: &Children,
|
||||
queried_size: UVec2,
|
||||
queried_position: UVec2,
|
||||
) -> bool {
|
||||
let item_corner = queried_size + queried_position;
|
||||
if item_corner.x > self.size.x || item_corner.y > self.size.y {
|
||||
return false;
|
||||
}
|
||||
|
||||
for entity in contained_items {
|
||||
let Ok(item) = item_query.get(*entity) else {
|
||||
warn!("Could not query inventory child ({entity}), probably not item?");
|
||||
continue;
|
||||
};
|
||||
|
||||
if item.overlaps(queried_size, queried_position) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue