This commit is contained in:
2024-06-10 21:28:04 -04:00
parent 05f9fa3143
commit 8cecad83c2
12 changed files with 76 additions and 9 deletions

View File

@@ -10,6 +10,7 @@ bevy = "0.13.2"
world_generation = {path = "../../engine/world_generation"}
shared = {path = "../shared"}
bevy_rapier3d = "0.26.0"
serde = {version="1.0.203", features=["derive"]}
[features]
tracing = []

View File

@@ -0,0 +1,18 @@
use bevy::prelude::*;
use serde::{Deserialize, Serialize};
use shared::resource::ResourceIdentifier;
use crate::footprint::BuildingFootprint;
#[derive(Resource, Serialize, Deserialize)]
pub struct BuildingAsset {
pub name: String,
pub description: String,
pub footprint: BuildingFootprint,
pub prefab_path: String,
pub prefab: (),
pub cost: Vec<ResourceIdentifier>,
pub consumption: Vec<ResourceIdentifier>,
pub production: Vec<ResourceIdentifier>,
}

View File

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

View File

@@ -0,0 +1,32 @@
use bevy::math::{IVec2, Vec3Swizzles};
use serde::{Deserialize, Serialize};
use world_generation::hex_utils::HexCoord;
#[derive(Serialize, Deserialize)]
pub struct BuildingFootprint {
pub footprint: Vec<IVec2>,
}
impl BuildingFootprint {
pub fn get_footprint(&self, center: &HexCoord) -> Vec<HexCoord> {
let c = center.hex.xy();
return self.footprint.iter().map(|p| HexCoord::from_hex(*p + c)).collect();
}
pub fn get_footprint_rotated(&self, center: &HexCoord, rotation: i32) -> Vec<HexCoord> {
let c = center.hex.xy();
return self
.footprint
.iter()
.map(|p| HexCoord::from_hex(*p + c).rotate_around(center, rotation))
.collect();
}
pub fn get_neighbors(&self, center: &HexCoord) -> Vec<HexCoord> {
todo!()
}
pub fn get_neighbors_rotated(&self, center: &HexCoord, rotation: i32) -> Vec<HexCoord> {
todo!();
}
}

View File

@@ -1,4 +1,6 @@
pub mod buildings_database;
pub mod assets;
pub mod building_plugin;
pub mod buildings_database;
pub mod footprint;
pub use building_plugin::*;
pub use building_plugin::*;