checksum working with file name and file path verification
This commit is contained in:
@@ -18,11 +18,14 @@ var persistent_save_path = "user://persistent_data.save"
|
||||
func _ready() -> void:
|
||||
SignalBus.shot_fired.connect(shot_fired)
|
||||
|
||||
func save_user_data():
|
||||
pass
|
||||
|
||||
func save_persistent_data():
|
||||
var file = FileAccess.open(persistent_save_path, FileAccess.WRITE)
|
||||
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 leaderboard_name = GameGlobals.leaderboard_name
|
||||
var money = GameGlobals.money
|
||||
var deposited_money = GameGlobals.deposited_money
|
||||
var health = GameGlobals.health
|
||||
@@ -31,8 +34,8 @@ func save_persistent_data():
|
||||
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(leaderboard_name)
|
||||
file.store_var(GameGlobals.current_level)
|
||||
file.store_var(money)
|
||||
file.store_var(deposited_money)
|
||||
file.store_var(health)
|
||||
@@ -45,7 +48,7 @@ func save_persistent_data():
|
||||
file.store_var(GameGlobals.gun_ammo)
|
||||
file.store_var(GameGlobals.ammo_reserve)
|
||||
file.store_var(GameGlobals.current_gun_index)
|
||||
var check_data = [money,deposited_money,health,high_score,player_deaths,shots_fired]
|
||||
var check_data = [persistent_save_path,leaderboard_name,money,deposited_money,health,high_score,player_deaths,shots_fired]
|
||||
file.store_var(HelperFuncs.checksum(check_data))
|
||||
|
||||
file.close()
|
||||
@@ -75,12 +78,16 @@ func load_persistent_data():
|
||||
get_tree().current_scene.gun_spawn(GameGlobals.current_gun_index)
|
||||
|
||||
var checksum = file.get_var()
|
||||
var check_data = [money,deposited_money,health,high_score,player_deaths,shots_fired]
|
||||
print("Checksum : ",checksum)
|
||||
var check_data = [persistent_save_path,GameGlobals.leaderboard_name,money,deposited_money,health,high_score,player_deaths,shots_fired]
|
||||
print("CHECK DATA : ",check_data)
|
||||
print("CHECKSUM CALC : ",HelperFuncs.checksum(check_data))
|
||||
file.close()
|
||||
await !file.is_open()
|
||||
if checksum == HelperFuncs.checksum(check_data):
|
||||
print("DATA VALID") #APPLY DATA AFTER
|
||||
else:
|
||||
print("DATA NOT VALID")
|
||||
file.close()
|
||||
else:
|
||||
print("no data saved...")
|
||||
|
||||
@@ -88,9 +95,8 @@ func load_persistent_data():
|
||||
func save_game_data(level_name):
|
||||
var level_control = get_tree().current_scene
|
||||
var player = level_control.player
|
||||
var game_save_path = str("user://",level_name,"_gamesave.save")
|
||||
var game_save_path = str("user://",GameGlobals.leaderboard_name,"_",level_name,"_gamesave.save")
|
||||
var file = FileAccess.open(game_save_path, FileAccess.WRITE)
|
||||
|
||||
#ASSIGN DATA TO VARIABLES
|
||||
data_cleared = false
|
||||
player_loc = player.global_position
|
||||
@@ -111,7 +117,6 @@ func save_game_data(level_name):
|
||||
file.store_line(json_string)
|
||||
|
||||
file.close()
|
||||
|
||||
save_persistent_data()
|
||||
|
||||
func clear_save_game_data():
|
||||
@@ -130,7 +135,7 @@ func clear_persistent_data():
|
||||
file.close()
|
||||
|
||||
func check_save_game_exists(level_name):
|
||||
var game_save_path = str("user://",level_name,"_gamesave.save")
|
||||
var game_save_path = str("user://",GameGlobals.leaderboard_name,"_",level_name,"_gamesave.save")
|
||||
if FileAccess.file_exists(game_save_path):
|
||||
return true
|
||||
else:
|
||||
@@ -139,7 +144,7 @@ func check_save_game_exists(level_name):
|
||||
func load_save_game_data(level_name):
|
||||
var level_control = get_tree().current_scene
|
||||
var player = level_control.player
|
||||
var game_save_path = str("user://",level_name,"_gamesave.save")
|
||||
var game_save_path = str("user://",GameGlobals.leaderboard_name,"_",level_name,"_gamesave.save")
|
||||
if FileAccess.file_exists(game_save_path):
|
||||
var file = FileAccess.open(game_save_path, FileAccess.READ)
|
||||
|
||||
@@ -224,4 +229,4 @@ func load_resource_path(array):
|
||||
return []
|
||||
|
||||
func shot_fired():
|
||||
GameGlobals.shots_fired += 1 #null_data_check(shots_fired, 1)
|
||||
GameGlobals.shots_fired += null_data_check(GameGlobals.shots_fired, 1)
|
||||
|
||||
Reference in New Issue
Block a user