2018-06-17 02:59:23 +00:00
|
|
|
package events
|
|
|
|
|
2018-06-17 14:56:51 +00:00
|
|
|
// BoolTick holds boolean state between this frame and the previous.
|
|
|
|
type BoolTick struct {
|
2018-06-17 02:59:23 +00:00
|
|
|
Now bool
|
|
|
|
Last bool
|
|
|
|
}
|
|
|
|
|
2018-06-17 14:56:51 +00:00
|
|
|
// Int32Tick manages int32 state between this frame and the previous.
|
|
|
|
type Int32Tick struct {
|
2018-06-17 02:59:23 +00:00
|
|
|
Now int32
|
|
|
|
Last int32
|
|
|
|
}
|
|
|
|
|
2018-07-22 03:43:01 +00:00
|
|
|
// StringTick manages strings between this frame and the previous.
|
|
|
|
type StringTick struct {
|
|
|
|
Now string
|
|
|
|
Last string
|
|
|
|
}
|
|
|
|
|
2018-06-17 02:59:23 +00:00
|
|
|
// Push a bool state, copying the current Now value to Last.
|
2018-06-17 14:56:51 +00:00
|
|
|
func (bs *BoolTick) Push(v bool) {
|
2018-06-17 02:59:23 +00:00
|
|
|
bs.Last = bs.Now
|
|
|
|
bs.Now = v
|
|
|
|
}
|
|
|
|
|
2018-06-17 14:56:51 +00:00
|
|
|
// Pressed returns true if the button was pressed THIS tick.
|
|
|
|
func (bs *BoolTick) Pressed() bool {
|
|
|
|
return bs.Now && !bs.Last
|
|
|
|
}
|
|
|
|
|
2018-07-22 03:43:01 +00:00
|
|
|
// Read a bool state, resetting its value to false.
|
|
|
|
func (bs *BoolTick) Read() bool {
|
|
|
|
now := bs.Now
|
|
|
|
bs.Push(false)
|
|
|
|
return now
|
|
|
|
}
|
|
|
|
|
2018-06-17 02:59:23 +00:00
|
|
|
// Push an int32 state, copying the current Now value to Last.
|
2018-06-17 14:56:51 +00:00
|
|
|
func (is *Int32Tick) Push(v int32) {
|
2018-06-17 02:59:23 +00:00
|
|
|
is.Last = is.Now
|
|
|
|
is.Now = v
|
|
|
|
}
|
2018-07-22 03:43:01 +00:00
|
|
|
|
|
|
|
// Push a string state.
|
|
|
|
func (s *StringTick) Push(v string) {
|
|
|
|
s.Last = s.Now
|
|
|
|
s.Now = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read a string state, resetting its value.
|
|
|
|
func (s *StringTick) Read() string {
|
|
|
|
now := s.Now
|
|
|
|
s.Push("")
|
|
|
|
return now
|
|
|
|
}
|