From c6fb6403dc141403506c64661483357b036feabf Mon Sep 17 00:00:00 2001
From: Ido-Barnea <dodo.barnea@gmail.com>
Date: Sun, 21 Jan 2024 18:46:01 +0200
Subject: [PATCH] [#151] Fixed players being able to drag enemy pieces

---
 development/code/ui/Events.ts | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/development/code/ui/Events.ts b/development/code/ui/Events.ts
index 82cc73bc..cf0594d2 100644
--- a/development/code/ui/Events.ts
+++ b/development/code/ui/Events.ts
@@ -1,3 +1,4 @@
+import { game } from '../Game';
 import { onPieceSelected } from '../LogicAdapter';
 import { HEAVEN_BOARD_BUTTON_ID, HELL_BOARD_BUTTON_ID, OVERWORLD_BOARD_BUTTON_ID } from '../logic/Constants';
 import { HEAVEN_BOARD, HELL_BOARD, OVERWORLD_BOARD } from './BoardManager';
@@ -52,6 +53,9 @@ export function dragPieceElement(element: HTMLElement) {
   function dragPieceOnMouseDown(event: MouseEvent) {
     event.preventDefault();
 
+    const currentTurnPlayerColor = game.getCurrentPlayer().color.toLowerCase();
+    if (!element.classList.contains(currentTurnPlayerColor)) return;
+
     endMouseX = event.clientX;
     endMouseY = event.clientY;
     document.onmousemove = pieceElementDrag;