diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs index 9d6a352ca..407a1b0da 100644 --- a/Dalamud/Data/DataManager.cs +++ b/Dalamud/Data/DataManager.cs @@ -8,6 +8,7 @@ using System.Threading; using Dalamud.Interface.Internal; using Dalamud.IoC; using Dalamud.IoC.Internal; +using Dalamud.Plugin.Services; using Dalamud.Utility; using Dalamud.Utility.Timing; using ImGuiScene; @@ -27,7 +28,10 @@ namespace Dalamud.Data; [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.BlockingEarlyLoadedService] -public sealed class DataManager : IDisposable, IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +public sealed class DataManager : IDisposable, IServiceType, IDataManager { private const string IconFileFormat = "ui/icon/{0:D3}000/{1}{2:D6}.tex"; private const string HighResolutionIconFileFormat = "ui/icon/{0:D3}000/{1}{2:D6}_hr1.tex"; @@ -127,75 +131,43 @@ public sealed class DataManager : IDisposable, IServiceType } } - /// - /// Gets the current game client language. - /// + /// public ClientLanguage Language { get; private set; } - /// - /// Gets the OpCodes sent by the server to the client. - /// + /// public ReadOnlyDictionary ServerOpCodes { get; private set; } - /// - /// Gets the OpCodes sent by the client to the server. - /// + /// [UsedImplicitly] public ReadOnlyDictionary ClientOpCodes { get; private set; } - /// - /// Gets a object which gives access to any excel/game data. - /// + /// public GameData GameData { get; private set; } - /// - /// Gets an object which gives access to any of the game's sheet data. - /// + /// public ExcelModule Excel => this.GameData.Excel; - /// - /// Gets a value indicating whether Game Data is ready to be read. - /// + /// public bool IsDataReady { get; private set; } - /// - /// Gets a value indicating whether the game data files have been modified by another third-party tool. - /// + /// public bool HasModifiedGameDataFiles { get; private set; } #region Lumina Wrappers - /// - /// Get an with the given Excel sheet row type. - /// - /// The excel sheet type to get. - /// The , giving access to game rows. + /// public ExcelSheet? GetExcelSheet() where T : ExcelRow => this.Excel.GetSheet(); - /// - /// Get an with the given Excel sheet row type with a specified language. - /// - /// Language of the sheet to get. - /// The excel sheet type to get. - /// The , giving access to game rows. + /// public ExcelSheet? GetExcelSheet(ClientLanguage language) where T : ExcelRow => this.Excel.GetSheet(language.ToLumina()); - /// - /// Get a with the given path. - /// - /// The path inside of the game files. - /// The of the file. + /// public FileResource? GetFile(string path) => this.GetFile(path); - /// - /// Get a with the given path, of the given type. - /// - /// The type of resource. - /// The path inside of the game files. - /// The of the file. + /// public T? GetFile(string path) where T : FileResource { var filePath = GameData.ParseFilePath(path); @@ -204,11 +176,7 @@ public sealed class DataManager : IDisposable, IServiceType return this.GameData.Repositories.TryGetValue(filePath.Repository, out var repository) ? repository.GetFile(filePath.Category, filePath) : default; } - /// - /// Check if the file with the given path exists within the game's index files. - /// - /// The path inside of the game files. - /// True if the file exists. + /// public bool FileExists(string path) => this.GameData.FileExists(path); @@ -217,25 +185,15 @@ public sealed class DataManager : IDisposable, IServiceType /// /// The icon ID. /// The containing the icon. - /// todo: remove in api9 in favor of GetIcon(uint iconId, bool highResolution) + /// TODO(v9): remove in api9 in favor of GetIcon(uint iconId, bool highResolution) public TexFile? GetIcon(uint iconId) => this.GetIcon(this.Language, iconId, false); - /// - /// Get a containing the icon with the given ID. - /// - /// The icon ID. - /// Return high resolution version. - /// The containing the icon. + /// public TexFile? GetIcon(uint iconId, bool highResolution) => this.GetIcon(this.Language, iconId, highResolution); - - /// - /// Get a containing the icon with the given ID, of the given quality. - /// - /// A value indicating whether the icon should be HQ. - /// The icon ID. - /// The containing the icon. + + /// public TexFile? GetIcon(bool isHq, uint iconId) { var type = isHq ? "hq/" : string.Empty; @@ -248,17 +206,11 @@ public sealed class DataManager : IDisposable, IServiceType /// The requested language. /// The icon ID. /// The containing the icon. - /// todo: remove in api9 in favor of GetIcon(ClientLanguage iconLanguage, uint iconId, bool highResolution) + /// TODO(v9): remove in api9 in favor of GetIcon(ClientLanguage iconLanguage, uint iconId, bool highResolution) public TexFile? GetIcon(ClientLanguage iconLanguage, uint iconId) => this.GetIcon(iconLanguage, iconId, false); - /// - /// Get a containing the icon with the given ID, of the given language. - /// - /// The requested language. - /// The icon ID. - /// Return high resolution version. - /// The containing the icon. + /// public TexFile? GetIcon(ClientLanguage iconLanguage, uint iconId, bool highResolution) { var type = iconLanguage switch @@ -279,17 +231,11 @@ public sealed class DataManager : IDisposable, IServiceType /// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon). /// The icon ID. /// The containing the icon. - /// todo: remove in api9 in favor of GetIcon(string? type, uint iconId, bool highResolution) + /// TODO(v9): remove in api9 in favor of GetIcon(string? type, uint iconId, bool highResolution) public TexFile? GetIcon(string? type, uint iconId) => this.GetIcon(type, iconId, false); - /// - /// Get a containing the icon with the given ID, of the given type. - /// - /// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon). - /// The icon ID. - /// Return high resolution version. - /// The containing the icon. + /// public TexFile? GetIcon(string? type, uint iconId, bool highResolution) { var format = highResolution ? HighResolutionIconFileFormat : IconFileFormat; @@ -310,27 +256,15 @@ public sealed class DataManager : IDisposable, IServiceType return file; } - /// - /// Get a containing the HQ icon with the given ID. - /// - /// The icon ID. - /// The containing the icon. + /// public TexFile? GetHqIcon(uint iconId) => this.GetIcon(true, iconId); - /// - /// Get the passed as a drawable ImGui TextureWrap. - /// - /// The Lumina . - /// A that can be used to draw the texture. + /// public TextureWrap? GetImGuiTexture(TexFile? tex) => tex == null ? null : Service.Get().LoadImageRaw(tex.GetRgbaImageData(), tex.Header.Width, tex.Header.Height, 4); - /// - /// Get the passed texture path as a drawable ImGui TextureWrap. - /// - /// The internal path to the texture. - /// A that can be used to draw the texture. + /// public TextureWrap? GetImGuiTexture(string path) => this.GetImGuiTexture(this.GetFile(path)); @@ -339,59 +273,33 @@ public sealed class DataManager : IDisposable, IServiceType /// /// The icon ID. /// The containing the icon. - /// todo: remove in api9 in favor of GetImGuiTextureIcon(uint iconId, bool highResolution) + /// TODO(v9): remove in api9 in favor of GetImGuiTextureIcon(uint iconId, bool highResolution) public TextureWrap? GetImGuiTextureIcon(uint iconId) => this.GetImGuiTexture(this.GetIcon(iconId, false)); - /// - /// Get a containing the icon with the given ID. - /// - /// The icon ID. - /// Return the high resolution version. - /// The containing the icon. + /// public TextureWrap? GetImGuiTextureIcon(uint iconId, bool highResolution) => this.GetImGuiTexture(this.GetIcon(iconId, highResolution)); - /// - /// Get a containing the icon with the given ID, of the given quality. - /// - /// A value indicating whether the icon should be HQ. - /// The icon ID. - /// The containing the icon. + /// public TextureWrap? GetImGuiTextureIcon(bool isHq, uint iconId) => this.GetImGuiTexture(this.GetIcon(isHq, iconId)); - /// - /// Get a containing the icon with the given ID, of the given language. - /// - /// The requested language. - /// The icon ID. - /// The containing the icon. + /// public TextureWrap? GetImGuiTextureIcon(ClientLanguage iconLanguage, uint iconId) => this.GetImGuiTexture(this.GetIcon(iconLanguage, iconId)); - /// - /// Get a containing the icon with the given ID, of the given type. - /// - /// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon). - /// The icon ID. - /// The containing the icon. + /// public TextureWrap? GetImGuiTextureIcon(string type, uint iconId) => this.GetImGuiTexture(this.GetIcon(type, iconId)); - /// - /// Get a containing the HQ icon with the given ID. - /// - /// The icon ID. - /// The containing the icon. + /// public TextureWrap? GetImGuiTextureHqIcon(uint iconId) => this.GetImGuiTexture(this.GetHqIcon(iconId)); #endregion - /// - /// Dispose this DataManager. - /// + /// void IDisposable.Dispose() { this.luminaCancellationTokenSource.Cancel(); diff --git a/Dalamud/Plugin/Services/IDataManager.cs b/Dalamud/Plugin/Services/IDataManager.cs new file mode 100644 index 000000000..69a3e9a21 --- /dev/null +++ b/Dalamud/Plugin/Services/IDataManager.cs @@ -0,0 +1,180 @@ +using System.Collections.ObjectModel; +using ImGuiScene; +using Lumina; +using Lumina.Data; +using Lumina.Data.Files; +using Lumina.Excel; + +namespace Dalamud.Plugin.Services; + +/// +/// This class provides data for Dalamud-internal features, but can also be used by plugins if needed. +/// +public interface IDataManager +{ + /// + /// Gets the current game client language. + /// + public ClientLanguage Language { get; } + + /// + /// Gets the OpCodes sent by the server to the client. + /// + public ReadOnlyDictionary ServerOpCodes { get; } + + /// + /// Gets the OpCodes sent by the client to the server. + /// + public ReadOnlyDictionary ClientOpCodes { get; } + + /// + /// Gets a object which gives access to any excel/game data. + /// + public GameData GameData { get; } + + /// + /// Gets an object which gives access to any of the game's sheet data. + /// + public ExcelModule Excel { get; } + + /// + /// Gets a value indicating whether Game Data is ready to be read. + /// + public bool IsDataReady { get; } + + /// + /// Gets a value indicating whether the game data files have been modified by another third-party tool. + /// + public bool HasModifiedGameDataFiles { get; } + + /// + /// Get an with the given Excel sheet row type. + /// + /// The excel sheet type to get. + /// The , giving access to game rows. + public ExcelSheet? GetExcelSheet() where T : ExcelRow; + + /// + /// Get an with the given Excel sheet row type with a specified language. + /// + /// Language of the sheet to get. + /// The excel sheet type to get. + /// The , giving access to game rows. + public ExcelSheet? GetExcelSheet(ClientLanguage language) where T : ExcelRow; + + /// + /// Get a with the given path. + /// + /// The path inside of the game files. + /// The of the file. + public FileResource? GetFile(string path); + + /// + /// Get a with the given path, of the given type. + /// + /// The type of resource. + /// The path inside of the game files. + /// The of the file. + public T? GetFile(string path) where T : FileResource; + + /// + /// Check if the file with the given path exists within the game's index files. + /// + /// The path inside of the game files. + /// True if the file exists. + public bool FileExists(string path); + + /// + /// Get a containing the icon with the given ID. + /// + /// The icon ID. + /// Return high resolution version. + /// The containing the icon. + public TexFile? GetIcon(uint iconId, bool highResolution = false); + + /// + /// Get a containing the icon with the given ID, of the given language. + /// + /// The requested language. + /// The icon ID. + /// Return high resolution version. + /// The containing the icon. + public TexFile? GetIcon(ClientLanguage iconLanguage, uint iconId, bool highResolution = false); + + /// + /// Get a containing the icon with the given ID, of the given type. + /// + /// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon). + /// The icon ID. + /// Return high resolution version. + /// The containing the icon. + public TexFile? GetIcon(string? type, uint iconId, bool highResolution = false); + + /// + /// Get a containing the icon with the given ID. + /// + /// The icon ID. + /// Return the high resolution version. + /// The containing the icon. + public TextureWrap? GetImGuiTextureIcon(uint iconId, bool highResolution = false); + + /// + /// Get a containing the icon with the given ID, of the given quality. + /// + /// A value indicating whether the icon should be HQ. + /// The icon ID. + /// The containing the icon. + public TexFile? GetIcon(bool isHq, uint iconId); + + /// + /// Get a containing the HQ icon with the given ID. + /// + /// The icon ID. + /// The containing the icon. + public TexFile? GetHqIcon(uint iconId); + + /// + /// Get the passed as a drawable ImGui TextureWrap. + /// + /// The Lumina . + /// A that can be used to draw the texture. + public TextureWrap? GetImGuiTexture(TexFile? tex); + + /// + /// Get the passed texture path as a drawable ImGui TextureWrap. + /// + /// The internal path to the texture. + /// A that can be used to draw the texture. + public TextureWrap? GetImGuiTexture(string path); + + /// + /// Get a containing the icon with the given ID, of the given quality. + /// + /// A value indicating whether the icon should be HQ. + /// The icon ID. + /// The containing the icon. + public TextureWrap? GetImGuiTextureIcon(bool isHq, uint iconId); + + /// + /// Get a containing the icon with the given ID, of the given language. + /// + /// The requested language. + /// The icon ID. + /// The containing the icon. + public TextureWrap? GetImGuiTextureIcon(ClientLanguage iconLanguage, uint iconId); + + /// + /// Get a containing the icon with the given ID, of the given type. + /// + /// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon). + /// The icon ID. + /// The containing the icon. + public TextureWrap? GetImGuiTextureIcon(string type, uint iconId); + + /// + /// Get a containing the HQ icon with the given ID. + /// + /// The icon ID. + /// The containing the icon. + public TextureWrap? GetImGuiTextureHqIcon(uint iconId); +}