From 2378288a5b4d48082f06cdae4c326de94eddbdc4 Mon Sep 17 00:00:00 2001 From: sergystepanov Date: Fri, 2 Jul 2021 13:34:12 +0300 Subject: [PATCH] Fix player select with touch controls (#325) --- web/js/controller.js | 3 +++ web/js/event/event.js | 2 ++ web/js/input/touch.js | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/web/js/controller.js b/web/js/controller.js index d024dc8f..205da1a1 100644 --- a/web/js/controller.js +++ b/web/js/controller.js @@ -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); }); diff --git a/web/js/event/event.js b/web/js/event/event.js index 7271cce4..cc214a6e 100644 --- a/web/js/event/event.js +++ b/web/js/event/event.js @@ -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'; diff --git a/web/js/input/touch.js b/web/js/input/touch.js index 9e645863..4693b1e0 100644 --- a/web/js/input/touch.js +++ b/web/js/input/touch.js @@ -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