feat: finish game; store reports

This commit is contained in:
Ilia Denisov
2026-02-04 14:21:37 +02:00
parent abc98ee72f
commit 9a6d4112cf
6 changed files with 43 additions and 10 deletions
+14 -2
View File
@@ -22,6 +22,18 @@ const (
metaPath = "meta.json"
)
func (r *repo) SaveReport(t uint, rep *report.Report) error {
return saveReport(r.s, t, rep)
}
func saveReport(s Storage, t uint, v *report.Report) error {
path := fmt.Sprintf("%s/report/%s.json", turnDir(t), v.RaceID.String())
if err := s.Write(path, v); err != nil {
return NewStorageError(err)
}
return nil
}
func (r *repo) SaveTurn(t uint, g *game.Game) error {
return saveTurn(r.s, t, g)
}
@@ -127,13 +139,13 @@ func (r *repo) SaveBattle(t uint, b *report.BattleReport, m *game.BattleMeta) er
}
func saveBattle(s Storage, t uint, b *report.BattleReport) error {
path := fmt.Sprintf("%s/battle/%s.json", turnDir(t), b.ID)
path := fmt.Sprintf("%s/battle/%s.json", turnDir(t), b.ID.String())
exist, err := s.Exists(path)
if err != nil {
return NewStorageError(err)
}
if exist {
return NewStateError(fmt.Sprintf("battle %s for turn %d already has been saved", b.ID, t))
return NewStateError(fmt.Sprintf("battle %v for turn %d already has been saved", b.ID, t))
}
if err := s.Write(path, b); err != nil {
return NewStorageError(err)