mittens_engine/engine/ecs/component/
avatar_body_yaw.rs1use crate::engine::ecs::ComponentId;
2use crate::engine::ecs::component::Component;
3
4#[derive(Debug, Clone)]
16pub struct AvatarBodyYawComponent {
17 pub threshold: f32,
19
20 pub rate: f32,
22
23 pub hmd_driven_transform: Option<ComponentId>,
26
27 pub(crate) body_yaw: f32,
30
31 pub forward_plus_z: bool,
35
36 component: Option<ComponentId>,
37}
38
39impl AvatarBodyYawComponent {
40 pub fn new() -> Self {
41 Self::default()
42 }
43
44 pub fn with_threshold(mut self, t: f32) -> Self {
45 self.threshold = t;
46 self
47 }
48
49 pub fn with_rate(mut self, r: f32) -> Self {
50 self.rate = r;
51 self
52 }
53
54 pub fn with_hmd_driven_transform(mut self, id: ComponentId) -> Self {
55 self.hmd_driven_transform = Some(id);
56 self
57 }
58
59 pub fn with_initial_yaw(mut self, yaw: f32) -> Self {
62 self.body_yaw = yaw;
63 self
64 }
65
66 pub fn with_forward_plus_z(mut self) -> Self {
69 self.forward_plus_z = true;
70 self
71 }
72}
73
74impl Default for AvatarBodyYawComponent {
75 fn default() -> Self {
76 Self {
77 threshold: std::f32::consts::FRAC_PI_4,
78 rate: 3.0,
79 hmd_driven_transform: None,
80 body_yaw: std::f32::consts::PI,
81 forward_plus_z: false,
82 component: None,
83 }
84 }
85}
86
87impl Component for AvatarBodyYawComponent {
88 fn name(&self) -> &'static str {
89 "avatar_body_yaw"
90 }
91
92 fn set_id(&mut self, id: ComponentId) {
93 self.component = Some(id);
94 }
95
96 fn init(&mut self, emit: &mut dyn crate::engine::ecs::SignalEmitter, component: ComponentId) {
97 emit.push_intent_now(
98 component,
99 crate::engine::ecs::IntentValue::RegisterAvatarBodyYaw {
100 component_ids: vec![component],
101 },
102 );
103 }
104
105 fn as_any(&self) -> &dyn std::any::Any {
106 self
107 }
108
109 fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
110 self
111 }
112
113 fn to_mms_ast(
114 &self,
115 _world: &crate::engine::ecs::World,
116 ) -> crate::scripting::ast::ComponentExpression {
117 use crate::engine::ecs::component::ce_helpers::*;
118 let mut c = ce("AvatarBodyYaw")
119 .with_call("threshold", vec![num(self.threshold as f64)])
120 .with_call("rate", vec![num(self.rate as f64)]);
121 if self.forward_plus_z {
122 c = c.with_call("forward_plus_z", vec![]);
123 }
124 c
125 }
126}