Improve code in tool and add comments

This commit is contained in:
Lorenzo Carletti 2020-10-28 10:54:54 +01:00
parent 4f910ebbcc
commit a4fc2450f3
1 changed files with 18 additions and 7 deletions

View File

@ -19,36 +19,45 @@ namespace RenderStaffCredits
static void Main(string[] args)
{
//Load the stuff we'll use
string[] staff_text = File.ReadAllLines(args[0]);
string dataFolder = args[1] + Path.DirectorySeparatorChar;
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"));
//Prepare the empty arrangements
Arrangements = createArrangements(getStaffTextLength(staff_text));
int pos = 0;
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);
}
//Save the 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];
writeIntToByteArr(extra_things, player_Y_Pos, 0, 2);
writeIntToByteArr(extra_things, defaultPlayerName.Length, 2, 2);
writeIntToByteArrLE(extra_things, player_Y_Pos, 0, 2);
writeIntToByteArrLE(extra_things, defaultPlayerName.Length, 2, 2);
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];
writeIntToByteArr(size, Arrangements.Length / 0x20, 0, 4);
writeIntToByteArrLE(size, arrSize, 0, 4);
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];
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);
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);
}
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++)
arr[pos + i] = (byte)((value >> (8 * i)) & 0xFF);
@ -79,6 +88,7 @@ namespace RenderStaffCredits
}
if (str.StartsWith("player_name"))
{
//Save data that tells us where to put the player_name at runtime
player_Y_Pos = YPosition;
handleBigText(defaultPlayerName, Arrangements, YPosition);
return 2;
@ -90,6 +100,7 @@ namespace RenderStaffCredits
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();
int XPosition = getStrStartPos(content);
for (int i = 0; i < content.Length; i++)
@ -98,7 +109,7 @@ namespace RenderStaffCredits
if (m12BigCharArrLookup.ContainsKey(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));
}
}
}