From 5fc2aed131368f9dcea54afcf2b88e4d172c35a6 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Thu, 29 Oct 2020 02:14:16 +0000 Subject: [PATCH] observe the wallllllls --- internal/ui/mode.go | 27 +++++++++++++++------------ internal/wire/client.go | 5 +++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/internal/ui/mode.go b/internal/ui/mode.go index c735826..970febc 100644 --- a/internal/ui/mode.go +++ b/internal/ui/mode.go @@ -23,17 +23,13 @@ func (m *roomDisplay) handleEvent(ui *UI, e tcell.Event) bool { if key == tcell.KeyRune { switch v.Rune() { case 'w': - go ui.client.Send(sim.Move{0, -1}) - // m.move(0, -1) + m.move(ui, 0, -1) case 'a': - go ui.client.Send(sim.Move{-1, 0}) - // m.move(-1, 0) + m.move(ui, -1, 0) case 's': - go ui.client.Send(sim.Move{0, 1}) - // m.move(0, 1) + m.move(ui, 0, 1) case 'd': - go ui.client.Send(sim.Move{1, 0}) - // m.move(1, 0) + m.move(ui, 1, 0) } } default: @@ -42,9 +38,16 @@ func (m *roomDisplay) handleEvent(ui *UI, e tcell.Event) bool { return true } -func (m *roomDisplay) move(dx, dy int) { - 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) move(ui *UI, dx, dy int) { + reply, err := ui.client.Send(sim.Move{dx, dy}) + if err != nil { + return + } + e := reply.Body.(*sim.Entity) + m.position.x = e.Position[0] + 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) { @@ -72,5 +75,5 @@ func (m *roomDisplay) draw(ui *UI) { } // add all characters - // ui.screen.SetContent(m.position.x+offset.x, m.position.y+offset.y, '@', nil, tcell.StyleDefault) + ui.screen.SetContent(m.position.x+offset.x, m.position.y+offset.y, '@', nil, tcell.StyleDefault) } diff --git a/internal/wire/client.go b/internal/wire/client.go index 361558f..40ab357 100644 --- a/internal/wire/client.go +++ b/internal/wire/client.go @@ -75,6 +75,11 @@ func (c *Client) Send(v Value) (Response, error) { select { case <-done: + if p.err == nil { + if err, ok := p.res.Body.(error); ok { + return p.res, err + } + } return p.res, p.err case <-timeout.C: return Response{}, fmt.Errorf("send timed out (2) after %v", d)