feat: wheel changes active slot

This commit is contained in:
cha0s 2019-05-23 05:30:31 -05:00
parent bbdd74f7e0
commit 79b8039937

View File

@ -87,7 +87,6 @@ export class App extends decorate(class {}) {
this.onBlur = this.onBlur.bind(this);
this.onFocus = this.onFocus.bind(this);
// Global keys.
this.stage.on('keyDown', this.onGlobalKeydown, this);
this.pointingAt = [-1, -1];
this.pointerMovementHandle = undefined;
// Net.
@ -231,7 +230,7 @@ export class App extends decorate(class {}) {
this.isFocused = true;
}
onGlobalKeydown(key) {
onKeyDown(key) {
switch (key) {
case 'F2':
this.isDebugging = !this.isDebugging;
@ -337,6 +336,19 @@ export class App extends decorate(class {}) {
}
}
onWheel(event) {
if (!this.selfEntity) {
return;
}
const activeSlotIndex = this.selfEntity.activeSlotIndex;
if (event.deltaY > 0) {
this.selfEntity.activeSlotIndex = (activeSlotIndex + 1) % 10;
}
else if (event.deltaY < 0) {
this.selfEntity.activeSlotIndex = (activeSlotIndex + 9) % 10;
}
}
// Stub for now!
readConfig() {
return {
@ -426,9 +438,11 @@ export class App extends decorate(class {}) {
startProcessingInput() {
const config = this.readConfig();
// Pointer input.
this.stage.on('keyDown', this.onKeyDown, this);
this.stage.on('pointerDown', this.onPointerDown, this);
this.stage.on('pointerMove', this.onPointerMove, this);
this.stage.on('pointerUp', this.onPointerUp, this);
this.stage.on('wheel', this.onWheel, this)
// Lol, Apple...
window.addEventListener('touchmove', (event) => {
event.preventDefault();
@ -527,9 +541,11 @@ export class App extends decorate(class {}) {
this.inputHandle = undefined;
this.stage.element.removeEventListener('focus', this.onFocus);
this.stage.element.removeEventListener('blur', this.onBlur);
this.stage.off('pointerUp', this.onPointerUp, this);
this.stage.off('pointerMove', this.onPointerMove, this);
this.stage.off('pointerDown', this.onPointerDown, this);
this.stage.off('keyDown', this.onKeyDown);
this.stage.off('pointerUp', this.onPointerUp);
this.stage.off('pointerMove', this.onPointerMove);
this.stage.off('pointerDown', this.onPointerDown);
this.stage.off('wheel', this.onWheel);
}
stopRendering() {