From 371cfc41c8aead0ccafcec5b635b276c17a45fb5 Mon Sep 17 00:00:00 2001 From: Ryan Mroczenski Date: Mon, 17 Jun 2024 18:50:01 -0500 Subject: [PATCH 1/3] #2 remove ex.tostring from appending to entry.text and spamming console. --- TweaksAndThings/Patches/ExpandedConsole_Patch.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/TweaksAndThings/Patches/ExpandedConsole_Patch.cs b/TweaksAndThings/Patches/ExpandedConsole_Patch.cs index 7036b6b..98fb6c4 100644 --- a/TweaksAndThings/Patches/ExpandedConsole_Patch.cs +++ b/TweaksAndThings/Patches/ExpandedConsole_Patch.cs @@ -102,7 +102,6 @@ public class ExpandedConsole_Add_Patch catch (Exception ex) { Log.Error(ex, ex.Message); - entry.Text += ex.ToString(); } } From b12f3b07c49081d55eb0ca5ed427c19166021643 Mon Sep 17 00:00:00 2001 From: Ryan Mroczenski Date: Mon, 17 Jun 2024 20:52:31 -0500 Subject: [PATCH 2/3] initial fixes for settings instantiation issue --- TweaksAndThings/Settings.cs | 13 +++++++++---- TweaksAndThings/TweaksAndThings.cs | 10 +++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/TweaksAndThings/Settings.cs b/TweaksAndThings/Settings.cs index 2b0dcc2..fc92a17 100644 --- a/TweaksAndThings/Settings.cs +++ b/TweaksAndThings/Settings.cs @@ -12,10 +12,11 @@ public class Settings { public Settings() - {} + { + WebhookSettingsList = new[] { new WebhookSettings() }.ToList(); + } - public Settings( - WebhookSettings webhookSettings, + public Settings( List webhookSettingsList, bool handBrakeAndAirTagModifiers ) @@ -29,7 +30,11 @@ public class Settings internal void AddAnotherRow() { - //if (!string.IsNullOrEmpty(WebhookSettingsList.Last().WebhookUrl)) WebhookSettingsList.Add(new()); + if (!string.IsNullOrEmpty(WebhookSettingsList.Last().WebhookUrl)) + { + WebhookSettingsList.Add(new()); + Log.Information($"Adding another {nameof(WebhookSettings)} list entry, last one was filled in"); + } } } diff --git a/TweaksAndThings/TweaksAndThings.cs b/TweaksAndThings/TweaksAndThings.cs index 2b54adf..abdf47e 100644 --- a/TweaksAndThings/TweaksAndThings.cs +++ b/TweaksAndThings/TweaksAndThings.cs @@ -1,16 +1,11 @@ using GalaSoft.MvvmLight.Messaging; -using Game.Messages; using Game.State; using HarmonyLib; -using Newtonsoft.Json.Linq; using Railloader; using Serilog; -using Serilog.Debugging; using System.Linq; using System.Net.Http; -using TweaksAndThings.Commands; using UI.Builder; -using UI.CarInspector; namespace TweaksAndThings { @@ -48,6 +43,11 @@ namespace TweaksAndThings //moddingContext.RegisterConsoleCommand(new EchoCommand()); settings = moddingContext.LoadSettingsData(self.Id); + if (settings.WebhookSettingsList?.Any() ?? false) + { + settings.WebhookSettingsList = new[] { new WebhookSettings() }.ToList(); + this.moddingContext.SaveSettingsData(this.modDefinition.Id, settings ?? new()); + } } public override void OnEnable() From 7a21c6472eeeadb18cd46e6aac59f6f26718d36d Mon Sep 17 00:00:00 2001 From: RMROC451 Date: Mon, 17 Jun 2024 22:55:51 -0500 Subject: [PATCH 3/3] removed hStack.RebuildOnInterval in favor of builder.AddObserver for each car in inspector car's consist. --- Directory.Build.targets | 2 +- .../CarInspector_PopulateCarPanel_Patch.cs | 35 +++++++++++-------- .../RMROC451.TweaksAndThings.csproj | 6 ---- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index 9dc8f41..28fc007 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -12,7 +12,7 @@ 0 1 - 1 + 2 $(MajorVersion).$(MinorVersion).$(PatchVersion) $(AssemblyVersion) $(AssemblyVersion) diff --git a/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs b/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs index 2a176c4..b9f7654 100644 --- a/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs +++ b/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs @@ -1,27 +1,16 @@ -using GalaSoft.MvvmLight.Messaging; -using Game; -using Game.Events; -using Game.Messages; +using Game.Messages; using Game.State; using HarmonyLib; using KeyValue.Runtime; -using Network; -using Network.Messages; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using Railloader; using Serilog; using System; -using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Runtime.Remoting.Messaging; using TweaksAndThings.Enums; using UI.Builder; using UI.CarInspector; -using WorldStreamer2; using static Model.Car; -using static Unity.IO.LowLevel.Unsafe.AsyncReadManagerMetrics; namespace TweaksAndThings.Patches; @@ -44,10 +33,11 @@ public class CarInspector_PopulateCarPanel_Patch TweaksAndThings tweaksAndThings = SingletonPluginBase.Shared; if (!tweaksAndThings.IsEnabled) return true; + var consist = __instance._car.EnumerateCoupled(LogicalEnd.A); + builder = AddCarConsistRebuildObservers(builder, consist); + builder.HStack(delegate (UIPanelBuilder hstack) { - var consist = __instance._car.EnumerateCoupled(LogicalEnd.A); - var buttonName = $"{(consist.Any(c => c.HandbrakeApplied()) ? "Release " : "Set ")} {TextSprites.HandbrakeWheel}"; hstack.AddButtonCompact(buttonName, delegate { @@ -63,12 +53,27 @@ public class CarInspector_PopulateCarPanel_Patch hstack.Rebuild(); }).Tooltip("Connect Consist Air Lines", "Iterates over each car in this consist and connects gladhands and opens anglecocks."); } - hstack.RebuildOnInterval(1f); }); return true; } + private static UIPanelBuilder AddCarConsistRebuildObservers(UIPanelBuilder builder, IEnumerable consist) + { + foreach (Model.Car car in consist) + { + builder.AddObserver(car.KeyValueObject.Observe(PropertyChange.KeyForControl(PropertyChange.Control.Handbrake), delegate (Value value) { builder.Rebuild(); }, false)); + foreach (LogicalEnd logicalEnd in ends) + { + builder.AddObserver(car.KeyValueObject.Observe(KeyValueKeyFor(EndGearStateKey.IsCoupled, car.LogicalToEnd(logicalEnd)), delegate (Value value) { builder.Rebuild(); }, false)); + builder.AddObserver(car.KeyValueObject.Observe(KeyValueKeyFor(EndGearStateKey.IsAirConnected, car.LogicalToEnd(logicalEnd)), delegate (Value value) { builder.Rebuild(); }, false)); + builder.AddObserver(car.KeyValueObject.Observe(KeyValueKeyFor(EndGearStateKey.Anglecock, car.LogicalToEnd(logicalEnd)), delegate (Value value) { builder.Rebuild(); }, false)); + } + } + + return builder; + } + public static void MrocConsistHelper(Model.Car car, MrocHelperType mrocHelperType) { IEnumerable consist = car.EnumerateCoupled(LogicalEnd.A); diff --git a/TweaksAndThings/RMROC451.TweaksAndThings.csproj b/TweaksAndThings/RMROC451.TweaksAndThings.csproj index 47d737c..5b93d89 100644 --- a/TweaksAndThings/RMROC451.TweaksAndThings.csproj +++ b/TweaksAndThings/RMROC451.TweaksAndThings.csproj @@ -27,10 +27,4 @@ - - - - D:\SteamLibrary\steamapps\common\Railroader\Mods\ForYourConvenience\ForYourConvenience.dll - -