Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions custom_components/beatify/game/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def serialize(gs: GameState) -> dict[str, Any] | None:
state: dict[str, Any] = {
"game_id": gs.game_id,
"phase": gs.phase.value,
"player_count": len(gs.players),
"player_count": len(gs._player_registry.players),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The GameState class now exposes the player_registry subsystem via a public property. External callers like this serializer should use the public property instead of accessing the private _player_registry attribute directly to maintain proper encapsulation and consistency with the refactoring goal.

Suggested change
"player_count": len(gs._player_registry.players),
"player_count": len(gs.player_registry.players),

"players": gs.get_players_state(),
"language": gs.language,
"difficulty": gs.difficulty,
Expand Down Expand Up @@ -89,7 +89,7 @@ def _add_playing_state(gs: GameState, state: dict[str, Any]) -> None:
)
# Submission tracking (Story 4.4)
state["submitted_count"] = sum(
1 for p in gs.players.values() if p.submitted
1 for p in gs._player_registry.players.values() if p.submitted
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the public player_registry property instead of the private _player_registry attribute.

Suggested change
1 for p in gs._player_registry.players.values() if p.submitted
1 for p in gs.player_registry.players.values() if p.submitted

)
state["all_submitted"] = gs.all_submitted()
# Song info WITHOUT year during PLAYING (hidden until reveal)
Expand Down Expand Up @@ -173,11 +173,11 @@ def _add_end_state(gs: GameState, state: dict[str, Any]) -> None:
state["leaderboard"] = gs.get_final_leaderboard()
state["game_stats"] = {
"total_rounds": rm.round,
"total_players": len(gs.players),
"total_players": len(gs._player_registry.players),
}
# Include winner info
if gs.players:
winner = max(gs.players.values(), key=lambda p: p.score)
if gs._player_registry.players:
winner = max(gs._player_registry.players.values(), key=lambda p: p.score)
state["winner"] = {"name": winner.name, "score": winner.score}
Comment on lines +176 to 181
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Multiple instances of private attribute access (_player_registry) should be replaced with the public player_registry property exposed on GameState.

Suggested change
"total_players": len(gs._player_registry.players),
}
# Include winner info
if gs.players:
winner = max(gs.players.values(), key=lambda p: p.score)
if gs._player_registry.players:
winner = max(gs._player_registry.players.values(), key=lambda p: p.score)
state["winner"] = {"name": winner.name, "score": winner.score}
"total_players": len(gs.player_registry.players),
}
# Include winner info
if gs.player_registry.players:
winner = max(gs.player_registry.players.values(), key=lambda p: p.score)
state["winner"] = {"name": winner.name, "score": winner.score}

# Game performance comparison for end screen (Story 14.4 AC5, AC6)
game_performance = gs.get_game_performance()
Expand All @@ -204,7 +204,7 @@ def get_reveal_players_state(gs: GameState) -> list[dict[str, Any]]:
"""
rm = gs._round_manager
players = []
for p in gs.players.values():
for p in gs._player_registry.players.values():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the public player_registry property instead of the private _player_registry attribute.

Suggested change
for p in gs._player_registry.players.values():
for p in gs.player_registry.players.values():

player_data = {
"name": p.name,
"score": p.score,
Expand All @@ -231,10 +231,10 @@ def get_reveal_players_state(gs: GameState) -> list[dict[str, Any]]:
"steal_available": p.steal_available,
}
# Story 20.4: Add artist bonus if challenge is enabled
if gs.artist_challenge_enabled:
if gs._challenge_manager.artist_challenge_enabled:
player_data["artist_bonus"] = p.artist_bonus
# Issue #28: Add movie bonus if quiz is enabled
if gs.movie_quiz_enabled:
if gs._challenge_manager.movie_quiz_enabled:
player_data["movie_bonus"] = p.movie_bonus
Comment on lines +234 to 238
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The GameState class now exposes the challenges subsystem via a public property. Accessing _challenge_manager directly from the serializer breaks encapsulation.

Suggested change
if gs._challenge_manager.artist_challenge_enabled:
player_data["artist_bonus"] = p.artist_bonus
# Issue #28: Add movie bonus if quiz is enabled
if gs.movie_quiz_enabled:
if gs._challenge_manager.movie_quiz_enabled:
player_data["movie_bonus"] = p.movie_bonus
if gs.challenges.artist_challenge_enabled:
player_data["artist_bonus"] = p.artist_bonus
# Issue #28: Add movie bonus if quiz is enabled
if gs.challenges.movie_quiz_enabled:
player_data["movie_bonus"] = p.movie_bonus

# Issue #23: Add intro bonus if mode is enabled
if rm.intro_mode_enabled:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/beatify/game/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ def build_share_data(game_state: Any) -> dict[str, Any]:
else:
playlist_name = playlist_path.replace(".json", "").replace("-", " ").title()

total_rounds = game_state.round
total_rounds = game_state.round_manager.round

emoji_grids: dict[str, str] = {}
for name, player in game_state.players.items():
for name, player in game_state.player_registry.players.items():
emoji_grids[name] = build_emoji_grid(player, playlist_name, total_rounds)

return {
Expand Down
Loading
Loading