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

10
Cargo.lock generated
View File

@@ -1327,6 +1327,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"bevy", "bevy",
"bevy_rapier3d", "bevy_rapier3d",
"serde",
"shared", "shared",
"world_generation", "world_generation",
] ]
@@ -3745,18 +3746,18 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.197" version = "1.0.203"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.197" version = "1.0.203"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -3788,6 +3789,7 @@ name = "shared"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bevy", "bevy",
"serde",
] ]
[[package]] [[package]]

View File

@@ -6,6 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
serde = "1.0.197" serde = "1.0.203"
serde_json = "1.0.115" serde_json = "1.0.115"
bevy = "0.13.2" bevy = "0.13.2"

View File

@@ -8,7 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
bevy = "0.13.2" bevy = "0.13.2"
noise = "0.9.0" noise = "0.9.0"
serde = {version="1.0.197", features=["derive"]} serde = {version="1.0.203", features=["derive"]}
serde_json = "1.0.115" serde_json = "1.0.115"
asset_loader = {path = "../asset_loader"} asset_loader = {path = "../asset_loader"}
rayon = "1.10.0" rayon = "1.10.0"

View File

@@ -10,6 +10,7 @@ bevy = "0.13.2"
world_generation = {path = "../../engine/world_generation"} world_generation = {path = "../../engine/world_generation"}
shared = {path = "../shared"} shared = {path = "../shared"}
bevy_rapier3d = "0.26.0" bevy_rapier3d = "0.26.0"
serde = {version="1.0.203", features=["derive"]}
[features] [features]
tracing = [] 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 building_plugin;
pub mod buildings_database;
pub mod footprint;
pub use building_plugin::*; pub use building_plugin::*;

View File

@@ -20,9 +20,11 @@ fn main() {
primary_window: Some(Window { primary_window: Some(Window {
title: "Phos".into(), title: "Phos".into(),
name: Some("phos".into()), name: Some("phos".into()),
#[cfg(debug_assertions)]
resolution: (1920., 1080.).into(), resolution: (1920., 1080.).into(),
present_mode: PresentMode::AutoNoVsync, present_mode: PresentMode::AutoNoVsync,
// mode: bevy::window::WindowMode::BorderlessFullscreen, #[cfg(not(debug_assertions))]
mode: bevy::window::WindowMode::BorderlessFullscreen,
..default() ..default()
}), }),
..default() ..default()

View File

@@ -7,6 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
bevy = "0.13.2" bevy = "0.13.2"
serde = {version="1.0.203", features=["derive"]}
[features] [features]

View File

@@ -1,3 +1,4 @@
pub mod despawn; pub mod despawn;
pub mod resource;
pub mod states; pub mod states;
pub mod tags; pub mod tags;

View File

@@ -0,0 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct ResourceIdentifier {
pub id: u32,
pub qty: u32,
}