Retail IconData::RenderIcons (decomp 407524) builds the icon layer stack bottom→top: type-default underlay (OPAQUE, Blit_Normal) first, then custom underlay, base icon, custom overlay. acdream's IconComposer omitted the type-default underlay, leaving filled toolbar slots with a transparent background. Resolution via the two-level EnumIDMap chain that retail uses (DBCache::GetDIDFromEnum 0x413940): Portal.Header.MasterMapId (0x25000000) → master[0x10000004] → submap DID (0x25000008) → submap[LSB(itemType)+1] → 0x06 RenderSurface underlay DID. Golden values confirmed against the live dats: MeleeWeapon→0x060011CB, Armor→0x060011CF, Clothing→0x060011F3, Jewelry→0x060011D5, None(fallback 0x21)→0x060011D4. Changes: - IconComposer: add ResolveUnderlayDid(ItemType)/EnsureUnderlaySubMap (memoised); widen cache key from (uint,uint,uint)→(uint,uint,uint,uint); GetIcon gains ItemType param and prepends the opaque underlay as layer 0 (Compose sizes to it → fully opaque) - ToolbarController: widen _iconIds Func from 3-arg to 4-arg; Populate passes item.Type - GameWindow: update toolbar mount lambda to 4-arg form - Tests: update ToolbarController test stubs to (_,_,_,_); add Compose_opaqueUnderlayFirst_resultIsFullyOpaque (dat-free) and ResolveUnderlayDid_goldenValues_matchDat (dat-gated, skip when dats absent) No divergence-register row existed for this omission; none added (fully ported now). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
104 lines
4.7 KiB
C#
104 lines
4.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using AcDream.App.UI;
|
|
using AcDream.Core.Items;
|
|
using DatReaderWriter;
|
|
using DatReaderWriter.Options;
|
|
|
|
namespace AcDream.App.Tests.UI;
|
|
|
|
public class IconComposerTests
|
|
{
|
|
private static byte[] Solid(int w, int h, byte r, byte g, byte b, byte a)
|
|
{
|
|
var px = new byte[w * h * 4];
|
|
for (int i = 0; i < w * h; i++) { px[i*4]=r; px[i*4+1]=g; px[i*4+2]=b; px[i*4+3]=a; }
|
|
return px;
|
|
}
|
|
|
|
[Fact]
|
|
public void Compose_alphaOver_topOpaqueLayerWins()
|
|
{
|
|
var bottom = (Solid(2, 2, 255, 0, 0, 255), 2, 2); // red, opaque
|
|
var top = (Solid(2, 2, 0, 0, 255, 255), 2, 2); // blue, opaque
|
|
var (rgba, w, h) = IconComposer.Compose(new[] { bottom, top });
|
|
Assert.Equal(2, w); Assert.Equal(2, h);
|
|
Assert.Equal(0, rgba[0]); // R
|
|
Assert.Equal(0, rgba[1]); // G
|
|
Assert.Equal(255, rgba[2]); // B — top layer won
|
|
Assert.Equal(255, rgba[3]); // A
|
|
}
|
|
|
|
[Fact]
|
|
public void Compose_alphaOver_transparentTopKeepsBottom()
|
|
{
|
|
var bottom = (Solid(1, 1, 255, 0, 0, 255), 1, 1);
|
|
var top = (Solid(1, 1, 0, 0, 255, 0), 1, 1); // fully transparent blue
|
|
var (rgba, _, _) = IconComposer.Compose(new[] { bottom, top });
|
|
Assert.Equal(255, rgba[0]); // bottom red preserved
|
|
Assert.Equal(0, rgba[2]);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dat-free: when an opaque type-default underlay is prepended as layer 0,
|
|
/// Compose yields a fully-opaque result even when the base icon is semi-transparent.
|
|
/// This validates the bottom-up ordering that makes filled toolbar slots non-transparent
|
|
/// (retail IconData::RenderIcons 407524: underlay is OPAQUE Blit_Normal first).
|
|
/// </summary>
|
|
[Fact]
|
|
public void Compose_opaqueUnderlayFirst_resultIsFullyOpaque()
|
|
{
|
|
var underlay = (Solid(2, 2, 128, 64, 32, 255), 2, 2); // opaque tawny
|
|
var baseIcon = (Solid(2, 2, 0, 0, 0, 128), 2, 2); // semi-transparent black
|
|
var (rgba, w, h) = IconComposer.Compose(new[] { underlay, baseIcon });
|
|
Assert.Equal(2, w); Assert.Equal(2, h);
|
|
// All pixels fully opaque: underlay A=255, baseIcon blends over it.
|
|
for (int i = 0; i < w * h; i++)
|
|
Assert.Equal(255, rgba[i * 4 + 3]);
|
|
}
|
|
|
|
// ── Dat-gated golden tests ────────────────────────────────────────────────
|
|
// These tests open the real Asheron's Call dats (ACDREAM_DAT_DIR or the default
|
|
// Documents path) and verify the EnumIDMap 0x10000004 resolve chain against the
|
|
// known golden DIDs from the dat (confirmed 2026-06-17 research).
|
|
// Golden values: IconData::RenderIcons 0058d214 + DBCache::GetDIDFromEnum 0x413940.
|
|
|
|
private static string? ResolveDatDir()
|
|
{
|
|
var fromEnv = Environment.GetEnvironmentVariable("ACDREAM_DAT_DIR");
|
|
if (!string.IsNullOrWhiteSpace(fromEnv) && Directory.Exists(fromEnv))
|
|
return fromEnv;
|
|
var def = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
|
"Documents", "Asheron's Call");
|
|
return Directory.Exists(def) ? def : null;
|
|
}
|
|
|
|
[Fact]
|
|
public void ResolveUnderlayDid_goldenValues_matchDat()
|
|
{
|
|
var datDir = ResolveDatDir();
|
|
if (datDir is null)
|
|
return; // dats absent (CI) — skip cleanly
|
|
|
|
using var dats = new DatCollection(datDir, DatAccessType.Read);
|
|
// TextureCache is not needed for the resolve path; pass a null-safe stub
|
|
// via IconComposer — the underlay-resolve methods only touch _dats.
|
|
// We cannot construct TextureCache without GL, so use a bare IconComposer
|
|
// with a null cache guard: ResolveUnderlayDid is internal and pure-dat.
|
|
var composer = new IconComposer(dats, null!);
|
|
|
|
// Golden values confirmed against C:/Users/erikn/Documents/Asheron's Call
|
|
// (IconData::RenderIcons decomp 407524; DBCache::GetDIDFromEnum 0x413940):
|
|
// MeleeWeapon (0x1) → index 1 → 0x060011CB
|
|
// Armor (0x2) → index 2 → 0x060011CF
|
|
// Clothing (0x4) → index 3 → 0x060011F3
|
|
// Jewelry (0x8) → index 4 → 0x060011D5
|
|
// None (0x0) → index 0x21 (fallback) → 0x060011D4
|
|
Assert.Equal(0x060011CBu, composer.ResolveUnderlayDid(ItemType.MeleeWeapon));
|
|
Assert.Equal(0x060011CFu, composer.ResolveUnderlayDid(ItemType.Armor));
|
|
Assert.Equal(0x060011F3u, composer.ResolveUnderlayDid(ItemType.Clothing));
|
|
Assert.Equal(0x060011D5u, composer.ResolveUnderlayDid(ItemType.Jewelry));
|
|
Assert.Equal(0x060011D4u, composer.ResolveUnderlayDid(ItemType.None));
|
|
}
|
|
}
|