34 lines
955 B
GDScript
34 lines
955 B
GDScript
class_name OptionsClass
|
|
extends Node
|
|
|
|
var username: String = "DefaultUsername"
|
|
var ip_address: String = "127.0.0.1"
|
|
var data_collection: bool = false
|
|
|
|
func _ready() -> void:
|
|
load_options()
|
|
|
|
func save_options() -> void:
|
|
var save_data: String = JSON.stringify({
|
|
"username": username,
|
|
"ip_address": ip_address,
|
|
"data_collection": data_collection,
|
|
})
|
|
|
|
var file: FileAccess = FileAccess.open("user://options.json", FileAccess.WRITE)
|
|
|
|
if file and !file.store_string(save_data):
|
|
print("Failed to save settings.")
|
|
|
|
func load_options() -> void:
|
|
var file: FileAccess = FileAccess.open("user://options.json", FileAccess.READ)
|
|
|
|
if file:
|
|
var save_data: Dictionary = JSON.parse_string(file.get_as_text())
|
|
if save_data:
|
|
if save_data.has("username"):
|
|
username = save_data.username
|
|
if save_data.has("ip_address"):
|
|
ip_address = save_data.ip_address
|
|
if save_data.has("data_collection"):
|
|
data_collection = save_data.data_collection
|