tins2020/herbarium.go

47 lines
945 B
Go
Raw Normal View History

package tins2020
import (
"fmt"
"strconv"
)
type Herbarium struct {
flowers map[string]FlowerDescriptor
order []string
}
func NewHerbarium() Herbarium {
return Herbarium{map[string]FlowerDescriptor{}, nil}
}
type FlowerDescriptor struct {
Name string
Description string
BuyPrice int
SellPrice int
Unlocked bool
IconTemplate IconTemplate
Traits FlowerTraits
}
type IconTemplate string
func (t IconTemplate) Disabled() string { return t.Fmt("disabled") }
func (t IconTemplate) Fmt(s string) string { return fmt.Sprintf(string(t), s) }
func (t IconTemplate) Variant(i int) string { return t.Fmt(strconv.Itoa(i)) }
func (h *Herbarium) Add(id string, desc FlowerDescriptor) {
h.flowers[id] = desc
h.order = append(h.order, id)
}
func (h *Herbarium) Find(id string) (FlowerDescriptor, bool) {
flower, ok := h.flowers[id]
return flower, ok
}
func (h *Herbarium) Flowers() []string { return h.order }