-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathgame_mode_detector.py
More file actions
113 lines (91 loc) · 4.43 KB
/
Copy pathgame_mode_detector.py
File metadata and controls
113 lines (91 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Game Mode Detector
Detects game mode and map information from LCU
"""
import logging
import traceback
from lcu import LCU
from lcu.core.lockfile import SWIFTPLAY_MODES, SWIFTPLAY_QUEUE_ID, SWIFTPLAY_QUEUE_IDS
from state import SharedState
from utils.core.logging import get_logger
log = get_logger()
class GameModeDetector:
"""Detects game mode and map information"""
def __init__(self, lcu: LCU, state: SharedState):
"""Initialize game mode detector
Args:
lcu: LCU client instance
state: Shared application state
"""
self.lcu = lcu
self.state = state
def detect_game_mode(self):
"""Detect game mode once when entering champion select"""
old_swiftplay_mode = self.state.is_swiftplay_mode
new_swiftplay_mode = False # Compute locally first, assign once at the end
try:
if not self.lcu.ok:
log.info("[WS] LCU not connected - cannot detect game mode, defaulting to non-swiftplay")
if old_swiftplay_mode:
log.info(f"[WS] Swiftplay mode flag reset: {old_swiftplay_mode} → False")
self.state.is_swiftplay_mode = False
return
# Get game session data
session = self.lcu.get("/lol-gameflow/v1/session")
if not session:
log.info("[WS] No game session data available, defaulting to non-swiftplay")
if old_swiftplay_mode:
log.info(f"[WS] Swiftplay mode flag reset: {old_swiftplay_mode} → False")
self.state.is_swiftplay_mode = False
return
# Extract game mode and map ID
game_mode = None
map_id = None
queue_id = None
# Try multiple locations for queue ID
if "gameData" in session:
game_data = session.get("gameData", {})
if "queue" in game_data:
queue = game_data.get("queue", {})
game_mode = queue.get("gameMode")
map_id = queue.get("mapId")
queue_id = queue.get("queueId")
# Second try: session.queueId
if queue_id is None:
queue_id = session.get("queueId")
# Third try: Check champ select session
if queue_id is None:
champ_session = self.lcu.get("/lol-champ-select/v1/session")
if champ_session and isinstance(champ_session, dict):
queue_id = champ_session.get("queueId")
# Store in shared state
self.state.current_game_mode = game_mode
self.state.current_map_id = map_id
self.state.current_queue_id = queue_id
# Compute is_swiftplay_mode without intermediate False visible to other threads
# Explicit queue ID check for Swiftplay / Quickplay (480 / 490)
if queue_id in SWIFTPLAY_QUEUE_IDS or queue_id == SWIFTPLAY_QUEUE_ID:
new_swiftplay_mode = True
if isinstance(game_mode, str) and game_mode.upper() in SWIFTPLAY_MODES:
new_swiftplay_mode = True
# Single atomic-style assignment
self.state.is_swiftplay_mode = new_swiftplay_mode
if old_swiftplay_mode != new_swiftplay_mode:
log.info(f"[WS] Swiftplay mode flag updated: {old_swiftplay_mode} → {new_swiftplay_mode}")
# Log queue ID
log.info(f"[WS] Queue ID: {queue_id}")
# Log detection result
if map_id == 12 or game_mode == "ARAM":
log.info("[WS] ARAM mode detected - chroma panel will use ARAM background")
elif map_id == 11 or game_mode == "CLASSIC":
log.info("[WS] Summoner's Rift mode detected - chroma panel will use SR background")
elif new_swiftplay_mode:
log.info(f"[WS] {game_mode} mode detected - will trigger early skin detection in lobby")
log.info("[WS] Swiftplay-like mode: Champion selection and skin detection will happen in lobby phase")
else:
log.info(f"[WS] Unknown game mode ({game_mode}, Map ID: {map_id}) - defaulting to SR background")
except Exception as e:
log.warning(f"[WS] Error detecting game mode: {e}")
log.warning(f"[WS] Traceback: {traceback.format_exc()}")