leaderboards can now be updated

This commit is contained in:
derek
2025-04-09 11:47:41 -05:00
parent 25eb9e725a
commit 2403fe0f33

View File

@@ -1,27 +1,38 @@
extends Node extends Node
var COLLECTION_ID = "leaderboard"
func save_leaderboard_data(): func save_leaderboard_data():
var auth = Firebase.Auth.auth var auth = Firebase.Auth.auth
var COLLECTION_ID = get_leaderboard_name()
if auth.localid: if auth.localid:
var collection: FirestoreCollection = Firebase.Firestore.collection(COLLECTION_ID) var collection: FirestoreCollection = Firebase.Firestore.collection(COLLECTION_ID)
var data : Dictionary = { var data : Dictionary = {
"user_name" : GameGlobals.user_names[GameGlobals.user_id], "user_name" : GameGlobals.user_names[GameGlobals.user_id],
"leaderboard" : GameGlobals.current_leaderboard_name, "leaderboard" : get_leaderboard_name(),
"high_score" : GameGlobals.high_score, "high_score" : GameGlobals.high_score,
"money" : GameGlobals.money, "money" : GameGlobals.money,
"deposited_money" : GameGlobals.deposited_money "deposited_money" : GameGlobals.deposited_money
} }
var task = await collection.get_doc(auth.localid) print("DATA: ",data)
if task: var document = await collection.get_doc(auth.localid)
await collection.update(FirestoreDocument.new(data)) 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: else:
await collection.add(auth.localid,data) await collection.add(auth.localid,data)
func load_leaderboard_data(): func load_leaderboard_data():
var auth = Firebase.Auth.auth var auth = Firebase.Auth.auth
var COLLECTION_ID = get_leaderboard_name()
if auth.localid: if auth.localid:
var collection: FirestoreCollection = Firebase.Firestore.collection(COLLECTION_ID) var collection: FirestoreCollection = Firebase.Firestore.collection(COLLECTION_ID)
var task = await collection.get_doc(auth.localid) var task = await collection.get_doc(auth.localid)
var result = task.get_value("high_score") 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])