v0.12.0 migrate sqlite3 to psql18, updated auth, deploy docs, account and replay updates
test / test (push) Canceled after 0s
test / test (push) Canceled after 0s
This commit is contained in:
1 parent
5d2be4abb2
commit
d0326b059e
66 files changed
+4016
-2433
No files matched your search
@@ -26,11 +26,12 @@ type MoveResult struct {
|
||||
}
|
||||
|
||||
type Game struct {
|
||||
snapshots []Snapshot
|
||||
players map[core.Color]*core.Player
|
||||
state core.State
|
||||
lastResult *MoveResult
|
||||
endTimeUTC *time.Time
|
||||
snapshots []Snapshot
|
||||
players map[core.Color]*core.Player
|
||||
state core.State
|
||||
lastResult *MoveResult
|
||||
endTimeUTC *time.Time
|
||||
lastActivity time.Time // last create, move, undo, reconfiguration, or state change
|
||||
}
|
||||
|
||||
// View is an immutable copy of the state needed by processors and transports.
|
||||
@@ -133,10 +134,6 @@ func (g *Game) SetLastResult(result *MoveResult) {
|
||||
g.lastResult = ©
|
||||
}
|
||||
|
||||
func (g *Game) LastResult() *MoveResult {
|
||||
return g.lastResult
|
||||
}
|
||||
|
||||
// CurrentSnapshot returns the latest game snapshot
|
||||
func (g *Game) CurrentSnapshot() Snapshot {
|
||||
return g.snapshots[len(g.snapshots)-1]
|
||||
@@ -217,11 +214,8 @@ func (g *Game) State() core.State {
|
||||
return g.state
|
||||
}
|
||||
|
||||
func (g *Game) SetState(s core.State) {
|
||||
g.SetStateAt(s, time.Now().UTC())
|
||||
}
|
||||
|
||||
func (g *Game) SetStateAt(s core.State, at time.Time) {
|
||||
g.Touch(at)
|
||||
if s.IsTerminal() {
|
||||
if !g.state.IsTerminal() || g.endTimeUTC == nil {
|
||||
ended := at.UTC()
|
||||
@@ -233,6 +227,28 @@ func (g *Game) SetStateAt(s core.State, at time.Time) {
|
||||
g.state = s
|
||||
}
|
||||
|
||||
// Touch records activity at the given time; earlier times are ignored.
|
||||
func (g *Game) Touch(at time.Time) {
|
||||
if at.After(g.lastActivity) {
|
||||
g.lastActivity = at
|
||||
}
|
||||
}
|
||||
|
||||
// LastActivity returns the latest time passed to Touch.
|
||||
func (g *Game) LastActivity() time.Time {
|
||||
return g.lastActivity
|
||||
}
|
||||
|
||||
// IsClaimed reports whether a registered user claimed either slot.
|
||||
func (g *Game) IsClaimed() bool {
|
||||
for _, player := range g.players {
|
||||
if player != nil && player.ClaimedBy != "" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *Game) EndTimeUTC() *time.Time {
|
||||
if g.endTimeUTC == nil {
|
||||
return nil
|
||||
@@ -278,11 +294,6 @@ func (g *Game) GetSlotOwner(color core.Color) string {
|
||||
return player.ClaimedBy
|
||||
}
|
||||
|
||||
// IsSlotClaimedBy checks if a specific user owns the slot
|
||||
func (g *Game) IsSlotClaimedBy(color core.Color, userID string) bool {
|
||||
return g.GetSlotOwner(color) == userID
|
||||
}
|
||||
|
||||
// HasComputerPlayer returns true if at least one player is computer
|
||||
func (g *Game) HasComputerPlayer() bool {
|
||||
white := g.players[core.ColorWhite]
|
||||
|
||||
Reference in new issue
Block a user