mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 18:24:09 +02:00
fix damage
This commit is contained in:
parent
ef38aadb68
commit
cdaa164575
6 changed files with 97 additions and 7 deletions
|
|
@ -136,6 +136,12 @@ impl TryFrom<&RawSubject<'_>> for SubjectData {
|
|||
#[derive(Debug, Hash, Eq, PartialEq)]
|
||||
pub struct SteamId3(pub SteamID);
|
||||
|
||||
impl From<SteamID> for SteamId3 {
|
||||
fn from(id: SteamID) -> Self {
|
||||
SteamId3(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for SteamId3 {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
|
|
|||
|
|
@ -43,11 +43,13 @@ impl<'a, T> GameEventErrTrait<T> for IResult<&str, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum GameEvent<'a> {
|
||||
ShotFired(ShotFiredEvent<'a>),
|
||||
ShotHit(ShotHitEvent<'a>),
|
||||
Damage(DamageEvent<'a>),
|
||||
Kill(KillEvent<'a>),
|
||||
KillAssist(KillAssistEvent<'a>),
|
||||
Say(&'a str),
|
||||
SayTeam(&'a str),
|
||||
Healed(HealedEvent<'a>),
|
||||
|
|
@ -65,6 +67,18 @@ impl<'a> GameEvent<'a> {
|
|||
RawEventType::ShotFired => {
|
||||
GameEvent::ShotFired(shot_fired_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::ShotHit => {
|
||||
GameEvent::ShotHit(shot_hit_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::Damage => {
|
||||
GameEvent::Damage(damage_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::Killed => {
|
||||
GameEvent::Kill(kill_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::KillAssist => {
|
||||
GameEvent::KillAssist(kill_assist_event_parser(raw.params).with_type(raw.ty)?)
|
||||
}
|
||||
RawEventType::SayTeam => GameEvent::SayTeam(raw.params.trim_matches('"')),
|
||||
RawEventType::Say => GameEvent::Say(raw.params.trim_matches('"')),
|
||||
RawEventType::Healed => {
|
||||
|
|
@ -122,7 +136,7 @@ fn param_pair_parse(input: &str) -> IResult<&str, (&str, &str)> {
|
|||
let (input, _) = tag(r#"""#)(input)?;
|
||||
|
||||
if open_tag.is_some() {
|
||||
let (_input, _) = tag("(")(input)?;
|
||||
let (_input, _) = tag(")")(input)?;
|
||||
}
|
||||
Ok((input, (key, value)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::event::{param_parse, param_parse_with, position, quoted, u_int, ParamIter};
|
||||
use crate::event::{param_parse, param_parse_with, position, u_int, ParamIter};
|
||||
use crate::raw_event::{subject_parser, RawSubject};
|
||||
use nom::combinator::opt;
|
||||
use nom::IResult;
|
||||
|
|
@ -19,9 +19,9 @@ pub struct ShotHitEvent<'a> {
|
|||
pub weapon: Option<&'a str>,
|
||||
}
|
||||
|
||||
pub fn shot_hit_event_parser(input: &str) -> IResult<&str, ShotFiredEvent> {
|
||||
pub fn shot_hit_event_parser(input: &str) -> IResult<&str, ShotHitEvent> {
|
||||
let (input, weapon) = opt(param_parse("weapon"))(input)?;
|
||||
Ok((input, ShotFiredEvent { weapon }))
|
||||
Ok((input, ShotHitEvent { weapon }))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -42,8 +42,8 @@ pub fn damage_event_parser(input: &str) -> IResult<&str, DamageEvent> {
|
|||
};
|
||||
for (key, value) in ParamIter::new(input) {
|
||||
match key {
|
||||
"damage" => event.damage = NonZeroU32::new(quoted(u_int)(value)?.1),
|
||||
"realdamage" => event.real_damage = NonZeroU32::new(quoted(u_int)(value)?.1),
|
||||
"damage" => event.damage = NonZeroU32::new(u_int(value)?.1),
|
||||
"realdamage" => event.real_damage = NonZeroU32::new(u_int(value)?.1),
|
||||
"weapon" => event.weapon = Some(value.trim_matches('"')),
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use std::ops::Index;
|
|||
use thiserror::Error;
|
||||
|
||||
mod common;
|
||||
mod event;
|
||||
pub mod event;
|
||||
#[macro_use]
|
||||
pub mod module;
|
||||
mod raw_event;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue