Skip to content

Commit

Permalink
feat: [DXDynamicTexture]ファイルパスの表現揺れを許容するように
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic9045 committed Aug 23, 2023
1 parent 822cf2b commit 068cfbf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions Extensions/AtsEx.Extensions.DXDynamicTexture/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static class TextureManager

internal static Device DXDevice;

private readonly static List<string> appliedTextureFileNames = new List<string>();
public static IReadOnlyList<string> AppliedTextureFileNames => appliedTextureFileNames;

internal static void Initialize()
{
if (IsInitialized) throw new InvalidOperationException("DXDynamicTexture has been already initialized.");
Expand All @@ -42,12 +45,19 @@ internal static void Initialize()
private static void FromFilePostfix(ref Texture __result, Device device, string fileName)
#pragma warning restore IDE1006 // 命名スタイル
{
var normalizedName = fileName.Replace('\\', '/').ToLowerInvariant();
var normalizedName = Path.GetFullPath(fileName.ToLowerInvariant());
appliedTextureFileNames.Add(normalizedName);
foreach (var item in Handles)
{
if (normalizedName.EndsWith(item.Key))
{
__result = Handles[item.Key].GetOrCreate(device);
System.Windows.Forms.MessageBox.Show(item.Key);
}

if (item.Key.EndsWith("ktisdx.png"))
{
System.Windows.Forms.MessageBox.Show($"normalizedName: {normalizedName}, item.Key: {item.Key}");
}
}
DXDevice = device;
Expand All @@ -59,7 +69,7 @@ public static TextureHandle Register(string fileNameEnding, int width, int heigh
if (!IsPowerOfTwo(width)) throw new ArgumentException("Must be a integral power of 2.", nameof(width));
if (!IsPowerOfTwo(height)) throw new ArgumentException("Must be a integral power of 2.", nameof(height));

fileNameEnding = fileNameEnding.ToLowerInvariant().Replace('\\', '/');
fileNameEnding = Path.GetFullPath(Path.Combine("a:", fileNameEnding.ToLowerInvariant())).Substring(3);
if (Handles.ContainsKey(fileNameEnding)) return Handles[fileNameEnding];
var result = new TextureHandle(width, height);
Handles.Add(fileNameEnding, result);
Expand Down Expand Up @@ -109,6 +119,7 @@ internal static void Dispose()
if (item.Value != null && item.Value.IsCreated) item.Value.Dispose();
}

appliedTextureFileNames.Clear();
Harmony.UnpatchAll(Harmony.Id);
}

Expand Down
3 changes: 2 additions & 1 deletion Extensions/AtsEx.Extensions.DXDynamicTexture/TouchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -166,7 +167,7 @@ public static TouchTextureHandle Register(string fileNameEnding, int width, int
if (!TextureManager.IsPowerOfTwo(width)) throw new ArgumentException("Must be a integral power of 2.", nameof(width));
if (!TextureManager.IsPowerOfTwo(height)) throw new ArgumentException("Must be a integral power of 2.", nameof(height));

fileNameEnding = fileNameEnding.ToLowerInvariant().Replace('\\', '/');
fileNameEnding = Path.GetFullPath(Path.Combine("a:", fileNameEnding.ToLowerInvariant())).Substring(3);
if (TextureManager.Handles.ContainsKey(fileNameEnding))
return (TouchTextureHandle)TextureManager.Handles[fileNameEnding];
var result = new TouchTextureHandle(width, height);
Expand Down

0 comments on commit 068cfbf

Please sign in to comment.