Add event handling to systems

This commit is contained in:
Emre Osmanoğlu 2025-09-10 15:54:23 +03:00
parent c32a452f17
commit 948a929040
5 changed files with 30 additions and 23 deletions

View file

@ -18,27 +18,18 @@ const MAIN_SCENE_ID: &str = "main_scene";
#[derive(Default)]
struct UpdateAspectRatioSystem;
impl System for UpdateAspectRatioSystem {
fn initialize(&mut self) {}
fn load_world(&mut self, _ctx: &mut SystemContext) {}
fn update(&mut self, ctx: &mut SystemContext) {
// FIXME: Need an event handler rework for systems.
match &ctx.platform_context.current_event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::Resized(sz) => {
let _ = ctx
.scene
.world
.query_mut::<&mut Camera>()
.into_iter()
.map(|(_, cam)| {
cam.aspect = sz.width as f32 / sz.height as f32;
});
}
_ => {}
},
_ => {}
fn handle_event(&mut self, ctx: &mut SystemContext) {
if let Event::WindowEvent { event: WindowEvent::Resized(sz), .. } =
&ctx.platform_context.current_event
{
let _ = ctx
.scene
.world
.query_mut::<&mut Camera>()
.into_iter()
.map(|(_, cam)| {
cam.aspect = sz.width as f32 / sz.height as f32;
});
}
}
}