diff --git a/data/converters.toml b/data/converters.toml new file mode 100644 index 0000000..b7d359d --- /dev/null +++ b/data/converters.toml @@ -0,0 +1,8 @@ +[[converter]] +itemid = 3 +name = "teaConverter" +displayName = "Tea Pulper" +source = "tea" +output = "brick" +rate = 5 + diff --git a/data/items.toml b/data/items.toml new file mode 100644 index 0000000..0d85c1f --- /dev/null +++ b/data/items.toml @@ -0,0 +1,11 @@ +[[resource]] +itemid = 1 +name = "tea" +displayName = "Tea" +buildable = true +rate = 3 + +[[resource]] +itemid = 2 +name = "brick" +displayName = "Tea Bricks" diff --git a/data/tech.toml b/data/tech.toml new file mode 100644 index 0000000..91f112a --- /dev/null +++ b/data/tech.toml @@ -0,0 +1,6 @@ +[[tech]] +techid = 1 +name = "teaConverter" +displayName = "Tea Pulper" +unlocks = ["2"] +require = [] diff --git a/go.mod b/go.mod index eededdf..e0a00c6 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( ) require ( + github.com/BurntSushi/toml v1.1.0 // indirect github.com/atotto/clipboard v0.1.4 // indirect github.com/charmbracelet/lipgloss v0.4.0 // indirect github.com/containerd/console v1.0.3 // indirect diff --git a/go.sum b/go.sum index b16df48..087a16e 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= +github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/charmbracelet/bubbles v0.10.3 h1:fKarbRaObLn/DCsZO4Y3vKCwRUzynQD9L+gGev1E/ho= diff --git a/simulator/item_table.go b/simulator/item_table.go index 711662d..7185bfd 100644 --- a/simulator/item_table.go +++ b/simulator/item_table.go @@ -25,9 +25,6 @@ const ( //GlobalItemList of all items var GlobalItemList = []itemType{itemPlantTea, itemPlantWood, convertPulper} -//GlobalTechList list of all techs -var GlobalTechList = []Tech{techPulper} - //Lookup returns a human friendly item entry func Lookup(id itemType) ItemEntry { switch id { @@ -40,13 +37,3 @@ func Lookup(id itemType) ItemEntry { } return nil } - -//LookupTech converts a tech ID to an item ID -func LookupTech(id Tech) ItemEntry { - switch id { - case techPulper: - return converterEntry{convertPulper, 5, "teaConverter", itemPlantTea, itemPlantWood} - } - return nil - -} diff --git a/simulator/player.go b/simulator/player.go index 2abc7e3..9bf01db 100644 --- a/simulator/player.go +++ b/simulator/player.go @@ -8,7 +8,8 @@ import ( //Player is a player controlled mob type Player struct { Resources map[itemType]int - Techs map[Tech]struct{} + Craftables map[itemType]struct{} + Techs map[TechID]struct{} CurrentTile *Tile log []string logIndex int @@ -16,7 +17,7 @@ type Player struct { //NewPlayer initializes a player func NewPlayer() *Player { - return &Player{Resources: make(map[itemType]int), Techs: make(map[Tech]struct{})} + return &Player{Resources: make(map[itemType]int), Techs: make(map[TechID]struct{})} } func (p *Player) String() string { diff --git a/simulator/science.go b/simulator/science.go index 715103b..ed9c2fa 100644 --- a/simulator/science.go +++ b/simulator/science.go @@ -1,8 +1,62 @@ package simulator +import "github.com/BurntSushi/toml" + +//TechID is a tech level +type TechID int + +type relation struct { + name string + value int +} + //Tech is a tech level -type Tech int +type Tech struct { + ID int `toml:"techid"` + DisplayName string `toml:"display_name"` + Name string `toml:"name"` + Requires []relation `toml:"requires"` + Unlocks []string `toml:"unlocks"` +} const ( - techPulper Tech = iota + techPulper TechID = iota ) + +//GlobalTechList list of all techs +var GlobalTechList = []TechID{techPulper} + +//GlobalTechs list of all techs +var GlobalTechs []Tech + +type techs struct { + tech []Tech +} + +//LookupTech converts a tech ID to an item ID +func LookupTech(id TechID) ItemEntry { + switch id { + case techPulper: + return converterEntry{convertPulper, 5, "teaConverter", itemPlantTea, itemPlantWood} + } + return nil + +} + +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) + } + GlobalTechs = res.tech +} diff --git a/simulator/simulator.go b/simulator/simulator.go index 6e3ee43..92a744b 100644 --- a/simulator/simulator.go +++ b/simulator/simulator.go @@ -19,6 +19,7 @@ type Simulator struct { func NewSimulator() *Simulator { pod := newPod() player := NewPlayer() + loadTechs("data/tech.toml") pod.Place(newPlant(itemPlantTea), 4, 4) pod.Tiles[0][0].User = player player.Announce("Game started")