use glam::Vec2;
use crate::camera::Rect;
use crate::color::Color;
use crate::ctx::Ctx;
use crate::texture::Texture;
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(default)]
#[repr(C)] pub struct Transform2D {
pub position: Vec2,
pub rotation: f32,
pub scale: Vec2,
}
impl Default for Transform2D {
fn default() -> Self {
Self {
position: Vec2::ZERO,
rotation: 0.0,
scale: Vec2::ONE,
}
}
}
impl Transform2D {
#[must_use]
pub fn at(position: Vec2) -> Self {
Self {
position,
..Default::default()
}
}
#[must_use]
pub fn rotated(self, rotation: f32) -> Self {
Self { rotation, ..self }
}
#[must_use]
pub fn scaled(self, scale: Vec2) -> Self {
Self { scale, ..self }
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Sprite {
pub texture: Texture,
pub color: Color,
pub z: f32,
pub pivot: Vec2,
pub region: Option<Rect>,
}
impl Sprite {
#[must_use]
pub fn new(texture: Texture) -> Self {
Self {
texture,
color: Color::WHITE,
z: 0.0,
pivot: Vec2::splat(0.5),
region: None,
}
}
#[must_use]
pub fn with_region(self, region: Rect) -> Self {
Self {
region: Some(region),
..self
}
}
#[must_use]
pub fn with_color(self, color: Color) -> Self {
Self { color, ..self }
}
#[must_use]
pub fn with_z(self, z: f32) -> Self {
Self { z, ..self }
}
#[must_use]
pub fn with_pivot(self, pivot: Vec2) -> Self {
Self { pivot, ..self }
}
}
pub fn draw_sprites(ctx: &mut Ctx) {
ctx.draw_world_sprites();
}