wip: battle

This commit is contained in:
Ilia Denisov
2026-01-13 18:53:17 +02:00
parent 4451850f22
commit 45c725a3ee
5 changed files with 197 additions and 30 deletions
+27 -5
View File
@@ -2,10 +2,9 @@ package repo
/*
/state.json
/000/state.json
/000/race/{UUID}/order/001.json
/000/race/{UUID}/report.json
/000/battle/{planet_UUID}
/0001/state.json
/0001/race/{UUID}/report.json
/0001/battle/{UUID}.json
*/
import (
@@ -23,7 +22,7 @@ func (r *repo) SaveTurn(t uint, g *game.Game) error {
}
func saveTurn(s Storage, t uint, g *game.Game) error {
path := fmt.Sprintf("%03d/state.json", t)
path := fmt.Sprintf("%s/state.json", turnDir(t))
exist, err := s.Exists(path)
if err != nil {
return NewStorageError(err)
@@ -86,3 +85,26 @@ func loadState(s Storage, locked bool) (*game.Game, error) {
}
return g, nil
}
func (r *repo) SaveBattle(t uint, b *game.BattleReport) error {
return saveBattle(r.s, t, b)
}
func saveBattle(s Storage, t uint, b *game.BattleReport) error {
path := fmt.Sprintf("%s/battle/%s.json", turnDir(t), b.ID)
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))
}
if err := s.Write(path, b); err != nil {
return NewStorageError(err)
}
return nil
}
func turnDir(t uint) string {
return fmt.Sprintf("%04d", t)
}