This commit is contained in:
NGnius (Graham) 2020-10-04 22:49:58 -04:00
commit 0e65267e88
8 changed files with 241 additions and 81 deletions

View file

@ -14,11 +14,18 @@ namespace Pixi.Common
StreamReader bluemap = new StreamReader(File.OpenRead(name)); StreamReader bluemap = new StreamReader(File.OpenRead(name));
return JsonConvert.DeserializeObject<Dictionary<string, BlockJsonInfo[]>>(bluemap.ReadToEnd()); return JsonConvert.DeserializeObject<Dictionary<string, BlockJsonInfo[]>>(bluemap.ReadToEnd());
} }
public static Dictionary<string, BlockJsonInfo[]> ParseBlueprintResource(string name) public static Dictionary<string, BlockJsonInfo[]> ParseBlueprintResource(string name)
{ {
StreamReader bluemap = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(name)); StreamReader bluemap;
return JsonConvert.DeserializeObject<Dictionary<string, BlockJsonInfo[]>>(bluemap.ReadToEnd()); #if DEBUG
if (File.Exists(name))
bluemap = File.OpenText(name);
else
#endif
bluemap = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(name));
using (bluemap)
return JsonConvert.DeserializeObject<Dictionary<string, BlockJsonInfo[]>>(bluemap.ReadToEnd());
} }
public static ProcessedVoxelObjectNotation[][] ProcessAndExpandBlocks(string name, BlockJsonInfo[] blocks, BlueprintProvider blueprints) public static ProcessedVoxelObjectNotation[][] ProcessAndExpandBlocks(string name, BlockJsonInfo[] blocks, BlueprintProvider blueprints)

View file

@ -47,12 +47,14 @@ namespace Pixi
root.Inject(new ImageTextBlockImporter()); root.Inject(new ImageTextBlockImporter());
root.Inject(new ImageCommandImporter()); root.Inject(new ImageCommandImporter());
// Robot functionality // Robot functionality
root.Inject(new RobotInternetImporter()); var robot = new RobotInternetImporter();
root.Inject(robot);
//RobotCommands.CreateRobotCRFCommand(); //RobotCommands.CreateRobotCRFCommand();
//RobotCommands.CreateRobotFileCommand(); //RobotCommands.CreateRobotFileCommand();
#if DEBUG #if DEBUG
// Development functionality // Development functionality
RobotCommands.CreatePartDumpCommand(); RobotCommands.CreatePartDumpCommand();
((RobotBlueprintProvider) robot.BlueprintProvider).AddDebugCommands();
root.Inject(new TestImporter()); root.Inject(new TestImporter());
#endif #endif
// Audio functionality // Audio functionality

View file

