Add live match timer countdown

- Add match_time_last_sync timestamp to track server updates
- Update timestamp in parser when TIME events received
- Calculate elapsed time in UI for live countdown
- Timer now ticks in real-time between server events
This commit is contained in:
pfl
2026-01-09 14:00:32 +01:00
parent 16b5209338
commit e6e32033ad
3 changed files with 16 additions and 2 deletions

View File

@ -94,6 +94,7 @@ class EventParser:
# Get Match Time # Get Match Time
if 'TIME' in data: if 'TIME' in data:
self.game_state.server_info.match_time = int(data['TIME']) self.game_state.server_info.match_time = int(data['TIME'])
self.game_state.server_info.match_time_last_sync = time.time()
if 'KILLER' not in data: if 'KILLER' not in data:
return None return None
@ -138,6 +139,7 @@ class EventParser:
# Get Match Time # Get Match Time
if 'TIME' in data: if 'TIME' in data:
self.game_state.server_info.match_time = int(data['TIME']) self.game_state.server_info.match_time = int(data['TIME'])
self.game_state.server_info.match_time_last_sync = time.time()
if 'VICTIM' not in data: if 'VICTIM' not in data:
return None return None
@ -244,6 +246,7 @@ class EventParser:
# Get Match Time # Get Match Time
if 'TIME' in data: if 'TIME' in data:
self.game_state.server_info.match_time = int(data['TIME']) self.game_state.server_info.match_time = int(data['TIME'])
self.game_state.server_info.match_time_last_sync = time.time()
team_won = data.get('TEAM_WON') team_won = data.get('TEAM_WON')
round_num = data.get('ROUND', 0) round_num = data.get('ROUND', 0)
@ -265,6 +268,7 @@ class EventParser:
# Get Match Time # Get Match Time
if 'TIME' in data: if 'TIME' in data:
self.game_state.server_info.match_time = int(data['TIME']) self.game_state.server_info.match_time = int(data['TIME'])
self.game_state.server_info.match_time_last_sync = time.time()
name = data.get('NAME', 'Unknown') name = data.get('NAME', 'Unknown')
medal = data.get('MEDAL', 'UNKNOWN') medal = data.get('MEDAL', 'UNKNOWN')
@ -299,6 +303,7 @@ class EventParser:
# Get Match Time # Get Match Time
if 'TIME' in data: if 'TIME' in data:
self.game_state.server_info.match_time = int(data['TIME']) self.game_state.server_info.match_time = int(data['TIME'])
self.game_state.server_info.match_time_last_sync = time.time()
if self.game_state.server_info.is_team_mode(): if self.game_state.server_info.is_team_mode():
return f"^8^2[GAME ON]^0 ^7Match has started - ^1^8RED ^0^7vs. ^4^8BLUE\n" return f"^8^2[GAME ON]^0 ^7Match has started - ^1^8RED ^0^7vs. ^4^8BLUE\n"
@ -320,6 +325,7 @@ class EventParser:
# Get Match Time # Get Match Time
if 'TIME' in data: if 'TIME' in data:
self.game_state.server_info.match_time = int(data['TIME']) self.game_state.server_info.match_time = int(data['TIME'])
self.game_state.server_info.match_time_last_sync = time.time()
if not self.game_state.server_info.is_team_mode(): if not self.game_state.server_info.is_team_mode():
return None return None

View File

@ -34,6 +34,7 @@ class ServerInfo:
self.dead_players = {} self.dead_players = {}
self.round_end_time = None self.round_end_time = None
self.match_time = 0 self.match_time = 0
self.match_time_last_sync = 0 # Timestamp of last TIME update from server
def is_team_mode(self): def is_team_mode(self):
"""Check if current gametype is a team mode""" """Check if current gametype is a team mode"""

11
ui.py
View File

@ -9,6 +9,7 @@ import curses.textpad
import threading import threading
import queue import queue
import logging import logging
import time
from config import COLOR_PAIRS, INFO_WINDOW_HEIGHT, INFO_WINDOW_Y, OUTPUT_WINDOW_Y, INPUT_WINDOW_HEIGHT, TEAM_MODES, MAX_COMMAND_HISTORY from config import COLOR_PAIRS, INFO_WINDOW_HEIGHT, INFO_WINDOW_Y, OUTPUT_WINDOW_Y, INPUT_WINDOW_HEIGHT, TEAM_MODES, MAX_COMMAND_HISTORY
from cvars import autocomplete, COMMAND_SIGNATURES, get_signature_with_highlight, get_argument_suggestions, COMMAND_ARGUMENTS from cvars import autocomplete, COMMAND_SIGNATURES, get_signature_with_highlight, get_argument_suggestions, COMMAND_ARGUMENTS
@ -535,8 +536,14 @@ class UIManager:
timer_display = "" timer_display = ""
if server_info.match_time > 0 and not server_info.warmup: if server_info.match_time > 0 and not server_info.warmup:
mins = server_info.match_time // 60 # Calculate live time: add elapsed seconds since last server update
secs = server_info.match_time % 60 current_time = server_info.match_time
if server_info.match_time_last_sync > 0:
elapsed = int(time.time() - server_info.match_time_last_sync)
current_time += elapsed
mins = current_time // 60
secs = current_time % 60
timer_display = f"^3^0Time:^8^7 {mins}:{secs:02d}^0" timer_display = f"^3^0Time:^8^7 {mins}:{secs:02d}^0"
else: else:
timer_display = "^3^0Time:^8^7 0:00^0" timer_display = "^3^0Time:^8^7 0:00^0"