feat : update backend

This commit is contained in:
2026-04-08 03:12:55 +08:00
parent 7e22f48c57
commit e222cc49ee
11 changed files with 619 additions and 935 deletions
+83
View File
@@ -25,6 +25,16 @@ signal profile_updated
@onready var avatar_popup := %AvatarSelectionPopup as PopupPanel
@onready var avatar_grid := %GridContainer as GridContainer
# Account Settings refs
@onready var acc_settings_dialog := %AccountSettingsDialog as AcceptDialog
@onready var old_pass_input := %OldPassInput as LineEdit
@onready var new_email_input := %NewEmailInput as LineEdit
@onready var new_pass_input := %NewPassInput as LineEdit
@onready var submit_cred_btn := %SubmitCredBtn as Button
@onready var tz_dropdown := %TzDropdown as OptionButton
@onready var save_tz_btn := %SaveTzBtn as Button
@onready var reset_stats_btn := %ResetStatsBtn as Button
# Loadout refs
@onready var char_left_btn := %CharLeftBtn as Button
@onready var char_right_btn := %CharRightBtn as Button
@@ -55,6 +65,7 @@ func _ready() -> void:
_connect_signals()
_load_profile_data()
_setup_avatar_grid()
_setup_account_settings_ui()
_load_loadout()
_setup_3d_preview()
@@ -71,6 +82,17 @@ func _connect_signals() -> void:
UserProfileManager.profile_updated.connect(_on_profile_updated)
UserProfileManager.profile_update_failed.connect(_on_profile_update_failed)
# Dynamically inject Account Settings button
var acc_settings_btn = Button.new()
acc_settings_btn.text = "Account Settings"
acc_settings_btn.custom_minimum_size = Vector2(0, 44)
acc_settings_btn.add_theme_font_override("font", load("res://assets/fonts/Nougat-ExtraBlack.ttf"))
acc_settings_btn.pressed.connect(_open_account_settings)
# Insert it before Logout button
var logout_idx = logout_btn.get_index()
logout_btn.get_parent().add_child(acc_settings_btn)
logout_btn.get_parent().move_child(acc_settings_btn, logout_idx)
# -------------------------------------------------------------------------
# Profile
@@ -279,6 +301,63 @@ func _on_link_account_pressed() -> void:
dialog.queue_free()
)
func _setup_account_settings_ui() -> void:
# Populate Timezone dropdown
tz_dropdown.clear()
for i in range(-12, 15):
var prefix = "+" if i >= 0 else ""
tz_dropdown.add_item("GMT " + prefix + str(i))
# Connect buttons
submit_cred_btn.pressed.connect(func():
status_label.text = "Updating credentials..."
var payload = {
"current_password": old_pass_input.text,
"new_email": new_email_input.text,
"new_password": new_pass_input.text
}
var result = await NakamaManager.client.rpc_async(NakamaManager.session, "change_credentials", JSON.stringify(payload))
if result.is_exception():
status_label.text = "Failed: " + result.get_exception().message
else:
status_label.text = "Credentials updated successfully!"
acc_settings_dialog.hide()
)
save_tz_btn.pressed.connect(func():
var selected_text = tz_dropdown.get_item_text(tz_dropdown.selected)
var res = await NakamaManager.client.update_account_async(NakamaManager.session, null, null, null, null, null, selected_text)
if res.is_exception():
status_label.text = "TZ Failed: " + res.get_exception().message
else:
status_label.text = "Timezone saved!"
)
reset_stats_btn.pressed.connect(func():
var conf = ConfirmationDialog.new()
conf.dialog_text = "Are you SURE you want to irreversibly wipe all your stats to 0?"
add_child(conf)
conf.popup_centered()
conf.confirmed.connect(func():
var r = await NakamaManager.client.rpc_async(NakamaManager.session, "reset_stats", "{}")
if not r.is_exception():
UserProfileManager.stats = {
"games_played": 0, "games_won": 0, "games_lost": 0, "total_score": 0, "high_score": 0, "play_time_minutes": 0
}
_load_profile_data()
status_label.text = "Stats wiped completely."
conf.queue_free()
acc_settings_dialog.hide()
)
)
func _open_account_settings() -> void:
old_pass_input.visible = not AuthManager.is_guest
old_pass_input.text = ""
new_email_input.text = ""
new_pass_input.text = ""
acc_settings_dialog.popup_centered()
func _on_logout_pressed() -> void:
AuthManager.logout()
get_tree().change_scene_to_file("res://scenes/ui/login_screen.tscn")
@@ -301,6 +380,10 @@ func show_panel() -> void:
_load_loadout()
_check_admin_visibility()
show()
if AuthManager.is_guest:
_on_link_account_pressed()
status_label.text = "Please link an email to save your progress permanently!"
func _check_admin_visibility() -> void:
admin_panel_btn.hide()