mittens_engine/engine/ecs/component/
stencil_clip.rs1use crate::engine::ecs::component::Component;
2use crate::engine::ecs::{ComponentId, IntentValue, SignalEmitter};
3
4pub struct StencilClipComponent {
25 pub stencil_ref: u8,
27}
28
29impl StencilClipComponent {
30 pub fn new() -> Self {
31 Self { stencil_ref: 0 }
32 }
33}
34
35impl Default for StencilClipComponent {
36 fn default() -> Self {
37 Self::new()
38 }
39}
40
41impl Component for StencilClipComponent {
42 fn name(&self) -> &'static str {
43 "stencil_clip"
44 }
45
46 fn set_id(&mut self, _component: ComponentId) {}
47
48 fn as_any(&self) -> &dyn std::any::Any {
49 self
50 }
51
52 fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
53 self
54 }
55
56 fn init(&mut self, emit: &mut dyn SignalEmitter, component: ComponentId) {
57 emit.push_intent_now(
58 component,
59 IntentValue::RegisterStencilClip {
60 component_ids: vec![component],
61 },
62 );
63 }
64
65 fn cleanup(&mut self, emit: &mut dyn SignalEmitter, component: ComponentId) {
66 emit.push_intent_now(
67 component,
68 IntentValue::UnregisterStencilClip {
69 component_ids: vec![component],
70 },
71 );
72 }
73
74 fn to_mms_ast(
75 &self,
76 _world: &crate::engine::ecs::World,
77 ) -> crate::scripting::ast::ComponentExpression {
78 use crate::engine::ecs::component::ce_helpers::*;
79 if self.stencil_ref == 0 {
80 ce("StencilClip")
81 } else {
82 ce("StencilClip").with_call("stencil_ref", vec![num(self.stencil_ref as f64)])
83 }
84 }
85}