From 30794201f062902adb3bd815e92a7ecccbfe45d0 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Sun, 24 Sep 2023 17:13:41 +0200 Subject: [PATCH] migrate to GameConfig & cleanup warnings --- PlayerTags.sln | 1 + .../GameConfig/GameConfigHelper.cs | 42 ++++--------------- .../Configuration/GameConfig/LogNameType.cs | 2 +- .../Configuration/PluginConfigurationUI.cs | 2 +- .../GameInterface/Nameplates/Nameplate.cs | 2 +- PlayerTags/Inheritables/InheritableValue.cs | 4 +- PlayerTags/Localizer.cs | 2 +- PlayerTags/Plugin.cs | 1 - PlayerTags/PluginServices.cs | 2 + PlayerTags/RandomNameGenerator.cs | 4 +- 10 files changed, 19 insertions(+), 43 deletions(-) diff --git a/PlayerTags.sln b/PlayerTags.sln index 9ce7dc5..74df2af 100644 --- a/PlayerTags.sln +++ b/PlayerTags.sln @@ -26,6 +26,7 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution + RESX_ShowErrorsInErrorList = False SolutionGuid = {B17E85B1-5F60-4440-9F9A-3DDE877E8CDF} EndGlobalSection EndGlobal diff --git a/PlayerTags/Configuration/GameConfig/GameConfigHelper.cs b/PlayerTags/Configuration/GameConfig/GameConfigHelper.cs index c10df56..f84a58d 100644 --- a/PlayerTags/Configuration/GameConfig/GameConfigHelper.cs +++ b/PlayerTags/Configuration/GameConfig/GameConfigHelper.cs @@ -30,45 +30,19 @@ namespace PlayerTags.Configuration.GameConfig } } - private int? GetIntValue(ConfigOption option) + private uint? GetIntValue(ConfigOption option) { - int? value = null; - - unsafe - { - var index = configModule->GetIndex(option); - if (index.HasValue) - value = configModule->GetIntValue(index.Value); - } - - return value; + if (PluginServices.GameConfig.UiConfig.TryGetUInt(nameof(ConfigOption.LogNameType), out var value)) + return value; + return null; } public LogNameType? GetLogNameType() { - LogNameType? logNameType = null; - int? value = GetIntValue(ConfigOption.LogNameType); - - if (value.HasValue) - { - switch (value) - { - case 0: - logNameType = LogNameType.FullName; - break; - case 1: - logNameType = LogNameType.LastNameShorted; - break; - case 2: - logNameType = LogNameType.FirstNameShorted; - break; - case 3: - logNameType = LogNameType.Initials; - break; - } - } - - return logNameType; + uint? value = GetIntValue(ConfigOption.LogNameType); + if (value != null) + return (LogNameType)value; + return null; } } } diff --git a/PlayerTags/Configuration/GameConfig/LogNameType.cs b/PlayerTags/Configuration/GameConfig/LogNameType.cs index 3605357..cc75bdf 100644 --- a/PlayerTags/Configuration/GameConfig/LogNameType.cs +++ b/PlayerTags/Configuration/GameConfig/LogNameType.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace PlayerTags.Configuration.GameConfig { - public enum LogNameType + public enum LogNameType : uint { FullName, LastNameShorted, diff --git a/PlayerTags/Configuration/PluginConfigurationUI.cs b/PlayerTags/Configuration/PluginConfigurationUI.cs index 3feb61f..05fe348 100644 --- a/PlayerTags/Configuration/PluginConfigurationUI.cs +++ b/PlayerTags/Configuration/PluginConfigurationUI.cs @@ -803,7 +803,7 @@ namespace PlayerTags.Configuration } else { - PluginLog.Warning($"Rendering for inheritable option not implemented: {selectedInheritable.Inheritable.Key}"); + PluginServices.PluginLog.Warning($"Rendering for inheritable option not implemented: {selectedInheritable.Inheritable.Key}"); } } } diff --git a/PlayerTags/GameInterface/Nameplates/Nameplate.cs b/PlayerTags/GameInterface/Nameplates/Nameplate.cs index 62c5350..8e90611 100644 --- a/PlayerTags/GameInterface/Nameplates/Nameplate.cs +++ b/PlayerTags/GameInterface/Nameplates/Nameplate.cs @@ -58,7 +58,7 @@ namespace PlayerTags.GameInterface.Nameplates } catch (Exception ex) { - PluginLog.Error(ex, $"SetPlayerNameplateDetour"); + PluginServices.PluginLog.Error(ex, $"SetPlayerNameplateDetour"); } } } diff --git a/PlayerTags/Inheritables/InheritableValue.cs b/PlayerTags/Inheritables/InheritableValue.cs index f17e55a..4ac7422 100644 --- a/PlayerTags/Inheritables/InheritableValue.cs +++ b/PlayerTags/Inheritables/InheritableValue.cs @@ -68,7 +68,7 @@ namespace PlayerTags.Inheritables else if (inheritableData.Value == null) { // This should never happen - PluginLog.Error($"Expected value of type {Value.GetType()} but received null"); + PluginServices.PluginLog.Error($"Expected value of type {Value.GetType()} but received null"); } else if (typeof(T) == typeof(Guid) && inheritableData.Value is string strValue) { @@ -81,7 +81,7 @@ namespace PlayerTags.Inheritables } catch (Exception ex) { - PluginLog.Error(ex, $"Failed to convert {inheritableData.Value.GetType()} value '{inheritableData.Value}' to {Value.GetType()}"); + PluginServices.PluginLog.Error(ex, $"Failed to convert {inheritableData.Value.GetType()} value '{inheritableData.Value}' to {Value.GetType()}"); } } diff --git a/PlayerTags/Localizer.cs b/PlayerTags/Localizer.cs index fffc28d..18c8a51 100644 --- a/PlayerTags/Localizer.cs +++ b/PlayerTags/Localizer.cs @@ -55,7 +55,7 @@ namespace PlayerTags if (value != null) return value; - PluginLog.Error($"Failed to get localized string for id {localizedStringId}"); + PluginServices.PluginLog.Error($"Failed to get localized string for id {localizedStringId}"); return localizedStringId; } } diff --git a/PlayerTags/Plugin.cs b/PlayerTags/Plugin.cs index 12a21d3..e27090d 100644 --- a/PlayerTags/Plugin.cs +++ b/PlayerTags/Plugin.cs @@ -26,7 +26,6 @@ namespace PlayerTags private PluginConfiguration pluginConfiguration = null; private PluginData pluginData = null; private PluginConfigurationUI pluginConfigurationUI = null; - private DalamudPluginInterface pluginInterface = null; private CustomTagsContextMenuFeature customTagsContextMenuFeature; private NameplateTagTargetFeature nameplatesTagTargetFeature; diff --git a/PlayerTags/PluginServices.cs b/PlayerTags/PluginServices.cs index 2c96eee..8e270e1 100644 --- a/PlayerTags/PluginServices.cs +++ b/PlayerTags/PluginServices.cs @@ -14,6 +14,8 @@ namespace PlayerTags public class PluginServices { [PluginService] public static DalamudPluginInterface DalamudPluginInterface { get; set; } = null!; + [PluginService] public static IPluginLog PluginLog { get; set; } = null; + [PluginService] public static IGameConfig GameConfig { get; set; } = null; [PluginService] public static IChatGui ChatGui { get; set; } = null!; [PluginService] public static IClientState ClientState { get; set; } = null!; [PluginService] public static ICommandManager CommandManager { get; set; } = null!; diff --git a/PlayerTags/RandomNameGenerator.cs b/PlayerTags/RandomNameGenerator.cs index 54bebfb..430b025 100644 --- a/PlayerTags/RandomNameGenerator.cs +++ b/PlayerTags/RandomNameGenerator.cs @@ -24,7 +24,7 @@ namespace PlayerTags } catch (Exception ex) { - PluginLog.Error(ex, $"RandomNameGenerator failed to read adjectives"); + PluginServices.PluginLog.Error(ex, $"RandomNameGenerator failed to read adjectives"); } } @@ -50,7 +50,7 @@ namespace PlayerTags } catch (Exception ex) { - PluginLog.Error(ex, $"RandomNameGenerator failed to read nouns"); + PluginServices.PluginLog.Error(ex, $"RandomNameGenerator failed to read nouns"); } }