2023-11-23 04:41:13 +02:00
|
|
|
extends Node
|
|
|
|
|
2023-12-09 19:39:38 +02:00
|
|
|
const VariantSerializer = preload("res://lib/utils/variant_serializer.gd")
|
|
|
|
|
|
|
|
var file_url: String = "user://config.cfg"
|
2023-11-23 04:41:13 +02:00
|
|
|
|
|
|
|
func save_config(data: Dictionary):
|
|
|
|
var file := FileAccess.open(file_url, FileAccess.WRITE)
|
|
|
|
|
|
|
|
if file == null:
|
|
|
|
return
|
|
|
|
|
2023-12-09 19:39:38 +02:00
|
|
|
var json_data := JSON.stringify(VariantSerializer.stringify_value(data))
|
2023-11-23 04:41:13 +02:00
|
|
|
file.store_string(json_data)
|
|
|
|
|
|
|
|
func load_config():
|
|
|
|
var file := FileAccess.open(file_url, FileAccess.READ)
|
|
|
|
|
|
|
|
if file == null:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
var json_data := file.get_as_text()
|
2023-12-09 19:39:38 +02:00
|
|
|
var data = VariantSerializer.parse_value(JSON.parse_string(json_data))
|
2023-11-23 04:41:13 +02:00
|
|
|
|
|
|
|
return data
|