Skip to content

Commit

Permalink
make cows properly appear in the screen when reloading save state
Browse files Browse the repository at this point in the history
  • Loading branch information
Raihan Rasheed committed Oct 28, 2024
1 parent b838aba commit 5459985
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ ocargo.LevelEditor = function(levelId) {
var bBox = image.getBBox();
imageWidth = bBox.width;
imageHeight = bBox.height;

var paperPosition = paper.position();
originX = x - paperPosition.left + paper.scrollLeft() - imageWidth/2;
originY = y - paperPosition.top + paper.scrollTop() - imageHeight/2;
Expand Down Expand Up @@ -1859,7 +1859,7 @@ ocargo.LevelEditor = function(levelId) {
const cowY = e.pageY + paper.scrollTop() - dragged_cow.height / 2;

if (draggedObjectOnGrid(e, dragged_cow)) {
image.transform('t' + cowX + ',' + cowY + 'r90');
image.transform('t' + cowX + ',' + cowY);
} else {
internalCow.destroy();
}
Expand Down Expand Up @@ -2965,12 +2965,16 @@ ocargo.LevelEditor = function(levelId) {
if ( data.coordinates && data.coordinates.length > 0 ) {
this.coordinate = new ocargo.Coordinate(data.coordinates[0].x, data.coordinates[0].y);
this.valid = isValidDraggedCowPlacement(this.coordinate, this);

if (this.isOnRoad()) {
const controlledNode = ocargo.Node.findNodeByCoordinate(coordinates, nodes);
const controlledNode = ocargo.Node.findNodeByCoordinate(this.coordinate, nodes);
drawing.setCowImagePosition(this.coordinate, this.image, controlledNode);
} else {
this.image.transform('...t' + (-paper.scrollLeft()) + ',' + paper.scrollTop());
const box = this.image.getBBox();
// calculate position of the image
const paperX = (this.coordinate.x + 1) * GRID_SPACE_SIZE - box.width/2;
const paperY = (GRID_HEIGHT - this.coordinate.y) * GRID_SPACE_SIZE - box.height/2;
this.image.transform('t' + paperX + ',' + paperY );
}
} else {
this.image.transform('...t' + (-paper.scrollLeft()) + ',' + paper.scrollTop());
Expand Down

0 comments on commit 5459985

Please sign in to comment.