Skip to content

Commit

Permalink
Merge pull request #46 from cohstats/master
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
JohannesMerkt committed Mar 24, 2023
2 parents 3bb54b6 + c3f2df2 commit 5a532bc
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 55 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "coh3-stats-desktop-app",
"private": true,
"version": "1.2.0",
"version": "1.2.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -24,13 +24,14 @@
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.5",
"tauri-plugin-fs-watch-api": "https://github.com/tauri-apps/tauri-plugin-fs-watch",
"tauri-plugin-log-api": "https://github.com/tauri-apps/tauri-plugin-log",
"tauri-plugin-store-api": "https://github.com/tauri-apps/tauri-plugin-store"
},
"devDependencies": {
"@tauri-apps/cli": "^1.2.2",
"@types/mixpanel-browser": "^2.38.1",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9",
"@types/mixpanel-browser": "^2.38.1",
"@vitejs/plugin-react": "^3.0.0",
"prettier": "^2.8.1",
"typescript": "^4.9.3",
Expand Down
72 changes: 68 additions & 4 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "coh3-stats-desktop-app"
version = "1.2.0"
version = "1.2.1"
description = "A Tauri App"
authors = ["you"]
license = ""
Expand All @@ -25,6 +25,8 @@ tauri-plugin-window-state = "0.1"
tauri-plugin-fs-watch = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
log = "^0.4"
tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
machine-uid = "0.2.0"

[features]
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tauri_plugin_fs_watch;
use std::path::Path;
use tauri::Manager;
use window_shadows::set_shadow;
use tauri_plugin_log::{LogTarget};
mod parse_log_file;

#[derive(Clone, serde::Serialize)]
Expand All @@ -29,6 +30,10 @@ fn main() {

app.emit_all("single-instance", Payload { args: argv, cwd }).unwrap();
}))
.plugin(tauri_plugin_log::Builder::default().targets([
LogTarget::LogDir,
LogTarget::Stdout,
]).build())
.plugin(tauri_plugin_fs_watch::init())
.plugin(tauri_plugin_window_state::Builder::default().build())
.plugin(tauri_plugin_store::Builder::default().build())
Expand Down
91 changes: 45 additions & 46 deletions src-tauri/src/parse_log_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use rev_lines::RevLines;
use nom;
use std::io::BufReader;
use std::fs::File;
use log::{info};

