Skip to content

Commit

Permalink
Join common system conditions (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
Indy2222 authored Jul 25, 2023
1 parent dca41f4 commit 854ab46
Show file tree
Hide file tree
Showing 31 changed files with 138 additions and 267 deletions.
33 changes: 11 additions & 22 deletions crates/camera/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,56 +54,45 @@ impl Plugin for CameraPlugin {
.add_systems(
InputSchedule,
(
handle_horizontal_events
.run_if(in_state(GameState::Playing))
.in_set(CameraSet::MoveHorizontallEvent),
handle_zoom_events
.run_if(in_state(GameState::Playing))
.in_set(CameraSet::ZoomEvent),
handle_rotate_events
.run_if(in_state(GameState::Playing))
.in_set(CameraSet::RotateEvent),
handle_tilt_events
.run_if(in_state(GameState::Playing))
.in_set(CameraSet::TiltEvent),
),
handle_horizontal_events.in_set(CameraSet::MoveHorizontallEvent),
handle_zoom_events.in_set(CameraSet::ZoomEvent),
handle_rotate_events.in_set(CameraSet::RotateEvent),
handle_tilt_events.in_set(CameraSet::TiltEvent),
)
.run_if(in_state(GameState::Playing)),
)
.add_systems(
PreMovement,
(
update_focus
.run_if(in_state(GameState::Playing))
.run_if(on_event::<FocusInvalidatedEvent>())
.in_set(InternalCameraSet::UpdateFocus),
process_move_focus_events
.run_if(in_state(GameState::Playing))
.in_set(InternalCameraSet::MoveFocus)
.after(InternalCameraSet::UpdateFocus),
update_translation_handler
.run_if(in_state(GameState::Playing))
.run_if(on_event::<UpdateTranslationEvent>())
.after(InternalCameraSet::MoveFocus),
),
)
.run_if(in_state(GameState::Playing)),
)
.add_systems(
Movement,
(
zoom.run_if(in_state(GameState::Playing))
.in_set(InternalCameraSet::Zoom),
zoom.in_set(InternalCameraSet::Zoom),
pivot
.run_if(in_state(GameState::Playing))
.run_if(
resource_exists_and_changed::<DesiredOffNadir>()
.or_else(resource_exists_and_changed::<DesiredAzimuth>()),
)
.in_set(InternalCameraSet::Pivot),
move_horizontaly
.run_if(in_state(GameState::Playing))
// Zooming changes camera focus point so do it
// after other types of camera movement.
.after(InternalCameraSet::Zoom)
.after(InternalCameraSet::Pivot),
),
)
.run_if(in_state(GameState::Playing)),
);
}
}
Expand Down
11 changes: 5 additions & 6 deletions crates/camera/src/distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ impl Plugin for DistancePlugin {
app.add_systems(
PostUpdate,
(
init::<MovableSolid>.run_if(in_state(AppState::InGame)),
init::<StaticSolid>.run_if(in_state(AppState::InGame)),
update
.run_if(in_state(AppState::InGame))
.in_set(DistanceSet::Update),
),
init::<MovableSolid>,
init::<StaticSolid>,
update.in_set(DistanceSet::Update),
)
.run_if(in_state(AppState::InGame)),
);
}
}
Expand Down
16 changes: 6 additions & 10 deletions crates/combat/src/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,21 @@ impl Plugin for AttackPlugin {
PreUpdate,
(
attack
.run_if(in_state(GameState::Playing))
.in_set(AttackingSet::Attack)
.before(ChaseSet::ChaseTargetEvent),
update_positions
.run_if(in_state(GameState::Playing))
.after(AttackingSet::Attack),
),
update_positions.after(AttackingSet::Attack),
)
.run_if(in_state(GameState::Playing)),
)
.add_systems(
Update,
(
charge
.run_if(in_state(GameState::Playing))
.in_set(AttackingSet::Charge),
charge.in_set(AttackingSet::Charge),
aim_and_fire
.run_if(in_state(GameState::Playing))
.after(AttackingSet::Charge)
.before(AttackingSet::Fire),
),
)
.run_if(in_state(GameState::Playing)),
);
}
}
Expand Down
5 changes: 1 addition & 4 deletions crates/combat/src/trail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ impl Plugin for TrailPlugin {
.add_systems(OnExit(AppState::InGame), cleanup)
.add_systems(
PostUpdate,
(
spawn.run_if(in_state(GameState::Playing)),
update.run_if(in_state(GameState::Playing)),
),
(spawn, update).run_if(in_state(GameState::Playing)),
);
}
}
Expand Down
16 changes: 5 additions & 11 deletions crates/construction/src/manufacturing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,14 @@ impl Plugin for ManufacturingPlugin {
.add_systems(
PreUpdate,
(
change_locations
.run_if(in_state(GameState::Playing))
.in_set(ManufacturingSet::ChangeLocations),
check_spawn_locations
.run_if(in_state(GameState::Playing))
.before(ManufacturingSet::Produce),
produce
.run_if(in_state(GameState::Playing))
.in_set(ManufacturingSet::Produce),
change_locations.in_set(ManufacturingSet::ChangeLocations),
check_spawn_locations.before(ManufacturingSet::Produce),
produce.in_set(ManufacturingSet::Produce),
deliver
.run_if(in_state(GameState::Playing))
.after(ManufacturingSet::ChangeLocations)
.after(ManufacturingSet::Produce),
),
)
.run_if(in_state(GameState::Playing)),
)
.add_systems(Update, enqueue.run_if(in_state(GameState::Playing)))
.add_systems(PostUpdate, configure.run_if(in_state(AppState::InGame)));
Expand Down
15 changes: 5 additions & 10 deletions crates/controller/src/commands/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ impl Plugin for ExecutorPlugin {
.add_systems(
InputSchedule,
(
send_selected_system
.run_if(in_state(GameState::Playing))
.in_set(CommandsSet::SendSelected),
delivery_location_system
.run_if(in_state(GameState::Playing))
.in_set(CommandsSet::DeliveryLocation),
attack_system
.run_if(in_state(GameState::Playing))
.in_set(CommandsSet::Attack),
),
send_selected_system.in_set(CommandsSet::SendSelected),
delivery_location_system.in_set(CommandsSet::DeliveryLocation),
attack_system.in_set(CommandsSet::Attack),
)
.run_if(in_state(GameState::Playing)),
);
}
}
Expand Down
23 changes: 5 additions & 18 deletions crates/controller/src/commands/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,53 +74,40 @@ impl Plugin for HandlersPlugin {
InputSchedule,
(
right_click_handler
.run_if(in_state(GameState::Playing))
.run_if(on_click(MouseButton::Right))
.after(PointerSet::Update)
.after(MouseSet::Buttons)
.before(CommandsSet::SendSelected)
.before(CommandsSet::DeliveryLocation)
.before(CommandsSet::Attack),
left_click_handler
.run_if(in_state(GameState::Playing))
.run_if(on_click(MouseButton::Left))
.in_set(HandlersSet::LeftClick)
.before(SelectionSet::Update)
.before(DraftSet::Spawn)
.after(PointerSet::Update)
.after(MouseSet::Buttons),
double_click_handler
.run_if(in_state(GameState::Playing))
.run_if(on_double_click(MouseButton::Left))
.before(SelectionSet::Update)
.before(DraftSet::Spawn)
.after(PointerSet::Update)
.after(MouseSet::Buttons)
.after(HandlersSet::LeftClick),
move_camera_arrows_system
.run_if(in_state(GameState::Playing))
.before(CameraSet::MoveHorizontallEvent),
move_camera_mouse_system
.run_if(in_state(GameState::Playing))
.before(CameraSet::MoveHorizontallEvent),
zoom_camera
.run_if(in_state(GameState::Playing))
.before(CameraSet::ZoomEvent),
move_camera_arrows_system.before(CameraSet::MoveHorizontallEvent),
move_camera_mouse_system.before(CameraSet::MoveHorizontallEvent),
zoom_camera.before(CameraSet::ZoomEvent),
pivot_camera
.run_if(in_state(GameState::Playing))
.before(CameraSet::RotateEvent)
.before(CameraSet::TiltEvent),
handle_escape
.run_if(in_state(GameState::Playing))
.run_if(KeyCondition::single(KeyCode::Escape).build())
.before(GameMenuSet::Toggle)
.before(DraftSet::Discard),
select_all
.run_if(in_state(GameState::Playing))
.run_if(KeyCondition::single(KeyCode::A).with_ctrl().build())
.before(SelectionSet::Update),
select_all_visible
.run_if(in_state(GameState::Playing))
.run_if(
KeyCondition::single(KeyCode::A)
.with_ctrl()
Expand All @@ -129,10 +116,10 @@ impl Plugin for HandlersPlugin {
)
.before(AreaSelectSet::SelectInArea),
update_drags
.run_if(in_state(GameState::Playing))
.before(AreaSelectSet::SelectInArea)
.after(MouseSet::Buttons),
),
)
.run_if(in_state(GameState::Playing)),
);

