mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-11-30 04:40:47 +01:00
some event parsing
This commit is contained in:
parent
d1b3525b2a
commit
e83f7928aa
7 changed files with 282 additions and 61 deletions
52
src/main.rs
52
src/main.rs
|
|
@ -7,59 +7,15 @@ use std::io::stdout;
|
|||
use tf_log_parser::module::{
|
||||
ChatHandler, ChatMessage, EventHandler, HealSpreadHandler, InvalidHealEvent,
|
||||
};
|
||||
use tf_log_parser::{parse_with_handler, RawEvent, RawEventType, SteamId3, SubjectId, SubjectMap};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Default)]
|
||||
struct LogHandler {
|
||||
chat: ChatHandler,
|
||||
heal_spread: HealSpreadHandler,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize)]
|
||||
struct LogOutput {
|
||||
chat: Vec<ChatMessage>,
|
||||
heal_spread: HashMap<SteamId3, HashMap<SteamId3, u32>>,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
enum LogError {
|
||||
#[error("{0}")]
|
||||
HealSpread(#[from] InvalidHealEvent),
|
||||
}
|
||||
|
||||
impl EventHandler for LogHandler {
|
||||
type Output = LogOutput;
|
||||
type Error = LogError;
|
||||
|
||||
fn does_handle(&self, ty: RawEventType) -> bool {
|
||||
self.chat.does_handle(ty) || self.heal_spread.does_handle(ty)
|
||||
}
|
||||
|
||||
fn handle(
|
||||
&mut self,
|
||||
time: u32,
|
||||
subject: SubjectId,
|
||||
event: &RawEvent,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.chat.handle(time, subject, event).unwrap();
|
||||
self.heal_spread.handle(time, subject, event)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn finish(self, subjects: &SubjectMap) -> Self::Output {
|
||||
LogOutput {
|
||||
chat: self.chat.finish(subjects),
|
||||
heal_spread: self.heal_spread.finish(subjects),
|
||||
}
|
||||
}
|
||||
}
|
||||
use tf_log_parser::{
|
||||
parse, parse_with_handler, LogHandler, RawEvent, RawEventType, SteamId3, SubjectId, SubjectMap,
|
||||
};
|
||||
|
||||
fn main() -> Result<(), MainError> {
|
||||
let path = args().skip(1).next().expect("No path provided");
|
||||
let content = fs::read_to_string(path)?;
|
||||
|
||||
let log = parse_with_handler::<LogHandler>(&content)?;
|
||||
let log = parse(&content)?;
|
||||
|
||||
serde_json::to_writer_pretty(stdout().lock(), &log).unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue