Add RC propellers and fix textblock <color> replacement regex

This commit is contained in:
NGnius (Graham) 2020-10-27 15:53:27 -04:00
parent 3c00d05a3b
commit c3dc80fc84
3 changed files with 16 additions and 24 deletions

View file

@ -35,14 +35,8 @@ namespace Pixi.Robots
if (!botprints.ContainsKey(root.name) || RobotInternetImporter.CubeSize != 3)
{
if (!parent.textBlockInfo.ContainsKey(name))
{
parent.textBlockInfo[name] = new FasterList<string>();
}
BlockJsonInfo copy = root;
copy.name = "TextBlock";
Logging.MetaLog($"Parsing uint from '{root.name}'");
parent.textBlockInfo[name].Add(root.name + " (" + CubeUtility.CubeIdDescription(uint.Parse(root.name)) + ")");
BlockJsonInfo copy = root;
copy.name = $"TextBlock\t{root.name} ({CubeUtility.CubeIdDescription(uint.Parse(root.name))})\tPixi";
return new BlockJsonInfo[1] {copy};
}
BlockJsonInfo[] blueprint = botprints[root.name];

View file

@ -27,8 +27,6 @@ namespace Pixi.Robots
public BlueprintProvider BlueprintProvider { get; }
public static int CubeSize = 3;
internal readonly Dictionary<string, FasterList<string>> textBlockInfo = new Dictionary<string, FasterList<string>>();
public RobotInternetImporter()
{
@ -126,34 +124,26 @@ namespace Pixi.Robots
blocks[i].position += pos;
}
// set textblock colors (replace <color="white"> with <color=#HEX> in textblocks)
Regex pattern = new Regex("<color=(\"white\")|(white)>", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
Regex pattern = new Regex("<color=((?:\"white\")|(?:white))>", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
for (int i = 0; i < blocks.Length; i++)
{
if (blocks[i].block == BlockIDs.TextBlock)
{
// TODO this blindly replaces color tags anywhere in metadata, not just ones that will go in the TextBlock's text field
#if DEBUG
Logging.MetaLog($"Replacing text field in block with colour {blocks[i].color} with #{ColorUtility.ToHtmlStringRGBA(ColorSpaceUtility.UnquantizeToColor(blocks[i].color))}");
#endif
blocks[i].metadata = pattern.Replace(
blocks[i].metadata,
$"<color=#{ColorUtility.ToHtmlStringRGBA(ColorSpaceUtility.UnquantizeToColor(blocks[i].color))}>");
// NOTE: Regex.Replace replaces the whole match string only when there's a capture group (it's dumb, idk why).
// The non-capturing groups may be messing with .NET or something
}
}
}
public void PostProcess(string name, ref Block[] blocks)
{
int textBlockInfoIndex = 0;
for (int c = 0; c < blocks.Length; c++)
{
Block block = blocks[c];
// the goal is for this to never evaluate to true (ie all cubes are translated correctly)
if (block.Type == BlockIDs.TextBlock)
{
block.Specialise<TextBlock>().Text = textBlockInfo[name][textBlockInfoIndex];
textBlockInfoIndex++;
}
}
textBlockInfo.Remove(name);
}
}
}

File diff suppressed because one or more lines are too long