Added player save function to "persistent" tag, added UI elements
This commit is contained in:
@@ -20,7 +20,7 @@ var reserve_ammo
|
||||
|
||||
## SAVE DATA PATHS
|
||||
var persistent_save_path = "user://persistent_data.save"
|
||||
var game_save_path = "user://game_save_data.save"
|
||||
var game_save_path = "user://gamesave.save"
|
||||
|
||||
func _ready() -> void:
|
||||
if player_deaths == null:
|
||||
@@ -76,8 +76,6 @@ func save_game_data():
|
||||
reserve_ammo = level_control.ammo_reserve
|
||||
|
||||
#SAVE DATA
|
||||
file.store_var(player_loc)
|
||||
file.store_var(player_rot)
|
||||
file.store_var(player_health)
|
||||
file.store_var(player_money)
|
||||
file.store_var(held_guns)
|
||||
@@ -126,8 +124,6 @@ func load_save_game_data():
|
||||
|
||||
#GET DATA
|
||||
if !data_cleared:
|
||||
player_loc = file.get_var()
|
||||
player_rot = file.get_var()
|
||||
player_health = file.get_var()
|
||||
player_money = file.get_var()
|
||||
var held_guns_encoded = file.get_var()
|
||||
@@ -137,7 +133,7 @@ func load_save_game_data():
|
||||
reserve_ammo = file.get_var()
|
||||
var current_nodes = get_tree().get_nodes_in_group("persist")
|
||||
for i in current_nodes:
|
||||
if i.get_class() == "CharacterBody3D":
|
||||
if i.is_in_group("enemy"):
|
||||
i.quiet_remove()
|
||||
else:
|
||||
i.queue_free()
|
||||
@@ -151,13 +147,17 @@ func load_save_game_data():
|
||||
continue
|
||||
var node_data = json.data
|
||||
var new_object = load(node_data["filename"]).instantiate()
|
||||
print("NEW OBJECT : ",new_object)
|
||||
|
||||
get_node(node_data["parent"]).add_child(new_object)
|
||||
|
||||
|
||||
#apply transform if available
|
||||
if node_data["pos_x"] != null:
|
||||
new_object.position = Vector3(node_data["pos_x"],node_data["pos_y"],node_data["pos_z"])
|
||||
if node_data["rot_x"] != null:
|
||||
new_object.rotation = Vector3(node_data["rot_x"],node_data["rot_y"],node_data["rot_z"])
|
||||
print("NEW OBJECT PLACED AT ", new_object.position)
|
||||
|
||||
#apply other save data
|
||||
for i in node_data.keys():
|
||||
if i == "filename" or i == "pos_x" or i == "pos_y" or i == "pos_z":
|
||||
continue
|
||||
@@ -165,14 +165,13 @@ func load_save_game_data():
|
||||
|
||||
|
||||
#APPLY DATA
|
||||
player.global_position = player_loc
|
||||
player.global_rotation = player_rot
|
||||
level_control.health = player_health
|
||||
level_control.money = player_money
|
||||
level_control.held_guns = held_guns
|
||||
if player.gun:
|
||||
player.gun.queue_free()
|
||||
level_control.gun_spawn(current_gun)
|
||||
if current_gun != null:
|
||||
level_control.gun_spawn(current_gun)
|
||||
level_control.ammo_current = current_ammo
|
||||
level_control.ammo_reserve = reserve_ammo
|
||||
|
||||
|
||||
Reference in New Issue
Block a user