public LocaleSymbol HandleFormatting(string formattingCode, LocaleSymbol prevSymbol)
{
if (formattingCode == "#")
prevSymbol.Wrap = true;
else if (formattingCode[0] == '%')
prevSymbol.TextSpeed = int.Parse(formattingCode[1..]);
else if (formattingCode.Contains('~'))
{
var perLetter = formattingCode.Contains('@');
var parsedShakingData = formattingCode[(1 + perLetter.ToInt())..].Split(", ");
var shaking = new Shaking((Vector2.One * int.Parse(parsedShakingData[0])).ToVector3());
shaking.IsLerped = bool.Parse(parsedShakingData[1]);
prevSymbol.Shaking = shaking;
prevSymbol.ShakingWholeFragment = !perLetter;
}
else if (formattingCode[0] == '&')
{
if (formattingCode.Contains("New"))
{
string colorValuesInString = formattingCode[5..].Replace(')', '\0');
string[] colorValues = colorValuesInString.Split(", ");
prevSymbol.Color = new Color(
Convert.ToByte(colorValues[0]),
Convert.ToByte(colorValues[1]),
Convert.ToByte(colorValues[2])) * Convert.ToSingle(colorValues[3]);
}
else
prevSymbol.Color = ColorExtensions.NameToColor(formattingCode[1..]);
}
return prevSymbol;
}
public string GetFormattingCode(string text)
{
// Use a string builder to reduce memory usage
StringBuilder sb = new();
foreach (var c in text)
{
if (c == '>')
break;
formattingCode.Append(c);
}
return formattingCode.ToString();
}