From c49b6ac33fc9dd06efd8c49080cdf735acc9b730 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 20 May 2021 14:54:13 -0500 Subject: [PATCH] Goodbye exits, hello portals. --- src/exploration.rs | 6 ++--- src/map.rs | 61 +++++++++++++++++++++++----------------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/exploration.rs b/src/exploration.rs index 6cae8c9..14a2bba 100644 --- a/src/exploration.rs +++ b/src/exploration.rs @@ -21,7 +21,7 @@ pub struct ExplorationFocused; #[allow(dead_code)] #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Reflect)] pub enum ExplorationType { - Exit = 0, + Portal = 0, Item = 1, Character = 2, Ally = 3, @@ -33,7 +33,7 @@ pub enum ExplorationType { impl Into for ExplorationType { fn into(self) -> String { match self { - ExplorationType::Exit => "Exit".into(), + ExplorationType::Portal => "Portal".into(), ExplorationType::Item => "Item".into(), ExplorationType::Character => "Character".into(), ExplorationType::Ally => "Ally".into(), @@ -47,7 +47,7 @@ impl Into for ExplorationType { impl Into<&str> for ExplorationType { fn into(self) -> &'static str { match self { - ExplorationType::Exit => "exit", + ExplorationType::Portal => "exit", ExplorationType::Item => "item", ExplorationType::Character => "character", ExplorationType::Ally => "ally", diff --git a/src/map.rs b/src/map.rs index 2768897..7226ac1 100644 --- a/src/map.rs +++ b/src/map.rs @@ -20,9 +20,9 @@ impl From for Coordinates { #[derive(Clone, Debug, Default, Deref, DerefMut)] pub struct Areas(pub Vec); -#[derive(Clone, Copy, Debug, Default, Reflect)] +#[derive(Clone, Debug, Default, Deref, DerefMut, Reflect)] #[reflect(Component)] -pub struct Exit; +pub struct Portal(Vec<(i32, i32)>); #[derive(Clone, Default)] pub struct Map { @@ -83,7 +83,7 @@ impl ITileType for TileType { #[derive(Clone, Debug)] pub struct MapConfig { - pub autospawn_exits: bool, + pub autospawn_portals: bool, pub describe_undescribed_areas: bool, pub speak_area_descriptions: bool, pub start_revealed: bool, @@ -92,7 +92,7 @@ pub struct MapConfig { impl Default for MapConfig { fn default() -> Self { Self { - autospawn_exits: true, + autospawn_portals: true, describe_undescribed_areas: false, speak_area_descriptions: true, start_revealed: false, @@ -101,21 +101,21 @@ impl Default for MapConfig { } #[derive(Bundle)] -pub struct ExitBundle { +pub struct PortalBundle { pub coordinates: Coordinates, - pub exit: Exit, + pub portal: Portal, pub exploration_type: ExplorationType, pub mappable: Mappable, pub transform: Transform, pub global_transform: GlobalTransform, } -impl Default for ExitBundle { +impl Default for PortalBundle { fn default() -> Self { Self { coordinates: Default::default(), - exit: Default::default(), - exploration_type: ExplorationType::Exit, + portal: Default::default(), + exploration_type: ExplorationType::Portal, mappable: Default::default(), transform: Default::default(), global_transform: Default::default(), @@ -203,17 +203,17 @@ impl MapFilter for GridBuilder { } } -fn exit_spawner( +fn portal_spawner( mut commands: Commands, map: Query<(Entity, &Map), Added>, config: Res, ) { for (entity, map) in map.iter() { - if config.autospawn_exits { - let mut exits: Vec<(f32, f32)> = vec![]; + if config.autospawn_portals { + let mut portals: Vec<(f32, f32)> = vec![]; for x in 1..map.width() { for y in 1..map.height() { - let mut spawn_exit = false; + let mut spawn_portal = false; if map.base.get_available_exits(x, y).len() > 2 { let idx = (x, y).to_index(map.width()); if map.base.tiles[idx] == TileType::Floor @@ -224,7 +224,7 @@ fn exit_spawner( && (y < map.height() - 2 && map.base.tiles[idx + map.width() as usize] == TileType::Wall) { - spawn_exit = true; + spawn_portal = true; } if map.base.tiles[idx] == TileType::Floor && (x > 1 && map.base.tiles[idx - 1] == TileType::Wall) @@ -234,31 +234,32 @@ fn exit_spawner( && (y < map.height() - 2 && map.base.tiles[idx + map.width() as usize] == TileType::Floor) { - spawn_exit = true; + spawn_portal = true; } } - if spawn_exit { + if spawn_portal { let x = x as f32; let y = y as f32; - if !exits.contains(&(x, y)) { - exits.push((x, y)); + if !portals.contains(&(x, y)) { + portals.push((x, y)); } } } } - for exit in exits { - let x = exit.0 as f32; - let y = exit.1 as f32; - let exit = commands + for portal in portals { + let x = portal.0 as f32; + let y = portal.1 as f32; + let coordinates = Coordinates((x, y)); + let portal = commands .spawn() - .insert_bundle(ExitBundle { - coordinates: Coordinates((x, y)), - exit: Default::default(), + .insert_bundle(PortalBundle { + coordinates, + portal: Portal(vec![coordinates.i32()]), transform: Transform::from_translation(Vec3::new(x, y, 0.)), ..Default::default() }) .id(); - commands.entity(entity).push_children(&[exit]); + commands.entity(entity).push_children(&[portal]); } } } @@ -358,14 +359,14 @@ impl Plugin for MapPlugin { app.insert_resource(MapConfig::default()); } let config = app.world().get_resource::().unwrap().clone(); - const SPAWN_EXITS: &str = "SPAWN_EXITS"; - app.register_type::() + const SPAWN_PORTALS: &str = "SPAWN_PORTALS"; + app.register_type::() .insert_resource(PreviousIndex::default()) .add_system(entity_indexing.system().label(UPDATE_ENTITY_INDEX_LABEL)) .add_system( - exit_spawner + portal_spawner .system() - .label(SPAWN_EXITS) + .label(SPAWN_PORTALS) .before(UPDATE_ENTITY_INDEX_LABEL), ) .add_system_to_stage(