mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-31 21:03:43 +01:00
Add state fetchers
This commit is contained in:
parent
eb4d9aba7e
commit
5eadfc1b4d
7 changed files with 72 additions and 20 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace Dalamud.Plugin.Services;
|
namespace Dalamud.Interface.Internal;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a lookup for a game icon.
|
/// Represents a lookup for a game icon.
|
||||||
|
|
@ -21,9 +21,6 @@ internal sealed class FileSystemSharableTexture : SharableTexture
|
||||||
this.UnderlyingWrap = this.CreateTextureAsync();
|
this.UnderlyingWrap = this.CreateTextureAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
protected override Task<IDalamudTextureWrap> UnderlyingWrap { get; set; }
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override string ToString() =>
|
public override string ToString() =>
|
||||||
$"{nameof(FileSystemSharableTexture)}#{this.InstanceIdForDebug}({this.path})";
|
$"{nameof(FileSystemSharableTexture)}#{this.InstanceIdForDebug}({this.path})";
|
||||||
|
|
@ -32,10 +29,8 @@ internal sealed class FileSystemSharableTexture : SharableTexture
|
||||||
protected override void FinalRelease()
|
protected override void FinalRelease()
|
||||||
{
|
{
|
||||||
this.DisposeSuppressingWrap = null;
|
this.DisposeSuppressingWrap = null;
|
||||||
_ = this.UnderlyingWrap.ToContentDisposedTask(true);
|
_ = this.UnderlyingWrap?.ToContentDisposedTask(true);
|
||||||
this.UnderlyingWrap =
|
this.UnderlyingWrap = null;
|
||||||
Task.FromException<IDalamudTextureWrap>(new ObjectDisposedException(nameof(GamePathSharableTexture)));
|
|
||||||
_ = this.UnderlyingWrap.Exception;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,6 @@ internal sealed class GamePathSharableTexture : SharableTexture
|
||||||
this.UnderlyingWrap = this.CreateTextureAsync();
|
this.UnderlyingWrap = this.CreateTextureAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
protected override Task<IDalamudTextureWrap> UnderlyingWrap { get; set; }
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override string ToString() => $"{nameof(GamePathSharableTexture)}#{this.InstanceIdForDebug}({this.path})";
|
public override string ToString() => $"{nameof(GamePathSharableTexture)}#{this.InstanceIdForDebug}({this.path})";
|
||||||
|
|
||||||
|
|
@ -35,10 +32,8 @@ internal sealed class GamePathSharableTexture : SharableTexture
|
||||||
protected override void FinalRelease()
|
protected override void FinalRelease()
|
||||||
{
|
{
|
||||||
this.DisposeSuppressingWrap = null;
|
this.DisposeSuppressingWrap = null;
|
||||||
_ = this.UnderlyingWrap.ToContentDisposedTask(true);
|
_ = this.UnderlyingWrap?.ToContentDisposedTask(true);
|
||||||
this.UnderlyingWrap =
|
this.UnderlyingWrap = null;
|
||||||
Task.FromException<IDalamudTextureWrap>(new ObjectDisposedException(nameof(GamePathSharableTexture)));
|
|
||||||
_ = this.UnderlyingWrap.Exception;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ internal abstract class SharableTexture : IRefCountable
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the underlying texture wrap.
|
/// Gets or sets the underlying texture wrap.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract Task<IDalamudTextureWrap> UnderlyingWrap { get; set; }
|
public Task<IDalamudTextureWrap>? UnderlyingWrap { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the dispose-suppressing wrap for <see cref="UnderlyingWrap"/>.
|
/// Gets or sets the dispose-suppressing wrap for <see cref="UnderlyingWrap"/>.
|
||||||
|
|
@ -185,8 +185,18 @@ internal abstract class SharableTexture : IRefCountable
|
||||||
public Task<IDalamudTextureWrap> CreateNewReference()
|
public Task<IDalamudTextureWrap> CreateNewReference()
|
||||||
{
|
{
|
||||||
this.AddRef();
|
this.AddRef();
|
||||||
|
if (this.UnderlyingWrap is null)
|
||||||
|
throw new InvalidOperationException("AddRef returned but UnderlyingWrap is null?");
|
||||||
|
|
||||||
return this.UnderlyingWrap.ContinueWith(
|
return this.UnderlyingWrap.ContinueWith(
|
||||||
r => (IDalamudTextureWrap)new RefCountableWrappingTextureWrap(r.Result, this));
|
r =>
|
||||||
|
{
|
||||||
|
if (r.IsCompletedSuccessfully)
|
||||||
|
return Task.FromResult((IDalamudTextureWrap)new RefCountableWrappingTextureWrap(r.Result, this));
|
||||||
|
|
||||||
|
this.Release();
|
||||||
|
return r;
|
||||||
|
}).Unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -207,9 +217,12 @@ internal abstract class SharableTexture : IRefCountable
|
||||||
if (this.RevivalPossibility?.TryGetTarget(out this.availableOnAccessWrapForApi9) is true)
|
if (this.RevivalPossibility?.TryGetTarget(out this.availableOnAccessWrapForApi9) is true)
|
||||||
return this.availableOnAccessWrapForApi9;
|
return this.availableOnAccessWrapForApi9;
|
||||||
|
|
||||||
this.UnderlyingWrap.Wait();
|
var newRefTask = this.CreateNewReference();
|
||||||
if (this.UnderlyingWrap.Exception is not null)
|
newRefTask.Wait();
|
||||||
|
if (!newRefTask.IsCompletedSuccessfully)
|
||||||
return null;
|
return null;
|
||||||
|
newRefTask.Result.Dispose();
|
||||||
|
|
||||||
this.availableOnAccessWrapForApi9 = new AvailableOnAccessTextureWrap(this);
|
this.availableOnAccessWrapForApi9 = new AvailableOnAccessTextureWrap(this);
|
||||||
this.RevivalPossibility = new(this.availableOnAccessWrapForApi9);
|
this.RevivalPossibility = new(this.availableOnAccessWrapForApi9);
|
||||||
}
|
}
|
||||||
|
|
@ -326,7 +339,7 @@ internal abstract class SharableTexture : IRefCountable
|
||||||
if (this.inner.GetImmediate() is { } t)
|
if (this.inner.GetImmediate() is { } t)
|
||||||
return t;
|
return t;
|
||||||
|
|
||||||
this.inner.UnderlyingWrap.Wait();
|
this.inner.UnderlyingWrap?.Wait();
|
||||||
return this.inner.DisposeSuppressingWrap ?? Service<DalamudAssetManager>.Get().Empty4X4;
|
return this.inner.DisposeSuppressingWrap ?? Service<DalamudAssetManager>.Get().Empty4X4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,36 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid
|
||||||
this.fileSystemTextures.GetOrAdd(file.FullName, CreateFileSystemSharableTexture).GetAvailableOnAccessWrapForApi9();
|
this.fileSystemTextures.GetOrAdd(file.FullName, CreateFileSystemSharableTexture).GetAvailableOnAccessWrapForApi9();
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool ImmediateGetStateFromGameIcon(in GameIconLookup lookup, out Exception? exception) =>
|
||||||
|
this.ImmediateGetStateFromGame(this.lookupToPath.GetOrAdd(lookup, this.GetIconPathByValue), out exception);
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool ImmediateGetStateFromGame(string path, out Exception? exception)
|
||||||
|
{
|
||||||
|
if (!this.gamePathTextures.TryGetValue(path, out var texture))
|
||||||
|
{
|
||||||
|
exception = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
exception = texture.UnderlyingWrap?.Exception;
|
||||||
|
return texture.UnderlyingWrap?.IsCompletedSuccessfully ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool ImmediateGetStateFromFile(string file, out Exception? exception)
|
||||||
|
{
|
||||||
|
if (!this.fileSystemTextures.TryGetValue(file, out var texture))
|
||||||
|
{
|
||||||
|
exception = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
exception = texture.UnderlyingWrap?.Exception;
|
||||||
|
return texture.UnderlyingWrap?.IsCompletedSuccessfully ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IDalamudTextureWrap ImmediateGetFromGameIcon(in GameIconLookup lookup) =>
|
public IDalamudTextureWrap ImmediateGetFromGameIcon(in GameIconLookup lookup) =>
|
||||||
this.ImmediateGetFromGame(this.lookupToPath.GetOrAdd(lookup, this.GetIconPathByValue));
|
this.ImmediateGetFromGame(this.lookupToPath.GetOrAdd(lookup, this.GetIconPathByValue));
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
|
using Dalamud.Interface;
|
||||||
using Dalamud.Interface.Internal;
|
using Dalamud.Interface.Internal;
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,24 @@ namespace Dalamud.Plugin.Services;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial interface ITextureProvider
|
public partial interface ITextureProvider
|
||||||
{
|
{
|
||||||
|
/// <summary>Gets the state of the background load task for <see cref="ImmediateGetFromGameIcon"/>.</summary>
|
||||||
|
/// <param name="lookup">The icon specifier.</param>
|
||||||
|
/// <param name="exception">The exception, if failed.</param>
|
||||||
|
/// <returns><c>true</c> if loaded; <c>false</c> if not fully loaded or failed.</returns>
|
||||||
|
public bool ImmediateGetStateFromGameIcon(in GameIconLookup lookup, out Exception? exception);
|
||||||
|
|
||||||
|
/// <summary>Gets the state of the background load task for <see cref="ImmediateGetFromGameIcon"/>.</summary>
|
||||||
|
/// <param name="path">The game-internal path to a .tex, .atex, or an image file such as .png.</param>
|
||||||
|
/// <param name="exception">The exception, if failed.</param>
|
||||||
|
/// <returns><c>true</c> if loaded; <c>false</c> if not fully loaded or failed.</returns>
|
||||||
|
public bool ImmediateGetStateFromGame(string path, out Exception? exception);
|
||||||
|
|
||||||
|
/// <summary>Gets the state of the background load task for <see cref="ImmediateGetFromGameIcon"/>.</summary>
|
||||||
|
/// <param name="file">The filesystem path to a .tex, .atex, or an image file such as .png.</param>
|
||||||
|
/// <param name="exception">The exception, if failed.</param>
|
||||||
|
/// <returns><c>true</c> if loaded; <c>false</c> if not fully loaded or failed.</returns>
|
||||||
|
public bool ImmediateGetStateFromFile(string file, out Exception? exception);
|
||||||
|
|
||||||
/// <summary>Gets the corresponding game icon for use with the current frame.</summary>
|
/// <summary>Gets the corresponding game icon for use with the current frame.</summary>
|
||||||
/// <param name="lookup">The icon specifier.</param>
|
/// <param name="lookup">The icon specifier.</param>
|
||||||
/// <returns>An instance of <see cref="IDalamudTextureWrap"/> that is guaranteed to be available for the current
|
/// <returns>An instance of <see cref="IDalamudTextureWrap"/> that is guaranteed to be available for the current
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue