Skip to content

Commit

Permalink
remove cow from cow group during dragging to fix the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RaihanRasheedApurbo committed Dec 7, 2024
1 parent f5e0ae2 commit 343634d
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 343634d

Please sign in to comment.