Don't list unplayed songs on the statistics cards

Cards only list songs that have been played. With fewer than six played
songs they are all listed as most played, so no song is listed twice. The
soundtrack popup still lists every song.

Closes #46
This commit is contained in:
Sansan committed 2026-10-09 16:55:39 +02:00
1 parent 06f457b027
commit cd4331881c
2 files changed
+69 -13

No files matched your search

+34 -8
View File
@@ -1,12 +1,15 @@
class_name SoundtrackCard
extends PanelContainer
## One soundtrack in the statistics view: its name, how often and when it was last
## played, and its most and least played songs. Clicking it asks for all its songs.
## played, and its most and least played songs. Songs never played are not listed, and
## the least played are only shown when there are enough played songs to not repeat
## any. Clicking it asks for all its songs.
## Emitted when the card is clicked.
signal pressed(soundtrack: SoundtrackWithSongs)
## How many of the most and least played songs the card lists.
## How many of the most and least played songs the card lists. With fewer than twice
## as many played songs, all of them are listed as most played.
const SONGS_SHOWN: int = 3
## The soundtrack the card shows.
@@ -36,13 +39,17 @@ func show_soundtrack(data: SoundtrackWithSongs) -> void:
last_played_label.text = last_played_text(data.soundtrack_last_played)
last_played_label.visible = !data.soundtrack_last_played.is_empty()
var most_played: Array[SongInfoForStats] = songs_by_plays(data.songs).slice(0, SONGS_SHOWN)
# Without the songs already shown as most played
var least_played: Array[SongInfoForStats] = songs_by_plays(data.songs, true).filter(
func(song: SongInfoForStats) -> bool: return !most_played.has(song)
).slice(0, SONGS_SHOWN)
var most_played: Array[SongInfoForStats] = []
var least_played: Array[SongInfoForStats] = []
var played: Array[SongInfoForStats] = played_songs(data.songs)
if played.size() >= SONGS_SHOWN * 2:
most_played = played.slice(0, SONGS_SHOWN)
least_played = songs_by_plays(played, true).slice(0, SONGS_SHOWN)
else:
# Too few to split without listing a song twice, so all of them are most played
most_played = played
most_played_header.text = "Most played" if !data.songs.is_empty() else "No songs"
most_played_header.text = song_list_header(data.songs.size(), played.size())
_fill_song_list(most_played_list, most_played)
least_played_header.visible = !least_played.is_empty()
_fill_song_list(least_played_list, least_played)
@@ -63,6 +70,25 @@ static func last_played_text(last_played: String) -> String:
return "Last played " + last_played.substr(0, 10)
## The songs of [param songs] that have been played, most played first. Songs never
## played are left out: the card only lists them in the popup with every song.
static func played_songs(songs: Array[SongInfoForStats]) -> Array[SongInfoForStats]:
var played: Array[SongInfoForStats] = []
played.assign(songs_by_plays(songs).filter(
func(song: SongInfoForStats) -> bool: return song.times_played > 0))
return played
## The header above the most played songs, for a soundtrack with [param song_count]
## songs of which [param played_count] have been played.
static func song_list_header(song_count: int, played_count: int) -> String:
if song_count == 0:
return "No songs"
if played_count == 0:
return "No songs played yet"
return "Most played"
## One line of a song list: how often the song was played, then its name.
static func song_text(song: SongInfoForStats) -> String:
return "%d × %s" % [song.times_played, song.song_name]