Skip to content

refactor DeviceKind getters in EventInfo, add last device tracking to Handler#44

Merged
quasilyte merged 1 commit intoquasilyte:masterfrom
sedyh:master
Jan 26, 2025
Merged

refactor DeviceKind getters in EventInfo, add last device tracking to Handler#44
quasilyte merged 1 commit intoquasilyte:masterfrom
sedyh:master

Conversation

@sedyh
Copy link
Contributor

@sedyh sedyh commented Jan 26, 2025

It would be useful to get the last used device to change button prompts when the player changes it. In connection with these changes, I moved the device definition getters closer to the type of these same devices in order to use them equally from the event and from the handler. Despite the fact that the previous getters were marked as deprecated, the missing types of pressed keys were added to them.

event.go Outdated
}

// Device returns the set of devices that were used to trigger the event.
func (e EventInfo) Device() DeviceKind {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a name like Source() or SourceDevice would be better? Since it reports the device that caused the event to trigger

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sure. I can rename that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it to Source().

event.go Outdated

// IsTouchEvent reports whether this event was triggered by a screen touch device.
func (e EventInfo) IsTouchEvent() bool { return e.kind == keyTouch }
// Deprecated: Use Device().IsTouch() instead.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there should be an empty line before "deprecated" directive
See: go-critic/go-critic#1453

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sure. It seems I forgot to run the linter.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gocritic doesn't detect it yet, I just remembered seeing it a little while ago :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I added an empty comment line.

handler.go Outdated
return true
}
if h.keyIsPressed(k) {
h.last = k.kind.device()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Info* methods be updated as well? It's OK to copy/paste this assignment everywhere for now, and then maybe we can refactor this stuff to somehow

Copy link
Contributor Author

@sedyh sedyh Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a single-line method for this, but decided to remove it. Probably worth returning.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly talking about JustPressedActionInfo methods that don't call ActionIsPressed method internally; or maybe I missed them updating the last device field in the code

Copy link
Contributor Author

@sedyh sedyh Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the duplication assignments to a method in the end and added more calls to Info* methods too.

@quasilyte quasilyte merged commit 9cc24ff into quasilyte:master Jan 26, 2025
1 check failed
@quasilyte
Copy link
Owner

For the sake of the pr/commit history, here is a follow-up:
#45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants