feat: finish game; store reports
This commit is contained in:
+14
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user