Settings has a Music folder row. A folder with subfolders is played as soundtracks: Next picks a random subfolder and a random song in it, the subfolder is the answer's soundtrack and the file name without its type the song. The inspiration list and Search show the subfolders. A folder with songs and no subfolders is a prepared quiz, played once in order (natural sort) or at random, showing only the song title. It has no winning score: after the last song Next becomes Show winner, and the players with the most points win, ties included. While a folder is used nothing but the characters is asked from the server: Sync, QR, Statistics, the update check and play counting are off. Characters fall back to the cached pictures when the server can't be reached. mp3, ogg and wav play; other files and broken ones are skipped. The old local playback code, the hidden Open button and the hidden Local toggle are removed. Next now waits for the song to start before preparing the next one.
178 lines
6.9 KiB
GDScript
178 lines
6.9 KiB
GDScript
extends MainWindowTestSuite
|
||
## The Winner popup's graph of the game and the facts under it, built from the points
|
||
## given with the keybinds, and Reset points starting a new game.
|
||
|
||
var _crono: PlayerObject
|
||
var _marle: PlayerObject
|
||
var _popup: WinnerPopup
|
||
|
||
|
||
func before_test() -> void:
|
||
super()
|
||
_crono = _add_player("Crono")
|
||
_marle = _add_player("Marle")
|
||
_popup = _quiz.get_node("WinnerPopup")
|
||
await _play_first_song()
|
||
Settings.winning_score = 3
|
||
|
||
|
||
## Moves on to a new song, like Next does, without waiting for a download. Songs the
|
||
## game downloaded ahead are left unplayed.
|
||
func _next_song() -> void:
|
||
var song: SongObject = SongObject.new()
|
||
song.song_number = Playlist.song_object_array.size()
|
||
Playlist.add_to_playlist(song)
|
||
Playlist.set_currently_playing_song(song.song_number)
|
||
Playlist.song_has_played(song.song_number)
|
||
|
||
|
||
func _legend_texts() -> Array[String]:
|
||
var texts: Array[String] = []
|
||
for entry: HBoxContainer in _popup.legend.get_children():
|
||
texts.append((entry.get_child(1) as Label).text)
|
||
return texts
|
||
|
||
|
||
# Song 1: Crono. Song 2: nobody. Song 3: Crono and Marle. Song 4: Crono wins.
|
||
func _play_a_game() -> void:
|
||
await _give_point_with_keybind(1)
|
||
_next_song()
|
||
_next_song()
|
||
await _give_point_with_keybind(1)
|
||
await _give_point_with_keybind(2)
|
||
_next_song()
|
||
await _give_point_with_keybind(1)
|
||
|
||
|
||
func test_winning_shows_how_the_game_went() -> void:
|
||
await _play_a_game()
|
||
|
||
assert_bool(_popup.visible).is_true()
|
||
var history: ScoreHistory = _popup.score_graph._history
|
||
assert_int(history.songs.size()).is_equal(4)
|
||
assert_array(history.scores_after_songs(_crono.id)).contains_exactly([0, 1, 1, 2, 3])
|
||
assert_array(history.scores_after_songs(_marle.id)).contains_exactly([0, 0, 0, 1, 1])
|
||
assert_array(_legend_texts()).contains_exactly(["Crono 3", "Marle 1"])
|
||
assert_str(_popup.streak_label.text).is_equal("Crono, 2 songs in a row (3–4)")
|
||
assert_str(_popup.standstill_label.text).is_equal("Song 2, nobody scored")
|
||
assert_str(_popup.shared_label.text).is_equal("Song 3, Crono and Marle")
|
||
|
||
|
||
func test_graph_draws_a_line_per_player_up_to_their_score() -> void:
|
||
await _play_a_game()
|
||
var graph: ScoreGraph = _popup.score_graph
|
||
|
||
for index: int in 2:
|
||
var points: PackedVector2Array = graph.line_points(index)
|
||
# Every line starts at song 0 with no points and ends at the last song
|
||
assert_float(points[0].x).is_less(points[points.size() - 1].x)
|
||
assert_float(points[0].y).is_greater(points[points.size() - 1].y)
|
||
# Crono's line ends higher than Marle's
|
||
var crono_end: Vector2 = graph.line_points(0)[graph.line_points(0).size() - 1]
|
||
var marle_end: Vector2 = graph.line_points(1)[graph.line_points(1).size() - 1]
|
||
assert_float(crono_end.y).is_less(marle_end.y)
|
||
assert_object(graph.player_color(0)).is_not_equal(graph.player_color(1))
|
||
|
||
|
||
func test_point_taken_back_is_not_in_the_graph() -> void:
|
||
await _give_point_with_keybind(2)
|
||
# The -1 button; after Ctrl+Alt the test runner keeps Ctrl held for later keys
|
||
_player_row(_marle).minus_button.pressed.emit()
|
||
await _give_point_with_keybind(1)
|
||
await _give_point_with_keybind(1)
|
||
await _give_point_with_keybind(1)
|
||
|
||
assert_array(_popup.score_graph._history.songs[0]).contains_exactly([_crono.id])
|
||
|
||
|
||
func test_reset_points_starts_a_new_game() -> void:
|
||
await _play_a_game()
|
||
_popup.close()
|
||
|
||
_press("QuizToolbar/ResetPointsButton")
|
||
for song: int in 3:
|
||
_next_song()
|
||
await _give_point_with_keybind(2)
|
||
|
||
assert_bool(_popup.visible).is_true()
|
||
var history: ScoreHistory = _popup.score_graph._history
|
||
assert_int(history.songs.size()).is_equal(3)
|
||
assert_array(_legend_texts()).contains_exactly(["Crono 0", "Marle 3"])
|
||
assert_str(_popup.streak_label.text).is_equal("Marle, 3 songs in a row (1–3)")
|
||
|
||
|
||
func test_reset_points_removes_the_points_from_the_songs() -> void:
|
||
await _play_a_game()
|
||
_popup.close()
|
||
|
||
_press("QuizToolbar/ResetPointsButton")
|
||
await _runner.simulate_frames(1)
|
||
|
||
for song: SongObject in Playlist.song_object_array:
|
||
assert_array(song.players_given_point).is_empty()
|
||
for row: SongRow in _quiz.music_list_panel._rows.get_children():
|
||
assert_int(row.song_list_players.get_child_count()).is_equal(0)
|
||
assert_int(Playlist.game_start_song).is_equal(Playlist.currently_playing_song + 1)
|
||
|
||
|
||
func test_long_game_with_five_players_stays_readable() -> void:
|
||
for player_name: String in ["Lucca", "Frog", "Robo"]:
|
||
_add_player(player_name)
|
||
Settings.winning_score = 20
|
||
var players: Array[PlayerObject] = Settings.player_array
|
||
var history: ScoreHistory = ScoreHistory.from_songs(players, UiTour.long_game(players))
|
||
for player: PlayerObject in players:
|
||
player.player_score = history.final_score(player.id)
|
||
assert_int(players[2].player_score).is_equal(20)
|
||
|
||
_popup.show_winner(players[2])
|
||
_popup.show_history(history)
|
||
await _runner.simulate_frames(2)
|
||
|
||
var graph: ScoreGraph = _popup.score_graph
|
||
assert_float(graph.size.x).override_failure_message("The graph is not full width") \
|
||
.is_greater(1400.0)
|
||
# Song numbers along the bottom are at least a label's width apart
|
||
var songs: Array[int] = graph.labelled_songs()
|
||
assert_int(songs.front()).is_equal(1)
|
||
assert_int(songs.back()).is_equal(60)
|
||
for i: int in range(1, songs.size()):
|
||
assert_float(graph.song_x(songs[i]) - graph.song_x(songs[i - 1])).is_greater_equal(40.0)
|
||
# Scores at the end of the lines do not overlap and stay inside the graph
|
||
var font_size: int = graph.get_theme_font_size(&"font_size", ScoreGraph.THEME_TYPE)
|
||
var label_ys: Array[float] = []
|
||
for position: Vector2 in graph.score_label_positions():
|
||
assert_bool(Rect2(Vector2.ZERO, graph.size).has_point(position)).is_true()
|
||
label_ys.append(position.y)
|
||
label_ys.sort()
|
||
for i: int in range(1, label_ys.size()):
|
||
assert_float(label_ys[i] - label_ys[i - 1]).is_greater_equal(font_size)
|
||
# Every line stays inside the graph
|
||
for index: int in players.size():
|
||
for point: Vector2 in graph.line_points(index):
|
||
assert_bool(Rect2(Vector2.ZERO, graph.size).has_point(point)).is_true()
|
||
# The facts fit on one line each
|
||
for label: Label in [_popup.streak_label, _popup.standstill_label, _popup.shared_label]:
|
||
assert_int(label.get_line_count()).override_failure_message(label.text + " wraps") \
|
||
.is_equal(1)
|
||
# The whole popup fits in the window
|
||
assert_bool(Rect2(Vector2.ZERO, Vector2(1920, 1080)).encloses(
|
||
_popup.winner_panel.get_global_rect())).is_true()
|
||
|
||
|
||
func test_winners_text() -> void:
|
||
var crono: PlayerObject = PlayerObject.new("Crono")
|
||
var marle: PlayerObject = PlayerObject.new("Marle")
|
||
var lucca: PlayerObject = PlayerObject.new("Lucca")
|
||
crono.player_score = 1
|
||
var one: Array[PlayerObject] = [crono]
|
||
var two: Array[PlayerObject] = [crono, marle]
|
||
var three: Array[PlayerObject] = [crono, marle, lucca]
|
||
var none: Array[PlayerObject] = []
|
||
|
||
assert_str(WinnerPopup.winners_text(one)).is_equal("Crono won with 1 point!!")
|
||
assert_str(WinnerPopup.winners_text(two)).is_equal("Crono and Marle won with 1 point!!")
|
||
assert_str(WinnerPopup.winners_text(three)) \
|
||
.is_equal("Crono, Marle and Lucca won with 1 point!!")
|
||
assert_str(WinnerPopup.winners_text(none)).is_equal("The quiz is over!")
|