Configure Mechanical Door to use CustomData for configuration. Also refactor Sequenceables to use the yield enumerator pattern.
This commit is contained in:
@ -24,21 +24,20 @@ namespace IngameScript
|
||||
_doors = new Dictionary<string, Sequencer>();
|
||||
|
||||
List<IMyTerminalBlock> doorBlocks = new List<IMyTerminalBlock>();
|
||||
GridTerminalSystem.GetBlocksOfType<IMyTerminalBlock>(doorBlocks, block => block.CustomName.Contains("!Door"));
|
||||
GridTerminalSystem.GetBlocksOfType(doorBlocks, block => MyIni.HasSection(block.CustomData, "mechDoor"));
|
||||
foreach (IMyTerminalBlock block in doorBlocks)
|
||||
{
|
||||
string doorName = Utils.ExtractTag(block, "!Door");
|
||||
|
||||
// Create the door if this is a new tag
|
||||
_ini.TryParse(block.CustomData);
|
||||
string doorName = _ini.Get("mechDoor", "id").ToString();
|
||||
// Create the door if this is a new id
|
||||
if (!_doors.ContainsKey(doorName))
|
||||
{
|
||||
_doors[doorName] = new Sequencer(doorName, new PrefixedConsole(_console, doorName));
|
||||
}
|
||||
|
||||
// Add the part; the Door object handles typing and sequencing.
|
||||
int defaultStep = 1;
|
||||
if (block is IMyShipMergeBlock) defaultStep = 0;
|
||||
ISequenceable wrapped = SequenceableFactory.MakeSequenceable(block, _ini, defaultStep);
|
||||
ISequenceable wrapped = SequenceableFactory.MakeSequenceable(block, _ini, "mechDoor");
|
||||
if (!(block is IMyShipMergeBlock)) wrapped.Step = 1;
|
||||
if (wrapped == null) { _console.Print($"Tried to add incompatible block '{block.CustomName}'"); continue; }
|
||||
_doors[doorName].AddBlock(wrapped);
|
||||
}
|
||||
@ -68,7 +67,7 @@ namespace IngameScript
|
||||
|
||||
for (int i = 0; i < _cli.ArgumentCount; i++)
|
||||
{
|
||||
string key = "Door" + _cli.Argument(i);
|
||||
string key = _cli.Argument(i);
|
||||
if (!_doors.ContainsKey(key))
|
||||
{
|
||||
_console.Print($"Door '{key}' not found. Skipping.");
|
||||
@ -89,10 +88,10 @@ namespace IngameScript
|
||||
else
|
||||
{
|
||||
_console.Print("Creating new job(s).");
|
||||
bool close = _cli.Switch("close");
|
||||
bool deploy = _cli.Switch("deploy") || _cli.Switch("open");
|
||||
foreach (Sequencer door in doorsToControl)
|
||||
{
|
||||
_jobs.Add(door.RunSequence(close));
|
||||
_jobs.Add(door.RunSequence(deploy));
|
||||
}
|
||||
Runtime.UpdateFrequency |= UpdateFrequency.Update1;
|
||||
}
|
||||
@ -101,13 +100,12 @@ namespace IngameScript
|
||||
// Process running jobs
|
||||
for (int i = 0; i < _jobs.Count; i++)
|
||||
{
|
||||
if (!_jobs[i].MoveNext())
|
||||
{
|
||||
_jobs[i].Dispose();
|
||||
_jobs.Remove(_jobs[i]);
|
||||
i--;
|
||||
_console.Print("Operation Complete.");
|
||||
}
|
||||
if (_jobs[i].MoveNext()) continue;
|
||||
|
||||
_jobs[i].Dispose();
|
||||
_jobs.Remove(_jobs[i]);
|
||||
i--;
|
||||
_console.Print("Operation Complete.");
|
||||
}
|
||||
|
||||
if (_jobs.Count == 0)
|
||||
|
Reference in New Issue
Block a user