75 lines
1.5 KiB
Go
Raw Normal View History

2019-06-03 09:32:43 +00:00
package arn
import "github.com/aerogo/nano"
const (
// ShopItemRarityCommon ...
ShopItemRarityCommon = "common"
// ShopItemRaritySuperior ...
ShopItemRaritySuperior = "superior"
// ShopItemRarityRare ...
ShopItemRarityRare = "rare"
// ShopItemRarityUnique ...
ShopItemRarityUnique = "unique"
// ShopItemRarityLegendary ...
ShopItemRarityLegendary = "legendary"
)
// ShopItem is a purchasable item in the shop.
type ShopItem struct {
2019-11-18 06:13:51 +00:00
ID ID `json:"id" primary:"true"`
2019-06-03 09:32:43 +00:00
Name string `json:"name"`
Description string `json:"description"`
Price uint `json:"price"`
Icon string `json:"icon"`
Rarity string `json:"rarity"`
Order int `json:"order"`
Consumable bool `json:"consumable"`
2019-09-15 23:17:20 +00:00
}
2019-09-15 23:17:20 +00:00
// GetID returns the ID.
func (item *ShopItem) GetID() string {
return item.ID
2019-06-03 09:32:43 +00:00
}
// GetShopItem ...
2019-11-18 06:13:51 +00:00
func GetShopItem(id ID) (*ShopItem, error) {
2019-06-03 09:32:43 +00:00
obj, err := DB.Get("ShopItem", id)
if err != nil {
return nil, err
}
return obj.(*ShopItem), nil
}
// StreamShopItems returns a stream of all shop items.
func StreamShopItems() <-chan *ShopItem {
channel := make(chan *ShopItem, nano.ChannelBufferSize)
go func() {
for obj := range DB.All("ShopItem") {
channel <- obj.(*ShopItem)
}
close(channel)
}()
return channel
}
// AllShopItems returns a slice of all items.
func AllShopItems() ([]*ShopItem, error) {
all := make([]*ShopItem, 0, DB.Collection("ShopItem").Count())
for obj := range StreamShopItems() {
all = append(all, obj)
}
return all, nil
}