feat: add dailylogin feature
This commit is contained in:
@@ -51,6 +51,15 @@ func _ready() -> void:
|
||||
_update_tab_visuals()
|
||||
_setup_3d_preview()
|
||||
|
||||
# Listen to profile and stats changes to keep the panel updated
|
||||
UserProfileManager.profile_updated.connect(_on_profile_or_stats_changed)
|
||||
UserProfileManager.stats_updated.connect(_on_profile_or_stats_changed)
|
||||
UserProfileManager.avatar_changed.connect(func(_url): _on_profile_or_stats_changed())
|
||||
|
||||
func _on_profile_or_stats_changed() -> void:
|
||||
if visible:
|
||||
_fetch_leaderboard_data()
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Show / Close
|
||||
# -------------------------------------------------------------------------
|
||||
@@ -97,6 +106,7 @@ func _fetch_leaderboard_data() -> void:
|
||||
var native_data = await _fetch_native_leaderboard()
|
||||
|
||||
if native_data.size() > 0:
|
||||
_apply_local_overrides(native_data)
|
||||
leaderboard_data = native_data
|
||||
_calculate_win_rates()
|
||||
status_label.text = ""
|
||||
@@ -156,6 +166,7 @@ func _fetch_via_rpc() -> void:
|
||||
if json.parse(result.payload) == OK:
|
||||
var data = json.get_data()
|
||||
if data.has("leaderboard") and data.leaderboard.size() > 0:
|
||||
_apply_local_overrides(data.leaderboard)
|
||||
leaderboard_data = data.leaderboard
|
||||
_calculate_win_rates()
|
||||
status_label.text = ""
|
||||
@@ -174,6 +185,28 @@ func _calculate_win_rates() -> void:
|
||||
var won = entry.get("games_won", 0)
|
||||
entry["win_rate"] = float(won) / float(played) * 100.0 if played > 0 else 0.0
|
||||
|
||||
func _apply_local_overrides(data: Array) -> void:
|
||||
if not NakamaManager.session:
|
||||
return
|
||||
var my_id = NakamaManager.session.user_id
|
||||
for entry in data:
|
||||
if entry.get("user_id") == my_id:
|
||||
entry["display_name"] = UserProfileManager.get_display_name(entry.get("display_name", "Unknown"))
|
||||
entry["avatar_url"] = UserProfileManager.get_avatar_url()
|
||||
entry["loadout_character"] = UserProfileManager.profile.get("loadout_character", entry.get("loadout_character", "Copper"))
|
||||
|
||||
var local_score = UserProfileManager.stats.get("high_score", 0)
|
||||
if local_score >= entry.get("high_score", 0):
|
||||
entry["high_score"] = local_score
|
||||
|
||||
var local_played = UserProfileManager.stats.get("games_played", 0)
|
||||
if local_played >= entry.get("games_played", 0):
|
||||
entry["games_played"] = local_played
|
||||
|
||||
var local_won = UserProfileManager.stats.get("games_won", 0)
|
||||
if local_won >= entry.get("games_won", 0):
|
||||
entry["games_won"] = local_won
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Sorting / Display
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user