You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
858 B
49 lines
858 B
package catalog
|
|
|
|
import "slices"
|
|
|
|
// Game describes an installed, internally published version. The registry
|
|
// never imports manifests from a player request or the legacy application.
|
|
type Game struct {
|
|
ID string
|
|
Version string
|
|
Title string
|
|
Summary string
|
|
MinPlayers int
|
|
MaxPlayers int
|
|
Published bool
|
|
}
|
|
|
|
type Registry struct {
|
|
games []Game
|
|
}
|
|
|
|
func NewRegistry(games []Game) *Registry {
|
|
return &Registry{games: slices.Clone(games)}
|
|
}
|
|
|
|
func (r *Registry) Published() []Game {
|
|
result := make([]Game, 0)
|
|
for _, game := range r.games {
|
|
if game.Published {
|
|
result = append(result, game)
|
|
}
|
|
}
|
|
slices.SortFunc(result, func(a, b Game) int {
|
|
if a.Title < b.Title {
|
|
return -1
|
|
}
|
|
if a.Title > b.Title {
|
|
return 1
|
|
}
|
|
if a.ID < b.ID {
|
|
return -1
|
|
}
|
|
if a.ID > b.ID {
|
|
return 1
|
|
}
|
|
return 0
|
|
})
|
|
return result
|
|
}
|