25 lines
724 B
Go
25 lines
724 B
Go
package game
|
|
|
|
import "github.com/iliadenisov/galaxy/pkg/model/game"
|
|
|
|
func DeclareWar(configure func(*Param), from, to string) (err error) {
|
|
control(configure, func(c *ctrl) {
|
|
c.execute(func(r Repo, g game.Game) { err = updateRelation(r, g, from, to, game.RelationWar) })
|
|
})
|
|
return
|
|
}
|
|
|
|
func DeclarePeace(configure func(*Param), from, to string) (err error) {
|
|
control(configure, func(c *ctrl) {
|
|
c.execute(func(r Repo, g game.Game) { err = updateRelation(r, g, from, to, game.RelationPeace) })
|
|
})
|
|
return
|
|
}
|
|
|
|
func updateRelation(r Repo, g game.Game, hostRace, opponentRace string, rel game.Relation) error {
|
|
if err := g.UpdateRelation(hostRace, opponentRace, rel); err != nil {
|
|
return err
|
|
}
|
|
return r.SaveState(g)
|
|
}
|