Improve selection system #78

Merged
CoCo_Sol merged 14 commits from improve-selection into main 2024-03-19 15:08:43 +00:00
2 changed files with 5 additions and 17 deletions
Showing only changes of commit 61c56bcdca - Show all commits

View file

@ -2,9 +2,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use border_wars::camera::CameraPlugin; use border_wars::camera::CameraPlugin;
use border_wars::map::generation::{MapGenerationPlugin, StartMapGeneration};
use border_wars::map::renderer::RendererPlugin; use border_wars::map::renderer::RendererPlugin;
use border_wars::map::selected_tile::TilesClickable;
use border_wars::scenes::ScenesPlugin; use border_wars::scenes::ScenesPlugin;
fn main() { fn main() {
@ -13,15 +11,5 @@ fn main() {
.add_plugins(ScenesPlugin) .add_plugins(ScenesPlugin)
.add_plugins(RendererPlugin) .add_plugins(RendererPlugin)
.add_plugins(CameraPlugin) .add_plugins(CameraPlugin)
.add_plugins(TilesClickable)
.add_plugins(MapGenerationPlugin)
.add_systems(OnEnter(border_wars::CurrentScene::Game), start)
.run(); .run();
} }
fn start(mut event: EventWriter<StartMapGeneration>) {
event.send(StartMapGeneration {
seed: 0,
radius: 10,
});
}

View file

@ -1,4 +1,4 @@
//! All programs related to the clicking on a tile. //! All programs related to the selection of a tile.
use bevy::prelude::*; use bevy::prelude::*;
@ -45,9 +45,9 @@ impl SelectedTile {
} }
/// A plugin that handles the selection of tiles. /// A plugin that handles the selection of tiles.
pub struct TilesClickable; pub struct SelectTilePlugin;
impl Plugin for TilesClickable { impl Plugin for SelectTilePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(PreUpdate, mouse_handler) app.add_systems(PreUpdate, mouse_handler)
.add_systems(PreUpdate, select_closest_tile) .add_systems(PreUpdate, select_closest_tile)
@ -97,7 +97,7 @@ fn mouse_handler(
events_writer.send(ClickOnTheWorld(cursor_position_in_world)); events_writer.send(ClickOnTheWorld(cursor_position_in_world));
} }
/// Get the closest tile to the cursor and send it in an event. /// Get the closest tile to the cursor, send it in an event and select it.
fn select_closest_tile( fn select_closest_tile(
tiles: Query<(Entity, &Transform, &Tile)>, tiles: Query<(Entity, &Transform, &Tile)>,
mut click_event_reader: EventReader<ClickOnTheWorld>, mut click_event_reader: EventReader<ClickOnTheWorld>,