diff --git a/game/shared/src/tags.rs b/game/shared/src/tags.rs index 093b86e..6bed005 100644 --- a/game/shared/src/tags.rs +++ b/game/shared/src/tags.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; #[derive(Component)] pub struct MainCamera; -#[derive(Component)] +#[derive(Component, Clone, Copy)] pub enum Faction { Player, Phos, diff --git a/game/units/src/components.rs b/game/units/src/components.rs index e5276f3..8f82a34 100644 --- a/game/units/src/components.rs +++ b/game/units/src/components.rs @@ -1,4 +1,4 @@ -use bevy::prelude::*; +use bevy::{ecs::world::CommandQueue, prelude::*, tasks::Task}; use serde::{Deserialize, Serialize}; #[derive(Component, Debug)] @@ -20,3 +20,9 @@ pub enum UnitDomain { #[derive(Component, Debug)] pub struct Target(pub Vec3); + +#[derive(Component, Debug)] +pub struct Path(pub Vec, pub usize); + +#[derive(Component, Debug)] +pub struct PathTask(pub Task); diff --git a/game/units/src/lib.rs b/game/units/src/lib.rs index 246b478..7c7b0a7 100644 --- a/game/units/src/lib.rs +++ b/game/units/src/lib.rs @@ -4,3 +4,8 @@ pub mod components; pub mod units_debug_plugin; pub mod units_plugin; pub mod units_spacial_set; + +#[derive(Clone, Copy)] +pub enum UnitType { + Basic, +} diff --git a/game/units/src/units_plugin.rs b/game/units/src/units_plugin.rs index eb1c078..610f7de 100644 --- a/game/units/src/units_plugin.rs +++ b/game/units/src/units_plugin.rs @@ -1,14 +1,17 @@ -use bevy::{prelude::*, window::PrimaryWindow}; +use bevy::{ + ecs::world::CommandQueue, prelude::*, tasks::AsyncComputeTaskPool, transform::commands, utils::futures, + window::PrimaryWindow, +}; use bevy_asset_loader::loading_state::{ config::{ConfigureLoadingState, LoadingStateConfig}, LoadingStateAppExt, }; -use shared::{sets::GameplaySet, states::AssetLoadState}; +use shared::{resources::TileUnderCursor, sets::GameplaySet, states::AssetLoadState}; use world_generation::{hex_utils::HexCoord, prelude::Map}; use crate::{ assets::{unit_asset::UnitAssetPlugin, unit_database::UnitDatabase}, - components::{Target, Unit}, + components::{Path, PathTask, Target, Unit}, units_debug_plugin::UnitsDebugPlugin, }; @@ -25,20 +28,30 @@ impl Plugin for UnitsPlugin { app.add_systems(Update, units_control.in_set(GameplaySet)); app.add_systems(Update, move_unit.in_set(GameplaySet)); + app.add_systems(FixedPreUpdate, (calculate_path, resolve_path_task).in_set(GameplaySet)); } } -fn units_control(input: Res>, window: Query<&Window, With>) { - let win = window.single(); +fn units_control(tile_under_cursor: Res) {} - let Some(cursor_pos) = win.cursor_position() else { - return; - }; -} - -fn move_unit(mut units: Query<(&mut Transform, &Target), With>, time: Res