Follow the GDScript style guide in every script
- Types on every parameter, return value and variable, and snake_case names (the player name limit is the constant MAX_NAME_LENGTH). - Spelling fixes: *_triggered, character_selected, separator, caught_errors. The server's catched_errors key stays as the server sends it. - Signals are connected with signal.connect() instead of by name. - Code is ordered signals, constants, exported vars, vars, @onready vars, functions, with @onready on one line and two blank lines between functions. - Every script starts with a ## description. Template comments, old LOC notes and commented-out code are gone, apart from the local play code. - Lines are at most 100 characters, apart from the local play path. - The screenshot tour turns off the blinking text cursor so pictures match.
This commit is contained in:
1 parent
674604425f
commit
a0428e3475
45 files changed
+580
-589
No files matched your search
+80
-92
@@ -1,79 +1,49 @@
|
||||
class_name SyncPopup
|
||||
extends BasePopup
|
||||
## Asks the server to sync its soundtracks with the music folder, shows the progress,
|
||||
## and then lists what was added, changed or removed.
|
||||
|
||||
@onready
|
||||
var sync_panel: Panel = %SyncPanel
|
||||
|
||||
@onready
|
||||
var sync_title_label: Label = %SyncTitleLabel
|
||||
|
||||
@onready
|
||||
var no_changes_label: Label = %NoChangesLabel
|
||||
|
||||
@onready
|
||||
var progress_hbox: HBoxContainer = %ProgressHBoxContainer
|
||||
|
||||
@onready
|
||||
var sync_hbox: HBoxContainer = %SyncHBoxContainer
|
||||
|
||||
@onready
|
||||
var sync_progress_bar: ProgressBar = %SyncProgressBar
|
||||
|
||||
@onready
|
||||
var soundtracks_added_vbox: VBoxContainer = %SoundtracksAddedVBox
|
||||
|
||||
@onready
|
||||
var soundtracks_added_separator: VSeparator = %SoundtracksAddedSeparator
|
||||
|
||||
@onready
|
||||
var soundtracks_readded_vbox: VBoxContainer = %SoundtracksReAddedVBox
|
||||
|
||||
@onready
|
||||
var soundtracks_readded_separator: VSeparator = %SoundtracksReAddedSeparator
|
||||
|
||||
@onready
|
||||
var soundtracks_changed_title_vbox: VBoxContainer = %SoundtracksChangedTitleVBox
|
||||
|
||||
@onready
|
||||
var soundtracks_changed_title_separator: VSeparator = %SoundtracksChangedTitleSeparator
|
||||
|
||||
@onready
|
||||
var soundtracks_changed_content_vbox: VBoxContainer = %SoundtracksChangedContentVBox
|
||||
|
||||
@onready
|
||||
var soundtracks_changed_content_separator: VSeparator = %SoundtracksChangedContentSeparator
|
||||
|
||||
@onready
|
||||
var soundtracks_removed_vbox: VBoxContainer = %SoundtracksRemovedVBox
|
||||
|
||||
@onready
|
||||
var soundtracks_removed_separator: VSeparator = %SoundtracksRemovedSeparator
|
||||
|
||||
@onready
|
||||
var catched_errors_vbox: VBoxContainer = %CatchedErrorsVBox
|
||||
|
||||
@onready
|
||||
var sync_time: Label = %SyncTime
|
||||
|
||||
@onready
|
||||
var sync_timer: Timer = %SyncTimer
|
||||
|
||||
@onready
|
||||
var restart_sync_button: Button = %RestartSyncButton
|
||||
|
||||
var changes: bool = false
|
||||
|
||||
var has_synced: bool = false
|
||||
## Emitted when the server has started syncing.
|
||||
|
||||
signal sync_started
|
||||
## Emitted when the sync is done and its result is shown.
|
||||
signal sync_finished
|
||||
|
||||
var changes: bool = false
|
||||
var has_synced: bool = false
|
||||
|
||||
@onready var sync_panel: Panel = %SyncPanel
|
||||
@onready var sync_title_label: Label = %SyncTitleLabel
|
||||
@onready var no_changes_label: Label = %NoChangesLabel
|
||||
@onready var progress_hbox: HBoxContainer = %ProgressHBoxContainer
|
||||
@onready var sync_hbox: HBoxContainer = %SyncHBoxContainer
|
||||
@onready var sync_progress_bar: ProgressBar = %SyncProgressBar
|
||||
@onready var soundtracks_added_vbox: VBoxContainer = %SoundtracksAddedVBox
|
||||
@onready var soundtracks_added_separator: VSeparator = %SoundtracksAddedSeparator
|
||||
@onready var soundtracks_readded_vbox: VBoxContainer = %SoundtracksReAddedVBox
|
||||
@onready var soundtracks_readded_separator: VSeparator = %SoundtracksReAddedSeparator
|
||||
@onready var soundtracks_changed_title_vbox: VBoxContainer = %SoundtracksChangedTitleVBox
|
||||
@onready var soundtracks_changed_title_separator: VSeparator = %SoundtracksChangedTitleSeparator
|
||||
@onready var soundtracks_changed_content_vbox: VBoxContainer = %SoundtracksChangedContentVBox
|
||||
@onready var soundtracks_changed_content_separator: VSeparator = %SoundtracksChangedContentSeparator
|
||||
@onready var soundtracks_removed_vbox: VBoxContainer = %SoundtracksRemovedVBox
|
||||
@onready var soundtracks_removed_separator: VSeparator = %SoundtracksRemovedSeparator
|
||||
@onready var caught_errors_vbox: VBoxContainer = %CaughtErrorsVBox
|
||||
@onready var sync_time: Label = %SyncTime
|
||||
@onready var sync_timer: Timer = %SyncTimer
|
||||
@onready var restart_sync_button: Button = %RestartSyncButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
sync_timer.timeout.connect(_on_sync_timeout)
|
||||
restart_sync_button.pressed.connect(start_sync)
|
||||
restart_sync_button.visible = false
|
||||
|
||||
func show_section_if_has_data(data: Variant, vbox: VBoxContainer, separator: VSeparator, header_text: String) -> bool:
|
||||
|
||||
## Lists [param data] under [param header_text] in [param vbox] and returns true, or hides
|
||||
## the column and its separator when there is nothing to list.
|
||||
func show_section_if_has_data(data: Variant, vbox: VBoxContainer, separator: VSeparator,
|
||||
header_text: String) -> bool:
|
||||
if data != null && data.size() > 0:
|
||||
vbox.visible = true
|
||||
make_list(data, vbox, header_text)
|
||||
@@ -83,9 +53,10 @@ func show_section_if_has_data(data: Variant, vbox: VBoxContainer, separator: VSe
|
||||
separator.visible = false
|
||||
return false
|
||||
|
||||
|
||||
func start_sync() -> void:
|
||||
GameLog.debug("start_sync")
|
||||
self.visible = true
|
||||
visible = true
|
||||
if has_synced:
|
||||
# Already synced, just show the results
|
||||
show_sync_result()
|
||||
@@ -98,6 +69,7 @@ func start_sync() -> void:
|
||||
if !Settings.currently_syncing:
|
||||
MusicServerClient.start_sync(sync_request_sent)
|
||||
|
||||
|
||||
func _on_sync_timeout() -> void:
|
||||
GameLog.debug("_on_sync_timeout!")
|
||||
var get_progress: Callable = func get_progress(data_received: Dictionary) -> void:
|
||||
@@ -111,38 +83,46 @@ func _on_sync_timeout() -> void:
|
||||
on_sync_finished(data_received)
|
||||
MusicServerClient.fetch_sync_progress(get_progress)
|
||||
|
||||
|
||||
func on_sync_finished(data_received: Dictionary) -> void:
|
||||
has_synced = true
|
||||
reset_sync_result()
|
||||
|
||||
if show_section_if_has_data(data_received.soundtracks_added, soundtracks_added_vbox, soundtracks_added_separator, "Added"):
|
||||
|
||||
if show_section_if_has_data(data_received.soundtracks_added, soundtracks_added_vbox,
|
||||
soundtracks_added_separator, "Added"):
|
||||
changes = true
|
||||
|
||||
if show_section_if_has_data(data_received.soundtracks_re_added, soundtracks_readded_vbox, soundtracks_readded_separator, "Re-added"):
|
||||
|
||||
if show_section_if_has_data(data_received.soundtracks_re_added, soundtracks_readded_vbox,
|
||||
soundtracks_readded_separator, "Re-added"):
|
||||
changes = true
|
||||
|
||||
if data_received.soundtracks_changed_title != null && data_received.soundtracks_changed_title.size() > 0:
|
||||
|
||||
var changed_titles: Variant = data_received.soundtracks_changed_title
|
||||
if changed_titles != null && changed_titles.size() > 0:
|
||||
changes = true
|
||||
Settings.delete_children(soundtracks_changed_title_vbox)
|
||||
make_header_label(soundtracks_changed_title_vbox, "Changed Title")
|
||||
var row: int = 0
|
||||
for old_soundtrack_title: String in data_received.soundtracks_changed_title:
|
||||
var new_soundtrack_title: String = data_received.soundtracks_changed_title[old_soundtrack_title]
|
||||
for old_soundtrack_title: String in changed_titles:
|
||||
var new_soundtrack_title: String = changed_titles[old_soundtrack_title]
|
||||
soundtracks_changed_title_vbox.add_child(make_soundtrack_row(
|
||||
old_soundtrack_title + "\nchanged title to\n" + new_soundtrack_title, row))
|
||||
row += 1
|
||||
soundtracks_changed_title_vbox.visible = true
|
||||
|
||||
if show_section_if_has_data(data_received.soundtracks_changed_content, soundtracks_changed_content_vbox, soundtracks_changed_content_separator, "Changed Content"):
|
||||
|
||||
if show_section_if_has_data(data_received.soundtracks_changed_content,
|
||||
soundtracks_changed_content_vbox, soundtracks_changed_content_separator,
|
||||
"Changed Content"):
|
||||
changes = true
|
||||
|
||||
if show_section_if_has_data(data_received.soundtracks_removed, soundtracks_removed_vbox, soundtracks_removed_separator, "Removed"):
|
||||
|
||||
if show_section_if_has_data(data_received.soundtracks_removed, soundtracks_removed_vbox,
|
||||
soundtracks_removed_separator, "Removed"):
|
||||
changes = true
|
||||
|
||||
|
||||
# The server's name for the errors it caught
|
||||
if data_received.catched_errors != null && data_received.catched_errors.size() > 0:
|
||||
catched_errors_vbox.visible = true
|
||||
make_list(data_received.catched_errors, catched_errors_vbox, "Errors")
|
||||
|
||||
caught_errors_vbox.visible = true
|
||||
make_list(data_received.catched_errors, caught_errors_vbox, "Errors")
|
||||
|
||||
# Separators go only between visible columns, not after the last one
|
||||
var visible_sections: Array = []
|
||||
if soundtracks_added_vbox.visible:
|
||||
@@ -155,11 +135,11 @@ func on_sync_finished(data_received: Dictionary) -> void:
|
||||
visible_sections.append("changed_content")
|
||||
if soundtracks_removed_vbox.visible:
|
||||
visible_sections.append("removed")
|
||||
|
||||
|
||||
# Show section separators only if there's a visible section after them
|
||||
for i in range(visible_sections.size()):
|
||||
var section = visible_sections[i]
|
||||
var separator_map = {
|
||||
for i: int in range(visible_sections.size()):
|
||||
var section: String = visible_sections[i]
|
||||
var separator_map: Dictionary = {
|
||||
"added": soundtracks_added_separator,
|
||||
"readded": soundtracks_readded_separator,
|
||||
"changed_title": soundtracks_changed_title_separator,
|
||||
@@ -171,10 +151,11 @@ func on_sync_finished(data_received: Dictionary) -> void:
|
||||
separator_map[section].visible = true
|
||||
else:
|
||||
separator_map[section].visible = false
|
||||
|
||||
|
||||
if !changes:
|
||||
no_changes_label.visible = true
|
||||
sync_time.text = "Total time: " + data_received.total_time if data_received.has("total_time") else ""
|
||||
sync_time.text = "Total time: " + data_received.total_time \
|
||||
if data_received.has("total_time") else ""
|
||||
Settings.currently_syncing = false
|
||||
sync_timer.stop()
|
||||
GameLog.debug("sync finished")
|
||||
@@ -182,9 +163,11 @@ func on_sync_finished(data_received: Dictionary) -> void:
|
||||
restart_sync_button.visible = true
|
||||
sync_finished.emit()
|
||||
|
||||
func list_visible(vbox: VBoxContainer, seperator: VSeparator) -> void:
|
||||
|
||||
func list_visible(vbox: VBoxContainer, separator: VSeparator) -> void:
|
||||
vbox.visible = true
|
||||
seperator.visible = true
|
||||
separator.visible = true
|
||||
|
||||
|
||||
func make_header_label(vbox: VBoxContainer, text: String) -> void:
|
||||
var label: Label = Label.new()
|
||||
@@ -194,6 +177,7 @@ func make_header_label(vbox: VBoxContainer, text: String) -> void:
|
||||
label.text = text
|
||||
vbox.add_child(label)
|
||||
|
||||
|
||||
# Items alternate between white and orange text as well as background shade
|
||||
func make_soundtrack_row(text: String, row: int) -> ListRow:
|
||||
var list_row: ListRow = ListRow.create(text, row, 18, HORIZONTAL_ALIGNMENT_CENTER)
|
||||
@@ -201,6 +185,7 @@ func make_soundtrack_row(text: String, row: int) -> ListRow:
|
||||
list_row.label.add_theme_color_override("font_color", Color(1, 0.5, 0))
|
||||
return list_row
|
||||
|
||||
|
||||
func reset_sync_result() -> void:
|
||||
sync_progress_bar.value = 0
|
||||
sync_time.text = ""
|
||||
@@ -216,7 +201,8 @@ func reset_sync_result() -> void:
|
||||
soundtracks_changed_content_separator.visible = false
|
||||
soundtracks_removed_vbox.visible = false
|
||||
soundtracks_removed_separator.visible = false
|
||||
catched_errors_vbox.visible = false
|
||||
caught_errors_vbox.visible = false
|
||||
|
||||
|
||||
func make_list(list: Array, vbox: VBoxContainer, text: String) -> void:
|
||||
Settings.delete_children(vbox)
|
||||
@@ -224,16 +210,18 @@ func make_list(list: Array, vbox: VBoxContainer, text: String) -> void:
|
||||
for row: int in list.size():
|
||||
vbox.add_child(make_soundtrack_row(list[row], row))
|
||||
|
||||
|
||||
func show_sync_result() -> void:
|
||||
sync_title_label.text = "Sync Result"
|
||||
progress_hbox.visible = false
|
||||
sync_hbox.visible = true
|
||||
restart_sync_button.visible = true
|
||||
|
||||
|
||||
|
||||
func show_sync_progress() -> void:
|
||||
sync_title_label.text = "Sync in Progress"
|
||||
progress_hbox.visible = true
|
||||
no_changes_label.visible = false
|
||||
sync_hbox.visible = false
|
||||
catched_errors_vbox.visible = false
|
||||
caught_errors_vbox.visible = false
|
||||
restart_sync_button.visible = false
|
||||
Reference in new issue
Block a user