29 lines
832 B
Go
29 lines
832 B
Go
package game
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"github.com/iliadenisov/galaxy/internal/controller"
|
|
"github.com/iliadenisov/galaxy/internal/model/game"
|
|
)
|
|
|
|
func LoadState(configure func(*controller.Param)) (g game.Game, err error) {
|
|
control(configure, func(c *controller.Controller) { c.ExecuteInit(func(r controller.Repo) { g, err = c.Repo.LoadState() }) })
|
|
return
|
|
}
|
|
|
|
func GenerateGame(configure func(*controller.Param), races []string) (gameID uuid.UUID, err error) {
|
|
control(configure, func(c *controller.Controller) {
|
|
c.ExecuteInit(func(r controller.Repo) { gameID, err = controller.NewGame(r, races) })
|
|
})
|
|
return
|
|
}
|
|
|
|
func control(configure func(*controller.Param), consumer func(*controller.Controller)) error {
|
|
c, err := controller.NewController(configure)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
consumer(c)
|
|
return nil
|
|
}
|