Galactica/crates/gameobject/src/system.rs

34 lines
659 B
Rust
Raw Normal View History

2024-01-01 15:46:39 -08:00
use crate::SystemObject;
use galactica_content as content;
2024-01-01 11:29:48 -08:00
use galactica_render::ObjectSprite;
2023-12-21 11:26:44 -08:00
pub struct System {
2023-12-25 09:01:59 -08:00
pub name: String,
2024-01-02 15:59:50 -08:00
pub bodies: Vec<SystemObject>,
2023-12-21 11:26:44 -08:00
}
impl System {
2024-01-01 15:46:39 -08:00
pub fn new(ct: &content::Content, handle: content::SystemHandle) -> Self {
let sys = ct.get_system(handle);
2023-12-23 23:24:04 -08:00
let mut s = System {
2024-01-01 15:46:39 -08:00
name: sys.name.clone(),
2023-12-23 23:24:04 -08:00
bodies: Vec::new(),
};
2023-12-22 16:51:21 -08:00
2024-01-01 15:46:39 -08:00
for o in &sys.objects {
2023-12-25 16:21:14 -08:00
s.bodies.push(SystemObject {
2023-12-25 10:30:27 -08:00
pos: o.position,
sprite: o.sprite,
2023-12-25 09:01:12 -08:00
size: o.size,
2023-12-25 10:30:27 -08:00
angle: o.angle,
2023-12-25 09:01:12 -08:00
});
}
2023-12-22 16:51:21 -08:00
2023-12-21 11:26:44 -08:00
return s;
}
2023-12-31 17:58:17 -08:00
pub fn get_sprites(&self) -> Vec<ObjectSprite> {
2023-12-24 18:45:39 -08:00
return self.bodies.iter().map(|x| x.get_sprite()).collect();
2023-12-21 11:26:44 -08:00
}
}