From b12f3b07c49081d55eb0ca5ed427c19166021643 Mon Sep 17 00:00:00 2001 From: Ryan Mroczenski Date: Mon, 17 Jun 2024 20:52:31 -0500 Subject: [PATCH] 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()