units wip
This commit is contained in:
@@ -38,7 +38,10 @@ impl Plugin for BuildingPugin {
|
||||
);
|
||||
|
||||
app.add_systems(Update, init.run_if(in_state(AssetLoadState::Loading)));
|
||||
app.add_systems(Update, hq_placement.run_if(in_state(GameplayState::PlaceHQ)));
|
||||
app.add_systems(
|
||||
Update,
|
||||
hq_placement.run_if(in_state(GameplayState::PlaceHQ).and_then(in_state(GeneratorState::Idle))),
|
||||
);
|
||||
app.add_systems(
|
||||
PreUpdate,
|
||||
prepare_building_map.run_if(in_state(GeneratorState::SpawnMap)),
|
||||
|
||||
@@ -15,6 +15,7 @@ world_generation = { path = "../../engine/world_generation" }
|
||||
bevy_rapier3d = { version = "0.27.0", features = ["simd-stable", "parallel"] }
|
||||
rayon = "1.10.0"
|
||||
buildings = { path = "../buildings" }
|
||||
units = { path = "../units" }
|
||||
shared = { path = "../shared" }
|
||||
bevy_asset_loader = { version = "0.21.0", features = [
|
||||
"standard_dynamic_assets",
|
||||
|
||||
@@ -37,7 +37,7 @@ fn chunk_rebuilder(
|
||||
for (chunk_entity, idx) in &chunk_query {
|
||||
#[cfg(feature = "tracing")]
|
||||
let _spawn_span = info_span!("Rebuild Chunk").entered();
|
||||
println!("Rebuilding Chunk");
|
||||
info!("Rebuilding Chunk");
|
||||
let chunk_index = idx.index;
|
||||
let chunk_data = heightmap.get_chunk_mesh_data(chunk_index);
|
||||
let chunk_offset = heightmap.chunks[chunk_index].chunk_offset;
|
||||
|
||||
@@ -84,9 +84,7 @@ impl Plugin for MapInitPlugin {
|
||||
app.add_systems(Update, despawn_map.run_if(in_state(GeneratorState::Regenerate)));
|
||||
app.add_systems(
|
||||
Update,
|
||||
spawn_map
|
||||
.run_if(in_state(AssetLoadState::LoadComplete))
|
||||
.run_if(in_state(GeneratorState::SpawnMap)),
|
||||
spawn_map.run_if(in_state(AssetLoadState::LoadComplete).and_then(in_state(GeneratorState::SpawnMap))),
|
||||
);
|
||||
|
||||
app.insert_resource(TileManager::default());
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
use bevy_inspector_egui::bevy_egui::EguiContexts;
|
||||
use bevy_inspector_egui::bevy_egui::{systems::InputEvents, EguiContexts};
|
||||
use bevy_inspector_egui::egui;
|
||||
use bevy_rapier3d::prelude::*;
|
||||
use shared::states::GameplayState;
|
||||
use shared::tags::MainCamera;
|
||||
use units::units_debug_plugin::UnitsDebugPlugin;
|
||||
use world_generation::{
|
||||
consts::HEX_CORNERS,
|
||||
hex_utils::{HexCoord, INNER_RADIUS},
|
||||
@@ -14,6 +16,7 @@ pub struct DebugPlugin;
|
||||
|
||||
impl Plugin for DebugPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(UnitsDebugPlugin);
|
||||
app.insert_state(DebugState::Base);
|
||||
|
||||
app.add_systems(
|
||||
@@ -30,6 +33,8 @@ impl Plugin for DebugPlugin {
|
||||
.run_if(in_state(DebugState::Verbose)),
|
||||
);
|
||||
|
||||
app.add_systems(Update, regenerate_map.run_if(in_state(GeneratorState::Idle)));
|
||||
|
||||
app.insert_resource(Shape(Polyline3d::new([
|
||||
HEX_CORNERS[0],
|
||||
HEX_CORNERS[1],
|
||||
@@ -52,6 +57,17 @@ pub enum DebugState {
|
||||
Verbose,
|
||||
}
|
||||
|
||||
fn regenerate_map(
|
||||
mut generator_state: ResMut<NextState<GeneratorState>>,
|
||||
mut gameplay_state: ResMut<NextState<GameplayState>>,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::KeyR) {
|
||||
generator_state.set(GeneratorState::Regenerate);
|
||||
gameplay_state.set(GameplayState::PlaceHQ);
|
||||
}
|
||||
}
|
||||
|
||||
fn show_tile_heights(
|
||||
cam_query: Query<(&GlobalTransform, &Camera), With<MainCamera>>,
|
||||
window: Query<&Window, With<PrimaryWindow>>,
|
||||
|
||||
@@ -4,3 +4,4 @@ pub mod resource;
|
||||
pub mod states;
|
||||
pub mod tags;
|
||||
pub mod events;
|
||||
pub mod sets;
|
||||
|
||||
4
game/shared/src/sets.rs
Normal file
4
game/shared/src/sets.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct GameplaySet;
|
||||
@@ -1,3 +1,9 @@
|
||||
use bevy::prelude::*;
|
||||
#[derive(Component)]
|
||||
pub struct MainCamera;
|
||||
|
||||
#[derive(Component)]
|
||||
pub enum Faction {
|
||||
Player,
|
||||
Phos,
|
||||
}
|
||||
|
||||
21
game/units/Cargo.toml
Normal file
21
game/units/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "units"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.14.0"
|
||||
world_generation = { path = "../../engine/world_generation" }
|
||||
shared = { path = "../shared" }
|
||||
bevy_rapier3d = "0.27.0"
|
||||
serde = { version = "1.0.204", features = ["derive"] }
|
||||
asset_loader = { path = "../../engine/asset_loader" }
|
||||
serde_json = "1.0.120"
|
||||
ron = "0.8.1"
|
||||
bevy_asset_loader = { version = "0.21.0", features = [
|
||||
"standard_dynamic_assets",
|
||||
"3d",
|
||||
] }
|
||||
|
||||
[features]
|
||||
tracing = []
|
||||
3
game/units/src/assets/mod.rs
Normal file
3
game/units/src/assets/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
pub mod unit_asset;
|
||||
pub mod unit_database;
|
||||
52
game/units/src/assets/unit_asset.rs
Normal file
52
game/units/src/assets/unit_asset.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use asset_loader::create_asset_loader;
|
||||
use bevy::{ecs::world::CommandQueue, prelude::*};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::components::{Unit, UnitDomain};
|
||||
|
||||
#[derive(Asset, TypePath, Debug, Serialize, Deserialize)]
|
||||
pub struct UnitAsset {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub size: u32,
|
||||
pub prefab_path: String,
|
||||
#[serde(skip)]
|
||||
pub prefab: Handle<Scene>,
|
||||
pub unit_type: UnitType,
|
||||
pub domain: UnitDomain,
|
||||
}
|
||||
|
||||
impl UnitAsset {
|
||||
pub fn spawn(&self, transform: Transform) -> CommandQueue {
|
||||
let mut commands = CommandQueue::default();
|
||||
|
||||
let bundle = (
|
||||
PbrBundle {
|
||||
transform: transform,
|
||||
..default()
|
||||
},
|
||||
Unit,
|
||||
self.domain.clone(),
|
||||
);
|
||||
commands.push(move |world: &mut World| {
|
||||
world.spawn(bundle);
|
||||
});
|
||||
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
create_asset_loader!(
|
||||
UnitAssetPlugin,
|
||||
UnitAssetLoader,
|
||||
UnitAsset,
|
||||
&["unit", "unit.ron"],
|
||||
prefab_path -> prefab
|
||||
;?
|
||||
);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum UnitType {
|
||||
Basic,
|
||||
Turret,
|
||||
}
|
||||
10
game/units/src/assets/unit_database.rs
Normal file
10
game/units/src/assets/unit_database.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_asset_loader::asset_collection::AssetCollection;
|
||||
|
||||
use super::unit_asset::UnitAsset;
|
||||
|
||||
#[derive(Resource, AssetCollection)]
|
||||
pub struct UnitDatabase {
|
||||
#[asset(key = "units", collection(typed))]
|
||||
pub units: Vec<Handle<UnitAsset>>,
|
||||
}
|
||||
12
game/units/src/components.rs
Normal file
12
game/units/src/components.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Unit;
|
||||
|
||||
#[derive(Component, Serialize, Deserialize, Debug, Clone, Copy)]
|
||||
pub enum UnitDomain {
|
||||
Land,
|
||||
Air,
|
||||
Navy,
|
||||
}
|
||||
5
game/units/src/lib.rs
Normal file
5
game/units/src/lib.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
#[cfg(debug_assertions)]
|
||||
pub mod units_debug_plugin;
|
||||
pub mod units_plugin;
|
||||
pub mod components;
|
||||
pub mod assets;
|
||||
18
game/units/src/units_debug_plugin.rs
Normal file
18
game/units/src/units_debug_plugin.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use bevy::prelude::*;
|
||||
use shared::states::GameplayState;
|
||||
use world_generation::states::GeneratorState;
|
||||
|
||||
pub struct UnitsDebugPlugin;
|
||||
|
||||
impl Plugin for UnitsDebugPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
Update,
|
||||
spawn_test_unit.run_if(in_state(GeneratorState::Idle).and_then(in_state(GameplayState::Playing))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_test_unit(mut commands: Commands, input: Res<ButtonInput<KeyCode>>) {
|
||||
|
||||
}
|
||||
37
game/units/src/units_plugin.rs
Normal file
37
game/units/src/units_plugin.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
use bevy_asset_loader::loading_state::{
|
||||
config::{ConfigureLoadingState, LoadingStateConfig},
|
||||
LoadingStateAppExt,
|
||||
};
|
||||
use shared::states::{AssetLoadState, GameplayState};
|
||||
use world_generation::states::GeneratorState;
|
||||
|
||||
use crate::assets::{unit_asset::UnitAssetPlugin, unit_database::UnitDatabase};
|
||||
|
||||
pub struct UnitsPlugin;
|
||||
|
||||
impl Plugin for UnitsPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(UnitAssetPlugin);
|
||||
|
||||
app.configure_loading_state(LoadingStateConfig::new(AssetLoadState::Loading).load_collection::<UnitDatabase>());
|
||||
|
||||
app.add_systems(Update, units_control.in_set(UnitUpdateSet));
|
||||
|
||||
app.configure_sets(
|
||||
Update,
|
||||
UnitUpdateSet.run_if(in_state(GameplayState::Playing).and_then(in_state(GeneratorState::Idle))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
struct UnitUpdateSet;
|
||||
|
||||
fn units_control(input: Res<ButtonInput<KeyCode>>, window: Query<&Window, With<PrimaryWindow>>) {
|
||||
let win = window.single();
|
||||
|
||||
let Some(cursor_pos) = win.cursor_position() else {
|
||||
return;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user