mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-13 12:14:17 +01:00
Add DalamudSubstitutionProvider
This commit is contained in:
parent
df808187e2
commit
09ca32f33d
2 changed files with 58 additions and 7 deletions
46
Penumbra/Api/DalamudSubstitutionProvider.cs
Normal file
46
Penumbra/Api/DalamudSubstitutionProvider.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
using System;
|
||||||
|
using Dalamud.Plugin.Services;
|
||||||
|
using Penumbra.Collections.Manager;
|
||||||
|
using Penumbra.String.Classes;
|
||||||
|
|
||||||
|
namespace Penumbra.Api;
|
||||||
|
|
||||||
|
public class DalamudSubstitutionProvider : IDisposable
|
||||||
|
{
|
||||||
|
private readonly ITextureSubstitutionProvider _substitution;
|
||||||
|
private readonly ActiveCollectionData _activeCollectionData;
|
||||||
|
|
||||||
|
public DalamudSubstitutionProvider(ITextureSubstitutionProvider substitution, ActiveCollectionData activeCollectionData)
|
||||||
|
{
|
||||||
|
_substitution = substitution;
|
||||||
|
_activeCollectionData = activeCollectionData;
|
||||||
|
_substitution.InterceptTexDataLoad += Substitute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
=> _substitution.InterceptTexDataLoad -= Substitute;
|
||||||
|
|
||||||
|
private void Substitute(string path, ref string? replacementPath)
|
||||||
|
{
|
||||||
|
// Let other plugins prioritize replacement paths.
|
||||||
|
if (replacementPath != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Only replace interface textures.
|
||||||
|
if (!path.StartsWith("ui/") && !path.StartsWith("common/font/"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!Utf8GamePath.FromString(path, out var utf8Path, true))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var resolved = _activeCollectionData.Interface.ResolvePath(utf8Path);
|
||||||
|
replacementPath = resolved?.FullName;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,7 @@ using Dalamud.Plugin;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Dalamud.Interface.DragDrop;
|
using Dalamud.Interface.DragDrop;
|
||||||
|
using Dalamud.Plugin.Services;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
|
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
|
||||||
|
|
@ -78,6 +79,8 @@ public class DalamudServices
|
||||||
services.AddSingleton(this);
|
services.AddSingleton(this);
|
||||||
services.AddSingleton(UiBuilder);
|
services.AddSingleton(UiBuilder);
|
||||||
services.AddSingleton(DragDropManager);
|
services.AddSingleton(DragDropManager);
|
||||||
|
services.AddSingleton(TextureProvider);
|
||||||
|
services.AddSingleton(TextureSubstitutionProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove static
|
// TODO remove static
|
||||||
|
|
@ -96,6 +99,8 @@ public class DalamudServices
|
||||||
[PluginService][RequiredVersion("1.0")] public KeyState KeyState { get; private set; } = null!;
|
[PluginService][RequiredVersion("1.0")] public KeyState KeyState { get; private set; } = null!;
|
||||||
[PluginService][RequiredVersion("1.0")] public SigScanner SigScanner { get; private set; } = null!;
|
[PluginService][RequiredVersion("1.0")] public SigScanner SigScanner { get; private set; } = null!;
|
||||||
[PluginService][RequiredVersion("1.0")] public IDragDropManager DragDropManager { get; private set; } = null!;
|
[PluginService][RequiredVersion("1.0")] public IDragDropManager DragDropManager { get; private set; } = null!;
|
||||||
|
[PluginService][RequiredVersion("1.0")] public ITextureProvider TextureProvider { get; private set; } = null!;
|
||||||
|
[PluginService][RequiredVersion("1.0")] public ITextureSubstitutionProvider TextureSubstitutionProvider { get; private set; } = null!;
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
public UiBuilder UiBuilder
|
public UiBuilder UiBuilder
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue