From 2403fe0f33d4061bc169520d7092c1c5375815d5 Mon Sep 17 00:00:00 2001 From: derek Date: Wed, 9 Apr 2025 11:47:41 -0500 Subject: [PATCH] leaderboards can now be updated --- scripts/leaderboard.gd | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/scripts/leaderboard.gd b/scripts/leaderboard.gd index 370c754..a4eae83 100644 --- a/scripts/leaderboard.gd +++ b/scripts/leaderboard.gd @@ -1,27 +1,38 @@ extends Node -var COLLECTION_ID = "leaderboard" - func save_leaderboard_data(): var auth = Firebase.Auth.auth + var COLLECTION_ID = get_leaderboard_name() if auth.localid: var collection: FirestoreCollection = Firebase.Firestore.collection(COLLECTION_ID) var data : Dictionary = { "user_name" : GameGlobals.user_names[GameGlobals.user_id], - "leaderboard" : GameGlobals.current_leaderboard_name, + "leaderboard" : get_leaderboard_name(), "high_score" : GameGlobals.high_score, "money" : GameGlobals.money, "deposited_money" : GameGlobals.deposited_money } - var task = await collection.get_doc(auth.localid) - if task: - await collection.update(FirestoreDocument.new(data)) + print("DATA: ",data) + var document = await collection.get_doc(auth.localid) + if document: + for key in data.keys(): + document.add_or_update_field(key,data[key]) + var task = await collection.update(document) + if task: + print("Document updated successfully") + else: + print("Failed to update document") else: await collection.add(auth.localid,data) func load_leaderboard_data(): var auth = Firebase.Auth.auth + var COLLECTION_ID = get_leaderboard_name() if auth.localid: var collection: FirestoreCollection = Firebase.Firestore.collection(COLLECTION_ID) var task = await collection.get_doc(auth.localid) var result = task.get_value("high_score") + +func get_leaderboard_name(): + print("CURRENT LEADERBOARD ID",GameGlobals.all_user_leaderboards[GameGlobals.user_id][GameGlobals.last_leaderboard_id]) + return "leaderboard_" + str(GameGlobals.all_user_leaderboards[GameGlobals.user_id][GameGlobals.last_leaderboard_id])