From a436679fc7828753bfcf25a99d4a04fb1af4f839 Mon Sep 17 00:00:00 2001 From: RaihanRasheedApurbo Date: Tue, 10 Dec 2024 14:38:11 +0000 Subject: [PATCH] fix: remove cow from cow group during dragging to fix the bug (#1752) --- game/static/game/js/level_editor.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/game/static/game/js/level_editor.js b/game/static/game/js/level_editor.js index c2fcd1ecc..5e12059b4 100644 --- a/game/static/game/js/level_editor.js +++ b/game/static/game/js/level_editor.js @@ -1680,6 +1680,8 @@ ocargo.LevelEditor = function(levelId) { } function onDragStart(x, y) { + // cow shouldn't be in the cow group during dragging + removeCowFromCowList(cow); var bBox = image.getBBox(); imageWidth = bBox.width; imageHeight = bBox.height; @@ -1695,12 +1697,14 @@ ocargo.LevelEditor = function(levelId) { } function onDragEnd() { - setCowMarkingsOnMouseUp(controlledCoord, cow); - + if (trashcanOpen) { cow.destroy(); + unmarkOldCowSquare(controlledCoord, cow); closeTrashcan(); } else { + setCowMarkingsOnMouseUp(controlledCoord, cow); + cows.push(cow); cow.coordinate = controlledCoord; cow.valid = isValidDraggedCowPlacement(controlledCoord, cow); if (cow.isOnRoad()) { @@ -1731,6 +1735,13 @@ ocargo.LevelEditor = function(levelId) { addReleaseListeners(image.node); } + function removeCowFromCowList(cow) { + var index = cows.indexOf(cow); + if (index > -1) { + cows.splice(index, 1); + } + } + function isValidDraggedCowPlacement(controlledCoord, cow){ if (isOriginCoordinate(controlledCoord) || isHouseCoordinate(controlledCoord)) return false; @@ -1864,10 +1875,12 @@ ocargo.LevelEditor = function(levelId) { internalCow.destroy(); } } - - setCowMarkingsOnMouseUp(controlledCoord, internalCow); - adjustCowGroupMinMaxFields(internalCow); - + + if (!trashcanOpen) { + setCowMarkingsOnMouseUp(controlledCoord, internalCow); + adjustCowGroupMinMaxFields(internalCow); + } + $(document) .off('mousemove', handleDraggableCowDragging) .off('mouseup mouseleave', handleDraggableCowMouseUp);