diff --git a/MainWindow.gd b/MainWindow.gd index 1d98926..b9ed7b7 100644 --- a/MainWindow.gd +++ b/MainWindow.gd @@ -41,7 +41,7 @@ var popup_backdrop: PopupBackdrop func _ready() -> void: popup_backdrop = PopupBackdrop.add_to(self, _popups()) if OS.has_feature("macos"): - print("is_mac") + GameLog.debug("is_mac") top_bar.search_pressed.connect(show_search) top_bar.sync_pressed.connect(sync_soundtracks) top_bar.statistics_pressed.connect(get_statistics) @@ -60,7 +60,7 @@ func _ready() -> void: func _input(event: InputEvent) -> void: if event is InputEventKey and event.pressed: if event.alt_pressed && event.keycode == KEY_ENTER: - print("Alt + Enter pressed") + GameLog.debug("Alt + Enter pressed") Settings.fullscreen = !Settings.fullscreen if Settings.fullscreen == true: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) @@ -77,44 +77,44 @@ func _popups() -> Array[PopupWindow]: func show_search() -> void: - print("show_search") + GameLog.debug("show_search") search_view.toggle() func show_about() -> void: - print("show_about") + GameLog.debug("show_about") about_window.open() func show_shortcuts() -> void: - print("show_shortcuts") + GameLog.debug("show_shortcuts") shortcuts_window.open() func show_qr() -> void: - print("show_qr") + GameLog.debug("show_qr") qr_window.open() func get_statistics() -> void: - print("get_statistics") + GameLog.debug("get_statistics") statistic_popup.visible = true statistic_label.text = "Total amount of soundtracks in the playlist: " \ + str(search_view.soundtracks.size()) func sync_soundtracks() -> void: - print("sync_soundtracks") + GameLog.debug("sync_soundtracks") sync_window.start_sync() func _on_sync_started() -> void: - print("_on_sync_started") + GameLog.debug("_on_sync_started") top_bar.sync_button.disabled = false quiz.lock_for_sync() func _on_sync_finished() -> void: - print("_on_sync_finished") + GameLog.debug("_on_sync_finished") search_view.get_list_of_soundtracks() quiz.on_sync_finished() diff --git a/MusicPlayer.gd b/MusicPlayer.gd index 74de4fd..29cd549 100644 --- a/MusicPlayer.gd +++ b/MusicPlayer.gd @@ -91,7 +91,7 @@ func play_or_pause() -> void: audio_player.stream_paused = false song_finished = false audio_player.seek(playback_position) - print("continue") + GameLog.debug("continue") progress_slider.max_value = round(stream.get_length()) if Settings.hide_ticks: progress_slider.tick_count = 0 @@ -184,7 +184,7 @@ func play_song(song: AudioStream) -> void: music_time_label.text = format_text(progress_slider.value, stream.get_length()) func play_song_object(song_object_no: int) -> void: - print("play_song_object") + GameLog.debug("play_song_object") if audio_player.is_playing(): audio_player.stop() await get_tree().create_timer(0.5).timeout @@ -204,7 +204,7 @@ func play_song_object(song_object_no: int) -> void: Playlist.set_currently_playing_song(song_object_no) Playlist.unset_is_playing() if !Settings.hide_next_track: - print("Show answer now!!") + GameLog.debug("Show answer now!!") Playlist.song_is_answered(song_object_no) Playlist.song_has_played(song_object_no) Playlist.song_is_playing(song_object_no) @@ -229,8 +229,8 @@ func load_mp3(_path: String) -> AudioStream: func play_local_song() -> void: if songs: local_path = songs[0] - print(local_path) - print(FileAccess.file_exists(local_path)) + GameLog.debug(local_path) + GameLog.debug(FileAccess.file_exists(local_path)) play_sound(load_mp3(local_path)) func sound_test_local() -> void: diff --git a/Player.gd b/Player.gd index a5ad97f..83cb1ac 100644 --- a/Player.gd +++ b/Player.gd @@ -61,7 +61,7 @@ func change_character() -> void: change_character_clicked.emit() func new_character_selected(character_texture: ImageTexture) -> void: - print("Back in player list with new") + GameLog.debug("Back in player list with new") player_object.character = character_texture set_player_character() diff --git a/QRWindow.gd b/QRWindow.gd index d13392a..336b1e8 100644 --- a/QRWindow.gd +++ b/QRWindow.gd @@ -19,7 +19,7 @@ func _ready() -> void: var url: String = Settings.default_path + "/search" qr_code_rect.data = url url_label.text = qr_code_rect.data - print("QR code generated for: ", url) + GameLog.debug("QR code generated for: ", url) func open() -> void: super() diff --git a/SearchWindow.gd b/SearchWindow.gd index d29d3ed..f56fc72 100644 --- a/SearchWindow.gd +++ b/SearchWindow.gd @@ -39,7 +39,7 @@ func close() -> void: super() func search() -> void: - print(search_bar.text) + GameLog.debug(search_bar.text) var search_text: String = search_bar.text if search_text == "": @@ -153,7 +153,7 @@ func check_if_soundtrack_exists(soundtrack: String) -> bool: return soundtrack_exists func get_list_of_soundtracks() -> void: - print("get_list_of_soundtracks") + GameLog.debug("get_list_of_soundtracks") var handle_soundtracks: Callable = func handle_soundtracks(array) -> void: if typeof(array) == TYPE_ARRAY: # Reuse existing labels: hide all and add to pool @@ -164,7 +164,7 @@ func get_list_of_soundtracks() -> void: for soundtrack: String in soundtracks: add_soundtrack_reuse(soundtrack) else: - print("Unexpected data") + GameLog.warning("Unexpected data") MusicServerClient.fetch_all_soundtracks_ordered(handle_soundtracks) ## Replaces the searchable soundtracks and precomputes their search forms. diff --git a/SettingsWindow.gd b/SettingsWindow.gd index bc70a6e..e9f927b 100644 --- a/SettingsWindow.gd +++ b/SettingsWindow.gd @@ -203,22 +203,22 @@ func increase_hide_for_seconds() -> void: hide_for_seconds_label.text = str(Settings.hide_for_seconds) func select_server(new_server: int) -> void: - print("select_server") + GameLog.debug("select_server") Settings.default_path = select_server_button.get_item_text(new_server) Settings.selected_server = new_server - print("Settings.default_path: " + Settings.default_path) - print("Settings.selected_server: " + str(Settings.selected_server)) - print("new_server: " + str(new_server)) - print("select_server_button.get_item_text(new_server): " + select_server_button.get_item_text(new_server)) + GameLog.debug("Settings.default_path: " + Settings.default_path) + GameLog.debug("Settings.selected_server: " + str(Settings.selected_server)) + GameLog.debug("new_server: " + str(new_server)) + GameLog.debug("select_server_button.get_item_text(new_server): " + select_server_button.get_item_text(new_server)) server_changed.emit() func set_selected_server(new_server: int) -> void: - print("set_selected_server") + GameLog.debug("set_selected_server") select_server_button.select(new_server) Settings.default_path = select_server_button.get_item_text(new_server) Settings.selected_server = new_server - print("Settings.default_path: " + Settings.default_path) - print("Settings.selected_server: " + str(Settings.selected_server)) - print("new_server: " + str(new_server)) - print("select_server_button.get_item_text(new_server): " + select_server_button.get_item_text(new_server)) + GameLog.debug("Settings.default_path: " + Settings.default_path) + GameLog.debug("Settings.selected_server: " + str(Settings.selected_server)) + GameLog.debug("new_server: " + str(new_server)) + GameLog.debug("select_server_button.get_item_text(new_server): " + select_server_button.get_item_text(new_server)) server_changed.emit() diff --git a/SongObject.gd b/SongObject.gd index 48d9290..a390df3 100644 --- a/SongObject.gd +++ b/SongObject.gd @@ -42,12 +42,12 @@ func get_song_info() -> String: return "??? - ???" func add_point(player_id: String) -> void: - print("add_point") + GameLog.debug("add_point") if !players_given_point.has(player_id): players_given_point.append(player_id) func remove_point(player_id: String) -> void: - print("remove_point") + GameLog.debug("remove_point") players_given_point.erase(player_id) func _to_string() -> String: diff --git a/character.gd b/character.gd index 3de4ac0..3f19408 100644 --- a/character.gd +++ b/character.gd @@ -22,10 +22,11 @@ func set_character_name(character_name: String) -> void: var img: Image = Image.new() var err: Error = img.load_png_from_buffer(image) if err != OK: - print(err) + GameLog.debug("Character image is not a PNG, trying JPG: ", error_string(err)) var err2: Error = img.load_jpg_from_buffer(image) if err2 != OK: - print(err2) + GameLog.warning("Could not load the image for ", character_name, ": ", + error_string(err2)) var new_image: ImageTexture = ImageTexture.new() new_image.set_image(img) character_image.custom_minimum_size = Vector2(200, 100) @@ -42,5 +43,5 @@ func _input(event: InputEvent) -> void: if event is InputEventMouseButton && event.is_pressed() && event.get_button_index() == MOUSE_BUTTON_LEFT: var evLocal: InputEvent = make_input_local(event) if Rect2(Vector2(0, 0), panel.size).has_point(evLocal.position): - print(character_name_label.text) + GameLog.debug(character_name_label.text) new_character_selected.emit(character_image.texture) diff --git a/game_log.gd b/game_log.gd new file mode 100644 index 0000000..6c79935 --- /dev/null +++ b/game_log.gd @@ -0,0 +1,21 @@ +extends Node +## Writes messages about what the game is doing, for finding problems. +## +## Registered as the [code]GameLog[/code] autoload. Use [method debug] instead of +## [code]print()[/code]: the messages show in debug builds and the editor, and are left +## out of released games. Problems the player may notice go through [method warning]. + + +## Prints [param parts] joined together, like [code]print()[/code], in debug builds only. +func debug(...parts: Array) -> void: + if OS.is_debug_build(): + print(_join(parts)) + + +## Reports a problem in the editor's debugger and the console, in every build. +func warning(...parts: Array) -> void: + push_warning(_join(parts)) + + +func _join(parts: Array) -> String: + return "".join(parts.map(func(part: Variant) -> String: return str(part))) diff --git a/game_log.gd.uid b/game_log.gd.uid new file mode 100644 index 0000000..9dde246 --- /dev/null +++ b/game_log.gd.uid @@ -0,0 +1 @@ +uid://c37mlo6svk03q diff --git a/inspiration_list.gd b/inspiration_list.gd index 5de3937..40a08ef 100644 --- a/inspiration_list.gd +++ b/inspiration_list.gd @@ -49,12 +49,12 @@ func _process(delta: float) -> void: ## Fetches every soundtrack from the server and shows them. func load_from_server() -> void: - print("load_from_server") + GameLog.debug("load_from_server") var populate_list: Callable = func populate_list(array) -> void: if typeof(array) == TYPE_ARRAY: show_soundtracks(array) else: - print("Unexpected data") + GameLog.warning("Unexpected data") MusicServerClient.fetch_all_soundtracks(populate_list) diff --git a/new_character_select.gd b/new_character_select.gd index fd720b9..42bebbf 100644 --- a/new_character_select.gd +++ b/new_character_select.gd @@ -22,18 +22,18 @@ func _ready() -> void: close_timer.timeout.connect(_on_close_timeout) func _on_close_timeout() -> void: - print("_on_close_timeout!") + GameLog.debug("_on_close_timeout!") Settings.character_select_open = false close_timer.stop() func load_characters() -> void: - print("load_characters") + GameLog.debug("load_characters") var fetch_character_list: Callable = func fetch_character_list(list) -> void: - print("fetch_character_list") + GameLog.debug("fetch_character_list") Settings.delete_children(character_grid) if typeof(list) == TYPE_ARRAY: for character_name: String in list: - print("character_name ", character_name) + GameLog.debug("character_name ", character_name) var character_box: Character = character.instantiate() character_grid.add_child(character_box) character_box.custom_minimum_size = Vector2(235, 145) @@ -43,7 +43,7 @@ func load_characters() -> void: MusicServerClient.fetch_character_list(fetch_character_list) func show_grid(player_name: String) -> void: - print("show_grid") + GameLog.debug("show_grid") title_label.text = "Select character for " + player_name close_timer.stop() open() @@ -55,7 +55,7 @@ func close() -> void: Settings.character_select_open = false func _on_character_selected(texture: ImageTexture) -> void: - print("_on_character_selected") + GameLog.debug("_on_character_selected") # Not close(): character_select_open stays true until close_timer fires, so the click # that picked the character does not also select a song behind it self.visible = false diff --git a/players_panel.gd b/players_panel.gd index 363b50a..1b1f84c 100644 --- a/players_panel.gd +++ b/players_panel.gd @@ -41,7 +41,7 @@ func _ready() -> void: ## Shows or hides the row for adding players, and the buttons for removing them. func add_players() -> void: - print("add_players") + GameLog.debug("add_players") Settings.edit_players = !Settings.edit_players add_player_container.visible = !add_player_container.visible new_player_name_field.grab_focus() @@ -50,7 +50,7 @@ func add_players() -> void: ## Adds a player with the name in the name field, unless it is empty or there are ## already as many players as there can be. func add_player() -> void: - print("add_player") + GameLog.debug("add_player") if new_player_name_field.text != "" && Settings.player_array.size() < Settings.MAX_NUMBER_OF_PLAYERS: var new_player_object: PlayerObject = PlayerObject.new(new_player_name_field.text) new_player_name_field.text = "" @@ -62,11 +62,11 @@ func add_player() -> void: ## Shows the players in [code]Settings.player_array[/code] again, e.g. after their ## points were reset. func reload() -> void: - print("load_players") + GameLog.debug("load_players") Settings.delete_children(players_list_container) var counter: int = 0 for player_object: PlayerObject in Settings.player_array: - print(player_object.player_name) + GameLog.debug(player_object.player_name) var new_player: Player = _player_row.instantiate() new_player.player_object = player_object @@ -84,7 +84,7 @@ func _on_change_character_clicked(row: Player, player_name: String) -> void: func _on_player_removed(player_object: PlayerObject) -> void: - print("_on_player_removed ", player_object.player_name) + GameLog.debug("_on_player_removed ", player_object.player_name) Settings.player_array.erase(player_object) reload() player_removed.emit(player_object) diff --git a/playlist.gd b/playlist.gd index cebc19b..08dec57 100644 --- a/playlist.gd +++ b/playlist.gd @@ -35,10 +35,10 @@ func song_is_answered(song_no: int = currently_playing_song) -> void: # Nothing is playing yet (-1); a negative index would answer the last, unplayed song if song_no < 0 || song_no >= song_object_array.size(): return - print("show_answer_pressed song_object: ", song_object_array[song_no]._to_string()) + GameLog.debug("show_answer_pressed song_object: ", song_object_array[song_no]._to_string()) song_object_array[song_no].is_answered = true if Settings.add_to_stats: - print("add to stats: ", song_no) + GameLog.debug("add to stats: ", song_no) MusicServerClient.mark_song_played(song_no) func add_to_playlist(new_song_object: SongObject) -> void: diff --git a/project.godot b/project.godot index 6929309..4e4c0ce 100644 --- a/project.godot +++ b/project.godot @@ -22,6 +22,7 @@ config/icon="res://icon.svg" [autoload] +GameLog="*res://game_log.gd" Settings="*res://Settings.gd" Playlist="*res://playlist.gd" MusicServerClient="*res://music_server_client.gd" diff --git a/quiz.gd b/quiz.gd index 770625c..e12f0aa 100644 --- a/quiz.gd +++ b/quiz.gd @@ -69,7 +69,7 @@ var popup_backdrop: PopupBackdrop func _ready() -> void: popup_backdrop = PopupBackdrop.add_to(self, _popups()) if OS.has_feature("debug"): - print("is_debug") + GameLog.debug("is_debug") debug_label.visible = true Settings.is_debug = true settings_window.set_winning_score(5) @@ -103,19 +103,19 @@ func _ready() -> void: func _input(event: InputEvent) -> void: if event is InputEventKey and event.pressed: if event.alt_pressed && event.keycode == KEY_UP: - print("Alt + UP pressed") + GameLog.debug("Alt + UP pressed") music_player_container.change_volume(0.05) if event.alt_pressed && event.keycode == KEY_DOWN: - print("Alt + DOWN pressed") + GameLog.debug("Alt + DOWN pressed") music_player_container.change_volume(-0.05) if event.alt_pressed && event.ctrl_pressed && event.keycode == KEY_LEFT: - print("Ctrl + Alt + LEFT pressed") + GameLog.debug("Ctrl + Alt + LEFT pressed") music_player_container.restart() elif event.alt_pressed && event.keycode == KEY_LEFT: - print("Alt + LEFT pressed") + GameLog.debug("Alt + LEFT pressed") music_player_container.seek(-5) if event.alt_pressed && event.keycode == KEY_RIGHT: - print("Alt + RIGHT pressed") + GameLog.debug("Alt + RIGHT pressed") music_player_container.seek(5) @@ -135,27 +135,27 @@ func on_sync_finished() -> void: ## Reloads the soundtracks, playlist and characters from the server. func refresh_from_server() -> void: - print("refresh_from_server") + GameLog.debug("refresh_from_server") inspiration_list.load_from_server() reset_playlist() new_character_select.load_characters() func _on_server_changed() -> void: - print("_on_server_changed") + GameLog.debug("_on_server_changed") refresh_from_server() reset_points() server_changed.emit() func show_answer_pressed() -> void: - print("show_answer_pressed") + GameLog.debug("show_answer_pressed") Playlist.song_is_answered() update_song_list() func play_next_song() -> void: - print("play_next_song ", Playlist.latest_played_song) + GameLog.debug("play_next_song ", Playlist.latest_played_song) if Playlist.first_song_played: Playlist.set_latest_played_song() Playlist.first_song_played = true @@ -183,7 +183,7 @@ func _on_song_added() -> void: func update_song_list() -> void: - print("update_song_list") + GameLog.debug("update_song_list") if Playlist.currently_playing_song >= 0: now_playing.show_song(Playlist.get_current_soundtrack_title(), Playlist.get_current_song_title()) @@ -191,10 +191,10 @@ func update_song_list() -> void: func song_object_clicked(song_no: int) -> void: - print("Clicked Song Object: ", Playlist.song_object_array[song_no].to_string()) + GameLog.debug("Clicked Song Object: ", Playlist.song_object_array[song_no].to_string()) if Settings.character_select_open == false: if Playlist.get_song(song_no) == null: - print("has no song, need to download") + GameLog.debug("has no song, need to download") var song_downloaded: Callable = func song_downloaded(body: PackedByteArray) -> void: var sound: AudioStream = AudioStreamMP3.new() sound.data = body @@ -202,12 +202,12 @@ func song_object_clicked(song_no: int) -> void: music_player_container.play_song_object(song_no) MusicServerClient.fetch_song(song_no, song_downloaded) else: - print("song already downloaded") + GameLog.debug("song already downloaded") music_player_container.play_song_object(song_no) func reset_playlist() -> void: - print("reset_playlist") + GameLog.debug("reset_playlist") var playlist_reset_done: Callable = func playlist_reset_done() -> void: Playlist.reset_playlist() song_loader.load_song_list() @@ -216,7 +216,7 @@ func reset_playlist() -> void: func reset_points() -> void: - print("reset_points") + GameLog.debug("reset_points") for player_objects: PlayerObject in Settings.player_array: player_objects.reset_points() players_panel.reload() @@ -227,7 +227,7 @@ func reset_points() -> void: func show_settings() -> void: - print("show_settings") + GameLog.debug("show_settings") settings_window.open() @@ -242,7 +242,7 @@ func _on_player_added(new_player_object: PlayerObject) -> void: func _on_point_given(player_object: PlayerObject) -> void: - print("_on_point_given") + GameLog.debug("_on_point_given") event_logged.emit(player_object.player_name + " got a point") if Playlist.currently_playing_song >= 0: Playlist.add_point(player_object.id) @@ -254,7 +254,7 @@ func _on_make_point_given_sound() -> void: func _on_point_taken(player_object: PlayerObject) -> void: - print("_on_point_taken") + GameLog.debug("_on_point_taken") event_logged.emit(player_object.player_name + " lost a point") music_player_container.play_sound_effect(preload("res://sounds/itemequip.wav")) if Playlist.currently_playing_song >= 0: @@ -263,7 +263,7 @@ func _on_point_taken(player_object: PlayerObject) -> void: func _on_player_won(player_object: PlayerObject) -> void: - print("_on_player_won") + GameLog.debug("_on_player_won") winner_window.show_winner(player_object) music_player_container.play_song(preload("res://sounds/winning.mp3")) # Songs played after the game is won don't count towards the statistics @@ -278,14 +278,14 @@ func _on_player_removed(player_object: PlayerObject) -> void: func _on_player_change_character_clicked(new_player: Player, player_name: String) -> void: - print("_on_player_change_character_clicked") + GameLog.debug("_on_player_change_character_clicked") current_player = new_player - print("Change character for: " + player_name) + GameLog.debug("Change character for: " + player_name) new_character_select.show_grid(player_name) func _on_new_character_selected(character_texture: ImageTexture) -> void: - print("_on_new_character_selected") + GameLog.debug("_on_new_character_selected") current_player.new_character_selected(character_texture) @@ -298,7 +298,7 @@ func open() -> void: func _on_file_dialog_dir_selected(path: String) -> void: - print(path) + GameLog.debug(path) dir_contents(path) @@ -311,13 +311,13 @@ func dir_contents(path: String) -> void: var soundtracks: Array = [] while file_name != "": if dir.current_is_dir(): - #print("Found directory: " + file_name) + #GameLog.debug("Found directory: " + file_name) soundtracks.append(file_name) else: - #print("Found file: " + file_name) + #GameLog.debug("Found file: " + file_name) if file_name.ends_with(".mp3"): songs.append(path + "/" + file_name) file_name = dir.get_next() inspiration_list.show_soundtracks(soundtracks) else: - print("An error occurred when trying to access the path.") + GameLog.warning("An error occurred when trying to access the path.") diff --git a/song_loader.gd b/song_loader.gd index 613347e..6fba366 100644 --- a/song_loader.gd +++ b/song_loader.gd @@ -20,7 +20,7 @@ var retry_seconds: float = 5.0 ## Loads the songs already in the server playlist, then starts preloading new ones. ## Preloading waits for the list, because loading the list clears the playlist. func load_song_list() -> void: - print("load_song_list") + GameLog.debug("load_song_list") var song_list_fetched: Callable = func song_list_fetched(data) -> void: Playlist.clear_song_list() if typeof(data) == TYPE_ARRAY: @@ -33,7 +33,7 @@ func load_song_list() -> void: new_song_object.has_played = true Playlist.add_to_playlist(new_song_object) elif data != null: - print("Unexpected data") + GameLog.warning("Unexpected data") Playlist.update_last_played_song() song_list_loaded.emit() fetch_song_if_idle() @@ -42,7 +42,7 @@ func load_song_list() -> void: ## Starts downloading one more song, which keeps downloading until the cache is full. func fetch_song() -> void: - print("fetch_song") + GameLog.debug("fetch_song") Playlist.is_song_downloading = true _download_random_song(SongObject.new()) @@ -64,7 +64,7 @@ func fill_cache() -> void: # the server and the game keep the same songs in their playlists. func _download_random_song(new_song_object: SongObject) -> void: var song_downloaded: Callable = func song_downloaded(body: PackedByteArray) -> void: - print("song_downloaded") + GameLog.debug("song_downloaded") var sound: AudioStream = AudioStreamMP3.new() sound.data = body new_song_object.song = sound @@ -80,11 +80,11 @@ func _add_song_to_queue(new_song_object: SongObject) -> void: func _fetch_song_info(new_song_object: SongObject) -> void: var song_info_fetched: Callable = func song_info_fetched(data_received: Dictionary) -> void: - print("song_info_fetched") + GameLog.debug("song_info_fetched") new_song_object.song_number = data_received.SongNo new_song_object.soundtrack_title = data_received.Soundtrack new_song_object.song_title = data_received.Song - print("new_song_object: ", new_song_object.to_string()) + GameLog.debug("new_song_object: ", new_song_object.to_string()) Playlist.add_to_playlist(new_song_object) if Playlist.should_preload_more_songs(): fetch_song() @@ -96,5 +96,5 @@ func _fetch_song_info(new_song_object: SongObject) -> void: func _retry_later(step: Callable) -> void: - print("Song download failed, retrying in %s seconds" % retry_seconds) + GameLog.warning("Song download failed, retrying in %s seconds" % retry_seconds) get_tree().create_timer(retry_seconds).timeout.connect(step) diff --git a/sync_window.gd b/sync_window.gd index 34869cb..652890a 100644 --- a/sync_window.gd +++ b/sync_window.gd @@ -83,7 +83,7 @@ func show_section_if_has_data(data: Variant, vbox: VBoxContainer, separator: VSe return false func start_sync() -> void: - print("start_sync") + GameLog.debug("start_sync") self.visible = true if has_synced: # Already synced, just show the results @@ -98,10 +98,10 @@ func start_sync() -> void: MusicServerClient.start_sync(sync_request_sent) func _on_sync_timeout() -> void: - print("_on_sync_timeout!") + GameLog.debug("_on_sync_timeout!") var get_progress: Callable = func get_progress(data_received: Dictionary) -> void: - print("get_progress") - print("data_received: ", data_received) + GameLog.debug("get_progress") + GameLog.debug("data_received: ", data_received) if data_received != null: if data_received.has("progress"): sync_progress_bar.value = int(data_received.progress) @@ -176,7 +176,7 @@ func on_sync_finished(data_received: Dictionary) -> void: sync_time.text = "Total time: " + data_received.total_time if data_received.has("total_time") else "" Settings.currently_syncing = false sync_timer.stop() - print("sync finished") + GameLog.debug("sync finished") show_sync_result() restart_sync_button.visible = true sync_finished.emit() diff --git a/tests/unit/test_game_log.gd b/tests/unit/test_game_log.gd new file mode 100644 index 0000000..975b874 --- /dev/null +++ b/tests/unit/test_game_log.gd @@ -0,0 +1,23 @@ +extends GdUnitTestSuite +## GameLog joins its arguments like print() does. + + +func test_joins_parts_without_spaces_like_print() -> void: + assert_str(GameLog._join(["Song ", 3, " of ", 10.5])).is_equal("Song 3 of 10.5") + + +func test_joins_any_kind_of_value() -> void: + assert_str(GameLog._join([null, true, [1, 2], {"a": 1}])) \ + .is_equal("true[1, 2]{ \"a\": 1 }") + + +func test_no_parts_gives_an_empty_line() -> void: + assert_str(GameLog._join([])).is_empty() + + +func test_debug_takes_any_number_of_arguments() -> void: + GameLog.debug() + GameLog.debug("one") + GameLog.debug("one", 2, Vector2.ONE) + # Reaching this line means none of the calls failed + assert_bool(true).is_true() diff --git a/tests/unit/test_game_log.gd.uid b/tests/unit/test_game_log.gd.uid new file mode 100644 index 0000000..335c06d --- /dev/null +++ b/tests/unit/test_game_log.gd.uid @@ -0,0 +1 @@ +uid://delnqk8yt0hes