Show display names everywhere accountId was shown in GameScreen
Server: - PlayerState: add DisplayName property (populated from identity DB) - PlayerStateDto: add DisplayName field (falls back to truncated ID) - GameEngine.ToDto: include DisplayName in player DTO - GameReadyHandler: resolve display names from identity DB after state initialization so every subsequent state push carries them Client: - Game.gd: add get_display_name(account_id) helper — reads displayName from player state, falls back to substr(0,8) - game_screen.gd: replace all 5 pid/eid/elim_id.substr(0,8) UI sites with Game.get_display_name() — HUD opp name, turn order strip, game-over outcome list, discard scope selector, elimination dialog - Turn order strip chips: use resolved display name; add mouse_filter STOP + tooltip_text showing SP/ST/Hand/Deck for opponent chips on hover Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -123,6 +123,18 @@ func get_opponent() -> Dictionary:
|
|||||||
return opps[0] if not opps.is_empty() else {}
|
return opps[0] if not opps.is_empty() else {}
|
||||||
|
|
||||||
|
|
||||||
|
## Returns the display name for an account ID, using the name embedded in the game state.
|
||||||
|
## Falls back to the first 8 characters of the ID if no name is available.
|
||||||
|
func get_display_name(account_id: String) -> String:
|
||||||
|
if account_id.is_empty(): return "?"
|
||||||
|
for p: Dictionary in state.get("players", []):
|
||||||
|
if str(p.get("accountId", "")) == account_id:
|
||||||
|
var dn : String = str(p.get("displayName", ""))
|
||||||
|
if not dn.is_empty(): return dn
|
||||||
|
break
|
||||||
|
return account_id.substr(0, min(8, account_id.length()))
|
||||||
|
|
||||||
|
|
||||||
## Returns true when it is the local player's turn.
|
## Returns true when it is the local player's turn.
|
||||||
func is_my_turn() -> bool:
|
func is_my_turn() -> bool:
|
||||||
return str(state.get("activePlayerAccountId", "")) == Auth.user_id
|
return str(state.get("activePlayerAccountId", "")) == Auth.user_id
|
||||||
|
|||||||
@@ -2934,7 +2934,7 @@ func _show_player_panel(scope: String, ownership: String) -> void:
|
|||||||
if show_enemy:
|
if show_enemy:
|
||||||
for ep: Dictionary in Game.get_enemy_players():
|
for ep: Dictionary in Game.get_enemy_players():
|
||||||
var eid : String = str(ep.get("accountId", ""))
|
var eid : String = str(ep.get("accountId", ""))
|
||||||
var ename : String = eid.substr(0, 8)
|
var ename : String = Game.get_display_name(eid)
|
||||||
_add_player_option(vbox, ename, eid, scope)
|
_add_player_option(vbox, ename, eid, scope)
|
||||||
|
|
||||||
panel.add_child(vbox)
|
panel.add_child(vbox)
|
||||||
@@ -3231,8 +3231,7 @@ func _update_hud(state: Dictionary) -> void:
|
|||||||
_st_lbl.text = "ST: %d" % int(my.get("currentSt", 0))
|
_st_lbl.text = "ST: %d" % int(my.get("currentSt", 0))
|
||||||
_deck_lbl.text = "Deck: %d" % int(my.get("deckCount", 0))
|
_deck_lbl.text = "Deck: %d" % int(my.get("deckCount", 0))
|
||||||
|
|
||||||
_opp_name_lbl.text = Game.opponent_name if not Game.opponent_name.is_empty() \
|
_opp_name_lbl.text = Game.get_display_name(str(opp.get("accountId", "")))
|
||||||
else str(opp.get("accountId", "Opponent")).substr(0, 8)
|
|
||||||
_opp_hand_lbl.text = "Hand: %d" % int(opp.get("handCount", 0))
|
_opp_hand_lbl.text = "Hand: %d" % int(opp.get("handCount", 0))
|
||||||
_opp_deck_lbl.text = "Deck: %d" % int(opp.get("deckCount", 0))
|
_opp_deck_lbl.text = "Deck: %d" % int(opp.get("deckCount", 0))
|
||||||
|
|
||||||
@@ -3291,10 +3290,12 @@ func _rebuild_turn_order_strip(state: Dictionary) -> void:
|
|||||||
var eliminated : bool = bool(p.get("isEliminated", false))
|
var eliminated : bool = bool(p.get("isEliminated", false))
|
||||||
var team_idx : int = int(p.get("teamIndex", -1))
|
var team_idx : int = int(p.get("teamIndex", -1))
|
||||||
var hex_str : String = str(team_colors.get(str(team_idx), ""))
|
var hex_str : String = str(team_colors.get(str(team_idx), ""))
|
||||||
|
var display : String = "You" if is_me else Game.get_display_name(pid)
|
||||||
|
|
||||||
var chip := PanelContainer.new()
|
var chip := PanelContainer.new()
|
||||||
chip.custom_minimum_size = Vector2(72, 36)
|
chip.custom_minimum_size = Vector2(72, 36)
|
||||||
chip.self_modulate = Color(1, 1, 1, 0.3 if eliminated else (0.95 if is_active else 0.6))
|
chip.self_modulate = Color(1, 1, 1, 0.3 if eliminated else (0.95 if is_active else 0.6))
|
||||||
|
chip.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||||
|
|
||||||
# Team-color left border via StyleBoxFlat.
|
# Team-color left border via StyleBoxFlat.
|
||||||
var style := StyleBoxFlat.new()
|
var style := StyleBoxFlat.new()
|
||||||
@@ -3307,11 +3308,11 @@ func _rebuild_turn_order_strip(state: Dictionary) -> void:
|
|||||||
chip.add_theme_stylebox_override("panel", style)
|
chip.add_theme_stylebox_override("panel", style)
|
||||||
|
|
||||||
var lbl := Label.new()
|
var lbl := Label.new()
|
||||||
var display : String = "You" if is_me else pid.substr(0, 8)
|
|
||||||
lbl.text = ("★ " if is_active else "") + display + (" ✗" if eliminated else "")
|
lbl.text = ("★ " if is_active else "") + display + (" ✗" if eliminated else "")
|
||||||
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||||
lbl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
lbl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||||
lbl.add_theme_font_size_override("font_size", 10)
|
lbl.add_theme_font_size_override("font_size", 10)
|
||||||
|
lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||||
if is_active:
|
if is_active:
|
||||||
lbl.add_theme_color_override("font_color", Color(1.0, 0.9, 0.3))
|
lbl.add_theme_color_override("font_color", Color(1.0, 0.9, 0.3))
|
||||||
elif eliminated:
|
elif eliminated:
|
||||||
@@ -3319,6 +3320,15 @@ func _rebuild_turn_order_strip(state: Dictionary) -> void:
|
|||||||
elif is_me:
|
elif is_me:
|
||||||
lbl.add_theme_color_override("font_color", Color(0.5, 1.0, 0.5))
|
lbl.add_theme_color_override("font_color", Color(0.5, 1.0, 0.5))
|
||||||
|
|
||||||
|
# Hover tooltip showing player specs (opponents only).
|
||||||
|
if not is_me:
|
||||||
|
var sp : int = int(p.get("currentSp", 0))
|
||||||
|
var st : int = int(p.get("currentSt", 0))
|
||||||
|
var hand : int = int(p.get("handCount", 0))
|
||||||
|
var deck : int = int(p.get("deckCount", 0))
|
||||||
|
chip.tooltip_text = "%s\nSP: %d ST: %d\nHand: %d Deck: %d" % [
|
||||||
|
display, sp, st, hand, deck]
|
||||||
|
|
||||||
chip.add_child(lbl)
|
chip.add_child(lbl)
|
||||||
_turn_order_strip.add_child(chip)
|
_turn_order_strip.add_child(chip)
|
||||||
|
|
||||||
@@ -3414,7 +3424,7 @@ func _on_game_over(winner_id: String, win_condition: String,
|
|||||||
var oc : String = str(po.get("outcome", "?"))
|
var oc : String = str(po.get("outcome", "?"))
|
||||||
var rd : int = int(po.get("rankDelta", 0))
|
var rd : int = int(po.get("rankDelta", 0))
|
||||||
var sign : String = "+" if rd >= 0 else ""
|
var sign : String = "+" if rd >= 0 else ""
|
||||||
var label: String = "You" if pid == Auth.user_id else pid.substr(0, 8)
|
var label: String = "You" if pid == Auth.user_id else Game.get_display_name(pid)
|
||||||
outcome_lines.append("%s: %s (%s%d)" % [label, oc, sign, rd])
|
outcome_lines.append("%s: %s (%s%d)" % [label, oc, sign, rd])
|
||||||
_go_rank_lbl.text = "[%s]
|
_go_rank_lbl.text = "[%s]
|
||||||
" % win_condition + "
|
" % win_condition + "
|
||||||
@@ -3495,7 +3505,7 @@ func _on_player_eliminated(session_id: String, elim_id: String, _seat_idx: int,
|
|||||||
"You have been eliminated!
|
"You have been eliminated!
|
||||||
You can continue watching the game as a spectator."
|
You can continue watching the game as a spectator."
|
||||||
if is_me
|
if is_me
|
||||||
else "Player %s has been eliminated from the game!" % elim_id.substr(0, 8))
|
else "Player %s has been eliminated from the game!" % Game.get_display_name(elim_id))
|
||||||
var dlg := AcceptDialog.new()
|
var dlg := AcceptDialog.new()
|
||||||
dlg.title = "Player Eliminated"
|
dlg.title = "Player Eliminated"
|
||||||
dlg.dialog_text = msg
|
dlg.dialog_text = msg
|
||||||
|
|||||||
@@ -1047,17 +1047,20 @@ public static class GameEngine
|
|||||||
var isSelf = p.AccountId == viewerAccountId;
|
var isSelf = p.AccountId == viewerAccountId;
|
||||||
|
|
||||||
return new PlayerStateDto(
|
return new PlayerStateDto(
|
||||||
AccountId : Guid.Parse(p.AccountId),
|
AccountId : Guid.Parse(p.AccountId),
|
||||||
HandCount : p.Hand.Count,
|
DisplayName : !string.IsNullOrEmpty(p.DisplayName)
|
||||||
DeckCount : p.Deck.Count,
|
? p.DisplayName
|
||||||
Hand : isSelf ? p.Hand.Select(ToCardDto) : null,
|
: p.AccountId.Length >= 8 ? p.AccountId[..8] : p.AccountId,
|
||||||
Field : p.Field.Select(ToCardDto),
|
HandCount : p.Hand.Count,
|
||||||
Discard : p.Discard.Select(ToCardDto),
|
DeckCount : p.Deck.Count,
|
||||||
ArchSpirit : p.ArchSpirit != null ? ToCardDto(p.ArchSpirit) : null,
|
Hand : isSelf ? p.Hand.Select(ToCardDto) : null,
|
||||||
CurrentSp : p.CurrentSp,
|
Field : p.Field.Select(ToCardDto),
|
||||||
CurrentSt : p.CurrentSt,
|
Discard : p.Discard.Select(ToCardDto),
|
||||||
SeatIndex : p.SeatIndex,
|
ArchSpirit : p.ArchSpirit != null ? ToCardDto(p.ArchSpirit) : null,
|
||||||
TeamIndex : p.TeamIndex,
|
CurrentSp : p.CurrentSp,
|
||||||
|
CurrentSt : p.CurrentSt,
|
||||||
|
SeatIndex : p.SeatIndex,
|
||||||
|
TeamIndex : p.TeamIndex,
|
||||||
IsEliminated: p.IsEliminated);
|
IsEliminated: p.IsEliminated);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -547,6 +547,7 @@ public sealed record GameStateDto(
|
|||||||
|
|
||||||
public sealed record PlayerStateDto(
|
public sealed record PlayerStateDto(
|
||||||
Guid AccountId,
|
Guid AccountId,
|
||||||
|
string DisplayName, // resolved display name; never empty (falls back to truncated ID)
|
||||||
int HandCount, // always shown; actual cards visible only to self
|
int HandCount, // always shown; actual cards visible only to self
|
||||||
int DeckCount,
|
int DeckCount,
|
||||||
IEnumerable<CardInstanceDto>? Hand, // null for opponent
|
IEnumerable<CardInstanceDto>? Hand, // null for opponent
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ public sealed class GameState
|
|||||||
|
|
||||||
public sealed class PlayerState
|
public sealed class PlayerState
|
||||||
{
|
{
|
||||||
public string AccountId { get; set; } = string.Empty;
|
public string AccountId { get; set; } = string.Empty;
|
||||||
|
public string DisplayName { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>0-based position in the turn order. Set during game initialization.</summary>
|
/// <summary>0-based position in the turn order. Set during game initialization.</summary>
|
||||||
public int SeatIndex { get; set; } = 0;
|
public int SeatIndex { get; set; } = 0;
|
||||||
|
|||||||
@@ -202,6 +202,20 @@ internal sealed class GameReadyHandler : GameHandlerBase, IMessageHandler
|
|||||||
rules);
|
rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve display names for all players so every client can show real names.
|
||||||
|
var pidGuids = state.Players.Keys
|
||||||
|
.Select(k => Guid.TryParse(k, out var g) ? g : Guid.Empty)
|
||||||
|
.Where(g => g != Guid.Empty)
|
||||||
|
.ToArray();
|
||||||
|
var nameMap = await _identityDb.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.Where(u => pidGuids.Contains(u.Id))
|
||||||
|
.Select(u => new { u.Id, Name = u.DisplayName ?? u.UserName ?? u.Id.ToString().Substring(0, 8) })
|
||||||
|
.ToDictionaryAsync(u => u.Id.ToString(), u => u.Name, ct);
|
||||||
|
foreach (var (pid, ps) in state.Players)
|
||||||
|
if (nameMap.TryGetValue(pid, out var dn))
|
||||||
|
ps.DisplayName = dn;
|
||||||
|
|
||||||
session.StateJson = GameEngine.Serialize(state);
|
session.StateJson = GameEngine.Serialize(state);
|
||||||
session.Status = GameSessionStatus.Active;
|
session.Status = GameSessionStatus.Active;
|
||||||
session.StartedAt = DateTimeOffset.UtcNow;
|
session.StartedAt = DateTimeOffset.UtcNow;
|
||||||
|
|||||||
Reference in New Issue
Block a user