Show in the top bar when a newer version is available
Build / test (push) Successful in 46s
Build / build (push) Successful in 1m12s

At start and after switching server, the game asks the server for the newest
MusicPlayer release and shows "Version X is available" in the top bar when it
is newer than this one.
This commit is contained in:
Sansan committed 2026-10-07 22:08:53 +02:00
1 parent 240c331ab2
commit 41974ea5e3
9 files changed
+4012 -1

No files matched your search

+14
View File
@@ -39,6 +39,20 @@ theme_type_variation = &"HighlightLarge"
text = "DEBUG"
vertical_alignment = 1
[node name="UpdateLabel" type="Label" parent="." unique_id=1959221258]
visible = false
layout_mode = 0
offset_left = 1096.0
offset_top = 12.0
offset_right = 1432.0
offset_bottom = 50.0
mouse_filter = 1
theme_type_variation = &"HighlightMedium"
text = "Version 0.0.0 is available"
horizontal_alignment = 2
vertical_alignment = 1
text_overrun_behavior = 3
[node name="SyncButton" type="Button" parent="." unique_id=1228313556]
layout_mode = 0
offset_left = 1450.0
+1
View File
@@ -38,6 +38,7 @@ func _ready() -> void:
sync_popup.sync_started.connect(_on_sync_started)
sync_popup.sync_finished.connect(_on_sync_finished)
quiz.server_changed.connect(search_popup.get_list_of_soundtracks)
quiz.server_changed.connect(top_bar.check_for_update)
quiz.event_logged.connect(log_popup.add_log_row)
statistics_view.soundtrack_selected.connect(soundtrack_stats_popup.show_soundtrack)
+31
View File
@@ -13,6 +13,7 @@ signal tab_selected(tab: StringName)
@onready var sync_button: Button = $SyncButton
@onready var debug_label: Label = $DebugLabel
@onready var update_label: Label = $UpdateLabel
@onready var quiz_tab: Button = $QuizTab
@onready var statistics_tab: Button = $StatisticsTab
@@ -27,6 +28,36 @@ func _ready() -> void:
$QRButton.pressed.connect(qr_pressed.emit)
quiz_tab.pressed.connect(tab_selected.emit.bind(&"quiz"))
statistics_tab.pressed.connect(tab_selected.emit.bind(&"statistics"))
check_for_update()
## Asks the server for the newest MusicPlayer release and tells the user when it is newer
## than this one.
func check_for_update() -> void:
MusicServerClient.fetch_latest_client_version(show_latest_version)
## Shows that [param latest] is available when it is newer than this version, and hides
## the message otherwise.
func show_latest_version(latest: Variant) -> void:
var newer: bool = latest is String && is_newer_version(latest, Settings.version)
update_label.visible = newer
if newer:
update_label.text = "Version %s is available" % latest
update_label.tooltip_text = "You have %s" % Settings.version
## Whether version [param latest] is newer than [param current], comparing numbers such as
## [code]1.10.0[/code] part by part. A leading "v" is ignored, and missing parts count as 0.
static func is_newer_version(latest: String, current: String) -> bool:
var latest_parts: PackedStringArray = latest.strip_edges().trim_prefix("v").split(".")
var current_parts: PackedStringArray = current.strip_edges().trim_prefix("v").split(".")
for i: int in maxi(latest_parts.size(), current_parts.size()):
var a: int = latest_parts[i].to_int() if i < latest_parts.size() else 0
var b: int = current_parts[i].to_int() if i < current_parts.size() else 0
if a != b:
return a > b
return false
## Shows [param tab] as the chosen tab, without emitting [signal tab_selected].
File diff suppressed because it is too large. Load diff
+1
View File
@@ -31,6 +31,7 @@ func before_test() -> void:
_server.respond_json("/music/all/order", ["Chrono Trigger", "Final Fantasy VI"])
_server.respond_json("/music/list", [])
_server.respond_json("/character/list", [])
_server.respond_json("/download", "1.0.0")
_server.respond_bytes("/music/rand", mp3)
_server.respond_bytes("/music/addQue", PackedByteArray())
_server.respond_json("/music/info", SONG_INFO[0])
+8
View File
@@ -77,6 +77,7 @@ static func make_server() -> FakeHttpTransport:
server.respond_json("/music/all", SOUNDTRACKS)
server.respond_json("/music/all/order", SOUNDTRACKS)
server.respond_json("/music/list", [])
server.respond_json("/download", "1.0.0")
var characters: Array[String] = character_names()
server.respond_json("/character/list", characters)
for character_name: String in characters:
@@ -243,6 +244,13 @@ func run(on_state: Callable) -> void:
sync_popup.close()
await _settle()
var top_bar: TopBar = _node("TopBar")
top_bar.show_latest_version("99.10.10")
await _settle()
await on_state.call("update_available", null)
top_bar.show_latest_version("1.0.0")
await _settle()
var statistics_view: StatisticsView = _node("StatisticsView")
_main.show_tab(&"statistics")
await _settle()
+1 -1
View File
@@ -29,7 +29,7 @@ const LOCKED_BY_SYNC: Array[String] = [
const TOP_BAR_CHILDREN: Array[String] = [
"TopPanelContainer", "Title", "SyncButton", "SettingsButton", "ShortcutsButton",
"DebugLabel",
"DebugLabel", "UpdateLabel",
"AboutButton", "QRButton", "QuizTab", "StatisticsTab",
]
+74
View File
@@ -0,0 +1,74 @@
extends MainWindowTestSuite
## The top bar tells the user when the server has a newer MusicPlayer release.
var _top_bar: TopBar
func before_test() -> void:
super()
_top_bar = _window.get_node("TopBar")
func test_no_message_when_this_is_the_newest_version() -> void:
assert_bool(_top_bar.update_label.visible).is_false()
assert_int(_server.count("/download")).is_equal(1)
func test_newer_release_shows_a_message() -> void:
_server.respond_json("/download", "99.0.0")
_top_bar.check_for_update()
assert_bool(_top_bar.update_label.is_visible_in_tree()).is_true()
assert_str(_top_bar.update_label.text).is_equal("Version 99.0.0 is available")
assert_str(_top_bar.update_label.tooltip_text).contains(Settings.version)
func test_message_fits_between_the_tabs_and_the_buttons() -> void:
_server.respond_json("/download", "99.10.10")
_top_bar.check_for_update()
await _runner.simulate_frames(1)
var label: Rect2 = _top_bar.update_label.get_global_rect()
var text_width: float = _top_bar.update_label.get_minimum_size().x
assert_float(text_width).is_less_equal(label.size.x)
assert_float(label.position.x).is_greater(
(_top_bar.get_node("StatisticsTab") as Control).get_global_rect().end.x)
assert_float(label.end.x).is_less(
(_top_bar.get_node("SyncButton") as Control).get_global_rect().position.x)
func test_message_stays_on_the_statistics_tab() -> void:
_server.respond_json("/download", "99.0.0")
_top_bar.check_for_update()
_window.show_tab(&"statistics")
assert_bool(_top_bar.update_label.is_visible_in_tree()).is_true()
func test_server_change_checks_again() -> void:
_server.respond_json("/download", "99.0.0")
_quiz.on_server_changed()
assert_bool(_top_bar.update_label.visible).is_true()
func test_failed_check_shows_nothing() -> void:
_server.respond_json("/download", "error", 502)
_top_bar.check_for_update()
assert_bool(_top_bar.update_label.visible).is_false()
func test_version_comparison() -> void:
assert_bool(TopBar.is_newer_version("2.0.1", "2.0.0")).is_true()
assert_bool(TopBar.is_newer_version("1.10.0", "1.9.0")).is_true()
assert_bool(TopBar.is_newer_version("v3.0", "2.9.9")).is_true()
assert_bool(TopBar.is_newer_version("2.1", "2.0.5")).is_true()
assert_bool(TopBar.is_newer_version("2.0.0", "2.0.0")).is_false()
assert_bool(TopBar.is_newer_version("2.0", "2.0.0")).is_false()
assert_bool(TopBar.is_newer_version("1.9.0", "2.0.0")).is_false()
assert_bool(TopBar.is_newer_version("1.9.9", "1.10.0")).is_false()
@@ -0,0 +1 @@
uid://dmm31450qjd8v