Update PixiBotFile command with correct blueprints functionality

This commit is contained in:
NGnius (Graham) 2020-06-07 11:59:45 -04:00
parent 6e817bff18
commit 0d25570cba

View file

@ -69,38 +69,59 @@ namespace Pixi.Robots
return; return;
} }
float3 position = new Player(PlayerType.Local).Position; float3 position = new Player(PlayerType.Local).Position;
position.y += (float)blockSize; position.y += (float)(blockSize * CubeSize * 3); // 3 is roughly the max height of any cube in RC
CubeInfo[] cubes = CubeUtility.ParseCubes(robot.Value); CubeInfo[] cubes = CubeUtility.ParseCubes(robot.Value);
Block[][] blocks = new Block[cubes.Length][]; // move origin closer to player (since bots are rarely built at the garage bay origin)
for (int c = 0; c < cubes.Length; c++) // sometimes I wish this were C++ if (cubes.Length == 0)
{ {
CubeInfo cube = cubes[c]; Logging.CommandLogError($"Robot data contains no cubes");
float3 realPosition = (cube.position * (float)blockSize * CubeSize) + position; return;
if (cube.block == BlockIDs.TextBlock && !string.IsNullOrEmpty(cube.name)) }
{ float3 minPosition = cubes[0].position;
// TextBlock block ID means it's a placeholder for (int c = 0; c < cubes.Length; c++)
blocks[c] = CubeUtility.BuildBlueprintOrTextBlock(cube, realPosition, CubeSize); {
} float3 cubePos = cubes[c].position;
else if (cubePos.x < minPosition.x)
{
blocks[c] = new Block[] { Block.PlaceNew(cube.block, realPosition, cube.rotation, cube.color, cube.darkness, CubeSize) };
}
}
// build placeholders
// Note: this is a separate loop because everytime a new block is placed,
// a slow Sync() call is required to access it's properties.
// This way, one Sync() call is needed, instead of O(cubes.Length) calls
for (int c = 0; c < cubes.Length; c++)
{
CubeInfo cube = cubes[c];
// the goal is for this to never evaluate to true (ie all cubes are translated correctly)
if (!string.IsNullOrEmpty(cube.name) && cube.block == BlockIDs.TextBlock && blocks[c].Length == 1)
{ {
//Logging.MetaLog($"Block is {blocks[c][0].Type} and was placed as {cube.block}"); minPosition.x = cubePos.x;
blocks[c][0].Specialise<TextBlock>().Text = cube.name;
} }
} if (cubePos.y < minPosition.y)
Logging.CommandLog($"Placed {robot.Value.name} by {robot.Value.addedByDisplayName} ({cubes.Length} cubes) beside you"); {
minPosition.y = cubePos.y;
}
if (cubePos.z < minPosition.z)
{
minPosition.z = cubePos.z;
}
}
Block[][] blocks = new Block[cubes.Length][];
for (int c = 0; c < cubes.Length; c++) // sometimes I wish this were C++
{
CubeInfo cube = cubes[c];
float3 realPosition = ((cube.position - minPosition) * (float)blockSize * CubeSize) + position;
if (cube.block == BlockIDs.TextBlock && !string.IsNullOrEmpty(cube.name))
{
// TextBlock block ID means it's a placeholder
blocks[c] = CubeUtility.BuildBlueprintOrTextBlock(cube, realPosition, CubeSize);
}
else
{
blocks[c] = new Block[] { Block.PlaceNew(cube.block, realPosition, cube.rotation, cube.color, cube.darkness, CubeSize) };
}
}
int blockCount = 0;
for (int c = 0; c < cubes.Length; c++)
{
CubeInfo cube = cubes[c];
// the goal is for this to never evaluate to true (ie all cubes are translated correctly)
if (!string.IsNullOrEmpty(cube.name) && cube.block == BlockIDs.TextBlock && blocks[c].Length == 1)
{
//Logging.MetaLog($"Block is {blocks[c][0].Type} and was placed as {cube.block}");
blocks[c][0].Specialise<TextBlock>().Text = cube.name;
}
blockCount += blocks[c].Length;
}
Logging.CommandLog($"Placed {robot?.name} by {robot?.addedByDisplayName} beside you ({cubes.Length}RC -> {blockCount}GC)");
} }
private static void ImportRobotOnline(string robotName) private static void ImportRobotOnline(string robotName)