units wip

This commit is contained in:
2024-08-27 23:04:03 -04:00
parent 25b6ad1099
commit 77fa421bb2
18 changed files with 210 additions and 7 deletions

View File

@@ -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",

View File

@@ -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;

View File

@@ -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());

View File

@@ -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>>,