remove global sim

This commit is contained in:
stryan 2022-08-22 18:39:41 -04:00
parent 4b5ba6c2fd
commit cc84c4c15c
4 changed files with 49 additions and 6 deletions

View File

@ -5,15 +5,14 @@ import (
"os"
sim "git.saintnet.tech/stryan/spacetea/simulator"
tea "github.com/charmbracelet/bubbletea"
)
var simulator *sim.Simulator
func main() {
simulator = sim.NewSimulator()
simulator := sim.NewSimulator()
simulator.Start()
parent := parent{initMainscreen()}
parent := parent{initMainscreen(simulator)}
if err := tea.NewProgram(parent, tea.WithAltScreen()).Start(); err != nil {
fmt.Printf("Uh oh, there was an error: %v\n", err)
os.Exit(1)

View File

@ -47,14 +47,14 @@ func (m model) simCommand() tea.Msg {
}
return nil
}
func initMainscreen() model {
func initMainscreen(sim *simulator) model {
ti := textinput.New()
ti.Placeholder = "input command"
ti.CharLimit = 156
ti.Width = 20
return model{
s: simulator,
s: sim,
input: ti,
help: help.New(),
keys: keys,

38
simulator/landmark.go Normal file
View File

@ -0,0 +1,38 @@
package simulator
import (
"strconv"
"github.com/BurntSushi/toml"
)
//LandmarkID is a landmark
type LandmarkID int
//Landmark is a flavour location
type Landmark struct {
LandmarkID LandmarkID `toml:"pageid"`
Name string `toml:"title"`
Content string `toml:"content"`
Links []LandmarkID `toml:"links"`
}
func (l Landmark) ID() string {
return strconv.Itoa(int(l.LandmarkID))
}
//GlobalPages is a list of all pages
var GlobalLandmarks []Landmark
type landmarks struct {
Landmark []Landmark
}
func loadLandmarks(filename string) {
var res landmarks
_, err := toml.DecodeFile(filename, &res)
if err != nil {
panic(err)
}
GlobalLandmarks = res.Landmark
}

View File

@ -30,6 +30,8 @@ func NewSimulator() *Simulator {
loadConverters("data/converters.toml")
log.Println("loading journal")
loadPages("data/journal.toml")
log.Println("loading landmarks")
loadLandmarks("data/landmark.toml")
if len(GlobalItems) < 1 {
panic("Loaded items but nothing in global items table")
}
@ -39,6 +41,10 @@ func NewSimulator() *Simulator {
if len(GlobalPages) < 1 {
panic("Loaded journal but no pages in table")
}
if len(GlobalLandmarks) < 1 {
panic("Loaded landmarks but nothing in table")
}
pod.Place(newResource(lookupByName("tea").ID()), 4, 4)
player.AddItem(itemType(1), 30)
player.AddItem(itemType(3), 5)