feat: turn generate api
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/iliadenisov/galaxy/internal/model/report"
|
||||
)
|
||||
|
||||
func MakeTurn(c *Controller, r Repo) error {
|
||||
func (c *Controller) MakeTurn() error {
|
||||
// Next turn
|
||||
c.Cache.g.Turn += 1
|
||||
c.Cache.g.Stage = 0
|
||||
@@ -61,7 +61,7 @@ func MakeTurn(c *Controller, r Repo) error {
|
||||
// Store bombings
|
||||
bombingReport := make([]*report.Bombing, len(bombings))
|
||||
if len(bombings) > 0 {
|
||||
if err := r.SaveBombings(c.Cache.g.Turn, bombings); err != nil {
|
||||
if err := c.Repo.SaveBombings(c.Cache.g.Turn, bombings); err != nil {
|
||||
return err
|
||||
}
|
||||
for i := range bombings {
|
||||
@@ -101,7 +101,7 @@ func MakeTurn(c *Controller, r Repo) error {
|
||||
}
|
||||
|
||||
report := TransformBattle(c.Cache, b)
|
||||
if err := r.SaveBattle(c.Cache.g.Turn, report, &battleMeta[i]); err != nil {
|
||||
if err := c.Repo.SaveBattle(c.Cache.g.Turn, report, &battleMeta[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
battleReport[i] = report
|
||||
@@ -112,12 +112,12 @@ func MakeTurn(c *Controller, r Repo) error {
|
||||
c.Cache.DeleteKilledShipGroups()
|
||||
|
||||
// Store game state for the new turn and 'current' state as well
|
||||
if err := r.SaveNewTurn(c.Cache.g.Turn, c.Cache.g); err != nil {
|
||||
if err := c.Repo.SaveNewTurn(c.Cache.g.Turn, c.Cache.g); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for rep := range c.Cache.Report(c.Cache.g.Turn, battleReport, bombingReport) {
|
||||
if err := r.SaveReport(c.Cache.g.Turn, rep); err != nil {
|
||||
if err := c.Repo.SaveReport(c.Cache.g.Turn, rep); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user