Commits

stqn committed 13fb872

End fix for insert/delete row/column.

Comments (0)

Files changed (2)

 				break;
 
 				case ActionType.DELETE_COLUMN:
-					gMap.insertColumn( xMap + xOffset );
+					gMap.deleteColumn( xMap + xOffset );
 				break;
 
 				case ActionType.INSERT_LINE:
 		mMap = mMap[0 .. rownum] ~ emptyRow2 ~ mMap[rownum .. $];
 
 		// move objects that are below this row one tile lower
-		for( int r = rownum + 1; r < mMap.length; r++ ) {
+		moveObjectRows( rownum + 1, mHeight, TILE_HEIGHT );
+
+		mHeight++;
+	}
+
+
+	void deleteRow( uint rownum ) {
+		mMapFile = mMapFile[0 .. rownum] ~ mMapFile[rownum+1 .. $];
+		// remove objects on this row
+		//foreach( cell; mMap[row] )
+			//foreach( o; cell ) removeObject(o);
+		// suppress the row
+		mMap = mMap[0 .. rownum] ~ mMap[rownum+1 .. $];
+
+		// move objects that are below this row one tile higher
+		moveObjectRows( rownum, mHeight - 2, -TILE_HEIGHT );
+
+		mHeight--;
+	}
+
+
+	void moveObjectRows( uint minRow, uint maxRow, int deltaPix ) {
+		for( int r = minRow; r <= maxRow; r++ ) {
 			foreach( inout square; mMap[r] ) {
 				foreach( o; square ) {
-					o.mY += TILE_HEIGHT;
+					o.mY += deltaPix;
 				}
 			}
 		}
+	}
 
-		mHeight++;
-	}
-
 
 	void insertColumn( uint colnum ) {
 		foreach( inout row; mMapFile ) {
 			// the right
 			for( int c = colnum + 1; c < mMap[r].length; c++ ) {
 				foreach( o; row[c] ) {
-					o.mX += TILE_HEIGHT;
+					o.mX += TILE_WIDTH;
 				}
 			}
 		}
 	}
 
 
-	void deleteRow( uint row ) {
-		mMapFile = mMapFile[0 .. row] ~ mMapFile[row+1 .. $];
-		// remove objects on this row
-		foreach( cell; mMap[row] )
-			foreach( o; cell ) removeObject(o);
-		// suppress the row
-		mMap = mMap[0 .. row] ~ mMap[row+1 .. $];
-	}
+	void deleteColumn( uint colnum ) {
+		foreach( inout row; mMapFile ) {
+			row = row[0 .. colnum] ~ row[colnum+1 .. $];
+		}
 
-
-	void deleteColumn( uint col ) {
-		foreach( inout row; mMapFile ) {
-			row = row[0 .. col] ~ row[col+1 .. $];
-		}
 		foreach( inout row; mMap ) {
 			// remove objects on this column for this row
-			foreach( o; row[col] ) removeObject( o );
-			// supress the cell at colum on this row
-			row = row[0 .. col] ~ row[col+1 .. $];
+			//foreach( o; row[colnum] ) removeObject( o );
+			// supress the cell at colnum on this row
+			row = row[0 .. colnum] ~ row[colnum+1 .. $];
+			// move objects that are on the right of the old column one tile to
+			// the left
+			for( int c = colnum; c < row.length; c++ ) {
+				foreach( o; row[c] ) {
+					o.mX -= TILE_WIDTH;
+				}
+			}
 		}
+
+		mWidth--;
 	}
 
 }