|
class MouseWheel { |
|
constructor (runtime) { |
|
|
|
|
|
|
|
|
|
this.runtime = runtime; |
|
|
|
|
|
this.scrollDelta = 0; |
|
this.runtime.on("RUNTIME_STEP_END", () => { |
|
this.scrollDelta = 0; |
|
}); |
|
} |
|
|
|
_addToScrollingDistanceBlock (amount) { |
|
if ('ext_pmSensingExpansion' in this.runtime) { |
|
this.runtime.ext_pmSensingExpansion.scrollDistance += amount; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
postData (data) { |
|
|
|
this.scrollDelta = data.deltaY; |
|
|
|
this._addToScrollingDistanceBlock(0 - data.deltaY); |
|
|
|
const matchFields = {}; |
|
const scrollFields = {}; |
|
if (data.deltaY < 0) { |
|
matchFields.KEY_OPTION = 'up arrow'; |
|
scrollFields.KEY_OPTION = 'up'; |
|
} else if (data.deltaY > 0) { |
|
matchFields.KEY_OPTION = 'down arrow'; |
|
scrollFields.KEY_OPTION = 'down'; |
|
} else { |
|
return; |
|
} |
|
|
|
this.runtime.startHats('event_whenkeypressed', matchFields); |
|
this.runtime.startHats('event_whenmousescrolled', scrollFields); |
|
} |
|
|
|
|
|
getScrollDelta () { |
|
return this.scrollDelta; |
|
} |
|
} |
|
|
|
module.exports = MouseWheel; |
|
|