use bevy_ecs::bundle::Bundle; use bevy_ecs::component::Component; use bevy_ecs::event::Event; use bevy_ecs::system::Resource; use nalgebra::Matrix3; use starkingdoms_common::packet::Packet; use starkingdoms_common::PlanetType; #[derive(Component, Debug, Clone, Copy)] pub struct Translation { pub x: f32, pub y: f32, } impl Translation { pub fn as_matrix(&self) -> Matrix3 { Matrix3::from_iterator([ 1.0, 0.0, self.x, 0.0, 1.0, self.y, 0.0, 0.0, 1.0, ]) } } #[derive(Component, Debug, Clone, Copy)] pub struct Shear { pub x: f32, pub y: f32, } impl Shear { pub fn as_matrix(&self) -> Matrix3 { Matrix3::from_iterator([ 1.0, self.x, 0.0, self.y, 1.0, 0.0, 0.0, 0.0, 1.0, ]) } } #[derive(Component, Debug, Clone, Copy)] pub struct Scale { pub width: f32, pub height: f32, } impl Scale { pub fn as_matrix(&self) -> Matrix3 { Matrix3::from_iterator([ self.width, 0.0, 0.0, 0.0, self.height, 0.0, 0.0, 0.0, 1.0 ]) } } #[derive(Component, Debug, Clone, Copy)] pub struct Rotation { pub radians: f32 } impl Rotation { pub fn as_matrix(&self) -> Matrix3 { let x = self.radians.cos(); let y = self.radians.sin(); Matrix3::from_iterator([ x, y, 0.0, -y, x, 0.0, 0.0, 0.0, 1.0 ]) } } #[derive(Component, Debug, Clone)] pub struct SpriteTexture { pub texture: String, } #[derive(Bundle)] pub struct SpriteBundle { pub position: Translation, pub shear: Shear, pub scale: Scale, pub texture: SpriteTexture, pub rotation: Rotation } #[derive(Resource, Debug)] pub struct Camera { pub x: f32, pub y: f32, pub shear_x: f32, pub shear_y: f32, pub zoom: f32, } #[derive(Component, Debug, Clone, Copy)] pub struct Player; #[derive(Component, Debug, Clone, Copy)] pub struct Planet(PlanetType); #[derive(Event, Clone, PartialEq)] pub struct SendPacket(pub Packet); #[derive(Event, Clone, PartialEq)] pub struct RecvPacket(pub Packet);