leaderboards can now be updated
This commit is contained in:
@@ -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)
|
||||
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:
|
||||
await collection.update(FirestoreDocument.new(data))
|
||||
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])
|
||||
|
||||
Reference in New Issue
Block a user