From 1eec16d808399b3a57892e5fc34a355992a0c1bd Mon Sep 17 00:00:00 2001 From: r00telement <47005506+r00telement@users.noreply.github.com> Date: Sun, 12 Dec 2021 05:51:14 +0000 Subject: [PATCH] Cleanup --- PlayerTags/Features/ChatTagTargetFeature.cs | 52 ++++++--------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/PlayerTags/Features/ChatTagTargetFeature.cs b/PlayerTags/Features/ChatTagTargetFeature.cs index b324973..281ade0 100644 --- a/PlayerTags/Features/ChatTagTargetFeature.cs +++ b/PlayerTags/Features/ChatTagTargetFeature.cs @@ -79,8 +79,8 @@ namespace PlayerTags.Features private void Chat_ChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled) { - AddTagsToChat(sender, out _); - AddTagsToChat(message, out _); + AddTagsToChat(sender); + AddTagsToChat(message); } protected override bool IsIconVisible(Tag tag) @@ -137,26 +137,6 @@ namespace PlayerTags.Features PluginLog.Error("Expected payload after player payload to be a text payload but it wasn't"); } } - - /// TODO: Not sure if this is desirable. Enabling this allows tags to appear next to the name of the local player by text in chat because the local player doesn't have a player payload. - /// But because it's just a simple string comparison, it won't work in all circumstances. E.g. in party chat the player name is wrapped in (). To be comprehensive we need to search substring. - /// This means we would need to think about breaking down existing payloads to split them out. - /// If we decide to do that, we could even for example find unlinked player names in chat and add player payloads for them. - // If it's just a text payload then either a character NEEDS to exist for it, or it needs to be identified as a character by custom tag configs - //else if (payload is TextPayload textPayload) - //{ - // var gameObject = ObjectTable.FirstOrDefault(gameObject => gameObject.Name.TextValue == textPayload.Text); - // var isIncludedInCustomTagConfig = m_Config.CustomTags.Any(customTagConfig => customTagConfig.IncludesGameObjectName(textPayload.Text)); - - // if (gameObject != null || isIncludedInCustomTagConfig) - // { - // var stringMatch = new StringMatch(seString, textPayload) - // { - // GameObject = gameObject - // }; - // stringMatches.Add(stringMatch); - // } - //} } return stringMatches; @@ -167,20 +147,17 @@ namespace PlayerTags.Features /// /// The message to change. /// Whether the message was changed. - private void AddTagsToChat(SeString message, out bool isMessageChanged) + private void AddTagsToChat(SeString message) { - isMessageChanged = false; - var stringMatches = GetStringMatches(message); foreach (var stringMatch in stringMatches) { Dictionary> stringChanges = new Dictionary>(); - // The role tag payloads - if (stringMatch.GameObject is Character character) + if (stringMatch.GameObject is PlayerCharacter playerCharacter) { // Add the job tag - if (m_PluginData.JobTags.TryGetValue(character.ClassJob.GameData.Abbreviation, out var jobTag)) + if (m_PluginData.JobTags.TryGetValue(playerCharacter.ClassJob.GameData.Abbreviation, out var jobTag)) { if (jobTag.TagPositionInChat.InheritedValue != null) { @@ -205,26 +182,25 @@ namespace PlayerTags.Features } } } - } - // Add the custom tag payloads - foreach (var customTag in m_PluginData.CustomTags) - { - if (customTag.TagPositionInChat.InheritedValue != null) + // Add the custom tag payloads + foreach (var customTag in m_PluginData.CustomTags) { - if (customTag.IncludesGameObjectNameToApplyTo(stringMatch.GetMatchText())) + if (customTag.TagPositionInChat.InheritedValue != null) { - var customTagPayloads = GetPayloads(stringMatch.GameObject, customTag); - if (customTagPayloads.Any()) + if (customTag.IncludesGameObjectNameToApplyTo(stringMatch.GetMatchText())) { - AddPayloadChanges(customTag.TagPositionInChat.InheritedValue.Value, customTagPayloads, stringChanges); + var customTagPayloads = GetPayloads(stringMatch.GameObject, customTag); + if (customTagPayloads.Any()) + { + AddPayloadChanges(customTag.TagPositionInChat.InheritedValue.Value, customTagPayloads, stringChanges); + } } } } } ApplyStringChanges(message, stringChanges, stringMatch.TextPayload); - isMessageChanged = true; } } }