buildings

This commit is contained in:
2024-06-29 19:00:29 -04:00
parent 805f50e40f
commit 7ff3638eff
17 changed files with 90 additions and 31 deletions

View File

@@ -0,0 +1,98 @@
use bevy::prelude::*;
use world_generation::hex_utils::HexCoord;
#[derive(Resource)]
pub struct BuildingMap {
pub chunks: Vec<BuildingChunk>,
}
impl BuildingMap {
pub fn new(size: UVec2) -> Self {
let mut db = BuildingMap {
chunks: Vec::with_capacity(size.length_squared() as usize),
};
for y in 0..size.y as i32 {
for x in 0..size.x as i32 {
let offset = IVec2::new(x, y);
let index = (x + y * size.x as i32) as usize;
db.chunks.push(BuildingChunk::new(offset, index));
}
}
return db;
}
pub fn get_buildings_in_range(&self, coord: &HexCoord, radius: usize) -> Option<Vec<&BuildingEntry>> {
assert!(radius != 0, "Radius cannot be zero");
todo!();
}
pub fn get_building(&self, coord: &HexCoord) -> Option<&BuildingEntry> {
todo!();
}
}
pub struct BuildingChunk {
pub entries: Vec<BuildingChunk>,
pub index: usize,
pub offset: IVec2,
}
impl BuildingChunk {
pub fn new(offset: IVec2, index: usize) -> Self {
return BuildingChunk {
entries: Vec::new(),
index,
offset,
};
}
pub fn get_building(&self, coord: &HexCoord) -> Option<&BuildingEntry> {
todo!();
}
}
pub struct BuildingEntry {
pub coord: HexCoord,
pub entity: Entity,
pub is_main: bool,
pub main_entity: Option<Entity>,
pub has_children: bool,
pub child_entities: Option<Vec<Entity>>,
}
impl BuildingEntry {
pub fn new(coord: HexCoord, entity: Entity) -> Self {
return BuildingEntry {
coord,
entity,
child_entities: None,
has_children: false,
main_entity: None,
is_main: true,
};
}
pub fn new_with_children(coord: HexCoord, entity: Entity, children: Vec<Entity>) -> BuildingEntry {
return BuildingEntry {
coord,
entity,
child_entities: Some(children),
has_children: true,
main_entity: None,
is_main: true,
};
}
pub fn new_with_parent(coord: HexCoord, entity: Entity, main: Entity) -> BuildingEntry {
return BuildingEntry {
coord,
entity,
child_entities: None,
has_children: false,
main_entity: Some(main),
is_main: false,
};
}
}