Skip to content

Commit

Permalink
fix bin bug (#1616)
Browse files Browse the repository at this point in the history
  • Loading branch information
evemartin authored May 15, 2024
1 parent dd97354 commit b27c137
Showing 1 changed file with 51 additions and 17 deletions.
68 changes: 51 additions & 17 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1447,14 +1447,14 @@ ocargo.LevelEditor = function(levelId) {
// Stop it being dragged off the edge of the page
if (paperX < 0) {
paperX = 0;
} else if (paperX + imageWidth > paperWidth) {
paperX = paperWidth - imageWidth;
} else if (paperX + imageWidth > EXTENDED_PAPER_WIDTH) {
paperX = EXTENDED_PAPER_WIDTH - imageWidth;
}

if (paperY < 0) {
paperY = 0;
} else if (paperY + imageHeight > paperHeight) {
paperY = paperHeight - imageHeight;
} else if (paperY + imageHeight > EXTENDED_PAPER_HEIGHT) {
paperY = EXTENDED_PAPER_HEIGHT - imageHeight;
}

image.transform('t' + paperX + ',' + paperY);
Expand All @@ -1477,8 +1477,17 @@ ocargo.LevelEditor = function(levelId) {
originX = paperX;
originY = paperY;

if(trashcanOpen) {
if (trashcanOpen) {
decor.destroy();
} else {
if (paperWidth < paperX + imageWidth) {
originX = paperWidth - imageWidth;
}
if (paperHeight < paperY + imageHeight) {
originY = paperHeight - imageHeight;
}

image.transform('t' + originX + ',' + originY);
}

closeTrashcan();
Expand Down Expand Up @@ -1528,13 +1537,13 @@ ocargo.LevelEditor = function(levelId) {
// Stop it being dragged off the edge of the page
if (paperX < 0) {
paperX = 0;
} else if (paperX + imageWidth > paperWidth) {
paperX = paperWidth - imageWidth;
} else if (paperX + imageWidth > EXTENDED_PAPER_WIDTH) {
paperX = EXTENDED_PAPER_WIDTH - imageWidth;
}
if (paperY < 0) {
paperY = 0;
} else if (paperY + imageHeight > paperHeight) {
paperY = paperHeight - imageHeight;
} else if (paperY + imageHeight > EXTENDED_PAPER_HEIGHT) {
paperY = EXTENDED_PAPER_HEIGHT - imageHeight;
}

// And perform the updatee
Expand Down Expand Up @@ -1630,9 +1639,9 @@ ocargo.LevelEditor = function(levelId) {
markAsDestination(destinationNode.coordinate);
}

if(trashcanOpen) {
if (trashcanOpen) {
cow.destroy();
} else if(isValidPlacement(controlledCoord)) {
} else if (isValidPlacement(controlledCoord)) {
// Add back to the list of cows if on valid nodes
var controlledNode = ocargo.Node.findNodeByCoordinate(controlledCoord, nodes);
cow.controlledNode = controlledNode;
Expand All @@ -1641,7 +1650,20 @@ ocargo.LevelEditor = function(levelId) {
} else {
cow.controlledNode = null;
cow.valid = false;
}

var cowX = paperX;
var cowY = paperY;

if (paperWidth < paperX + imageWidth) {
cowX = paperWidth - imageWidth
}

if (paperHeight < paperY + imageHeight) {
cowY = paperHeight - imageHeight
}

image.transform('t' + cowX + ',' + cowY);
}
adjustCowGroupMinMaxFields(cow);

image.attr({'cursor':'pointer'});
Expand Down Expand Up @@ -1731,16 +1753,16 @@ ocargo.LevelEditor = function(levelId) {
// Stop it being dragged off the edge of the page
if (paperX < 0) {
paperX = 0;
} else if (paperX + imageWidth > paperWidth) {
paperX = paperWidth - imageWidth;
} else if (paperX + imageWidth > EXTENDED_PAPER_WIDTH) {
paperX = EXTENDED_PAPER_WIDTH - imageWidth;
}
if (paperY < 0) {
paperY = 0;
} else if (paperY + imageHeight > paperHeight) {
paperY = paperHeight - imageHeight;
} else if (paperY + imageHeight > EXTENDED_PAPER_HEIGHT) {
paperY = EXTENDED_PAPER_HEIGHT - imageHeight;
}

// And perform the updatee
// And perform the update
image.transform('t' + paperX + ',' + paperY + 'r' + rotation + 's' + scaling);

// Unmark the squares the light previously occupied
Expand Down Expand Up @@ -1886,6 +1908,18 @@ ocargo.LevelEditor = function(levelId) {
trafficLight.valid = true;

drawing.setTrafficLightImagePosition(sourceCoord, controlledCoord, image);
} else {
var trafficLightX = paperX;
var trafficLightY = paperY;

if (paperWidth < paperX + imageWidth) {
trafficLightX = paperWidth - imageWidth
image.transform('t' + trafficLightX + ',' + trafficLightY + 'r' + rotation + 's' + scaling);
}
if (paperHeight < paperY + imageHeight) {
trafficLightY = paperHeight - imageHeight
image.transform('t' + trafficLightX + ',' + trafficLightY + 'r' + rotation + 's' + scaling);
}
}

image.attr({'cursor':'pointer'});
Expand Down

0 comments on commit b27c137

Please sign in to comment.