#[derive(Serialize, Deserialize, Clone)]
pub enum GameState {
Expand Down Expand Up @@ -78,63 +79,29 @@ pub fn parse_log_file_reverse(path: String) -> LogFileData {
let mut language_code = "".to_string();
// Read log file in reverse order line by line
for line in rev_lines {
// Is the line when the game is being closed correctly
if nom::bytes::complete::tag::<&str, &str, ()>("Application closed")(line.as_str()).is_ok() {
//println!("Found application closed");
game_running = false;
continue;
}

if let Ok((tail, parsed_timestamp)) = get_timestamped_line(line.as_str()) {

// Is the line where a game starts
if is_game_start_line(tail) {
timestamp = parsed_timestamp.to_string();
//println!("Timestamp {}", timestamp);

continue;
}

// Is the line that logs the player steam id
if let Ok((steam_id, _)) = get_game_player_steam_id(tail) {
player_steam_id = steam_id.to_string();
//println!("Game steam {}", steam_id);
continue;
}
// these logs have been removed by relic
/*if let Ok((tail, _)) = get_match_started_line(tail) {
//println!("Match started {}", tail);
if let Ok((tail, relic_id)) = nom::bytes::complete::take_until1::<&str, &str, ()>(" /steam/")(tail) {
if let Ok((tail, _)) = nom::bytes::complete::tag::<&str, &str, ()>(" /steam/")(tail) {
//println!("Match started relic {}", relic_id);
if let Ok((tail, steam_id)) = nom::bytes::complete::take_until1::<&str, &str, ()>("], ")(tail) {
if let Ok((tail, _)) = nom::bytes::complete::tag::<&str, &str, ()>("], slot = ")(tail) {
//println!("Match started steam {}", steam_id);
if let Ok((tail, _position_str)) = nom::bytes::complete::take_until1::<&str, &str, ()>(", ranking = ")(tail) {
if let Ok((rank_str, _)) = nom::bytes::complete::tag::<&str, &str, ()>(", ranking = ")(tail) {
if let Ok(rank) = rank_str.parse::<i64>() {
//println!("Match started slot {}", position);
//println!("Match started rank {}", rank);
if let Some(index) = left.iter().position(|p| *p.relic_id == relic_id.to_string()) {
left[index].steam_id = steam_id.to_string();
left[index].rank = rank;
}
if let Some(index) = right.iter().position(|p| *p.relic_id == relic_id.to_string()) {
right[index].steam_id = steam_id.to_string();
right[index].rank = rank;
}
}
}
}
}
}
}
}
}*/

if let Ok((tail, param)) = get_param_line(tail) {
if param == "GAME" {
if let Ok((steam_name, _)) = get_game_player_name(tail) {
player_name = steam_name.to_string();
//println!("Steam name {}", steam_name);
break;
}
if let Ok((game_language, _)) = get_game_language(tail) {
language_code = game_language.to_string();
//println!("Game language {}", game_language);
}

if let Ok((tail, sub_param)) = get_game_sub_param(tail) {
if sub_param == "Scenario" {
if let Ok((parsed_map, _)) = get_map_name(tail) {
Expand Down Expand Up @@ -222,6 +189,15 @@ pub fn parse_log_file_reverse(path: String) -> LogFileData {
}
}
}

// Is the line that logs the playing players name
} else if let Ok((steam_name, _)) = get_game_player_name(tail) {
player_name = steam_name.to_string();
break;

// Is the line that logs the games language
} else if let Ok((game_language, _)) = get_game_language(tail) {
language_code = game_language.to_string();
}
} else if param == "MOD" {
if let Ok((duration_str, _)) = get_game_over(tail) {
Expand All @@ -240,6 +216,7 @@ pub fn parse_log_file_reverse(path: String) -> LogFileData {
let game_state = determine_game_state(game_running, game_ended, game_loading, game_started);
let left_team = get_team_data(left);
let right_team = get_team_data(right);
info!("Log file parsed: Found {} players", left_team.players.len() + right_team.players.len());
LogFileData {
game_state,
game_type: determine_game_type(&left_team, &right_team),
Expand Down Expand Up @@ -355,7 +332,8 @@ fn get_game_sub_param(game_param_tail: &str) -> nom::IResult<&str, &str> {

fn get_game_player_name(game_param_tail: &str) -> nom::IResult<&str, ()> {
let (name_tail, _) = nom::bytes::complete::tag("Current Steam name is [")(game_param_tail)?;
let (_, name) = nom::bytes::complete::take_until1("]")(name_tail)?;
let (name, _) = get_till_last_tag(name_tail, "]")?;
//let (_, name) = nom::bytes::complete::take_until1("]")(name_tail)?;
Ok((name,()))
}

Expand Down Expand Up @@ -385,15 +363,36 @@ fn get_game_over(mod_param_tail: &str) -> nom::IResult<&str, &str> {
}

fn get_last_separated_by_space(line: &str) -> nom::IResult<&str, &str> {
let (tail, front) = nom::bytes::complete::take_until1(" ")(line)?;
let (tail, front) = nom::bytes::complete::take_until(" ")(line)?;
let (tail, _) = nom::bytes::complete::tag(" ")(tail)?;
if let Ok((tail, _)) = get_last_separated_by_space(tail) {
return Ok((tail, &line[0..(line.len() - tail.len() - 1)]))
}
Ok((tail, front))
}

fn get_till_last_tag<'a>(line: &'a str, tag: &'a str) -> nom::IResult<&'a str, &'a str> {
let (tail, front) = nom::bytes::complete::take_until(tag)(line)?;
let (tail, _) = nom::bytes::complete::tag(tag)(tail)?;
if let Ok((front, tail)) = get_till_last_tag(tail, tag) {
return Ok((front, tail))
}
Ok((front, tail))
}

fn get_without_leading_space(line: &str) -> nom::IResult<&str, ()> {
let (without_space, _) = nom::bytes::complete::tag(" ")(line)?;
Ok((without_space, ()))
}
}

/*fn test_logging_solution(line: &str) -> nom::IResult<&str, ()> {
let test = nom::bytes::complete::tag("Applsdasdasded")(line);
let result = match test {
Ok((tail, _)) => tail,
Err(e) => {
info!("Failed!");
return Err(e)
}
};
Ok(("without_space", ()))
}*/
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "Coh3 Stats Desktop App",
"version": "1.2.0"
"version": "1.2.1"
},
"tauri": {
"allowlist": {
Expand Down
6 changes: 5 additions & 1 deletion src/components/PlayerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export const PlayerCard: React.FC<PlayerCardProps> = ({

<Group position="apart" grow>
<PlayerRank rank={rank} />
<PlayerELO rating={rank ? rating : undefined} />
<PlayerELO
rating={
!rank || rank < 1 ? undefined : rating
}
/>
<PlayerStreak streak={streak} />
<PlayerWinRatio wins={wins} losses={losses} />
<PlayerWins wins={wins} />
Expand Down
Loading

0 comments on commit 5a532bc

Please sign in to comment.