249 lines
14 KiB
C#
249 lines
14 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Collections.Generic;
|
|
using OpenBveApi.Runtime;
|
|
|
|
namespace OpenbveFcmbTrainPlugin
|
|
{
|
|
/// <summary>A class for loading plugin settings from a file.</summary>
|
|
internal static class ConfigManager
|
|
{
|
|
/// <summary>Represents a collection of plugin settings.</summary>
|
|
internal class SettingsCollection
|
|
{
|
|
internal double TrainLength;
|
|
|
|
internal bool DoorSelectionDeviceEnabled;
|
|
internal bool DoorClosingSoundDeviceEnabled;
|
|
internal bool DoorTractionCutDeviceEnabled;
|
|
internal bool DeadmanDeviceEnabled;
|
|
internal bool TrainStopDeviceEnabled;
|
|
internal bool AtcBombardierDeviceEnabled;
|
|
internal bool AtcDimetronicDeviceEnabled;
|
|
|
|
internal bool DoorClosingSoundRequired;
|
|
internal int DoorClosingSoundDuration = 5;
|
|
internal int DoorClosingSoundTimeout = 15;
|
|
internal int DoorClosingSoundIndex = 10;
|
|
|
|
internal int DeadmanBrakeDelay = 5;
|
|
internal bool DeadmanRequireFullStop;
|
|
|
|
internal int AtcBombardierInitializationTime = 30;
|
|
internal int AtcBombardierYardIdleTime = 60;
|
|
internal int AtcBombardierYardSpeedLimit = 20;
|
|
internal int AtcBombardierBlinkTime = 500;
|
|
|
|
internal Speed AtcDimetronicYardSpeedLimit = new Speed(25 / 3.6);
|
|
internal bool AtcDimetronicAtoAvailable;
|
|
internal List<AtcDimetronic.SignalCode> AtcDimetronicSignalCodes = new List<AtcDimetronic.SignalCode>();
|
|
}
|
|
|
|
/// <summary>Represents the plugin settings.</summary>
|
|
internal static SettingsCollection PluginSettings = new SettingsCollection();
|
|
|
|
/// <summary>Loads a config file.</summary>
|
|
internal static void LoadConfig(string folder, string file)
|
|
{
|
|
string configFile = OpenBveApi.Path.CombineFile(folder, file);
|
|
if (System.IO.File.Exists(configFile))
|
|
{
|
|
// load options
|
|
string[] Lines = System.IO.File.ReadAllLines(configFile, new System.Text.UTF8Encoding());
|
|
string Section = "";
|
|
for (int i = 0; i < Lines.Length; i++)
|
|
{
|
|
Lines[i] = Lines[i].Trim(new char[] { });
|
|
if (Lines[i].Length != 0 && !Lines[i].StartsWith(";", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
if (Lines[i].StartsWith("[", StringComparison.Ordinal) &
|
|
Lines[i].EndsWith("]", StringComparison.Ordinal))
|
|
{
|
|
Section = Lines[i].Substring(1, Lines[i].Length - 2).Trim(new char[] { }).ToLowerInvariant();
|
|
}
|
|
else
|
|
{
|
|
int j = Lines[i].IndexOf("=", StringComparison.OrdinalIgnoreCase);
|
|
string Key, Value;
|
|
if (j >= 0)
|
|
{
|
|
Key = Lines[i].Substring(0, j).TrimEnd().ToLowerInvariant();
|
|
Value = Lines[i].Substring(j + 1).TrimStart();
|
|
}
|
|
else
|
|
{
|
|
Key = "";
|
|
Value = Lines[i];
|
|
}
|
|
switch (Section)
|
|
{
|
|
case "train":
|
|
switch (Key)
|
|
{
|
|
case "length":
|
|
{
|
|
if (double.TryParse(Value, NumberStyles.Float, CultureInfo.InvariantCulture, out double a))
|
|
{
|
|
PluginSettings.TrainLength = a;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
break;
|
|
case "doorselection":
|
|
switch (Key)
|
|
{
|
|
case "enabled":
|
|
PluginSettings.DoorSelectionDeviceEnabled = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
|
|
break;
|
|
}
|
|
break;
|
|
case "doorclosingsound":
|
|
switch (Key)
|
|
{
|
|
case "enabled":
|
|
PluginSettings.DoorClosingSoundDeviceEnabled = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
|
|
break;
|
|
case "required":
|
|
PluginSettings.DoorClosingSoundRequired = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
|
|
break;
|
|
case "duration":
|
|
{
|
|
if (int.TryParse(Value, out int a))
|
|
{
|
|
PluginSettings.DoorClosingSoundDuration = a;
|
|
}
|
|
}
|
|
break;
|
|
case "timeout":
|
|
{
|
|
if (int.TryParse(Value, out int a))
|
|
{
|
|
PluginSettings.DoorClosingSoundTimeout = a;
|
|
}
|
|
}
|
|
break;
|
|
case "index":
|
|
{
|
|
if (int.TryParse(Value, out int a))
|
|
{
|
|
PluginSettings.DoorClosingSoundIndex = a;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
break;
|
|
case "doortractioncut":
|
|
switch (Key)
|
|
{
|
|
case "enabled":
|
|
PluginSettings.DoorTractionCutDeviceEnabled = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
|
|
break;
|
|
}
|
|
break;
|
|
case "deadman":
|
|
switch (Key)
|
|
{
|
|
case "enabled":
|
|
PluginSettings.DeadmanDeviceEnabled = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
|
|
break;
|
|
case "brakedelay":
|
|
{
|
|
if (int.TryParse(Value, out int a))
|
|
{
|
|
PluginSettings.DeadmanBrakeDelay = a;
|
|
}
|
|
}
|
|
break;
|
|
case "requirefullstop":
|
|
PluginSettings.DeadmanRequireFullStop = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
|
|
break;
|
|
}
|
|
break;
|
|
case "trainstop":
|
|
switch (Key)
|
|
{
|
|
case "enabled":
|
|
PluginSettings.TrainStopDeviceEnabled = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
|
|
break;
|
|
}
|
|
break;
|
|
case "atcbombardier":
|
|
switch (Key)
|
|
{
|
|
case "enabled":
|
|
PluginSettings.AtcBombardierDeviceEnabled = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
|
|
break;
|
|
case "initializationtime":
|
|
{
|
|
if (int.TryParse(Value, out int a))
|
|
{
|
|
PluginSettings.AtcBombardierInitializationTime = a;
|
|
}
|
|
}
|
|
break;
|
|
case "yardidletime":
|
|
{
|
|
if (int.TryParse(Value, out int a))
|
|
{
|
|
PluginSettings.AtcBombardierYardIdleTime = a;
|
|
}
|
|
}
|
|
break;
|
|
case "yardspeedlimit":
|
|
{
|
|
if (int.TryParse(Value, out int a))
|
|
{
|
|
PluginSettings.AtcBombardierYardSpeedLimit = a;
|
|
}
|
|
}
|
|
break;
|
|
case "blinktime":
|
|
{
|
|
if (int.TryParse(Value, out int a))
|
|
{
|
|
PluginSettings.AtcBombardierBlinkTime = a;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
break;
|
|
case "atcdimetronic":
|
|
switch (Key)
|
|
{
|
|
case "enabled":
|
|
PluginSettings.AtcDimetronicDeviceEnabled = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
|
|
break;
|
|
case "yardspeedlimit":
|
|
{
|
|
if (int.TryParse(Value, out int a))
|
|
{
|
|
PluginSettings.AtcDimetronicYardSpeedLimit = new Speed(a / 3.6);
|
|
}
|
|
}
|
|
break;
|
|
case "atoavailable":
|
|
PluginSettings.AtcDimetronicAtoAvailable = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
|
|
break;
|
|
default:
|
|
if (int.TryParse(Key, NumberStyles.Integer, CultureInfo.InvariantCulture, out int aspect))
|
|
{
|
|
AtcDimetronic.SignalCode signalCode = new AtcDimetronic.SignalCode(aspect, Value);
|
|
if (signalCode != null)
|
|
{
|
|
PluginSettings.AtcDimetronicSignalCodes.Add(signalCode);
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|