Compare commits

...

4 Commits

Author SHA1 Message Date
207a0e2d69 bubble up more, accounts 2022-08-22 19:34:53 -04:00
a6d74089ee pass around accounts 2022-08-22 19:00:15 -04:00
cc84c4c15c remove global sim 2022-08-22 18:39:41 -04:00
4b5ba6c2fd add todo file 2022-08-21 22:39:17 -04:00
12 changed files with 172 additions and 62 deletions

12
TODO.md Normal file
View File

@ -0,0 +1,12 @@
* Adventure system
* Moving from landmark to another
* UI for it
* How to associate pods with landmarks
* Flags
* replace Requirements with "flags"?
* Flag processor (put flags on stack, pop them out to evalute?)
* "Accounts"
* how to handle a player that isn't in a pod
* or just ignore, player is in a pod until moved to new pod?
* what about player-the-person level triggers?

10
account.go Normal file
View File

@ -0,0 +1,10 @@
package main
import sim "git.saintnet.tech/stryan/spacetea/simulator"
//Account is a account
type Account struct {
Player *sim.Player
Simulator *sim.Simulator
Landmark *sim.Landmark
}

11
data/landmark.toml Normal file
View File

@ -0,0 +1,11 @@
[[landmark]]
landmarkid = 0
name = "Spawn"
content = "Nothing's here but us chickens"
links = [1]
[[landmark]]
landmarkid = 1
name = "Landmark 1"
content = "New spot"
links = []

23
go.mod
View File

@ -3,23 +3,26 @@ module git.saintnet.tech/stryan/spacetea
go 1.18
require (
github.com/BurntSushi/toml v1.1.0
github.com/charmbracelet/bubbles v0.10.3
github.com/charmbracelet/bubbletea v0.20.0
github.com/charmbracelet/lipgloss v0.4.0
github.com/BurntSushi/toml v1.2.0
github.com/charmbracelet/bubbles v0.13.0
github.com/charmbracelet/bubbletea v0.22.1
github.com/charmbracelet/lipgloss v0.5.0
)
require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/muesli/termenv v0.12.0 // indirect
github.com/rivo/uniseg v0.3.4 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed // indirect
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/text v0.3.7 // indirect
)

60
go.sum
View File

@ -1,48 +1,60 @@
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/BurntSushi/toml v1.2.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=
github.com/charmbracelet/bubbles v0.10.3/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA=
github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA=
github.com/charmbracelet/bubbletea v0.20.0 h1:/b8LEPgCbNr7WWZ2LuE/BV1/r4t5PyYJtDb+J3vpwxc=
github.com/charmbracelet/bubbletea v0.20.0/go.mod h1:zpkze1Rioo4rJELjRyGlm9T2YNou1Fm4LIJQSa5QMEM=
github.com/charmbracelet/harmonica v0.1.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/lipgloss v0.4.0 h1:768h64EFkGUr8V5yAKV7/Ta0NiVceiPaV+PphaW1K9g=
github.com/charmbracelet/lipgloss v0.4.0/go.mod h1:vmdkHvce7UzX6xkyf4cca8WlwdQ5RQr8fzta+xl7BOM=
github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ=
github.com/charmbracelet/bubbles v0.13.0 h1:zP/ROH3wJEBqZWKIsD50ZKKlx3ydLInq3LdD/Nrlb8w=
github.com/charmbracelet/bubbles v0.13.0/go.mod h1:bbeTiXwPww4M031aGi8UK2HT9RDWoiNibae+1yCMtcc=
github.com/charmbracelet/bubbletea v0.21.0/go.mod h1:GgmJMec61d08zXsOhqRC/AiOx4K4pmz+VIcRIm1FKr4=
github.com/charmbracelet/bubbletea v0.22.1 h1:z66q0LWdJNOWEH9zadiAIXp2GN1AWrwNXU8obVY9X24=
github.com/charmbracelet/bubbletea v0.22.1/go.mod h1:8/7hVvbPN6ZZPkczLiB8YpLkLJ0n7DMho5Wvfd2X1C0=
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8=
github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 h1:kMlmsLSbjkikxQJ1IPwaM+7LJ9ltFu/fi8CRzvSnQmA=
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
github.com/muesli/cancelreader v0.2.0/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/muesli/termenv v0.9.0/go.mod h1:R/LzAKf+suGs4IsO95y7+7DpFHO0KABgnZqtlyx2mBw=
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 h1:QANkGiGr39l1EESqrE0gZw0/AJNYzIvoGLhIoVYtluI=
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/muesli/termenv v0.12.0 h1:KuQRUE3PgxRFWhq4gHvZtPSLCGDqM5q/cYr1pZ39ytc=
github.com/muesli/termenv v0.12.0/go.mod h1:WCCv32tusQ/EEZ5S8oUIIrC/nIuBcxCVqlN4Xfkv+7A=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.3.4 h1:3Z3Eu6FGHZWSfNKJTOUiPatWwfc7DzJRU04jFUqJODw=
github.com/rivo/uniseg v0.3.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed h1:Ei4bQjjpYUsS4efOUz+5Nz++IVkHk87n2zBA0NxBWc0=
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 h1:Sx/u41w+OwrInGdEckYmEuU5gHoGSL4QbDz3S9s6j4U=
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View File

@ -16,13 +16,14 @@ func (i jEntry) ID() string { return i.id }
func (i jEntry) FilterValue() string { return i.title }
type jMenuModel struct {
acc *Account
list list.Model
lastSize tea.WindowSizeMsg
}
type readMsg string
func newJMenuModel(pages []sim.JournalPage) jMenuModel {
func newJMenuModel(pages []sim.JournalPage, acc *Account) jMenuModel {
var jm jMenuModel
items := []list.Item{}
for _, v := range pages {
@ -31,6 +32,7 @@ func newJMenuModel(pages []sim.JournalPage) jMenuModel {
jm.list = list.New(items, list.NewDefaultDelegate(), 80, 32)
jm.list.DisableQuitKeybindings()
jm.list.Title = "Read which entry?"
jm.acc = acc
return jm
}
@ -50,11 +52,11 @@ func (j jMenuModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg:
switch keypress := msg.String(); keypress {
case "ctrl-c":
return j, tea.Quit
return j, tea.Batch(tea.Quit, j.GetSize)
case "esc":
return initMainscreen(), tea.Batch(j.GetSize, heartbeat())
return initMainscreen(j.acc), tea.Batch(j.GetSize, heartbeat())
case "enter":
return initMainscreen(), tea.Batch(j.GetSize, j.buildJmenuMsg, heartbeat())
return initMainscreen(j.acc), tea.Batch(j.GetSize, j.buildJmenuMsg, heartbeat())
}
}

View File

@ -31,10 +31,11 @@ type jview struct {
ready bool
lastSize tea.WindowSizeMsg
viewport viewport.Model
acc *Account
}
func newJView(title, content string) jview {
return jview{title: title, content: content}
func newJView(title, content string, acc *Account) jview {
return jview{title: title, content: content, acc: acc}
}
func (m jview) Init() tea.Cmd {
@ -50,7 +51,7 @@ func (m jview) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
if k := msg.String(); k == "ctrl+c" || k == "q" || k == "esc" {
return initMainscreen(), tea.Batch(m.GetSize, heartbeat())
return initMainscreen(m.acc), tea.Batch(m.GetSize, heartbeat())
}
case tea.WindowSizeMsg:

15
main.go
View File

@ -5,15 +5,22 @@ 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()
player := sim.NewPlayer()
acc := &Account{
Player: player,
Simulator: simulator,
Landmark: nil,
}
sim.Demo(acc.Player, acc.Simulator)
simulator.Start()
parent := parent{initMainscreen()}
parent := parent{initMainscreen(acc)}
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

@ -28,6 +28,7 @@ type model struct {
keys keyMap
next string
lastSize tea.WindowSizeMsg
acc *Account
}
type beat struct{}
@ -47,17 +48,18 @@ func (m model) simCommand() tea.Msg {
}
return nil
}
func initMainscreen() model {
func initMainscreen(acc *Account) model {
ti := textinput.New()
ti.Placeholder = "input command"
ti.CharLimit = 156
ti.Width = 20
return model{
s: simulator,
s: acc.Simulator,
input: ti,
help: help.New(),
keys: keys,
acc: acc,
}
}
func (m model) Init() tea.Cmd {
@ -87,7 +89,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if err != nil {
panic(err)
}
return newJView(sim.GlobalPages[pid].Title, sim.GlobalPages[pid].Content), m.GetSize
return newJView(sim.GlobalPages[pid].Title, sim.GlobalPages[pid].Content, m.acc), m.GetSize
case tea.KeyMsg:
switch {
case key.Matches(msg, m.keys.Help):
@ -118,7 +120,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
sort.Sort(res)
return newMenuModel(res, placeMenu), m.GetSize
return newMenuModel(res, placeMenu, m.acc), m.GetSize
case key.Matches(msg, m.keys.Pickup):
m.s.Input("pickup")
case key.Matches(msg, m.keys.Destroy):
@ -129,14 +131,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
res = append(res, sim.GlobalItems[k].(sim.ItemEntry))
}
sort.Sort(res)
return newMenuModel(res, craftMenu), m.GetSize
return newMenuModel(res, craftMenu, m.acc), m.GetSize
case key.Matches(msg, m.keys.Journal):
var res pagelist
for k := range m.s.Player.Pages {
res = append(res, sim.GlobalPages[k])
}
sort.Sort(res)
return newJMenuModel(res), m.GetSize
return newJMenuModel(res, m.acc), m.GetSize
}
}
m.input, cmd = m.input.Update(msg)

View File

@ -31,13 +31,15 @@ type menuModel struct {
list list.Model
kind menutype
lastSize tea.WindowSizeMsg
acc *Account
}
type placeMsg string
type craftMsg string
func newMenuModel(entries []sim.ItemEntry, i menutype) menuModel {
func newMenuModel(entries []sim.ItemEntry, i menutype, acc *Account) menuModel {
var p menuModel
p.acc = acc
p.kind = i
items := []list.Item{}
for _, v := range entries {
@ -89,9 +91,9 @@ func (p menuModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "ctrl-c":
return p, tea.Quit
case "esc":
return initMainscreen(), tea.Batch(p.GetSize, heartbeat())
return initMainscreen(p.acc), tea.Batch(p.GetSize, heartbeat())
case "enter":
return initMainscreen(), tea.Batch(p.GetSize, p.buildMenuMsg, heartbeat())
return initMainscreen(p.acc), tea.Batch(p.GetSize, p.buildMenuMsg, heartbeat())
}
}

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:"landmarkid"`
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

@ -16,10 +16,19 @@ type Simulator struct {
stop chan bool
}
func Demo(p *Player, s *Simulator) {
pod := newPod()
pod.Place(newResource(lookupByName("tea").ID()), 4, 4)
p.AddItem(itemType(1), 30)
p.AddItem(itemType(3), 5)
pod.Tiles[0][0].User = p
p.Announce("Game started")
s.Place = pod
s.Player = p
}
//NewSimulator creates a new simulator instance
func NewSimulator() *Simulator {
pod := newPod()
player := NewPlayer()
log.Println("loading items")
initItems()
log.Println("loading techs")
@ -30,6 +39,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,12 +50,11 @@ func NewSimulator() *Simulator {
if len(GlobalPages) < 1 {
panic("Loaded journal but no pages in table")
}
pod.Place(newResource(lookupByName("tea").ID()), 4, 4)
player.AddItem(itemType(1), 30)
player.AddItem(itemType(3), 5)
pod.Tiles[0][0].User = player
player.Announce("Game started")
return &Simulator{pod, player, 0, 0, 0, make(chan bool)}
if len(GlobalLandmarks) < 1 {
panic("Loaded landmarks but nothing in table")
}
return &Simulator{nil, nil, 0, 0, 0, make(chan bool)}
}
//Start begins the simulation, non blocking