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

+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].