From 2941deedc66b302d8c81573a28570eea126ed55a Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 2 Jun 2024 11:37:48 +0300 Subject: [PATCH] Reverted Settings instance cache and cache invalidation --- build/common.props | 2 +- changelog.txt | 4 ++++ .../Base/Global/GlobalSettings.cs | 14 ++++++++++++++ .../Base/PerCampaign/PerCampaignSettings.cs | 15 +++++++++++++++ .../Base/PerSave/PerSaveSettings.cs | 15 +++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/build/common.props b/build/common.props index 5d40d3ab..126fa0b0 100644 --- a/build/common.props +++ b/build/common.props @@ -4,7 +4,7 @@ 1.0.0 v$(GameVersion) - 5.10.0 + 5.10.1 2.2.2 2.8.15 2.8.1 diff --git a/changelog.txt b/changelog.txt index 077c8b80..e731df86 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,8 @@ --------------------------------------------------------------------------------------------------- +Version: 5.10.1 +Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.1.6,v1.2.x +* Reverted Settings instance cache and cache invalidation +--------------------------------------------------------------------------------------------------- Version: 5.10.0 Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.1.6,v1.2.x * Added Settings instance cache and cache invalidation diff --git a/src/MCM.Abstractions/Base/Global/GlobalSettings.cs b/src/MCM.Abstractions/Base/Global/GlobalSettings.cs index 188acf45..b573cd55 100644 --- a/src/MCM.Abstractions/Base/Global/GlobalSettings.cs +++ b/src/MCM.Abstractions/Base/Global/GlobalSettings.cs @@ -13,6 +13,19 @@ namespace MCM.Abstractions.Base.Global # endif abstract class GlobalSettings : GlobalSettings where T : GlobalSettings, new() { + /// + /// A modder flriendly way to get settings from any place + /// + public static T? Instance + { + get + { + if (!Cache.ContainsKey(typeof(T))) + Cache.TryAdd(typeof(T), new T().Id); + return BaseSettingsProvider.Instance?.GetSettings(Cache[typeof(T)]) as T; + } + } + /* /// /// A modder flriendly way to get settings from any place /// We now cache it. Cache is invalidated on game start/end. @@ -29,6 +42,7 @@ namespace MCM.Abstractions.Base.Global { return new T().Id; })!); + */ } #if !BANNERLORDMCM_INCLUDE_IN_CODE_COVERAGE diff --git a/src/MCM.Abstractions/Base/PerCampaign/PerCampaignSettings.cs b/src/MCM.Abstractions/Base/PerCampaign/PerCampaignSettings.cs index 4651bbec..9fd92a84 100644 --- a/src/MCM.Abstractions/Base/PerCampaign/PerCampaignSettings.cs +++ b/src/MCM.Abstractions/Base/PerCampaign/PerCampaignSettings.cs @@ -13,6 +13,20 @@ namespace MCM.Abstractions.Base.PerCampaign # endif abstract class PerCampaignSettings : PerCampaignSettings where T : PerCampaignSettings, new() { + /// + /// A modder flriendly way to get settings from any place + /// + public static T? Instance + { + get + { + if (!Cache.ContainsKey(typeof(T))) + Cache.TryAdd(typeof(T), new T().Id); + return BaseSettingsProvider.Instance?.GetSettings(Cache[typeof(T)]) as T; + } + } + + /* /// /// A modder flriendly way to get settings from any place /// We now cache it. Cache is invalidated on game start/end. @@ -29,6 +43,7 @@ namespace MCM.Abstractions.Base.PerCampaign { return new T().Id; })!); + */ } #if !BANNERLORDMCM_INCLUDE_IN_CODE_COVERAGE diff --git a/src/MCM.Abstractions/Base/PerSave/PerSaveSettings.cs b/src/MCM.Abstractions/Base/PerSave/PerSaveSettings.cs index 4309b223..d1747be7 100644 --- a/src/MCM.Abstractions/Base/PerSave/PerSaveSettings.cs +++ b/src/MCM.Abstractions/Base/PerSave/PerSaveSettings.cs @@ -13,6 +13,20 @@ namespace MCM.Abstractions.Base.PerSave # endif abstract class PerSaveSettings : PerSaveSettings where T : PerSaveSettings, new() { + /// + /// A modder flriendly way to get settings from any place + /// + public static T? Instance + { + get + { + if (!Cache.ContainsKey(typeof(T))) + Cache.TryAdd(typeof(T), new T().Id); + return BaseSettingsProvider.Instance?.GetSettings(Cache[typeof(T)]) as T; + } + } + + /* /// /// A modder flriendly way to get settings from any place /// We now cache it. Cache is invalidated on game start/end. @@ -29,6 +43,7 @@ namespace MCM.Abstractions.Base.PerSave { return new T().Id; })!); + */ } #if !BANNERLORDMCM_INCLUDE_IN_CODE_COVERAGE