From 643c5caf0e1f3ea84bb28cc258e0a7a1f03c7fde Mon Sep 17 00:00:00 2001 From: lisk77 Date: Tue, 6 May 2025 17:09:00 +0200 Subject: [PATCH] feat: added a `Timer` component --- crates/comet_ecs/src/component.rs | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/comet_ecs/src/component.rs b/crates/comet_ecs/src/component.rs index c22fbbe..fc2252e 100644 --- a/crates/comet_ecs/src/component.rs +++ b/crates/comet_ecs/src/component.rs @@ -2,7 +2,6 @@ // You can use these components as is or as a reference to create your own components // Also just as a nomenclature: bundles are a component made up of multiple components, // so it's a collection of components bundled together (like Transform2D) - use comet_math::m4; use crate::math::{ v2, @@ -75,6 +74,13 @@ pub struct Color { a: f32 } +#[derive(Component)] +pub struct Timer { + time_stack: f32, + interval: f32, + done: bool +} + // ################################################## // # BUNDLES # // ################################################## @@ -401,6 +407,10 @@ impl Text { self.color } + pub fn set_visibility(&mut self, visibility: bool) { + self.is_visible = visibility + } + pub fn is_visible(&self) -> bool { self.is_visible } @@ -465,4 +475,26 @@ impl Color { a: self.a as f64 } } +} + +impl Timer { + pub fn set_interval(&mut self, interval: f32) { + self.interval = interval + } + + pub fn update_timer(&mut self, elapsed_time: f32) { + self.time_stack += elapsed_time; + if self.time_stack > self.interval { + self.done = true + } + } + + pub fn is_done(&self) -> bool { + self.done + } + + pub fn reset(&mut self) { + self.time_stack = 0.0; + self.done = false; + } } \ No newline at end of file