started work on adding user data that stores array of subscribed leaderboards
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
[resource]
|
[resource]
|
||||||
script = ExtResource("1_bpthy")
|
script = ExtResource("1_bpthy")
|
||||||
gamemode_name = "HUB"
|
gamemode_name = "HUB"
|
||||||
|
estimated_difficulty = 0
|
||||||
win_conditions = null
|
win_conditions = null
|
||||||
survival_time = 160.0
|
survival_time = 160.0
|
||||||
money_lost_multiplier = 1.0
|
money_lost_multiplier = 1.0
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func _ready():
|
|||||||
GameGlobals.health = gamemode.start_health
|
GameGlobals.health = gamemode.start_health
|
||||||
|
|
||||||
#LOAD DATA
|
#LOAD DATA
|
||||||
SaveLoad.load_persistent_data()
|
SaveLoad.load_user_data()
|
||||||
|
|
||||||
if SaveLoad.data_cleared or !gamemode.load_save:
|
if SaveLoad.data_cleared or !gamemode.load_save:
|
||||||
refresh_scene()
|
refresh_scene()
|
||||||
@@ -149,11 +149,9 @@ func die():
|
|||||||
#record stats
|
#record stats
|
||||||
GameGlobals.money_penalty()
|
GameGlobals.money_penalty()
|
||||||
GameGlobals.weapon_penalty()
|
GameGlobals.weapon_penalty()
|
||||||
if SaveLoad.player_deaths:
|
if GameGlobals.player_deaths:
|
||||||
SaveLoad.player_deaths += 1
|
GameGlobals.player_deaths += 1
|
||||||
else:
|
SaveLoad.save_user_data()
|
||||||
SaveLoad.player_deaths = 1
|
|
||||||
SaveLoad.save_persistent_data()
|
|
||||||
SaveLoad.clear_save_game_data()
|
SaveLoad.clear_save_game_data()
|
||||||
var deadmsg = DEAD_ANNOUNCE.instantiate()
|
var deadmsg = DEAD_ANNOUNCE.instantiate()
|
||||||
get_parent().add_child(deadmsg)
|
get_parent().add_child(deadmsg)
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ var loading_gamemode
|
|||||||
var current_level = "res://scenes/HUBWORLD.tscn"
|
var current_level = "res://scenes/HUBWORLD.tscn"
|
||||||
var current_gamemode
|
var current_gamemode
|
||||||
|
|
||||||
#Leaderboard
|
#Persistent Data
|
||||||
|
var user_id = 0
|
||||||
|
var current_user_leaderboards = ["global"]
|
||||||
|
var all_user_leaderboards = []
|
||||||
|
|
||||||
var leaderboard_name = "Test"
|
var leaderboard_name = "Test"
|
||||||
var playlist_test
|
var playlist_test
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ var last_scene
|
|||||||
|
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
SaveLoad.load_persistent_data()
|
SaveLoad.load_persistent_data()
|
||||||
|
SaveLoad.load_user_data()
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
|||||||
@@ -13,16 +13,28 @@ var current_ammo
|
|||||||
var reserve_ammo
|
var reserve_ammo
|
||||||
|
|
||||||
## SAVE DATA PATHS
|
## SAVE DATA PATHS
|
||||||
var persistent_save_path = "user://persistent_data.save"
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
SignalBus.shot_fired.connect(shot_fired)
|
SignalBus.shot_fired.connect(shot_fired)
|
||||||
|
|
||||||
func save_user_data():
|
|
||||||
pass
|
|
||||||
|
|
||||||
func save_persistent_data():
|
func save_persistent_data():
|
||||||
var file = FileAccess.open(persistent_save_path, FileAccess.WRITE)
|
var file = FileAccess.open("user://persistent_data.save", FileAccess.WRITE)
|
||||||
|
file.store_var(GameGlobals.user_id)
|
||||||
|
var all_user_leaderboards_file = []
|
||||||
|
for i in GameGlobals.all_user_leaderboards:
|
||||||
|
all_user_leaderboards_file.append(GameGlobals.current_user_leaderboards)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
func load_persistent_data():
|
||||||
|
var file = FileAccess.open("user://persistent_data.save", FileAccess.WRITE)
|
||||||
|
GameGlobals.user_id = file.get_var()
|
||||||
|
GameGlobals.all_user_leaderboards = file.get_var()
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
func save_user_data():
|
||||||
|
var user_save_path = str("user://user_",GameGlobals.user_id,"_data.save")
|
||||||
|
var file = FileAccess.open(user_save_path, FileAccess.WRITE)
|
||||||
|
|
||||||
#cache data before saving and creating checksum in case it changes between data saving and checksum generating
|
#cache data before saving and creating checksum in case it changes between data saving and checksum generating
|
||||||
var leaderboard_name = GameGlobals.leaderboard_name
|
var leaderboard_name = GameGlobals.leaderboard_name
|
||||||
@@ -48,14 +60,15 @@ func save_persistent_data():
|
|||||||
file.store_var(GameGlobals.gun_ammo)
|
file.store_var(GameGlobals.gun_ammo)
|
||||||
file.store_var(GameGlobals.ammo_reserve)
|
file.store_var(GameGlobals.ammo_reserve)
|
||||||
file.store_var(GameGlobals.current_gun_index)
|
file.store_var(GameGlobals.current_gun_index)
|
||||||
var check_data = [persistent_save_path,leaderboard_name,money,deposited_money,health,high_score,player_deaths,shots_fired]
|
var check_data = [user_save_path,leaderboard_name,money,deposited_money,health,high_score,player_deaths,shots_fired]
|
||||||
file.store_var(HelperFuncs.checksum(check_data))
|
file.store_var(HelperFuncs.checksum(check_data))
|
||||||
|
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
func load_persistent_data():
|
func load_user_data():
|
||||||
if FileAccess.file_exists(persistent_save_path):
|
var user_save_path = str("user://user_",GameGlobals.user_id,"_data.save")
|
||||||
var file = FileAccess.open(persistent_save_path, FileAccess.READ)
|
if FileAccess.file_exists(user_save_path):
|
||||||
|
var file = FileAccess.open(user_save_path, FileAccess.READ)
|
||||||
GameGlobals.last_hit_path = file.get_var()
|
GameGlobals.last_hit_path = file.get_var()
|
||||||
GameGlobals.leaderboard_name = file.get_var()
|
GameGlobals.leaderboard_name = file.get_var()
|
||||||
GameGlobals.current_level = str(file.get_var())
|
GameGlobals.current_level = str(file.get_var())
|
||||||
@@ -79,7 +92,7 @@ func load_persistent_data():
|
|||||||
|
|
||||||
var checksum = file.get_var()
|
var checksum = file.get_var()
|
||||||
print("Checksum : ",checksum)
|
print("Checksum : ",checksum)
|
||||||
var check_data = [persistent_save_path,GameGlobals.leaderboard_name,money,deposited_money,health,high_score,player_deaths,shots_fired]
|
var check_data = [user_save_path,GameGlobals.leaderboard_name,money,deposited_money,health,high_score,player_deaths,shots_fired]
|
||||||
print("CHECK DATA : ",check_data)
|
print("CHECK DATA : ",check_data)
|
||||||
print("CHECKSUM CALC : ",HelperFuncs.checksum(check_data))
|
print("CHECKSUM CALC : ",HelperFuncs.checksum(check_data))
|
||||||
file.close()
|
file.close()
|
||||||
@@ -119,21 +132,6 @@ func save_game_data(level_name):
|
|||||||
file.close()
|
file.close()
|
||||||
save_persistent_data()
|
save_persistent_data()
|
||||||
|
|
||||||
func clear_save_game_data():
|
|
||||||
data_cleared = true
|
|
||||||
save_persistent_data()
|
|
||||||
|
|
||||||
func clear_persistent_data():
|
|
||||||
var file = FileAccess.open(persistent_save_path, FileAccess.WRITE)
|
|
||||||
file.store_var(null)
|
|
||||||
file.store_var(null)
|
|
||||||
file.store_var(null)
|
|
||||||
file.store_var(null)
|
|
||||||
file.store_var(null)
|
|
||||||
|
|
||||||
print("PERSISTENT DATA CLEARED")
|
|
||||||
file.close()
|
|
||||||
|
|
||||||
func check_save_game_exists(level_name):
|
func check_save_game_exists(level_name):
|
||||||
var game_save_path = str("user://",GameGlobals.leaderboard_name,"_",level_name,"_gamesave.save")
|
var game_save_path = str("user://",GameGlobals.leaderboard_name,"_",level_name,"_gamesave.save")
|
||||||
if FileAccess.file_exists(game_save_path):
|
if FileAccess.file_exists(game_save_path):
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func _on_body_entered(body: Node3D) -> void:
|
|||||||
#Save data
|
#Save data
|
||||||
if get_tree().current_scene.gamemode.load_save == true:
|
if get_tree().current_scene.gamemode.load_save == true:
|
||||||
SaveLoad.save_game_data(get_tree().current_scene.get_name())
|
SaveLoad.save_game_data(get_tree().current_scene.get_name())
|
||||||
SaveLoad.save_persistent_data()
|
SaveLoad.save_user_data()
|
||||||
get_tree().change_scene_to_file(scene_path)
|
get_tree().change_scene_to_file(scene_path)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user