Skip to content

Commit

Permalink
Image importing now checks all tiles/blocks/chunks for duplicates.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Apr 16, 2015
1 parent 1fa399b commit 5d34ef1
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions SonLVL/MainForm.cs
Expand Up @@ -4228,12 +4228,10 @@ private void ImportImage(Bitmap bmp)
int h = bmp.Height;
int pal = 0;
bool match = false;
List<BitmapBits> tiles = new List<BitmapBits>();
List<Block> blocks = new List<Block>();
List<Chunk> chunks = new List<Chunk>();
List<BitmapBits> tiles = new List<BitmapBits>(LevelData.Tiles.Count);
foreach (byte[] t in LevelData.Tiles)
tiles.Add(BitmapBits.FromTile(t, 0));
byte[] tile;
int curtilecnt = LevelData.Tiles.Count;
int curblkcnt = LevelData.Blocks.Count;
switch (CurrentTab)
{
case Tab.Chunks:
Expand All @@ -4257,15 +4255,15 @@ private void ImportImage(Bitmap bmp)
if (tiles[i].Equals(bits))
{
match = true;
blk.Tiles[x, y].Tile = (ushort)(i + curtilecnt);
blk.Tiles[x, y].Tile = (ushort)i;
break;
}
BitmapBits flip = new BitmapBits(bits);
flip.Flip(true, false);
if (tiles[i].Equals(flip))
{
match = true;
blk.Tiles[x, y].Tile = (ushort)(i + curtilecnt);
blk.Tiles[x, y].Tile = (ushort)i;
blk.Tiles[x, y].XFlip = true;
break;
}
Expand All @@ -4274,7 +4272,7 @@ private void ImportImage(Bitmap bmp)
if (tiles[i].Equals(flip))
{
match = true;
blk.Tiles[x, y].Tile = (ushort)(i + curtilecnt);
blk.Tiles[x, y].Tile = (ushort)i;
blk.Tiles[x, y].YFlip = true;
break;
}
Expand All @@ -4283,7 +4281,7 @@ private void ImportImage(Bitmap bmp)
if (tiles[i].Equals(flip))
{
match = true;
blk.Tiles[x, y].Tile = (ushort)(i + curtilecnt);
blk.Tiles[x, y].Tile = (ushort)i;
blk.Tiles[x, y].XFlip = true;
blk.Tiles[x, y].YFlip = true;
break;
Expand All @@ -4298,17 +4296,16 @@ private void ImportImage(Bitmap bmp)
TileSelector.Images.Add(LevelData.TileToBmp4bpp(LevelData.Tiles[SelectedTile], 0, SelectedColor.Y));
}
match = false;
for (int i = 0; i < blocks.Count; i++)
for (int i = 0; i < LevelData.Blocks.Count; i++)
{
if (blk.Equals(blocks[i]))
if (blk.Equals(LevelData.Blocks[i]))
{
match = true;
cnk.Blocks[bx, by].Block = (ushort)i;
break;
}
}
if (match) continue;
blocks.Add(blk);
LevelData.Blocks.Add(blk);
LevelData.ColInds1.Add(0);
switch (LevelData.Level.ChunkFormat)
Expand All @@ -4330,16 +4327,15 @@ private void ImportImage(Bitmap bmp)
cnk.Blocks[bx, by].Block = (ushort)SelectedBlock;
}
match = false;
for (int i = 0; i < chunks.Count; i++)
for (int i = 0; i < LevelData.Chunks.Count; i++)
{
if (cnk.Equals(chunks[i]))
if (cnk.Equals(LevelData.Chunks[i]))
{
match = true;
break;
}
}
if (match) continue;
chunks.Add(cnk);
LevelData.Chunks.Add(cnk);
SelectedChunk = (byte)(LevelData.Chunks.Count - 1);
LevelData.ChunkBmpBits.Add(new BitmapBits[2]);
Expand Down Expand Up @@ -4371,15 +4367,15 @@ private void ImportImage(Bitmap bmp)
if (tiles[i].Equals(bits))
{
match = true;
blk.Tiles[x, y].Tile = (ushort)(i + curtilecnt);
blk.Tiles[x, y].Tile = (ushort)i;
break;
}
BitmapBits flip = new BitmapBits(bits);
flip.Flip(true, false);
if (tiles[i].Equals(flip))
{
match = true;
blk.Tiles[x, y].Tile = (ushort)(i + curtilecnt);
blk.Tiles[x, y].Tile = (ushort)i;
blk.Tiles[x, y].XFlip = true;
break;
}
Expand All @@ -4388,7 +4384,7 @@ private void ImportImage(Bitmap bmp)
if (tiles[i].Equals(flip))
{
match = true;
blk.Tiles[x, y].Tile = (ushort)(i + curtilecnt);
blk.Tiles[x, y].Tile = (ushort)i;
blk.Tiles[x, y].YFlip = true;
break;
}
Expand All @@ -4397,7 +4393,7 @@ private void ImportImage(Bitmap bmp)
if (tiles[i].Equals(flip))
{
match = true;
blk.Tiles[x, y].Tile = (ushort)(i + curtilecnt);
blk.Tiles[x, y].Tile = (ushort)i;
blk.Tiles[x, y].XFlip = true;
blk.Tiles[x, y].YFlip = true;
break;
Expand All @@ -4412,14 +4408,13 @@ private void ImportImage(Bitmap bmp)
TileSelector.Images.Add(LevelData.TileToBmp4bpp(LevelData.Tiles[SelectedTile], 0, SelectedColor.Y));
}
match = false;
for (int i = 0; i < blocks.Count; i++)
if (blk.Equals(blocks[i]))
for (int i = 0; i < LevelData.Blocks.Count; i++)
if (blk.Equals(LevelData.Blocks[i]))
{
match = true;
break;
}
if (match) continue;
blocks.Add(blk);
LevelData.Blocks.Add(blk);
LevelData.ColInds1.Add(0);
switch (LevelData.Level.ChunkFormat)
Expand Down

0 comments on commit 5d34ef1

Please sign in to comment.