This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use bevy_mod_raycast to handle tile selection (#262)
* Add bevy_mod_picking * More explicit usage * Remove CursorWorldPos * Cleanup * Update cursor position using bevy_mod_picking * WIP tile highlights * Add tests for tile selection * Bind Esc to clear selection * Rearrange tile selection logic for clarity * Swap to simple bevy_mod_raycast solution * Remove debug cursor * Actually store tile handles * Remove redundant TileSelectionActionModify
- Loading branch information
1 parent
a4325e3
commit dc33e76
Showing
14 changed files
with
248 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//! Code related to loading, storing and tracking assets | ||
use bevy::{prelude::*, utils::HashMap}; | ||
|
||
use crate::terrain::Terrain; | ||
|
||
/// Collects asset management systems and resources. | ||
pub struct AssetManagementPlugin; | ||
|
||
impl Plugin for AssetManagementPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.init_resource::<TileHandles>(); | ||
} | ||
} | ||
|
||
/// Stores material handles for the different tile types. | ||
#[derive(Resource)] | ||
pub(crate) struct TileHandles { | ||
/// The material used for each type of terrain | ||
pub(crate) terrain_handles: HashMap<Terrain, Handle<StandardMaterial>>, | ||
/// The material used for tiles when they are selected | ||
pub(crate) selected_tile_handle: Handle<StandardMaterial>, | ||
} | ||
|
||
impl FromWorld for TileHandles { | ||
fn from_world(world: &mut World) -> Self { | ||
let mut materials = world.resource_mut::<Assets<StandardMaterial>>(); | ||
let mut terrain_handles = HashMap::new(); | ||
terrain_handles.insert(Terrain::Plain, materials.add(Color::WHITE.into())); | ||
terrain_handles.insert(Terrain::Rocky, materials.add(Color::BEIGE.into())); | ||
terrain_handles.insert(Terrain::High, materials.add(Color::RED.into())); | ||
|
||
let selected_tile_handle = materials.add(Color::SEA_GREEN.into()); | ||
|
||
TileHandles { | ||
terrain_handles, | ||
selected_tile_handle, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.