organization and buidings db

This commit is contained in:
2024-06-04 09:18:31 -04:00
parent ee0b17f4b6
commit c31c2fb908
21 changed files with 453 additions and 348 deletions

13
game/buildings/Cargo.toml Normal file
View File

@@ -0,0 +1,13 @@
[package]
name = "buildings"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = "0.13.2"
world_generation = {path = "../../engine/world_generation"}
[features]
tracing = []

View File

@@ -0,0 +1,65 @@
use bevy::prelude::*;
use world_generation::hex_utils::HexCoord;
#[derive(Resource)]
pub struct BuildingDatabase {
pub chunks: Vec<BuildingChunk>,
}
impl BuildingDatabase {
pub fn new(size: UVec2) -> Self {
let mut db = BuildingDatabase {
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,
}
impl BuildingEntry {
pub fn new(coord: HexCoord, entity: Entity) -> Self {
return BuildingEntry { coord, entity };
}
}

View File

@@ -0,0 +1 @@
pub mod buildings_database;