feat: shorter names for events.

This commit is contained in:
Andrey Parhomenko 2024-06-03 13:04:42 +05:00
parent eda12973e9
commit ab8a3f3387
7 changed files with 20 additions and 20 deletions

View file

@ -27,7 +27,7 @@ func NewCamera() *Camera {
func (cam *Camera) OnUpdate(c gg.Context) { func (cam *Camera) OnUpdate(c gg.Context) {
dt := c.Engine().DT().Seconds() dt := c.Engine().DT().Seconds()
mov := c.Events().Mouse.Move mov := c.Events().Mouse.Move
wheel := c.Events().Mouse.WheelChange wheel := c.Events().Mouse.Wheel
shiftPressed := c.Engine().IsPressed(gg.KeyShift) shiftPressed := c.Engine().IsPressed(gg.KeyShift)
d := float64(1.) d := float64(1.)
if shiftPressed { if shiftPressed {
@ -41,7 +41,7 @@ func (cam *Camera) OnUpdate(c gg.Context) {
cam.Move(mov.AbsDelta) cam.Move(mov.AbsDelta)
} }
for _, btn := range c.Events().Mouse.ButtonDowns { for _, btn := range c.Events().Mouse.Downs {
switch btn.MouseButton { switch btn.MouseButton {
case gg.MouseButtonLeft : case gg.MouseButtonLeft :
t := NewTri(ox.T().SetPosition( t := NewTri(ox.T().SetPosition(

View file

@ -15,7 +15,7 @@ type Debug struct {
} }
func (d *Debug) OnUpdate(c Context) { func (d *Debug) OnUpdate(c Context) {
for _, key := range c.Events().Keyboard.KeyDowns { for _, key := range c.Events().Keyboard.Downs {
switch key.Key { switch key.Key {
case gg.KeyF11: case gg.KeyF11:
d.ToggleVisibility() d.ToggleVisibility()

View file

@ -11,7 +11,7 @@ type Grid struct {
func (grid *Grid) OnUpdate(c Context) { func (grid *Grid) OnUpdate(c Context) {
//d := c.IsPressed(gg.KeyShift) //d := c.IsPressed(gg.KeyShift)
for _, down := range c.Events().Keyboard.KeyDowns { for _, down := range c.Events().Keyboard.Downs {
switch down.Key { switch down.Key {
case gg.Key9: case gg.Key9:
grid.Cage /= 10 grid.Cage /= 10

View file

@ -121,7 +121,7 @@ func (p *Player) OnUpdate(c Context) {
p.Animate(Stand) p.Animate(Stand)
} }
for _, down := range c.Events().Keyboard.KeyDowns { for _, down := range c.Events().Keyboard.Downs {
switch { switch {
case down.Key == gg.KeyZ: case down.Key == gg.KeyZ:
if p.Layer != LayerPlayer { if p.Layer != LayerPlayer {

View file

@ -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 { switch down.Key {
case gg.Key1: case gg.Key1:
if t.IsConnected() { if t.IsConnected() {

View file

@ -241,16 +241,16 @@ func (e *engine) updateEvents() Events {
for _, btn := range allButtons { for _, btn := range allButtons {
if inpututil.IsMouseButtonJustPressed(btn) { if inpututil.IsMouseButtonJustPressed(btn) {
btns[btn] = struct{}{} btns[btn] = struct{}{}
events.Mouse.ButtonDowns = append( events.Mouse.Downs = append(
events.Mouse.ButtonDowns, events.Mouse.Downs,
MouseButtonDown{ MouseButtonDown{
MouseButton: btn, MouseButton: btn,
}, },
) )
} else if inpututil.IsMouseButtonJustReleased(btn) { } else if inpututil.IsMouseButtonJustReleased(btn) {
delete(btns, btn) delete(btns, btn)
events.Mouse.ButtonUps = append( events.Mouse.Ups = append(
events.Mouse.ButtonUps, events.Mouse.Ups,
MouseButtonUp{ MouseButtonUp{
MouseButton: btn, MouseButton: btn,
}, },
@ -262,7 +262,7 @@ func (e *engine) updateEvents() Events {
x, y := ebiten.Wheel() x, y := ebiten.Wheel()
e.wheel = mx.Vector{x, y} e.wheel = mx.Vector{x, y}
if !(e.wheel.Eq(mx.ZV)) { if !(e.wheel.Eq(mx.ZV)) {
events.Mouse.WheelChange = &WheelChange{ events.Mouse.Wheel = &WheelChange{
Offset: e.wheel, Offset: e.wheel,
} }
} }
@ -294,15 +294,15 @@ func (e *engine) updateEvents() Events {
keyDiff := diffEm(e.prevKeys, e.keys) keyDiff := diffEm(e.prevKeys, e.keys)
for _, key := range keyDiff { for _, key := range keyDiff {
if eng.IsPressed(key) { if eng.IsPressed(key) {
events.Keyboard.KeyDowns = append( events.Keyboard.Downs = append(
events.Keyboard.KeyDowns, events.Keyboard.Downs,
KeyDown{ KeyDown{
Key: key, Key: key,
}, },
) )
} else { } else {
events.Keyboard.KeyUps = append( events.Keyboard.Ups = append(
events.Keyboard.KeyUps, events.Keyboard.Ups,
KeyUp{ KeyUp{
Key: key, Key: key,
}, },

View file

@ -68,15 +68,15 @@ type WheelChange struct {
} }
type KeyboardEvents struct { type KeyboardEvents struct {
KeyDowns []KeyDown Downs []KeyDown
KeyUps []KeyUp Ups []KeyUp
} }
type MouseEvents struct { type MouseEvents struct {
ButtonDowns []MouseButtonDown Downs []MouseButtonDown
ButtonUps []MouseButtonUp Ups []MouseButtonUp
Move *MouseMove Move *MouseMove
WheelChange *WheelChange Wheel *WheelChange
} }
type Events struct { type Events struct {