30 lines
670 B
Go
30 lines
670 B
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/iliadenisov/galaxy/internal/model/game"
|
|
)
|
|
|
|
func (c *Cache) Planet(planetNumber uint) (*game.Planet, bool) {
|
|
if c.planetByPlanetNumber == nil {
|
|
c.planetByPlanetNumber = make(map[uint]*game.Planet)
|
|
for p := range c.g.Map.Planet {
|
|
c.planetByPlanetNumber[c.g.Map.Planet[p].Number] = &c.g.Map.Planet[p]
|
|
}
|
|
}
|
|
if v, ok := c.planetByPlanetNumber[planetNumber]; ok {
|
|
return v, true
|
|
} else {
|
|
return nil, false
|
|
}
|
|
}
|
|
|
|
func (c *Cache) MustPlanet(planetNumber uint) *game.Planet {
|
|
if v, ok := c.Planet(planetNumber); ok {
|
|
return v
|
|
} else {
|
|
panic(fmt.Sprintf("Planet: not found by number=%d", planetNumber))
|
|
}
|
|
}
|