From 3c9c60b679dd50e6ed3c65c0ff1446c5d162d48a Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 27 Sep 2020 20:29:02 -0400 Subject: [PATCH] Add text block support to RC importer & general tweaks to make that work --- Pixi/Common/BlockJsonInfo.cs | 2 +- Pixi/Common/CommandRoot.cs | 55 +++++++++++++++++++++++++++- Pixi/PixiPlugin.cs | 1 + Pixi/Robots/RobotInternetImporter.cs | 14 ++++++- Pixi/TestImporter.cs | 52 ++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 Pixi/TestImporter.cs diff --git a/Pixi/Common/BlockJsonInfo.cs b/Pixi/Common/BlockJsonInfo.cs index 0193254..a4bd92a 100644 --- a/Pixi/Common/BlockJsonInfo.cs +++ b/Pixi/Common/BlockJsonInfo.cs @@ -20,7 +20,7 @@ namespace Pixi.Common internal ProcessedVoxelObjectNotation Process() { - BlockIDs block = ConversionUtility.BlockIDsToEnum(name); + BlockIDs block = ConversionUtility.BlockIDsToEnum(name.Split('\t')[0]); return new ProcessedVoxelObjectNotation { block = block, diff --git a/Pixi/Common/CommandRoot.cs b/Pixi/Common/CommandRoot.cs index df73fad..f0b3c14 100644 --- a/Pixi/Common/CommandRoot.cs +++ b/Pixi/Common/CommandRoot.cs @@ -52,7 +52,7 @@ namespace Pixi.Common public static int OPTIMISATION_PASSES = 2; - public static int GROUP_SIZE = 64; + public static int GROUP_SIZE = 32; // optimisation algorithm constants private static float3[] cornerMultiplicands1 = new float3[8] @@ -217,7 +217,16 @@ namespace Pixi.Common desc.color.Darkness, 1, desc.scale); blocks[i] = b; } +#if DEBUG + else + { + Logging.LogWarning($"Found invalid block at index {i}\n\t{optVONsArr[i].ToString()}"); + } +#endif } + // handle special block parameters + PostProcessSpecialBlocks(ref optVONsArr, ref blocks); + // post processing magicImporter.PostProcess(name, ref blocks); if (magicImporter.Optimisable && blockCountPreOptimisation > blocks.Length) { @@ -516,6 +525,50 @@ namespace Pixi.Common return result; } + private static void PostProcessSpecialBlocks(ref ProcessedVoxelObjectNotation[] pVONs, ref Block[] blocks) + { + // populate block attributes using metadata field from ProcessedVoxelObjectNotation + for (int i = 0; i < pVONs.Length; i++) + { + switch (pVONs[i].block) + { + case BlockIDs.TextBlock: + string[] textSplit = pVONs[i].metadata.Split('\t'); + if (textSplit.Length > 1) + { + TextBlock tb = blocks[i].Specialise(); + tb.Text = textSplit[1]; + if (textSplit.Length > 2) + { + tb.TextBlockId = textSplit[2]; + } + } + break; + case BlockIDs.ConsoleBlock: + string[] cmdSplit = pVONs[i].metadata.Split('\t'); + if (cmdSplit.Length > 1) + { + ConsoleBlock cb = blocks[i].Specialise(); + cb.Command = cmdSplit[1]; + if (cmdSplit.Length > 2) + { + cb.Arg1 = cmdSplit[2]; + if (cmdSplit.Length > 3) + { + cb.Arg1 = cmdSplit[3]; + if (cmdSplit.Length > 4) + { + cb.Arg1 = cmdSplit[4]; + } + } + } + } + break; + default: break; // do nothing + } + } + } + private static string float3ArrToString(float3[] arr) { string result = "["; diff --git a/Pixi/PixiPlugin.cs b/Pixi/PixiPlugin.cs index bf44e1b..78e73d4 100644 --- a/Pixi/PixiPlugin.cs +++ b/Pixi/PixiPlugin.cs @@ -53,6 +53,7 @@ namespace Pixi #if DEBUG // Development functionality RobotCommands.CreatePartDumpCommand(); + root.Inject(new TestImporter()); #endif // Audio functionality root.Inject(new MidiImporter()); diff --git a/Pixi/Robots/RobotInternetImporter.cs b/Pixi/Robots/RobotInternetImporter.cs index a79e6ae..8e0151d 100644 --- a/Pixi/Robots/RobotInternetImporter.cs +++ b/Pixi/Robots/RobotInternetImporter.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Security.Cryptography; using System.Text; - +using System.Text.RegularExpressions; using Svelto.DataStructures; using Unity.Mathematics; using UnityEngine; @@ -125,6 +125,18 @@ namespace Pixi.Robots { blocks[i].position += pos; } + // set textblock colors (replace with in textblocks) + Regex pattern = new Regex("", 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 + blocks[i].metadata = pattern.Replace( + blocks[i].metadata, + $""); + } + } } public void PostProcess(string name, ref Block[] blocks) diff --git a/Pixi/TestImporter.cs b/Pixi/TestImporter.cs new file mode 100644 index 0000000..7245846 --- /dev/null +++ b/Pixi/TestImporter.cs @@ -0,0 +1,52 @@ +using System; +using GamecraftModdingAPI; +using GamecraftModdingAPI.Blocks; +using GamecraftModdingAPI.Players; +using Pixi.Common; +using Unity.Mathematics; + +namespace Pixi +{ + public class TestImporter : Importer + { + public int Priority { get; } = 0; + public bool Optimisable { get; } = false; + public string Name { get; } = "Test~Spell"; + public BlueprintProvider BlueprintProvider { get; } = null; + public bool Qualifies(string name) + { + return name.Equals("test", StringComparison.InvariantCultureIgnoreCase); + } + + public BlockJsonInfo[] Import(string name) + { + return new[] + { + new BlockJsonInfo + { + name = BlockIDs.TextBlock.ToString() + + "\ttext that is preserved through the whole import process and ends up in the text block\ttextblockIDs_sux", + position = new[] {0f, 0f, 0f}, + rotation = new[] {0f, 0f, 0f}, + color = new[] {0f, 0f, 0f}, + scale = new[] {1f, 1f, 1f}, + } + }; + } + + public void PreProcess(string name, ref ProcessedVoxelObjectNotation[] blocks) + { + Player p = new Player(PlayerType.Local); + float3 pos = p.Position; + for (int i = 0; i < blocks.Length; i++) + { + blocks[i].position += pos; + } + } + + public void PostProcess(string name, ref Block[] blocks) + { + // meh + } + } +} \ No newline at end of file