mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-11 02:29:25 +00:00
wip
This commit is contained in:
40
pong/src/event.rs
Normal file
40
pong/src/event.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
pub mod event {
|
||||
pub struct Event {
|
||||
pub msg: String
|
||||
}
|
||||
|
||||
pub trait EventWriterImpl {
|
||||
fn write(&self, event: Event) -> std::io::Result<()>;
|
||||
}
|
||||
|
||||
pub struct FileEventWriterImpl {}
|
||||
impl EventWriterImpl for FileEventWriterImpl {
|
||||
fn write(&self, event: Event) -> std::io::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EventWriter {
|
||||
writer_impl: Box<dyn EventWriterImpl>
|
||||
}
|
||||
|
||||
impl EventWriter {
|
||||
fn new(writer_impl: Box<dyn EventWriterImpl>) -> EventWriter {
|
||||
EventWriter {
|
||||
writer_impl
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file() -> EventWriter {
|
||||
EventWriter {
|
||||
writer_impl: Box::new(FileEventWriterImpl {})
|
||||
}
|
||||
}
|
||||
// TODO: Kafka
|
||||
|
||||
pub fn write(&self, event: Event) -> std::io::Result<()> {
|
||||
self.writer_impl.write(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,3 +4,4 @@ pub mod game_object;
|
||||
pub mod geom;
|
||||
pub mod pong;
|
||||
pub mod utils;
|
||||
pub mod event;
|
||||
|
||||
@@ -56,3 +56,37 @@ pub mod pong_collisions {
|
||||
player_pos.y = new_pos.y;
|
||||
}
|
||||
}
|
||||
|
||||
pub mod pong_events {
|
||||
use crate::event::event::EventWriter;
|
||||
use crate::geom::geom::Vector;
|
||||
|
||||
pub enum PongEventType {
|
||||
GameObjUpdate(GameObjUpdate)
|
||||
}
|
||||
|
||||
pub struct GameObjUpdate {
|
||||
pub pos: Vector,
|
||||
pub vel: Vector,
|
||||
pub orientation: Vector
|
||||
}
|
||||
|
||||
pub struct PongEventWriter {
|
||||
writer: EventWriter
|
||||
}
|
||||
|
||||
impl PongEventWriter {
|
||||
pub fn new() -> PongEventWriter {
|
||||
PongEventWriter {
|
||||
writer: EventWriter::file()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(&self, event: PongEventType) -> std::io::Result<()> {
|
||||
// TODO: Event to string
|
||||
self.writer.write()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user