Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
251 lines (206 loc) · 6.34 KB
/
Copy pathutils.py
File metadata and controls
251 lines (206 loc) · 6.34 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import sys
import os
import threading
import win32gui
from PySide6.QtGui import QPixmap
from PySide6.QtCore import Qt
# shared globals
VERSION = "v1.0.7"
DEBUG = False
IMPERSONATE_OPTIONS = [
"chrome120", "chrome124",
"edge99", "edge101",
]
FONT_NAME = "Segoe UI"
FONT_SIZE = 11
CACHE_TTL = 300
TRACKER_ATTEMPTS_PER_ROUND = 3
TRACKER_RETRY_WAIT = 10
FADE_STEP_IN = 0.3
FADE_STEP_OUT = 1.0 / 6.0
BASE_SCREEN_W = 1920
BASE_SCREEN_H = 1080
OVERLAY_WIDTH_PCT = 45.00
MIN_HEIGHT_PCT = 7.41
HEADER_TOP_PCT = 0.74
HEADER_ICON_SIZE_PCT = 2.22
DIVIDER_Y_PCT = 3.52
ROW_START_Y_PCT = 4.26
ROW_HEIGHT_PCT = 3.40
INNER_BOTTOM_PADDING_PCT = 0.0
RANK_ICON_SIZE_PCT = 3.52
DIVISION_HEIGHT_PCT = 0.58
DIVISION_GAP_PCT = 0.09
MAX_VISIBLE_PLAYERS = 8
state = {
"in_match": False,
"players": [],
"lock": threading.Lock(),
}
tracker_cache = {}
pixmap_cache = {}
PLAYLIST_IMAGE_MAP = {
10: "0.png",
11: "1.png",
13: "2.png",
27: "3.png",
28: "4.png",
29: "5.png",
30: "6.png",
34: "7.png",
}
ALL_PLAYLIST_IDS = [10, 11, 13, 27, 28, 29, 30, 34, 61, 63]
# path / pixmap helpers
def resource_path(relative_path):
"""Get absolute path to resource, works for dev and for PyInstaller"""
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def get_pixmap(folder: str, filename: str, target_w, target_h) -> QPixmap:
path = resource_path(os.path.join(folder, filename))
cache_key = f"{path}_{target_w}x{target_h}"
if cache_key not in pixmap_cache:
if os.path.exists(path):
pm = QPixmap(path)
if not pm.isNull():
if target_w is None:
scaled = pm.scaledToHeight(
target_h, Qt.TransformationMode.SmoothTransformation
)
elif target_h is None:
scaled = pm.scaledToWidth(
target_w, Qt.TransformationMode.SmoothTransformation
)
else:
scaled = pm.scaled(
target_w,
target_h,
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation,
)
pixmap_cache[cache_key] = scaled
else:
pixmap_cache[cache_key] = None
else:
pixmap_cache[cache_key] = None
return pixmap_cache[cache_key]
# rank helpers
def is_bot(primary_id: str) -> bool:
if not primary_id:
return True
if "unknown" in primary_id.lower():
return True
if "|" not in primary_id:
return True
return False
def get_platform_tag(primary_id: str) -> str:
if is_bot(primary_id):
return "[BOT]"
plat = primary_id.split("|")[0].lower()
mapping = {
"steam": "[Steam]",
"epic": "[Epic]",
"xboxone": "[Xbox]",
"ps4": "[PSN]",
"switch": "[Switch]",
}
return mapping.get(plat, "[?]")
def get_tier_id(rank_name: str) -> int:
ranks = [
"Unranked", "Bronze I", "Bronze II", "Bronze III",
"Silver I", "Silver II", "Silver III", "Gold I", "Gold II", "Gold III",
"Platinum I", "Platinum II", "Platinum III", "Diamond I", "Diamond II", "Diamond III",
"Champion I", "Champion II", "Champion III", "Grand Champion I", "Grand Champion II", "Grand Champion III",
"Supersonic Legend",
]
try:
return ranks.index(rank_name)
except ValueError:
return 0
def get_div_id(div_name: str) -> int:
divs = {"Division I": 1, "Division II": 2, "Division III": 3, "Division IV": 4}
return divs.get(div_name, 0)
def get_div_color_id(tier_id: int) -> int:
if 1 <= tier_id <= 3:
return 1
elif 4 <= tier_id <= 6:
return 2
elif 7 <= tier_id <= 9:
return 3
elif 10 <= tier_id <= 12:
return 4
elif 13 <= tier_id <= 15:
return 5
elif 16 <= tier_id <= 18:
return 6
elif 19 <= tier_id <= 21:
return 7
return 7
def shorten_rank(rank_str: str) -> str:
if not rank_str:
return "Unranked"
s = rank_str.strip()
if s.lower() == "supersonic legend":
return "SSL"
if s.lower() == "unranked":
return "Unranked"
roman_map = {"I": "1", "II": "2", "III": "3"}
parts = s.split()
if len(parts) >= 2:
num = roman_map.get(parts[-1].upper(), parts[-1])
if "Grand Champion" in s:
return f"GC{num}"
else:
return f"{parts[0][0].upper()}{num}"
return s
def get_total_matches(stats: dict) -> int:
total = 0
for pid in ALL_PLAYLIST_IDS:
entry = stats.get(pid)
if entry:
total += entry.get("matches_played", 0)
return total
# RL window helpers
def get_rl_window(window_title: str) -> int:
"""Returns the handle for the Rocket League window based on a given title for it."""
hwnd = win32gui.FindWindow(None, window_title)
if not hwnd:
result = []
def enum_cb(h, _):
t = win32gui.GetWindowText(h)
if window_title.lower() in t.lower() and win32gui.IsWindowVisible(h):
result.append(h)
win32gui.EnumWindows(enum_cb, None)
hwnd = result[0] if result else None
if not hwnd:
return None
return hwnd
def is_cursor_inside_window(hwnd: int) -> bool:
try:
left, top, right, bottom = win32gui.GetWindowRect(hwnd)
x, y = win32gui.GetCursorPos()
return left <= x <= right and top <= y <= bottom
except Exception:
return True
def is_rl_focused(window_title: str, require_mouse_over_rl_window: bool) -> bool:
try:
hwnd = win32gui.GetForegroundWindow()
title = win32gui.GetWindowText(hwnd)
if window_title.lower() not in title.lower():
return False
if require_mouse_over_rl_window and not is_cursor_inside_window(hwnd):
return False
return True
except Exception:
return False
# logging
def log(msg: str, tag: str = None):
"""Print to stdout. [tag] prefix only shown when DEBUG is on. tag=\"DEBUG\" messages are silent unless DEBUG."""
if tag == "DEBUG" and not DEBUG:
return
if tag and DEBUG:
print(f"[{tag}] {msg}")
else:
print(msg)