diff --git a/MechanicalDoor/MechanicalDoor.csproj b/MechanicalDoor/MechanicalDoor.csproj
index a0c8b60..44a8516 100644
--- a/MechanicalDoor/MechanicalDoor.csproj
+++ b/MechanicalDoor/MechanicalDoor.csproj
@@ -24,7 +24,6 @@
-
\ No newline at end of file
diff --git a/MechanicalDoor/Program.cs b/MechanicalDoor/Program.cs
index b7a68fa..c36f841 100644
--- a/MechanicalDoor/Program.cs
+++ b/MechanicalDoor/Program.cs
@@ -8,6 +8,7 @@ namespace IngameScript
public partial class Program : MyGridProgram
{
private MyCommandLine _cli;
+ private MyIni _ini;
private Console _console;
private List> _jobs;
private Dictionary _doors;
@@ -17,13 +18,14 @@ namespace IngameScript
{
_tickCount = 0;
_cli = new MyCommandLine();
- _console = new Console(this);
+ _ini = new MyIni();
+ _console = new Console(this, _ini);
_jobs = new List>();
-
_doors = new Dictionary();
- List doorParts = Utils.GetBlocksNameContains(GridTerminalSystem, "!Door");
- foreach (IMyTerminalBlock block in doorParts)
+ List doorBlocks = new List();
+ GridTerminalSystem.GetBlocksOfType(doorBlocks, block => block.CustomName.Contains("!Door"));
+ foreach (IMyTerminalBlock block in doorBlocks)
{
string doorName = Utils.ExtractTag(block, "!Door");
@@ -36,7 +38,7 @@ namespace IngameScript
// Add the part; the Door object handles typing and sequencing.
int defaultStep = 1;
if (block is IMyShipMergeBlock) defaultStep = 0;
- ISequenceable wrapped = SequenceableFactory.MakeSequenceable(block, defaultStep);
+ ISequenceable wrapped = SequenceableFactory.MakeSequenceable(block, _ini, defaultStep);
if (wrapped == null) { _console.Print($"Tried to add incompatible block '{block.CustomName}'"); continue; }
_doors[doorName].AddBlock(wrapped);
}
diff --git a/Mixins/ConfigParser/ConfigParser.cs b/Mixins/ConfigParser/ConfigParser.cs
deleted file mode 100644
index 8692087..0000000
--- a/Mixins/ConfigParser/ConfigParser.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using Sandbox.ModAPI.Ingame;
-using System;
-using System.Collections.Generic;
-
-namespace IngameScript
-{
- partial class Program
- {
- public class ConfigParser
- {
- private Dictionary _config;
- private IMyTerminalBlock _input;
-
- public ConfigParser(IMyTerminalBlock input)
- {
- _input = input;
- _config = new Dictionary();
- Parse();
- }
-
- // Get a config value, or a default value.
- // that also does type inference, but the type of `defaultValue` must contain a `Parse()` method.
- public T GetValue(string key, T defaultValue)
- {
- if (!_config.ContainsKey(key))
- {
- return defaultValue;
-
- }
- return (T)Convert.ChangeType(_config[key], typeof(T));
- }
-
- // Only call this method manually if you are monitoring CustomData for changes.
- public void Parse()
- {
- _config.Clear();
- string[] lines = _input.CustomData.Split('\n');
- foreach (string line in lines)
- {
- string[] tokens = line.Split('=');
- if (tokens.Length != 2) continue;
- _config[tokens[0]] = tokens[1];
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Mixins/ConfigParser/ConfigParser.projitems b/Mixins/ConfigParser/ConfigParser.projitems
deleted file mode 100644
index 141cea5..0000000
--- a/Mixins/ConfigParser/ConfigParser.projitems
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
- $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
- true
- 8a3cdcc5-4b55-4d87-a415-698a0e1ff06f
-
-
-
-
-
\ No newline at end of file
diff --git a/Mixins/ConfigParser/ConfigParser.shproj b/Mixins/ConfigParser/ConfigParser.shproj
deleted file mode 100644
index 2d68160..0000000
--- a/Mixins/ConfigParser/ConfigParser.shproj
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
- 8a3cdcc5-4b55-4d87-a415-698a0e1ff06f
- 14.0
-
-
-
-
-
-
- bin\Debug\
-
-
- bin\Release\
-
-
-
-
diff --git a/Mixins/Console/Console.cs b/Mixins/Console/Console.cs
index ce8a725..7c25e80 100644
--- a/Mixins/Console/Console.cs
+++ b/Mixins/Console/Console.cs
@@ -5,6 +5,7 @@
using Sandbox.ModAPI.Ingame;
using System.Collections.Generic;
using System.Text;
+using VRage.Game.ModAPI.Ingame.Utilities;
namespace IngameScript
{
@@ -24,14 +25,14 @@ namespace IngameScript
private const int DefaultMaxLines = 10;
- public Console(MyGridProgram program)
+ public Console(MyGridProgram program, MyIni ini)
{
_program = program;
_buffer = new List();
// Check the PB's custom data for a maxlines directive.
- ConfigParser config = new ConfigParser(_program.Me);
- _maxLines = config.GetValue("ConsoleMaxLines", DefaultMaxLines);
+ ini.TryParse(program.Me.CustomData);
+ _maxLines = ini.Get("console", "maxLines").ToInt32(DefaultMaxLines);
}
public PrefixedConsole CreatePrefixedConsole(string prefix)
diff --git a/Mixins/Sequencer/SequenceableFactory.cs b/Mixins/Sequencer/SequenceableFactory.cs
index 829bebc..330447e 100644
--- a/Mixins/Sequencer/SequenceableFactory.cs
+++ b/Mixins/Sequencer/SequenceableFactory.cs
@@ -2,6 +2,7 @@
using Sandbox.ModAPI.Ingame;
using SpaceEngineers.Game.ModAPI.Ingame;
+using VRage.Game.ModAPI.Ingame.Utilities;
namespace IngameScript
{
@@ -9,11 +10,14 @@ namespace IngameScript
{
public class SequenceableFactory
{
- public static ISequenceable MakeSequenceable(IMyTerminalBlock block, int step = 0)
+ public static ISequenceable MakeSequenceable(
+ IMyTerminalBlock block,
+ MyIni ini,
+ int step = 0)
{
if (block is IMyMotorStator)
{
- return new SequenceableRotor(block as IMyMotorStator, step);
+ return new SequenceableRotor(block as IMyMotorStator, ini, step);
}
if (block is IMyPistonBase)
{
diff --git a/Mixins/Sequencer/SequenceableRotor.cs b/Mixins/Sequencer/SequenceableRotor.cs
index b106fc3..da82cf1 100644
--- a/Mixins/Sequencer/SequenceableRotor.cs
+++ b/Mixins/Sequencer/SequenceableRotor.cs
@@ -1,6 +1,6 @@
using Sandbox.ModAPI.Ingame;
-using System.Collections.Generic;
using System;
+using VRage.Game.ModAPI.Ingame.Utilities;
namespace IngameScript
{
@@ -19,15 +19,18 @@ namespace IngameScript
private float _closedAngle;
private IMyMotorStator _rotor;
- public SequenceableRotor(IMyMotorStator rotor, int defaultStep = 0)
+ public SequenceableRotor(
+ IMyMotorStator rotor,
+ MyIni ini,
+ int defaultStep = 0)
{
_rotor = rotor;
- ConfigParser config = new ConfigParser(_rotor);
- _openAngle = config.GetValue("OpenAngle", 90F);
- _closedAngle = config.GetValue("ClosedAngle", 0F);
- _velocity = config.GetValue("Velocity", 5F);
- Step = config.GetValue("Step", defaultStep);
+ ini.TryParse(rotor.CustomData);
+ _openAngle = ini.Get("sequencer", "openAngle").ToSingle(90F);
+ _closedAngle = ini.Get("sequencer", "closedAngle").ToSingle(0F);
+ _velocity = ini.Get("sequencer", "velocity").ToSingle(5F);
+ Step = ini.Get("sequencer", "step").ToInt32(defaultStep);
}
public void Start(bool reverse)
diff --git a/Mixins/Utils/Utils.cs b/Mixins/Utils/Utils.cs
index 2b6bfdf..1c698d9 100644
--- a/Mixins/Utils/Utils.cs
+++ b/Mixins/Utils/Utils.cs
@@ -48,9 +48,9 @@ namespace IngameScript
public static string ExtractTag(IMyTerminalBlock block, string tag)
{
- Regex r = new Regex($@"({tag}\w*?)\s");
- Match m = r.Match(block.CustomName);
- if (m.Success) return m.Groups[0].Captures[0].ToString();
+ foreach (string token in block.CustomName.Split(' ')) {
+ if (token.StartsWith(tag)) return token;
+ }
return "";
}
}