From 9dcf923a4959cddd41f1dad6d13b645456577bcc Mon Sep 17 00:00:00 2001 From: annabunches Date: Sat, 8 Feb 2025 21:04:28 -0500 Subject: [PATCH] Use ConfigParser library. --- MechanicalDoor/DoorHinge.cs | 28 +++++----------------------- MechanicalDoor/MechanicalDoor.csproj | 2 ++ 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/MechanicalDoor/DoorHinge.cs b/MechanicalDoor/DoorHinge.cs index bdcaab2..d0cf1e6 100644 --- a/MechanicalDoor/DoorHinge.cs +++ b/MechanicalDoor/DoorHinge.cs @@ -20,7 +20,11 @@ namespace IngameScript { _p = p; _hinge = hinge; - parseConfig(); + + ConfigParser config = new ConfigParser(_hinge); + _openAngle = config.GetValue("OpenAngle", 90F); + _closedAngle = config.GetValue("ClosedAngle", 0F); + _velocity = config.GetValue("Velocity", 5F); } // For these two functions, IMyMotorStator.Angle reports radians, but @@ -52,28 +56,6 @@ namespace IngameScript return Locked; } - private void parseConfig() - { - string[] lines = _hinge.CustomData.Split('\n'); - foreach (string line in lines) - { - string[] tokens = line.Split('='); - if (tokens.Length != 2) continue; - switch (tokens[0]) - { - case "OpenAngle": - _openAngle = float.Parse(tokens[1]); - break; - case "ClosedAngle": - _closedAngle = float.Parse(tokens[1]); - break; - case "Velocity": - _velocity = float.Parse(tokens[1]); - break; - } - } - } - private float degToRad(float degrees) { return degrees * ((float)Math.PI / 180F); diff --git a/MechanicalDoor/MechanicalDoor.csproj b/MechanicalDoor/MechanicalDoor.csproj index f2006f4..7b595e0 100644 --- a/MechanicalDoor/MechanicalDoor.csproj +++ b/MechanicalDoor/MechanicalDoor.csproj @@ -23,4 +23,6 @@ + + \ No newline at end of file