refactor DeviceKind getters in EventInfo, add last device tracking to Handler#44
refactor DeviceKind getters in EventInfo, add last device tracking to Handler#44quasilyte merged 1 commit intoquasilyte:masterfrom
Conversation
event.go
Outdated
| } | ||
|
|
||
| // Device returns the set of devices that were used to trigger the event. | ||
| func (e EventInfo) Device() DeviceKind { |
There was a problem hiding this comment.
Maybe a name like Source() or SourceDevice would be better? Since it reports the device that caused the event to trigger
There was a problem hiding this comment.
Yeah, sure. I can rename that.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Nit: there should be an empty line before "deprecated" directive
See: go-critic/go-critic#1453
There was a problem hiding this comment.
Ok, sure. It seems I forgot to run the linter.
There was a problem hiding this comment.
gocritic doesn't detect it yet, I just remembered seeing it a little while ago :D
There was a problem hiding this comment.
Ok, I added an empty comment line.
handler.go
Outdated
| return true | ||
| } | ||
| if h.keyIsPressed(k) { | ||
| h.last = k.kind.device() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I had a single-line method for this, but decided to remove it. Probably worth returning.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Moved the duplication assignments to a method in the end and added more calls to Info* methods too.
|
For the sake of the pr/commit history, here is a follow-up: |
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.