From cc84c4c15cf638a166e6826ae49e82a1f43d27e6 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 22 Aug 2022 18:39:41 -0400 Subject: [PATCH] remove global sim --- main.go | 7 +++---- mainscreen.go | 4 ++-- simulator/landmark.go | 38 ++++++++++++++++++++++++++++++++++++++ simulator/simulator.go | 6 ++++++ 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 simulator/landmark.go diff --git a/main.go b/main.go index 2a7fd78..32eac91 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/mainscreen.go b/mainscreen.go index 557d452..3527c7f 100644 --- a/mainscreen.go +++ b/mainscreen.go @@ -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, diff --git a/simulator/landmark.go b/simulator/landmark.go new file mode 100644 index 0000000..ea3fbf0 --- /dev/null +++ b/simulator/landmark.go @@ -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 +} diff --git a/simulator/simulator.go b/simulator/simulator.go index 56adfcb..f3a8a59 100644 --- a/simulator/simulator.go +++ b/simulator/simulator.go @@ -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)