how do I make eventing extensible without cluttering this file with standalone functions

This commit is contained in:
2020-09-19 01:24:00 -07:00
parent 84999130bb
commit aaef25f710
2 changed files with 69 additions and 30 deletions

64
src/event_system.rs Normal file
View File

@@ -0,0 +1,64 @@
use std::sync::Arc;
use specs::{Component, Entities, Join, System, VecStorage, Write, WriteStorage};
use vulkano::swapchain::Surface;
use winit::window::Window;
use crate::canvas::canvas_frame::CanvasFrame;
use crate::canvas::compu_frame::CompuFrame;
use crate::PersistentState;
use crate::render_system::Position;
use crate::util::tr_event::{TrEvent, TrEventExtension, TrWindowEvent};
use crate::vkprocessor::VkProcessor;
use winit::event::ElementState;
#[derive(Debug, Clone)]
pub struct Evented {
pub subscribed: fn(event: TrEvent<TrEventExtension>) -> bool,
}
impl Component for Evented {
type Storage = VecStorage<Self>;
}
pub struct EventSystem;
impl<'a> System<'a> for EventSystem {
type SystemData = (
Entities<'a>,
WriteStorage<'a, Position>,
WriteStorage<'a, Evented>,
Write<'a, PersistentState>,
Write<'a, VkProcessor>,
Write<'a, Vec<TrEvent<TrEventExtension>>>
);
fn run(&mut self, (
entity,
mut position_list,
mut evented_list,
mut state,
mut vk_processor,
event_stack
): Self::SystemData) {
for (position, evented) in (&mut position_list, &evented_list).join() {
for event in &*event_stack {
match event {
TrEvent::WindowEvent { window_id, event } => {
match event {
TrWindowEvent::MouseInput { device_id, state, button, modifiers } => {
if *state == ElementState::Pressed {
position.x += 100.0;
}
},
_ => {}
}
}
_ => {}
}
}
}
for (entity, evented) in (&*entity, &mut evented_list).join() {}
}
}