feat: turn stage increment after player's command
This commit is contained in:
@@ -7,31 +7,39 @@ import (
|
||||
)
|
||||
|
||||
func GenerateGame(configure func(*controller.Param), races []string) (gameID uuid.UUID, err error) {
|
||||
control(configure, func(c *controller.Controller) {
|
||||
c.ExecuteState(func(r controller.Repo) { gameID, err = controller.NewGame(r, races) })
|
||||
err = control(configure, func(c *controller.Controller) error {
|
||||
return c.ExecuteState(func(r controller.Repo) error {
|
||||
gameID, err = controller.NewGame(r, races)
|
||||
return err
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// LoadState used for lock-safe loading game state and may be called concurrently.
|
||||
func LoadState(configure func(*controller.Param)) (g *game.Game, err error) {
|
||||
control(configure, func(c *controller.Controller) { g, err = c.Repo.LoadStateSafe() })
|
||||
err = control(configure, func(c *controller.Controller) error {
|
||||
g, err = c.Repo.LoadStateSafe()
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: command for loading report by players (MUST be limited by router)
|
||||
func LoadReport(configure func(*controller.Param)) (g *game.Game, err error) {
|
||||
control(configure, func(c *controller.Controller) {
|
||||
c.ExecuteState(func(r controller.Repo) { g, err = c.Repo.LoadState() })
|
||||
err = control(configure, func(c *controller.Controller) error {
|
||||
return c.ExecuteState(func(r controller.Repo) error {
|
||||
g, err = c.Repo.LoadState()
|
||||
return err
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func control(configure func(*controller.Param), consumer func(*controller.Controller)) error {
|
||||
func control(configure func(*controller.Param), consumer func(*controller.Controller) error) (err error) {
|
||||
c, err := controller.NewController(configure)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
consumer(c)
|
||||
return nil
|
||||
return consumer(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user