diff --git a/game_server.py b/game_server.py index 296057d..1663764 100644 --- a/game_server.py +++ b/game_server.py @@ -1448,8 +1448,6 @@ def game_loop(): game_state['enemies'].extend(generate_enemies(1)) break - # Update player shooting - # Update player shooting for player_id, player in game_state['players'].items(): if not player.is_paused: update_synth_coins(game_state['players']) @@ -1473,7 +1471,7 @@ def game_loop(): if game_state['is_playing']: song_duration = len(AudioSegment.from_mp3(game_state['playlist'][game_state['current_song_index']])) if current_time - game_state['music_start_time'] > song_duration / 1000: - change_song() + music_player.next_song() if music_player.is_playing: if music_player.update(): @@ -1493,6 +1491,7 @@ def game_loop(): socketio.emit('game_update', serialized_state, room=main_room) socketio.sleep(0.033) # Update approximately 30 times per second + except Exception as e: logging.error(f"Error in game loop: {str(e)}") break @@ -1560,17 +1559,6 @@ def stop_music(): music_player.stop() socketio.emit('music_stop', room=main_room) -def change_song(): - new_song = music_player.next_song() - socketio.emit('music_control', { - 'action': 'change', - 'song': new_song, - 'startTime': music_player.start_time, - 'serverTime': time.time(), - 'songDuration': music_player.get_current_song_duration() - }, room=main_room) - - class AudioStreamer: def __init__(self, music_player): self.music_player = music_player @@ -1619,7 +1607,6 @@ class MusicPlayer: self.is_playing = True self.start_time = time.time() self.load_current_song() - send_discord_alert(f"🎵 Now playing: {self.get_current_song()}") def stop(self): @@ -1653,7 +1640,6 @@ class MusicPlayer: self.start_time = time.time() self.load_current_song() new_song = self.get_current_song() - send_discord_alert(f"🎵 Now playing: {new_song}") # Emit updated music sync information socketio.emit('music_control', { @@ -1663,7 +1649,8 @@ class MusicPlayer: 'serverTime': time.time(), 'songDuration': self.get_current_song_duration() }, room=main_room) - + send_discord_alert(f"🎵 Now playing: {new_song}") + return new_song @@ -1672,7 +1659,6 @@ class MusicPlayer: self.current_song_index = (self.current_song_index + 1) % len(self.playlist) self.start_time = time.time() self.load_current_song() - send_discord_alert(f"🎵 Now playing: {self.get_current_song()}") def reload_playlist(self): new_playlist = load_music_playlist() @@ -1858,13 +1844,6 @@ class AdminConsole(cmd.Cmd): """Stop the music""" stop_music() - def do_change_song(self, arg): - """Change the current song""" - if not arg: - print("Error: Song filename is required") - else: - change_song(arg) - def do_quit(self, arg): """Exit the admin console""" print("Exiting admin console") @@ -1872,15 +1851,7 @@ class AdminConsole(cmd.Cmd): def do_next_song(self, arg): """Change to the next song in the playlist""" - new_song = music_player.next_song() - print(f"Changed to next song: {new_song}") - socketio.emit('music_control', { - 'action': 'change', - 'song': new_song, - 'startTime': music_player.start_time, - 'serverTime': time.time(), - 'songDuration': music_player.get_current_song_duration() - }, room=main_room) + music_player.next_song() def do_send_alert(self, arg): """Send an alert to all players: send_alert """ @@ -1896,19 +1867,7 @@ class AdminConsole(cmd.Cmd): """Reload the music playlist""" song_count = music_player.reload_playlist() print(f"Playlist reloaded. {song_count} songs available.") - - # Optionally, you can change to the next song after reloading - new_song = music_player.next_song() - print(f"Changed to next song: {new_song}") - socketio.emit('music_control', { - 'action': 'change', - 'song': new_song, - 'startTime': music_player.start_time, - 'serverTime': time.time(), - 'songDuration': music_player.get_current_song_duration() - }, room=main_room) - - + music_player.next_song() def admin_cli(): try: