Add text block support to RC importer & general tweaks to make that work
This commit is contained in:
parent
84fc330b12
commit
3c9c60b679
5 changed files with 121 additions and 3 deletions
|
@ -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,
|
||||
|
|
|
@ -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<TextBlock>();
|
||||
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<ConsoleBlock>();
|
||||
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 = "[";
|
||||
|
|
|
@ -53,6 +53,7 @@ namespace Pixi
|
|||
#if DEBUG
|
||||
// Development functionality
|
||||
RobotCommands.CreatePartDumpCommand();
|
||||
root.Inject(new TestImporter());
|
||||
#endif
|
||||
// Audio functionality
|
||||
root.Inject(new MidiImporter());
|
||||
|
|
|
@ -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 <color="white"> with <color=#HEX> in textblocks)
|
||||
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
|
||||
blocks[i].metadata = pattern.Replace(
|
||||
blocks[i].metadata,
|
||||
$"<color=#{ColorUtility.ToHtmlStringRGBA(ColorSpaceUtility.UnquantizeToColor(blocks[i].color))}>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PostProcess(string name, ref Block[] blocks)
|
||||
|
|
52
Pixi/TestImporter.cs
Normal file
52
Pixi/TestImporter.cs
Normal file
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue