From 29a8755784bdcf45e36ac0d784a97c94cbd9c119 Mon Sep 17 00:00:00 2001
From: Leonardo Bishop <me@leonardobishop.com>
Date: Sun, 5 Nov 2023 11:14:34 +0000
Subject: add move limit of 1 per sec

---
 frontend/src/views/JoinView.vue | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

(limited to 'frontend/src/views/JoinView.vue')

diff --git a/frontend/src/views/JoinView.vue b/frontend/src/views/JoinView.vue
index 83e00c2..83421ee 100644
--- a/frontend/src/views/JoinView.vue
+++ b/frontend/src/views/JoinView.vue
@@ -8,6 +8,7 @@ const sessionId = route.params.id;
 const joiningGame = ref(true);
 const connected = ref(false);
 const gameState = ref('');
+const controlsLocked = ref(false);
 
 const socket = new WebSocket(`${import.meta.env.VITE_BACKEND_WS_URL}`);
 socket.onopen = () => {
@@ -26,6 +27,13 @@ socket.onmessage = (event) => {
 };
 
 function sendMove(move: string) {
+  if (controlsLocked.value) {
+    return;
+  }
+  controlsLocked.value = true;
+  setTimeout(() => {
+    controlsLocked.value = false;
+  }, 1000);
   socket.send(JSON.stringify({
     action: 'move',
     sessionId: sessionId,
@@ -56,9 +64,9 @@ function sendRight() {
     <h1 v-if="connected">Connected to "{{ sessionId }}"</h1>
     <h1 v-if="gameState === 'waiting'">Waiting for host to start the game...</h1>
     <div class='controls' v-if="gameState === 'playing'">
-      <button @click="sendLeft">Left</button>
-      <button @click="sendRotate">Rotate</button>
-      <button @click="sendRight">Right</button>
+      <button @click="sendLeft" :disabled="controlsLocked">Left</button>
+      <button @click="sendRotate" :disabled="controlsLocked">Rotate</button>
+      <button @click="sendRight" :disabled="controlsLocked">Right</button>
     </div>
   </main>
 </template>
-- 
cgit v1.2.3-70-g09d2

