Remove bundles.
This commit is contained in:
parent
08c91380ad
commit
8db8b72824
|
@ -23,10 +23,12 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Component, Clone, Debug, Default, Reflect)]
|
#[derive(Component, Clone, Debug, Default, Reflect)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
|
#[require(Transform, Collider(||Collider::rectangle(1., 1.)), RigidBody(|| RigidBody::Static))]
|
||||||
pub struct Obstacle;
|
pub struct Obstacle;
|
||||||
|
|
||||||
#[derive(Default, Component, Clone, Debug, Reflect)]
|
#[derive(Default, Component, Clone, Debug, Reflect)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
|
#[require(Transform, Collider, Sensor)]
|
||||||
pub struct Zone;
|
pub struct Zone;
|
||||||
|
|
||||||
fn relative_desc(rot: &Rot2) -> String {
|
fn relative_desc(rot: &Rot2) -> String {
|
||||||
|
|
96
src/map.rs
96
src/map.rs
|
@ -14,6 +14,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Component, Clone, Default, Deref, DerefMut)]
|
#[derive(Component, Clone, Default, Deref, DerefMut)]
|
||||||
|
#[require(Transform, SpawnColliders, SpawnPortals)]
|
||||||
pub struct Map<D: 'static + Clone + Default + Send + Sync>(pub MapgenMap<D>);
|
pub struct Map<D: 'static + Clone + Default + Send + Sync>(pub MapgenMap<D>);
|
||||||
|
|
||||||
impl<D: Clone + Default + Send + Sync> From<MapgenMap<D>> for Map<D> {
|
impl<D: Clone + Default + Send + Sync> From<MapgenMap<D>> for Map<D> {
|
||||||
|
@ -24,6 +25,7 @@ impl<D: Clone + Default + Send + Sync> From<MapgenMap<D>> for Map<D> {
|
||||||
|
|
||||||
#[derive(Component, Clone, Debug, Default, Reflect)]
|
#[derive(Component, Clone, Debug, Default, Reflect)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
|
#[require(Transform, Mappable)]
|
||||||
pub struct Portal;
|
pub struct Portal;
|
||||||
|
|
||||||
#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect)]
|
#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect)]
|
||||||
|
@ -36,12 +38,6 @@ impl Default for SpawnColliders {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<bool> for SpawnColliders {
|
|
||||||
fn from(v: bool) -> Self {
|
|
||||||
Self(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect)]
|
#[derive(Component, Clone, Debug, Deref, DerefMut, Reflect)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct SpawnPortals(pub bool);
|
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<D: 'static + Clone + Default + Send + Sync> {
|
|
||||||
pub map: Map<D>,
|
|
||||||
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 {
|
pub struct GridBuilder {
|
||||||
width_in_rooms: usize,
|
width_in_rooms: usize,
|
||||||
height_in_rooms: usize,
|
height_in_rooms: usize,
|
||||||
|
@ -234,7 +160,12 @@ fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
|
||||||
for x in 0..map.width {
|
for x in 0..map.width {
|
||||||
if let Some(tile) = map.at(x, y) {
|
if let Some(tile) = map.at(x, y) {
|
||||||
if tile.blocks_motion() {
|
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() {
|
if tile.blocks_visibility() {
|
||||||
commands.entity(id).insert(Visible::opaque());
|
commands.entity(id).insert(Visible::opaque());
|
||||||
}
|
}
|
||||||
|
@ -245,7 +176,11 @@ fn spawn_colliders<D: 'static + Clone + Default + Send + Sync>(
|
||||||
}
|
}
|
||||||
for room in &map.rooms {
|
for room in &map.rooms {
|
||||||
commands.entity(map_entity).with_children(|parent| {
|
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<D: 'static + Clone + Default + Send + Sync>(
|
||||||
}
|
}
|
||||||
for (x, y) in portals {
|
for (x, y) in portals {
|
||||||
commands.entity(map_entity).with_children(|parent| {
|
commands.entity(map_entity).with_children(|parent| {
|
||||||
parent.spawn(PortalBundle {
|
parent.spawn((Portal, Transform::from_xyz(x, y, 0.)));
|
||||||
transform: Transform::from_translation(Vec3::new(x, y, 0.)).into(),
|
|
||||||
..default()
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ pub struct DontLogWhenVisible;
|
||||||
pub struct RevealedTiles(pub Vec<bool>);
|
pub struct RevealedTiles(pub Vec<bool>);
|
||||||
|
|
||||||
#[derive(Component, Clone, Debug, Eq, PartialEq)]
|
#[derive(Component, Clone, Debug, Eq, PartialEq)]
|
||||||
|
#[require(VisibleEntities)]
|
||||||
pub struct Viewshed {
|
pub struct Viewshed {
|
||||||
pub range: u32,
|
pub range: u32,
|
||||||
pub visible_points: HashSet<IVec2>,
|
pub visible_points: HashSet<IVec2>,
|
||||||
|
@ -228,21 +229,6 @@ fn update_opacity_map(
|
||||||
#[derive(Component, Clone, Debug, Default, Deref, DerefMut)]
|
#[derive(Component, Clone, Debug, Default, Deref, DerefMut)]
|
||||||
pub struct VisibleEntities(HashSet<Entity>);
|
pub struct VisibleEntities(HashSet<Entity>);
|
||||||
|
|
||||||
#[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)]
|
#[derive(Event)]
|
||||||
pub enum VisibilityChanged {
|
pub enum VisibilityChanged {
|
||||||
Gained(Entity),
|
Gained(Entity),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user