added firebase and rudimentary leaderboard support

This commit is contained in:
derek
2025-04-09 11:19:02 -05:00
parent ce08df66e6
commit 25eb9e725a
121 changed files with 4987 additions and 4 deletions

51
scripts/authentication.gd Normal file
View File

@@ -0,0 +1,51 @@
extends Control
@onready var email_edit: LineEdit = $VBoxContainer/email_edit
@onready var password_edit: LineEdit = $VBoxContainer/password_edit
@onready var state_label: Label = %StateLabel
func _ready() -> void:
Firebase.Auth.login_succeeded.connect(on_login_succeeded)
Firebase.Auth.login_failed.connect(on_login_failed)
Firebase.Auth.signup_succeeded.connect(on_signup_succeeded)
Firebase.Auth.signup_failed.connect(on_signup_failed)
if Firebase.Auth.check_auth_file():
state_label.text = "Logged in"
func _on_log_in_pressed() -> void:
var email = email_edit.text
var password = password_edit.text
Firebase.Auth.login_with_email_and_password(email,password)
state_label.text = "Logging In"
func _on_sign_up_pressed() -> void:
var email = email_edit.text
var password = password_edit.text
Firebase.Auth.signup_with_email_and_password(email,password)
state_label.text = "Signing Up"
func on_login_succeeded(auth):
print(auth)
state_label.text = "Login Success!"
Firebase.Auth.save_auth(auth)
visible = false
func on_signup_succeeded(auth):
print(auth)
state_label.text = "Signup Success!"
Firebase.Auth.save_auth(auth)
visible = false
func on_login_failed(error_code,message):
print(error_code)
print(message)
state_label.text = "Login failed. Error: %s" % message
func on_signup_failed(error_code,message):
print(error_code)
print(message)
state_label.text = "Signup failed. Error: %s" % message

View File

@@ -0,0 +1 @@
uid://cbmnj1dfgfwp5

27
scripts/leaderboard.gd Normal file
View 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")

View File

@@ -0,0 +1 @@
uid://ccnfikfg8kph1

View File

@@ -47,6 +47,7 @@ func load_persistent_data():
print("No file found...")
func save_user_data():
Leaderboard.save_leaderboard_data()
var user_save_path = str("user://user_",str(GameGlobals.user_id),"_",str(GameGlobals.all_user_leaderboards[GameGlobals.user_id][GameGlobals.last_leaderboard_id]),"_data.save")
var file = FileAccess.open(user_save_path, FileAccess.WRITE)