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