Simplify codebase and fix Enter key on home page

- Enter key now triggers createGame action on home page
- Remove redundant setNickname action from home page
- Remove unused code: join channel, Leave(), Stop() methods
- Consolidate ID generation into game.GenerateID()
- Remove unused CreatedAt field from Game struct
This commit is contained in:
Ryan Hamamura
2026-01-14 14:10:18 -10:00
parent 389fc12bf2
commit 63d0773ab5
6 changed files with 34 additions and 61 deletions

View File

@@ -28,7 +28,7 @@ func NewGameStore() *GameStore {
}
func (gs *GameStore) Create() *GameInstance {
id := generateGameID()
id := GenerateID(4)
gi := NewGameInstance(id)
gs.gamesMu.Lock()
gs.games[id] = gi
@@ -44,8 +44,8 @@ func (gs *GameStore) Get(id string) (*GameInstance, bool) {
return gi, ok
}
func generateGameID() string {
b := make([]byte, 4)
func GenerateID(size int) string {
b := make([]byte, size)
rand.Read(b)
return hex.EncodeToString(b)
}
@@ -55,7 +55,6 @@ type GameInstance struct {
gameMu sync.RWMutex
players map[PlayerID]Syncable
playersMu sync.RWMutex
join chan *PlayerSession
leave chan PlayerID
done chan struct{}
dirty bool
@@ -65,7 +64,6 @@ func NewGameInstance(id string) *GameInstance {
return &GameInstance{
game: NewGame(id),
players: make(map[PlayerID]Syncable),
join: make(chan *PlayerSession, 5),
leave: make(chan PlayerID, 5),
done: make(chan struct{}),
}
@@ -101,10 +99,6 @@ func (gi *GameInstance) Join(ps *PlayerSession) bool {
return true
}
func (gi *GameInstance) Leave(pid PlayerID) {
gi.leave <- pid
}
func (gi *GameInstance) GetGame() *Game {
gi.gameMu.RLock()
defer gi.gameMu.RUnlock()
@@ -186,7 +180,3 @@ func (gi *GameInstance) publish() {
sync.Sync()
}
}
func (gi *GameInstance) Stop() {
close(gi.done)
}