NGnius (Graham) 3 years ago
parent
commit
0e65267e88
8 changed files with 242 additions and 82 deletions
  1. +10
    -3
      Pixi/Common/BlueprintUtility.cs
  2. +3
    -1
      Pixi/PixiPlugin.cs
  3. +19
    -66
      Pixi/Robots/CubeUtility.cs
  4. +47
    -1
      Pixi/Robots/RobotBlueprintProvider.cs
  5. +3
    -1
      Pixi/Robots/RobotCommands.cs
  6. +2
    -2
      Pixi/Robots/RobotInternetImporter.cs
  7. +157
    -7
      Pixi/blueprints.json
  8. +1
    -1
      Pixi/cubes-id.json

+ 10
- 3
Pixi/Common/BlueprintUtility.cs View File

@@ -14,11 +14,18 @@ namespace Pixi.Common
StreamReader bluemap = new StreamReader(File.OpenRead(name));
return JsonConvert.DeserializeObject<Dictionary<string, BlockJsonInfo[]>>(bluemap.ReadToEnd());
}
public static Dictionary<string, BlockJsonInfo[]> ParseBlueprintResource(string name)
{
StreamReader bluemap = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(name));
return JsonConvert.DeserializeObject<Dictionary<string, BlockJsonInfo[]>>(bluemap.ReadToEnd());
StreamReader bluemap;
#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)


+ 3
- 1
Pixi/PixiPlugin.cs View File

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


+ 19
- 66
Pixi/Robots/CubeUtility.cs View File

@@ -215,10 +215,10 @@ namespace Pixi.Robots
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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"));
map = JsonConvert.DeserializeObject<Dictionary<uint, string>>(cubemap.ReadToEnd());
map = JsonConvert.DeserializeObject<Dictionary<uint, string>>(cubemap.ReadToEnd());
}

if (!map.ContainsKey(cubeId))
@@ -231,81 +231,34 @@ namespace Pixi.Robots
#endif
}
string cubeName = map[cubeId];

string gcName = cubeName.Contains("glass") || cubeName.Contains("windshield")
? "Glass"
: "Aluminium";
if (cubeName.Contains("round"))
gcName += "Rounded";

if (cubeName.Contains("cube"))
{
result.block = BlockIDs.AluminiumCube;
result.rotation = float3.zero;
}
gcName += "Cube";
else if (cubeName.Contains("prism") || cubeName.Contains("edge"))
{
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;
}
}
gcName += "Slope";
else if (cubeName.Contains("inner"))
{
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;
}
}
gcName += "SlicedCube";
else if (cubeName.Contains("tetra") || cubeName.Contains("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;
}
}
gcName += "Corner";
else if (cubeName.Contains("pyramid"))
{
result.block = BlockIDs.AluminiumPyramidSegment;
}
gcName += "PyramidSegment";
else if (cubeName.Contains("cone"))
{
result.block = BlockIDs.AluminiumConeSegment;
}
gcName += "ConeSegment";
else
{
result.block = BlockIDs.TextBlock;
result.name = cubeName;
return;
}

BlockIDs id = VoxelObjectNotationUtility.NameToEnum(gcName);
result.block = id;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]


+ 47
- 1
Pixi/Robots/RobotBlueprintProvider.cs View File

@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using Svelto.DataStructures;
using Unity.Mathematics;
using UnityEngine;

using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Commands;
using GamecraftModdingAPI.Utility;
using Newtonsoft.Json;
using Pixi.Common;

namespace Pixi.Robots
@@ -96,5 +98,49 @@ namespace Pixi.Robots
}
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
}
}

+ 3
- 1
Pixi/Robots/RobotCommands.cs View File

@@ -31,7 +31,9 @@ namespace Pixi.Robots
{
Player local = new Player(PlayerType.Local);
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);
if (isBaseScaled)
{


+ 2
- 2
Pixi/Robots/RobotInternetImporter.cs 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)
if (block.Type == BlockIDs.TextBlock)
{
textBlockInfoIndex++;
block.Specialise<TextBlock>().Text = textBlockInfo[name][textBlockInfoIndex];
block.Specialise<TextBlock>().Text = textBlockInfo[name][textBlockInfoIndex];
textBlockInfoIndex++;
}
}



+ 157
- 7
Pixi/blueprints.json
File diff suppressed because it is too large
View File


+ 1
- 1
Pixi/cubes-id.json
File diff suppressed because it is too large
View File