generated from tipragot/rust
Improve selection system #78
|
@ -2,9 +2,7 @@
|
|||
|
||||
use bevy::prelude::*;
|
||||
use border_wars::camera::CameraPlugin;
|
||||
use border_wars::map::generation::{MapGenerationPlugin, StartMapGeneration};
|
||||
use border_wars::map::renderer::RendererPlugin;
|
||||
use border_wars::map::selected_tile::TilesClickable;
|
||||
use border_wars::scenes::ScenesPlugin;
|
||||
|
||||
fn main() {
|
||||
|
@ -13,15 +11,5 @@ fn main() {
|
|||
.add_plugins(ScenesPlugin)
|
||||
.add_plugins(RendererPlugin)
|
||||
.add_plugins(CameraPlugin)
|
||||
.add_plugins(TilesClickable)
|
||||
.add_plugins(MapGenerationPlugin)
|
||||
.add_systems(OnEnter(border_wars::CurrentScene::Game), start)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn start(mut event: EventWriter<StartMapGeneration>) {
|
||||
event.send(StartMapGeneration {
|
||||
seed: 0,
|
||||
radius: 10,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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::*;
|
||||
|
||||
|
@ -45,9 +45,9 @@ impl SelectedTile {
|
|||
}
|
||||
|
||||
/// 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) {
|
||||
app.add_systems(PreUpdate, mouse_handler)
|
||||
.add_systems(PreUpdate, select_closest_tile)
|
||||
|
@ -97,7 +97,7 @@ fn mouse_handler(
|
|||
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(
|
||||
tiles: Query<(Entity, &Transform, &Tile)>,
|
||||
mut click_event_reader: EventReader<ClickOnTheWorld>,
|
||||
|
|
Loading…
Reference in a new issue