Fix player select with touch controls (#325)

This commit is contained in:
sergystepanov 2021-07-02 13:34:12 +03:00 committed by GitHub
parent 875673c661
commit 2378288a5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View file

@ -406,6 +406,9 @@
event.sub(GAME_ROOM_AVAILABLE, onGameRoomAvailable, 2);
event.sub(GAME_SAVED, () => message.show('Saved'));
event.sub(GAME_LOADED, () => message.show('Loaded'));
event.sub(GAME_PLAYER_IDX_CHANGE, data => {
updatePlayerIndex(data.index);
});
event.sub(GAME_PLAYER_IDX, idx => {
if (!isNaN(+idx)) message.show(+idx + 1);
});

View file

@ -62,6 +62,8 @@ const PING_RESPONSE = 'pingResponse';
const GAME_ROOM_AVAILABLE = 'gameRoomAvailable';
const GAME_SAVED = 'gameSaved';
const GAME_LOADED = 'gameLoaded';
// used to transfer the index value between touch and controller
const GAME_PLAYER_IDX_CHANGE = 'gamePlayerIndexChange';
const GAME_PLAYER_IDX = 'gamePlayerIndex';
const CONNECTION_READY = 'connectionReady';

View file

@ -165,8 +165,9 @@ const touch = (() => {
}, 30);
}
// !to rewrite slider completely
function handlePlayerSlider() {
socket.updatePlayerIndex(this.value - 1);
event.pub(GAME_PLAYER_IDX_CHANGE, {index: +this.value - 1})
}
// Touch menu
@ -279,6 +280,7 @@ const touch = (() => {
playerSlider.addEventListener('oninput', handlePlayerSlider);
playerSlider.addEventListener('onchange', handlePlayerSlider);
playerSlider.addEventListener('mouseup', handlePlayerSlider);
playerSlider.addEventListener('touchend', handlePlayerSlider);
// Bind events for menu
// TODO change this flow