From da1ecb1f2136f4c7ada3a7a8dba33ba306a270c5 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Fri, 1 Aug 2025 19:25:14 -0500 Subject: [PATCH] #13 cleanup extensions --- src/extensions/id.rs | 4 ++-- src/extensions/mod.rs | 2 -- src/extensions/resources.rs | 22 ---------------------- src/extensions/tick.rs | 4 ++-- src/extensions/velocity.rs | 6 ++---- 5 files changed, 6 insertions(+), 32 deletions(-) delete mode 100644 src/extensions/resources.rs diff --git a/src/extensions/id.rs b/src/extensions/id.rs index de629d9..d2be182 100644 --- a/src/extensions/id.rs +++ b/src/extensions/id.rs @@ -4,6 +4,8 @@ use crate::{component, extensions::Extension, widget::Widget, Screen}; pub struct IdExtension(pub Arc); +component!(Id(pub usize)); + impl Extension for Arc {} impl IdExtension { @@ -23,5 +25,3 @@ impl IdExtension { None } } - -component!(Id(pub usize)); diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index 3d19d81..ea6607e 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -1,10 +1,8 @@ pub mod id; -pub mod resources; pub mod tick; pub mod velocity; pub use id::*; -pub use resources::*; pub use tick::*; pub use velocity::*; diff --git a/src/extensions/resources.rs b/src/extensions/resources.rs deleted file mode 100644 index 1542111..0000000 --- a/src/extensions/resources.rs +++ /dev/null @@ -1,22 +0,0 @@ -use std::sync::{Arc, Mutex}; - -#[derive(Clone)] -pub struct VecResource(Arc>>); - -impl VecResource { - pub fn new() -> Self { - Self(Arc::new(Mutex::new(Box::new(|_| {})))) - } - - pub fn iterate(&self, f: F) { - *self.0.lock().unwrap() = Box::new(f); - } - - pub fn push(&self, e: T) { - let i = self.0.clone(); - - std::thread::spawn(move || { - (i.lock().unwrap())(&e); - }); - } -} diff --git a/src/extensions/tick.rs b/src/extensions/tick.rs index 9ee857a..6334015 100644 --- a/src/extensions/tick.rs +++ b/src/extensions/tick.rs @@ -6,6 +6,8 @@ use crate::{event, Screen}; pub struct TickExtension(pub u16); +event!(TickEvent(pub u32)); + impl Extension for TickExtension { fn init(&mut self, screen: Arc) { let rate_dur = 1000 / self.0 as u64; @@ -25,5 +27,3 @@ impl Extension for TickExtension { }); } } - -event!(TickEvent(pub u32)); diff --git a/src/extensions/velocity.rs b/src/extensions/velocity.rs index 1f3fefb..74aabee 100644 --- a/src/extensions/velocity.rs +++ b/src/extensions/velocity.rs @@ -10,6 +10,8 @@ use crate::{ pub struct VelocityExtension; +component!(Velocity(pub i32, pub i32)); + impl VelocityExtension { fn apply_velocity(ticks: u16, velocity: i32, x: &mut u16) { if velocity.abs() != 0 && ticks as i32 % (1000 / velocity.abs()) == 0 { @@ -20,9 +22,7 @@ impl VelocityExtension { } } } -} -impl VelocityExtension { fn apply_velocity_xy(ticks: u16, widget: &Arc) { if let Some(velocity) = widget.get::() { if let Some(mut t) = widget.get::() { @@ -62,5 +62,3 @@ impl Extension for VelocityExtension { }); } } - -component!(Velocity(pub i32, pub i32));