public Dictionary <string, int> GetRequiredComponents() { IMyTextPanel panel = GridTerminalSystem.GetBlockWithName("TXTPNL") as IMyTextPanel; var blocks = Projector.RemainingBlocksPerType; char[] delimiters = new char[] { ',' }; char[] remove = new char[] { '[', ']' }; Dictionary <string, int> totalComponents = new Dictionary <string, int>(); foreach (var item in blocks) { string[] blockInfo = item.ToString().Trim(remove).Split(delimiters, StringSplitOptions.None); try { string blockName = blockInfo[0]; int amount = Convert.ToInt32(blockInfo[1]); BlueprintDefinitions.AddComponents(totalComponents, BlueprintDefinitions.GetBlockComponents(blockName), amount); } catch (Exception ex) { GridProgram.Echo($"Error in GetRequiredComponent() at {blockInfo[0]}:{blockInfo[1]} => {ex.Message}"); } // blockInfo[0] is blueprint, blockInfo[1] is number of required item } string output = ""; foreach (KeyValuePair <string, int> component in totalComponents) { output += component.Key.Replace("MyObjectBuilder_BlueprintDefinition/", "") + " " + component.Value.ToString() + "\n"; } panel.WriteText(output); return(totalComponents); }
public void Main(string arguments, UpdateType updateSource) { if (arguments == "i") { GridProgram = new GridProgramRef(GridTerminalSystem, null, Echo, Me); GridProgram.Utils = new UtilsClass(GridProgram); BlueprintDefinitions.Initialize(GridProgram); Echo("Initialized blueprint definitions."); Echo($"{BlueprintDefinitions.blueprints.Count} definitions loaded."); projectionController = new ProjectionController(GridProgram, "Projector", ProjectorState.Unpowered); projectionController.SetProjectorState(ProjectorState.Powered); if (!projectionController.Projector.IsProjecting) { Echo("Projector wasn't projecting."); return; } Dictionary <string, int> components = projectionController.GetRequiredComponents(); foreach (KeyValuePair <string, int> kvp in components) { Echo($"{kvp.Key}: {kvp.Value}"); } } if (arguments == "a") { List <IMyAssembler> assemblers = new List <IMyAssembler>(); GridTerminalSystem.GetBlocksOfType(assemblers); IMyAssembler assembler = assemblers[0]; IMyTextPanel textpanel = GridTerminalSystem.GetBlockWithName("TXTPNL") as IMyTextPanel; MyDefinitionId id = MyDefinitionId.Parse("MyObjectBuilder_BlueprintDefinition/BulletproofGlass"); assembler.AddQueueItem(id, 1.0); return; } if (arguments == "p") { IMyTextPanel textpanel = GridTerminalSystem.GetBlockWithName("TXTPNL") as IMyTextPanel; textpanel.WriteText(projectionController.Projector.DetailedInfo); return; } if (arguments == "m") { return; } switch (internal_state) { case 0: // config try { GridProgram = new GridProgramRef(GridTerminalSystem, null, Echo, Me); GridProgram.Utils = new UtilsClass(GridProgram); platformMotor = new PlatformMotor(GridProgram, "Pistons", new MotorConfig(0.05f, 10f, 0.05f, MotorExtendType.POSITIVE)); platformTracker = new PlatformTracker(new TrackerConfig(GridProgram, "Camera X1", "Camera X2", "Camera Y1", "Camera Y2", 370), GridProgram); welderController = new WelderController(GridProgram, new WelderConfig("Welders", WelderState.Unpowered)); cargoController = new CargoController(GridProgram, true); projectionController = new ProjectionController(GridProgram, "Projector", ProjectorState.Unpowered); platformTracker.EnableRaycast(); internal_state = 1; } catch (Exception ex) { Echo($"Execution halted, safeguard violation raised in {ex.TargetSite}: {ex.Message}"); } break; case 1: try { platformMotor.SetMotorState(MotorState.Extend); internal_state = 2; } catch (Exception ex) { Echo($"Execution halted, safeguard violation raised in {ex.TargetSite}: {ex.Message}"); } break; case 2: try { TrackedPlatform tp = platformTracker.Track(); platformTracker.IsPlatformSafe(tp); } catch (Exception ex) { Echo($"Execution halted, safeguard violation raised in {ex.TargetSite}: {ex.Message}"); } break; } }