fixed saving & added first basic save creation menu
This commit is contained in:
@@ -4,16 +4,11 @@ extends Node
|
||||
var file: ConfigFile = ConfigFile.new()
|
||||
var save_path: String = "user://save.binary"
|
||||
|
||||
func get_section_name(res: Resource) -> String:
|
||||
return res.resource_name if res.resource_name != "" else res.get_class()
|
||||
|
||||
func save(res: Resource) -> bool:
|
||||
func save(res: SaveFile) -> bool:
|
||||
if not is_instance_valid(res):
|
||||
push_error("cannot save: invalid resource")
|
||||
return false
|
||||
|
||||
var section_name: String = get_section_name(res)
|
||||
|
||||
if FileAccess.file_exists(save_path) and file.load(save_path) != OK:
|
||||
printerr("Save file corrupted!")
|
||||
return false
|
||||
@@ -23,26 +18,25 @@ func save(res: Resource) -> bool:
|
||||
for property in res.get_property_list():
|
||||
if property.usage & PROPERTY_USAGE_STORAGE:
|
||||
var v_name: String = property.name
|
||||
file.set_value(section_name, v_name, res.get(v_name))
|
||||
file.set_value(res.save_name, v_name, res.get(v_name))
|
||||
|
||||
return file.save(save_path) == OK
|
||||
|
||||
func load(res: Resource) -> bool:
|
||||
func load(res: SaveFile) -> bool:
|
||||
if not FileAccess.file_exists(save_path):
|
||||
return true
|
||||
if file.load(save_path) != OK:
|
||||
printerr("Save file corrupted!")
|
||||
return false
|
||||
|
||||
var section_name: String = get_section_name(res)
|
||||
|
||||
var props := []
|
||||
for p in res.get_property_list():
|
||||
if p.usage & PROPERTY_USAGE_STORAGE:
|
||||
props.append(p.name)
|
||||
|
||||
for key in file.get_section_keys(section_name):
|
||||
for key in file.get_section_keys(res.save_name):
|
||||
if key in props:
|
||||
res.set(key, file.get_value(section_name, key))
|
||||
res.set(key, file.get_value(res.save_name, key))
|
||||
return true
|
||||
|
||||
func delete() -> void:
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
extends Node
|
||||
|
||||
var config: Config = Config.new()
|
||||
var config: Config = Config.new("config")
|
||||
|
||||
func _ready() -> void:
|
||||
Save.load(config)
|
||||
config.load()
|
||||
toggle_fullscreen()
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed("fullscreen"):
|
||||
config.fullscreen = !config.fullscreen
|
||||
Save.save(config)
|
||||
config.save()
|
||||
toggle_fullscreen()
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
|
||||
Reference in New Issue
Block a user