~starkingdoms/starkingdoms

ref: ceb494101ee016d1502ac0048ddeab3de93a7dfd starkingdoms/crates/client/src/components.rs -rw-r--r-- 1.3 KiB
ceb49410 — ghostly_zsh saturn draws again 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use bevy_ecs::{bundle::Bundle, component::Component, event::Event, system::Resource};
use nalgebra::{Matrix4, Rotation2, Scale3, Translation3};
use starkingdoms_common::packet::Packet;

#[derive(Component, Debug)]
pub struct Texture {
    pub name: String,
}

#[derive(Component, Debug)]
pub struct Transform {
    pub translation: Translation3<f32>,
    pub rotation: Rotation2<f32>,
    pub scale: Scale3<f32>,
}
impl Transform {
    pub fn to_matrix(&self) -> Matrix4<f32> {
        self.translation.to_homogeneous() * self.rotation.to_homogeneous().to_homogeneous() * self.scale.to_homogeneous()
    }
}

#[derive(Bundle, Debug)]
pub struct SpriteBundle {
    pub transform: Transform,
    pub texture: Texture,
}

#[derive(Resource, Debug)]
pub struct Camera {
    pub x: f32,
    pub y: f32,
    pub zoom: f32,
    pub width: u32, // screen width (these are for aspect ratio)
    pub height: u32, // screen height
}

#[derive(Component, Debug, Clone, Copy)]
pub struct Player;
#[derive(Component, Debug, Clone, Copy)]
pub struct Planet;
#[derive(Component, Debug, Clone, Copy)]
pub struct Part;
#[derive(Component, Debug, Clone, Copy)]
pub struct ServerId(pub u32);

#[derive(Event, Clone, PartialEq)]
pub struct SendPacket(pub Packet);
#[derive(Event, Clone, PartialEq)]
pub struct RecvPacket(pub Packet);