mirror of
https://github.com/rmroc451/TweaksAndThings.git
synced 2025-12-16 09:19:37 -06:00
additional refactor for #56; fixing AEPlanner spamming recalc of gear when coupling in waypoint mode and reporting stationary endlessly.
This commit is contained in:
@@ -2,6 +2,6 @@
|
||||
<PropertyGroup>
|
||||
<MajorVersion>2</MajorVersion>
|
||||
<MinorVersion>1</MinorVersion>
|
||||
<PatchVersion>3</PatchVersion>
|
||||
<PatchVersion>4</PatchVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -86,6 +86,8 @@ internal class AutoEngineerOrdersHelper_SendAutoEngineerCommand_Patch
|
||||
noCaboose();
|
||||
|
||||
logMessage += $"\nGovern AE? {output}";
|
||||
if (_log.IsEnabled(Serilog.Events.LogEventLevel.Debug))
|
||||
logMessage += $"\n{Environment.StackTrace}";
|
||||
|
||||
_log.Information(logMessage);
|
||||
|
||||
|
||||
@@ -30,9 +30,7 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
|
||||
|
||||
private static readonly HashSet<IDisposable> _keyChangeObservers = new();
|
||||
private static readonly Dictionary<string, Dictionary<string, OpsCarPosition>> locoConsistDestinations = new();
|
||||
private static readonly HashSet<Car> consist = new();
|
||||
private static string _lastLocoCarId = string.Empty;
|
||||
private static bool recalcing = false;
|
||||
private static string _lastSelectedLoco = string.Empty;
|
||||
|
||||
static string getDictKey(Car car) => car.DisplayName;
|
||||
|
||||
@@ -40,7 +38,9 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
|
||||
{
|
||||
PrepLocoUsage(out BaseLocomotive selectedLoco, out int numberOfCars);
|
||||
TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase<TweaksAndThingsPlugin>.Shared;
|
||||
if (!tweaksAndThings.IsEnabled()) return;
|
||||
if (!tweaksAndThings.IsEnabled() || (locoConsistDestinations.TryGetValue(getDictKey(selectedLoco), out Dictionary<string, OpsCarPosition> cars) && cars != null && _lastSelectedLoco == getDictKey(selectedLoco))) return;
|
||||
|
||||
_lastSelectedLoco = getDictKey(selectedLoco);
|
||||
|
||||
IterateCarsDetectDestinations(
|
||||
__instance,
|
||||
@@ -220,7 +220,6 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
|
||||
_log.Debug($"{getDictKey(selectedLoco)} --> HI BOB[{numberOfCars}]");
|
||||
foreach (var o in _keyChangeObservers) o.Dispose();
|
||||
_keyChangeObservers.Clear();
|
||||
recalcing = false;
|
||||
}
|
||||
|
||||
private static OpsCarPosition? GetCarDestinationIdentifier(Car c)
|
||||
@@ -276,7 +275,11 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
|
||||
key,
|
||||
delegate (Value value)
|
||||
{
|
||||
if (recalcing) return;
|
||||
|
||||
_log.Debug($"{getDictKey(car)} OBSV {key}: {value}");
|
||||
|
||||
if (locoConsistDestinations.TryGetValue(getDictKey(TrainController.Shared.SelectedLocomotive), out Dictionary<string, OpsCarPosition> cars) && cars == null) return;
|
||||
|
||||
bool waybillChng = (new[] { Car.KeyOpsWaybill, Car.KeyOpsRepairDestination }).Contains(key);
|
||||
string? destId =
|
||||
waybillChng ?
|
||||
@@ -284,8 +287,7 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
|
||||
null;
|
||||
if (waybillChng)
|
||||
{
|
||||
if (locoConsistDestinations.TryGetValue(getDictKey(TrainController.Shared.SelectedLocomotive), out Dictionary<string, OpsCarPosition> cars)
|
||||
&& cars.TryGetValue(getDictKey(car), out OpsCarPosition pos)
|
||||
if (cars.TryGetValue(getDictKey(car), out OpsCarPosition pos)
|
||||
&& pos.Identifier == destId)
|
||||
{
|
||||
return;
|
||||
@@ -307,7 +309,7 @@ internal class AutoEngineerWaypointControls_ConfigureOptionsDropdown_Patch
|
||||
var loco = TrainController.Shared.SelectedLocomotive;
|
||||
if (!TrainController.Shared.SelectRecall()) TrainController.Shared.SelectedCar = null;
|
||||
_keyChangeObservers.Clear();
|
||||
recalcing = true;
|
||||
if (locoConsistDestinations.TryGetValue(getDictKey(TrainController.Shared.SelectedLocomotive), out _)) locoConsistDestinations[getDictKey(TrainController.Shared.SelectedLocomotive)] = null;
|
||||
TrainController.Shared.SelectedCar = loco;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user