Added way to get user input events from Spectator
This commit is contained in:
parent
15f1ad15f4
commit
aaf2641d80
10
spectator.go
10
spectator.go
@ -37,6 +37,10 @@ type Spectator struct {
|
|||||||
|
|
||||||
// when closed will cause the Spectator to exit the render loop.
|
// when closed will cause the Spectator to exit the render loop.
|
||||||
Die chan struct{}
|
Die chan struct{}
|
||||||
|
|
||||||
|
// User, if populated, will return a stream of (ostensibly keyboard) events
|
||||||
|
// for use outside of the Spectator.
|
||||||
|
User chan termbox.Event
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetIDs is implemented so Spectator can be used as a client.Player.
|
// SetIDs is implemented so Spectator can be used as a client.Player.
|
||||||
@ -58,6 +62,8 @@ func (s *Spectator) Spectate() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
termbox.SetInputMode(termbox.InputMouse)
|
||||||
|
|
||||||
s.viewX, s.viewY = termbox.Size()
|
s.viewX, s.viewY = termbox.Size()
|
||||||
|
|
||||||
events := make(chan termbox.Event, 1024)
|
events := make(chan termbox.Event, 1024)
|
||||||
@ -101,6 +107,10 @@ func (s *Spectator) Spectate() error {
|
|||||||
err = fmt.Errorf("Quitting because of termbox error:\n%v\n", event.Err)
|
err = fmt.Errorf("Quitting because of termbox error:\n%v\n", event.Err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.User != nil {
|
||||||
|
s.User <- event
|
||||||
|
}
|
||||||
case update := <-s.StateStream:
|
case update := <-s.StateStream:
|
||||||
termbox.Clear(termbox.ColorBlack, termbox.ColorBlack)
|
termbox.Clear(termbox.ColorBlack, termbox.ColorBlack)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user