|
|
@ -2,6 +2,7 @@ package app
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
|
|
|
|
"github.com/jordanorelli/astro-domu/internal/math"
|
|
|
|
"github.com/jordanorelli/astro-domu/internal/sim"
|
|
|
|
"github.com/jordanorelli/astro-domu/internal/sim"
|
|
|
|
"github.com/jordanorelli/blammo"
|
|
|
|
"github.com/jordanorelli/blammo"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -9,14 +10,28 @@ import (
|
|
|
|
type gameView struct {
|
|
|
|
type gameView struct {
|
|
|
|
*blammo.Log
|
|
|
|
*blammo.Log
|
|
|
|
inFocus bool
|
|
|
|
inFocus bool
|
|
|
|
|
|
|
|
keyHandler func(*tcell.EventKey) change
|
|
|
|
|
|
|
|
statusLine string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (v *gameView) handleEvent(e tcell.Event) change {
|
|
|
|
func (v *gameView) handleEvent(e tcell.Event) change {
|
|
|
|
|
|
|
|
if v.keyHandler == nil {
|
|
|
|
|
|
|
|
v.keyHandler = v.walkHandler
|
|
|
|
|
|
|
|
v.statusLine = "(walk)"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch t := e.(type) {
|
|
|
|
switch t := e.(type) {
|
|
|
|
case *tcell.EventKey:
|
|
|
|
case *tcell.EventKey:
|
|
|
|
key := t.Key()
|
|
|
|
return v.keyHandler(t)
|
|
|
|
if key == tcell.KeyRune {
|
|
|
|
default:
|
|
|
|
switch t.Rune() {
|
|
|
|
// ui.Debug("screen saw unhandled event of type %T", e)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (v *gameView) walkHandler(e *tcell.EventKey) change {
|
|
|
|
|
|
|
|
if e.Key() == tcell.KeyRune {
|
|
|
|
|
|
|
|
switch e.Rune() {
|
|
|
|
case 'w':
|
|
|
|
case 'w':
|
|
|
|
return move{0, -1}
|
|
|
|
return move{0, -1}
|
|
|
|
case 'a':
|
|
|
|
case 'a':
|
|
|
@ -25,10 +40,40 @@ func (v *gameView) handleEvent(e tcell.Event) change {
|
|
|
|
return move{0, 1}
|
|
|
|
return move{0, 1}
|
|
|
|
case 'd':
|
|
|
|
case 'd':
|
|
|
|
return move{1, 0}
|
|
|
|
return move{1, 0}
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
|
|
|
|
v.keyHandler = v.lookHandler
|
|
|
|
|
|
|
|
v.statusLine = "(look)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
// ui.Debug("screen saw unhandled event of type %T", e)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (v *gameView) lookHandler(e *tcell.EventKey) change {
|
|
|
|
|
|
|
|
if e.Key() == tcell.KeyESC {
|
|
|
|
|
|
|
|
v.keyHandler = v.walkHandler
|
|
|
|
|
|
|
|
v.statusLine = "(walk)"
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if e.Key() == tcell.KeyRune {
|
|
|
|
|
|
|
|
switch e.Rune() {
|
|
|
|
|
|
|
|
case 'w':
|
|
|
|
|
|
|
|
v.keyHandler = v.walkHandler
|
|
|
|
|
|
|
|
v.statusLine = "(walk)"
|
|
|
|
|
|
|
|
return lookAt{0, -1}
|
|
|
|
|
|
|
|
case 'a':
|
|
|
|
|
|
|
|
v.keyHandler = v.walkHandler
|
|
|
|
|
|
|
|
v.statusLine = "(walk)"
|
|
|
|
|
|
|
|
return lookAt{-1, 0}
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
|
|
|
|
v.keyHandler = v.walkHandler
|
|
|
|
|
|
|
|
v.statusLine = "(walk)"
|
|
|
|
|
|
|
|
return lookAt{0, 1}
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
|
|
|
|
v.keyHandler = v.walkHandler
|
|
|
|
|
|
|
|
v.statusLine = "(walk)"
|
|
|
|
|
|
|
|
return lookAt{1, 0}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -59,6 +104,7 @@ func (v *gameView) draw(img canvas, st *state) {
|
|
|
|
pos := e.Position
|
|
|
|
pos := e.Position
|
|
|
|
img.setTile(pos.X+1, pos.Y+2, tile{r: e.Glyph, style: tcell.StyleDefault})
|
|
|
|
img.setTile(pos.X+1, pos.Y+2, tile{r: e.Glyph, style: tcell.StyleDefault})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
writeString(img, v.statusLine, math.Vec{0, img.bounds().Height - 1}, tcell.StyleDefault)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (v *gameView) drawHeader(img canvas, st *state) {
|
|
|
|
func (v *gameView) drawHeader(img canvas, st *state) {
|
|
|
@ -89,3 +135,26 @@ type move struct {
|
|
|
|
func (m move) exec(ui *UI) {
|
|
|
|
func (m move) exec(ui *UI) {
|
|
|
|
go ui.client.Send(sim.Move{m.x, m.y})
|
|
|
|
go ui.client.Send(sim.Move{m.x, m.y})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type lookAt struct {
|
|
|
|
|
|
|
|
x int
|
|
|
|
|
|
|
|
y int
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (l lookAt) exec(ui *UI) {
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
res, err := ui.client.Send(sim.LookAt{l.x, l.y})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
ui.Error("look error: %v", err)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
look, ok := res.Body.(*sim.Look)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
ui.Error("look response is not look: %v", res.Body)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ui.Info("look: %v", look)
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
}
|
|
|
|