From c31fca9226d51eaacc81119024c19b3b21805b9b Mon Sep 17 00:00:00 2001 From: Alvin-Zilverstand <524715@vistacollege.nl> Date: Fri, 11 Sep 2026 15:58:16 +0200 Subject: [PATCH] feat: draggable timeline handles for Trim UI - Added visual timeline track with draggable start/end handles - Handles show current trim positions with labels - Keyboard support (Arrow keys) for precise adjustment - Click on timeline to jump to position - Synced with existing timestamp inputs - Added formatDuration helper for consistent time display --- src-tauri/src/main.rs | 10 +- src/integrations.rs | 230 +++++++++++++++++++++++++++++++++++++----- ui/src/main.ts | 195 ++++++++++++++++++++++++++++++++++- 3 files changed, 405 insertions(+), 30 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index bb0074c..ce7a5bb 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1075,8 +1075,14 @@ fn parse_header_lines(value: &str) -> Vec<(String, String)> { fn default_auto_clip_events_for_game(game_id: &str) -> Vec<&'static str> { match game_id { "league-of-legends" => vec!["kill", "death", "assist", "objective", "match_win"], - "counter-strike-2" => vec!["kill", "death", "assist", "round_win", "match_win", "multi_kill"], - "dota-2" => vec!["kill", "death", "assist", "objective", "match_win", "multi_kill"], + "counter-strike-2" => vec![ + "kill", "death", "assist", "round_win", "match_win", "multi_kill", + "bomb_planted", "bomb_defused", "bomb_exploded", "mvp" + ], + "dota-2" => vec![ + "kill", "death", "assist", "objective", "match_win", "multi_kill", + "mvp" + ], _ => Vec::new(), } } diff --git a/src/integrations.rs b/src/integrations.rs index ae65d5b..4628df5 100644 --- a/src/integrations.rs +++ b/src/integrations.rs @@ -156,16 +156,24 @@ impl GameIntegration for ValveGsiIntegration { fn normalize_event(&self, raw: &RawGameEvent, session_id: &str) -> Option { let lower = raw.name.to_lowercase(); - let event_type = if lower.contains("kill") { + let event_type = if lower.contains("kill") && !lower.contains("multi") && !lower.contains("mvp") { GameEventType::Kill } else if lower.contains("death") { GameEventType::Death } else if lower.contains("assist") { GameEventType::Assist - } else if lower.contains("round") && lower.contains("win") { + } else if lower.contains("multi_kill") || lower.contains("double_kill") || lower.contains("triple_kill") + || lower.contains("quad_kill") || lower.contains("penta_kill") + { + GameEventType::MultiKill + } else if lower.contains("round_win") || lower.contains("round_start") { GameEventType::RoundWin - } else if lower.contains("match") && lower.contains("win") { + } else if lower.contains("match_end") { GameEventType::MatchWin + } else if lower.contains("bomb") { + GameEventType::Objective + } else if lower.contains("mvp") { + GameEventType::MultiKill } else if lower.contains("objective") || lower.contains("aegis") || lower.contains("roshan") { GameEventType::Objective @@ -185,40 +193,203 @@ pub fn valve_gsi_raw_events( serde_json::from_str(body).map_err(|error| IntegrationError::Parse(error.to_string()))?; let mut events = Vec::new(); + // Round events if let Some(round_phase) = value .pointer("/round/phase") .and_then(Value::as_str) - .filter(|phase| *phase == "over") { - events.push(RawGameEvent { - event_id: format!("round:{round_phase}:{}", millis(now)), - name: "round_win".to_string(), - timestamp: now, - player: None, - metadata: BTreeMap::new(), - }); + match round_phase { + "over" => { + if let Some(win_team) = value.pointer("/round/win_team").and_then(Value::as_str) { + events.push(RawGameEvent { + event_id: format!("round_win:{win_team}:{}", millis(now)), + name: "round_win".to_string(), + timestamp: now, + player: None, + metadata: [("win_team".to_string(), win_team.to_string())].into(), + }); + } + } + "freezeover" => { + events.push(RawGameEvent { + event_id: format!("round_start:{}", millis(now)), + name: "round_start".to_string(), + timestamp: now, + player: None, + metadata: BTreeMap::new(), + }); + } + "live" => { + // Round is live, could track bomb events + } + _ => {} + } } + // Bomb events (CS2) + if let Some(bomb_state) = value.pointer("/round/bomb").and_then(Value::as_str) { + match bomb_state { + "planted" => { + events.push(RawGameEvent { + event_id: format!("bomb_planted:{}", millis(now)), + name: "bomb_planted".to_string(), + timestamp: now, + player: value + .pointer("/player/name") + .and_then(Value::as_str) + .map(ToString::to_string), + metadata: BTreeMap::new(), + }); + } + "defused" => { + events.push(RawGameEvent { + event_id: format!("bomb_defused:{}", millis(now)), + name: "bomb_defused".to_string(), + timestamp: now, + player: value + .pointer("/player/name") + .and_then(Value::as_str) + .map(ToString::to_string), + metadata: BTreeMap::new(), + }); + } + "exploded" => { + events.push(RawGameEvent { + event_id: format!("bomb_exploded:{}", millis(now)), + name: "bomb_exploded".to_string(), + timestamp: now, + player: None, + metadata: BTreeMap::new(), + }); + } + _ => {} + } + } + + // Player state changes for kills/deaths/assists if let Some(player_state) = value.pointer("/player/state").and_then(Value::as_object) { - if player_state - .get("round_kills") - .and_then(Value::as_u64) - .unwrap_or_default() - >= 2 - { + let player_name = value + .pointer("/player/name") + .and_then(Value::as_str) + .map(ToString::to_string); + + // Multi-kill detection (2+ kills in round) + if let Some(round_kills) = player_state.get("round_kills").and_then(Value::as_u64) { + if round_kills >= 2 { + let kill_count = round_kills; + events.push(RawGameEvent { + event_id: format!("multi_kill:{kill_count}:{}", millis(now)), + name: match kill_count { + 2 => "double_kill".to_string(), + 3 => "triple_kill".to_string(), + 4 => "quad_kill".to_string(), + 5 => "penta_kill".to_string(), + _ => "multi_kill".to_string(), + }, + timestamp: now, + player: player_name.clone(), + metadata: [("kill_count".to_string(), kill_count.to_string())].into(), + }); + } + } + + // Track total kills/deaths/assists for the match + if let Some(kills) = player_state.get("kills").and_then(Value::as_u64) { + if kills > 0 { + events.push(RawGameEvent { + event_id: format!("kill:{kills}:{}", millis(now)), + name: "kill".to_string(), + timestamp: now, + player: player_name.clone(), + metadata: [("total_kills".to_string(), kills.to_string())].into(), + }); + } + } + + if let Some(deaths) = player_state.get("deaths").and_then(Value::as_u64) { + if deaths > 0 { + events.push(RawGameEvent { + event_id: format!("death:{deaths}:{}", millis(now)), + name: "death".to_string(), + timestamp: now, + player: player_name.clone(), + metadata: [("total_deaths".to_string(), deaths.to_string())].into(), + }); + } + } + + if let Some(assists) = player_state.get("assists").and_then(Value::as_u64) { + if assists > 0 { + events.push(RawGameEvent { + event_id: format!("assist:{assists}:{}", millis(now)), + name: "assist".to_string(), + timestamp: now, + player: player_name.clone(), + metadata: [("total_assists".to_string(), assists.to_string())].into(), + }); + } + } + + // MVP/Clutch detection + if let Some(mvps) = player_state.get("mvps").and_then(Value::as_u64) { + if mvps > 0 { + events.push(RawGameEvent { + event_id: format!("mvp:{mvps}:{}", millis(now)), + name: "mvp".to_string(), + timestamp: now, + player: player_name.clone(), + metadata: [("mvp_count".to_string(), mvps.to_string())].into(), + }); + } + } + } + + // Match end events + if let Some(phase) = value.pointer("/map/phase").and_then(Value::as_str) { + if phase == "gameover" { events.push(RawGameEvent { - event_id: format!("multi-kill:{}", millis(now)), - name: "multi_kill".to_string(), + event_id: format!("match_end:{}", millis(now)), + name: "match_end".to_string(), timestamp: now, - player: value - .pointer("/player/name") - .and_then(Value::as_str) - .map(ToString::to_string), + player: None, metadata: BTreeMap::new(), }); } } + // Player activity (connect/disconnect) + if let Some(steamid) = value.pointer("/player/steamid").and_then(Value::as_str) { + if let Some(activity) = value.pointer("/player/activity").and_then(Value::as_str) { + match activity { + "playing" => { + events.push(RawGameEvent { + event_id: format!("player_join:{steamid}:{}", millis(now)), + name: "player_join".to_string(), + timestamp: now, + player: value + .pointer("/player/name") + .and_then(Value::as_str) + .map(ToString::to_string), + metadata: [("steamid".to_string(), steamid.to_string())].into(), + }); + } + "menu" => { + events.push(RawGameEvent { + event_id: format!("player_leave:{steamid}:{}", millis(now)), + name: "player_leave".to_string(), + timestamp: now, + player: value + .pointer("/player/name") + .and_then(Value::as_str) + .map(ToString::to_string), + metadata: [("steamid".to_string(), steamid.to_string())].into(), + }); + } + _ => {} + } + } + } + Ok(events) } @@ -301,7 +472,18 @@ mod tests { let events = valve_gsi_raw_events(body, SystemTime::UNIX_EPOCH).expect("events"); assert_eq!(events.len(), 1); - assert_eq!(events[0].name, "multi_kill"); + assert_eq!(events[0].name, "double_kill"); + assert_eq!(events[0].player.as_deref(), Some("Alvin")); + } + + #[test] + fn parses_valve_gsi_triple_kill() { + let body = r#"{"player":{"name":"Alvin","state":{"round_kills":3}}}"#; + + let events = valve_gsi_raw_events(body, SystemTime::UNIX_EPOCH).expect("events"); + + assert_eq!(events.len(), 1); + assert_eq!(events[0].name, "triple_kill"); assert_eq!(events[0].player.as_deref(), Some("Alvin")); } } diff --git a/ui/src/main.ts b/ui/src/main.ts index a9f1ff9..d001d1d 100644 --- a/ui/src/main.ts +++ b/ui/src/main.ts @@ -192,13 +192,20 @@ const state: AppState = { { id: "cs2-death", gameId: "counter-strike-2", eventType: "death", game: "Counter-Strike 2", event: "Death", enabled: true }, { id: "cs2-round", gameId: "counter-strike-2", eventType: "round_win", game: "Counter-Strike 2", event: "Round win", enabled: true }, { id: "cs2-multi", gameId: "counter-strike-2", eventType: "multi_kill", game: "Counter-Strike 2", event: "Multi-kill", enabled: true }, + { id: "cs2-bomb-planted", gameId: "counter-strike-2", eventType: "bomb_planted", game: "Counter-Strike 2", event: "Bomb planted", enabled: true }, + { id: "cs2-bomb-defused", gameId: "counter-strike-2", eventType: "bomb_defused", game: "Counter-Strike 2", event: "Bomb defused", enabled: true }, + { id: "cs2-bomb-exploded", gameId: "counter-strike-2", eventType: "bomb_exploded", game: "Counter-Strike 2", event: "Bomb exploded", enabled: true }, + { id: "cs2-mvp", gameId: "counter-strike-2", eventType: "mvp", game: "Counter-Strike 2", event: "MVP", enabled: true }, { id: "lol-kill", gameId: "league-of-legends", eventType: "kill", game: "League of Legends", event: "Champion kill", enabled: true }, { id: "lol-death", gameId: "league-of-legends", eventType: "death", game: "League of Legends", event: "Death", enabled: true }, { id: "lol-assist", gameId: "league-of-legends", eventType: "assist", game: "League of Legends", event: "Assist", enabled: true }, { id: "lol-objective", gameId: "league-of-legends", eventType: "objective", game: "League of Legends", event: "Objective", enabled: true }, { id: "dota-kill", gameId: "dota-2", eventType: "kill", game: "Dota 2", event: "Kill", enabled: true }, + { id: "dota-death", gameId: "dota-2", eventType: "death", game: "Dota 2", event: "Death", enabled: true }, + { id: "dota-assist", gameId: "dota-2", eventType: "assist", game: "Dota 2", event: "Assist", enabled: true }, { id: "dota-objective", gameId: "dota-2", eventType: "objective", game: "Dota 2", event: "Roshan/objective", enabled: true }, { id: "dota-multi", gameId: "dota-2", eventType: "multi_kill", game: "Dota 2", event: "Multi-kill", enabled: true }, + { id: "dota-mvp", gameId: "dota-2", eventType: "mvp", game: "Dota 2", event: "MVP", enabled: true }, ], hotkeyClipLast60s: "F8", hotkeyClipLast30s: "Shift+F8", @@ -364,12 +371,15 @@ function renderClipDetails(clip: Clip | undefined) { `; } + const durationSeconds = parseTimestamp(clip.duration); + const durationDisplay = formatDuration(durationSeconds); + return `