use bevy::prelude::*;
use crate::draw::{Draw, drawing};
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct Properties {
pub x: Option<f32>,
pub y: Option<f32>,
pub z: Option<f32>,
}
pub trait SetDimensions: Sized {
fn properties(&mut self) -> &mut Properties;
fn width(mut self, w: f32) -> Self {
self.properties().x = Some(w);
self
}
fn height(mut self, h: f32) -> Self {
self.properties().y = Some(h);
self
}
fn depth(mut self, d: f32) -> Self {
self.properties().z = Some(d);
self
}
fn w(self, w: f32) -> Self {
self.width(w)
}
fn h(self, h: f32) -> Self {
self.height(h)
}
fn d(self, d: f32) -> Self {
self.depth(d)
}
fn wh(self, v: Vec2) -> Self {
self.w(v.x).h(v.y)
}
fn whd(self, v: Vec3) -> Self {
self.w(v.x).h(v.y).d(v.z)
}
fn w_h(self, x: f32, y: f32) -> Self {
self.wh([x, y].into())
}
fn w_h_d(self, x: f32, y: f32, z: f32) -> Self {
self.whd([x, y, z].into())
}
}
impl SetDimensions for Properties {
fn properties(&mut self) -> &mut Properties {
self
}
}
pub(crate) fn set_dimensions(
draw: &Draw,
index: usize,
x: Option<f32>,
y: Option<f32>,
z: Option<f32>,
) {
drawing::with_primitive(draw, index, |prim| match prim.dimensions_mut() {
Some(props) => {
if x.is_some() {
props.x = x;
}
if y.is_some() {
props.y = y;
}
if z.is_some() {
props.z = z;
}
}
None => bevy::log::warn_once!("drawing primitive does not support `dimensions`"),
})
}