refactor: add save()/savePlayer() methods on game instances
Wrap free persistence functions in instance methods for cleaner call sites (gi.save() instead of saveGame(gi.queries, gi.game)). Methods log errors via zerolog before returning them.
This commit is contained in:
@@ -62,7 +62,7 @@ func (si *SnakeGameInstance) countdownPhase() {
|
||||
si.game.Status = StatusInProgress
|
||||
|
||||
if si.queries != nil {
|
||||
saveSnakeGame(si.queries, si.game) //nolint:errcheck
|
||||
si.save() //nolint:errcheck
|
||||
}
|
||||
si.gameMu.Unlock()
|
||||
si.notify()
|
||||
@@ -123,7 +123,7 @@ func (si *SnakeGameInstance) gamePhase() {
|
||||
if time.Since(lastInput) > inactivityLimit {
|
||||
si.game.Status = StatusFinished
|
||||
if si.queries != nil {
|
||||
saveSnakeGame(si.queries, si.game) //nolint:errcheck
|
||||
si.save() //nolint:errcheck
|
||||
}
|
||||
si.gameMu.Unlock()
|
||||
si.notify()
|
||||
@@ -193,7 +193,7 @@ func (si *SnakeGameInstance) gamePhase() {
|
||||
|
||||
// Throttle DB saves: persist on game over or every 2 seconds
|
||||
if si.queries != nil && (gameOver || time.Since(lastSave) >= 2*time.Second) {
|
||||
saveSnakeGame(si.queries, si.game) //nolint:errcheck
|
||||
si.save() //nolint:errcheck
|
||||
lastSave = time.Now()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user