Skip to content

Commit a436679

Browse files
fix: remove cow from cow group during dragging to fix the bug (#1752)
1 parent 090c16d commit a436679

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

game/static/game/js/level_editor.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,8 @@ ocargo.LevelEditor = function(levelId) {
16801680
}
16811681

16821682
function onDragStart(x, y) {
1683+
// cow shouldn't be in the cow group during dragging
1684+
removeCowFromCowList(cow);
16831685
var bBox = image.getBBox();
16841686
imageWidth = bBox.width;
16851687
imageHeight = bBox.height;
@@ -1695,12 +1697,14 @@ ocargo.LevelEditor = function(levelId) {
16951697
}
16961698

16971699
function onDragEnd() {
1698-
setCowMarkingsOnMouseUp(controlledCoord, cow);
1699-
1700+
17001701
if (trashcanOpen) {
17011702
cow.destroy();
1703+
unmarkOldCowSquare(controlledCoord, cow);
17021704
closeTrashcan();
17031705
} else {
1706+
setCowMarkingsOnMouseUp(controlledCoord, cow);
1707+
cows.push(cow);
17041708
cow.coordinate = controlledCoord;
17051709
cow.valid = isValidDraggedCowPlacement(controlledCoord, cow);
17061710
if (cow.isOnRoad()) {
@@ -1731,6 +1735,13 @@ ocargo.LevelEditor = function(levelId) {
17311735
addReleaseListeners(image.node);
17321736
}
17331737

1738+
function removeCowFromCowList(cow) {
1739+
var index = cows.indexOf(cow);
1740+
if (index > -1) {
1741+
cows.splice(index, 1);
1742+
}
1743+
}
1744+
17341745
function isValidDraggedCowPlacement(controlledCoord, cow){
17351746
if (isOriginCoordinate(controlledCoord) || isHouseCoordinate(controlledCoord))
17361747
return false;
@@ -1864,10 +1875,12 @@ ocargo.LevelEditor = function(levelId) {
18641875
internalCow.destroy();
18651876
}
18661877
}
1867-
1868-
setCowMarkingsOnMouseUp(controlledCoord, internalCow);
1869-
adjustCowGroupMinMaxFields(internalCow);
1870-
1878+
1879+
if (!trashcanOpen) {
1880+
setCowMarkingsOnMouseUp(controlledCoord, internalCow);
1881+
adjustCowGroupMinMaxFields(internalCow);
1882+
}
1883+
18711884
$(document)
18721885
.off('mousemove', handleDraggableCowDragging)
18731886
.off('mouseup mouseleave', handleDraggableCowMouseUp);

0 commit comments

Comments
 (0)