you can now look at stuff, it's DOPE

master
Jordan Orelli 4 years ago
parent f132a11929
commit 49659ce876

@ -60,19 +60,19 @@ func (v *gameView) lookHandler(e *tcell.EventKey) change {
case 'w': case 'w':
v.keyHandler = v.walkHandler v.keyHandler = v.walkHandler
v.statusLine = "(walk)" v.statusLine = "(walk)"
return lookAt{0, -1} return &lookAt{x: 0, y: -1}
case 'a': case 'a':
v.keyHandler = v.walkHandler v.keyHandler = v.walkHandler
v.statusLine = "(walk)" v.statusLine = "(walk)"
return lookAt{-1, 0} return &lookAt{x: -1, y: 0}
case 's': case 's':
v.keyHandler = v.walkHandler v.keyHandler = v.walkHandler
v.statusLine = "(walk)" v.statusLine = "(walk)"
return lookAt{0, 1} return &lookAt{x: 0, y: 1}
case 'd': case 'd':
v.keyHandler = v.walkHandler v.keyHandler = v.walkHandler
v.statusLine = "(walk)" v.statusLine = "(walk)"
return lookAt{1, 0} return &lookAt{x: 1, y: 0}
} }
} }
return nil return nil
@ -83,9 +83,10 @@ func (v *gameView) draw(img canvas, st *state) {
v.drawHeader(img, st) v.drawHeader(img, st)
// fill in background dots first // fill in background dots first
dim := tcell.StyleDefault.Foreground(tcell.NewRGBColor(76, 72, 83))
for x := 0; x < st.room.Width; x++ { for x := 0; x < st.room.Width; x++ {
for y := 0; y < st.room.Height; y++ { 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: '┌'}) img.setTile(0, 1, tile{r: '┌'})
@ -137,11 +138,12 @@ func (m move) exec(ui *UI) {
} }
type lookAt struct { type lookAt struct {
x int x int
y int y int
results *sim.Look
} }
func (l lookAt) exec(ui *UI) { func (l *lookAt) exec(ui *UI) {
go func() { go func() {
res, err := ui.client.Send(sim.LookAt{l.x, l.y}) res, err := ui.client.Send(sim.LookAt{l.x, l.y})
if err != nil { if err != nil {
@ -155,6 +157,25 @@ func (l lookAt) exec(ui *UI) {
return 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)
}
}

@ -1,6 +1,7 @@
package app package app
import ( import (
"github.com/gdamore/tcell/v2"
"github.com/jordanorelli/astro-domu/internal/sim" "github.com/jordanorelli/astro-domu/internal/sim"
"github.com/jordanorelli/astro-domu/internal/wire" "github.com/jordanorelli/astro-domu/internal/wire"
) )
@ -9,4 +10,26 @@ type state struct {
playerName string playerName string
room *wire.Room room *wire.Room
history []sim.ChatMessage 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)
} }

@ -68,6 +68,8 @@ func (ui *UI) Run() {
case n := <-notify: case n := <-notify:
ui.Info("notification: %v", n) ui.Info("notification: %v", n)
ui.handleNotification(n.Body) 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}, frame: math.Rect{math.Vec{4, 0}, 4, 4},
view: &borderedView{ view: &borderedView{
inner: &menuList{ inner: &detailView{},
choices: []menuItem{
menuItem{name: "chocolate"},
menuItem{name: "vanilla"},
menuItem{name: "strawberry"},
menuItem{name: "banana"},
},
},
}, },
}, },
{ {

Loading…
Cancel
Save