From 8596726a1aa8f458b69e431e68737535bb9efeed Mon Sep 17 00:00:00 2001 From: Keepoccino Date: Fri, 30 Apr 2021 17:40:48 +0200 Subject: [PATCH] Added mapping between item and blueprint names --- IngameScript/Program.cs | 59 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/IngameScript/Program.cs b/IngameScript/Program.cs index 217b7e8..6bcf71d 100644 --- a/IngameScript/Program.cs +++ b/IngameScript/Program.cs @@ -24,6 +24,21 @@ namespace IngameScript partial class Program : MyGridProgram { + Dictionary componentItemBlueprintMap = new Dictionary + { + { "Construction", "ConstructionComponent"}, + { "Computer", "ComputerComponent"}, + { "Detector", "DetectorComponent"}, + { "Explosive", "ExplosiveComponent"}, + { "Girder", "GirderComponent"}, + { "GravityGenerator", "GravityGeneratorComponent"}, + { "Medical", "MedicalComponent"}, + { "Motor", "MotorComponent"}, + { "Reactor", "ReactorComponent"}, + { "RadioCommunication", "RadioCommunicationComponent"}, + { "Thrust", "ThrustComponent"}, + }; + IMyAssembler Assembler; List Containers; List TextPanels; @@ -51,6 +66,38 @@ partial class Program : MyGridProgram // // to learn more about ingame scripts. + private void debugInfoInventory() + { + var outText = ""; + foreach (IMyEntity container in Containers) + { + var items = new List(); + container.GetInventory().GetItems(items); + foreach (var item in items) + { + outText += item.ToString() + "\r\n"; + } + } + foreach (IMyTextPanel textPanel in TextPanels) + { + textPanel.WriteText(outText); + } + } + private void debugInfoQueue() + { + var outText = ""; + var items = new List(); + Assembler.GetQueue(items); + foreach (var item in items) + { + outText += item.BlueprintId.ToString() + "\r\n"; + } + foreach (IMyTextPanel textPanel in TextPanels) + { + textPanel.WriteText(outText); + } + } + public Program() { // The constructor, called only once every session and @@ -117,6 +164,9 @@ public void Main(string argument, UpdateType updateSource) // The method itself is required, but the arguments above // can be removed if not needed. + //debugInfoQueue(); + //return; + List assemblerQueue = new List(); Assembler.GetQueue(assemblerQueue); @@ -158,7 +208,11 @@ public void Main(string argument, UpdateType updateSource) if (count < lowerBound) { - AddToAssemblerQueueIfNotPresent(assemblerQueue, itemName, upperBound - count); + string blueprintName; + if (!componentItemBlueprintMap.TryGetValue(itemName, out blueprintName)) + blueprintName = itemName; + + AddToAssemblerQueueIfNotPresent(assemblerQueue, blueprintName, upperBound - count); } textPanelText += itemName + " " + count.ToString() + "\n"; @@ -166,7 +220,8 @@ public void Main(string argument, UpdateType updateSource) } catch (Exception e) { - + Echo("An error occurred during script execution."); + Echo($"Exception: {e}\n---"); } }