Skip to content

Commit

Permalink
fix: set location of trash can on first render (#1160)
Browse files Browse the repository at this point in the history
* fix: set location of trash can on first render
  • Loading branch information
sebp999 authored Feb 8, 2021
1 parent 0633d6a commit a879d5c
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1231,37 +1231,42 @@ ocargo.LevelEditor = function() {
/* Trashcan */
/************/

function setupTrashcan() {

var trashcan = $('#trashcanHolder');

function placeTrashcan(trashcan) {
// Iffy way of making sure the trashcan stays inside the grid
// when window bigger than grid
$(window).resize(function() {
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var windowWidth = $(window).width();
var windowHeight = $(window).height();

var paperRightEdge = PAPER_WIDTH + $('#tools').width();
var paperBottomEdge = PAPER_HEIGHT;
var paperRightEdge = PAPER_WIDTH + $('#tools').width();
var paperBottomEdge = PAPER_HEIGHT;

var bottom = 50;
if(windowHeight > paperBottomEdge) {
bottom += windowHeight - paperBottomEdge
}
var bottom = 50;
if(windowHeight > paperBottomEdge) {
bottom += windowHeight - paperBottomEdge
}

var right = 50;
if(windowWidth > paperRightEdge) {
right += windowWidth - paperRightEdge;
}
var right = 50;
if(windowWidth > paperRightEdge) {
right += windowWidth - paperRightEdge;
}

trashcan.css('right', right);
trashcan.css('bottom', bottom);

var trashcanOffset = trashcan.offset();
var paperOffset = paper.offset();
trashcanAbsolutePaperX = trashcanOffset.left - paperOffset.left;
trashcanAbsolutePaperY = trashcanOffset.top - paperOffset.top;
}

trashcan.css('right', right);
trashcan.css('bottom', bottom);
function setupTrashcan() {

var trashcan = $('#trashcanHolder');

placeTrashcan(trashcan);

var trashcanOffset = trashcan.offset();
var paperOffset = paper.offset();
trashcanAbsolutePaperX = trashcanOffset.left - paperOffset.left;
trashcanAbsolutePaperY = trashcanOffset.top - paperOffset.top;
$(window).resize(function() {
placeTrashcan(trashcan);
});

addReleaseListeners(trashcan[0]);
Expand Down

0 comments on commit a879d5c

Please sign in to comment.