refactor: extract shared player, session, and chat packages #5
Reference in New Issue
Block a user
Delete Branch "refactor/shared-player-session-chat"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Three incremental refactors to reduce duplication and decouple chat from game logic:
playerpackage — Extractedplayer.IDtype andplayer.GenerateID()from identical definitions ingameandsnakepackages. Both now import fromplayer/.sessions.GetPlayerID(),GetUserID(),GetNickname()replacing the inline 10-line player-identity-resolution pattern duplicated across every handler in both game features.chatpackage — Extractedchat.Room(NATS pub/sub + in-memory buffer),chat.Message(unified wire format), DB persistence helpers, and a single parameterized templ component. Replaces duplicatedChatMessagetypes,Chat()templ components,chatAutoScroll()scripts, color functions, and manual buffer management in both c4game and snakegame.Stats
17 files changed, 412 insertions, 390 deletions (3 new packages, 2 deleted templ files)
Rename game/ -> connect4/ to avoid c4/game stutter. Drop redundant Game prefix from exported types (GameStore -> Store, GameInstance -> Instance, GameStatus -> Status). Rename NATS subjects from game.{id} to connect4.{id}. URL routes unchanged.