Skip to content

Commit

Permalink
Fixing art cloning, flipping and importing.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Apr 19, 2015
1 parent 811ca54 commit 5d5e12d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions SonLVL/MainForm.cs
Expand Up @@ -4211,6 +4211,7 @@ private void ImportImage(Bitmap bmp)
int w = bmp.Width;
int h = bmp.Height;
int pal = 0;
byte? forcepal = bmp.PixelFormat == PixelFormat.Format1bppIndexed || bmp.PixelFormat == PixelFormat.Format4bppIndexed ? (byte)SelectedColor.Y : (byte?)null;
bool match = false;
List<BitmapBits> tiles = new List<BitmapBits>(LevelData.Tiles.Count);
foreach (byte[] t in LevelData.Tiles)
Expand All @@ -4231,7 +4232,7 @@ private void ImportImage(Bitmap bmp)
for (int x = 0; x < 2; x++)
{
tile = LevelData.BmpToTile(bmp.Clone(new Rectangle((cx * LevelData.Level.ChunkWidth) + (bx * 16) + (x * 8), (cy * LevelData.Level.ChunkHeight) + (by * 16) + (y * 8), 8, 8), bmp.PixelFormat), out pal);
blk.Tiles[x, y].Palette = (byte)pal;
blk.Tiles[x, y].Palette = forcepal ?? (byte)pal;
BitmapBits bits = BitmapBits.FromTile(tile, 0);
match = false;
for (int i = 0; i < tiles.Count; i++)
Expand Down Expand Up @@ -4368,7 +4369,7 @@ private void ImportImage(Bitmap bmp)
for (int x = 0; x < 2; x++)
{
tile = LevelData.BmpToTile(bmp.Clone(new Rectangle((bx * 16) + (x * 8), (by * 16) + (y * 8), 8, 8), bmp.PixelFormat), out pal);
blk.Tiles[x, y].Palette = (byte)pal;
blk.Tiles[x, y].Palette = forcepal ?? (byte)pal;
BitmapBits bits = BitmapBits.FromTile(tile, 0);
match = false;
for (int i = 0; i < tiles.Count; i++)
Expand Down Expand Up @@ -7209,6 +7210,7 @@ private void pasteOverToolStripMenuItem_Click(object sender, EventArgs e)
int ch = h / LevelData.Level.ChunkHeight;
byte[,] result = new byte[cw, ch];
int pal = 0;
byte? forcepal = bmp.PixelFormat == PixelFormat.Format1bppIndexed || bmp.PixelFormat == PixelFormat.Format4bppIndexed ? (byte)SelectedColor.Y : (byte?)null;
bool match = false;
List<BitmapBits> tiles = new List<BitmapBits>(LevelData.Tiles.Count);
foreach (byte[] t in LevelData.Tiles)
Expand All @@ -7226,7 +7228,7 @@ private void pasteOverToolStripMenuItem_Click(object sender, EventArgs e)
for (int x = 0; x < 2; x++)
{
tile = LevelData.BmpToTile(bmp.Clone(new Rectangle((cx * LevelData.Level.ChunkWidth) + (bx * 16) + (x * 8), (cy * LevelData.Level.ChunkHeight) + (by * 16) + (y * 8), 8, 8), bmp.PixelFormat), out pal);
blk.Tiles[x, y].Palette = (byte)pal;
blk.Tiles[x, y].Palette = forcepal ?? (byte)pal;
BitmapBits bits = BitmapBits.FromTile(tile, 0);
match = false;
for (int i = 0; i < tiles.Count; i++)
Expand Down
6 changes: 4 additions & 2 deletions SonLVLAPI/DataTypes.cs
Expand Up @@ -265,9 +265,10 @@ public override int GetHashCode()
public Block Clone()
{
Block result = (Block)MemberwiseClone();
result.Tiles = (PatternIndex[,])Tiles.Clone();
for (int y = 0; y < 2; y++)
for (int x = 0; x < 2; x++)
Tiles[x, y] = Tiles[x, y].Clone();
result.Tiles[x, y] = Tiles[x, y].Clone();
return result;
}

Expand Down Expand Up @@ -574,9 +575,10 @@ public override int GetHashCode()
public Chunk Clone()
{
Chunk result = (Chunk)MemberwiseClone();
result.Blocks = (ChunkBlock[,])Blocks.Clone();
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
result.Blocks[x, y] = result.Blocks[x, y].Clone();
result.Blocks[x, y] = Blocks[x, y].Clone();
return result;
}

Expand Down

0 comments on commit 5d5e12d

Please sign in to comment.