mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-04 02:34:10 +02:00
class stats
This commit is contained in:
parent
cdaa164575
commit
9c63c8b658
8 changed files with 354 additions and 8 deletions
24
src/event/game.rs
Normal file
24
src/event/game.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use crate::event::{param_parse, param_parse_with};
|
||||
use nom::combinator::opt;
|
||||
use nom::number::complete::float;
|
||||
use nom::IResult;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RoundWinEvent<'a> {
|
||||
pub team: Option<&'a str>,
|
||||
}
|
||||
|
||||
pub fn round_win_event_parser(input: &str) -> IResult<&str, RoundWinEvent> {
|
||||
let (input, team) = opt(param_parse("against"))(input)?;
|
||||
Ok((input, RoundWinEvent { team }))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RoundLengthEvent {
|
||||
pub length: Option<f32>,
|
||||
}
|
||||
|
||||
pub fn round_length_event_parser(input: &str) -> IResult<&str, RoundLengthEvent> {
|
||||
let (input, length) = opt(param_parse_with("against", float))(input)?;
|
||||
Ok((input, RoundLengthEvent { length }))
|
||||
}
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
mod game;
|
||||
mod medic;
|
||||
mod player;
|
||||
|
||||
use crate::event::game::{RoundLengthEvent, RoundWinEvent};
|
||||
use crate::{RawEvent, RawEventType};
|
||||
pub use game::*;
|
||||
pub use medic::*;
|
||||
use nom::bytes::complete::{tag, take_while};
|
||||
use nom::character::complete::{alpha1, digit1};
|
||||
|
|
@ -59,6 +62,12 @@ pub enum GameEvent<'a> {
|
|||
FirstHeal(FirstHealEvent),
|
||||
ChargeReady,
|
||||
MedicDeath(MedicDeathEvent),
|
||||
Spawned(SpawnEvent),
|
||||
RoleChange(RoleChangeEvent),
|
||||
RoundStart,
|
||||
RoundWin(RoundWinEvent<'a>),
|
||||
RoundLength(RoundLengthEvent),
|
||||
RoundOverTime,
|
||||
}
|
||||
|
||||
impl<'a> GameEvent<'a> {
|
||||
|
|
@ -100,6 +109,20 @@ impl<'a> GameEvent<'a> {
|
|||
RawEventType::MedicDeath => {
|
||||
GameEvent::MedicDeath(medic_death_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::Spawned => {
|
||||
GameEvent::Spawned(spawn_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::ChangedRole => {
|
||||
GameEvent::RoleChange(role_changed_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::RoundStart => GameEvent::RoundStart,
|
||||
RawEventType::RoundLength => {
|
||||
GameEvent::RoundLength(round_length_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::RoundWin => {
|
||||
GameEvent::RoundWin(round_win_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::RoundOvertime => GameEvent::RoundOverTime,
|
||||
_ => {
|
||||
todo!("{:?} not parsed yet", raw.ty);
|
||||
}
|
||||
|
|
@ -161,6 +184,7 @@ fn param_parse_with<'a, T, P: Fn(&'a str) -> IResult<&'a str, T>>(
|
|||
parser: P,
|
||||
) -> impl Fn(&'a str) -> IResult<&'a str, T> {
|
||||
move |input: &str| {
|
||||
let (input, _) = opt(tag(" "))(input)?;
|
||||
let (input, open_tag) = opt(tag("("))(input)?;
|
||||
|
||||
let (input, _) = tag(key)(input)?;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::common::Class;
|
||||
use crate::event::{param_parse, param_parse_with, position, u_int, ParamIter};
|
||||
use crate::raw_event::{subject_parser, RawSubject};
|
||||
use nom::combinator::opt;
|
||||
|
|
@ -60,7 +61,7 @@ pub struct KillEvent<'a> {
|
|||
}
|
||||
|
||||
pub fn kill_event_parser(input: &str) -> IResult<&str, KillEvent> {
|
||||
let (input, target) = param_parse_with("against", subject_parser)(input)?;
|
||||
let (input, target) = subject_parser(input)?;
|
||||
let (input, weapon) = param_parse("with")(input)?;
|
||||
let mut event = KillEvent {
|
||||
target,
|
||||
|
|
@ -101,3 +102,33 @@ pub fn kill_assist_event_parser(input: &str) -> IResult<&str, KillAssistEvent> {
|
|||
}
|
||||
Ok(("", event))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SpawnEvent {
|
||||
pub class: Option<Class>,
|
||||
}
|
||||
|
||||
pub fn spawn_event_parser(input: &str) -> IResult<&str, SpawnEvent> {
|
||||
let (input, class_str) = param_parse("as")(input)?;
|
||||
Ok((
|
||||
input,
|
||||
SpawnEvent {
|
||||
class: class_str.parse().ok(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RoleChangeEvent {
|
||||
pub class: Option<Class>,
|
||||
}
|
||||
|
||||
pub fn role_changed_event_parser(input: &str) -> IResult<&str, RoleChangeEvent> {
|
||||
let (input, class_str) = param_parse("to")(input)?;
|
||||
Ok((
|
||||
input,
|
||||
RoleChangeEvent {
|
||||
class: class_str.parse().ok(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue