From a6d74089eedbe8b157646d0154b4d16ef3501d15 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 22 Aug 2022 19:00:15 -0400 Subject: [PATCH] pass around accounts --- go.mod | 23 +++++++++------- go.sum | 60 +++++++++++++++++++++++++----------------- jmenu.go | 8 +++--- jview.go | 7 ++--- main.go | 8 +++++- mainscreen.go | 14 +++++----- menu.go | 8 +++--- simulator/landmark.go | 2 +- simulator/simulator.go | 21 +++++++++------ 9 files changed, 92 insertions(+), 59 deletions(-) diff --git a/go.mod b/go.mod index e5c6d54..208c6c1 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 087a16e..fdb9cf1 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/jmenu.go b/jmenu.go index c0e5c14..ddea30c 100644 --- a/jmenu.go +++ b/jmenu.go @@ -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 } @@ -52,9 +54,9 @@ func (j jMenuModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case "ctrl-c": return j, tea.Quit 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()) } } diff --git a/jview.go b/jview.go index d981d73..e312ce2 100644 --- a/jview.go +++ b/jview.go @@ -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: diff --git a/main.go b/main.go index 32eac91..698d48a 100644 --- a/main.go +++ b/main.go @@ -11,8 +11,14 @@ import ( func main() { simulator := sim.NewSimulator() + sim.Demo(simulator) + acc := &Account{ + Player: simulator.Player, + Simulator: simulator, + Landmark: nil, + } simulator.Start() - parent := parent{initMainscreen(simulator)} + 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) diff --git a/mainscreen.go b/mainscreen.go index 3527c7f..0aff0e2 100644 --- a/mainscreen.go +++ b/mainscreen.go @@ -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(sim *simulator) model { +func initMainscreen(acc *Account) model { ti := textinput.New() ti.Placeholder = "input command" ti.CharLimit = 156 ti.Width = 20 return model{ - s: sim, + 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) diff --git a/menu.go b/menu.go index 4da7031..7a42741 100644 --- a/menu.go +++ b/menu.go @@ -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()) } } diff --git a/simulator/landmark.go b/simulator/landmark.go index ea3fbf0..6bea09a 100644 --- a/simulator/landmark.go +++ b/simulator/landmark.go @@ -11,7 +11,7 @@ type LandmarkID int //Landmark is a flavour location type Landmark struct { - LandmarkID LandmarkID `toml:"pageid"` + LandmarkID LandmarkID `toml:"landmarkid"` Name string `toml:"title"` Content string `toml:"content"` Links []LandmarkID `toml:"links"` diff --git a/simulator/simulator.go b/simulator/simulator.go index f3a8a59..1844ae6 100644 --- a/simulator/simulator.go +++ b/simulator/simulator.go @@ -16,10 +16,20 @@ type Simulator struct { stop chan bool } -//NewSimulator creates a new simulator instance -func NewSimulator() *Simulator { +func Demo(s *Simulator) { pod := newPod() player := NewPlayer() + 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") + s.Place = pod + s.Player = player +} + +//NewSimulator creates a new simulator instance +func NewSimulator() *Simulator { log.Println("loading items") initItems() log.Println("loading techs") @@ -45,12 +55,7 @@ func NewSimulator() *Simulator { 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) - pod.Tiles[0][0].User = player - player.Announce("Game started") - return &Simulator{pod, player, 0, 0, 0, make(chan bool)} + return &Simulator{nil, nil, 0, 0, 0, make(chan bool)} } //Start begins the simulation, non blocking