The Winner popup now shows every player's score after each song as a step line, with the winning score marked, and three facts under it: the longest streak, the longest standstill and the song most players scored on. The data comes from the points each song already records, through the new ScoreHistory. The popup grows to 1600x920 with the graph across the full width, so a 60-song game with five players stays readable. Reset points now starts a new game: it clears the points on the songs and the graph starts after the song that was playing. Songs already on the server at startup count as an earlier game. The screenshot tour has a long five-player game, and only the Winner popup differs from before.
165 lines
5.7 KiB
GDScript
165 lines
5.7 KiB
GDScript
extends GdUnitTestSuite
|
||
## ScoreHistory: the scores after each song of a game and the facts shown under the
|
||
## graph on the Winner popup.
|
||
|
||
var _crono: PlayerObject
|
||
var _marle: PlayerObject
|
||
var _lucca: PlayerObject
|
||
var _players: Array[PlayerObject] = []
|
||
var _snapshot: AutoloadSnapshot
|
||
|
||
|
||
func before_test() -> void:
|
||
_snapshot = AutoloadSnapshot.take([Playlist])
|
||
Playlist.reset_playlist()
|
||
_crono = PlayerObject.new("Crono")
|
||
_marle = PlayerObject.new("Marle")
|
||
_lucca = PlayerObject.new("Lucca")
|
||
_players = [_crono, _marle, _lucca]
|
||
|
||
|
||
func after_test() -> void:
|
||
Playlist.reset_playlist()
|
||
_snapshot.restore()
|
||
|
||
|
||
## A history where song n (counting from 1) was scored on by the players in
|
||
## [param scorers][n - 1].
|
||
func _history(scorers: Array) -> ScoreHistory:
|
||
var song_scorers: Array = []
|
||
for players: Array in scorers:
|
||
song_scorers.append(players.map(func(player: PlayerObject) -> String: return player.id))
|
||
return ScoreHistory.from_songs(_players, song_scorers)
|
||
|
||
|
||
func _add_songs(scorers: Array) -> void:
|
||
for players: Array in scorers:
|
||
var song: SongObject = SongObject.new()
|
||
for player: PlayerObject in players:
|
||
song.add_point(player.id)
|
||
Playlist.add_to_playlist(song)
|
||
|
||
|
||
func test_scores_after_each_song() -> void:
|
||
var history: ScoreHistory = _history([[_crono], [], [_crono, _marle], [_marle]])
|
||
|
||
assert_array(history.scores_after_songs(_crono.id)).contains_exactly([0, 1, 1, 2, 2])
|
||
assert_array(history.scores_after_songs(_marle.id)).contains_exactly([0, 0, 0, 1, 2])
|
||
assert_array(history.scores_after_songs(_lucca.id)).contains_exactly([0, 0, 0, 0, 0])
|
||
assert_int(history.final_score(_crono.id)).is_equal(2)
|
||
|
||
|
||
func test_from_playlist_takes_the_songs_of_the_current_game() -> void:
|
||
_add_songs([[_lucca], [_crono], [_marle], [_crono], [_lucca]])
|
||
for song_no: int in 4:
|
||
Playlist.song_object_array[song_no].has_played = true
|
||
Playlist.game_start_song = 1
|
||
Playlist.currently_playing_song = 3
|
||
|
||
var history: ScoreHistory = ScoreHistory.from_playlist(_players)
|
||
|
||
# Song 0 was the last game, song 4 is not played yet
|
||
assert_int(history.songs.size()).is_equal(3)
|
||
assert_array(history.scores_after_songs(_crono.id)).contains_exactly([0, 1, 1, 2])
|
||
assert_int(history.final_score(_lucca.id)).is_equal(0)
|
||
|
||
|
||
func test_from_playlist_leaves_out_songs_not_played() -> void:
|
||
_add_songs([[_crono], [_marle], [_crono], [_marle]])
|
||
Playlist.song_object_array[0].has_played = true
|
||
Playlist.song_object_array[2].has_played = true
|
||
Playlist.currently_playing_song = 3
|
||
|
||
var history: ScoreHistory = ScoreHistory.from_playlist(_players)
|
||
|
||
assert_int(history.songs.size()).is_equal(3)
|
||
assert_array(history.scores_after_songs(_marle.id)).contains_exactly([0, 0, 0, 1])
|
||
|
||
|
||
func test_from_playlist_goes_on_to_the_last_played_song() -> void:
|
||
_add_songs([[_crono], [_marle], [_crono]])
|
||
for song: SongObject in Playlist.song_object_array:
|
||
song.has_played = true
|
||
# An older song picked in the music list
|
||
Playlist.currently_playing_song = 0
|
||
|
||
var history: ScoreHistory = ScoreHistory.from_playlist(_players)
|
||
|
||
assert_int(history.songs.size()).is_equal(3)
|
||
|
||
|
||
func test_from_playlist_before_any_song() -> void:
|
||
_add_songs([[], []])
|
||
|
||
var history: ScoreHistory = ScoreHistory.from_playlist(_players)
|
||
|
||
assert_array(history.songs).is_empty()
|
||
assert_str(history.longest_streak_text()).is_equal("No songs played")
|
||
assert_str(history.longest_standstill_text()).is_equal("No songs played")
|
||
assert_str(history.most_shared_text()).is_equal("No songs played")
|
||
|
||
|
||
func test_points_of_removed_players_are_left_out() -> void:
|
||
var history: ScoreHistory = ScoreHistory.from_songs([_crono],
|
||
[[_crono.id, "removed-player"], ["removed-player"]])
|
||
|
||
assert_array(history.songs[0]).contains_exactly([_crono.id])
|
||
assert_array(history.songs[1]).is_empty()
|
||
|
||
|
||
func test_longest_streak() -> void:
|
||
var history: ScoreHistory = _history(
|
||
[[_marle], [_marle], [], [_crono], [_crono], [_crono], [_marle]])
|
||
|
||
assert_str(history.longest_streak_text()).is_equal("Crono, 3 songs in a row (4–6)")
|
||
|
||
|
||
func test_longest_streak_tie_goes_to_the_earliest() -> void:
|
||
var history: ScoreHistory = _history([[_crono], [_crono], [_marle], [_marle]])
|
||
|
||
assert_str(history.longest_streak_text()).is_equal("Crono, 2 songs in a row (1–2)")
|
||
history = _history([[_marle], [_marle], [_crono], [_crono]])
|
||
assert_str(history.longest_streak_text()).is_equal("Marle, 2 songs in a row (1–2)")
|
||
|
||
|
||
func test_no_streak() -> void:
|
||
var history: ScoreHistory = _history([[_crono], [_marle], [_crono], []])
|
||
|
||
assert_str(history.longest_streak_text()).is_equal("Nobody scored twice in a row")
|
||
|
||
|
||
func test_longest_standstill() -> void:
|
||
var history: ScoreHistory = _history([[_crono], [], [], [_marle], [], [], [], [_crono]])
|
||
|
||
assert_str(history.longest_standstill_text()).is_equal("Songs 5–7, nobody scored")
|
||
|
||
|
||
func test_standstill_of_one_song() -> void:
|
||
var history: ScoreHistory = _history([[_crono], [], [_marle]])
|
||
|
||
assert_str(history.longest_standstill_text()).is_equal("Song 2, nobody scored")
|
||
|
||
|
||
func test_no_standstill() -> void:
|
||
var history: ScoreHistory = _history([[_crono], [_marle]])
|
||
|
||
assert_str(history.longest_standstill_text()).is_equal("Someone scored on every song")
|
||
|
||
|
||
func test_most_shared_song_names_two_players_in_player_order() -> void:
|
||
var history: ScoreHistory = _history([[_crono], [_lucca, _marle], [_crono, _lucca]])
|
||
|
||
assert_str(history.most_shared_text()).is_equal("Song 2, Marle and Lucca")
|
||
|
||
|
||
func test_most_shared_song_counts_more_than_two_players() -> void:
|
||
var history: ScoreHistory = _history([[_crono, _marle], [_crono, _marle, _lucca]])
|
||
|
||
assert_str(history.most_shared_text()).is_equal("Song 2, 3 players")
|
||
|
||
|
||
func test_no_shared_song() -> void:
|
||
var history: ScoreHistory = _history([[_crono], [_marle], []])
|
||
|
||
assert_str(history.most_shared_text()).is_equal("No song had two scorers")
|