mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-04 02:34:10 +02:00
medic stats
This commit is contained in:
parent
b2d169601c
commit
a5040ec355
5 changed files with 147 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::event::{param_parse, param_parse_with, quoted, u_int};
|
||||
use crate::event::{param_parse, param_parse_with, quoted, u_int, ParamIter};
|
||||
use crate::raw_event::{subject_parser, RawSubject};
|
||||
use nom::combinator::opt;
|
||||
use nom::number::complete::float;
|
||||
|
|
@ -41,3 +41,39 @@ pub fn charge_ended_event_parser(input: &str) -> IResult<&str, ChargeEndedEvent>
|
|||
let (input, duration) = opt(param_parse_with("duration", quoted(float)))(input)?;
|
||||
Ok((input, ChargeEndedEvent { duration }))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AdvantageLostEvent {
|
||||
pub time: Option<f32>,
|
||||
}
|
||||
|
||||
pub fn advantage_lost_event_parser(input: &str) -> IResult<&str, AdvantageLostEvent> {
|
||||
let (input, time) = opt(param_parse_with("time", quoted(float)))(input)?;
|
||||
Ok((input, AdvantageLostEvent { time }))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FirstHealEvent {
|
||||
pub time: Option<f32>,
|
||||
}
|
||||
|
||||
pub fn first_heal_event_parser(input: &str) -> IResult<&str, FirstHealEvent> {
|
||||
let (input, time) = opt(param_parse_with("time", quoted(float)))(input)?;
|
||||
Ok((input, FirstHealEvent { time }))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MedicDeathEvent {
|
||||
pub charge: Option<u32>,
|
||||
}
|
||||
|
||||
pub fn medic_death_event_parser(input: &str) -> IResult<&str, MedicDeathEvent> {
|
||||
let mut charge = None;
|
||||
for (key, value) in ParamIter::new(input) {
|
||||
if key == "ubercharge" {
|
||||
charge = Some(quoted(u_int)(value)?.1);
|
||||
}
|
||||
}
|
||||
let (input, time) = opt(param_parse_with("time", quoted(float)))(input)?;
|
||||
Ok((input, MedicDeathEvent { charge }))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ impl<'a, T> GameEventErrTrait<T> for IResult<&str, T> {
|
|||
|
||||
Err::Incomplete(_) => GameEventError::Incomplete(ty),
|
||||
})
|
||||
.map(|(rest, t)| t)
|
||||
.map(|(_rest, t)| t)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +51,12 @@ pub enum GameEvent<'a> {
|
|||
Say(&'a str),
|
||||
SayTeam(&'a str),
|
||||
Healed(HealedEvent<'a>),
|
||||
ChargeDeployed(ChargeDeployedEvent<'a>),
|
||||
ChargeEnded(ChargeEndedEvent),
|
||||
AdvantageLost(AdvantageLostEvent),
|
||||
FirstHeal(FirstHealEvent),
|
||||
ChargeReady,
|
||||
MedicDeath(MedicDeathEvent),
|
||||
}
|
||||
|
||||
impl<'a> GameEvent<'a> {
|
||||
|
|
@ -64,6 +70,22 @@ impl<'a> GameEvent<'a> {
|
|||
RawEventType::Healed => {
|
||||
GameEvent::Healed(healed_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::ChargeDeployed => GameEvent::ChargeDeployed(
|
||||
charge_deployed_event_parser(raw.params).with_type(raw.ty)?,
|
||||
),
|
||||
RawEventType::ChargeEnd => {
|
||||
GameEvent::ChargeEnded(charge_ended_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::UberAdvantageLost => {
|
||||
GameEvent::AdvantageLost(advantage_lost_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::FirstHealAfterSpawn => {
|
||||
GameEvent::FirstHeal(first_heal_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::ChargeReady => GameEvent::ChargeReady,
|
||||
RawEventType::MedicDeath => {
|
||||
GameEvent::MedicDeath(medic_death_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
_ => {
|
||||
todo!("{:?} not parsed yet", raw.ty);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue