Compare commits
No commits in common. "f255239517b7c37f57e5f5090c8ec4ec1b948ea9" and "1e9860e3a129e30bbb675ef182d4243e75239777" have entirely different histories.
f255239517
...
1e9860e3a1
32
src/core.rs
32
src/core.rs
|
@ -650,6 +650,15 @@ pub struct CoreConfig {
|
|||
pub pixels_per_unit: u8,
|
||||
}
|
||||
|
||||
impl Default for CoreConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
relative_direction_mode: RelativeDirectionMode::Directional,
|
||||
pixels_per_unit: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_config(config: Res<CoreConfig>) {
|
||||
if config.is_changed() {
|
||||
let mut mode = RELATIVE_DIRECTION_MODE.write().unwrap();
|
||||
|
@ -657,30 +666,21 @@ fn sync_config(config: Res<CoreConfig>) {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct CorePlugin<RapierUserData> {
|
||||
pub relative_direction_mode: RelativeDirectionMode,
|
||||
pub pixels_per_unit: u8,
|
||||
pub rapier_user_data: PhantomData<RapierUserData>,
|
||||
}
|
||||
pub struct CorePlugin<RapierUserData>(PhantomData<RapierUserData>);
|
||||
|
||||
impl<RapierUserData> Default for CorePlugin<RapierUserData> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
relative_direction_mode: RelativeDirectionMode::Directional,
|
||||
pixels_per_unit: 1,
|
||||
rapier_user_data: default(),
|
||||
}
|
||||
Self(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<RapierUserData: 'static + WorldQuery + Send + Sync> Plugin for CorePlugin<RapierUserData> {
|
||||
fn build(&self, app: &mut App) {
|
||||
let config = CoreConfig {
|
||||
relative_direction_mode: self.relative_direction_mode,
|
||||
pixels_per_unit: self.pixels_per_unit,
|
||||
};
|
||||
app.insert_resource(config)
|
||||
.register_type::<CardinalDirection>()
|
||||
if !app.world.contains_resource::<CoreConfig>() {
|
||||
app.insert_resource(CoreConfig::default());
|
||||
}
|
||||
let config = *app.world.get_resource::<CoreConfig>().unwrap();
|
||||
app.register_type::<CardinalDirection>()
|
||||
.add_plugin(RapierPhysicsPlugin::<RapierUserData>::pixels_per_meter(
|
||||
config.pixels_per_unit as f32,
|
||||
))
|
||||
|
|
|
@ -49,21 +49,21 @@ where
|
|||
#[reflect(Component)]
|
||||
pub struct Mappable;
|
||||
|
||||
fn exploration_type_change<ExplorationType, State>(
|
||||
fn exploration_type_change<T, S>(
|
||||
mut tts: ResMut<Tts>,
|
||||
mut explorers: Query<(
|
||||
&ActionState<ExplorationAction>,
|
||||
&VisibleEntities,
|
||||
&mut FocusedExplorationType<ExplorationType>,
|
||||
&mut FocusedExplorationType<T>,
|
||||
)>,
|
||||
features: Query<&ExplorationType>,
|
||||
features: Query<&T>,
|
||||
) -> Result<(), Box<dyn Error>>
|
||||
where
|
||||
ExplorationType: Component + Default + Copy + Ord,
|
||||
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
T: Component + Default + Copy + Ord,
|
||||
S: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
{
|
||||
for (actions, visible, mut focused) in explorers.iter_mut() {
|
||||
let mut types: Vec<ExplorationType> = vec![];
|
||||
let mut types: Vec<T> = vec![];
|
||||
for e in visible.iter() {
|
||||
if let Ok(t) = features.get(*e) {
|
||||
types.push(*t);
|
||||
|
@ -112,28 +112,28 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn exploration_type_focus<ExplorationType, State>(
|
||||
fn exploration_type_focus<T, S>(
|
||||
mut commands: Commands,
|
||||
mut tts: ResMut<Tts>,
|
||||
explorers: Query<(
|
||||
Entity,
|
||||
&ActionState<ExplorationAction>,
|
||||
&VisibleEntities,
|
||||
&FocusedExplorationType<ExplorationType>,
|
||||
&FocusedExplorationType<T>,
|
||||
Option<&Exploring>,
|
||||
)>,
|
||||
features: Query<(Entity, &Transform, &ExplorationType)>,
|
||||
features: Query<(Entity, &Transform, &T)>,
|
||||
) -> Result<(), Box<dyn Error>>
|
||||
where
|
||||
ExplorationType: Component + Default + PartialEq,
|
||||
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
T: Component + Default + PartialEq,
|
||||
S: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
{
|
||||
for (entity, actions, visible_entities, focused_type, exploring) in explorers.iter() {
|
||||
let mut features = features
|
||||
.iter()
|
||||
.filter(|v| visible_entities.contains(&v.0))
|
||||
.map(|v| (v.1.floor(), v.2))
|
||||
.collect::<Vec<((f32, f32), &ExplorationType)>>();
|
||||
.collect::<Vec<((f32, f32), &T)>>();
|
||||
if features.is_empty() {
|
||||
tts.speak("Nothing visible.", true)?;
|
||||
return Ok(());
|
||||
|
@ -142,7 +142,7 @@ where
|
|||
if let Some(focused) = &focused_type.0 {
|
||||
features.retain(|(_, t)| **t == *focused);
|
||||
}
|
||||
let mut target: Option<&((f32, f32), &ExplorationType)> = None;
|
||||
let mut target: Option<&((f32, f32), &T)> = None;
|
||||
if actions.just_pressed(ExplorationAction::FocusNext) {
|
||||
if let Some(exploring) = exploring {
|
||||
target = features.iter().find(|(c, _)| *c > **exploring);
|
||||
|
@ -172,18 +172,18 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn exploration_type_changed_announcement<ExplorationType>(
|
||||
fn exploration_type_changed_announcement<T>(
|
||||
mut tts: ResMut<Tts>,
|
||||
focused: Query<
|
||||
(
|
||||
&FocusedExplorationType<ExplorationType>,
|
||||
ChangeTrackers<FocusedExplorationType<ExplorationType>>,
|
||||
&FocusedExplorationType<T>,
|
||||
ChangeTrackers<FocusedExplorationType<T>>,
|
||||
),
|
||||
Changed<FocusedExplorationType<ExplorationType>>,
|
||||
Changed<FocusedExplorationType<T>>,
|
||||
>,
|
||||
) -> Result<(), Box<dyn Error>>
|
||||
where
|
||||
ExplorationType: Component + Default + Copy + Into<String>,
|
||||
T: Component + Default + Copy + Into<String>,
|
||||
{
|
||||
for (focused, changed) in focused.iter() {
|
||||
if changed.is_added() {
|
||||
|
@ -202,9 +202,9 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn exploration_focus<State, MapData>(
|
||||
fn exploration_focus<S, D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
map: Query<&Map<MapData>>,
|
||||
map: Query<&Map<D>>,
|
||||
explorers: Query<
|
||||
(
|
||||
Entity,
|
||||
|
@ -215,8 +215,7 @@ fn exploration_focus<State, MapData>(
|
|||
With<Player>,
|
||||
>,
|
||||
) where
|
||||
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
MapData: 'static + Clone + Default + Send + Sync,
|
||||
S: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
{
|
||||
for (entity, actions, transform, exploring) in explorers.iter() {
|
||||
let coordinates = transform.translation;
|
||||
|
@ -252,13 +251,12 @@ fn exploration_focus<State, MapData>(
|
|||
}
|
||||
}
|
||||
|
||||
fn navigate_to_explored<State, MapData>(
|
||||
fn navigate_to_explored<S, D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
map: Query<(&Map<MapData>, &RevealedTiles)>,
|
||||
map: Query<(&Map<D>, &RevealedTiles)>,
|
||||
explorers: Query<(Entity, &ActionState<ExplorationAction>, &Exploring)>,
|
||||
) where
|
||||
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
MapData: 'static + Clone + Default + Send + Sync,
|
||||
S: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
{
|
||||
for (entity, actions, exploring) in explorers.iter() {
|
||||
for (map, revealed_tiles) in map.iter() {
|
||||
|
@ -274,21 +272,21 @@ fn navigate_to_explored<State, MapData>(
|
|||
}
|
||||
}
|
||||
|
||||
fn exploration_changed_announcement<ExplorationType, MapData>(
|
||||
fn exploration_changed_announcement<T, D>(
|
||||
mut commands: Commands,
|
||||
mut tts: ResMut<Tts>,
|
||||
map: Query<(&Map<MapData>, &RevealedTiles)>,
|
||||
map: Query<(&Map<D>, &RevealedTiles)>,
|
||||
explorer: Query<(&Transform, &Exploring, &Viewshed), Changed<Exploring>>,
|
||||
focused: Query<Entity, With<ExplorationFocused>>,
|
||||
explorable: Query<Entity, Or<(With<Visible>, With<Explorable>)>>,
|
||||
names: Query<&Name>,
|
||||
types: Query<&ExplorationType>,
|
||||
types: Query<&T>,
|
||||
mappables: Query<&Mappable>,
|
||||
rapier_context: Res<RapierContext>,
|
||||
) -> Result<(), Box<dyn Error>>
|
||||
where
|
||||
ExplorationType: Component + Copy + Into<String>,
|
||||
MapData: 'static + Clone + Default + Send + Sync,
|
||||
T: Component + Copy + Into<String>,
|
||||
D: 'static + Clone + Default + Send + Sync,
|
||||
{
|
||||
if let Ok((coordinates, exploring, viewshed)) = explorer.get_single() {
|
||||
let coordinates = coordinates.floor();
|
||||
|
@ -372,66 +370,72 @@ fn cleanup(
|
|||
}
|
||||
|
||||
#[derive(Resource, Clone, Debug)]
|
||||
pub struct ExplorationConfig<State> {
|
||||
pub states: Vec<State>,
|
||||
pub struct ExplorationConfig<S> {
|
||||
pub exploration_control_states: Vec<S>,
|
||||
}
|
||||
|
||||
impl<State> Default for ExplorationConfig<State> {
|
||||
impl<S> Default for ExplorationConfig<S> {
|
||||
fn default() -> Self {
|
||||
Self { states: vec![] }
|
||||
Self {
|
||||
exploration_control_states: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Clone, Default)]
|
||||
pub struct ExplorationPlugin<ExplorationType, State, MapData> {
|
||||
states: Vec<State>,
|
||||
exploration_type: PhantomData<ExplorationType>,
|
||||
map_data: PhantomData<MapData>,
|
||||
pub struct ExplorationPlugin<'a, T, S: 'static, A: 'static, D>(
|
||||
PhantomData<T>,
|
||||
PhantomData<&'a S>,
|
||||
PhantomData<&'static A>,
|
||||
PhantomData<D>,
|
||||
);
|
||||
|
||||
impl<T, S, A, D> Default for ExplorationPlugin<'static, S, A, D, T> {
|
||||
fn default() -> Self {
|
||||
Self(PhantomData, PhantomData, PhantomData, PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<ExplorationType, State, MapData> Plugin for ExplorationPlugin<ExplorationType, State, MapData>
|
||||
impl<T, S, A, D> Plugin for ExplorationPlugin<'static, T, S, A, D>
|
||||
where
|
||||
ExplorationType: 'static + Component + Default + Copy + Ord + PartialEq + Into<String>,
|
||||
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
MapData: 'static + Clone + Default + Send + Sync,
|
||||
T: 'static + Component + Default + Copy + Ord + PartialEq + Into<String>,
|
||||
S: Clone + Debug + Eq + Hash + Send + Sync,
|
||||
A: Hash + Eq + Clone + Send + Sync,
|
||||
D: 'static + Clone + Default + Send + Sync,
|
||||
{
|
||||
fn build(&self, app: &mut App) {
|
||||
let config = ExplorationConfig {
|
||||
states: self.states.clone(),
|
||||
};
|
||||
app.insert_resource(config.clone())
|
||||
.register_type::<ExplorationFocused>()
|
||||
if !app.world.contains_resource::<ExplorationConfig<S>>() {
|
||||
app.insert_resource(ExplorationConfig::<S>::default());
|
||||
}
|
||||
let config = app
|
||||
.world
|
||||
.get_resource::<ExplorationConfig<S>>()
|
||||
.unwrap()
|
||||
.clone();
|
||||
app.register_type::<ExplorationFocused>()
|
||||
.register_type::<Mappable>()
|
||||
.register_type::<Explorable>()
|
||||
.add_plugin(InputManagerPlugin::<ExplorationAction>::default())
|
||||
.add_system(
|
||||
exploration_changed_announcement::<ExplorationType, MapData>.pipe(error_handler),
|
||||
);
|
||||
if config.states.is_empty() {
|
||||
app.add_system(exploration_focus::<State, MapData>)
|
||||
.add_system(exploration_type_focus::<ExplorationType, State>.pipe(error_handler))
|
||||
.add_system(exploration_type_change::<ExplorationType, State>.pipe(error_handler))
|
||||
.add_system(navigate_to_explored::<State, MapData>)
|
||||
.add_system(exploration_changed_announcement::<T, D>.pipe(error_handler));
|
||||
if config.exploration_control_states.is_empty() {
|
||||
app.add_system(exploration_focus::<S, D>)
|
||||
.add_system(exploration_type_focus::<T, S>.pipe(error_handler))
|
||||
.add_system(exploration_type_change::<T, S>.pipe(error_handler))
|
||||
.add_system(navigate_to_explored::<S, D>)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
exploration_type_changed_announcement::<ExplorationType>.pipe(error_handler),
|
||||
exploration_type_changed_announcement::<T>.pipe(error_handler),
|
||||
);
|
||||
} else {
|
||||
let states = config.states;
|
||||
let states = config.exploration_control_states;
|
||||
for state in states {
|
||||
app.add_system_set(
|
||||
SystemSet::on_update(state.clone())
|
||||
.with_system(exploration_focus::<State, MapData>)
|
||||
.with_system(exploration_focus::<S, D>)
|
||||
.with_system(exploration_type_focus::<T, S>.pipe(error_handler))
|
||||
.with_system(exploration_type_change::<T, S>.pipe(error_handler))
|
||||
.with_system(navigate_to_explored::<S, D>)
|
||||
.with_system(
|
||||
exploration_type_focus::<ExplorationType, State>.pipe(error_handler),
|
||||
)
|
||||
.with_system(
|
||||
exploration_type_change::<ExplorationType, State>.pipe(error_handler),
|
||||
)
|
||||
.with_system(navigate_to_explored::<State, MapData>)
|
||||
.with_system(
|
||||
exploration_type_changed_announcement::<ExplorationType>
|
||||
.pipe(error_handler),
|
||||
exploration_type_changed_announcement::<T>.pipe(error_handler),
|
||||
),
|
||||
)
|
||||
.add_system_set(SystemSet::on_exit(state).with_system(cleanup));
|
||||
|
|
32
src/map.rs
32
src/map.rs
|
@ -78,6 +78,11 @@ impl ITileType for Tile {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Clone, Debug, Default)]
|
||||
pub struct MapConfig {
|
||||
pub start_revealed: bool,
|
||||
}
|
||||
|
||||
#[derive(Bundle, Default)]
|
||||
pub struct PortalBundle {
|
||||
pub portal: Portal,
|
||||
|
@ -309,27 +314,22 @@ fn spawn_portal_colliders<D: 'static + Clone + Default + Send + Sync>(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Clone, Copy, Debug)]
|
||||
pub struct MapPlugin<MapData: 'static + Clone + Default + Send + Sync> {
|
||||
pub start_revealed: bool,
|
||||
pub map_data: PhantomData<MapData>,
|
||||
}
|
||||
pub struct MapPlugin<D: 'static + Clone + Default + Send + Sync>(PhantomData<D>);
|
||||
|
||||
impl<MapData: 'static + Clone + Default + Send + Sync> Default for MapPlugin<MapData> {
|
||||
impl<D: 'static + Clone + Default + Send + Sync> Default for MapPlugin<D> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
start_revealed: default(),
|
||||
map_data: default(),
|
||||
}
|
||||
Self(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<MapData: 'static + Clone + Default + Send + Sync> Plugin for MapPlugin<MapData> {
|
||||
impl<D: 'static + Clone + Default + Send + Sync> Plugin for MapPlugin<D> {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(self.clone())
|
||||
.register_type::<Portal>()
|
||||
.add_system_to_stage(CoreStage::PreUpdate, spawn_colliders::<MapData>)
|
||||
.add_system_to_stage(CoreStage::PreUpdate, spawn_portals::<MapData>)
|
||||
.add_system_to_stage(CoreStage::PreUpdate, spawn_portal_colliders::<MapData>);
|
||||
if !app.world.contains_resource::<MapConfig>() {
|
||||
app.insert_resource(MapConfig::default());
|
||||
}
|
||||
app.register_type::<Portal>()
|
||||
.add_system_to_stage(CoreStage::PreUpdate, spawn_colliders::<D>)
|
||||
.add_system_to_stage(CoreStage::PreUpdate, spawn_portals::<D>)
|
||||
.add_system_to_stage(CoreStage::PreUpdate, spawn_portal_colliders::<D>);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use std::{collections::HashMap, error::Error, f32::consts::PI, fmt::Debug, hash::Hash};
|
||||
use std::{
|
||||
collections::HashMap, error::Error, f32::consts::PI, fmt::Debug, hash::Hash,
|
||||
marker::PhantomData,
|
||||
};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_rapier2d::prelude::*;
|
||||
|
@ -58,9 +61,9 @@ impl Default for SnapTimer {
|
|||
#[derive(Resource, Default, Deref, DerefMut)]
|
||||
struct SnapTimers(HashMap<Entity, SnapTimer>);
|
||||
|
||||
fn movement_controls<State>(
|
||||
fn movement_controls<S>(
|
||||
mut commands: Commands,
|
||||
config: Res<NavigationPlugin<State>>,
|
||||
config: Res<NavigationConfig<S>>,
|
||||
snap_timers: Res<SnapTimers>,
|
||||
mut query: Query<(
|
||||
Entity,
|
||||
|
@ -73,7 +76,7 @@ fn movement_controls<State>(
|
|||
)>,
|
||||
exploration_focused: Query<Entity, With<ExplorationFocused>>,
|
||||
) where
|
||||
State: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
S: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
{
|
||||
for (entity, mut actions, mut velocity, mut speed, max_speed, rotation_speed, transform) in
|
||||
&mut query
|
||||
|
@ -292,14 +295,15 @@ fn remove_speed(removed: RemovedComponents<Speed>, mut query: Query<&mut Velocit
|
|||
}
|
||||
}
|
||||
|
||||
fn log_area_descriptions<State>(
|
||||
fn log_area_descriptions<S, A>(
|
||||
mut events: EventReader<CollisionEvent>,
|
||||
areas: Query<(&Area, Option<&Name>)>,
|
||||
players: Query<&Player>,
|
||||
config: Res<NavigationPlugin<State>>,
|
||||
config: Res<NavigationConfig<S>>,
|
||||
mut log: Query<&mut Log>,
|
||||
) where
|
||||
State: 'static + Send + Sync,
|
||||
S: 'static + Send + Sync,
|
||||
A: 'static + Send + Sync,
|
||||
{
|
||||
if !config.log_area_descriptions {
|
||||
return;
|
||||
|
@ -336,36 +340,52 @@ fn log_area_descriptions<State>(
|
|||
}
|
||||
|
||||
#[derive(Resource, Clone, Debug)]
|
||||
pub struct NavigationPlugin<State> {
|
||||
pub struct NavigationConfig<S> {
|
||||
pub forward_movement_factor: f32,
|
||||
pub backward_movement_factor: f32,
|
||||
pub strafe_movement_factor: f32,
|
||||
pub sprint_movement_factor: f32,
|
||||
pub states: Vec<State>,
|
||||
pub movement_control_states: Vec<S>,
|
||||
pub describe_undescribed_areas: bool,
|
||||
pub log_area_descriptions: bool,
|
||||
}
|
||||
|
||||
impl<State> Default for NavigationPlugin<State> {
|
||||
impl<S> Default for NavigationConfig<S> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
forward_movement_factor: 1.,
|
||||
backward_movement_factor: 1.,
|
||||
strafe_movement_factor: 1.,
|
||||
sprint_movement_factor: 3.,
|
||||
states: vec![],
|
||||
movement_control_states: vec![],
|
||||
describe_undescribed_areas: false,
|
||||
log_area_descriptions: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<State> Plugin for NavigationPlugin<State>
|
||||
pub struct NavigationPlugin<'a, S, A>(PhantomData<&'a S>, PhantomData<&'a A>);
|
||||
|
||||
impl<'a, S, A> Default for NavigationPlugin<'a, S, A> {
|
||||
fn default() -> Self {
|
||||
Self(PhantomData, PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, A> Plugin for NavigationPlugin<'static, S, A>
|
||||
where
|
||||
State: 'static + Clone + Copy + Debug + Eq + Hash + Send + Sync,
|
||||
S: 'static + Clone + Copy + Debug + Eq + Hash + Send + Sync,
|
||||
A: Hash + Eq + Copy + Send + Sync,
|
||||
{
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(self.clone());
|
||||
if !app.world.contains_resource::<NavigationConfig<S>>() {
|
||||
app.insert_resource(NavigationConfig::<S>::default());
|
||||
}
|
||||
let config = app
|
||||
.world
|
||||
.get_resource::<NavigationConfig<S>>()
|
||||
.unwrap()
|
||||
.clone();
|
||||
app.init_resource::<SnapTimers>()
|
||||
.register_type::<MaxSpeed>()
|
||||
.register_type::<RotationSpeed>()
|
||||
|
@ -378,20 +398,21 @@ where
|
|||
.add_system(add_speed)
|
||||
.add_system(limit_speed)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, remove_speed)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, log_area_descriptions::<State>);
|
||||
.add_system_to_stage(CoreStage::PostUpdate, log_area_descriptions::<S, A>);
|
||||
const MOVEMENT_CONTROLS: &str = "MOVEMENT_CONTROLS";
|
||||
if self.states.is_empty() {
|
||||
if config.movement_control_states.is_empty() {
|
||||
app.add_system(
|
||||
movement_controls::<State>
|
||||
movement_controls::<S>
|
||||
.label(MOVEMENT_CONTROLS)
|
||||
.after(limit_speed),
|
||||
)
|
||||
.add_system(snap.pipe(error_handler).before(MOVEMENT_CONTROLS));
|
||||
} else {
|
||||
for state in &self.states {
|
||||
let states = config.movement_control_states;
|
||||
for state in states {
|
||||
app.add_system_set(
|
||||
SystemSet::on_update(*state)
|
||||
.with_system(movement_controls::<State>.label(MOVEMENT_CONTROLS))
|
||||
SystemSet::on_update(state)
|
||||
.with_system(movement_controls::<S>.label(MOVEMENT_CONTROLS))
|
||||
.with_system(snap.pipe(error_handler).before(MOVEMENT_CONTROLS)),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -12,9 +12,24 @@ use crate::{
|
|||
#[reflect(Component)]
|
||||
struct Behind;
|
||||
|
||||
#[derive(Resource, Clone, Copy, Debug)]
|
||||
pub struct PitchShiftConfig {
|
||||
pub downshift_behind: bool,
|
||||
pub downshift: f64,
|
||||
}
|
||||
|
||||
impl Default for PitchShiftConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
downshift_behind: false,
|
||||
downshift: 0.95,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn tag_behind(
|
||||
mut commands: Commands,
|
||||
config: Res<PitchShiftPlugin>,
|
||||
config: Res<PitchShiftConfig>,
|
||||
sounds: Query<(Entity, &GlobalTransform, Option<&Sound>, Option<&SoundIcon>)>,
|
||||
listener: Query<&GlobalTransform, With<Listener>>,
|
||||
behind: Query<Entity, With<Behind>>,
|
||||
|
@ -56,7 +71,7 @@ struct LastIconPitch(HashMap<Entity, f64>);
|
|||
struct LastSoundPitch(HashMap<Entity, f64>);
|
||||
|
||||
fn behind_added(
|
||||
config: Res<PitchShiftPlugin>,
|
||||
config: Res<PitchShiftConfig>,
|
||||
mut last_icon_pitch: ResMut<LastIconPitch>,
|
||||
mut last_sound_pitch: ResMut<LastSoundPitch>,
|
||||
mut query: Query<(Entity, Option<&mut SoundIcon>, Option<&mut Sound>), Added<Behind>>,
|
||||
|
@ -73,7 +88,7 @@ fn behind_added(
|
|||
}
|
||||
|
||||
fn behind_removed(
|
||||
config: Res<PitchShiftPlugin>,
|
||||
config: Res<PitchShiftConfig>,
|
||||
mut last_icon_pitch: ResMut<LastIconPitch>,
|
||||
mut last_sound_pitch: ResMut<LastSoundPitch>,
|
||||
removed: RemovedComponents<Behind>,
|
||||
|
@ -93,7 +108,7 @@ fn behind_removed(
|
|||
}
|
||||
|
||||
fn sound_icon_changed(
|
||||
config: Res<PitchShiftPlugin>,
|
||||
config: Res<PitchShiftConfig>,
|
||||
mut last_icon_pitch: ResMut<LastIconPitch>,
|
||||
mut icons: Query<(Entity, &mut SoundIcon), (With<Behind>, Changed<SoundIcon>)>,
|
||||
) {
|
||||
|
@ -111,7 +126,7 @@ fn sound_icon_changed(
|
|||
}
|
||||
|
||||
fn sound_changed(
|
||||
config: Res<PitchShiftPlugin>,
|
||||
config: Res<PitchShiftConfig>,
|
||||
mut last_sound_pitch: ResMut<LastSoundPitch>,
|
||||
mut sounds: Query<(Entity, &mut Sound), (With<Behind>, Without<SoundIcon>, Changed<Sound>)>,
|
||||
) {
|
||||
|
@ -130,7 +145,7 @@ fn sound_changed(
|
|||
|
||||
fn sync_config(
|
||||
mut commands: Commands,
|
||||
config: Res<PitchShiftPlugin>,
|
||||
config: Res<PitchShiftConfig>,
|
||||
behind: Query<Entity, With<Behind>>,
|
||||
) {
|
||||
if config.is_changed() {
|
||||
|
@ -140,25 +155,12 @@ fn sync_config(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Clone, Copy, Debug)]
|
||||
pub struct PitchShiftPlugin {
|
||||
pub downshift_behind: bool,
|
||||
pub downshift: f64,
|
||||
}
|
||||
|
||||
impl Default for PitchShiftPlugin {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
downshift_behind: false,
|
||||
downshift: 0.95,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct PitchShiftPlugin;
|
||||
|
||||
impl Plugin for PitchShiftPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(*self)
|
||||
.register_type::<Behind>()
|
||||
app.register_type::<Behind>()
|
||||
.init_resource::<PitchShiftConfig>()
|
||||
.init_resource::<LastIconPitch>()
|
||||
.init_resource::<LastSoundPitch>()
|
||||
.add_system_to_stage(CoreStage::PreUpdate, tag_behind)
|
||||
|
|
|
@ -58,7 +58,7 @@ fn added(mut commands: Commands, icons: Query<(Entity, &SoundIcon), Added<SoundI
|
|||
}
|
||||
|
||||
fn update<S>(
|
||||
config: Res<SoundIconPlugin<S>>,
|
||||
config: Res<SoundIconConfig<S>>,
|
||||
state: Res<State<S>>,
|
||||
time: Res<Time>,
|
||||
viewers: Query<&VisibleEntities, With<Player>>,
|
||||
|
@ -183,24 +183,25 @@ fn reset_timer_on_visibility_gain(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct SoundIconPlugin<S> {
|
||||
#[derive(Resource, Clone, Debug, Default)]
|
||||
pub struct SoundIconConfig<S> {
|
||||
pub states: Vec<S>,
|
||||
}
|
||||
|
||||
impl<S> Default for SoundIconPlugin<S> {
|
||||
pub struct SoundIconPlugin<'a, S>(std::marker::PhantomData<&'a S>);
|
||||
|
||||
impl<'a, S> Default for SoundIconPlugin<'a, S> {
|
||||
fn default() -> Self {
|
||||
Self { states: default() }
|
||||
Self(std::marker::PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Plugin for SoundIconPlugin<S>
|
||||
impl<S> Plugin for SoundIconPlugin<'static, S>
|
||||
where
|
||||
S: 'static + Clone + Debug + Eq + Hash + Send + Sync,
|
||||
{
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(self.clone())
|
||||
.register_type::<SoundIcon>()
|
||||
app.register_type::<SoundIcon>()
|
||||
.add_system(added)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, update::<S>)
|
||||
.add_system_to_stage(
|
||||
|
|
|
@ -17,7 +17,7 @@ use crate::{
|
|||
bevy_rapier2d::prelude::*,
|
||||
core::{GlobalTransformExt, Player, PointLike},
|
||||
log::Log,
|
||||
map::{Map, MapObstruction, MapPlugin},
|
||||
map::{Map, MapConfig, MapObstruction},
|
||||
};
|
||||
|
||||
#[derive(Component, Clone, Copy, Debug, Default, Reflect)]
|
||||
|
@ -248,10 +248,10 @@ impl PointLike for Coord {
|
|||
}
|
||||
}
|
||||
|
||||
fn add_visibility_indices<MapData: 'static + Clone + Default + Send + Sync>(
|
||||
fn add_visibility_indices<D: 'static + Clone + Default + Send + Sync>(
|
||||
mut commands: Commands,
|
||||
map_config: Res<MapPlugin<MapData>>,
|
||||
query: Query<(Entity, &Map<MapData>), (Added<Map<MapData>>, Without<RevealedTiles>)>,
|
||||
query: Query<(Entity, &Map<D>), (Added<Map<D>>, Without<RevealedTiles>)>,
|
||||
map_config: Res<MapConfig>,
|
||||
) {
|
||||
for (entity, map) in query.iter() {
|
||||
let count = map.width * map.height;
|
||||
|
@ -430,22 +430,22 @@ fn log_visible(
|
|||
|
||||
pub const LOG_VISIBLE_LABEL: &str = "LOG_VISIBLE";
|
||||
|
||||
pub struct VisibilityPlugin<MapData: 'static + Clone + Default + Send + Sync>(PhantomData<MapData>);
|
||||
pub struct VisibilityPlugin<D: 'static + Clone + Default + Send + Sync>(PhantomData<D>);
|
||||
|
||||
impl<MapData: 'static + Clone + Default + Send + Sync> Default for VisibilityPlugin<MapData> {
|
||||
impl<D: 'static + Clone + Default + Send + Sync> Default for VisibilityPlugin<D> {
|
||||
fn default() -> Self {
|
||||
Self(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<MapData: 'static + Clone + Default + Send + Sync> Plugin for VisibilityPlugin<MapData> {
|
||||
impl<D: 'static + Clone + Default + Send + Sync> Plugin for VisibilityPlugin<D> {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_event::<VisibilityChanged>()
|
||||
.add_system_to_stage(CoreStage::PreUpdate, add_visibility_indices::<MapData>)
|
||||
.add_system_to_stage(CoreStage::PreUpdate, add_visibility_indices::<D>)
|
||||
.add_system_to_stage(CoreStage::PreUpdate, update_viewshed)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, viewshed_removed)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, remove_visible)
|
||||
.add_system_to_stage(CoreStage::PreUpdate, update_revealed_tiles::<MapData>)
|
||||
.add_system_to_stage(CoreStage::PreUpdate, update_revealed_tiles::<D>)
|
||||
.add_system_to_stage(CoreStage::PreUpdate, log_visible);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user