Simplify exploration code.

This commit is contained in:
Nolan Darilek 2024-12-01 16:02:14 -06:00
parent 1cfbf7f65b
commit f903801ba8

View File

@ -1,4 +1,9 @@
use std::{error::Error, fmt::Debug, hash::Hash, marker::PhantomData}; use std::{
error::Error,
fmt::{Debug, Display},
hash::Hash,
marker::PhantomData,
};
use bevy::prelude::*; use bevy::prelude::*;
use bevy_rapier2d::prelude::*; use bevy_rapier2d::prelude::*;
@ -182,7 +187,7 @@ fn exploration_type_changed_announcement<ExplorationType>(
>, >,
) -> Result<(), Box<dyn Error>> ) -> Result<(), Box<dyn Error>>
where where
ExplorationType: Component + Default + Copy + Into<String>, ExplorationType: Component + Default + Copy + Display,
{ {
for (focused, changed) in &focused { for (focused, changed) in &focused {
if changed.is_added() { if changed.is_added() {
@ -190,8 +195,7 @@ where
} }
match &focused.0 { match &focused.0 {
Some(v) => { Some(v) => {
let v: String = (*v).into(); tts.speak(format!("{v}"), true)?;
tts.speak(v, true)?;
} }
None => { None => {
tts.speak("Everything", true)?; tts.speak("Everything", true)?;
@ -284,7 +288,7 @@ fn exploration_changed_announcement<ExplorationType, MapData>(
rapier_context: Res<RapierContext>, rapier_context: Res<RapierContext>,
) -> Result<(), Box<dyn Error>> ) -> Result<(), Box<dyn Error>>
where where
ExplorationType: Component + Copy + Into<String>, ExplorationType: Component + Copy + Display,
MapData: 'static + Clone + Default + Send + Sync, MapData: 'static + Clone + Default + Send + Sync,
{ {
if let Ok((coordinates, exploring, viewshed)) = explorer.get_single() { if let Ok((coordinates, exploring, viewshed)) = explorer.get_single() {
@ -318,7 +322,7 @@ where
} }
if tokens.is_empty() { if tokens.is_empty() {
if let Ok(t) = types.get(entity) { if let Ok(t) = types.get(entity) {
tokens.push((*t).into()); tokens.push(format!("{t}"));
} }
} }
} }
@ -385,7 +389,7 @@ pub struct Exploration;
impl<ExplorationType, MapData> Plugin for ExplorationPlugin<ExplorationType, MapData> impl<ExplorationType, MapData> Plugin for ExplorationPlugin<ExplorationType, MapData>
where where
ExplorationType: 'static + Component + Default + Copy + Ord + PartialEq + Into<String>, ExplorationType: 'static + Component + Default + Copy + Ord + PartialEq + Display,
MapData: 'static + Clone + Default + Send + Sync, MapData: 'static + Clone + Default + Send + Sync,
{ {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {