initial file loading
This commit is contained in:
parent
a3e028e916
commit
8503d07da7
8
data/converters.toml
Normal file
8
data/converters.toml
Normal 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
11
data/items.toml
Normal 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
6
data/tech.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[[tech]]
|
||||
techid = 1
|
||||
name = "teaConverter"
|
||||
displayName = "Tea Pulper"
|
||||
unlocks = ["2"]
|
||||
require = []
|
1
go.mod
1
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
|
||||
|
2
go.sum
2
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=
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user