-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSonLVL.cs
55 lines (46 loc) · 2.02 KB
/
SonLVL.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using SonicRetro.SonLVL.API;
namespace CustomLayout
{
public class CustomLayout : LayoutFormatSeparate
{
private void ReadLayoutInternal(byte[] rawdata, ref ushort[,] layout, ref bool[,] loop)
{
layout = new ushort[MaxSize.Width, MaxSize.Height];
loop = new bool[MaxSize.Width, MaxSize.Height];
for (int lr = 0; lr < MaxSize.Height; lr++)
for (int lc = 0; lc < MaxSize.Width; lc++)
{
if ((lr * MaxSize.Width) + lc >= rawdata.Length) break;
layout[lc, lr] = (byte)(rawdata[(lr * MaxSize.Width) + lc] & 0x7F);
loop[lc, lr] = (rawdata[(lr * MaxSize.Width) + lc] & 0x80) == 0x80;
}
}
public override void ReadFG(byte[] rawdata, LayoutData layout)
{
ReadLayoutInternal(rawdata, ref layout.FGLayout, ref layout.FGLoop);
}
public override void ReadBG(byte[] rawdata, LayoutData layout)
{
ReadLayoutInternal(rawdata, ref layout.BGLayout, ref layout.BGLoop);
}
private void WriteLayoutInternal(ushort[,] layout, bool[,] loop, out byte[] rawdata)
{
rawdata = new byte[MaxSize.Width * MaxSize.Height];
int c = 0;
for (int lr = 0; lr < MaxSize.Height; lr++)
for (int lc = 0; lc < MaxSize.Width; lc++)
rawdata[c++] = (byte)(layout[lc, lr] | (loop[lc, lr] ? 0x80 : 0));
}
public override void WriteFG(LayoutData layout, out byte[] rawdata)
{
WriteLayoutInternal(layout.FGLayout, layout.FGLoop, out rawdata);
}
public override void WriteBG(LayoutData layout, out byte[] rawdata)
{
WriteLayoutInternal(layout.BGLayout, layout.BGLoop, out rawdata);
}
public override bool HasLoopFlag { get { return true; } }
public override bool IsResizable { get { return false; } }
public override System.Drawing.Size MaxSize { get { return new System.Drawing.Size(128, 8); } }
}
}