initial file loading

This commit is contained in:
stryan 2022-05-24 21:12:35 -04:00
parent a3e028e916
commit 8503d07da7
9 changed files with 88 additions and 17 deletions

8
data/converters.toml Normal file
View File

@ -0,0 +1,8 @@
[[converter]]
itemid = 3
name = "teaConverter"
displayName = "Tea Pulper"
source = "tea"
output = "brick"
rate = 5

11
data/items.toml Normal file
View File

@ -0,0 +1,11 @@
[[resource]]
itemid = 1
name = "tea"
displayName = "Tea"
buildable = true
rate = 3
[[resource]]
itemid = 2
name = "brick"
displayName = "Tea Bricks"

6
data/tech.toml Normal file
View File

@ -0,0 +1,6 @@
[[tech]]
techid = 1
name = "teaConverter"
displayName = "Tea Pulper"
unlocks = ["2"]
require = []

1
go.mod
View File

@ -8,6 +8,7 @@ require (
) )
require ( require (
github.com/BurntSushi/toml v1.1.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect github.com/atotto/clipboard v0.1.4 // indirect
github.com/charmbracelet/lipgloss v0.4.0 // indirect github.com/charmbracelet/lipgloss v0.4.0 // indirect
github.com/containerd/console v1.0.3 // indirect github.com/containerd/console v1.0.3 // indirect

2
go.sum
View File

@ -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 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/charmbracelet/bubbles v0.10.3 h1:fKarbRaObLn/DCsZO4Y3vKCwRUzynQD9L+gGev1E/ho= github.com/charmbracelet/bubbles v0.10.3 h1:fKarbRaObLn/DCsZO4Y3vKCwRUzynQD9L+gGev1E/ho=

View File

@ -25,9 +25,6 @@ const (
//GlobalItemList of all items //GlobalItemList of all items
var GlobalItemList = []itemType{itemPlantTea, itemPlantWood, convertPulper} var GlobalItemList = []itemType{itemPlantTea, itemPlantWood, convertPulper}
//GlobalTechList list of all techs
var GlobalTechList = []Tech{techPulper}
//Lookup returns a human friendly item entry //Lookup returns a human friendly item entry
func Lookup(id itemType) ItemEntry { func Lookup(id itemType) ItemEntry {
switch id { switch id {
@ -40,13 +37,3 @@ func Lookup(id itemType) ItemEntry {
} }
return nil 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
}

View File

@ -8,7 +8,8 @@ import (
//Player is a player controlled mob //Player is a player controlled mob
type Player struct { type Player struct {
Resources map[itemType]int Resources map[itemType]int
Techs map[Tech]struct{} Craftables map[itemType]struct{}
Techs map[TechID]struct{}
CurrentTile *Tile CurrentTile *Tile
log []string log []string
logIndex int logIndex int
@ -16,7 +17,7 @@ type Player struct {
//NewPlayer initializes a player //NewPlayer initializes a player
func NewPlayer() *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 { func (p *Player) String() string {

View File

@ -1,8 +1,62 @@
package simulator 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 //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 ( 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
}

View File

@ -19,6 +19,7 @@ type Simulator struct {
func NewSimulator() *Simulator { func NewSimulator() *Simulator {
pod := newPod() pod := newPod()
player := NewPlayer() player := NewPlayer()
loadTechs("data/tech.toml")
pod.Place(newPlant(itemPlantTea), 4, 4) pod.Place(newPlant(itemPlantTea), 4, 4)
pod.Tiles[0][0].User = player pod.Tiles[0][0].User = player
player.Announce("Game started") player.Announce("Game started")