buildings
This commit is contained in:
@@ -11,6 +11,8 @@ world_generation = {path = "../../engine/world_generation"}
|
||||
shared = {path = "../shared"}
|
||||
bevy_rapier3d = "0.26.0"
|
||||
serde = {version="1.0.203", features=["derive"]}
|
||||
asset_loader = {path = "../../engine/asset_loader"}
|
||||
|
||||
|
||||
[features]
|
||||
tracing = []
|
||||
|
||||
@@ -4,7 +4,7 @@ use shared::resource::ResourceIdentifier;
|
||||
|
||||
use crate::footprint::BuildingFootprint;
|
||||
|
||||
#[derive(Resource, Serialize, Deserialize)]
|
||||
#[derive(Asset, TypePath, Debug, Serialize, Deserialize)]
|
||||
pub struct BuildingAsset {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
|
||||
22
game/buildings/src/assets/building_database.rs
Normal file
22
game/buildings/src/assets/building_database.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use asset_loader::create_asset_loader;
|
||||
use bevy::prelude::{self, Resource};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::building_asset::BuildingAsset;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, TypePath, Asset)]
|
||||
pub struct BuildingDatabase {
|
||||
pub hq: u32,
|
||||
pub buildings_paths: Vec<String>,
|
||||
pub buildings: Vec<BuildingAsset>,
|
||||
}
|
||||
|
||||
create_asset_loader!(
|
||||
BuildingDatabasePlugin,
|
||||
BuildingDatabaseLoader,
|
||||
BuildingDatabase,
|
||||
BuildingDatabaseState,
|
||||
&["building.db.json"],;
|
||||
buildings_paths -> buildings
|
||||
?
|
||||
);
|
||||
@@ -1 +1,2 @@
|
||||
pub mod building_asset;
|
||||
pub mod building_database;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use bevy::prelude::Resource;
|
||||
use shared::building::BuildingIdentifier;
|
||||
use world_generation::hex_utils::HexCoord;
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct BuildQueue {
|
||||
pub queue: Vec<QueueEntry>,
|
||||
}
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
use bevy_rapier3d::{pipeline::QueryFilter, plugin::RapierContext};
|
||||
use shared::{despawn::Despawn, states::GameplayState, tags::MainCamera};
|
||||
use shared::{
|
||||
despawn::Despawn,
|
||||
states::{GameplayState, MenuState},
|
||||
tags::MainCamera,
|
||||
};
|
||||
use world_generation::{hex_utils::HexCoord, map::map::Map};
|
||||
|
||||
use crate::build_queue::{self, BuildQueue, QueueEntry};
|
||||
|
||||
pub struct BuildingPugin;
|
||||
|
||||
impl Plugin for BuildingPugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(BuildQueue::default());
|
||||
|
||||
app.add_systems(Startup, init);
|
||||
app.add_systems(Update, hq_placement.run_if(in_state(GameplayState::PlaceHQ)));
|
||||
|
||||
app.add_systems(PreUpdate, process_build_queue.run_if(in_state(GameplayState::Playing)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +40,8 @@ fn hq_placement(
|
||||
rapier_context: Res<RapierContext>,
|
||||
map: Res<Map>,
|
||||
indicator: Res<IndicatorCube>,
|
||||
mut build_queue: ResMut<BuildQueue>,
|
||||
next_state: ResMut<NextState<GameplayState>>,
|
||||
) {
|
||||
let win = window.single();
|
||||
let (cam_transform, camera) = cam_query.single();
|
||||
@@ -53,16 +65,29 @@ fn hq_placement(
|
||||
let contact_point = cam_ray.get_point(dist);
|
||||
let contact_coord = HexCoord::from_world_pos(contact_point);
|
||||
let positions = map.hex_select(&contact_coord, 3, true, |pos, h, _| pos.to_world(h));
|
||||
for p in positions {
|
||||
commands.spawn((
|
||||
PbrBundle {
|
||||
mesh: indicator.0.clone(),
|
||||
material: indicator.1.clone(),
|
||||
transform: Transform::from_translation(p),
|
||||
..default()
|
||||
},
|
||||
Despawn,
|
||||
));
|
||||
show_indicators(positions, &mut commands, &indicator);
|
||||
|
||||
if mouse.just_pressed(MouseButton::Left) {
|
||||
build_queue.queue.push(QueueEntry {
|
||||
building: 0.into(),
|
||||
pos: contact_coord,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn show_indicators(positions: Vec<Vec3>, commands: &mut Commands, indicator: &IndicatorCube) {
|
||||
for p in positions {
|
||||
commands.spawn((
|
||||
PbrBundle {
|
||||
mesh: indicator.0.clone(),
|
||||
material: indicator.1.clone(),
|
||||
transform: Transform::from_translation(p),
|
||||
..default()
|
||||
},
|
||||
Despawn,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn process_build_queue(mut queue: ResMut<BuildQueue>) {}
|
||||
|
||||
@@ -2,13 +2,13 @@ use bevy::prelude::*;
|
||||
use world_generation::hex_utils::HexCoord;
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct BuildingDatabase {
|
||||
pub struct BuildingMap {
|
||||
pub chunks: Vec<BuildingChunk>,
|
||||
}
|
||||
|
||||
impl BuildingDatabase {
|
||||
impl BuildingMap {
|
||||
pub fn new(size: UVec2) -> Self {
|
||||
let mut db = BuildingDatabase {
|
||||
let mut db = BuildingMap {
|
||||
chunks: Vec::with_capacity(size.length_squared() as usize),
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ use bevy::math::{IVec2, Vec3Swizzles};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use world_generation::hex_utils::HexCoord;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct BuildingFootprint {
|
||||
pub footprint: Vec<IVec2>,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pub mod assets;
|
||||
pub mod build_queue;
|
||||
pub mod building_plugin;
|
||||
pub mod buildings_database;
|
||||
pub mod buildings_map;
|
||||
pub mod footprint;
|
||||
pub use building_plugin::*;
|
||||
|
||||
Reference in New Issue
Block a user