Ignore Show answer when no song is playing
Before the first song played, currently_playing_song is -1, so pressing Show answer marked the last song in the list as answered. That is the preloaded song, so its title was shown as soon as it started playing, and played?song=-1 was sent to the server. With an empty playlist it crashed.
This commit is contained in:
1 parent
5a979fca48
commit
ed292877ef
3 files changed
+32
No files matched your search
@@ -36,6 +36,9 @@ func set_last_played_answered() -> void:
|
|||||||
song_object_array[latest_played_song].is_answered = true
|
song_object_array[latest_played_song].is_answered = true
|
||||||
|
|
||||||
func song_is_answered(song_no: int = currently_playing_song) -> void:
|
func song_is_answered(song_no: int = currently_playing_song) -> void:
|
||||||
|
# Nothing is playing yet (-1); a negative index would answer the last, unplayed song
|
||||||
|
if song_no < 0 || song_no >= song_object_array.size():
|
||||||
|
return
|
||||||
print("show_answer_pressed song_object: ", song_object_array[song_no]._to_string())
|
print("show_answer_pressed song_object: ", song_object_array[song_no]._to_string())
|
||||||
song_object_array[song_no].is_answered = true
|
song_object_array[song_no].is_answered = true
|
||||||
if Settings.add_to_stats:
|
if Settings.add_to_stats:
|
||||||
|
|||||||
@@ -214,3 +214,15 @@ func test_closing_settings_with_full_cache_downloads_nothing() -> void:
|
|||||||
_close_settings()
|
_close_settings()
|
||||||
|
|
||||||
assert_int(_server.count("/music/rand")).is_equal(downloads_before)
|
assert_int(_server.count("/music/rand")).is_equal(downloads_before)
|
||||||
|
|
||||||
|
|
||||||
|
func test_show_answer_before_first_song_does_not_reveal_next_song() -> void:
|
||||||
|
_press("ShowAnswerButton")
|
||||||
|
|
||||||
|
assert_bool(Playlist.song_object_array[0].is_answered).is_false()
|
||||||
|
assert_int(_server.count("/music/played?song=-1")).is_equal(0)
|
||||||
|
|
||||||
|
await _play_first_song()
|
||||||
|
|
||||||
|
assert_str((_window.get_node("VBoxContainer/SoundtrackLabel") as Label).text) \
|
||||||
|
.is_equal("????????")
|
||||||
@@ -182,3 +182,20 @@ func test_current_titles_are_hidden_until_answered() -> void:
|
|||||||
|
|
||||||
assert_str(Playlist.get_current_soundtrack_title()).is_equal("Soundtrack 0")
|
assert_str(Playlist.get_current_soundtrack_title()).is_equal("Soundtrack 0")
|
||||||
assert_str(Playlist.get_current_song_title()).is_equal("Song 0")
|
assert_str(Playlist.get_current_song_title()).is_equal("Song 0")
|
||||||
|
|
||||||
|
|
||||||
|
func test_answering_when_nothing_is_playing_does_nothing() -> void:
|
||||||
|
Settings.add_to_stats = true
|
||||||
|
var songs: Array[SongObject] = _add_songs(2)
|
||||||
|
|
||||||
|
Playlist.song_is_answered()
|
||||||
|
|
||||||
|
assert_bool(songs[0].is_answered).is_false()
|
||||||
|
assert_bool(songs[1].is_answered).is_false()
|
||||||
|
assert_array(_server.requested_paths).is_empty()
|
||||||
|
|
||||||
|
|
||||||
|
func test_answering_with_empty_playlist_does_nothing() -> void:
|
||||||
|
Playlist.song_is_answered()
|
||||||
|
|
||||||
|
assert_array(_server.requested_paths).is_empty()
|
||||||
Reference in new issue
Block a user