From 8db8b72824ee1e9f37d0a891b6cc1e01c268fd49 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 7 Jan 2025 12:27:37 -0500 Subject: [PATCH] Remove bundles. --- src/core.rs | 2 + src/map.rs | 96 +++++++---------------------------------------- src/visibility.rs | 16 +------- 3 files changed, 17 insertions(+), 97 deletions(-) diff --git a/src/core.rs b/src/core.rs index 3abd675..d688143 100644 --- a/src/core.rs +++ b/src/core.rs @@ -23,10 +23,12 @@ use serde::{Deserialize, Serialize}; #[derive(Component, Clone, Debug, Default, Reflect)] #[reflect(Component)] +#[require(Transform, Collider(||Collider::rectangle(1., 1.)), RigidBody(|| RigidBody::Static))] pub struct Obstacle; #[derive(Default, Component, Clone, Debug, Reflect)] #[reflect(Component)] +#[require(Transform, Collider, Sensor)] pub struct Zone; fn relative_desc(rot: &Rot2) -> String { diff --git a/src/map.rs b/src/map.rs index 5391674..cc74c77 100644 --- a/src/map.rs +++ b/src/map.rs @@ -14,6 +14,7 @@ use crate::{ }; #[derive(Component, Clone, Default, Deref, DerefMut)] +#[require(Transform, SpawnColliders, SpawnPortals)] pub struct Map(pub MapgenMap); impl From> for Map { @@ -24,6 +25,7 @@ impl From> for Map { #[derive(Component, Clone, Debug, Default, Reflect)] #[reflect(Component)] +#[require(Transform, Mappable)] pub struct Portal; #[derive(Component, Clone, Debug, Deref, DerefMut, Reflect)] @@ -36,12 +38,6 @@ impl Default for SpawnColliders { } } -impl From for SpawnColliders { - fn from(v: bool) -> Self { - Self(v) - } -} - #[derive(Component, Clone, Debug, Deref, DerefMut, Reflect)] #[reflect(Component)] pub struct SpawnPortals(pub bool); @@ -67,76 +63,6 @@ impl ITileType for Tile { } } -#[derive(Bundle, Default)] -pub struct PortalBundle { - pub transform: Transform, - pub portal: Portal, - pub mappable: Mappable, -} - -#[derive(Bundle, Clone, Default)] -pub struct MapBundle { - pub map: Map, - pub spawn_colliders: SpawnColliders, - pub spawn_portals: SpawnPortals, - pub transform: Transform, -} - -#[derive(Bundle, Clone, Debug)] -pub struct TileBundle { - pub transform: Transform, - pub collider: Collider, - pub rigid_body: RigidBody, - pub obstacle: Obstacle, -} - -impl Default for TileBundle { - fn default() -> Self { - Self { - transform: default(), - collider: Collider::rectangle(1., 1.), - rigid_body: RigidBody::Static, - obstacle: default(), - } - } -} - -impl TileBundle { - pub fn new(x: i32, y: i32) -> Self { - Self { - transform: Transform::from_xyz(x as f32 + 0.5, y as f32 + 0.5, 0.), - ..default() - } - } -} - -#[derive(Bundle, Clone, Debug)] -pub struct ZoneBundle { - pub collider: Collider, - pub transform: Transform, - pub zone: Zone, - pub sensor: Sensor, -} - -impl ZoneBundle { - fn new(collider: Collider, position: Vec2) -> Self { - Self { - collider, - transform: Transform::from_translation(position.extend(0.)).into(), - zone: default(), - sensor: default(), - } - } -} - -impl From<&MRect> for ZoneBundle { - fn from(rect: &MRect) -> Self { - let collider = Collider::rectangle(rect.width() as f32 + 1., rect.height() as f32 + 1.); - let position = Vec2::new(rect.center().x(), rect.center().y()); - Self::new(collider, position) - } -} - pub struct GridBuilder { width_in_rooms: usize, height_in_rooms: usize, @@ -234,7 +160,12 @@ fn spawn_colliders( for x in 0..map.width { if let Some(tile) = map.at(x, y) { if tile.blocks_motion() { - let id = commands.spawn(TileBundle::new(x as i32, y as i32)).id(); + let id = commands + .spawn(( + Obstacle, + Transform::from_xyz(x as f32 + 0.5, y as f32 + 0.5, 0.), + )) + .id(); if tile.blocks_visibility() { commands.entity(id).insert(Visible::opaque()); } @@ -245,7 +176,11 @@ fn spawn_colliders( } for room in &map.rooms { commands.entity(map_entity).with_children(|parent| { - parent.spawn(ZoneBundle::from(room)); + parent.spawn(( + Zone, + Transform::from_xyz(room.center().x as f32, room.center().y as f32, 0.), + Collider::rectangle(room.width() as f32 + 1., room.height() as f32 + 1.), + )); }); } } @@ -291,10 +226,7 @@ fn spawn_portals( } for (x, y) in portals { commands.entity(map_entity).with_children(|parent| { - parent.spawn(PortalBundle { - transform: Transform::from_translation(Vec3::new(x, y, 0.)).into(), - ..default() - }); + parent.spawn((Portal, Transform::from_xyz(x, y, 0.))); }); } } diff --git a/src/visibility.rs b/src/visibility.rs index 2365df0..b3dde56 100644 --- a/src/visibility.rs +++ b/src/visibility.rs @@ -23,6 +23,7 @@ pub struct DontLogWhenVisible; pub struct RevealedTiles(pub Vec); #[derive(Component, Clone, Debug, Eq, PartialEq)] +#[require(VisibleEntities)] pub struct Viewshed { pub range: u32, pub visible_points: HashSet, @@ -228,21 +229,6 @@ fn update_opacity_map( #[derive(Component, Clone, Debug, Default, Deref, DerefMut)] pub struct VisibleEntities(HashSet); -#[derive(Bundle, Default)] -pub struct ViewshedBundle { - pub viewshed: Viewshed, - pub visible_entities: VisibleEntities, -} - -impl ViewshedBundle { - pub fn new(range: u32) -> Self { - Self { - viewshed: Viewshed { range, ..default() }, - ..default() - } - } -} - #[derive(Event)] pub enum VisibilityChanged { Gained(Entity),