Refactor to do non-dependent initializations before construction.
This commit is contained in:
parent
6a51e203e0
commit
2311019f4e
|
@ -1,5 +1,6 @@
|
||||||
using Sandbox.ModAPI.Ingame;
|
using Sandbox.ModAPI.Ingame;
|
||||||
using SpaceEngineers.Game.ModAPI.Ingame;
|
using SpaceEngineers.Game.ModAPI.Ingame;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using VRageMath;
|
using VRageMath;
|
||||||
|
|
||||||
|
@ -9,16 +10,16 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
public class AirZone
|
public class AirZone
|
||||||
{
|
{
|
||||||
public bool Triggered { get; private set; } = false;
|
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
public List<IMyAirVent> Vents { get; private set; }
|
public bool Triggered { get; private set; } = false;
|
||||||
|
public List<IMyAirVent> Vents { get; } = new List<IMyAirVent>();
|
||||||
|
|
||||||
private IConsoleProgram _program;
|
private IConsoleProgram _program;
|
||||||
private List<IMyDoor> _doors;
|
private List<IMyDoor> _doors = new List<IMyDoor>();
|
||||||
private List<IMyTextSurface> _displays;
|
private List<IMyTextSurface> _displays = new List<IMyTextSurface>();
|
||||||
|
private List<IMyLightingBlock> _lights = new List<IMyLightingBlock>();
|
||||||
private PrefixedConsole _console;
|
private PrefixedConsole _console;
|
||||||
private Sequencer _sequencer;
|
private Sequencer _sequencer;
|
||||||
private List<IMyLightingBlock> _lights;
|
|
||||||
|
|
||||||
private const float TriggerLevel = 0.75F;
|
private const float TriggerLevel = 0.75F;
|
||||||
|
|
||||||
|
@ -28,10 +29,6 @@ namespace IngameScript
|
||||||
_program = program;
|
_program = program;
|
||||||
_console = new PrefixedConsole(program.Console, zoneName);
|
_console = new PrefixedConsole(program.Console, zoneName);
|
||||||
_sequencer = new Sequencer(zoneName, _console);
|
_sequencer = new Sequencer(zoneName, _console);
|
||||||
Vents = new List<IMyAirVent>();
|
|
||||||
_doors = new List<IMyDoor>();
|
|
||||||
_displays = new List<IMyTextSurface>();
|
|
||||||
_lights = new List<IMyLightingBlock>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddBlock(IMyTerminalBlock block)
|
public void AddBlock(IMyTerminalBlock block)
|
||||||
|
|
|
@ -10,28 +10,20 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
public partial class Program : MyGridProgram, IConsoleProgram
|
public partial class Program : MyGridProgram, IConsoleProgram
|
||||||
{
|
{
|
||||||
public MyIni Ini { get; private set; }
|
public MyIni Ini { get; } = new MyIni();
|
||||||
public IConsole Console { get; private set; }
|
public IConsole Console { get; private set; }
|
||||||
|
|
||||||
private MyCommandLine _cli;
|
private MyCommandLine _cli = new MyCommandLine();
|
||||||
private Dictionary<string, AirZone> _zones;
|
private Dictionary<string, AirZone> _zones = new Dictionary<string, AirZone>();
|
||||||
private List<IEnumerator<bool>> _jobs;
|
private List<IEnumerator<bool>> _jobs = new List<IEnumerator<bool>>();
|
||||||
private List<IMyTextSurface> _displays;
|
private List<IMyTextSurface> _displays = new List<IMyTextSurface>();
|
||||||
private StringBuilder _displayBuffer;
|
private StringBuilder _displayBuffer = new StringBuilder();
|
||||||
private List<IMyGasTank> _oxygenTanks;
|
private List<IMyGasTank> _oxygenTanks = new List<IMyGasTank>();
|
||||||
|
|
||||||
public Program()
|
public Program()
|
||||||
{
|
{
|
||||||
Ini = new MyIni();
|
|
||||||
Console = new MainConsole(this, "Air Pressure Monitor");
|
Console = new MainConsole(this, "Air Pressure Monitor");
|
||||||
|
|
||||||
_cli = new MyCommandLine();
|
|
||||||
_zones = new Dictionary<string, AirZone>();
|
|
||||||
_jobs = new List<IEnumerator<bool>>();
|
|
||||||
_displays = new List<IMyTextSurface>();
|
|
||||||
_displayBuffer = new StringBuilder();
|
|
||||||
_oxygenTanks = new List<IMyGasTank>();
|
|
||||||
|
|
||||||
// Find all tagged objects and build out zones
|
// Find all tagged objects and build out zones
|
||||||
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
|
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
|
||||||
GridTerminalSystem.GetBlocksOfType(blocks, block => MyIni.HasSection(block.CustomData, "airMonitor"));
|
GridTerminalSystem.GetBlocksOfType(blocks, block => MyIni.HasSection(block.CustomData, "airMonitor"));
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return ((_airVent.Depressurize && _airVent.GetOxygenLevel() <= targetOxygenLevel) ||
|
return ((_airVent.Depressurize && _airVent.GetOxygenLevel() <= _targetOxygenLevel) ||
|
||||||
(!_airVent.Depressurize && _airVent.Status == VentStatus.Pressurized));
|
(!_airVent.Depressurize && _airVent.Status == VentStatus.Pressurized));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,14 +74,14 @@ namespace IngameScript
|
||||||
private string _name;
|
private string _name;
|
||||||
private PrefixedConsole _console;
|
private PrefixedConsole _console;
|
||||||
private MyIni _ini;
|
private MyIni _ini;
|
||||||
private float targetOxygenLevel = 0.0F;
|
|
||||||
|
|
||||||
|
private List<IMyLightingBlock> _lights = new List<IMyLightingBlock>();
|
||||||
private IMyDoor _innerDoor;
|
private IMyDoor _innerDoor;
|
||||||
private IMyDoor _outerDoor;
|
private IMyDoor _outerDoor;
|
||||||
private List<IMyLightingBlock> _lights;
|
|
||||||
private IMyGasTank _oxygenTank;
|
private IMyGasTank _oxygenTank;
|
||||||
private IMyAirVent _airVent;
|
private IMyAirVent _airVent;
|
||||||
// private List<IMyTextSurface> _displays;
|
|
||||||
|
private float _targetOxygenLevel = 0.0F;
|
||||||
|
|
||||||
private const int CooldownTicks = 120;
|
private const int CooldownTicks = 120;
|
||||||
private const int SealTimeoutTicks = 30;
|
private const int SealTimeoutTicks = 30;
|
||||||
|
@ -91,8 +91,6 @@ namespace IngameScript
|
||||||
_ini = _program.Ini;
|
_ini = _program.Ini;
|
||||||
_name = name;
|
_name = name;
|
||||||
_console = new PrefixedConsole(_program.Console, _name);
|
_console = new PrefixedConsole(_program.Console, _name);
|
||||||
_lights = new List<IMyLightingBlock>();
|
|
||||||
// _displays = new List<IMyTextSurface>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddBlock(IMyTerminalBlock block)
|
public void AddBlock(IMyTerminalBlock block)
|
||||||
|
@ -101,7 +99,6 @@ namespace IngameScript
|
||||||
else if (block is IMyLightingBlock) _lights.Add(block as IMyLightingBlock);
|
else if (block is IMyLightingBlock) _lights.Add(block as IMyLightingBlock);
|
||||||
else if (block is IMyAirVent) addVent(block as IMyAirVent);
|
else if (block is IMyAirVent) addVent(block as IMyAirVent);
|
||||||
else if (block is IMyGasTank) addOxygenTank(block as IMyGasTank);
|
else if (block is IMyGasTank) addOxygenTank(block as IMyGasTank);
|
||||||
// else if (block is IMyTextSurfaceProvider) _displays.Add(((IMyTextSurfaceProvider)block).GetSurface(0));
|
|
||||||
else _console.Print($"Tried to add invalid block '{block.CustomName}'");
|
else _console.Print($"Tried to add invalid block '{block.CustomName}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,8 +213,8 @@ namespace IngameScript
|
||||||
// TODO: test this for floating point errors
|
// TODO: test this for floating point errors
|
||||||
if (_airVent.Depressurize && ReferenceVent != null)
|
if (_airVent.Depressurize && ReferenceVent != null)
|
||||||
{
|
{
|
||||||
targetOxygenLevel = ReferenceVent.GetOxygenLevel();
|
_targetOxygenLevel = ReferenceVent.GetOxygenLevel();
|
||||||
_console.Print($"Set depressurization target to {targetOxygenLevel}");
|
_console.Print($"Set depressurization target to {_targetOxygenLevel}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,20 +7,16 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
public partial class Program : MyGridProgram, IConsoleProgram
|
public partial class Program : MyGridProgram, IConsoleProgram
|
||||||
{
|
{
|
||||||
|
public MyIni Ini { get; } = new MyIni();
|
||||||
public IConsole Console { get; private set; }
|
public IConsole Console { get; private set; }
|
||||||
public MyIni Ini { get; private set; }
|
|
||||||
|
|
||||||
private Dictionary<string, Airlock> _airlocks;
|
private Dictionary<string, Airlock> _airlocks = new Dictionary<string, Airlock>();
|
||||||
private List<IEnumerator<bool>> _jobs;
|
private List<IEnumerator<bool>> _jobs = new List<IEnumerator<bool>>();
|
||||||
private MyCommandLine _cli;
|
private MyCommandLine _cli = new MyCommandLine();
|
||||||
|
|
||||||
public Program()
|
public Program()
|
||||||
{
|
{
|
||||||
Ini = new MyIni();
|
|
||||||
Console = new MainConsole(this, "Airlock Controller");
|
Console = new MainConsole(this, "Airlock Controller");
|
||||||
_cli = new MyCommandLine();
|
|
||||||
_jobs = new List<IEnumerator<bool>>();
|
|
||||||
_airlocks = new Dictionary<string, Airlock>();
|
|
||||||
|
|
||||||
List<IMyTerminalBlock> airlockBlocks = new List<IMyTerminalBlock>();
|
List<IMyTerminalBlock> airlockBlocks = new List<IMyTerminalBlock>();
|
||||||
GridTerminalSystem.GetBlocksOfType(airlockBlocks, block => MyIni.HasSection(block.CustomData, "airlock"));
|
GridTerminalSystem.GetBlocksOfType(airlockBlocks, block => MyIni.HasSection(block.CustomData, "airlock"));
|
||||||
|
|
|
@ -7,19 +7,16 @@ namespace IngameScript
|
||||||
{
|
{
|
||||||
public partial class Program : MyGridProgram, IConsoleProgram
|
public partial class Program : MyGridProgram, IConsoleProgram
|
||||||
{
|
{
|
||||||
private MyCommandLine _cli;
|
public MyIni Ini { get; } = new MyIni();
|
||||||
public MyIni Ini { get; private set; }
|
|
||||||
public IConsole Console { get; private set; }
|
public IConsole Console { get; private set; }
|
||||||
private List<IEnumerator<bool>> _jobs;
|
|
||||||
private Dictionary<string, Sequencer> _doors;
|
private MyCommandLine _cli = new MyCommandLine();
|
||||||
|
private List<IEnumerator<bool>> _jobs = new List<IEnumerator<bool>>();
|
||||||
|
private Dictionary<string, Sequencer> _doors = new Dictionary<string, Sequencer>();
|
||||||
|
|
||||||
public Program()
|
public Program()
|
||||||
{
|
{
|
||||||
_cli = new MyCommandLine();
|
|
||||||
Ini = new MyIni();
|
|
||||||
Console = new MainConsole(this, "Door Controller");
|
Console = new MainConsole(this, "Door Controller");
|
||||||
_jobs = new List<IEnumerator<bool>>();
|
|
||||||
_doors = new Dictionary<string, Sequencer>();
|
|
||||||
|
|
||||||
List<IMyTerminalBlock> doorBlocks = new List<IMyTerminalBlock>();
|
List<IMyTerminalBlock> doorBlocks = new List<IMyTerminalBlock>();
|
||||||
GridTerminalSystem.GetBlocksOfType(doorBlocks, block => MyIni.HasSection(block.CustomData, "mechDoor"));
|
GridTerminalSystem.GetBlocksOfType(doorBlocks, block => MyIni.HasSection(block.CustomData, "mechDoor"));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user