fix: improve endgame clock and gameplay stability
This commit is contained in:
1 parent
ce6aabfc55
commit
658298ee86
46 files changed
+1915
-99
No files matched your search
@@ -42,6 +42,36 @@ func TestGameClockSharedStateAndReset(t *testing.T) {
|
||||
if string(before) != string(after) {
|
||||
t.Fatal("read rewrote state")
|
||||
}
|
||||
begin := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
end := begin.Add(24 * time.Hour)
|
||||
if _, err := SetGameTimeWindow(begin, end); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
window, err := ReadGameClock()
|
||||
if err != nil || window.WindowBeginMS != begin.UnixMilli() || window.WindowEndMS != end.UnixMilli() {
|
||||
t.Fatalf("window not saved: %+v %v", window, err)
|
||||
}
|
||||
// Simulate the clock having advanced beyond the end without waiting a day.
|
||||
window.OffsetMS = end.Add(time.Hour).UnixMilli() - time.Now().UnixMilli()
|
||||
raw, _ = json.Marshal(window)
|
||||
if err := os.WriteFile(cfg.GameClock.StateFile, raw, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now, err = GameTime()
|
||||
if err != nil || now.Sub(begin.Add(time.Hour)) < 0 || now.Sub(begin.Add(time.Hour)) > time.Second {
|
||||
t.Fatalf("window did not wrap: %v %v", now, err)
|
||||
}
|
||||
before, _ = os.ReadFile(cfg.GameClock.StateFile)
|
||||
if _, err := GameTime(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
after, _ = os.ReadFile(cfg.GameClock.StateFile)
|
||||
if string(before) != string(after) {
|
||||
t.Fatal("window read rewrote state")
|
||||
}
|
||||
if _, err := SetGameTimeWindow(end, begin); err == nil {
|
||||
t.Fatal("invalid window accepted")
|
||||
}
|
||||
if _, err := SetGameTime(nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -49,6 +79,10 @@ func TestGameClockSharedStateAndReset(t *testing.T) {
|
||||
if err != nil || time.Since(now).Abs() > time.Second {
|
||||
t.Fatalf("real time not restored: %v %v", now, err)
|
||||
}
|
||||
window, err = ReadGameClock()
|
||||
if err != nil || window.WindowBeginMS != 0 || window.WindowEndMS != 0 {
|
||||
t.Fatalf("reset retained window: %+v %v", window, err)
|
||||
}
|
||||
if err := os.WriteFile(cfg.GameClock.StateFile, []byte(`{"offset_ms":9223372036854775807}`), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user