handle some more event types

This commit is contained in:
Robin Appelman 2023-03-11 22:56:46 +01:00
commit 3ad9ebafd7
5 changed files with 33 additions and 5 deletions

View file

@ -26,6 +26,7 @@ impl Derivable for Events {
Ok(
quote_spanned!(span => impl #impl_generics #enum_ident #ty_generics #where_clause {
pub fn parse(raw: &RawEvent<'a>) -> Result<Self, GameEventError> {
dbg!(raw);
Ok(match raw.ty {
#(#variants)*
_ => {

View file

@ -93,14 +93,29 @@ pub enum GameEvent<'a> {
PointCaptured(PointCapturedEvent<'a>),
CurrentScore(CurrentScoreEvent),
BuiltObject(BuiltObjectEvent<'a>),
DropObject(DropObjectEvent<'a>),
CarryObject(BuiltCarryEvent<'a>),
KilledObject(KilledObjectEvent<'a>),
Extinguished(ExtinguishedEvent<'a>),
GameOver(GameOverEvent<'a>),
FinalScore(FinalScoreEvent),
ObjectDetonated(ObjectDetonatedEvent<'a>),
Request(UnparsedEvent<'a>),
Response(UnparsedEvent<'a>),
LogFileClosed,
}
#[derive(Debug)]
pub struct UnparsedEvent<'a> {
pub params: &'a str,
}
impl<'a> Event<'a> for UnparsedEvent<'a> {
fn parse(input: &'a str) -> IResult<Self> {
Ok(("", UnparsedEvent { params: input }))
}
}
pub struct ParamIter<'a> {
input: &'a str,
}

View file

@ -100,6 +100,18 @@ pub struct BuiltObjectEvent<'a> {
pub position: Option<(i32, i32, i32)>,
}
#[derive(Debug, Event)]
pub struct BuiltCarryEvent<'a> {
pub object: Option<&'a str>,
pub position: Option<(i32, i32, i32)>,
}
#[derive(Debug, Event)]
pub struct DropObjectEvent<'a> {
pub object: Option<&'a str>,
pub position: Option<(i32, i32, i32)>,
}
#[derive(Debug, Event)]
pub struct KilledObjectEvent<'a> {
pub object: Option<&'a str>,

View file

@ -120,7 +120,7 @@ impl<'a> LineSplit<'a> {
LineSplit {
input,
start: 0,
iter: find_iter(input.as_bytes(), b"L "),
iter: find_iter(input.as_bytes(), b"\nL "),
}
}
}
@ -131,8 +131,8 @@ impl<'a> Iterator for LineSplit<'a> {
fn next(&mut self) -> Option<Self::Item> {
match self.iter.next() {
Some(next) => {
let line = &self.input[self.start..next - 1]; // -1 for the newline we strip
self.start = next + 2;
let line = &self.input[self.start..next];
self.start = next + 3;
Some(line)
}
None if self.start < self.input.len() => {

View file

@ -180,9 +180,9 @@ pub enum RawEventType {
#[token(r#"triggered "player_builtobject""#)]
BuiltObject,
#[token(r#"triggered "player_dropobject""#)]
PlayerCarryObject,
CarryObject,
#[token(r#"triggered "player_carryobject""#)]
PlayerDropObject,
DropObject,
#[token(r#"triggered "killedobject""#)]
KilledObject,
#[token(r#"triggered "object_detonated""#)]