From d568b71e8fc580ba2fc14c80b1737f5f6a06a176 Mon Sep 17 00:00:00 2001 From: Raihan Date: Sat, 7 Dec 2024 20:00:50 +0000 Subject: [PATCH] remove cow from cow group during dragging to fix the bug --- 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);