bugfixes and tweaks. Auto key bindings for RA3

This commit is contained in:
edschuy95 2026-01-08 17:22:47 -05:00
parent 55f85f6794
commit c3171a99b4
13 changed files with 291 additions and 8956 deletions

View file

@ -30,9 +30,9 @@ DEFAULT_PLAYLIST = r".\arena\music\playlist.txt"
DEFAULT_RA3_MAPS = r".\arena\music\ra3_maps.txt"
# Debug override paths
DEBUG_GAME_EXE = r"D:\GOG Games\Quake III\quake3e_con.exe"
DEBUG_PLAYLIST = r"D:\GOG Games\Rocket Arena 3\arena\music\playlist.txt"
DEBUG_RA3_MAPS = r"D:\GOG Games\Rocket Arena 3\arena\music\ra3_maps.txt"
DEBUG_GAME_EXE = r"D:\GOG Games\Quake III\qgame.dll"
DEBUG_PLAYLIST = r"D:\GOG Games\Quake III\arena\music\playlist.txt"
DEBUG_RA3_MAPS = r"D:\GOG Games\Quake III\arena\music\ra3_maps.txt"
# Initial volume
VOLUME_STEP = 0.1 # step for W/S volume control
@ -149,39 +149,43 @@ def load_playlist(playlist_path):
base_dir = playlist_path.parent
songs = []
with open(playlist_path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line:
continue
if line.startswith("#"):
continue
try:
with open(playlist_path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line:
continue
if line.startswith("#"):
continue
song_path = Path(line)
song_path = Path(line)
# If the playlist entry is relative, resolve it relative to playlist.txt
if not song_path.is_absolute():
song_path = base_dir / song_path
# If the playlist entry is relative, resolve it relative to playlist.txt
if not song_path.is_absolute():
song_path = base_dir / song_path
songs.append(str(song_path))
songs.append(str(song_path))
if current_mode == "shuffle":
random.shuffle(songs)
if current_mode == "shuffle":
random.shuffle(songs)
# Re-align song that's playing to new index
if current_song != "nosong":
_song_index = 0
_found_song = False
for s in songs:
_song_eval = Path(s).stem
if current_song == _song_eval:
_found_song = True
playlist_index = _song_index
break
_song_index += 1
if not _found_song:
playlist_index = 0
play_current()
# Re-align song that's playing to new index
if current_song != "nosong":
_song_index = 0
_found_song = False
for s in songs:
_song_eval = Path(s).stem
if current_song == _song_eval:
_found_song = True
playlist_index = _song_index
break
_song_index += 1
if not _found_song:
playlist_index = 0
play_current()
except:
print(f"[DEBUG] Failed to open playlist.txt")
pass
return songs
@ -194,13 +198,16 @@ def load_ra3_maps(path):
line = line.strip()
if line:
maps.add(line.lower())
except PermissionError:
# File is locked by another process (e.g., Notepad)
# Decide how your app should behave
except:
print(f"[DEBUG] Failed to open ra3_maps.txt")
return set()
return maps
def next_track():
global playlist
if not playlist:
return
global volumecheck
volumecheck = True
send_command(pty_proc,"s_musicvolume")
@ -212,6 +219,10 @@ def next_track():
play_current()
def previous_track():
global playlist
if not playlist:
return
global volumecheck
volumecheck = True
send_command(pty_proc,"s_musicVolume")
@ -223,7 +234,7 @@ def previous_track():
play_current()
def play_current():
global is_playing, current_song
global is_playing, current_song, playlist
if not playlist:
return
track = playlist[playlist_index]
@ -247,6 +258,10 @@ def stop_playback():
is_playing = False
def toggle_pause():
global playlist
if not playlist:
return
global volumecheck
volumecheck = True
send_command(pty_proc,"s_musicVolume")
@ -324,16 +339,18 @@ def handle_game_line(line, pty_proc):
print(f"[DEBUG] Active mod is Rocket Arena 3 - enabling music playback")
is_ra3 = True
volumecheck = True
threading.Timer(1.0, lambda: send_command(pty_proc,"s_musicVolume")).start()
if current_mode == "shuffle":
global playlist_index
playlist_index = random.randint(0, len(playlist) - 1)
threading.Timer(2.0, play_current).start()
threading.Timer(.5, lambda: send_command(pty_proc,"s_musicVolume")).start()
if playlist:
if current_mode == "shuffle":
global playlist_index
playlist_index = random.randint(0, len(playlist) - 1)
threading.Timer(1.0, play_current).start()
else:
if not is_playing:
next_track()
threading.Timer(.2, lambda: send_command(pty_proc,"bind [ echo ]\\prevtrack\r\nbind ] echo ]\\nexttrack\r\nbind \\ echo ]\\musicmode\r\nbind ' echo ]\\pausetrack")).start()
else:
print(f"[DEBUG] Active mod is NOT Rocket Arena 3 - disabling music playback")
#print(f"[DEBUG] Active mod is NOT Rocket Arena 3 - disabling music playback")
is_ra3 = False
if is_playing:
stop_playback()
@ -408,7 +425,7 @@ def send_command(pty_proc, cmd):
try:
pty_proc.write(cmd + "\r\n")
pty_proc.flush()
print(f"[DEBUG] Sent command: {cmd}")
#print(f"[DEBUG] Sent command: {cmd}")
except Exception as e:
print(f"[DEBUG] Failed to send command: {e}")
# ==========================================================
@ -448,9 +465,9 @@ def main():
playlist = load_playlist(playlist_path)
ra3_maps = load_ra3_maps(ra3_maps_path)
if not playlist:
print("Playlist is empty!")
return
#if not playlist:
# print("Playlist is empty!")
# return
#if not ra3_maps:
# print("RA3 maps list is empty!")
# return