Shuffle marker components out of `map module.

This commit is contained in:
Nolan Darilek 2025-01-03 20:13:53 -05:00
parent c2d6a1f0e8
commit 90351718cc
4 changed files with 29 additions and 18 deletions

View File

@ -21,6 +21,14 @@ use once_cell::sync::Lazy;
use rand::prelude::*; use rand::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)]
pub struct Obstacle;
#[derive(Default, Component, Clone, Debug, Reflect)]
#[reflect(Component)]
pub struct Zone;
fn relative_desc(rot: &Rot2) -> String { fn relative_desc(rot: &Rot2) -> String {
let mode = RELATIVE_DIRECTION_MODE.read().unwrap(); let mode = RELATIVE_DIRECTION_MODE.read().unwrap();
match rot.as_radians() { match rot.as_radians() {

View File

@ -7,7 +7,11 @@ use here_be_dragons::{geometry::Rect as MRect, MapFilter, Tile};
use maze_generator::{prelude::*, recursive_backtracking::RbGenerator}; use maze_generator::{prelude::*, recursive_backtracking::RbGenerator};
use rand::prelude::StdRng; use rand::prelude::StdRng;
use crate::{core::PointLike, exploration::Mappable, visibility::Visible}; use crate::{
core::{Obstacle, PointLike, Zone},
exploration::Mappable,
visibility::Visible,
};
#[derive(Component, Clone, Default, Deref, DerefMut)] #[derive(Component, Clone, Default, Deref, DerefMut)]
pub struct Map<D: 'static + Clone + Default + Send + Sync>(pub MapgenMap<D>); pub struct Map<D: 'static + Clone + Default + Send + Sync>(pub MapgenMap<D>);
@ -18,10 +22,6 @@ impl<D: Clone + Default + Send + Sync> From<MapgenMap<D>> for Map<D> {
} }
} }
#[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)]
pub struct MapObstruction;
#[derive(Component, Clone, Debug, Default, Reflect)] #[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Portal; pub struct Portal;
@ -52,10 +52,6 @@ impl Default for SpawnPortals {
} }
} }
#[derive(Default, Component, Clone, Debug, Reflect)]
#[reflect(Component)]
pub struct Zone;
pub trait ITileType { pub trait ITileType {
fn blocks_motion(&self) -> bool; fn blocks_motion(&self) -> bool;
fn blocks_visibility(&self) -> bool; fn blocks_visibility(&self) -> bool;
@ -91,7 +87,7 @@ pub struct TileBundle {
pub transform: Transform, pub transform: Transform,
pub collider: Collider, pub collider: Collider,
pub rigid_body: RigidBody, pub rigid_body: RigidBody,
pub map_obstruction: MapObstruction, pub map_obstruction: Obstacle,
} }
impl Default for TileBundle { impl Default for TileBundle {

View File

@ -8,10 +8,9 @@ use bevy_tts::Tts;
use leafwing_input_manager::prelude::*; use leafwing_input_manager::prelude::*;
use crate::{ use crate::{
core::{CardinalDirection, GlobalTransformExt, Player, TransformExt}, core::{CardinalDirection, GlobalTransformExt, Player, TransformExt, Zone},
error::error_handler, error::error_handler,
log::Log, log::Log,
map::Zone,
utils::target_and_other, utils::target_and_other,
}; };
@ -154,6 +153,7 @@ fn tick_snap_timers(time: Res<Time>, mut snap_timers: ResMut<SnapTimers>) {
} }
fn controls( fn controls(
mut commands: Commands,
spatial_query: SpatialQuery, spatial_query: SpatialQuery,
time: Res<Time>, time: Res<Time>,
snap_timers: Res<SnapTimers>, snap_timers: Res<SnapTimers>,
@ -235,6 +235,8 @@ fn controls(
&SpatialQueryFilter::from_excluded_entities(&sensors), &SpatialQueryFilter::from_excluded_entities(&sensors),
|hit| { |hit| {
if hit.entity != entity { if hit.entity != entity {
commands.entity(entity).log_components();
println!("Hit {}: can't translate", hit.entity);
can_translate = false; can_translate = false;
false false
} else { } else {
@ -244,8 +246,9 @@ fn controls(
); );
if can_translate { if can_translate {
transform.translation += pair.extend(0.); transform.translation += pair.extend(0.);
actions.set_axis_pair(&NavigationAction::Translate, Vec2::ZERO);
} else {
} }
actions.set_axis_pair(&NavigationAction::Translate, Vec2::ZERO);
} }
if !snap_timers.contains_key(&entity) { if !snap_timers.contains_key(&entity) {
if let Some(rotation_speed) = rotation_speed { if let Some(rotation_speed) = rotation_speed {

View File

@ -4,8 +4,8 @@ use leafwing_input_manager::{plugin::InputManagerSystem, prelude::*};
use pathfinding::prelude::*; use pathfinding::prelude::*;
use crate::{ use crate::{
core::GlobalTransformExt, core::{GlobalTransformExt, Obstacle},
map::{Map, MapObstruction}, map::Map,
navigation::{NavigationAction, RotationSpeed, Speed}, navigation::{NavigationAction, RotationSpeed, Speed},
}; };
@ -92,7 +92,7 @@ fn calculate_path(
), ),
Changed<Destination>, Changed<Destination>,
>, >,
obstructions: Query<Entity, With<MapObstruction>>, obstructions: Query<Entity, With<Obstacle>>,
sensors: Query<Entity, With<Sensor>>, sensors: Query<Entity, With<Sensor>>,
) { ) {
for (entity, destination, transform, collider, cost_map, actions) in &mut query { for (entity, destination, transform, collider, cost_map, actions) in &mut query {
@ -199,7 +199,7 @@ fn negotiate_path(
&Speed, &Speed,
Option<&RotationSpeed>, Option<&RotationSpeed>,
)>, )>,
obstructions: Query<Entity, With<MapObstruction>>, obstructions: Query<Entity, With<Obstacle>>,
sensors: Query<Entity, With<Sensor>>, sensors: Query<Entity, With<Sensor>>,
) { ) {
if physics_time.is_paused() { if physics_time.is_paused() {
@ -259,6 +259,10 @@ fn negotiate_path(
}, },
); );
if !hits.is_empty() { if !hits.is_empty() {
println!("{entity} is stuck");
for entity in hits {
commands.entity(entity).log_components();
}
// TODO: Remove when we have an actual character controller. // TODO: Remove when we have an actual character controller.
next.x = next.x.trunc(); next.x = next.x.trunc();
next.y = next.y.trunc(); next.y = next.y.trunc();
@ -328,7 +332,7 @@ pub struct PathfindingPlugin;
impl Plugin for PathfindingPlugin { impl Plugin for PathfindingPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_plugins(InputManagerPlugin::<NegotiatePathAction>::default()) app.add_plugins((InputManagerPlugin::<NegotiatePathAction>::default(),))
.register_type::<Destination>() .register_type::<Destination>()
.register_type::<NoPath>() .register_type::<NoPath>()
.register_type::<Path>() .register_type::<Path>()