Skip to content

Commit

Permalink
Adding fix for block list larger than collision index list.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Dec 23, 2015
1 parent 1d1b2ff commit bd50640
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 27 deletions.
52 changes: 28 additions & 24 deletions SonLVL/MainForm.cs
Expand Up @@ -1155,11 +1155,11 @@ private void blocksToolStripMenuItem_Click(object sender, EventArgs e)
}
if (dualPath)
{
LevelData.ColBmpBits[LevelData.ColInds1[i]].ToBitmap1bpp(Color.Black, Color.White).Save(pathBase + "_col1.png");
LevelData.ColBmpBits[LevelData.ColInds2[i]].ToBitmap1bpp(Color.Black, Color.White).Save(pathBase + "_col2.png");
LevelData.ColBmpBits[LevelData.GetColInd1(i)].ToBitmap1bpp(Color.Black, Color.White).Save(pathBase + "_col1.png");
LevelData.ColBmpBits[LevelData.GetColInd2(i)].ToBitmap1bpp(Color.Black, Color.White).Save(pathBase + "_col2.png");
}
else
LevelData.ColBmpBits[LevelData.ColInds1[i]].ToBitmap1bpp(Color.Black, Color.White).Save(pathBase + "_col.png");
LevelData.ColBmpBits[LevelData.GetColInd1(i)].ToBitmap1bpp(Color.Black, Color.White).Save(pathBase + "_col.png");
bits = new BitmapBits(16, 16);
for (int y = 0; y < 2; y++)
for (int x = 0; x < 2; x++)
Expand All @@ -1179,13 +1179,13 @@ private void blocksToolStripMenuItem_Click(object sender, EventArgs e)
bits = new BitmapBits(16, 16);
if (path1ToolStripMenuItem.Checked)
{
BitmapBits bmp = new BitmapBits(LevelData.ColBmpBits[LevelData.ColInds1[i]]);
BitmapBits bmp = new BitmapBits(LevelData.ColBmpBits[LevelData.GetColInd1(i)]);
bmp.IncrementIndexes(LevelData.ColorWhite - 1);
bits.DrawBitmapComposited(bmp, 0, 0);
}
else if (path2ToolStripMenuItem.Checked)
{
BitmapBits bmp = new BitmapBits(LevelData.ColBmpBits[LevelData.ColInds2[i]]);
BitmapBits bmp = new BitmapBits(LevelData.ColBmpBits[LevelData.GetColInd2(i)]);
bmp.IncrementIndexes(LevelData.ColorWhite - 1);
bits.DrawBitmapComposited(bmp, 0, 0);
}
Expand Down Expand Up @@ -1624,7 +1624,7 @@ internal void DrawLevel()
if (blk.Block > LevelData.Blocks.Count) continue;
Solidity solid = path2ToolStripMenuItem.Checked ? ((S2ChunkBlock)blk).Solid2 : blk.Solid1;
if (solid == Solidity.NotSolid) continue;
byte coli = path2ToolStripMenuItem.Checked ? LevelData.ColInds2[blk.Block] : LevelData.ColInds1[blk.Block];
byte coli = path2ToolStripMenuItem.Checked ? LevelData.GetColInd2(blk.Block) : LevelData.GetColInd1(blk.Block);
byte angle = LevelData.Angles[coli];
if (angle != 0xFF)
{
Expand Down Expand Up @@ -1733,7 +1733,7 @@ internal void DrawLevel()
if (blk.Block > LevelData.Blocks.Count) continue;
Solidity solid = path2ToolStripMenuItem.Checked ? ((S2ChunkBlock)blk).Solid2 : blk.Solid1;
if (solid == Solidity.NotSolid) continue;
byte coli = path2ToolStripMenuItem.Checked ? LevelData.ColInds2[blk.Block] : LevelData.ColInds1[blk.Block];
byte coli = path2ToolStripMenuItem.Checked ? LevelData.GetColInd2(blk.Block) : LevelData.GetColInd1(blk.Block);
byte angle = LevelData.Angles[coli];
if (angle != 0xFF)
{
Expand Down Expand Up @@ -1817,7 +1817,7 @@ internal void DrawLevel()
if (blk.Block > LevelData.Blocks.Count) continue;
Solidity solid = path2ToolStripMenuItem.Checked ? ((S2ChunkBlock)blk).Solid2 : blk.Solid1;
if (solid == Solidity.NotSolid) continue;
byte coli = path2ToolStripMenuItem.Checked ? LevelData.ColInds2[blk.Block] : LevelData.ColInds1[blk.Block];
byte coli = path2ToolStripMenuItem.Checked ? LevelData.GetColInd2(blk.Block) : LevelData.GetColInd1(blk.Block);
byte angle = LevelData.Angles[coli];
if (angle != 0xFF)
{
Expand Down Expand Up @@ -3642,10 +3642,14 @@ private void BlockSelector_SelectedIndexChanged(object sender, EventArgs e)
SelectedBlockTile = new Point();
blockTileEditor.SelectedObject = LevelData.Blocks[SelectedBlock].Tiles[0, 0];
if (LevelData.ColInds1.Count > 0)
{
BlockCollision1.Value = LevelData.ColInds1[SelectedBlock];
BlockCollision2.Value = LevelData.ColInds2[SelectedBlock];
}
if (SelectedBlock < LevelData.ColInds1.Count)
{
ColIndBox.Enabled = true;
BlockCollision1.Value = LevelData.GetColInd1(SelectedBlock);
BlockCollision2.Value = LevelData.GetColInd2(SelectedBlock);
}
else
ColIndBox.Enabled = false;
BlockID.Text = SelectedBlock.ToString("X3");
BlockCount.Text = LevelData.Blocks.Count.ToString("X") + " / " + LevelData.GetBlockMax().ToString("X");
DrawBlockPicture();
Expand Down Expand Up @@ -3680,13 +3684,13 @@ private void DrawBlockPicture()
bmp.DrawBitmapComposited(LevelData.BlockBmpBits[SelectedBlock][1], 0, 0);
if (path1ToolStripMenuItem.Checked)
{
BitmapBits tmp = new BitmapBits(LevelData.ColBmpBits[LevelData.ColInds1[SelectedBlock]]);
BitmapBits tmp = new BitmapBits(LevelData.ColBmpBits[LevelData.GetColInd1(SelectedBlock)]);
tmp.IncrementIndexes(LevelData.ColorWhite);
bmp.DrawBitmapComposited(tmp, 0, 0);
}
if (path2ToolStripMenuItem.Checked)
{
BitmapBits tmp = new BitmapBits(LevelData.ColBmpBits[LevelData.ColInds2[SelectedBlock]]);
BitmapBits tmp = new BitmapBits(LevelData.ColBmpBits[LevelData.GetColInd2(SelectedBlock)]);
tmp.IncrementIndexes(LevelData.ColorWhite);
bmp.DrawBitmapComposited(tmp, 0, 0);
}
Expand Down Expand Up @@ -6458,12 +6462,12 @@ private void alignLeftWallToolStripButton_Click(object sender, EventArgs e)
if (path2ToolStripMenuItem.Checked)
{
solid = ((S2ChunkBlock)blk).Solid2;
colind = LevelData.ColInds2[blk.Block];
colind = LevelData.GetColInd2(blk.Block);
}
else
{
solid = blk.Solid1;
colind = LevelData.ColInds1[blk.Block];
colind = LevelData.GetColInd1(blk.Block);
}
if ((solid & Solidity.LRBSolid) == Solidity.LRBSolid)
{
Expand Down Expand Up @@ -6518,12 +6522,12 @@ private void alignGroundToolStripButton_Click(object sender, EventArgs e)
if (path2ToolStripMenuItem.Checked)
{
solid = ((S2ChunkBlock)blk).Solid2;
colind = LevelData.ColInds2[blk.Block];
colind = LevelData.GetColInd2(blk.Block);
}
else
{
solid = blk.Solid1;
colind = LevelData.ColInds1[blk.Block];
colind = LevelData.GetColInd1(blk.Block);
}
if ((solid & Solidity.TopSolid) == Solidity.TopSolid)
{
Expand Down Expand Up @@ -6578,12 +6582,12 @@ private void alignRightWallToolStripButton_Click(object sender, EventArgs e)
if (path2ToolStripMenuItem.Checked)
{
solid = ((S2ChunkBlock)blk).Solid2;
colind = LevelData.ColInds2[blk.Block];
colind = LevelData.GetColInd2(blk.Block);
}
else
{
solid = blk.Solid1;
colind = LevelData.ColInds1[blk.Block];
colind = LevelData.GetColInd1(blk.Block);
}
if ((solid & Solidity.LRBSolid) == Solidity.LRBSolid)
{
Expand Down Expand Up @@ -6638,12 +6642,12 @@ private void alignCeilingToolStripButton_Click(object sender, EventArgs e)
if (path2ToolStripMenuItem.Checked)
{
solid = ((S2ChunkBlock)blk).Solid2;
colind = LevelData.ColInds2[blk.Block];
colind = LevelData.GetColInd2(blk.Block);
}
else
{
solid = blk.Solid1;
colind = LevelData.ColInds1[blk.Block];
colind = LevelData.GetColInd1(blk.Block);
}
if ((solid & Solidity.LRBSolid) == Solidity.LRBSolid)
{
Expand Down Expand Up @@ -8725,9 +8729,9 @@ public ChunkCopyData(Chunk chunk)
blocks.Add(chunk.Blocks[x, y].Block);
if (ColInds1 != null)
{
ColInds1.Add(LevelData.ColInds1[chunk.Blocks[x, y].Block]);
ColInds1.Add(LevelData.GetColInd1(chunk.Blocks[x, y].Block));
if (ColInds2 != null)
ColInds2.Add(LevelData.ColInds2[chunk.Blocks[x, y].Block]);
ColInds2.Add(LevelData.GetColInd2(chunk.Blocks[x, y].Block));
}
}
Chunk.Blocks[x, y].Block = (ushort)i;
Expand Down
20 changes: 17 additions & 3 deletions SonLVLAPI/LevelData.cs
Expand Up @@ -2684,13 +2684,13 @@ public static void RedrawChunk(int chunk)
bx * 16, by * 16);
if (ColInds1.Count > 0)
{
bmp = new BitmapBits(ColBmpBits[ColInds1[blk.Block]]);
bmp = new BitmapBits(ColBmpBits[GetColInd1(blk.Block)]);
bmp.IncrementIndexes((int)blk.Solid1 - 1);
bmp.Flip(blk.XFlip, blk.YFlip);
ChunkColBmpBits[chunk][0].DrawBitmap(bmp, bx * 16, by * 16);
if (blk is S2ChunkBlock)
{
bmp = new BitmapBits(ColBmpBits[ColInds2[blk.Block]]);
bmp = new BitmapBits(ColBmpBits[GetColInd2(blk.Block)]);
bmp.IncrementIndexes((int)((S2ChunkBlock)blk).Solid2 - 1);
bmp.Flip(blk.XFlip, blk.YFlip);
ChunkColBmpBits[chunk][1].DrawBitmap(bmp, bx * 16, by * 16);
Expand Down Expand Up @@ -2813,7 +2813,7 @@ public static void RedrawCol(int block, bool drawChunks)
bool dr = false;
for (int k = 0; k < Level.ChunkHeight / 16; k++)
for (int j = 0; j < Level.ChunkWidth / 16; j++)
if (ColInds1[Chunks[i].Blocks[j, k].Block] == block | ColInds2[Chunks[i].Blocks[j, k].Block] == block)
if (GetColInd1(Chunks[i].Blocks[j, k].Block) == block | GetColInd2(Chunks[i].Blocks[j, k].Block) == block)
dr = true;
if (dr)
RedrawChunk(i);
Expand Down Expand Up @@ -3252,6 +3252,20 @@ public static int GetBlockMax()
blockmax = Game.BlockMax.Value;
return blockmax;
}

public static byte GetColInd1(int index)
{
if (index >= ColInds1.Count)
return 0;
return ColInds1[index];
}

public static byte GetColInd2(int index)
{
if (index >= ColInds2.Count)
return 0;
return ColInds2[index];
}
}

public class LayoutData
Expand Down

0 comments on commit bd50640

Please sign in to comment.