Self::add_place_draft_systems(app);
Expand Down
21 changes: 10 additions & 11 deletions crates/controller/src/draft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ impl Plugin for DraftPlugin {
.add_systems(
InputSchedule,
(
spawn
.run_if(in_state(AppState::InGame))
.run_if(on_event::<SpawnDraftsEvent>())
.in_set(DraftSet::Spawn),
new_drafts
.run_if(in_state(AppState::InGame))
.in_set(DraftSet::New),
discard_drafts
.run_if(in_state(AppState::InGame))
.run_if(on_event::<DiscardDraftsEvent>())
.in_set(DraftSet::Discard),
(
spawn
.run_if(on_event::<SpawnDraftsEvent>())
.in_set(DraftSet::Spawn),
new_drafts.in_set(DraftSet::New),
discard_drafts
.run_if(on_event::<DiscardDraftsEvent>())
.in_set(DraftSet::Discard),
)
.run_if(in_state(AppState::InGame)),
move_drafts
.run_if(in_state(GameState::Playing))
.after(PointerSet::Update),
Expand Down
8 changes: 3 additions & 5 deletions crates/controller/src/hud/actionbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ impl Plugin for ActionBarPlugin {
.add_systems(
PostUpdate,
(
detect_update
.run_if(in_state(GameState::Playing))
.in_set(ActionBarSet::DetectUpdate),
detect_update.in_set(ActionBarSet::DetectUpdate),
update
.run_if(in_state(GameState::Playing))
.run_if(resource_exists_and_changed::<ActiveEntity>())
.after(ActionBarSet::DetectUpdate),
),
)
.run_if(in_state(GameState::Playing)),
)
.add_systems(
InputSchedule,
Expand Down
8 changes: 2 additions & 6 deletions crates/controller/src/hud/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ impl Plugin for MenuPlugin {
.add_systems(OnExit(GameState::Playing), cleanup)
.add_systems(
InputSchedule,
(
toggle_system
.run_if(in_state(GameState::Playing))
.in_set(GameMenuSet::Toggle),
button_system.run_if(in_state(GameState::Playing)),
),
(toggle_system.in_set(GameMenuSet::Toggle), button_system)
.run_if(in_state(GameState::Playing)),
);
}
}
Expand Down
12 changes: 4 additions & 8 deletions crates/controller/src/hud/minimap/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@ impl Plugin for FillPlugin {
app.add_systems(
PostMovement,
(
clear_system
.run_if(in_state(GameState::Playing))
.in_set(FillSet::Clear),
clear_system.in_set(FillSet::Clear),
draw_entities_system
.run_if(in_state(GameState::Playing))
.in_set(FillSet::DrawEntities)
.after(FillSet::Clear),
draw_camera_system
.run_if(in_state(GameState::Playing))
.after(FillSet::DrawEntities),
),
draw_camera_system.after(FillSet::DrawEntities),
)
.run_if(in_state(GameState::Playing)),
);
}
}
Expand Down
13 changes: 4 additions & 9 deletions crates/controller/src/hud/minimap/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,16 @@ impl Plugin for InteractionPlugin {
app.add_event::<MinimapClickEvent>().add_systems(
InputSchedule,
(
click_handler
.run_if(in_state(GameState::Playing))
.in_set(InteractionSet::ClickHandler),
move_camera_system
.run_if(in_state(GameState::Playing))
.after(InteractionSet::ClickHandler),
click_handler.in_set(InteractionSet::ClickHandler),
move_camera_system.after(InteractionSet::ClickHandler),
send_units_system
.run_if(in_state(GameState::Playing))
.after(InteractionSet::ClickHandler)
.before(CommandsSet::SendSelected),
delivery_location_system
.run_if(in_state(GameState::Playing))
.after(InteractionSet::ClickHandler)
.before(CommandsSet::DeliveryLocation),
),
)
.run_if(in_state(GameState::Playing)),
);
}
}
Expand Down
10 changes: 3 additions & 7 deletions crates/controller/src/mouse/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,19 @@ impl Plugin for InputPlugin {
.add_systems(
InputSchedule,
(
update_position
.run_if(in_state(GameState::Playing))
.in_set(MouseSet::Position),
update_position.in_set(MouseSet::Position),
update_drags
.run_if(in_state(GameState::Playing))
.run_if(resource_exists_and_changed::<MousePosition>())
.in_set(MouseSet::Drags)
.after(MouseSet::Position),
update_buttons
.run_if(in_state(GameState::Playing))
.in_set(MouseSet::SingeButton)
.after(MouseSet::Drags),
check_double_click
.run_if(in_state(GameState::Playing))
.in_set(MouseSet::Buttons)
.after(MouseSet::SingeButton),
),
)
.run_if(in_state(GameState::Playing)),
);
}
}
Expand Down
Loading

0 comments on commit 854ab46

Please sign in to comment.