diff --git a/Airlock/Airlock.cs b/Airlock/Airlock.cs index 4c210ec..cc3ac27 100644 --- a/Airlock/Airlock.cs +++ b/Airlock/Airlock.cs @@ -11,6 +11,7 @@ using Sandbox.ModAPI.Ingame; using SpaceEngineers.Game.ModAPI.Ingame; using System.Collections.Generic; +using VRage.Game.ModAPI.Ingame.Utilities; using VRageMath; namespace IngameScript @@ -83,7 +84,7 @@ namespace IngameScript private string _name; private PrefixedConsole _console; - private MyGridProgram _p; + private MyIni _ini; private float targetOxygenLevel = 0.0F; private IMyDoor _innerDoor; @@ -97,9 +98,9 @@ namespace IngameScript private const int CooldownTicks = 120; private const int SealTimeoutTicks = 30; - public Airlock(MyGridProgram program, Console console, string name) + public Airlock(MyIni ini, Console console, string name) { - _p = program; + _ini = ini; _name = name; _console = console.CreatePrefixedConsole(_name); _lights = new List(); @@ -116,14 +117,15 @@ namespace IngameScript else _console.Print($"Tried to add invalid block '{block.CustomName}'"); } + // Precondition: _ini.TryParse() should be called on the block before calling this function. private void addDoor(IMyDoor door) { - if (door.CustomName.Contains("Inner") && _innerDoor == null) + if (_ini.Get("airlock", "doorPosition").ToString() == "inner" && _innerDoor == null) { _innerDoor = door; return; } - if (door.CustomName.Contains("Outer") && _outerDoor == null) + if (_ini.Get("airlock", "doorPosition").ToString() == "outer" && _outerDoor == null) { _outerDoor = door; return; @@ -131,14 +133,15 @@ namespace IngameScript _console.Print($"Couldn't add door '{door.CustomName}'"); } + // Precondition: _ini.TryParse() should be called on the block before calling this function. private void addVent(IMyAirVent vent) { - if (vent.CustomName.Contains("Main") && _airVent == null) + if (_ini.Get("airlock", "ventRole").ToString() == "cycling" && _airVent == null) { _airVent = vent; return; } - if (vent.CustomName.Contains("Reference") && _airSensor == null) + if (_ini.Get("airlock", "ventRole").ToString() == "reference" && _airSensor == null) { _airSensor = vent; return; diff --git a/Airlock/Program.cs b/Airlock/Program.cs index ccd4fab..2ad01d4 100644 --- a/Airlock/Program.cs +++ b/Airlock/Program.cs @@ -23,19 +23,19 @@ namespace IngameScript _airlocks = new Dictionary(); List airlockBlocks = new List(); - GridTerminalSystem.GetBlocksOfType(airlockBlocks, block => block.CustomName.Contains("!Airlock")); + GridTerminalSystem.GetBlocksOfType(airlockBlocks, block => _ini.ContainsSection("airlock")); foreach (IMyTerminalBlock block in airlockBlocks) { + _ini.TryParse(block.CustomData, "airlock"); + string airlockName = _ini.Get("airlock", "id").ToString(); + if (!_airlocks.ContainsKey(airlockName)) { - string airlockName = Utils.ExtractTag(block, "!Airlock"); - if (!_airlocks.ContainsKey(airlockName)) - { - _airlocks[airlockName] = new Airlock(this, _console, airlockName); - } - - _airlocks[airlockName].AddBlock(block); + _airlocks[airlockName] = new Airlock(_ini, _console, airlockName); } + _airlocks[airlockName].AddBlock(block); + + // TODO: it would be most convenient to just delete non-functional Airlocks... but maybe they're worth // keeping around for warnings. } @@ -53,8 +53,8 @@ namespace IngameScript if (_cli.ArgumentCount == 0) { _console.Print("You must provide an airlock ID."); } else { - string airlockName = $"!Airlock{_cli.Argument(0)}"; - if (!_airlocks.ContainsKey(airlockName)) _console.Print($"Invalid airlock ID {_cli.Argument(0)}"); + string airlockName = _cli.Argument(0); + if (!_airlocks.ContainsKey(airlockName)) _console.Print($"Airlock ID '{airlockName}' not found."); else if (!_airlocks[airlockName].Functional) _console.Print($"Airlock '{airlockName}' is not functional."); else {