Click-on tile handle system #74

Merged
CoCo_Sol merged 12 commits from select-tiles into main 2024-03-09 14:51:46 +00:00
2 changed files with 6 additions and 6 deletions
Showing only changes of commit 87c8f508d8 - Show all commits

View file

@ -2,7 +2,7 @@
use bevy::prelude::*;
use border_wars::camera::CameraPlugin;
use border_wars::map::click_tile::SelectorPlugin;
use border_wars::map::click_tile::TilesClickable;
use border_wars::map::renderer::RendererPlugin;
use border_wars::scenes::ScenesPlugin;
@ -12,6 +12,6 @@ fn main() {
.add_plugins(ScenesPlugin)
.add_plugins(RendererPlugin)
.add_plugins(CameraPlugin)
.add_plugins(SelectorPlugin)
.add_plugins(TilesClickable)
.run();
}

View file

@ -22,9 +22,9 @@ struct ClickOnTheWorld(Vec2);
pub struct ZoneNotClickable;
/// A plugin that handles the selection of tiles.
pub struct SelectorPlugin;
pub struct TilesClickable;
impl Plugin for SelectorPlugin {
impl Plugin for TilesClickable {
fn build(&self, app: &mut App) {
app.add_systems(PreUpdate, mouse_handler)
.add_systems(PreUpdate, select_closest_tile)
@ -77,7 +77,7 @@ fn mouse_handler(
fn select_closest_tile(
tiles: Query<(Entity, &Transform, &Tile)>,
mut click_event_reader: EventReader<ClickOnTheWorld>,
mut select_tile_event_writer: EventWriter<TileJustClicked>,
mut clicked_tile_event_writer: EventWriter<TileJustClicked>,
) {
for click_event in click_event_reader.read() {
// The closest tile and its distance to the cursor.
@ -99,7 +99,7 @@ fn select_closest_tile(
}
}
if let Some(tile_entity) = closest_entity {
select_tile_event_writer.send(TileJustClicked(tile_entity.index()));
clicked_tile_event_writer.send(TileJustClicked(tile_entity.index()));
}
}
}