Noah Petherbridge
9356502a50
Implements the dev console in-game with various commands to start out with. Press the Enter key to show or hide the console. Commands supported: new Start a new map in Edit Mode. save [filename.json] Save the current map to disk. Filename is required unless you have saved recently. edit filename.json Open a map from disk in Edit Mode. play filename.json Play a map from disk in Play Mode.
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package events
|
|
|
|
// BoolTick holds boolean state between this frame and the previous.
|
|
type BoolTick struct {
|
|
Now bool
|
|
Last bool
|
|
}
|
|
|
|
// Int32Tick manages int32 state between this frame and the previous.
|
|
type Int32Tick struct {
|
|
Now int32
|
|
Last int32
|
|
}
|
|
|
|
// StringTick manages strings between this frame and the previous.
|
|
type StringTick struct {
|
|
Now string
|
|
Last string
|
|
}
|
|
|
|
// Push a bool state, copying the current Now value to Last.
|
|
func (bs *BoolTick) Push(v bool) {
|
|
bs.Last = bs.Now
|
|
bs.Now = v
|
|
}
|
|
|
|
// Pressed returns true if the button was pressed THIS tick.
|
|
func (bs *BoolTick) Pressed() bool {
|
|
return bs.Now && !bs.Last
|
|
}
|
|
|
|
// Read a bool state, resetting its value to false.
|
|
func (bs *BoolTick) Read() bool {
|
|
now := bs.Now
|
|
bs.Push(false)
|
|
return now
|
|
}
|
|
|
|
// Push an int32 state, copying the current Now value to Last.
|
|
func (is *Int32Tick) Push(v int32) {
|
|
is.Last = is.Now
|
|
is.Now = v
|
|
}
|
|
|
|
// 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
|
|
}
|