This commit is contained in:
2025-06-24 17:21:12 +02:00
parent f72959bcee
commit 6c0dde8e85
5 changed files with 65 additions and 88 deletions
+13 -31
View File
@@ -1,35 +1,17 @@
use std::{any::TypeId, thread, time::Duration};
pub mod text;
pub mod macros;
pub mod output;
use std::fmt::Debug;
use downcast_rs::{impl_downcast, DowncastSync};
pub trait Component: DowncastSync + Debug {}
impl_downcast!(sync Component);
pub trait Element {
fn get_component<T: Component + 'static>(&mut self) -> Option<&mut T>;
fn add_component<T: Component + 'static>(&mut self, component: T);
}
pub trait Extension {
fn tick(&mut self, args: &mut Args);
}
pub trait BaseElement {
fn init(&mut self);
fn get_components<'a>(&'a mut self) -> &'a mut Vec<Box<dyn ElementComponent>>;
}
pub trait ElementComponent {
fn get_type_id(&self) -> TypeId;
}
pub struct Args {
pub tick_rate: u16,
pub base_elements: Vec<Box<dyn BaseElement>>,
}
pub fn run(mut args: Args, mut extensions: Vec<Box<dyn Extension>>) {
for elem in &mut args.base_elements {
elem.init();
}
loop {
for extension in &mut extensions {
extension.tick(&mut args);
}
thread::sleep(Duration::from_millis(1000 / args.tick_rate as u64));
}
fn tick(&mut self);
}