|
|
@ -3,17 +3,19 @@ package ui
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
"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"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type Mode interface {
|
|
|
|
type Mode interface {
|
|
|
|
handleEvent(*UI, tcell.Event) bool
|
|
|
|
handleEvent(*UI, tcell.Event) bool
|
|
|
|
|
|
|
|
notify(wire.Value)
|
|
|
|
draw(*UI)
|
|
|
|
draw(*UI)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type roomDisplay struct {
|
|
|
|
type roomDisplay struct {
|
|
|
|
width int
|
|
|
|
width int
|
|
|
|
height int
|
|
|
|
height int
|
|
|
|
position point
|
|
|
|
entities map[int]sim.Entity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *roomDisplay) handleEvent(ui *UI, e tcell.Event) bool {
|
|
|
|
func (m *roomDisplay) handleEvent(ui *UI, e tcell.Event) bool {
|
|
|
@ -38,16 +40,19 @@ func (m *roomDisplay) handleEvent(ui *UI, e tcell.Event) bool {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *roomDisplay) notify(v wire.Value) {
|
|
|
|
|
|
|
|
if e, ok := v.(*sim.Entity); ok {
|
|
|
|
|
|
|
|
m.entities[e.ID] = *e
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *roomDisplay) move(ui *UI, dx, dy int) {
|
|
|
|
func (m *roomDisplay) move(ui *UI, dx, dy int) {
|
|
|
|
reply, err := ui.client.Send(sim.Move{dx, dy})
|
|
|
|
reply, err := ui.client.Send(sim.Move{dx, dy})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e := reply.Body.(*sim.Entity)
|
|
|
|
e := reply.Body.(*sim.Entity)
|
|
|
|
m.position.x = e.Position[0]
|
|
|
|
m.entities[e.ID] = *e
|
|
|
|
m.position.y = e.Position[1]
|
|
|
|
|
|
|
|
// m.position.x = clamp(m.position.x+dx, 0, m.width-1)
|
|
|
|
|
|
|
|
// m.position.y = clamp(m.position.y+dy, 0, m.height-1)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *roomDisplay) draw(ui *UI) {
|
|
|
|
func (m *roomDisplay) draw(ui *UI) {
|
|
|
@ -74,6 +79,7 @@ func (m *roomDisplay) draw(ui *UI) {
|
|
|
|
ui.screen.SetContent(offset.x+m.width, y+offset.y, '│', nil, tcell.StyleDefault)
|
|
|
|
ui.screen.SetContent(offset.x+m.width, y+offset.y, '│', nil, tcell.StyleDefault)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add all characters
|
|
|
|
for _, e := range m.entities {
|
|
|
|
ui.screen.SetContent(m.position.x+offset.x, m.position.y+offset.y, '@', nil, tcell.StyleDefault)
|
|
|
|
ui.screen.SetContent(e.Position[0]+offset.x, e.Position[1]+offset.y, e.Glyph, nil, tcell.StyleDefault)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|