Skip to content

Commit

Permalink
Adding 32X support to SonLVLColor.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed May 31, 2015
1 parent d8c7a79 commit 63d39b6
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion SonLVLAPI/DataTypes.cs
Expand Up @@ -13,6 +13,7 @@ public struct SonLVLColor
public byte R { get; set; }
public byte G { get; set; }
public byte B { get; set; }
public bool Priority { get; set; }

public Color RGBColor
{
Expand All @@ -28,6 +29,24 @@ public Color RGBColor
}
}

public ushort X32Color
{
get
{
return (ushort)((R >> 3) | ((G >> 3) << 5) | ((B >> 3) << 10) | (Priority ? 0x8000 : 0));
}
set
{
int tmp = value & 0x1F;
R = (byte)((tmp >> 2) | (tmp << 3));
tmp = (value >> 5) & 0x1F;
G = (byte)((tmp >> 2) | (tmp << 3));
tmp = (value >> 10) & 0x1F;
B = (byte)((tmp >> 2) | (tmp << 3));
Priority = (value & 0x8000) == 0x8000;
}
}

public ushort MDColor
{
get
Expand Down Expand Up @@ -74,6 +93,15 @@ public SonLVLColor(ushort mdcolor)
MDColor = mdcolor;
}

public SonLVLColor(ushort color, bool x32)
: this()
{
if (x32)
X32Color = color;
else
MDColor = color;
}

private static readonly byte[] MDColorTable = { 0, 0x24, 0x49, 0x6D, 0x92, 0xB6, 0xDB, 0xFF };

private static int RGBToMD(byte RGB)
Expand All @@ -99,7 +127,7 @@ public static SonLVLColor[] Load(byte[] file, int address, int length, EngineVer
SonLVLColor[] palfile = new SonLVLColor[length];
if (game != EngineVersion.SCDPC)
for (int pi = 0; pi < length; pi++)
palfile[pi] = new SonLVLColor(ByteConverter.ToUInt16(file, address + (pi * 2)));
palfile[pi] = new SonLVLColor(ByteConverter.ToUInt16(file, address + (pi * 2)), game == EngineVersion.Chaotix);
else
for (int pi = 0; pi < length; pi++)
palfile[pi] = new SonLVLColor(file[address + (pi * 4)], file[address + (pi * 4) + 1], file[address + (pi * 4) + 2]);
Expand Down

0 comments on commit 63d39b6

Please sign in to comment.