pokeapi_importer/editor/import_log.gd
2026-10-04 13:44:21 +02:00

30 lines
981 B
GDScript

# 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)