spacetea/simulator/tech.go

51 lines
855 B
Go
Raw Normal View History

2022-05-24 18:26:34 -04:00
package simulator
2022-05-24 21:12:35 -04:00
import "github.com/BurntSushi/toml"
//TechID is a tech level
type TechID int
type relation struct {
2022-05-25 16:45:23 -04:00
Name string
Value int
2022-05-24 21:12:35 -04:00
}
2022-05-24 18:26:34 -04:00
//Tech is a tech level
2022-05-24 21:12:35 -04:00
type Tech struct {
2022-05-25 16:45:23 -04:00
ID TechID `toml:"techid"`
DisplayName string `toml:"displayName"`
2022-05-24 21:12:35 -04:00
Name string `toml:"name"`
2022-05-25 18:07:07 -04:00
Flavour string `toml:"flavour"`
2022-05-24 21:12:35 -04:00
Requires []relation `toml:"requires"`
Unlocks []string `toml:"unlocks"`
}
2022-05-24 18:26:34 -04:00
const (
2022-05-24 21:12:35 -04:00
techPulper TechID = iota
2022-05-24 18:26:34 -04:00
)
2022-05-24 21:12:35 -04:00
//GlobalTechs list of all techs
var GlobalTechs []Tech
type techs struct {
2022-05-25 16:45:23 -04:00
Tech []Tech
2022-05-24 21:12:35 -04:00
}
func lookupTechByName(name string) Tech {
for _, v := range GlobalTechs {
if v.Name == name {
return v
}
}
return Tech{}
}
func loadTechs(filename string) {
var res techs
_, err := toml.DecodeFile(filename, &res)
if err != nil {
panic(err)
}
2022-05-25 16:45:23 -04:00
GlobalTechs = res.Tech
2022-05-24 21:12:35 -04:00
}