remove global sim
This commit is contained in:
parent
4b5ba6c2fd
commit
cc84c4c15c
7
main.go
7
main.go
@ -5,15 +5,14 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
sim "git.saintnet.tech/stryan/spacetea/simulator"
|
sim "git.saintnet.tech/stryan/spacetea/simulator"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
|
||||||
var simulator *sim.Simulator
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
simulator = sim.NewSimulator()
|
simulator := sim.NewSimulator()
|
||||||
simulator.Start()
|
simulator.Start()
|
||||||
parent := parent{initMainscreen()}
|
parent := parent{initMainscreen(simulator)}
|
||||||
if err := tea.NewProgram(parent, tea.WithAltScreen()).Start(); err != nil {
|
if err := tea.NewProgram(parent, tea.WithAltScreen()).Start(); err != nil {
|
||||||
fmt.Printf("Uh oh, there was an error: %v\n", err)
|
fmt.Printf("Uh oh, there was an error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -47,14 +47,14 @@ func (m model) simCommand() tea.Msg {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func initMainscreen() model {
|
func initMainscreen(sim *simulator) model {
|
||||||
ti := textinput.New()
|
ti := textinput.New()
|
||||||
ti.Placeholder = "input command"
|
ti.Placeholder = "input command"
|
||||||
ti.CharLimit = 156
|
ti.CharLimit = 156
|
||||||
ti.Width = 20
|
ti.Width = 20
|
||||||
|
|
||||||
return model{
|
return model{
|
||||||
s: simulator,
|
s: sim,
|
||||||
input: ti,
|
input: ti,
|
||||||
help: help.New(),
|
help: help.New(),
|
||||||
keys: keys,
|
keys: keys,
|
||||||
|
38
simulator/landmark.go
Normal file
38
simulator/landmark.go
Normal 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
|
||||||
|
}
|
@ -30,6 +30,8 @@ func NewSimulator() *Simulator {
|
|||||||
loadConverters("data/converters.toml")
|
loadConverters("data/converters.toml")
|
||||||
log.Println("loading journal")
|
log.Println("loading journal")
|
||||||
loadPages("data/journal.toml")
|
loadPages("data/journal.toml")
|
||||||
|
log.Println("loading landmarks")
|
||||||
|
loadLandmarks("data/landmark.toml")
|
||||||
if len(GlobalItems) < 1 {
|
if len(GlobalItems) < 1 {
|
||||||
panic("Loaded items but nothing in global items table")
|
panic("Loaded items but nothing in global items table")
|
||||||
}
|
}
|
||||||
@ -39,6 +41,10 @@ func NewSimulator() *Simulator {
|
|||||||
if len(GlobalPages) < 1 {
|
if len(GlobalPages) < 1 {
|
||||||
panic("Loaded journal but no pages in table")
|
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)
|
pod.Place(newResource(lookupByName("tea").ID()), 4, 4)
|
||||||
player.AddItem(itemType(1), 30)
|
player.AddItem(itemType(1), 30)
|
||||||
player.AddItem(itemType(3), 5)
|
player.AddItem(itemType(3), 5)
|
||||||
|
Loading…
Reference in New Issue
Block a user