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