mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-13 12:14:17 +01:00
Update to current state of ActorIdentification, add start of collection management.
This commit is contained in:
parent
cbc27d31da
commit
0b1a11132b
3 changed files with 85 additions and 67 deletions
|
|
@ -6,14 +6,14 @@ using Dalamud;
|
||||||
using Dalamud.Data;
|
using Dalamud.Data;
|
||||||
using Dalamud.Game.ClientState;
|
using Dalamud.Game.ClientState;
|
||||||
using Dalamud.Game.ClientState.Objects;
|
using Dalamud.Game.ClientState.Objects;
|
||||||
using Dalamud.Logging;
|
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
using Lumina.Excel.GeneratedSheets;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
|
using Penumbra.GameData.Data;
|
||||||
|
|
||||||
namespace Penumbra.GameData.Actors;
|
namespace Penumbra.GameData.Actors;
|
||||||
|
|
||||||
public partial class ActorManager : IDisposable
|
public sealed partial class ActorManager : DataSharer
|
||||||
{
|
{
|
||||||
/// <summary> Worlds available for players. </summary>
|
/// <summary> Worlds available for players. </summary>
|
||||||
public IReadOnlyDictionary<ushort, string> Worlds { get; }
|
public IReadOnlyDictionary<ushort, string> Worlds { get; }
|
||||||
|
|
@ -30,95 +30,67 @@ public partial class ActorManager : IDisposable
|
||||||
/// <summary> Valid ENPC names in title case by ENPC id. </summary>
|
/// <summary> Valid ENPC names in title case by ENPC id. </summary>
|
||||||
public IReadOnlyDictionary<uint, string> ENpcs { get; }
|
public IReadOnlyDictionary<uint, string> ENpcs { get; }
|
||||||
|
|
||||||
public ActorManager(DalamudPluginInterface pluginInterface, ObjectTable objects, ClientState state, DataManager gameData, Func<ushort, short> toParentIdx)
|
public ActorManager(DalamudPluginInterface pluginInterface, ObjectTable objects, ClientState state, DataManager gameData,
|
||||||
|
Func<ushort, short> toParentIdx)
|
||||||
: this(pluginInterface, objects, state, gameData, gameData.Language, toParentIdx)
|
: this(pluginInterface, objects, state, gameData, gameData.Language, toParentIdx)
|
||||||
{}
|
{ }
|
||||||
|
|
||||||
public ActorManager(DalamudPluginInterface pluginInterface, ObjectTable objects, ClientState state, DataManager gameData,
|
public ActorManager(DalamudPluginInterface pluginInterface, ObjectTable objects, ClientState state, DataManager gameData,
|
||||||
ClientLanguage language, Func<ushort, short> toParentIdx)
|
ClientLanguage language, Func<ushort, short> toParentIdx)
|
||||||
|
: base(pluginInterface, language, 1)
|
||||||
{
|
{
|
||||||
_pluginInterface = pluginInterface;
|
_objects = objects;
|
||||||
_objects = objects;
|
_clientState = state;
|
||||||
_clientState = state;
|
_toParentIdx = toParentIdx;
|
||||||
_gameData = gameData;
|
|
||||||
_language = language;
|
|
||||||
_toParentIdx = toParentIdx;
|
|
||||||
|
|
||||||
Worlds = TryCatchData("Worlds", CreateWorldData);
|
Worlds = TryCatchData("Worlds", () => CreateWorldData(gameData));
|
||||||
Mounts = TryCatchData("Mounts", CreateMountData);
|
Mounts = TryCatchData("Mounts", () => CreateMountData(gameData));
|
||||||
Companions = TryCatchData("Companions", CreateCompanionData);
|
Companions = TryCatchData("Companions", () => CreateCompanionData(gameData));
|
||||||
BNpcs = TryCatchData("BNpcs", CreateBNpcData);
|
BNpcs = TryCatchData("BNpcs", () => CreateBNpcData(gameData));
|
||||||
ENpcs = TryCatchData("ENpcs", CreateENpcData);
|
ENpcs = TryCatchData("ENpcs", () => CreateENpcData(gameData));
|
||||||
|
|
||||||
ActorIdentifier.Manager = this;
|
ActorIdentifier.Manager = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
protected override void DisposeInternal()
|
||||||
{
|
{
|
||||||
if (_disposed)
|
DisposeTag("Worlds");
|
||||||
return;
|
DisposeTag("Mounts");
|
||||||
|
DisposeTag("Companions");
|
||||||
GC.SuppressFinalize(this);
|
DisposeTag("BNpcs");
|
||||||
_pluginInterface.RelinquishData(GetVersionedTag("Worlds"));
|
DisposeTag("ENpcs");
|
||||||
_pluginInterface.RelinquishData(GetVersionedTag("Mounts"));
|
|
||||||
_pluginInterface.RelinquishData(GetVersionedTag("Companions"));
|
|
||||||
_pluginInterface.RelinquishData(GetVersionedTag("BNpcs"));
|
|
||||||
_pluginInterface.RelinquishData(GetVersionedTag("ENpcs"));
|
|
||||||
_disposed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~ActorManager()
|
~ActorManager()
|
||||||
=> Dispose();
|
=> Dispose();
|
||||||
|
|
||||||
private const int Version = 1;
|
private readonly ObjectTable _objects;
|
||||||
|
private readonly ClientState _clientState;
|
||||||
private readonly DalamudPluginInterface _pluginInterface;
|
|
||||||
private readonly ObjectTable _objects;
|
|
||||||
private readonly ClientState _clientState;
|
|
||||||
private readonly DataManager _gameData;
|
|
||||||
private readonly ClientLanguage _language;
|
|
||||||
private bool _disposed;
|
|
||||||
|
|
||||||
private readonly Func<ushort, short> _toParentIdx;
|
private readonly Func<ushort, short> _toParentIdx;
|
||||||
|
|
||||||
private IReadOnlyDictionary<ushort, string> CreateWorldData()
|
private IReadOnlyDictionary<ushort, string> CreateWorldData(DataManager gameData)
|
||||||
=> _gameData.GetExcelSheet<World>(_language)!
|
=> gameData.GetExcelSheet<World>(Language)!
|
||||||
.Where(w => w.IsPublic && !w.Name.RawData.IsEmpty)
|
.Where(w => w.IsPublic && !w.Name.RawData.IsEmpty)
|
||||||
.ToDictionary(w => (ushort)w.RowId, w => w.Name.ToString());
|
.ToDictionary(w => (ushort)w.RowId, w => w.Name.ToString());
|
||||||
|
|
||||||
private IReadOnlyDictionary<uint, string> CreateMountData()
|
private IReadOnlyDictionary<uint, string> CreateMountData(DataManager gameData)
|
||||||
=> _gameData.GetExcelSheet<Mount>(_language)!
|
=> gameData.GetExcelSheet<Mount>(Language)!
|
||||||
.Where(m => m.Singular.RawData.Length > 0 && m.Order >= 0)
|
.Where(m => m.Singular.RawData.Length > 0 && m.Order >= 0)
|
||||||
.ToDictionary(m => m.RowId, m => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(m.Singular.ToDalamudString().ToString()));
|
.ToDictionary(m => m.RowId, m => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(m.Singular.ToDalamudString().ToString()));
|
||||||
|
|
||||||
private IReadOnlyDictionary<uint, string> CreateCompanionData()
|
private IReadOnlyDictionary<uint, string> CreateCompanionData(DataManager gameData)
|
||||||
=> _gameData.GetExcelSheet<Companion>(_language)!
|
=> gameData.GetExcelSheet<Companion>(Language)!
|
||||||
.Where(c => c.Singular.RawData.Length > 0 && c.Order < ushort.MaxValue)
|
.Where(c => c.Singular.RawData.Length > 0 && c.Order < ushort.MaxValue)
|
||||||
.ToDictionary(c => c.RowId, c => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(c.Singular.ToDalamudString().ToString()));
|
.ToDictionary(c => c.RowId, c => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(c.Singular.ToDalamudString().ToString()));
|
||||||
|
|
||||||
private IReadOnlyDictionary<uint, string> CreateBNpcData()
|
private IReadOnlyDictionary<uint, string> CreateBNpcData(DataManager gameData)
|
||||||
=> _gameData.GetExcelSheet<BNpcName>(_language)!
|
=> gameData.GetExcelSheet<BNpcName>(Language)!
|
||||||
.Where(n => n.Singular.RawData.Length > 0)
|
.Where(n => n.Singular.RawData.Length > 0)
|
||||||
.ToDictionary(n => n.RowId, n => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(n.Singular.ToDalamudString().ToString()));
|
.ToDictionary(n => n.RowId, n => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(n.Singular.ToDalamudString().ToString()));
|
||||||
|
|
||||||
private IReadOnlyDictionary<uint, string> CreateENpcData()
|
private IReadOnlyDictionary<uint, string> CreateENpcData(DataManager gameData)
|
||||||
=> _gameData.GetExcelSheet<ENpcResident>(_language)!
|
=> gameData.GetExcelSheet<ENpcResident>(Language)!
|
||||||
.Where(e => e.Singular.RawData.Length > 0)
|
.Where(e => e.Singular.RawData.Length > 0)
|
||||||
.ToDictionary(e => e.RowId, e => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(e.Singular.ToDalamudString().ToString()));
|
.ToDictionary(e => e.RowId, e => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(e.Singular.ToDalamudString().ToString()));
|
||||||
|
|
||||||
private string GetVersionedTag(string tag)
|
|
||||||
=> $"Penumbra.Actors.{tag}.{_language}.V{Version}";
|
|
||||||
|
|
||||||
private T TryCatchData<T>(string tag, Func<T> func) where T : class
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return _pluginInterface.GetOrCreateData(GetVersionedTag(tag), func);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
PluginLog.Error($"Error creating shared actor data for {tag}:\n{ex}");
|
|
||||||
return func();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using Dalamud.Game.ClientState.Objects.Enums;
|
using Dalamud.Game.ClientState.Objects.Enums;
|
||||||
using Dalamud.Game.ClientState.Objects.Types;
|
using Dalamud.Game.ClientState.Objects.Types;
|
||||||
using Lumina.Excel.GeneratedSheets;
|
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Penumbra.String;
|
using Penumbra.String;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,64 @@ namespace Penumbra.Collections;
|
||||||
public class IndividualCollections
|
public class IndividualCollections
|
||||||
{
|
{
|
||||||
private readonly ActorManager _manager;
|
private readonly ActorManager _manager;
|
||||||
public readonly List< (string DisplayName, ModCollection Collection, IReadOnlyList< ActorIdentifier > Identifiers) > Assignments;
|
private readonly List< (string DisplayName, ModCollection Collection, IReadOnlyList< ActorIdentifier > Identifiers) > _assignments = new();
|
||||||
public readonly Dictionary< ActorIdentifier, ModCollection > Individuals;
|
private readonly Dictionary< ActorIdentifier, ModCollection > _individuals = new();
|
||||||
|
|
||||||
|
public IReadOnlyList< (string DisplayName, ModCollection Collection, IReadOnlyList< ActorIdentifier > Identifiers) > Assignments
|
||||||
|
=> _assignments;
|
||||||
|
|
||||||
|
public IReadOnlyDictionary< ActorIdentifier, ModCollection > Individuals
|
||||||
|
=> _individuals;
|
||||||
|
|
||||||
public IndividualCollections( ActorManager manager )
|
public IndividualCollections( ActorManager manager )
|
||||||
=> _manager = manager;
|
=> _manager = manager;
|
||||||
|
|
||||||
public bool CanAdd( IdentifierType type, string name, ushort homeWorld, ObjectKind kind, uint dataId )
|
public bool CanAdd( ActorIdentifier identifier )
|
||||||
|
=> identifier.IsValid && !Individuals.ContainsKey( identifier );
|
||||||
|
|
||||||
|
public bool CanAdd( IdentifierType type, string name, ushort homeWorld, ObjectKind kind, IEnumerable< uint > dataIds, out ActorIdentifier[] identifiers )
|
||||||
{
|
{
|
||||||
return false;
|
identifiers = Array.Empty< ActorIdentifier >();
|
||||||
|
|
||||||
|
switch( type )
|
||||||
|
{
|
||||||
|
case IdentifierType.Player:
|
||||||
|
{
|
||||||
|
if( !ByteString.FromString( name, out var playerName ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var identifier = _manager.CreatePlayer( playerName, homeWorld );
|
||||||
|
if( !CanAdd( identifier ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
identifiers = new[] { identifier };
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//case IdentifierType.Owned:
|
||||||
|
//{
|
||||||
|
// if( !ByteString.FromString( name, out var ownerName ) )
|
||||||
|
// {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// identifiers = dataIds.Select( id => _manager.CreateOwned( ownerName, homeWorld, kind, id ) ).ToArray();
|
||||||
|
// return
|
||||||
|
// identifier = _manager.CreateIndividual( type, byteName, homeWorld, kind, dataId );
|
||||||
|
// return CanAdd( identifier );
|
||||||
|
//}
|
||||||
|
//case IdentifierType.Npc:
|
||||||
|
//{
|
||||||
|
// identifier = _manager.CreateIndividual( IdentifierType.Npc, ByteString.Empty, ushort.MaxValue, kind, dataId );
|
||||||
|
// return CanAdd( identifier );
|
||||||
|
//}
|
||||||
|
default:
|
||||||
|
identifiers = Array.Empty< ActorIdentifier >();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Add( string displayName, ActorIdentifier identifier, ModCollection collection )
|
public bool Add( string displayName, ActorIdentifier identifier, ModCollection collection )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue