From 49659ce8760d559d88f360fc150b2dd9929a1aa9 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Tue, 10 Nov 2020 01:15:08 +0000 Subject: [PATCH] you can now look at stuff, it's DOPE --- internal/app/game_view.go | 39 ++++++++++++++++++++++++++++++--------- internal/app/state.go | 23 +++++++++++++++++++++++ internal/app/ui.go | 11 +++-------- 3 files changed, 56 insertions(+), 17 deletions(-) diff --git a/internal/app/game_view.go b/internal/app/game_view.go index 12a9582..8023a06 100644 --- a/internal/app/game_view.go +++ b/internal/app/game_view.go @@ -60,19 +60,19 @@ func (v *gameView) lookHandler(e *tcell.EventKey) change { case 'w': v.keyHandler = v.walkHandler v.statusLine = "(walk)" - return lookAt{0, -1} + return &lookAt{x: 0, y: -1} case 'a': v.keyHandler = v.walkHandler v.statusLine = "(walk)" - return lookAt{-1, 0} + return &lookAt{x: -1, y: 0} case 's': v.keyHandler = v.walkHandler v.statusLine = "(walk)" - return lookAt{0, 1} + return &lookAt{x: 0, y: 1} case 'd': v.keyHandler = v.walkHandler v.statusLine = "(walk)" - return lookAt{1, 0} + return &lookAt{x: 1, y: 0} } } return nil @@ -83,9 +83,10 @@ func (v *gameView) draw(img canvas, st *state) { v.drawHeader(img, st) // fill in background dots first + dim := tcell.StyleDefault.Foreground(tcell.NewRGBColor(76, 72, 83)) for x := 0; x < st.room.Width; x++ { for y := 0; y < st.room.Height; y++ { - img.setTile(x+1, y+2, tile{r: '·', style: tcell.StyleDefault}) + img.setTile(x+1, y+2, tile{r: '·', style: dim}) } } img.setTile(0, 1, tile{r: '┌'}) @@ -137,11 +138,12 @@ func (m move) exec(ui *UI) { } type lookAt struct { - x int - y int + x int + y int + results *sim.Look } -func (l lookAt) exec(ui *UI) { +func (l *lookAt) exec(ui *UI) { go func() { res, err := ui.client.Send(sim.LookAt{l.x, l.y}) if err != nil { @@ -155,6 +157,25 @@ func (l lookAt) exec(ui *UI) { return } - ui.Info("look: %v", look) + l.results = look + ui.misc <- func(ui *UI) { + ui.Info("setting detail view to %T", l) + ui.state.detail = l + } }() } + +func (l *lookAt) handleEvent(e tcell.Event) change { + return nil +} + +func (l *lookAt) draw(img canvas, st *state) { + if len(l.results.Here) == 0 { + writeString(img, "there's nothing here...", math.Vec{0, 0}, tcell.StyleDefault) + return + } + + for i, item := range l.results.Here { + writeString(img, item.Name, math.Vec{0, i}, tcell.StyleDefault) + } +} diff --git a/internal/app/state.go b/internal/app/state.go index 6a19059..9025a53 100644 --- a/internal/app/state.go +++ b/internal/app/state.go @@ -1,6 +1,7 @@ package app import ( + "github.com/gdamore/tcell/v2" "github.com/jordanorelli/astro-domu/internal/sim" "github.com/jordanorelli/astro-domu/internal/wire" ) @@ -9,4 +10,26 @@ type state struct { playerName string room *wire.Room history []sim.ChatMessage + detail view +} + +// detailView is a proxy view. Wherever you put a detailView, you get the +// current view assigned to the detail in the room state +type detailView struct { + showing view +} + +func (v *detailView) handleEvent(e tcell.Event) change { + if v.showing == nil { + return nil + } + return v.showing.handleEvent(e) +} + +func (v *detailView) draw(img canvas, st *state) { + v.showing = st.detail + if v.showing == nil { + return + } + v.showing.draw(img, st) } diff --git a/internal/app/ui.go b/internal/app/ui.go index fa0ac97..6a2a3a8 100644 --- a/internal/app/ui.go +++ b/internal/app/ui.go @@ -68,6 +68,8 @@ func (ui *UI) Run() { case n := <-notify: ui.Info("notification: %v", n) ui.handleNotification(n.Body) + case f := <-ui.misc: + f(ui) } } } @@ -212,14 +214,7 @@ var inGameView = &containerView{ { frame: math.Rect{math.Vec{4, 0}, 4, 4}, view: &borderedView{ - inner: &menuList{ - choices: []menuItem{ - menuItem{name: "chocolate"}, - menuItem{name: "vanilla"}, - menuItem{name: "strawberry"}, - menuItem{name: "banana"}, - }, - }, + inner: &detailView{}, }, }, {