mittens_engine/engine/ecs/component/
serialize.rs1use crate::engine::ecs::ComponentId;
2use crate::engine::ecs::component::Component;
3
4#[derive(Debug, Clone, Copy)]
10pub struct SerializeComponent {
11 pub enabled: bool,
12 component: Option<ComponentId>,
13}
14
15impl SerializeComponent {
16 pub fn on() -> Self {
17 Self {
18 enabled: true,
19 component: None,
20 }
21 }
22
23 pub fn off() -> Self {
24 Self {
25 enabled: false,
26 component: None,
27 }
28 }
29}
30
31impl Default for SerializeComponent {
32 fn default() -> Self {
33 Self::on()
34 }
35}
36
37impl Component for SerializeComponent {
38 fn set_id(&mut self, id: ComponentId) {
39 self.component = Some(id);
40 }
41
42 fn name(&self) -> &'static str {
43 "serialize"
44 }
45
46 fn as_any(&self) -> &dyn std::any::Any {
47 self
48 }
49
50 fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
51 self
52 }
53
54 fn to_mms_ast(
55 &self,
56 _world: &crate::engine::ecs::World,
57 ) -> crate::scripting::ast::ComponentExpression {
58 use crate::engine::ecs::component::ce_helpers::*;
59 let ctor = if self.enabled { "on" } else { "off" };
60 ce_call("Serialize", ctor, vec![])
61 }
62}