public Program() { Reroute console = new Reroute(this); try { console.Compile("Good Class"); GoodClass gc = new GoodClass(this); console.Compile("Bad Class"); BadClass bc = new BadClass(this); console.Report(); } catch (Exception e) { console.Cancel(e.Message); } }
public Worker(Program parent, string cockpit = "", string container = "", float yaw_speed = 0.5f) { Reroute console = new Reroute((gParent = parent)); try { console.Compile("Battery"); gBattery = new Battery(gParent); console.Compile("Payload"); gPayload = new Payload(gParent, container); console.Compile("Stabilizer"); gStabilizer = new Stabilizer(gParent, yaw_speed); console.Compile("Worker"); // Get a cockpit: if (cockpit == string.Empty) { List <IMyCockpit> cockpitblocks = new List <IMyCockpit>(); gParent.GridTerminalSystem.GetBlocksOfType(cockpitblocks, x => x.IsSameConstructAs(gParent.Me)); if (cockpitblocks.Count == 0) { throw new Exception("No cockpit found."); } else { gCockpit = cockpitblocks[0]; } } else { gCockpit = gParent.GridTerminalSystem.GetBlockWithName(cockpit) as IMyCockpit; } if (gCockpit == null || !gCockpit.IsSameConstructAs(gParent.Me)) { throw new Exception($"No cockpit found with argument: '{cockpit}'"); } // Set up text surfaces: lSurface = null; switch (gCockpit.BlockDefinition.SubtypeName) { case "SmallBlockCockpit": case "LargeBlockCockpitSeat": lSurface = new List <IMyTextSurface> { gCockpit.GetSurface(0), gCockpit.GetSurface(1), gCockpit.GetSurface(2) }; break; case "SmallBlockCockpitIndustrial": lSurface = new List <IMyTextSurface> { gCockpit.GetSurface(1), gCockpit.GetSurface(0), gCockpit.GetSurface(2) }; break; case "LargeBlockCockpitIndustrial": lSurface = new List <IMyTextSurface> { gCockpit.GetSurface(2), gCockpit.GetSurface(1), gCockpit.GetSurface(3) }; break; default: throw new Exception($"Cockpit '{gCockpit.CustomName}' is not a suitable cockpit."); } gParent.Echo($"Using cockpit: '{gCockpit.CustomName}'"); foreach (IMyTextSurface s in lSurface) { s.Font = "Debug"; s.FontSize = 3.0f; s.TextPadding = 20.0f; s.ContentType = ContentType.TEXT_AND_IMAGE; s.Alignment = TextAlignment.CENTER; } if (gCockpit.BlockDefinition.SubtypeName == "SmallBlockCockpit") { lSurface[0].FontSize = 4.0f; } // Done: SetCargoScreen(); SetStabilizerScreen(false); SetBatteryScreen(); console.Report(); gParent.Runtime.UpdateFrequency = UpdateFrequency.Update100; } catch (Exception e) { console.Cancel(e.Message); } }