mirror of
https://github.com/deunix-educ/aventuriers-des-mots.git
synced 2026-11-26 21:29:42 +01:00
Read corrupted save and settings files without engine error logs
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -70,7 +70,9 @@ func load_from_disk() -> void:
|
|||||||
if FileAccess.file_exists(SETTINGS_PATH):
|
if FileAccess.file_exists(SETTINGS_PATH):
|
||||||
var file := FileAccess.open(SETTINGS_PATH, FileAccess.READ)
|
var file := FileAccess.open(SETTINGS_PATH, FileAccess.READ)
|
||||||
if file != null:
|
if file != null:
|
||||||
raw = JSON.parse_string(file.get_as_text())
|
var json := JSON.new()
|
||||||
|
if json.parse(file.get_as_text()) == OK:
|
||||||
|
raw = json.data
|
||||||
var clean := AppSettings.sanitize(raw)
|
var clean := AppSettings.sanitize(raw)
|
||||||
volume = clean["volume"]
|
volume = clean["volume"]
|
||||||
music_volume = clean["music_volume"]
|
music_volume = clean["music_volume"]
|
||||||
|
|||||||
@@ -87,7 +87,12 @@ static func _read_raw_json(path: String) -> Variant:
|
|||||||
var text := file.get_as_text()
|
var text := file.get_as_text()
|
||||||
if text.strip_edges().is_empty():
|
if text.strip_edges().is_empty():
|
||||||
return null
|
return null
|
||||||
return JSON.parse_string(text)
|
# JSON.new().parse : un fichier corrompu est un cas normal (repli sur la
|
||||||
|
# copie de secours), pas une erreur moteur a journaliser.
|
||||||
|
var json := JSON.new()
|
||||||
|
if json.parse(text) != OK:
|
||||||
|
return null
|
||||||
|
return json.data
|
||||||
|
|
||||||
|
|
||||||
static func _copy_file(from_path: String, to_path: String) -> void:
|
static func _copy_file(from_path: String, to_path: String) -> void:
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ func test_corrupted_main_file_falls_back_to_backup() -> void:
|
|||||||
main_file.close()
|
main_file.close()
|
||||||
|
|
||||||
var read_back: Variant = SaveIO.read(profile_id, save_schema)
|
var read_back: Variant = SaveIO.read(profile_id, save_schema)
|
||||||
assert_engine_error("Parse JSON failed")
|
|
||||||
assert_not_null(read_back)
|
assert_not_null(read_back)
|
||||||
assert_eq(int(read_back["session_count"]), 1)
|
assert_eq(int(read_back["session_count"]), 1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user