Skip to content

Instantly share code, notes, and snippets.

@opparco
Created April 21, 2017 05:43
Show Gist options
  • Save opparco/a77e03299192f0dd0129fa0e62ce0bc2 to your computer and use it in GitHub Desktop.
Save opparco/a77e03299192f0dd0129fa0e62ce0bc2 to your computer and use it in GitHub Desktop.
handle virtual controller input on RPGAtsumaru
interface Window {
RPGAtsumaru;
}
class RPGAtsumaruState {
buttons;
next: Function;
create() {
this.buttons = {
left: {}, up: {}, right: {}, down: {}, ok: {}, cancel: {}
};
/**
* next
* @param event {type: string, key: string}
*/
this.next = function(event) {
if (event.key in this.buttons) {
let isDown = false;
if (event.type === 'keydown')
isDown = true;
this.buttons[event.key].isDown = isDown;
}
}.bind(this);
if (window.RPGAtsumaru) {
console.log('window.RPGAtsumaru is defined.');
window.RPGAtsumaru.controllers.defaultController.subscribe(this.next);
}
else {
console.log('window.RPGAtsumaru is undefined.');
}
}
update() {
if (window.RPGAtsumaru) {
this._handleInputRPGAtsumaru();
}
}
_handleInputRPGAtsumaru() {
if (this.buttons.ok.isDown) {
/* */
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment