|
1218 | 1218 |
|
1219 | 1219 |
|
1220 | 1220 | /**
|
1221 |
| - * Get widgets overlapping with the player. |
| 1221 | + * Get widgets overlapping with the player or with the object passed |
| 1222 | + * representing the grid cells. |
1222 | 1223 | *
|
1223 | 1224 | * @method get_widgets_under_player
|
1224 | 1225 | * @return {HTMLElement} Returns a jQuery collection of HTMLElements
|
1225 | 1226 | */
|
1226 |
| - fn.get_widgets_under_player = function() { |
1227 |
| - var cells = this.cells_occupied_by_player || {cols: [], rows: []}; |
| 1227 | + fn.get_widgets_under_player = function(cells) { |
| 1228 | + cells || (cells = this.cells_occupied_by_player || {cols: [], rows: []}); |
1228 | 1229 | var $widgets = $([]);
|
1229 | 1230 |
|
1230 | 1231 | $.each(cells.cols, $.proxy(function(i, col) {
|
|
1258 | 1259 | size_x: phgd.size_x
|
1259 | 1260 | });
|
1260 | 1261 |
|
1261 |
| - //Prevents widgets go out of the grid |
| 1262 | + // Prevents widgets go out of the grid |
1262 | 1263 | var right_col = (col + phgd.size_x - 1);
|
1263 | 1264 | if (right_col > this.cols) {
|
1264 | 1265 | col = col - (right_col - col);
|
|
1285 | 1286 | }, this));
|
1286 | 1287 | }
|
1287 | 1288 |
|
| 1289 | + |
| 1290 | + var $widgets_under_ph = this.get_widgets_under_player(this.cells_occupied_by_placeholder); |
| 1291 | + if ($widgets_under_ph.length) { |
| 1292 | + $widgets_under_ph.each($.proxy(function(i, widget) { |
| 1293 | + var $w = $(widget); |
| 1294 | + this.move_widget_down( |
| 1295 | + $w, row + phgd.size_y - $w.data('coords').grid.row); |
| 1296 | + }, this)); |
| 1297 | + }; |
| 1298 | + |
1288 | 1299 | };
|
1289 | 1300 |
|
1290 | 1301 |
|
|
1352 | 1363 | var upper_rows = [];
|
1353 | 1364 | var min_row = 10000;
|
1354 | 1365 |
|
1355 |
| - if (widget_grid_data.col < this.player_grid_data.col && |
1356 |
| - (widget_grid_data.col + widget_grid_data.size_y - 1) > |
1357 |
| - (this.player_grid_data.col + this.player_grid_data.size_y - 1) |
1358 |
| - ) { |
1359 |
| - return false; |
1360 |
| - }; |
1361 |
| - |
1362 |
| - /* generate an array with columns as index and array with upper rows |
| 1366 | + /* generate an array with columns as index and array with topmost rows |
1363 | 1367 | * empty as value */
|
1364 | 1368 | this.for_each_column_occupied(widget_grid_data, function(tcol) {
|
1365 | 1369 | var grid_col = this.gridmap[tcol];
|
1366 | 1370 | upper_rows[tcol] = [];
|
1367 | 1371 |
|
1368 | 1372 | var r = p_bottom_row + 1;
|
1369 |
| - |
| 1373 | + // iterate over each row |
1370 | 1374 | while (--r > 0) {
|
1371 | 1375 | if (this.is_widget(tcol, r) && !this.is_player_in(tcol, r)) {
|
1372 | 1376 | if (!grid_col[r].is(widget_grid_data.el)) {
|
|
0 commit comments