mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 10:14:10 +02:00
wip
This commit is contained in:
parent
9da2d2230a
commit
8a88e452ea
13 changed files with 291 additions and 284 deletions
|
|
@ -3,11 +3,11 @@
|
|||
use main_error::MainError;
|
||||
use std::env::args;
|
||||
use std::fs;
|
||||
use tf_log_parser::module::{ChatHandler, LobbySettingsHandler};
|
||||
use tf_log_parser::module::{ChatMessages, LobbySettingsHandler};
|
||||
use tf_log_parser::{handler, parse_with_handler};
|
||||
|
||||
handler!(Handler {
|
||||
chat: ChatHandler,
|
||||
chat: ChatMessages,
|
||||
lobby_settings: LobbySettingsHandler
|
||||
});
|
||||
|
||||
|
|
@ -15,12 +15,15 @@ fn main() -> Result<(), MainError> {
|
|||
let path = args().skip(1).next().expect("No path provided");
|
||||
let content = fs::read_to_string(path)?;
|
||||
|
||||
let HandlerOutput {
|
||||
chat,
|
||||
lobby_settings,
|
||||
} = parse_with_handler::<Handler>(&content)?;
|
||||
let (
|
||||
HandlerGlobalOutput {
|
||||
chat,
|
||||
lobby_settings,
|
||||
},
|
||||
_,
|
||||
) = parse_with_handler::<Handler>(&content)?;
|
||||
|
||||
if let Ok(Some(settings)) = lobby_settings {
|
||||
if let Some(Ok(settings)) = lobby_settings {
|
||||
println!("Lobby settings: {:#?}", settings);
|
||||
println!();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ use main_error::MainError;
|
|||
use std::env::args;
|
||||
use std::fs;
|
||||
use tf_log_parser::event::DamageEvent;
|
||||
use tf_log_parser::module::GlobalData;
|
||||
use tf_log_parser::{
|
||||
parse_with_handler, EventHandler, GameEvent, RawEventType, SubjectData, SubjectId, SubjectMap,
|
||||
parse_with_handler, EventMeta, GameEvent, RawEventType, SubjectData, SubjectId, SubjectMap,
|
||||
};
|
||||
|
||||
struct HighestDamage {
|
||||
|
|
@ -18,14 +19,14 @@ struct HighestDamageHandler {
|
|||
current: Option<(SubjectId, u32)>,
|
||||
}
|
||||
|
||||
impl EventHandler for HighestDamageHandler {
|
||||
type GlobalOutput = Option<HighestDamage>;
|
||||
impl GlobalData for HighestDamageHandler {
|
||||
type Output = Option<HighestDamage>;
|
||||
|
||||
fn does_handle(&self, ty: RawEventType) -> bool {
|
||||
fn does_handle(ty: RawEventType) -> bool {
|
||||
matches!(ty, RawEventType::Damage)
|
||||
}
|
||||
|
||||
fn handle(&mut self, _time: u32, subject: SubjectId, event: &GameEvent) {
|
||||
fn handle_event(&mut self, _meta: &EventMeta, subject: SubjectId, event: &GameEvent) {
|
||||
if let GameEvent::Damage(DamageEvent {
|
||||
damage: Some(damage),
|
||||
..
|
||||
|
|
@ -42,9 +43,9 @@ impl EventHandler for HighestDamageHandler {
|
|||
}
|
||||
}
|
||||
|
||||
fn finish_global(self, subjects: &SubjectMap) -> Self::GlobalOutput {
|
||||
fn finish(self, subjects: &SubjectMap) -> Self::Output {
|
||||
self.current.map(|(subject, damage)| {
|
||||
let user = match &subjects[subject] {
|
||||
let user = match subjects.subject(subject) {
|
||||
SubjectData::Player { name, .. } => name.clone(),
|
||||
_ => {
|
||||
panic!("A non player did the most damage?")
|
||||
|
|
@ -59,8 +60,9 @@ fn main() -> Result<(), MainError> {
|
|||
let path = args().skip(1).next().expect("No path provided");
|
||||
let content = fs::read_to_string(path)?;
|
||||
|
||||
let HighestDamage { user, damage } =
|
||||
parse_with_handler::<HighestDamageHandler>(&content)?.expect("nobody did any damage?");
|
||||
let HighestDamage { user, damage } = parse_with_handler::<HighestDamageHandler>(&content)?
|
||||
.0
|
||||
.expect("nobody did any damage?");
|
||||
|
||||
println!("highest damage was {} done by {}", user, damage);
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue