public static ProcessedVoxelObjectNotation[][] ProcessAndExpandBlocks(string name, BlockJsonInfo[] blocks, BlueprintProvider blueprints) { List <ProcessedVoxelObjectNotation[]> expandedBlocks = new List <ProcessedVoxelObjectNotation[]>(); for (int i = 0; i < blocks.Length; i++) { ProcessedVoxelObjectNotation root = blocks[i].Process(); if (root.blueprint) { if (blueprints == null) { throw new NullReferenceException("Blueprint block info found but BlueprintProvider is null"); } BlockJsonInfo[] blueprint = blueprints.Blueprint(name, blocks[i]); ProcessedVoxelObjectNotation[] expanded = new ProcessedVoxelObjectNotation[blueprint.Length]; for (int j = 0; j < expanded.Length; j++) { expanded[j] = blueprint[j].Process(); } expandedBlocks.Add(expanded); } else { expandedBlocks.Add(new ProcessedVoxelObjectNotation[] { root }); } } return(expandedBlocks.ToArray()); }
private void Pixi(string importerName, string name) { // organise priorities int[] priorities = importers.Keys.ToArray(); Array.Sort(priorities); Array.Reverse(priorities); // higher priorities go first // find relevant importer Importer magicImporter = null; foreach (int p in priorities) { Importer[] imps = importers[p]; for (int i = 0; i < imps.Length; i++) { //Logging.MetaLog($"Now checking importer {imps[i].Name}"); if ((importerName == null && imps[i].Qualifies(name)) || (importerName != null && imps[i].Name.Contains(importerName))) { magicImporter = imps[i]; break; } } if (magicImporter != null) { break; } } if (magicImporter == null) { Logging.CommandLogError("Unsupported file or string."); return; } #if DEBUG Logging.MetaLog($"Using '{magicImporter.Name}' to import '{name}'"); #endif // import blocks BlockJsonInfo[] blocksInfo = magicImporter.Import(name); if (blocksInfo == null || blocksInfo.Length == 0) { #if DEBUG Logging.CommandLogError($"Importer {magicImporter.Name} didn't provide any blocks to import. Mission Aborted!"); #endif return; } ProcessedVoxelObjectNotation[][] procVONs; BlueprintProvider blueprintProvider = magicImporter.BlueprintProvider; if (blueprintProvider == null) { // convert block info to API-compatible format procVONs = new ProcessedVoxelObjectNotation[][] { BlueprintUtility.ProcessBlocks(blocksInfo) }; } else { // expand blueprints and convert block info procVONs = BlueprintUtility.ProcessAndExpandBlocks(name, blocksInfo, magicImporter.BlueprintProvider); } // reduce block placements by grouping neighbouring similar blocks // (after flattening block data representation) List <ProcessedVoxelObjectNotation> optVONs = new List <ProcessedVoxelObjectNotation>(); for (int arr = 0; arr < procVONs.Length; arr++) { for (int elem = 0; elem < procVONs[arr].Length; elem++) { optVONs.Add(procVONs[arr][elem]); } } #if DEBUG Logging.MetaLog($"Imported {optVONs.Count} blocks for '{name}'"); #endif int blockCountPreOptimisation = optVONs.Count; if (magicImporter.Optimisable) { for (int pass = 0; pass < OPTIMISATION_PASSES; pass++) { OptimiseBlocks(ref optVONs, (pass + 1) * GROUP_SIZE); #if DEBUG Logging.MetaLog($"Optimisation pass {pass} completed"); #endif } #if DEBUG Logging.MetaLog($"Optimised down to {optVONs.Count} blocks for '{name}'"); #endif } ProcessedVoxelObjectNotation[] optVONsArr = optVONs.ToArray(); magicImporter.PreProcess(name, ref optVONsArr); // place blocks Block[] blocks = new Block[optVONsArr.Length]; for (int i = 0; i < optVONsArr.Length; i++) { ProcessedVoxelObjectNotation desc = optVONsArr[i]; if (desc.block != BlockIDs.Invalid) { Block b = Block.PlaceNew(desc.block, desc.position, desc.rotation, desc.color.Color, 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) { Logging.CommandLog($"Imported {blocks.Length} blocks using {magicImporter.Name} ({blockCountPreOptimisation/blocks.Length}x ratio)"); } else { Logging.CommandLog($"Imported {blocks.Length} blocks using {magicImporter.Name}"); } }
public RobotInternetImporter() { BlueprintProvider = new RobotBlueprintProvider(this); }