diff --git a/formatter.py b/formatter.py index d20d5b7..3a5d865 100644 --- a/formatter.py +++ b/formatter.py @@ -137,19 +137,19 @@ def format_chat_message(message, player_tracker): player_name = strip_color_codes(name_match.group(1).strip()) team_prefix = get_team_prefix(player_name, player_tracker) location_clean = strip_color_codes(location_part) - return f"{team_prefix}^8{player_part}^0 ^3{location_clean}^7:^5{message_part}" + return f"^8^5[TEAMSAY]^7^0 {team_prefix}^8{player_part}^0^3{location_clean}^7:^5{message_part}" # Team chat without location: (PlayerName): message colon_match = re.match(r'^(\([^)]+\)):(\s*.*)', clean_msg) if colon_match: - player_part = colon_match.group(1) + ':' + player_part = colon_match.group(1) message_part = colon_match.group(2) name_match = re.match(r'\(([^)]+)\)', player_part) if name_match: player_name = strip_color_codes(name_match.group(1).strip()) team_prefix = get_team_prefix(player_name, player_tracker) - return f"{team_prefix}^8{player_part}^0^5{message_part}\n" + return f"^8^5[TEAMSAY]^7^0 {team_prefix}^8{player_part}^7^0:^5{message_part}\n" # Regular chat: PlayerName: message parts = clean_msg.split(':', 1) @@ -160,7 +160,7 @@ def format_chat_message(message, player_tracker): # Preserve original color-coded name original_parts = message.replace(chr(25), '').split(':', 1) if len(original_parts) == 2: - return f"{team_prefix}^8{original_parts[0]}^0:^2{original_parts[1]}" + return f"^8^2[SAY]^7^0 {team_prefix}^8{original_parts[0]}^0^7:^2{original_parts[1]}" return message @@ -193,7 +193,7 @@ def format_powerup_message(message, player_tracker): colored_powerup = POWERUP_COLORS.get(powerup_name, f'^6{powerup_name}^7') timestamp = time.strftime('%H:%M:%S') - return f"^3[^7{timestamp}^3]^7 {team_prefix}^8{player_name}^0 ^7got the {colored_powerup}!\n" + return f"^3[^7{timestamp}^3] ^8^5[POWERUP]^7^0 {team_prefix}^8{player_name}^0 ^7got the {colored_powerup}!\n" # Powerup carrier kill: "PlayerName killed the PowerupName carrier!" carrier_match = re.match(r'^(.+?)\s+killed the\s+(.+?)\s+carrier!', message) @@ -206,6 +206,6 @@ def format_powerup_message(message, player_tracker): colored_powerup = POWERUP_COLORS.get(powerup_name, f'^6{powerup_name}^7') timestamp = time.strftime('%H:%M:%S') - return f"^3[^7{timestamp}^3]^7 {team_prefix}^8{player_name}^0 ^7killed the {colored_powerup} ^7carrier!\n" + return f"^3[^7{timestamp}^3] ^8^5[POWERUP]^7^0 {team_prefix}^8{player_name}^0 ^7killed the {colored_powerup} ^7carrier!\n" return None diff --git a/parser.py b/parser.py index 0957f1c..cdc1830 100644 --- a/parser.py +++ b/parser.py @@ -89,6 +89,11 @@ class EventParser: def _handle_switchteam(self, data): """Handle PLAYER_SWITCHTEAM event""" + + # Get Match Time + if 'TIME' in data: + self.game_state.server_info.match_time = int(data['TIME']) + if 'KILLER' not in data: return None @@ -124,10 +129,15 @@ class EventParser: old_team_msg = old_team_messages.get(old_team, f'team {old_team}') team_prefix = get_team_prefix(name, self.game_state.player_tracker) - return f"{team_prefix}^8{name}^0{team_msg} from {old_team_msg}{warmup}\n" + return f"^8^5[SWITCH]^7 {team_prefix}^8{name}^0{team_msg} from {old_team_msg}{warmup}\n" def _handle_death(self, data): """Handle PLAYER_DEATH and PLAYER_KILL events""" + + # Get Match Time + if 'TIME' in data: + self.game_state.server_info.match_time = int(data['TIME']) + if 'VICTIM' not in data: return None @@ -217,6 +227,11 @@ class EventParser: def _handle_round_over(self, data): """Handle ROUND_OVER events for CA""" + + # Get Match Time + if 'TIME' in data: + self.game_state.server_info.match_time = int(data['TIME']) + team_won = data.get('TEAM_WON') round_num = data.get('ROUND', 0) @@ -234,36 +249,47 @@ class EventParser: def _handle_medal(self, data): """Handle PLAYER_MEDAL event""" + + # Get Match Time + if 'TIME' in data: + self.game_state.server_info.match_time = int(data['TIME']) + name = data.get('NAME', 'Unknown') medal = data.get('MEDAL', 'UNKNOWN') warmup = " ^8^3(Warmup)^7^0" if data.get('WARMUP', False) else "" + medal_prefix = "^8^6[MEDAL]^7^0 " team_prefix = get_team_prefix(name, self.game_state.player_tracker) # RED Medals (^1) if medal in ["FIRSTFRAG", "HUMILIATION", "REVENGE"]: - return f"{team_prefix}^8{name}^0 ^7got a medal: ^8^9^1{medal}^0{warmup}\n" + return f"{medal_prefix}{team_prefix}^8{name}^0 ^7got ^8^1{medal}^0{warmup}\n" # GREEN Medals (^2) elif medal in ["MIDAIR", "PERFECT"]: - return f"{team_prefix}^8{name}^0 ^7got a medal: ^8^9^2{medal}^0{warmup}\n" + return f"{medal_prefix}{team_prefix}^8{name}^0 ^7got ^8^2{medal}^0{warmup}\n" # YELLOW Medals (^3) elif medal in ["EXCELLENT", "HEADSHOT", "RAMPAGE"]: - return f"{team_prefix}^8{name}^0 ^7got a medal: ^8^9^3{medal}^0{warmup}\n" + return f"{medal_prefix}{team_prefix}^8{name}^0 ^7got ^8^3{medal}^0{warmup}\n" # BLUE Medals (^4) elif medal in ["ASSIST", "DEFENSE", "QUADGOD"]: - return f"{team_prefix}^8{name}^0 ^7got a medal: ^8^9^4{medal}^0{warmup}\n" + return f"{medal_prefix}{team_prefix}^8{name}^0 ^7got ^8^4{medal}^0{warmup}\n" # CYAN Medals (^5) elif medal in ["CAPTURE", "COMBOKILL", "IMPRESSIVE"]: - return f"{team_prefix}^8{name}^0 ^7got a medal: ^8^9^5{medal}^0{warmup}\n" + return f"{medal_prefix}{team_prefix}^8{name}^0 ^7got ^8^5{medal}^0{warmup}\n" # PINK Medals (^6) elif medal in ["ACCURACY", "PERFORATED"]: - return f"{team_prefix}^8{name}^0 ^7got a medal: ^8^9^6{medal}^0{warmup}\n" + return f"{medal_prefix}{team_prefix}^8{name}^0 ^7got ^8^6{medal}^0{warmup}\n" else: - return f"{team_prefix}^8{name}^0 ^7got a medal: ^8^9^7{medal}^0{warmup}\n" + return f"{medal_prefix}{team_prefix}^8{name}^0 ^7got ^8^7{medal}^0{warmup}\n" def _handle_match_started(self, data): """Handle MATCH_STARTED event""" + + # Get Match Time + if 'TIME' in data: + self.game_state.server_info.match_time = int(data['TIME']) + if self.game_state.server_info.is_team_mode(): - return None + return f"^8^2[GAME ON]^0 ^7Match has started - ^1^8RED ^0^7vs. ^4^8BLUE\n" players = [] for player in data.get('PLAYERS', []): @@ -272,24 +298,30 @@ class EventParser: if players: formatted = "^0 vs. ^8".join(players) - return f"^8^3Match has started - ^8^7{formatted}\n" + return f"^8^2[GAME ON]^0 ^7Match has started - ^8^7{formatted}\n" return None def _handle_match_report(self, data): """Handle MATCH_REPORT event""" + + # Get Match Time + if 'TIME' in data: + self.game_state.server_info.match_time = int(data['TIME']) + if not self.game_state.server_info.is_team_mode(): return None red_score = int(data.get('TSCORE0', '0')) blue_score = int(data.get('TSCORE1', '0')) + report_prefix = "^8^1[GAME OVER]" if red_score > blue_score: - return f"^1RED TEAM ^7WINS by a score of {red_score} to {blue_score}\n" + return f"{report_prefix} ^7The ^1RED TEAM ^7WINS^0 by a score of ^8^1{red_score} ^0^7to ^8^4{blue_score}\n" elif blue_score > red_score: - return f"^4BLUE TEAM ^7WINS by a score of {blue_score} to {red_score}\n" + return f"{report_prefix} ^7The ^4BLUE TEAM ^7WINS^0 by a score of ^8^4{blue_score} ^0^7to ^8^1{red_score}\n" else: - return f"^7The match is a TIE with a score of {red_score} to {blue_score}\n" + return f"{report_prefix} ^7The match is a TIE^0 with a score of ^8^1{red_score} ^0^7to ^8^4{blue_score}\n" def _handle_player_stats(self, data): """Handle PLAYER_STATS event""" diff --git a/state.py b/state.py index 7995f49..037985f 100644 --- a/state.py +++ b/state.py @@ -33,6 +33,7 @@ class ServerInfo: self.warmup = False self.dead_players = {} self.round_end_time = None + self.match_time = 0 def is_team_mode(self): """Check if current gametype is a team mode""" diff --git a/ui.py b/ui.py index ce53f80..47e51bd 100644 --- a/ui.py +++ b/ui.py @@ -309,10 +309,21 @@ class UIManager: max_y, max_x = self.info_window.getmaxyx() server_info = game_state.server_info - # Line 1: Hostname + # Line 1: Hostname with Timer and Warmup Indicator hostname = server_info.hostname - warmup_display = "^3Warmup: ^2YES^0" if server_info.warmup else "^3Warmup: ^1NO^0" - print_colored(self.info_window, f"^3Name:^8 {hostname} {warmup_display}\n", 0) + + timer_display = "" + if not server_info.warmup: + #if server_info.match_time > 0 and not server_info.warmup: + mins = server_info.match_time // 60 + secs = server_info.match_time % 60 + timer_display = f"^3^0Time:^8^7 {mins}:{secs:02d}^0" + else: + timer_display = "^3^0Time:^8^7 0:00^0" + + warmup_display = "^3^0Warmup:^8 ^2YES^0" if server_info.warmup else "^3^0Warmup: ^8^1NO^0" + + print_colored(self.info_window, f"^3Name:^8 {hostname} {warmup_display} {timer_display}\n", 0) # Line 2: Game info gametype = server_info.gametype @@ -337,7 +348,7 @@ class UIManager: limit_display = f"^3^0| Timelimit:^7^8 {timelimit} ^0^3| Fraglimit:^7^8 {fraglimit}" print_colored(self.info_window, - f"^3^0Type:^7^8 {gametype} ^8^3| Map:^7^8 {mapname} ^0^3| Players:^7^8 {curclients}/{maxclients} " + f"^3^0Type:^7^8 {gametype} ^0^3| Map:^7^8 {mapname} ^0^3| Players:^7^8 {curclients}/{maxclients} " f"{limit_display}^0\n", 0) # Blank lines to fill