started work on save structures and data validation

This commit is contained in:
derek
2025-02-26 13:19:34 -06:00
parent bd991c21c9
commit 45246a6098
14 changed files with 108 additions and 50 deletions

View File

@@ -1,11 +1,6 @@
extends Node
## SAVE DATA
#PERSISTENT DATA
var last_hit_path
var player_deaths = 0
var enemies_killed = 0
var shots_fired = 0
#GAME DATA
var data_cleared
@@ -23,53 +18,51 @@ var persistent_save_path = "user://persistent_data.save"
func _ready() -> void:
SignalBus.shot_fired.connect(shot_fired)
if player_deaths == null:
player_deaths = 0
if enemies_killed == null:
enemies_killed = 0
func save_persistent_data():
var level_control = get_tree().current_scene
var player = level_control.player
var file = FileAccess.open(persistent_save_path, FileAccess.WRITE)
print("LAST HIT PATH " + str(last_hit_path))
file.store_var(last_hit_path)
file.store_var(player.velocity)
print("LAST HIT PATH " + str(GameGlobals.last_hit_path))
#cache data before saving and creating checksum in case it changes between data saving and checksum generating
var money = GameGlobals.money
var deposited_money = GameGlobals.deposited_money
var health = GameGlobals.health
var high_score = GameGlobals.high_score
var player_deaths = GameGlobals.player_deaths
var shots_fired = GameGlobals.shots_fired
file.store_var(GameGlobals.last_hit_path)
file.store_var(GameGlobals.leaderboard_name)
file.store_var(get_tree().current_scene.scene_file_path)
file.store_var(get_tree().current_scene.gamemode.resource_path)
file.store_var(GameGlobals.money)
file.store_var(GameGlobals.deposited_money)
file.store_var(GameGlobals.health)
file.store_var(GameGlobals.high_score)
file.store_var(money)
file.store_var(deposited_money)
file.store_var(health)
file.store_var(high_score)
file.store_var(player_deaths)
file.store_var(enemies_killed)
file.store_var(GameGlobals.enemies_killed)
file.store_var(shots_fired)
var held_guns = save_resource_path(GameGlobals.held_guns)
file.store_var(held_guns)
file.store_var(GameGlobals.gun_ammo)
file.store_var(GameGlobals.ammo_reserve)
file.store_var(GameGlobals.current_gun_index)
file.store_var(data_cleared)
var check_data = [money,deposited_money,health,high_score,player_deaths,shots_fired]
file.store_var(HelperFuncs.checksum(check_data))
file.close()
func load_persistent_data():
var level_control = get_tree().current_scene
if FileAccess.file_exists(persistent_save_path):
var file = FileAccess.open(persistent_save_path, FileAccess.READ)
last_hit_path = file.get_var()
player_velocity_cache = file.get_var()
GameGlobals.last_hit_path = file.get_var()
GameGlobals.leaderboard_name = file.get_var()
GameGlobals.current_level = str(file.get_var())
GameGlobals.current_gamemode = file.get_var()
GameGlobals.money = set_nulls_zero(file.get_var())
GameGlobals.deposited_money = set_nulls_zero(file.get_var())
GameGlobals.health = file.get_var()
GameGlobals.high_score = file.get_var()
player_deaths = set_nulls_zero(file.get_var())
enemies_killed = set_nulls_zero(file.get_var())
shots_fired = set_nulls_zero(file.get_var())
var money = set_nulls_zero(file.get_var())
var deposited_money = set_nulls_zero(file.get_var())
var health = file.get_var()
var high_score = file.get_var()
var player_deaths = set_nulls_zero(file.get_var())
GameGlobals.enemies_killed = set_nulls_zero(file.get_var())
var shots_fired = set_nulls_zero(file.get_var())
var held_guns_encoded = file.get_var()
@@ -81,13 +74,15 @@ func load_persistent_data():
if !get_tree().current_scene.is_in_group("ui"):
get_tree().current_scene.gun_spawn(GameGlobals.current_gun_index)
data_cleared = file.get_var()
var checksum = file.get_var()
var check_data = [money,deposited_money,health,high_score,player_deaths,shots_fired]
if checksum == HelperFuncs.checksum(check_data):
print("DATA VALID") #APPLY DATA AFTER
else:
print("DATA NOT VALID")
file.close()
else:
print("no data saved...")
last_hit_path = null
player_deaths = null
enemies_killed = null
func save_game_data(level_name):
@@ -229,4 +224,4 @@ func load_resource_path(array):
return []
func shot_fired():
shots_fired += 1 #null_data_check(shots_fired, 1)
GameGlobals.shots_fired += 1 #null_data_check(shots_fired, 1)