Commits

stqn committed fdffc8e

Fix Map.insertRow()/insertColumn().

Comments (0)

Files changed (1)

 
 
 	void insertRow( uint rownum ) {
-
 		// update the mapfile
 		char[] emptyRow;
 		emptyRow = std.string.repeat(" ", mWidth-1 );
 		emptyRow2.length = mWidth;
 		mMap = mMap[0 .. rownum] ~ emptyRow2 ~ mMap[rownum .. $];
 
-		// move objects
-		foreach( cell; mMap[rownum] ) {
-			foreach( o; cell ) {
-				float oldx = o.mX;
-				float oldy = o.mY; o.mY += TILE_HEIGHT;
-				updateObjectPosition( o, oldx, oldy );
+		// move objects that are below this row one tile lower
+		for( int r = rownum + 1; r < mMap.length; r++ ) {
+			foreach( inout square; mMap[r] ) {
+				foreach( o; square ) {
+					o.mY += TILE_HEIGHT;
+				}
 			}
 		}
+
+		mHeight++;
 	}
 
 
 			row = row[0 .. colnum] ~ ' ' ~ row[colnum .. $];
 		}
 
-		foreach( inout row; mMap ) {
+		foreach( r, inout row; mMap ) {
 			ObjectList o;
 			row = row[0 .. colnum] ~ o ~ row[colnum .. $];
 
-			// move objects
-			foreach( o; row[colnum] ) {
-				float oldx = o.mX;
-				float oldy = o.mY; o.mY += TILE_HEIGHT;
-				updateObjectPosition( o, oldx, oldy );
+			// move objects that are on the right of the new column one tile to
+			// the right
+			for( int c = colnum + 1; c < mMap[r].length; c++ ) {
+				foreach( o; row[c] ) {
+					o.mX += TILE_HEIGHT;
+				}
 			}
 		}
+
+		mWidth++;
 	}
 
 
 		// suppress the row
 		mMap = mMap[0 .. row] ~ mMap[row+1 .. $];
 	}
+
 
 	void deleteColumn( uint col ) {
 		foreach( inout row; mMapFile ) {