From ab8a3f3387c1b6e4df49cd4dd83dc85723b79ddd Mon Sep 17 00:00:00 2001 From: surdeus Date: Mon, 3 Jun 2024 13:04:42 +0500 Subject: [PATCH] feat: shorter names for events. --- cmd/test/camera.go | 4 ++-- cmd/test/debug.go | 2 +- cmd/test/grid.go | 2 +- cmd/test/player.go | 2 +- cmd/test/trianlge.go | 2 +- engine.go | 18 +++++++++--------- event.go | 10 +++++----- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cmd/test/camera.go b/cmd/test/camera.go index 348e191..6b60cfa 100644 --- a/cmd/test/camera.go +++ b/cmd/test/camera.go @@ -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( diff --git a/cmd/test/debug.go b/cmd/test/debug.go index fbf9dc1..35d0fa3 100644 --- a/cmd/test/debug.go +++ b/cmd/test/debug.go @@ -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() diff --git a/cmd/test/grid.go b/cmd/test/grid.go index 654e5e8..9662a1a 100644 --- a/cmd/test/grid.go +++ b/cmd/test/grid.go @@ -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 diff --git a/cmd/test/player.go b/cmd/test/player.go index 545cc3e..5d1eb5b 100644 --- a/cmd/test/player.go +++ b/cmd/test/player.go @@ -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 { diff --git a/cmd/test/trianlge.go b/cmd/test/trianlge.go index b2788c4..7fccc53 100644 --- a/cmd/test/trianlge.go +++ b/cmd/test/trianlge.go @@ -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() { diff --git a/engine.go b/engine.go index 9244c23..84c5156 100644 --- a/engine.go +++ b/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, }, diff --git a/event.go b/event.go index aa934c1..1e0e223 100644 --- a/event.go +++ b/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 {