This commit is contained in:
Thilo Behnke
2022-05-02 14:04:39 +02:00
parent 97ac6b6f55
commit 6b91bd09c4
3 changed files with 75 additions and 0 deletions

40
pong/src/event.rs Normal file
View 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)
}
}
}

View File

@@ -4,3 +4,4 @@ pub mod game_object;
pub mod geom;
pub mod pong;
pub mod utils;
pub mod event;

View File

@@ -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()
}
}
}