transform: impl deref/derefmut for components
This commit is contained in:
parent
fe1adb6cf6
commit
f0fc380a39
@ -1,6 +1,7 @@
|
||||
use bevy_ecs::Entity;
|
||||
use bevy_property::Properties;
|
||||
use smallvec::SmallVec;
|
||||
use std::ops::{DerefMut, Deref};
|
||||
|
||||
#[derive(Default, Clone, Properties, Debug)]
|
||||
pub struct Children(pub SmallVec<[Entity; 8]>);
|
||||
@ -10,3 +11,16 @@ impl Children {
|
||||
Self(SmallVec::from_slice(entity))
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Children {
|
||||
type Target = SmallVec<[Entity; 8]>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Children {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
use bevy_math::Mat4;
|
||||
use bevy_property::Properties;
|
||||
use std::fmt;
|
||||
use std::{ops::{DerefMut, Deref}, fmt};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Properties)]
|
||||
pub struct LocalTransform(pub Mat4);
|
||||
@ -22,3 +22,16 @@ impl fmt::Display for LocalTransform {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for LocalTransform {
|
||||
type Target = Mat4;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for LocalTransform {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
use bevy_math::Vec3;
|
||||
use bevy_property::Properties;
|
||||
use std::fmt;
|
||||
use std::{ops::{DerefMut, Deref}, fmt};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Properties)]
|
||||
pub struct NonUniformScale(pub Vec3);
|
||||
@ -41,3 +41,16 @@ impl fmt::Display for NonUniformScale {
|
||||
write!(f, "NonUniformScale({}, {}, {})", x, y, z)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for NonUniformScale {
|
||||
type Target = Vec3;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for NonUniformScale {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,22 @@
|
||||
use bevy_ecs::Entity;
|
||||
use bevy_property::Properties;
|
||||
use std::ops::{DerefMut, Deref};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Properties)]
|
||||
pub struct Parent(pub Entity);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub struct PreviousParent(pub Option<Entity>);
|
||||
|
||||
impl Deref for Parent {
|
||||
type Target = Entity;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Parent {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
use bevy_math::Quat;
|
||||
use bevy_property::Properties;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Properties)]
|
||||
pub struct Rotation(pub Quat);
|
||||
@ -21,3 +22,16 @@ impl From<Quat> for Rotation {
|
||||
Self(rotation)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Rotation {
|
||||
type Target = Quat;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Rotation {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
use bevy_property::Properties;
|
||||
use std::fmt;
|
||||
use std::{ops::{DerefMut, Deref}, fmt};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Properties)]
|
||||
pub struct Scale(pub f32);
|
||||
@ -29,3 +29,16 @@ impl fmt::Display for Scale {
|
||||
write!(f, "Scale({})", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Scale {
|
||||
type Target = f32;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Scale {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,8 @@
|
||||
use bevy_math::Vec3;
|
||||
use bevy_property::Properties;
|
||||
use std::ops::{DerefMut, Deref};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Properties)]
|
||||
#[derive(Debug, PartialEq, Copy, Clone, Properties)]
|
||||
pub struct Translation(pub Vec3);
|
||||
|
||||
impl Translation {
|
||||
@ -27,3 +28,16 @@ impl From<Vec3> for Translation {
|
||||
Self(Vec3::from(translation))
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Translation {
|
||||
type Target = Vec3;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Translation {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
@ -166,7 +166,6 @@ mod test {
|
||||
world
|
||||
.get::<Children>(parent)
|
||||
.unwrap()
|
||||
.0
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>(),
|
||||
@ -177,7 +176,6 @@ mod test {
|
||||
world
|
||||
.get::<Children>(children[1])
|
||||
.unwrap()
|
||||
.0
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>(),
|
||||
@ -192,7 +190,6 @@ mod test {
|
||||
world
|
||||
.get::<Children>(parent)
|
||||
.unwrap()
|
||||
.0
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>(),
|
||||
|
||||
@ -193,8 +193,7 @@ fn ball_collision_system(
|
||||
mut brick_query: Query<(Entity, &Brick, &Translation, &Sprite)>,
|
||||
mut wall_query: Query<(&Wall, &Translation, &Sprite)>,
|
||||
) {
|
||||
for (mut ball, translation, sprite) in &mut ball_query.iter() {
|
||||
let ball_position = translation.0;
|
||||
for (mut ball, ball_translation, sprite) in &mut ball_query.iter() {
|
||||
let ball_size = sprite.size;
|
||||
let velocity = &mut ball.velocity;
|
||||
let mut collision = None;
|
||||
@ -205,7 +204,7 @@ fn ball_collision_system(
|
||||
break;
|
||||
}
|
||||
|
||||
collision = collide(ball_position, ball_size, translation.0, sprite.size);
|
||||
collision = collide(ball_translation.0, ball_size, translation.0, sprite.size);
|
||||
}
|
||||
|
||||
// check collision with paddle(s)
|
||||
@ -214,7 +213,7 @@ fn ball_collision_system(
|
||||
break;
|
||||
}
|
||||
|
||||
collision = collide(ball_position, ball_size, translation.0, sprite.size);
|
||||
collision = collide(ball_translation.0, ball_size, translation.0, sprite.size);
|
||||
}
|
||||
|
||||
// check collision with bricks
|
||||
@ -223,7 +222,7 @@ fn ball_collision_system(
|
||||
break;
|
||||
}
|
||||
|
||||
collision = collide(ball_position, ball_size, translation.0, sprite.size);
|
||||
collision = collide(ball_translation.0, ball_size, translation.0, sprite.size);
|
||||
if collision.is_some() {
|
||||
scoreboard.score += 1;
|
||||
commands.despawn(brick_entity);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user