Configure Airlock entirely from CustomData.

This commit is contained in:
Anna Rose 2025-02-10 16:16:36 -05:00
parent 606442d3a0
commit 8c55176aed
2 changed files with 20 additions and 17 deletions

View File

@ -11,6 +11,7 @@
using Sandbox.ModAPI.Ingame; using Sandbox.ModAPI.Ingame;
using SpaceEngineers.Game.ModAPI.Ingame; using SpaceEngineers.Game.ModAPI.Ingame;
using System.Collections.Generic; using System.Collections.Generic;
using VRage.Game.ModAPI.Ingame.Utilities;
using VRageMath; using VRageMath;
namespace IngameScript namespace IngameScript
@ -83,7 +84,7 @@ namespace IngameScript
private string _name; private string _name;
private PrefixedConsole _console; private PrefixedConsole _console;
private MyGridProgram _p; private MyIni _ini;
private float targetOxygenLevel = 0.0F; private float targetOxygenLevel = 0.0F;
private IMyDoor _innerDoor; private IMyDoor _innerDoor;
@ -97,9 +98,9 @@ namespace IngameScript
private const int CooldownTicks = 120; private const int CooldownTicks = 120;
private const int SealTimeoutTicks = 30; 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; _name = name;
_console = console.CreatePrefixedConsole(_name); _console = console.CreatePrefixedConsole(_name);
_lights = new List<IMyLightingBlock>(); _lights = new List<IMyLightingBlock>();
@ -116,14 +117,15 @@ namespace IngameScript
else _console.Print($"Tried to add invalid block '{block.CustomName}'"); 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) private void addDoor(IMyDoor door)
{ {
if (door.CustomName.Contains("Inner") && _innerDoor == null) if (_ini.Get("airlock", "doorPosition").ToString() == "inner" && _innerDoor == null)
{ {
_innerDoor = door; _innerDoor = door;
return; return;
} }
if (door.CustomName.Contains("Outer") && _outerDoor == null) if (_ini.Get("airlock", "doorPosition").ToString() == "outer" && _outerDoor == null)
{ {
_outerDoor = door; _outerDoor = door;
return; return;
@ -131,14 +133,15 @@ namespace IngameScript
_console.Print($"Couldn't add door '{door.CustomName}'"); _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) private void addVent(IMyAirVent vent)
{ {
if (vent.CustomName.Contains("Main") && _airVent == null) if (_ini.Get("airlock", "ventRole").ToString() == "cycling" && _airVent == null)
{ {
_airVent = vent; _airVent = vent;
return; return;
} }
if (vent.CustomName.Contains("Reference") && _airSensor == null) if (_ini.Get("airlock", "ventRole").ToString() == "reference" && _airSensor == null)
{ {
_airSensor = vent; _airSensor = vent;
return; return;

View File

@ -23,19 +23,19 @@ namespace IngameScript
_airlocks = new Dictionary<string, Airlock>(); _airlocks = new Dictionary<string, Airlock>();
List<IMyTerminalBlock> airlockBlocks = new List<IMyTerminalBlock>(); List<IMyTerminalBlock> airlockBlocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType(airlockBlocks, block => block.CustomName.Contains("!Airlock")); GridTerminalSystem.GetBlocksOfType(airlockBlocks, block => _ini.ContainsSection("airlock"));
foreach (IMyTerminalBlock block in airlockBlocks) 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"); _airlocks[airlockName] = new Airlock(_ini, _console, airlockName);
if (!_airlocks.ContainsKey(airlockName))
{
_airlocks[airlockName] = new Airlock(this, _console, airlockName);
}
_airlocks[airlockName].AddBlock(block);
} }
_airlocks[airlockName].AddBlock(block);
// TODO: it would be most convenient to just delete non-functional Airlocks... but maybe they're worth // TODO: it would be most convenient to just delete non-functional Airlocks... but maybe they're worth
// keeping around for warnings. // keeping around for warnings.
} }
@ -53,8 +53,8 @@ namespace IngameScript
if (_cli.ArgumentCount == 0) { _console.Print("You must provide an airlock ID."); } if (_cli.ArgumentCount == 0) { _console.Print("You must provide an airlock ID."); }
else else
{ {
string airlockName = $"!Airlock{_cli.Argument(0)}"; string airlockName = _cli.Argument(0);
if (!_airlocks.ContainsKey(airlockName)) _console.Print($"Invalid airlock ID {_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 if (!_airlocks[airlockName].Functional) _console.Print($"Airlock '{airlockName}' is not functional.");
else else
{ {