More id fixes
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||
using Dalamud.Game.ClientState.Party;
|
||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -13,26 +15,52 @@ namespace PlayerTags.Data
|
||||
public struct Identity : IComparable<Identity>, IEquatable<Identity>
|
||||
{
|
||||
public string Name;
|
||||
public string? World;
|
||||
public uint? WorldId;
|
||||
public string? Id;
|
||||
|
||||
public Identity(string name)
|
||||
public string? World
|
||||
{
|
||||
Name = name;
|
||||
World = null;
|
||||
Id = null;
|
||||
get
|
||||
{
|
||||
var worldId = WorldId;
|
||||
if (worldId != null)
|
||||
{
|
||||
var worlds = PluginServices.DataManager.GetExcelSheet<World>();
|
||||
if (worlds != null)
|
||||
{
|
||||
var world = worlds.FirstOrDefault(world => world.RowId == worldId.Value);
|
||||
if (world != null)
|
||||
{
|
||||
return world.Name.RawString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Regex s_WorldRegex = new Regex(@"@([a-zA-Z0-9]+)");
|
||||
private static Regex s_IdRegex = new Regex(@"@([a-zA-Z0-9]+)");
|
||||
|
||||
public Identity(string name)
|
||||
{
|
||||
Name = name;
|
||||
WorldId = null;
|
||||
Id = null;
|
||||
}
|
||||
|
||||
public static Identity From(string str)
|
||||
{
|
||||
var identity = new Identity();
|
||||
|
||||
while (s_WorldRegex.Match(str) is Match match && match.Success)
|
||||
{
|
||||
identity.World = match.Groups.Values.Last().Value;
|
||||
if (uint.TryParse(match.Groups.Values.Last().Value, out var value))
|
||||
{
|
||||
identity.WorldId = value;
|
||||
}
|
||||
|
||||
str = str.Replace(match.Value, "");
|
||||
}
|
||||
|
||||
@@ -51,7 +79,7 @@ namespace PlayerTags.Data
|
||||
{
|
||||
return new Identity(playerCharacter.Name.TextValue)
|
||||
{
|
||||
World = playerCharacter.HomeWorld.GameData.Name.RawString
|
||||
WorldId = playerCharacter.HomeWorld.GameData.RowId
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,17 +87,30 @@ namespace PlayerTags.Data
|
||||
{
|
||||
return new Identity(partyMember.Name.TextValue)
|
||||
{
|
||||
World = partyMember.World.GameData.Name.RawString
|
||||
WorldId = partyMember.World.GameData.RowId
|
||||
};
|
||||
}
|
||||
|
||||
public static Identity From(PlayerPayload playerPayload)
|
||||
{
|
||||
return new Identity(playerPayload.PlayerName)
|
||||
{
|
||||
WorldId = playerPayload.World.RowId
|
||||
};
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public string ToDataString()
|
||||
{
|
||||
string str = Name;
|
||||
|
||||
if (World != null)
|
||||
if (WorldId != null)
|
||||
{
|
||||
str += $"@{World}";
|
||||
str += $"@{WorldId}";
|
||||
}
|
||||
|
||||
if (Id != null)
|
||||
@@ -97,7 +138,12 @@ namespace PlayerTags.Data
|
||||
return first.Id == second.Id;
|
||||
}
|
||||
|
||||
return first.Name.ToLower().Trim() == second.Name.ToLower().Trim();
|
||||
bool areNamesEqual = first.Name.ToLower().Trim() == second.Name.ToLower().Trim();
|
||||
|
||||
// If one of the worlds are null then it's technically equal as it could be promoted to the identity that does have a world
|
||||
bool areWorldsEqual = first.WorldId == null || second.WorldId == null || first.WorldId == second.WorldId;
|
||||
|
||||
return areNamesEqual && areWorldsEqual;
|
||||
}
|
||||
|
||||
public static bool operator !=(Identity first, Identity second)
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace PlayerTags.Data
|
||||
return;
|
||||
}
|
||||
|
||||
GameObjectNamesToApplyTo.Value = string.Join(", ", IdentitiesToAddTo.Append(identity));
|
||||
GameObjectNamesToApplyTo.Value = string.Join(", ", IdentitiesToAddTo.Append(identity).Select(id => id.ToDataString()));
|
||||
}
|
||||
|
||||
public void RemoveIdentityToAddTo(Identity identity)
|
||||
@@ -216,7 +216,7 @@ namespace PlayerTags.Data
|
||||
return;
|
||||
}
|
||||
|
||||
GameObjectNamesToApplyTo.Value = string.Join(", ", IdentitiesToAddTo.Where(identityToAddTo => identityToAddTo != identity));
|
||||
GameObjectNamesToApplyTo.Value = string.Join(", ", IdentitiesToAddTo.Where(identityToAddTo => identityToAddTo != identity).Select(id => id.ToDataString()));
|
||||
}
|
||||
|
||||
public Dictionary<string, InheritableData> GetChanges(Dictionary<string, InheritableData>? defaultChanges = null)
|
||||
|
||||
@@ -210,7 +210,7 @@ namespace PlayerTags.Features
|
||||
// Add all other tags
|
||||
foreach (var customTag in m_PluginData.CustomTags)
|
||||
{
|
||||
if (customTag.CanAddToIdentity(new Identity(stringMatch.PlayerPayload.PlayerName)))
|
||||
if (customTag.CanAddToIdentity(Identity.From(stringMatch.PlayerPayload)))
|
||||
{
|
||||
if (customTag.TagPositionInChat.InheritedValue != null)
|
||||
{
|
||||
@@ -229,13 +229,13 @@ namespace PlayerTags.Features
|
||||
{
|
||||
foreach (var customTag in m_PluginData.CustomTags)
|
||||
{
|
||||
if (customTag.CanAddToIdentity(new Identity(stringMatch.PlayerPayload.PlayerName)))
|
||||
if (customTag.CanAddToIdentity(Identity.From(stringMatch.PlayerPayload)))
|
||||
{
|
||||
if (IsTagVisible(customTag, stringMatch.GameObject))
|
||||
{
|
||||
if (customTag.TextColor.InheritedValue != null)
|
||||
{
|
||||
if (message.Payloads.Any(payload => payload is TextPayload)
|
||||
if (message.Payloads.Any(payload => payload is TextPayload || payload is PlayerPayload)
|
||||
&& customTag.IsTextColorAppliedToChatName.InheritedValue != null
|
||||
&& customTag.IsTextColorAppliedToChatName.InheritedValue.Value)
|
||||
{
|
||||
@@ -256,7 +256,7 @@ namespace PlayerTags.Features
|
||||
{
|
||||
if (jobTag.TextColor.InheritedValue != null)
|
||||
{
|
||||
if (message.Payloads.Any(payload => payload is TextPayload)
|
||||
if (message.Payloads.Any(payload => payload is TextPayload || payload is PlayerPayload)
|
||||
&& jobTag.IsTextColorAppliedToChatName.InheritedValue != null
|
||||
&& jobTag.IsTextColorAppliedToChatName.InheritedValue.Value)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using PlayerTags.Configuration;
|
||||
using Dalamud.Logging;
|
||||
using PlayerTags.Configuration;
|
||||
using PlayerTags.Data;
|
||||
using PlayerTags.Resources;
|
||||
using System;
|
||||
@@ -51,12 +52,13 @@ namespace PlayerTags.Features
|
||||
return;
|
||||
}
|
||||
|
||||
string gameObjectName = args.Text!.TextValue;
|
||||
|
||||
var notAddedTags = m_PluginData.CustomTags.Where(tag => !tag.CanAddToIdentity(new Identity()
|
||||
var identity = new Identity()
|
||||
{
|
||||
Name = gameObjectName
|
||||
}));
|
||||
Name = args.Text!.TextValue,
|
||||
WorldId = args.ObjectWorld
|
||||
};
|
||||
|
||||
var notAddedTags = m_PluginData.CustomTags.Where(tag => !tag.CanAddToIdentity(identity));
|
||||
if (notAddedTags.Any())
|
||||
{
|
||||
args.Items.Add(new NormalContextSubMenuItem(Strings.Loc_Static_ContextMenu_AddTag, (itemArgs =>
|
||||
@@ -65,21 +67,14 @@ namespace PlayerTags.Features
|
||||
{
|
||||
itemArgs.Items.Add(new NormalContextMenuItem(notAddedTag.Text.Value, (args =>
|
||||
{
|
||||
notAddedTag.AddIdentityToAddTo(new Identity()
|
||||
{
|
||||
Name = gameObjectName
|
||||
});
|
||||
|
||||
notAddedTag.AddIdentityToAddTo(identity);
|
||||
m_PluginConfiguration.Save(m_PluginData);
|
||||
})));
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
var addedTags = m_PluginData.CustomTags.Where(tag => tag.CanAddToIdentity(new Identity()
|
||||
{
|
||||
Name = gameObjectName
|
||||
}));
|
||||
var addedTags = m_PluginData.CustomTags.Where(tag => tag.CanAddToIdentity(identity));
|
||||
if (addedTags.Any())
|
||||
{
|
||||
args.Items.Add(new NormalContextSubMenuItem(Strings.Loc_Static_ContextMenu_RemoveTag, (itemArgs =>
|
||||
@@ -88,11 +83,7 @@ namespace PlayerTags.Features
|
||||
{
|
||||
itemArgs.Items.Add(new NormalContextMenuItem(addedTag.Text.Value, (args =>
|
||||
{
|
||||
addedTag.RemoveIdentityToAddTo(new Identity()
|
||||
{
|
||||
Name = gameObjectName
|
||||
});
|
||||
|
||||
addedTag.RemoveIdentityToAddTo(identity);
|
||||
m_PluginConfiguration.Save(m_PluginData);
|
||||
})));
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace PlayerTags.Features
|
||||
// Add all other tags
|
||||
foreach (var customTag in m_PluginData.CustomTags)
|
||||
{
|
||||
if (customTag.CanAddToIdentity(new Identity(gameObject.Name.TextValue)))
|
||||
if (customTag.CanAddToIdentity(Identity.From(playerCharacter)))
|
||||
{
|
||||
if (customTag.TagTargetInNameplates.InheritedValue != null && customTag.TagPositionInNameplates.InheritedValue != null)
|
||||
{
|
||||
@@ -247,48 +247,48 @@ namespace PlayerTags.Features
|
||||
}
|
||||
}
|
||||
|
||||
// An additional step to apply text color to additional locations
|
||||
foreach (var customTag in m_PluginData.CustomTags)
|
||||
if (gameObject is PlayerCharacter playerCharacter1)
|
||||
{
|
||||
if (customTag.CanAddToIdentity(new Identity(gameObject.Name.TextValue)))
|
||||
// An additional step to apply text color to additional locations
|
||||
foreach (var customTag in m_PluginData.CustomTags)
|
||||
{
|
||||
if (IsTagVisible(customTag, gameObject))
|
||||
if (customTag.CanAddToIdentity(Identity.From(playerCharacter1)))
|
||||
{
|
||||
if (customTag.TextColor.InheritedValue != null)
|
||||
if (IsTagVisible(customTag, gameObject))
|
||||
{
|
||||
if (name.Payloads.Any(payload => payload is TextPayload)
|
||||
&& customTag.IsTextColorAppliedToNameplateName.InheritedValue != null
|
||||
&& customTag.IsTextColorAppliedToNameplateName.InheritedValue.Value)
|
||||
if (customTag.TextColor.InheritedValue != null)
|
||||
{
|
||||
name.Payloads.Insert(0, (new UIForegroundPayload(customTag.TextColor.InheritedValue.Value)));
|
||||
name.Payloads.Add(new UIForegroundPayload(0));
|
||||
isNameChanged = true;
|
||||
}
|
||||
if (name.Payloads.Any(payload => payload is TextPayload)
|
||||
&& customTag.IsTextColorAppliedToNameplateName.InheritedValue != null
|
||||
&& customTag.IsTextColorAppliedToNameplateName.InheritedValue.Value)
|
||||
{
|
||||
name.Payloads.Insert(0, (new UIForegroundPayload(customTag.TextColor.InheritedValue.Value)));
|
||||
name.Payloads.Add(new UIForegroundPayload(0));
|
||||
isNameChanged = true;
|
||||
}
|
||||
|
||||
if (title.Payloads.Any(payload => payload is TextPayload)
|
||||
&& customTag.IsTextColorAppliedToNameplateTitle.InheritedValue != null
|
||||
&& customTag.IsTextColorAppliedToNameplateTitle.InheritedValue.Value)
|
||||
{
|
||||
title.Payloads.Insert(0, (new UIForegroundPayload(customTag.TextColor.InheritedValue.Value)));
|
||||
title.Payloads.Add(new UIForegroundPayload(0));
|
||||
isTitleChanged = true;
|
||||
}
|
||||
if (title.Payloads.Any(payload => payload is TextPayload)
|
||||
&& customTag.IsTextColorAppliedToNameplateTitle.InheritedValue != null
|
||||
&& customTag.IsTextColorAppliedToNameplateTitle.InheritedValue.Value)
|
||||
{
|
||||
title.Payloads.Insert(0, (new UIForegroundPayload(customTag.TextColor.InheritedValue.Value)));
|
||||
title.Payloads.Add(new UIForegroundPayload(0));
|
||||
isTitleChanged = true;
|
||||
}
|
||||
|
||||
if (freeCompany.Payloads.Any(payload => payload is TextPayload)
|
||||
&& customTag.IsTextColorAppliedToNameplateFreeCompany.InheritedValue != null
|
||||
&& customTag.IsTextColorAppliedToNameplateFreeCompany.InheritedValue.Value)
|
||||
{
|
||||
freeCompany.Payloads.Insert(0, (new UIForegroundPayload(customTag.TextColor.InheritedValue.Value)));
|
||||
freeCompany.Payloads.Add(new UIForegroundPayload(0));
|
||||
isFreeCompanyChanged = true;
|
||||
if (freeCompany.Payloads.Any(payload => payload is TextPayload)
|
||||
&& customTag.IsTextColorAppliedToNameplateFreeCompany.InheritedValue != null
|
||||
&& customTag.IsTextColorAppliedToNameplateFreeCompany.InheritedValue.Value)
|
||||
{
|
||||
freeCompany.Payloads.Insert(0, (new UIForegroundPayload(customTag.TextColor.InheritedValue.Value)));
|
||||
freeCompany.Payloads.Add(new UIForegroundPayload(0));
|
||||
isFreeCompanyChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gameObject is PlayerCharacter playerCharacter1)
|
||||
{
|
||||
if (m_PluginData.JobTags.TryGetValue(playerCharacter1.ClassJob.GameData.Abbreviation, out var jobTag))
|
||||
{
|
||||
if (IsTagVisible(jobTag, gameObject))
|
||||
@@ -323,7 +323,7 @@ namespace PlayerTags.Features
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user