added firebase and rudimentary leaderboard support
This commit is contained in:
27
scripts/leaderboard.gd
Normal file
27
scripts/leaderboard.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
extends Node
|
||||
|
||||
var COLLECTION_ID = "leaderboard"
|
||||
|
||||
func save_leaderboard_data():
|
||||
var auth = Firebase.Auth.auth
|
||||
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,
|
||||
"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))
|
||||
else:
|
||||
await collection.add(auth.localid,data)
|
||||
|
||||
func load_leaderboard_data():
|
||||
var auth = Firebase.Auth.auth
|
||||
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")
|
||||
Reference in New Issue
Block a user