Fixes related to overlapping problems. Solve part of #4.

Some fixes are about errors (seen in the link provided by @floflow in #16)
produced by drag large blocks.
This commit is contained in:
vieron
2012-08-12 18:47:02 +02:00
parent c047153f05
commit 6c9eaf067d
+21 -14
View File
@@ -849,7 +849,6 @@
return this;
};
/**
* Determines if there is a widget in the row and col given. Or if the
* HTMLElement passed as first argument is the player.
@@ -877,7 +876,7 @@
* @return {Boolean} Returns true or false.
*/
fn.is_player_in = function(col, row) {
var c = this.cells_occupied_by_player;
var c = this.cells_occupied_by_player || {};
return $.inArray(col, c.cols) >= 0 && $.inArray(row, c.rows) >= 0;
};
@@ -1125,6 +1124,13 @@
var upper_rows = [];
var min_row = 10000;
if (widget_grid_data.col < this.player_grid_data.col &&
(widget_grid_data.col + widget_grid_data.size_y - 1) >
(this.player_grid_data.col + this.player_grid_data.size_y - 1)
) {
return false;
};
/* generate an array with columns as index and array with upper rows
* empty as value */
this.for_each_column_occupied(widget_grid_data, function(tcol) {
@@ -1134,17 +1140,19 @@
var r = p_bottom_row + 1;
while (--r > 0) {
if (this.is_occupied(tcol, r) && !this.is_player(tcol, r)) {
break;
if (this.is_widget(tcol, r) && !this.is_player_in(tcol, r)) {
if (!grid_col[r].is(widget_grid_data.el)) {
break;
};
}
if (!this.is_player(tcol, r) &&
!this.is_placeholder_in(tcol, r)
) {
!this.is_placeholder_in(tcol, r) &&
!this.is_player_in(tcol, r)) {
upper_rows[tcol].push(r);
}
};
if (r < min_row ) {
if (r < min_row) {
min_row = r;
}
}
@@ -1186,7 +1194,7 @@
while (++r <= p_bottom_row ) {
var common = true;
$.each(upper_rows, function(col, rows) {
if (rows && $.inArray(r, rows) === -1) {
if ($.isArray(rows) && $.inArray(r, rows) === -1) {
common = false;
}
});
@@ -1211,7 +1219,6 @@
}
}
return new_row;
};
@@ -1306,7 +1313,7 @@
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
*/
fn.on_stop_overlapping_column = function(col) {
this.set_player();
this.set_player(col, false);
var self = this;
this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
@@ -1324,7 +1331,7 @@
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
*/
fn.on_stop_overlapping_row = function(row) {
this.set_player();
this.set_player(false, row);
var self = this;
var cols = this.cells_occupied_by_player.cols;
@@ -1370,7 +1377,6 @@
var $w = $(widget);
var wgd = $w.coords().grid;
var can_go_up = self.can_go_widget_up(wgd);
if (can_go_up && can_go_up !== wgd.row) {
self.move_widget_to($w, can_go_up);
}
@@ -1637,7 +1643,8 @@
var $w = this.is_widget(col, prev_row);
if (this.is_occupied(col, prev_row) ||
this.is_player(col, prev_row) ||
this.is_placeholder_in(col, prev_row)
this.is_placeholder_in(col, prev_row) ||
this.is_player_in(col, prev_row)
) {
result = false;
return true; //break