Add importer log
This commit is contained in:
parent
9c4d3fbc1c
commit
734ef61226
29
editor/import_log.gd
Normal file
29
editor/import_log.gd
Normal file
|
|
@ -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)
|
||||||
1
editor/import_log.gd.uid
Normal file
1
editor/import_log.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bdaspaenqgeoo
|
||||||
|
|
@ -53,6 +53,13 @@ func _ready() -> void:
|
||||||
_log.scroll_following = true
|
_log.scroll_following = true
|
||||||
_log.selection_enabled = true
|
_log.selection_enabled = true
|
||||||
add_child(_log)
|
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())
|
add_child(HSeparator.new())
|
||||||
var item_label := Label.new()
|
var item_label := Label.new()
|
||||||
item_label.text = "Objets, par catégorie :"
|
item_label.text = "Objets, par catégorie :"
|
||||||
|
|
@ -167,3 +174,4 @@ func _set_busy(value : bool) -> void:
|
||||||
|
|
||||||
func _print(msg : String) -> void:
|
func _print(msg : String) -> void:
|
||||||
_log.append_text(msg + "\n")
|
_log.append_text(msg + "\n")
|
||||||
|
PokeApiImportLog.append(msg)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue