Another small step towards better identities
- Can no longer type game object names to apply to in the editor. Tags must be added through quick tag or context menu.
This commit is contained in:
@@ -131,11 +131,11 @@ namespace PlayerTags.Configuration
|
||||
|
||||
if (PluginServices.ClientState.LocalPlayer != null)
|
||||
{
|
||||
Dictionary<string, PlayerInfo> playerNameContexts = PluginServices.ObjectTable
|
||||
Dictionary<Identity, PlayerInfo> playerNameContexts = PluginServices.ObjectTable
|
||||
.Where(gameObject => gameObject is PlayerCharacter)
|
||||
.Select(gameObject => gameObject as PlayerCharacter)
|
||||
.ToDictionary(
|
||||
playerCharacter => playerCharacter!.Name.TextValue,
|
||||
playerCharacter => Identity.From(playerCharacter!),
|
||||
playerCharacter => new PlayerInfo()
|
||||
{
|
||||
PlayerContext = PlayerContextHelper.GetPlayerContext(playerCharacter!),
|
||||
@@ -145,9 +145,11 @@ namespace PlayerTags.Configuration
|
||||
// Include party members that aren't in the game object list
|
||||
foreach (var partyMember in PluginServices.PartyList)
|
||||
{
|
||||
if (!playerNameContexts.ContainsKey(partyMember.Name.TextValue))
|
||||
var partyMemberIdentity = Identity.From(partyMember);
|
||||
|
||||
if (!playerNameContexts.ContainsKey(partyMemberIdentity))
|
||||
{
|
||||
playerNameContexts[partyMember.Name.TextValue] = new PlayerInfo()
|
||||
playerNameContexts[partyMemberIdentity] = new PlayerInfo()
|
||||
{
|
||||
PlayerContext = PlayerContext.Party,
|
||||
Proximity = int.MaxValue
|
||||
@@ -172,7 +174,7 @@ namespace PlayerTags.Configuration
|
||||
int rowIndex = 0;
|
||||
foreach (var player in orderedPlayerNameContexts)
|
||||
{
|
||||
DrawQuickAddRow(new Identity(player.Key), rowIndex);
|
||||
DrawQuickAddRow(player.Key, rowIndex);
|
||||
++rowIndex;
|
||||
}
|
||||
}
|
||||
@@ -201,7 +203,7 @@ namespace PlayerTags.Configuration
|
||||
ImGui.TableHeadersRow();
|
||||
|
||||
int rowIndex = 0;
|
||||
foreach (var identity in m_PluginData.CustomTags.SelectMany(customTag => customTag.IdentitiesToAddTo).Distinct().OrderBy(name => name).ToArray())
|
||||
foreach (var identity in m_PluginData.CustomTags.SelectMany(customTag => customTag.IdentitiesToAddTo).Distinct().OrderBy(name => name))
|
||||
{
|
||||
DrawQuickAddRow(identity, rowIndex);
|
||||
++rowIndex;
|
||||
@@ -209,7 +211,7 @@ namespace PlayerTags.Configuration
|
||||
|
||||
if (PluginServices.ObjectTable.Length == 0 && PluginServices.ClientState.LocalPlayer != null)
|
||||
{
|
||||
DrawQuickAddRow(new Identity(PluginServices.ClientState.LocalPlayer.Name.TextValue), 0);
|
||||
DrawQuickAddRow(Identity.From(PluginServices.ClientState.LocalPlayer), 0);
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
@@ -245,7 +247,7 @@ namespace PlayerTags.Configuration
|
||||
ImGui.TableNextColumn();
|
||||
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.Text(identity.Name);
|
||||
ImGui.Text(identity.ToString());
|
||||
|
||||
foreach (Tag customTag in m_PluginData.CustomTags)
|
||||
{
|
||||
|
||||
@@ -1,37 +1,83 @@
|
||||
using System;
|
||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||
using Dalamud.Game.ClientState.Party;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PlayerTags.Data
|
||||
{
|
||||
// FirstName LastName
|
||||
// FirstName LastName@World
|
||||
// FirstName LastName:Id
|
||||
// FirstName LastName@World:Id
|
||||
public struct Identity : IComparable<Identity>, IEquatable<Identity>
|
||||
{
|
||||
public string Name;
|
||||
public string? World;
|
||||
public string? Id;
|
||||
|
||||
public Identity(string name)
|
||||
{
|
||||
Name = name;
|
||||
World = null;
|
||||
Id = null;
|
||||
}
|
||||
|
||||
public Identity(string name, string id)
|
||||
private static Regex s_WorldRegex = new Regex(@"@([a-zA-Z0-9]+)");
|
||||
private static Regex s_IdRegex = new Regex(@"@([a-zA-Z0-9]+)");
|
||||
|
||||
public static Identity From(string str)
|
||||
{
|
||||
Name = name;
|
||||
Id = id;
|
||||
var identity = new Identity();
|
||||
|
||||
while (s_WorldRegex.Match(str) is Match match && match.Success)
|
||||
{
|
||||
identity.World = match.Groups.Values.Last().Value;
|
||||
str = str.Replace(match.Value, "");
|
||||
}
|
||||
|
||||
while (s_IdRegex.Match(str) is Match match && match.Success)
|
||||
{
|
||||
identity.Id = match.Groups.Values.Last().Value;
|
||||
str = str.Replace(match.Value, "");
|
||||
}
|
||||
|
||||
identity.Name = str;
|
||||
|
||||
return identity;
|
||||
}
|
||||
|
||||
public static Identity From(PlayerCharacter playerCharacter)
|
||||
{
|
||||
return new Identity(playerCharacter.Name.TextValue)
|
||||
{
|
||||
World = playerCharacter.HomeWorld.GameData.Name.RawString
|
||||
};
|
||||
}
|
||||
|
||||
public static Identity From(PartyMember partyMember)
|
||||
{
|
||||
return new Identity(partyMember.Name.TextValue)
|
||||
{
|
||||
World = partyMember.World.GameData.Name.RawString
|
||||
};
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string str = Name;
|
||||
|
||||
if (World != null)
|
||||
{
|
||||
str += $"@{World}";
|
||||
}
|
||||
|
||||
if (Id != null)
|
||||
{
|
||||
Name += $":{Id}";
|
||||
str += $":{Id}";
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
|
||||
@@ -91,7 +91,6 @@ namespace PlayerTags.Data
|
||||
Behavior = InheritableBehavior.Enabled
|
||||
};
|
||||
|
||||
[InheritableCategory("GeneralCategory")]
|
||||
public InheritableReference<string> GameObjectNamesToApplyTo = new InheritableReference<string>("");
|
||||
|
||||
[InheritableCategory("IconCategory")]
|
||||
@@ -162,26 +161,11 @@ namespace PlayerTags.Data
|
||||
}
|
||||
}
|
||||
|
||||
private Identity GetIdentity(string identityData)
|
||||
{
|
||||
var identity = new Identity();
|
||||
|
||||
var IdParts = identityData.Split(':');
|
||||
if (IdParts.Length > 1)
|
||||
{
|
||||
identity.Id = IdParts[1];
|
||||
}
|
||||
|
||||
identity.Name = IdParts[0];
|
||||
|
||||
return identity;
|
||||
}
|
||||
|
||||
public Identity[] IdentitiesToAddTo
|
||||
{
|
||||
get
|
||||
{
|
||||
return IdentityDatasToAddTo.Select(identityData => GetIdentity(identityData)).ToArray();
|
||||
return IdentityDatasToAddTo.Select(identityData => Identity.From(identityData)).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace PlayerTags.Features
|
||||
{
|
||||
public class CustomTagsContextMenuFeature : IDisposable
|
||||
{
|
||||
private string?[] CustomTagsSupportedAddonNames = new string?[]
|
||||
private string?[] SupportedAddonNames = new string?[]
|
||||
{
|
||||
null,
|
||||
"_PartyList",
|
||||
@@ -107,7 +107,7 @@ namespace PlayerTags.Features
|
||||
return false;
|
||||
}
|
||||
|
||||
return CustomTagsSupportedAddonNames.Contains(args.ParentAddonName);
|
||||
return SupportedAddonNames.Contains(args.ParentAddonName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user