fix saving/loading debug buttons
This commit is contained in:
parent
be47641bab
commit
b4fc5c4906
4 changed files with 76 additions and 22 deletions
|
@ -76,5 +76,5 @@ text = "Load
|
||||||
"
|
"
|
||||||
|
|
||||||
[connection signal="interacted" from="Door/Interactable" to="Door" method="_on_interact"]
|
[connection signal="interacted" from="Door/Interactable" to="Door" method="_on_interact"]
|
||||||
[connection signal="pressed" from="Control/HBoxContainer/SaveButton" to="Control/Persistence" method="save"]
|
[connection signal="pressed" from="Control/HBoxContainer/SaveButton" to="Control/Persistence" method="save" binds= ["save1.sav"]]
|
||||||
[connection signal="pressed" from="Control/HBoxContainer/LoadButton" to="Control/Persistence" method="load"]
|
[connection signal="pressed" from="Control/HBoxContainer/LoadButton" to="Control/Persistence" method="load" binds= ["save1.sav"]]
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -14,11 +14,20 @@ static func get_instance_data(node: Node):
|
||||||
data = node.call(SaveMethod)
|
data = node.call(SaveMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func get_file(filename: String) -> Result:
|
||||||
|
if not filename.is_valid_filename():
|
||||||
|
return Result.err('invalid filename "%s"' % filename)
|
||||||
|
else:
|
||||||
|
var file_path = path.path_join(filename)
|
||||||
|
return Result.ok(file_path)
|
||||||
|
|
||||||
func save(filename: String) -> Result:
|
func save(filename: String) -> Result:
|
||||||
DirAccess.make_dir_recursive_absolute(path.get_base_dir())
|
DirAccess.make_dir_recursive_absolute(path.get_base_dir())
|
||||||
var file_path = path.path_join(filename)
|
var file_result = get_file(filename)
|
||||||
if not file_path.is_valid_filename():
|
if file_result.is_err():
|
||||||
return Result.err('invalid file path "%s"' % file_path)
|
push_error(file_result.unwrap_err())
|
||||||
|
return file_result
|
||||||
|
var file_path = file_result.unwrap()
|
||||||
var file = FileAccess.open(file_path, FileAccess.WRITE)
|
var file = FileAccess.open(file_path, FileAccess.WRITE)
|
||||||
var nodes = get_tree().get_nodes_in_group(group_name)
|
var nodes = get_tree().get_nodes_in_group(group_name)
|
||||||
|
|
||||||
|
@ -56,13 +65,21 @@ func _get_or_add(instance_data: Dictionary) -> Variant:
|
||||||
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
func load() -> Result:
|
func load(filename: String) -> Result:
|
||||||
if not FileAccess.file_exists(path):
|
var file_result = get_file(filename)
|
||||||
return Result.err('ENOENT: "%s" does not exist' % path)
|
if file_result.is_err():
|
||||||
|
push_error(file_result.unwrap_err())
|
||||||
|
return file_result
|
||||||
|
var file_path = file_result.unwrap()
|
||||||
|
|
||||||
|
if not FileAccess.file_exists(file_path):
|
||||||
|
var err = 'ENOENT: "%s" does not exist' % path
|
||||||
|
push_error(err)
|
||||||
|
return Result.err(err)
|
||||||
|
|
||||||
get_tree().call_group(group_name, OnBeforeLoadMethod)
|
get_tree().call_group(group_name, OnBeforeLoadMethod)
|
||||||
|
|
||||||
var file = FileAccess.open(path, FileAccess.READ)
|
var file = FileAccess.open(file_path, FileAccess.READ)
|
||||||
|
|
||||||
var length = file.get_length()
|
var length = file.get_length()
|
||||||
while file.get_position() < length:
|
while file.get_position() < length:
|
||||||
|
|
|
@ -6,6 +6,9 @@ class_name Player extends CharacterBody3D
|
||||||
@onready var input = $Input
|
@onready var input = $Input
|
||||||
@onready var interactor = $Interactor
|
@onready var interactor = $Interactor
|
||||||
|
|
||||||
|
var is_running: bool:
|
||||||
|
get: return velocity and input.is_running
|
||||||
|
|
||||||
var is_carrying_item = true
|
var is_carrying_item = true
|
||||||
var is_weapon_ready: bool:
|
var is_weapon_ready: bool:
|
||||||
get: return is_carrying_item and input.is_weapon_ready
|
get: return is_carrying_item and input.is_weapon_ready
|
||||||
|
@ -28,6 +31,7 @@ func move_and_rotate(_delta: float):
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
func rotate_toward_look(_delta: float):
|
func rotate_toward_look(_delta: float):
|
||||||
|
velocity = Vector3.ZERO
|
||||||
var target = input.get_look_target(global_position)
|
var target = input.get_look_target(global_position)
|
||||||
if target.is_some():
|
if target.is_some():
|
||||||
look_at(target.unwrap(), Vector3.UP, true)
|
look_at(target.unwrap(), Vector3.UP, true)
|
||||||
|
|
Loading…
Add table
Reference in a new issue