Add console system to print debug output to the PB screen.

This commit is contained in:
2025-02-08 14:48:59 -05:00
parent 4a288ed859
commit c75159f706
9 changed files with 205 additions and 16 deletions

View File

@ -55,7 +55,7 @@ namespace IngameScript
{
if (innerDoor.Status == DoorStatus.Closed || outerDoor.Status == DoorStatus.Open || OxygenBalanced) { return false; }
_p.Echo("DEBUG: Balancing Oxygen Tank");
_console.Print($"{_name}: Balancing Oxygen Tank");
// Configure the vent to suck in Oxygen.
airVent.Depressurize = true;
@ -64,6 +64,7 @@ namespace IngameScript
}
private string _name;
private PrefixedConsole _console;
private MyGridProgram _p;
private float targetOxygenLevel = 0.0F;
@ -75,10 +76,11 @@ namespace IngameScript
private IMyAirVent airSensor;
private const int CooldownTicks = 120;
public Airlock(MyGridProgram p, string name)
public Airlock(MyGridProgram program, Console console, string name)
{
_p = p;
_p = program;
_name = name;
_console = console.CreatePrefixedConsole(_name);
// Find the appropriate blocks given the airlock name
initDoors();
@ -204,17 +206,19 @@ namespace IngameScript
// Cooldown period
int cooldown = 0;
while(cooldown < CooldownTicks) {
while (cooldown < CooldownTicks)
{
cooldown++;
yield return true;
}
setLights(AirlockLightState.Off);
_console.Print("Cycling Complete.");
}
private void closeDoors()
{
_p.Echo("DEBUG: Closing Doors");
_console.Print("Closing Doors");
// close the doors
innerDoor.Enabled = true;
@ -225,7 +229,7 @@ namespace IngameScript
private void pressurizeDepressurize()
{
_p.Echo("DEBUG: Cycling");
_console.Print("Cycling");
// toggle the current state
airVent.Depressurize = !airVent.Depressurize;
@ -236,14 +240,14 @@ namespace IngameScript
if (airVent.Depressurize && airSensor != null)
{
targetOxygenLevel = airSensor.GetOxygenLevel();
_p.Echo($"Set depressurization target to {targetOxygenLevel}");
_console.Print($"Set depressurization target to {targetOxygenLevel}");
}
}
// Open the appropriate door based on pressure state.
private void openDoor()
{
_p.Echo("DEBUG: Opening Door");
_console.Print($"Opening Door");
if (airVent.Status == VentStatus.Pressurized)
{
@ -298,7 +302,7 @@ namespace IngameScript
private void error(string error)
{
_p.Echo(error);
_console.Print(error);
setLights(AirlockLightState.Error);
}
}

View File

@ -23,4 +23,6 @@
<AdditionalFiles Include="Instructions.readme" />
<AdditionalFiles Include="thumb.png" />
</ItemGroup>
<Import Project="..\Mixins\Console\Console.projitems" Label="shared" />
<Import Project="..\Mixins\ConfigParser\ConfigParser.projitems" Label="shared" />
</Project>

View File

@ -11,9 +11,11 @@ namespace IngameScript
private int _tickCount = 0;
private MyCommandLine _cli;
private Console _console;
public Program()
{
_console = new Console(this);
_cli = new MyCommandLine();
_jobs = new List<IEnumerator<bool>>();
_airlocks = new Dictionary<string, Airlock>();
@ -25,32 +27,32 @@ namespace IngameScript
if (!door.CustomName.StartsWith("Airlock")) continue;
string airlockName = door.CustomName.Split(' ')[0];
if (_airlocks.ContainsKey(airlockName)) continue;
Airlock newAirlock = new Airlock(this, airlockName);
Airlock newAirlock = new Airlock(this, _console, airlockName);
if (!newAirlock.Functional)
{
Echo($"{airlockName} is missing one or more required blocks.");
_console.Print($"{airlockName} is missing one or more required blocks.");
continue;
}
_airlocks[airlockName] = newAirlock;
}
Echo($"Found {_airlocks.Count} airlocks.");
_console.Print($"Found {_airlocks.Count} airlocks.");
}
public void Main(string argument, UpdateType updateSource)
{
Echo($"index: {_tickCount++}");
_console.PrintLower($"Total Ticks: {_tickCount++}");
if (updateSource == UpdateType.Trigger || updateSource == UpdateType.Terminal)
{
_cli.TryParse(argument);
if (_cli.ArgumentCount == 0) { Echo("You must provide an airlock ID."); }
if (_cli.ArgumentCount == 0) { _console.Print("You must provide an airlock ID."); }
else
{
string airlockName = $"Airlock{_cli.Argument(0)}";
if (!_airlocks.ContainsKey(airlockName))
{
Echo($"Invalid airlock ID {_cli.Argument(0)}");
_console.Print($"Invalid airlock ID {_cli.Argument(0)}");
}
else
{
@ -68,7 +70,7 @@ namespace IngameScript
job.Dispose();
_jobs.Remove(job);
i--;
Echo("Airlock Cycling Complete.");
_console.Print("Job Removed From Queue.");
}
}