pass around accounts

This commit is contained in:
stryan 2022-08-22 19:00:15 -04:00
parent cc84c4c15c
commit a6d74089ee
9 changed files with 92 additions and 59 deletions

23
go.mod
View File

@ -3,23 +3,26 @@ module git.saintnet.tech/stryan/spacetea
go 1.18 go 1.18
require ( require (
github.com/BurntSushi/toml v1.1.0 github.com/BurntSushi/toml v1.2.0
github.com/charmbracelet/bubbles v0.10.3 github.com/charmbracelet/bubbles v0.13.0
github.com/charmbracelet/bubbletea v0.20.0 github.com/charmbracelet/bubbletea v0.22.1
github.com/charmbracelet/lipgloss v0.4.0 github.com/charmbracelet/lipgloss v0.5.0
) )
require ( require (
github.com/atotto/clipboard v0.1.4 // indirect github.com/atotto/clipboard v0.1.4 // indirect
github.com/containerd/console v1.0.3 // indirect github.com/containerd/console v1.0.3 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // 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/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/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect github.com/muesli/termenv v0.12.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect github.com/rivo/uniseg v0.3.4 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect github.com/sahilm/fuzzy v0.1.0 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed // 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.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= 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 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= 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.13.0 h1:zP/ROH3wJEBqZWKIsD50ZKKlx3ydLInq3LdD/Nrlb8w=
github.com/charmbracelet/bubbles v0.10.3/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA= github.com/charmbracelet/bubbles v0.13.0/go.mod h1:bbeTiXwPww4M031aGi8UK2HT9RDWoiNibae+1yCMtcc=
github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA= github.com/charmbracelet/bubbletea v0.21.0/go.mod h1:GgmJMec61d08zXsOhqRC/AiOx4K4pmz+VIcRIm1FKr4=
github.com/charmbracelet/bubbletea v0.20.0 h1:/b8LEPgCbNr7WWZ2LuE/BV1/r4t5PyYJtDb+J3vpwxc= github.com/charmbracelet/bubbletea v0.22.1 h1:z66q0LWdJNOWEH9zadiAIXp2GN1AWrwNXU8obVY9X24=
github.com/charmbracelet/bubbletea v0.20.0/go.mod h1:zpkze1Rioo4rJELjRyGlm9T2YNou1Fm4LIJQSa5QMEM= github.com/charmbracelet/bubbletea v0.22.1/go.mod h1:8/7hVvbPN6ZZPkczLiB8YpLkLJ0n7DMho5Wvfd2X1C0=
github.com/charmbracelet/harmonica v0.1.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/lipgloss v0.4.0 h1:768h64EFkGUr8V5yAKV7/Ta0NiVceiPaV+PphaW1K9g= github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8=
github.com/charmbracelet/lipgloss v0.4.0/go.mod h1:vmdkHvce7UzX6xkyf4cca8WlwdQ5RQr8fzta+xl7BOM= github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs=
github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= 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 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 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 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= 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.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.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.12/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 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 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-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.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 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= 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.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 h1:QANkGiGr39l1EESqrE0gZw0/AJNYzIvoGLhIoVYtluI=
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/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.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.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 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= 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-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/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/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 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 } func (i jEntry) FilterValue() string { return i.title }
type jMenuModel struct { type jMenuModel struct {
acc *Account
list list.Model list list.Model
lastSize tea.WindowSizeMsg lastSize tea.WindowSizeMsg
} }
type readMsg string type readMsg string
func newJMenuModel(pages []sim.JournalPage) jMenuModel { func newJMenuModel(pages []sim.JournalPage, acc *Account) jMenuModel {
var jm jMenuModel var jm jMenuModel
items := []list.Item{} items := []list.Item{}
for _, v := range pages { 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 = list.New(items, list.NewDefaultDelegate(), 80, 32)
jm.list.DisableQuitKeybindings() jm.list.DisableQuitKeybindings()
jm.list.Title = "Read which entry?" jm.list.Title = "Read which entry?"
jm.acc = acc
return jm return jm
} }
@ -52,9 +54,9 @@ func (j jMenuModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "ctrl-c": case "ctrl-c":
return j, tea.Quit return j, tea.Quit
case "esc": case "esc":
return initMainscreen(), tea.Batch(j.GetSize, heartbeat()) return initMainscreen(j.acc), tea.Batch(j.GetSize, heartbeat())
case "enter": 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 ready bool
lastSize tea.WindowSizeMsg lastSize tea.WindowSizeMsg
viewport viewport.Model viewport viewport.Model
acc *Account
} }
func newJView(title, content string) jview { func newJView(title, content string, acc *Account) jview {
return jview{title: title, content: content} return jview{title: title, content: content, acc: acc}
} }
func (m jview) Init() tea.Cmd { 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) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
if k := msg.String(); k == "ctrl+c" || k == "q" || k == "esc" { 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: case tea.WindowSizeMsg:

View File

@ -11,8 +11,14 @@ import (
func main() { func main() {
simulator := sim.NewSimulator() simulator := sim.NewSimulator()
sim.Demo(simulator)
acc := &Account{
Player: simulator.Player,
Simulator: simulator,
Landmark: nil,
}
simulator.Start() simulator.Start()
parent := parent{initMainscreen(simulator)} parent := parent{initMainscreen(acc)}
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)

View File

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

View File

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

View File

@ -11,7 +11,7 @@ type LandmarkID int
//Landmark is a flavour location //Landmark is a flavour location
type Landmark struct { type Landmark struct {
LandmarkID LandmarkID `toml:"pageid"` LandmarkID LandmarkID `toml:"landmarkid"`
Name string `toml:"title"` Name string `toml:"title"`
Content string `toml:"content"` Content string `toml:"content"`
Links []LandmarkID `toml:"links"` Links []LandmarkID `toml:"links"`

View File

@ -16,10 +16,20 @@ type Simulator struct {
stop chan bool stop chan bool
} }
//NewSimulator creates a new simulator instance func Demo(s *Simulator) {
func NewSimulator() *Simulator {
pod := newPod() pod := newPod()
player := NewPlayer() 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") log.Println("loading items")
initItems() initItems()
log.Println("loading techs") log.Println("loading techs")
@ -45,12 +55,7 @@ func NewSimulator() *Simulator {
panic("Loaded landmarks but nothing in table") panic("Loaded landmarks but nothing in table")
} }
pod.Place(newResource(lookupByName("tea").ID()), 4, 4) return &Simulator{nil, nil, 0, 0, 0, make(chan bool)}
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)}
} }
//Start begins the simulation, non blocking //Start begins the simulation, non blocking