From 734ef612266745fd9334ed9089a5f7eabcce781a Mon Sep 17 00:00:00 2001 From: TheThomaas Date: Sun, 4 Oct 2026 13:44:21 +0200 Subject: [PATCH] Add importer log --- editor/import_log.gd | 29 +++++++++++++++++++++++++++++ editor/import_log.gd.uid | 1 + editor/importer_dock.gd | 8 ++++++++ 3 files changed, 38 insertions(+) create mode 100644 editor/import_log.gd create mode 100644 editor/import_log.gd.uid diff --git a/editor/import_log.gd b/editor/import_log.gd new file mode 100644 index 0000000..b775616 --- /dev/null +++ b/editor/import_log.gd @@ -0,0 +1,29 @@ +# editor/import_log.gd +@tool +class_name PokeApiImportLog +extends RefCounted + +const LOG_PATH := "user://pokeapi_import.log" +const MAX_SIZE := 1 << 20 # 1 Mo : au-delà, on repart d'un fichier vide plutôt que de l'alourdir indéfiniment + +static func append(text : String) -> void: + var stamp := Time.get_datetime_string_from_system() + var plain := _strip_bbcode(text) + + if FileAccess.file_exists(LOG_PATH) and FileAccess.get_file_as_bytes(LOG_PATH).size() > MAX_SIZE: + var f := FileAccess.open(LOG_PATH, FileAccess.WRITE) + if f: f.close() + + var f := FileAccess.open(LOG_PATH, FileAccess.READ_WRITE if FileAccess.file_exists(LOG_PATH) else FileAccess.WRITE) + if f == null: return + f.seek_end() + f.store_line("[%s] %s" % [stamp, plain]) + f.close() + +static func _strip_bbcode(text : String) -> String: + var regex := RegEx.new() + regex.compile("\\[/?color[^\\]]*\\]") + return regex.sub(text, "", true) + +static func path() -> String: + return ProjectSettings.globalize_path(LOG_PATH) diff --git a/editor/import_log.gd.uid b/editor/import_log.gd.uid new file mode 100644 index 0000000..4774ae6 --- /dev/null +++ b/editor/import_log.gd.uid @@ -0,0 +1 @@ +uid://bdaspaenqgeoo diff --git a/editor/importer_dock.gd b/editor/importer_dock.gd index 4f3a335..ccdec8c 100644 --- a/editor/importer_dock.gd +++ b/editor/importer_dock.gd @@ -53,6 +53,13 @@ func _ready() -> void: _log.scroll_following = true _log.selection_enabled = true add_child(_log) + + var btn_log := Button.new() + btn_log.text = "Ouvrir le dossier du journal" + btn_log.pressed.connect(func() -> void: + OS.shell_show_in_file_manager(PokeApiImportLog.path())) + add_child(btn_log) + add_child(HSeparator.new()) var item_label := Label.new() item_label.text = "Objets, par catégorie :" @@ -167,3 +174,4 @@ func _set_busy(value : bool) -> void: func _print(msg : String) -> void: _log.append_text(msg + "\n") + PokeApiImportLog.append(msg)