checksum working with file name and file path verification
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
@tool
|
||||
extends Node
|
||||
|
||||
var letter_to_number = {
|
||||
"A": 1, "B": 2, "C": 3, "D": 4, "E": 5,
|
||||
"F": 6, "G": 7, "H": 8, "I": 9, "J": 10,
|
||||
"K": 11, "L": 12, "M": 13, "N": 14, "O": 15,
|
||||
"P": 16, "Q": 17, "R": 18, "S": 19, "T": 20,
|
||||
"U": 21, "V": 22, "W": 23, "X": 24, "Y": 25, "Z": 26
|
||||
}
|
||||
|
||||
## ANGLES
|
||||
|
||||
# Check if a colliding body is aligned within a given angle of the object
|
||||
@@ -52,7 +60,21 @@ func checksum(check_data):
|
||||
var index = 0.0
|
||||
|
||||
for data in check_data:
|
||||
if data == null:
|
||||
#get value from names
|
||||
if data is String:
|
||||
var stringnumber = 0
|
||||
var letter_index = 0
|
||||
for char in data:
|
||||
if char.is_valid_identifier():
|
||||
if letter_to_number.has(char.to_upper()):
|
||||
stringnumber += letter_to_number[char.to_upper()]
|
||||
|
||||
letter_index += 1
|
||||
|
||||
print("stringnumber : ",stringnumber)
|
||||
data = stringnumber + letter_index
|
||||
|
||||
if data == null or data ==0:
|
||||
data = TAU
|
||||
if data > div:
|
||||
div = data
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
extends Node3D
|
||||
class_name map
|
||||
class_name level
|
||||
|
||||
@export var map_name : String = "Map Name"
|
||||
@export var gamemode : gamemode
|
||||
@@ -254,5 +254,5 @@ func pickup_spawn(randomized):
|
||||
|
||||
func save_quit():
|
||||
SignalBus.emit_signal("player_exiting_tree")
|
||||
SaveLoad.save_game_data(level_name)
|
||||
SaveLoad.save_game_data(self.get_name())
|
||||
get_tree().quit()
|
||||
|
||||
@@ -2,15 +2,15 @@ extends Node
|
||||
|
||||
var game_loaded = false
|
||||
var high_score : int = 0
|
||||
var deposited_money
|
||||
var deposited_money : int = 0
|
||||
var money : int = 0
|
||||
var health
|
||||
var health : int = 0
|
||||
var held_guns = []
|
||||
var current_gun_index
|
||||
var gun_ammo = {}
|
||||
var ammo_reserve = {}
|
||||
var loading_gamemode
|
||||
var current_level
|
||||
var current_level = "res://scenes/HUBWORLD.tscn"
|
||||
var current_gamemode
|
||||
|
||||
#Leaderboard
|
||||
@@ -18,8 +18,8 @@ var leaderboard_name = "Test"
|
||||
var playlist_test
|
||||
|
||||
#Player Stats
|
||||
var player_deaths
|
||||
var shots_fired
|
||||
var player_deaths = 0
|
||||
var shots_fired = 0
|
||||
var last_hit_path
|
||||
var enemies_killed = 0
|
||||
|
||||
|
||||
@@ -16,13 +16,16 @@ func _ready() -> void:
|
||||
playlist_generator.load_playlist()
|
||||
print("leaderboard : ",GameGlobals.leaderboard_name)
|
||||
|
||||
|
||||
func _on_continue_pressed() -> void:
|
||||
var level
|
||||
var load_to_gamemode
|
||||
|
||||
if GameGlobals.leaderboard_name != leaderboard_name.text:
|
||||
GameGlobals.leaderboard_name = leaderboard_name.text
|
||||
playlist_generator.load_playlist()
|
||||
|
||||
playlist_generator.load_playlist()
|
||||
|
||||
|
||||
if GameGlobals.current_level == null:
|
||||
level = "res://scenes/HUBWORLD.tscn"
|
||||
|
||||
@@ -781,10 +781,10 @@ func enemy_hit():
|
||||
hit_indicator.play()
|
||||
|
||||
func enemy_killed():
|
||||
if SaveLoad.enemies_killed:
|
||||
SaveLoad.enemies_killed += 1
|
||||
if GameGlobals.enemies_killed:
|
||||
GameGlobals.enemies_killed += 1
|
||||
else:
|
||||
SaveLoad.enemies_killed = 1
|
||||
GameGlobals.enemies_killed = 1
|
||||
|
||||
SaveLoad.save_persistent_data()
|
||||
enemy_killed_audio.play()
|
||||
|
||||
@@ -55,7 +55,8 @@ func only_valid_chars(input_string: String) -> String:
|
||||
return valid_chars
|
||||
|
||||
func save_playlist(playlist):
|
||||
var playlist_path : String = "user://" + str(only_valid_chars(GameGlobals.leaderboard_name)) + "_playlist.save"
|
||||
var playlist_name = str(only_valid_chars(GameGlobals.leaderboard_name))
|
||||
var playlist_path : String = "user://"+ playlist_name + "_playlist.save"
|
||||
var file = FileAccess.open(playlist_path, FileAccess.WRITE)
|
||||
file.store_var(only_valid_chars(GameGlobals.leaderboard_name))
|
||||
file.store_var(playlist)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -194,8 +194,8 @@ func die():
|
||||
get_tree().get_root().add_child(particlespawn)
|
||||
|
||||
drop_loot(loot_amount)
|
||||
if SaveLoad.last_hit_path == str(get_path()):
|
||||
SaveLoad.last_hit_path = null
|
||||
if GameGlobals.last_hit_path == str(get_path()):
|
||||
GameGlobals.last_hit_path = null
|
||||
|
||||
SignalBus.emit_signal("enemy_killed")
|
||||
queue_free()
|
||||
|
||||
Reference in New Issue
Block a user