@ -215,10 +215,10 @@ namespace Pixi.Robots
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void TranslateBlockId(uint cubeId, ref CubeInfo result) private static void TranslateBlockId(uint cubeId, ref CubeInfo result)
{ {
if (map == null) if (map == null)
{ {
StreamReader cubemap = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Pixi.cubes-id.json")); StreamReader cubemap = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Pixi.cubes-id.json"));
map = JsonConvert.DeserializeObject<Dictionary<uint, string>>(cubemap.ReadToEnd()); map = JsonConvert.DeserializeObject<Dictionary<uint, string>>(cubemap.ReadToEnd());
} }
if (!map.ContainsKey(cubeId)) if (!map.ContainsKey(cubeId))
@ -231,81 +231,34 @@ namespace Pixi.Robots
#endif #endif
} }
string cubeName = map[cubeId]; string cubeName = map[cubeId];
string gcName = cubeName.Contains("glass") || cubeName.Contains("windshield")
? "Glass"
: "Aluminium";
if (cubeName.Contains("round"))
gcName += "Rounded";
if (cubeName.Contains("cube")) if (cubeName.Contains("cube"))
{ gcName += "Cube";
result.block = BlockIDs.AluminiumCube;
result.rotation = float3.zero;
}
else if (cubeName.Contains("prism") || cubeName.Contains("edge")) else if (cubeName.Contains("prism") || cubeName.Contains("edge"))
{ gcName += "Slope";
if (cubeName.Contains("round"))
{
if (cubeName.Contains("glass") || cubeName.Contains("windshield"))
{
result.block = BlockIDs.GlassRoundedSlope;
} else
result.block = BlockIDs.AluminiumRoundedSlope;
}
else
{
if (cubeName.Contains("glass") || cubeName.Contains("windshield"))
{
result.block = BlockIDs.GlassSlope;
} else
result.block = BlockIDs.AluminiumSlope;
}
}
else if (cubeName.Contains("inner")) else if (cubeName.Contains("inner"))
{ gcName += "SlicedCube";
if (cubeName.Contains("round"))
{
if (cubeName.Contains("glass") || cubeName.Contains("windshield"))
{
result.block = BlockIDs.GlassRoundedSlicedCube;
} else
result.block = BlockIDs.AluminiumRoundedSlicedCube;
}
else
{
if (cubeName.Contains("glass") || cubeName.Contains("windshield"))
{
result.block = BlockIDs.GlassSlicedCube;
} else
result.block = BlockIDs.AluminiumSlicedCube;
}
}
else if (cubeName.Contains("tetra") || cubeName.Contains("corner")) else if (cubeName.Contains("tetra") || cubeName.Contains("corner"))
{ gcName += "Corner";
if (cubeName.Contains("round"))
{
if (cubeName.Contains("glass") || cubeName.Contains("windshield"))
{
result.block = BlockIDs.GlassRoundedCorner;
} else
result.block = BlockIDs.AluminiumRoundedCorner;
}
else
{
if (cubeName.Contains("glass") || cubeName.Contains("windshield"))
{
result.block = BlockIDs.GlassCorner;
} else
result.block = BlockIDs.AluminiumCorner;
}
}
else if (cubeName.Contains("pyramid")) else if (cubeName.Contains("pyramid"))
{ gcName += "PyramidSegment";
result.block = BlockIDs.AluminiumPyramidSegment;
}
else if (cubeName.Contains("cone")) else if (cubeName.Contains("cone"))
{ gcName += "ConeSegment";
result.block = BlockIDs.AluminiumConeSegment;
}
else else
{ {
result.block = BlockIDs.TextBlock; result.block = BlockIDs.TextBlock;
result.name = cubeName; result.name = cubeName;
return;
} }
BlockIDs id = VoxelObjectNotationUtility.NameToEnum(gcName);
result.block = id;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -1,12 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using Svelto.DataStructures; using Svelto.DataStructures;
using Unity.Mathematics; using Unity.Mathematics;
using UnityEngine; using UnityEngine;
using GamecraftModdingAPI.Blocks; using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Commands;
using GamecraftModdingAPI.Utility; using GamecraftModdingAPI.Utility;
using Newtonsoft.Json;
using Pixi.Common; using Pixi.Common;
namespace Pixi.Robots namespace Pixi.Robots
@ -96,5 +98,49 @@ namespace Pixi.Robots
} }
return adjustedBlueprint; return adjustedBlueprint;
} }
#if DEBUG
public void AddDebugCommands()
{
CommandBuilder.Builder("PixiReload", "Reloads the robot blueprints")
.Action(() => botprints = null).Build();
CommandBuilder.Builder("RotateBlueprint",
"Rotates a blueprint with a given ID and dumps the result to a file. 1 means 90 degrees.")
.Action<string>(RotateBlueprint).Build();
}
private void RotateBlueprint(string parameters)
{
var p = parameters.Split(' ');
string id = p[0];
var xyz = new int[3];
for (int i = 0; i < xyz.Length; i++)
xyz[i] = int.Parse(p[i + 1]) * 90;
if (botprints == null)
{
botprints = BlueprintUtility.ParseBlueprintResource("Pixi.blueprints.json");
}
if (!botprints.ContainsKey(id))
{
Logging.CommandLogWarning("Blueprint with that ID not found.");
return;
}
var bp = botprints[id];
var rotChange = Quaternion.Euler(xyz[0], xyz[1], xyz[2]);
for (var i = 0; i < bp.Length; i++)
{
ref var info = ref bp[i];
var pos = ConversionUtility.FloatArrayToFloat3(info.position);
info.position = ConversionUtility.Float3ToFloatArray(rotChange * pos);
var rot = Quaternion.Euler(ConversionUtility.FloatArrayToFloat3(info.rotation));
info.rotation = ConversionUtility.Float3ToFloatArray((rotChange * rot).eulerAngles);
}
File.WriteAllText(id, JsonConvert.SerializeObject(bp));
Logging.CommandLog("Blueprint rotated " + rotChange.eulerAngles + " and dumped");
}
#endif
} }
} }

View file

@ -31,7 +31,9 @@ namespace Pixi.Robots
{ {
Player local = new Player(PlayerType.Local); Player local = new Player(PlayerType.Local);
Block baseBlock = local.GetBlockLookedAt(); Block baseBlock = local.GetBlockLookedAt();
Block[] blocks = baseBlock.GetConnectedCubes(); Block[] blocks = local.GetSelectedBlocks();
if (blocks.Length == 0)
blocks = baseBlock.GetConnectedCubes();
bool isBaseScaled = !(baseBlock.Scale.x > 0 && baseBlock.Scale.x < 2 && baseBlock.Scale.y > 0 && baseBlock.Scale.y < 2 && baseBlock.Scale.z > 0 && baseBlock.Scale.z < 2); bool isBaseScaled = !(baseBlock.Scale.x > 0 && baseBlock.Scale.x < 2 && baseBlock.Scale.y > 0 && baseBlock.Scale.y < 2 && baseBlock.Scale.z > 0 && baseBlock.Scale.z < 2);
if (isBaseScaled) if (isBaseScaled)
{ {

View file

@ -148,8 +148,8 @@ namespace Pixi.Robots
// the goal is for this to never evaluate to true (ie all cubes are translated correctly) // the goal is for this to never evaluate to true (ie all cubes are translated correctly)
if (block.Type == BlockIDs.TextBlock) if (block.Type == BlockIDs.TextBlock)
{ {
textBlockInfoIndex++; block.Specialise<TextBlock>().Text = textBlockInfo[name][textBlockInfoIndex];
block.Specialise<TextBlock>().Text = textBlockInfo[name][textBlockInfoIndex]; textBlockInfoIndex++;
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long