buildings
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1325,6 +1325,7 @@ dependencies = [
|
|||||||
name = "buildings"
|
name = "buildings"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"asset_loader",
|
||||||
"bevy",
|
"bevy",
|
||||||
"bevy_rapier3d",
|
"bevy_rapier3d",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ 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"]}
|
serde = {version="1.0.203", features=["derive"]}
|
||||||
|
asset_loader = {path = "../../engine/asset_loader"}
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
tracing = []
|
tracing = []
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use shared::resource::ResourceIdentifier;
|
|||||||
|
|
||||||
use crate::footprint::BuildingFootprint;
|
use crate::footprint::BuildingFootprint;
|
||||||
|
|
||||||
#[derive(Resource, Serialize, Deserialize)]
|
#[derive(Asset, TypePath, Debug, Serialize, Deserialize)]
|
||||||
pub struct BuildingAsset {
|
pub struct BuildingAsset {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: 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_asset;
|
||||||
|
pub mod building_database;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
use bevy::prelude::Resource;
|
||||||
use shared::building::BuildingIdentifier;
|
use shared::building::BuildingIdentifier;
|
||||||
use world_generation::hex_utils::HexCoord;
|
use world_generation::hex_utils::HexCoord;
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
pub struct BuildQueue {
|
pub struct BuildQueue {
|
||||||
pub queue: Vec<QueueEntry>,
|
pub queue: Vec<QueueEntry>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
use bevy::{prelude::*, window::PrimaryWindow};
|
use bevy::{prelude::*, window::PrimaryWindow};
|
||||||
use bevy_rapier3d::{pipeline::QueryFilter, plugin::RapierContext};
|
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 world_generation::{hex_utils::HexCoord, map::map::Map};
|
||||||
|
|
||||||
|
use crate::build_queue::{self, BuildQueue, QueueEntry};
|
||||||
|
|
||||||
pub struct BuildingPugin;
|
pub struct BuildingPugin;
|
||||||
|
|
||||||
impl Plugin for BuildingPugin {
|
impl Plugin for BuildingPugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
|
app.insert_resource(BuildQueue::default());
|
||||||
|
|
||||||
app.add_systems(Startup, init);
|
app.add_systems(Startup, init);
|
||||||
app.add_systems(Update, hq_placement.run_if(in_state(GameplayState::PlaceHQ)));
|
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>,
|
rapier_context: Res<RapierContext>,
|
||||||
map: Res<Map>,
|
map: Res<Map>,
|
||||||
indicator: Res<IndicatorCube>,
|
indicator: Res<IndicatorCube>,
|
||||||
|
mut build_queue: ResMut<BuildQueue>,
|
||||||
|
next_state: ResMut<NextState<GameplayState>>,
|
||||||
) {
|
) {
|
||||||
let win = window.single();
|
let win = window.single();
|
||||||
let (cam_transform, camera) = cam_query.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_point = cam_ray.get_point(dist);
|
||||||
let contact_coord = HexCoord::from_world_pos(contact_point);
|
let contact_coord = HexCoord::from_world_pos(contact_point);
|
||||||
let positions = map.hex_select(&contact_coord, 3, true, |pos, h, _| pos.to_world(h));
|
let positions = map.hex_select(&contact_coord, 3, true, |pos, h, _| pos.to_world(h));
|
||||||
for p in positions {
|
show_indicators(positions, &mut commands, &indicator);
|
||||||
commands.spawn((
|
|
||||||
PbrBundle {
|
if mouse.just_pressed(MouseButton::Left) {
|
||||||
mesh: indicator.0.clone(),
|
build_queue.queue.push(QueueEntry {
|
||||||
material: indicator.1.clone(),
|
building: 0.into(),
|
||||||
transform: Transform::from_translation(p),
|
pos: contact_coord,
|
||||||
..default()
|
});
|
||||||
},
|
|
||||||
Despawn,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
use world_generation::hex_utils::HexCoord;
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct BuildingDatabase {
|
pub struct BuildingMap {
|
||||||
pub chunks: Vec<BuildingChunk>,
|
pub chunks: Vec<BuildingChunk>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildingDatabase {
|
impl BuildingMap {
|
||||||
pub fn new(size: UVec2) -> Self {
|
pub fn new(size: UVec2) -> Self {
|
||||||
let mut db = BuildingDatabase {
|
let mut db = BuildingMap {
|
||||||
chunks: Vec::with_capacity(size.length_squared() as usize),
|
chunks: Vec::with_capacity(size.length_squared() as usize),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@ use bevy::math::{IVec2, Vec3Swizzles};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use world_generation::hex_utils::HexCoord;
|
use world_generation::hex_utils::HexCoord;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct BuildingFootprint {
|
pub struct BuildingFootprint {
|
||||||
pub footprint: Vec<IVec2>,
|
pub footprint: Vec<IVec2>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
pub mod assets;
|
pub mod assets;
|
||||||
pub mod build_queue;
|
pub mod build_queue;
|
||||||
pub mod building_plugin;
|
pub mod building_plugin;
|
||||||
pub mod buildings_database;
|
pub mod buildings_map;
|
||||||
pub mod footprint;
|
pub mod footprint;
|
||||||
pub use building_plugin::*;
|
pub use building_plugin::*;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use bevy::core_pipeline::prepass::DepthPrepass;
|
|||||||
use bevy::input::mouse::{MouseMotion, MouseScrollUnit, MouseWheel};
|
use bevy::input::mouse::{MouseMotion, MouseScrollUnit, MouseWheel};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::window::CursorGrabMode;
|
use bevy::window::CursorGrabMode;
|
||||||
use shared::states::GameState;
|
use shared::states::MenuState;
|
||||||
use shared::tags::MainCamera;
|
use shared::tags::MainCamera;
|
||||||
use world_generation::hex_utils::HexCoord;
|
use world_generation::hex_utils::HexCoord;
|
||||||
use world_generation::prelude::Map;
|
use world_generation::prelude::Map;
|
||||||
@@ -18,7 +18,7 @@ impl Plugin for PhosCameraPlugin {
|
|||||||
|
|
||||||
app.add_systems(PreStartup, setup);
|
app.add_systems(PreStartup, setup);
|
||||||
|
|
||||||
app.add_systems(Update, rts_camera_system.run_if(in_state(GameState::Playing)));
|
app.add_systems(Update, rts_camera_system.run_if(in_state(MenuState::InGame)));
|
||||||
app.add_systems(PostUpdate, limit_camera_bounds);
|
app.add_systems(PostUpdate, limit_camera_bounds);
|
||||||
//Free Cam
|
//Free Cam
|
||||||
//app.add_systems(Update, (grab_mouse, (update_camera, update_camera_mouse).chain()));
|
//app.add_systems(Update, (grab_mouse, (update_camera, update_camera_mouse).chain()));
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use bevy::{
|
|||||||
};
|
};
|
||||||
use bevy_inspector_egui::quick::ResourceInspectorPlugin;
|
use bevy_inspector_egui::quick::ResourceInspectorPlugin;
|
||||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||||
use shared::states::{GameState, GameplayState};
|
use shared::states::{GameplayState, MenuState};
|
||||||
use world_generation::{
|
use world_generation::{
|
||||||
biome_painter::*,
|
biome_painter::*,
|
||||||
heightmap::generate_heightmap,
|
heightmap::generate_heightmap,
|
||||||
@@ -273,8 +273,8 @@ fn spawn_map(
|
|||||||
biome_painters: Res<Assets<BiomePainterAsset>>,
|
biome_painters: Res<Assets<BiomePainterAsset>>,
|
||||||
painter: Res<CurrentBiomePainter>,
|
painter: Res<CurrentBiomePainter>,
|
||||||
mut generator_state: ResMut<NextState<GeneratorState>>,
|
mut generator_state: ResMut<NextState<GeneratorState>>,
|
||||||
cur_game_state: Res<State<GameState>>,
|
cur_game_state: Res<State<MenuState>>,
|
||||||
mut game_state: ResMut<NextState<GameState>>,
|
mut game_state: ResMut<NextState<MenuState>>,
|
||||||
mut gameplay_state: ResMut<NextState<GameplayState>>,
|
mut gameplay_state: ResMut<NextState<GameplayState>>,
|
||||||
) {
|
) {
|
||||||
let b_painter = biome_painters.get(painter.handle.clone());
|
let b_painter = biome_painters.get(painter.handle.clone());
|
||||||
@@ -332,8 +332,8 @@ fn spawn_map(
|
|||||||
|
|
||||||
commands.insert_resource(registry);
|
commands.insert_resource(registry);
|
||||||
generator_state.set(GeneratorState::Idle);
|
generator_state.set(GeneratorState::Idle);
|
||||||
if cur_game_state.get() != &GameState::Playing {
|
if cur_game_state.get() != &MenuState::InGame {
|
||||||
game_state.set(GameState::Playing);
|
game_state.set(MenuState::InGame);
|
||||||
gameplay_state.set(GameplayState::PlaceHQ);
|
gameplay_state.set(GameplayState::PlaceHQ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin};
|
|||||||
use buildings::BuildingPugin;
|
use buildings::BuildingPugin;
|
||||||
use iyes_perf_ui::prelude::*;
|
use iyes_perf_ui::prelude::*;
|
||||||
use shared::despawn::DespawnPuglin;
|
use shared::despawn::DespawnPuglin;
|
||||||
use shared::states::{GameState, GameplayState};
|
use shared::states::{MenuState, GameplayState};
|
||||||
use world_generation::biome_painter::BiomePainterPlugin;
|
use world_generation::biome_painter::BiomePainterPlugin;
|
||||||
use world_generation::tile_manager::TileAssetPlugin;
|
use world_generation::tile_manager::TileAssetPlugin;
|
||||||
use world_generation::tile_mapper::TileMapperAssetPlugin;
|
use world_generation::tile_mapper::TileMapperAssetPlugin;
|
||||||
@@ -29,7 +29,7 @@ impl Plugin for PhosGamePlugin {
|
|||||||
DespawnPuglin,
|
DespawnPuglin,
|
||||||
));
|
));
|
||||||
|
|
||||||
app.insert_state(GameState::Startup);
|
app.insert_state(MenuState::Startup);
|
||||||
app.insert_state(GameplayState::Waiting);
|
app.insert_state(GameplayState::Waiting);
|
||||||
|
|
||||||
//Systems - Startup
|
//Systems - Startup
|
||||||
|
|||||||
@@ -2,3 +2,9 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
#[derive(Default, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct BuildingIdentifier(u32);
|
pub struct BuildingIdentifier(u32);
|
||||||
|
|
||||||
|
impl From<u32> for BuildingIdentifier {
|
||||||
|
fn from(value: u32) -> Self {
|
||||||
|
return BuildingIdentifier(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::states::GameState;
|
use crate::states::MenuState;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
pub struct DespawnPuglin;
|
pub struct DespawnPuglin;
|
||||||
@@ -17,7 +17,7 @@ impl Plugin for DespawnPuglin {
|
|||||||
app.add_systems(PostUpdate, despawn_at);
|
app.add_systems(PostUpdate, despawn_at);
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
PreUpdate,
|
PreUpdate,
|
||||||
(despawn, despawn_after).run_if(not(in_state(GameState::Paused))),
|
(despawn, despawn_after).run_if(not(in_state(MenuState::Paused))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct ResourceIdentifier {
|
pub struct ResourceIdentifier {
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub qty: u32,
|
pub qty: u32,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
#[derive(States, Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(States, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum GameState {
|
pub enum MenuState {
|
||||||
Startup,
|
Startup,
|
||||||
MainMenu,
|
MainMenu,
|
||||||
Loading,
|
Loading,
|
||||||
Playing,
|
InGame,
|
||||||
Paused,
|
Paused,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user