#13 cleanup extensions

This commit is contained in:
2025-08-01 19:25:14 -05:00
parent 75827260cc
commit da1ecb1f21
5 changed files with 6 additions and 32 deletions
+2 -2
View File
@@ -4,6 +4,8 @@ use crate::{component, extensions::Extension, widget::Widget, Screen};
pub struct IdExtension(pub Arc<Screen>);
component!(Id(pub usize));
impl Extension for Arc<IdExtension> {}
impl IdExtension {
@@ -23,5 +25,3 @@ impl IdExtension {
None
}
}
component!(Id(pub usize));
-2
View File
@@ -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::*;
-22
View File
@@ -1,22 +0,0 @@
use std::sync::{Arc, Mutex};
#[derive(Clone)]
pub struct VecResource<T>(Arc<Mutex<Box<dyn FnMut(&T) + Send + Sync>>>);
impl<T: Send + Sync + 'static> VecResource<T> {
pub fn new() -> Self {
Self(Arc::new(Mutex::new(Box::new(|_| {}))))
}
pub fn iterate<F: FnMut(&T) + Send + Sync + 'static>(&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);
});
}
}
+2 -2
View File
@@ -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<Screen>) {
let rate_dur = 1000 / self.0 as u64;
@@ -25,5 +27,3 @@ impl Extension for TickExtension {
});
}
}
event!(TickEvent(pub u32));
+2 -4
View File
@@ -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<Widget>) {
if let Some(velocity) = widget.get::<Velocity>() {
if let Some(mut t) = widget.get::<Transform>() {
@@ -62,5 +62,3 @@ impl Extension for VelocityExtension {
});
}
}
component!(Velocity(pub i32, pub i32));