feat: shorter names for events.
This commit is contained in:
parent
eda12973e9
commit
ab8a3f3387
7 changed files with 20 additions and 20 deletions
|
@ -27,7 +27,7 @@ func NewCamera() *Camera {
|
|||
func (cam *Camera) OnUpdate(c gg.Context) {
|
||||
dt := c.Engine().DT().Seconds()
|
||||
mov := c.Events().Mouse.Move
|
||||
wheel := c.Events().Mouse.WheelChange
|
||||
wheel := c.Events().Mouse.Wheel
|
||||
shiftPressed := c.Engine().IsPressed(gg.KeyShift)
|
||||
d := float64(1.)
|
||||
if shiftPressed {
|
||||
|
@ -41,7 +41,7 @@ func (cam *Camera) OnUpdate(c gg.Context) {
|
|||
cam.Move(mov.AbsDelta)
|
||||
}
|
||||
|
||||
for _, btn := range c.Events().Mouse.ButtonDowns {
|
||||
for _, btn := range c.Events().Mouse.Downs {
|
||||
switch btn.MouseButton {
|
||||
case gg.MouseButtonLeft :
|
||||
t := NewTri(ox.T().SetPosition(
|
||||
|
|
|
@ -15,7 +15,7 @@ type Debug struct {
|
|||
}
|
||||
|
||||
func (d *Debug) OnUpdate(c Context) {
|
||||
for _, key := range c.Events().Keyboard.KeyDowns {
|
||||
for _, key := range c.Events().Keyboard.Downs {
|
||||
switch key.Key {
|
||||
case gg.KeyF11:
|
||||
d.ToggleVisibility()
|
||||
|
|
|
@ -11,7 +11,7 @@ type Grid struct {
|
|||
|
||||
func (grid *Grid) OnUpdate(c Context) {
|
||||
//d := c.IsPressed(gg.KeyShift)
|
||||
for _, down := range c.Events().Keyboard.KeyDowns {
|
||||
for _, down := range c.Events().Keyboard.Downs {
|
||||
switch down.Key {
|
||||
case gg.Key9:
|
||||
grid.Cage /= 10
|
||||
|
|
|
@ -121,7 +121,7 @@ func (p *Player) OnUpdate(c Context) {
|
|||
p.Animate(Stand)
|
||||
}
|
||||
|
||||
for _, down := range c.Events().Keyboard.KeyDowns {
|
||||
for _, down := range c.Events().Keyboard.Downs {
|
||||
switch {
|
||||
case down.Key == gg.KeyZ:
|
||||
if p.Layer != LayerPlayer {
|
||||
|
|
|
@ -85,7 +85,7 @@ func (t *Tri) OnUpdate(c Context) {
|
|||
}
|
||||
}
|
||||
|
||||
for _, down := range c.Events().Keyboard.KeyDowns {
|
||||
for _, down := range c.Events().Keyboard.Downs {
|
||||
switch down.Key {
|
||||
case gg.Key1:
|
||||
if t.IsConnected() {
|
||||
|
|
18
engine.go
18
engine.go
|
@ -241,16 +241,16 @@ func (e *engine) updateEvents() Events {
|
|||
for _, btn := range allButtons {
|
||||
if inpututil.IsMouseButtonJustPressed(btn) {
|
||||
btns[btn] = struct{}{}
|
||||
events.Mouse.ButtonDowns = append(
|
||||
events.Mouse.ButtonDowns,
|
||||
events.Mouse.Downs = append(
|
||||
events.Mouse.Downs,
|
||||
MouseButtonDown{
|
||||
MouseButton: btn,
|
||||
},
|
||||
)
|
||||
} else if inpututil.IsMouseButtonJustReleased(btn) {
|
||||
delete(btns, btn)
|
||||
events.Mouse.ButtonUps = append(
|
||||
events.Mouse.ButtonUps,
|
||||
events.Mouse.Ups = append(
|
||||
events.Mouse.Ups,
|
||||
MouseButtonUp{
|
||||
MouseButton: btn,
|
||||
},
|
||||
|
@ -262,7 +262,7 @@ func (e *engine) updateEvents() Events {
|
|||
x, y := ebiten.Wheel()
|
||||
e.wheel = mx.Vector{x, y}
|
||||
if !(e.wheel.Eq(mx.ZV)) {
|
||||
events.Mouse.WheelChange = &WheelChange{
|
||||
events.Mouse.Wheel = &WheelChange{
|
||||
Offset: e.wheel,
|
||||
}
|
||||
}
|
||||
|
@ -294,15 +294,15 @@ func (e *engine) updateEvents() Events {
|
|||
keyDiff := diffEm(e.prevKeys, e.keys)
|
||||
for _, key := range keyDiff {
|
||||
if eng.IsPressed(key) {
|
||||
events.Keyboard.KeyDowns = append(
|
||||
events.Keyboard.KeyDowns,
|
||||
events.Keyboard.Downs = append(
|
||||
events.Keyboard.Downs,
|
||||
KeyDown{
|
||||
Key: key,
|
||||
},
|
||||
)
|
||||
} else {
|
||||
events.Keyboard.KeyUps = append(
|
||||
events.Keyboard.KeyUps,
|
||||
events.Keyboard.Ups = append(
|
||||
events.Keyboard.Ups,
|
||||
KeyUp{
|
||||
Key: key,
|
||||
},
|
||||
|
|
10
event.go
10
event.go
|
@ -68,15 +68,15 @@ type WheelChange struct {
|
|||
}
|
||||
|
||||
type KeyboardEvents struct {
|
||||
KeyDowns []KeyDown
|
||||
KeyUps []KeyUp
|
||||
Downs []KeyDown
|
||||
Ups []KeyUp
|
||||
}
|
||||
|
||||
type MouseEvents struct {
|
||||
ButtonDowns []MouseButtonDown
|
||||
ButtonUps []MouseButtonUp
|
||||
Downs []MouseButtonDown
|
||||
Ups []MouseButtonUp
|
||||
Move *MouseMove
|
||||
WheelChange *WheelChange
|
||||
Wheel *WheelChange
|
||||
}
|
||||
|
||||
type Events struct {
|
||||
|
|
Loading…
Reference in a new issue