Improve code in tool and add comments
This commit is contained in:
parent
4f910ebbcc
commit
a4fc2450f3
|
@ -19,36 +19,45 @@ namespace RenderStaffCredits
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
//Load the stuff we'll use
|
||||||
string[] staff_text = File.ReadAllLines(args[0]);
|
string[] staff_text = File.ReadAllLines(args[0]);
|
||||||
string dataFolder = args[1] + Path.DirectorySeparatorChar;
|
string dataFolder = args[1] + Path.DirectorySeparatorChar;
|
||||||
m12BigCharArrLookup = JsonConvert.DeserializeObject<Dictionary<string, ushort>>(Asset.ReadAllText("m12-big-arr-lookup.json"));
|
m12BigCharArrLookup = JsonConvert.DeserializeObject<Dictionary<string, ushort>>(Asset.ReadAllText("m12-big-arr-lookup.json"));
|
||||||
m12SmallCharArrLookup = JsonConvert.DeserializeObject<Dictionary<string, ushort>>(Asset.ReadAllText("m12-small-arr-lookup.json"));
|
m12SmallCharArrLookup = JsonConvert.DeserializeObject<Dictionary<string, ushort>>(Asset.ReadAllText("m12-small-arr-lookup.json"));
|
||||||
|
|
||||||
|
//Prepare the empty arrangements
|
||||||
Arrangements = createArrangements(getStaffTextLength(staff_text));
|
Arrangements = createArrangements(getStaffTextLength(staff_text));
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (int i = 0; i < staff_text.Length; i++)
|
for (int i = 0; i < staff_text.Length; i++)
|
||||||
{
|
{
|
||||||
|
//Handle a single line and increment the current YPosition accordingly
|
||||||
pos += handleStr(staff_text[i], Arrangements, pos);
|
pos += handleStr(staff_text[i], Arrangements, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Save the arrangements
|
||||||
File.WriteAllBytes(dataFolder + "m2-credits-arrangements_[c].bin", GBA.LZ77.Compress(convertUShortArrToByteArrLE(Arrangements)));
|
File.WriteAllBytes(dataFolder + "m2-credits-arrangements_[c].bin", GBA.LZ77.Compress(convertUShortArrToByteArrLE(Arrangements)));
|
||||||
|
//Save some data that tells us where to put the player name at runtime
|
||||||
byte[] extra_things = new byte[4];
|
byte[] extra_things = new byte[4];
|
||||||
writeIntToByteArr(extra_things, player_Y_Pos, 0, 2);
|
writeIntToByteArrLE(extra_things, player_Y_Pos, 0, 2);
|
||||||
writeIntToByteArr(extra_things, defaultPlayerName.Length, 2, 2);
|
writeIntToByteArrLE(extra_things, defaultPlayerName.Length, 2, 2);
|
||||||
File.WriteAllBytes(dataFolder + "m2-credits-extra-data.bin", extra_things);
|
File.WriteAllBytes(dataFolder + "m2-credits-extra-data.bin", extra_things);
|
||||||
|
//Save some data that tells us how many vertical tiles the arrangement is long
|
||||||
|
int arrSize = Arrangements.Length / 0x20;
|
||||||
byte[] size = new byte[4];
|
byte[] size = new byte[4];
|
||||||
writeIntToByteArr(size, Arrangements.Length / 0x20, 0, 4);
|
writeIntToByteArrLE(size, arrSize, 0, 4);
|
||||||
File.WriteAllBytes(dataFolder + "m2-credits-size.bin", size);
|
File.WriteAllBytes(dataFolder + "m2-credits-size.bin", size);
|
||||||
|
//Save some data that tells us where to end scrolling at runtime (in pixels)
|
||||||
|
int scrollSize = (arrSize + defaultOffset) * 8;
|
||||||
byte[] size_full = new byte[4];
|
byte[] size_full = new byte[4];
|
||||||
writeIntToByteArr(size_full, ((Arrangements.Length / 0x20) + defaultOffset) * 8, 0, 4);
|
writeIntToByteArrLE(size_full, scrollSize, 0, 4);
|
||||||
File.WriteAllBytes(dataFolder + "m2-credits-scroll-size.bin", size_full);
|
File.WriteAllBytes(dataFolder + "m2-credits-scroll-size.bin", size_full);
|
||||||
byte[] size_minus_one = new byte[4];
|
byte[] size_minus_one = new byte[4];
|
||||||
writeIntToByteArr(size_minus_one, (((Arrangements.Length / 0x20) + defaultOffset) * 8) - 1, 0, 4);
|
writeIntToByteArrLE(size_minus_one, scrollSize - 1, 0, 4);
|
||||||
File.WriteAllBytes(dataFolder + "m2-credits-scroll-size-limit.bin", size_minus_one);
|
File.WriteAllBytes(dataFolder + "m2-credits-scroll-size-limit.bin", size_minus_one);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeIntToByteArr(byte[] arr, int value, int pos, int limiter)
|
static void writeIntToByteArrLE(byte[] arr, int value, int pos, int limiter)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < limiter; i++)
|
for (int i = 0; i < limiter; i++)
|
||||||
arr[pos + i] = (byte)((value >> (8 * i)) & 0xFF);
|
arr[pos + i] = (byte)((value >> (8 * i)) & 0xFF);
|
||||||
|
@ -79,6 +88,7 @@ namespace RenderStaffCredits
|
||||||
}
|
}
|
||||||
if (str.StartsWith("player_name"))
|
if (str.StartsWith("player_name"))
|
||||||
{
|
{
|
||||||
|
//Save data that tells us where to put the player_name at runtime
|
||||||
player_Y_Pos = YPosition;
|
player_Y_Pos = YPosition;
|
||||||
handleBigText(defaultPlayerName, Arrangements, YPosition);
|
handleBigText(defaultPlayerName, Arrangements, YPosition);
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -90,6 +100,7 @@ namespace RenderStaffCredits
|
||||||
|
|
||||||
static void handleBigText(string content, ushort[] Arrangements, int YPosition)
|
static void handleBigText(string content, ushort[] Arrangements, int YPosition)
|
||||||
{
|
{
|
||||||
|
//The big text, normally, has a top tile and a bottom tile. The bottom tile is 0x20 tiles after the top tile
|
||||||
content = content.ToUpper();
|
content = content.ToUpper();
|
||||||
int XPosition = getStrStartPos(content);
|
int XPosition = getStrStartPos(content);
|
||||||
for (int i = 0; i < content.Length; i++)
|
for (int i = 0; i < content.Length; i++)
|
||||||
|
@ -98,7 +109,7 @@ namespace RenderStaffCredits
|
||||||
if (m12BigCharArrLookup.ContainsKey(value))
|
if (m12BigCharArrLookup.ContainsKey(value))
|
||||||
{
|
{
|
||||||
Arrangements[(YPosition * 0x20) + XPosition + i] = (ushort)(Palette | (arrStart + m12BigCharArrLookup[value]));
|
Arrangements[(YPosition * 0x20) + XPosition + i] = (ushort)(Palette | (arrStart + m12BigCharArrLookup[value]));
|
||||||
Arrangements[(YPosition * 0x20) + XPosition + i + 0x20] = (ushort)(Palette | (arrStart + m12BigCharArrLookup[value]) + 0x20);
|
Arrangements[(YPosition * 0x20) + XPosition + i + 0x20] = (ushort)(Palette | (arrStart + m12BigCharArrLookup[value] + 0x20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue