Skip to content

Commit 76d1322

Browse files
committed
refactor(maps): extract the shared map-texture candidate resolver
HuntZoneMapTextures and HousingGameMaps each carried their own copy of TextureCandidates/FileExists/ResolveTexturePath, with Hunts silently missing the _s.tex fallback candidate Housing had. Extract both into Core/Maps/MapTextures, keeping all five candidates so the two callers stay behaviorally identical; both now pass a subsystem label through for the existing Debug-level 'could not test' log line.
1 parent 78cf1a1 commit 76d1322

3 files changed

Lines changed: 55 additions & 89 deletions

File tree

src/Aetherphone/Core/Housing/HousingGameMaps.cs

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text;
2+
using Aetherphone.Core.Maps;
23
using Dalamud.Interface.Textures.TextureWraps;
34
using Dalamud.Plugin.Services;
45
using Lumina.Excel.Sheets;
@@ -306,51 +307,8 @@ private Dictionary<uint, List<Vector3>> CollectMarkerGroups(uint districtId)
306307
private static float Normalize(float world, short offset, float scaleFactor) =>
307308
((world + offset) * scaleFactor + MapPageSize * 0.5f) / MapPageSize;
308309

309-
private string? ResolveTexturePath(string mapId)
310-
{
311-
if (string.IsNullOrEmpty(mapId))
312-
{
313-
return null;
314-
}
315-
316-
var candidates = TextureCandidates(mapId);
317-
for (var index = 0; index < candidates.Length; index++)
318-
{
319-
if (FileExists(candidates[index]))
320-
{
321-
return candidates[index];
322-
}
323-
}
324-
325-
return null;
326-
}
327-
328-
private static string[] TextureCandidates(string mapId)
329-
{
330-
var flat = mapId.Replace("/", string.Empty);
331-
var underscored = mapId.Replace('/', '_');
332-
return
333-
[
334-
$"ui/map/{mapId}/{flat}_m.tex",
335-
$"ui/map/{mapId}/{flat}m_m.tex",
336-
$"ui/map/{mapId}/{flat}_s.tex",
337-
$"ui/map/{mapId}/{underscored}_m.tex",
338-
$"ui/map/{mapId}/{underscored}m_m.tex",
339-
];
340-
}
341-
342-
private bool FileExists(string path)
343-
{
344-
try
345-
{
346-
return data.FileExists(path);
347-
}
348-
catch (Exception exception)
349-
{
350-
AepLog.Debug(exception, $"Housing could not test '{path}'");
351-
return false;
352-
}
353-
}
310+
private string? ResolveTexturePath(string mapId) =>
311+
string.IsNullOrEmpty(mapId) ? null : MapTextures.ResolveTexturePath(data, mapId, "Housing");
354312

355313
public string Describe(uint districtId)
356314
{
@@ -406,10 +364,11 @@ private void DescribeGroup(StringBuilder report, uint mapRowId, List<Vector3> ma
406364
}
407365

408366
report.Append($" sizeFactor {map.SizeFactor} offset {map.OffsetX},{map.OffsetY}\n");
409-
var candidates = TextureCandidates(mapId);
367+
var candidates = MapTextures.Candidates(mapId);
410368
for (var index = 0; index < candidates.Length; index++)
411369
{
412-
report.Append($" texture: {candidates[index]} -> {(FileExists(candidates[index]) ? "OK" : "missing")}\n");
370+
report.Append(
371+
$" texture: {candidates[index]} -> {(MapTextures.FileExists(data, candidates[index], "Housing") ? "OK" : "missing")}\n");
413372
}
414373

415374
var sampleCount = Math.Min(3, markers.Count);

src/Aetherphone/Core/Hunts/HuntZoneMapTextures.cs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Aetherphone.Core.Media;
1+
using Aetherphone.Core.Maps;
22
using Dalamud.Interface.Textures.TextureWraps;
33
using Dalamud.Plugin.Services;
44
using Lumina.Excel.Sheets;
@@ -63,46 +63,6 @@ public HuntZoneMapTextures(IDataManager data, ITextureProvider textures)
6363
}
6464

6565
var mapId = map.Id.ExtractText();
66-
if (mapId.Length == 0)
67-
{
68-
return null;
69-
}
70-
71-
var candidates = TextureCandidates(mapId);
72-
for (var index = 0; index < candidates.Length; index++)
73-
{
74-
if (FileExists(candidates[index]))
75-
{
76-
return candidates[index];
77-
}
78-
}
79-
80-
return null;
81-
}
82-
83-
private static string[] TextureCandidates(string mapId)
84-
{
85-
var flat = mapId.Replace("/", string.Empty);
86-
var underscored = mapId.Replace('/', '_');
87-
return
88-
[
89-
$"ui/map/{mapId}/{flat}_m.tex",
90-
$"ui/map/{mapId}/{flat}m_m.tex",
91-
$"ui/map/{mapId}/{underscored}_m.tex",
92-
$"ui/map/{mapId}/{underscored}m_m.tex",
93-
];
94-
}
95-
96-
private bool FileExists(string path)
97-
{
98-
try
99-
{
100-
return data.FileExists(path);
101-
}
102-
catch (Exception exception)
103-
{
104-
AepLog.Debug(exception, $"Hunts could not test '{path}'");
105-
return false;
106-
}
66+
return mapId.Length == 0 ? null : MapTextures.ResolveTexturePath(data, mapId, "Hunts");
10767
}
10868
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Dalamud.Plugin.Services;
2+
3+
namespace Aetherphone.Core.Maps;
4+
5+
internal static class MapTextures
6+
{
7+
public static string[] Candidates(string mapId)
8+
{
9+
var flat = mapId.Replace("/", string.Empty);
10+
var underscored = mapId.Replace('/', '_');
11+
return
12+
[
13+
$"ui/map/{mapId}/{flat}_m.tex",
14+
$"ui/map/{mapId}/{flat}m_m.tex",
15+
$"ui/map/{mapId}/{flat}_s.tex",
16+
$"ui/map/{mapId}/{underscored}_m.tex",
17+
$"ui/map/{mapId}/{underscored}m_m.tex",
18+
];
19+
}
20+
21+
public static string? ResolveTexturePath(IDataManager data, string mapId, string subsystem)
22+
{
23+
var candidates = Candidates(mapId);
24+
for (var index = 0; index < candidates.Length; index++)
25+
{
26+
if (FileExists(data, candidates[index], subsystem))
27+
{
28+
return candidates[index];
29+
}
30+
}
31+
32+
return null;
33+
}
34+
35+
public static bool FileExists(IDataManager data, string path, string subsystem)
36+
{
37+
try
38+
{
39+
return data.FileExists(path);
40+
}
41+
catch (Exception exception)
42+
{
43+
AepLog.Debug(exception, $"{subsystem} could not test '{path}'");
44+
return false;
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)