Move server calls to MusicServerClient and give players stable ids
Server requests move out of Settings into a new MusicServerClient autoload with one function per endpoint. It sends requests through a swappable HttpTransport so tests can fake the server, and it frees its HTTPRequest nodes after use. Players now have a UUID that never changes. Their position in Settings.player_array is only used for the Alt+<number> keybinds. Previously the position doubled as the id, so removing a player made points and wins land on the wrong player, and could delete another player's point from a song. Also fixes: - format_time showed 59.6 seconds as "00:60" - searches containing regex characters such as "Q*bert" broke search - SongObject and PlayerObject were Nodes that were never freed; they are now RefCounted - search matching is split out of the UI code into find_matches()
This commit is contained in:
1 parent
4a275e6a88
commit
87ff3d899b
18 files changed
+281
-162
No files matched your search
+27
-31
@@ -257,7 +257,7 @@ func fetch_song_list_at_start() -> void:
|
||||
print("Unexpected data")
|
||||
Playlist.update_last_played_song()
|
||||
update_song_list()
|
||||
Settings.make_request2("/music/list", fetch_song_list_at_start_done, true)
|
||||
MusicServerClient.fetch_song_list(fetch_song_list_at_start_done)
|
||||
|
||||
func play_next_song() -> void:
|
||||
print("play_next_song ", Playlist.latest_played_song)
|
||||
@@ -277,11 +277,6 @@ func play_next_song() -> void:
|
||||
func fetch_song() -> void:
|
||||
print("fetch_song")
|
||||
Playlist.is_song_downloading = true
|
||||
var url: String = ""
|
||||
if Settings.use_low_played_mode:
|
||||
url = "/music/rand/low"
|
||||
else:
|
||||
url = "/music/rand"
|
||||
var new_song_object: SongObject = SongObject.new()
|
||||
var fetch_song_done: Callable = func fetch_song_done(body: PackedByteArray) -> void:
|
||||
print("fetch_song_done")
|
||||
@@ -306,11 +301,11 @@ func fetch_song() -> void:
|
||||
Playlist.is_song_downloading = false
|
||||
if Settings.is_debug:
|
||||
update_song_list()
|
||||
Settings.make_request2("/music/info", fetch_song_info_done, true)
|
||||
MusicServerClient.fetch_song_info(fetch_song_info_done)
|
||||
|
||||
Settings.make_request2("/music/addQue", added_to_que_done, false)
|
||||
MusicServerClient.add_to_queue(added_to_que_done)
|
||||
|
||||
Settings.make_request2(url, fetch_song_done, true)
|
||||
MusicServerClient.fetch_random_song(Settings.use_low_played_mode, fetch_song_done)
|
||||
|
||||
func update_song_list() -> void:
|
||||
print("update_song_list")
|
||||
@@ -335,7 +330,7 @@ func song_object_clicked(event: InputEvent, song_no: int) -> void:
|
||||
sound.data = body
|
||||
Playlist.add_song_to_song_object(song_no, sound)
|
||||
music_player_container.play_song_object(song_no)
|
||||
Settings.make_request2("/music?song=" + str(song_no), song_downloaded, true)
|
||||
MusicServerClient.fetch_song(song_no, song_downloaded)
|
||||
else:
|
||||
print("song already downloaded")
|
||||
music_player_container.play_song_object(song_no)
|
||||
@@ -347,7 +342,7 @@ func reset_playlist() -> void:
|
||||
fetch_song_list_at_start()
|
||||
fetch_song()
|
||||
|
||||
Settings.make_request2("/music/reset", playlist_reset_done, false)
|
||||
MusicServerClient.reset_playlist(playlist_reset_done)
|
||||
|
||||
func reset_points() -> void:
|
||||
print("reset_points")
|
||||
@@ -412,7 +407,7 @@ func get_suggestion_list() -> void:
|
||||
inspiration_list.add_child(inspiration_label)
|
||||
else:
|
||||
print("Unexpected data")
|
||||
Settings.make_request2("/music/all", populate_list, true)
|
||||
MusicServerClient.fetch_all_soundtracks(populate_list)
|
||||
|
||||
func add_players() -> void:
|
||||
print("add_players")
|
||||
@@ -423,15 +418,15 @@ func add_players() -> void:
|
||||
func add_player() -> void:
|
||||
print("add_player")
|
||||
if new_player_name_field.text != "" && Settings.player_array.size() < Settings.MAX_NUMBER_OF_PLAYERS:
|
||||
var new_player_object: PlayerObject = PlayerObject.new(new_player_name_field.text, Settings.player_array.size())
|
||||
var new_player_object: PlayerObject = PlayerObject.new(new_player_name_field.text)
|
||||
new_player_name_field.text = ""
|
||||
Settings.player_array.append(new_player_object)
|
||||
new_player_object.connect("first_point_triggerd", music_player_container._on_point_triggered.bind("first"))
|
||||
new_player_object.connect("match_point_triggerd", music_player_container._on_point_triggered.bind("match"))
|
||||
new_player_object.connect("winner_triggerd", _on_player_won.bind(new_player_object.id))
|
||||
new_player_object.connect("winner_triggerd", _on_player_won.bind(new_player_object))
|
||||
new_player_object.connect("point_given_sound", _on_make_point_given_sound)
|
||||
new_player_object.connect("player_point_given", _on_point_given.bind(new_player_object.id))
|
||||
new_player_object.connect("player_point_taken", _on_point_taken.bind(new_player_object.id))
|
||||
new_player_object.connect("player_point_given", _on_point_given.bind(new_player_object))
|
||||
new_player_object.connect("player_point_taken", _on_point_taken.bind(new_player_object))
|
||||
load_players()
|
||||
|
||||
func load_players() -> void:
|
||||
@@ -442,43 +437,44 @@ func load_players() -> void:
|
||||
print(player_object.player_name)
|
||||
|
||||
var new_player: Player = player.instantiate()
|
||||
new_player.id = counter
|
||||
|
||||
new_player.player_object = player_object
|
||||
new_player.list_index = counter
|
||||
|
||||
new_player.connect("change_character_clicked", _on_player_change_character_clicked.bind(new_player, player_object.player_name))
|
||||
new_player.connect("player_removed", _on_player_removed.bind(counter))
|
||||
new_player.connect("player_removed", _on_player_removed.bind(player_object))
|
||||
|
||||
players_list_container.add_child(new_player)
|
||||
counter += 1
|
||||
|
||||
func _on_point_given(player_given_point: int) -> void:
|
||||
func _on_point_given(player_object: PlayerObject) -> void:
|
||||
print("_on_point_given")
|
||||
log_window.add_log_row(Settings.player_array[player_given_point].player_name + " got a point")
|
||||
log_window.add_log_row(player_object.player_name + " got a point")
|
||||
if Playlist.currently_playing_song >= 0:
|
||||
Playlist.add_point(player_given_point)
|
||||
Playlist.add_point(player_object.id)
|
||||
update_song_list()
|
||||
|
||||
func _on_make_point_given_sound() -> void:
|
||||
music_player_container.play_sound_effect(preload("res://sounds/itemopen.wav"))
|
||||
|
||||
func _on_point_taken(player_taken_point: int) -> void:
|
||||
func _on_point_taken(player_object: PlayerObject) -> void:
|
||||
print("_on_point_taken")
|
||||
log_window.add_log_row(Settings.player_array[player_taken_point].player_name + " lost a point")
|
||||
log_window.add_log_row(player_object.player_name + " lost a point")
|
||||
music_player_container.play_sound_effect(preload("res://sounds/itemequip.wav"))
|
||||
if Playlist.currently_playing_song >= 0:
|
||||
Playlist.remove_point(player_taken_point)
|
||||
Playlist.remove_point(player_object.id)
|
||||
update_song_list()
|
||||
|
||||
func _on_player_won(winning_player_id: int) -> void:
|
||||
func _on_player_won(player_object: PlayerObject) -> void:
|
||||
print("_on_player_won")
|
||||
winner_window.show_winner(winning_player_id)
|
||||
winner_window.show_winner(player_object)
|
||||
music_player_container.play_song(preload("res://sounds/winning.mp3"))
|
||||
Settings.add_to_stats = false
|
||||
|
||||
func _on_player_removed(player_to_remove: int) -> void:
|
||||
print("_on_player_removed ", player_to_remove)
|
||||
Settings.player_array.remove_at(player_to_remove)
|
||||
func _on_player_removed(player_object: PlayerObject) -> void:
|
||||
print("_on_player_removed ", player_object.player_name)
|
||||
Settings.player_array.erase(player_object)
|
||||
load_players()
|
||||
Playlist.remove_player_from_list(player_to_remove)
|
||||
Playlist.remove_player_from_list(player_object.id)
|
||||
update_song_list()
|
||||
|
||||
func _on_player_change_character_clicked(new_player: Player, player_name: String) -> void:
|
||||
|
||||
Reference in new issue
Block a user