test(D.2b): UiDatElement — cover DrawMode passthrough + media fallbacks
- Assert DrawMode values (not just File) in the existing named-vs-direct test - Add ActiveMedia_NoMedia_ReturnsZero: empty StateMedia → (0,0) - Add ActiveMedia_MissingNamedState_FallsBackToDirect: absent named key → DirectState - OnDraw: replace `var (file, drawMode) = ...; _ = drawMode;` with idiomatic `var (file, _) = ...` - Add `// exposed for unit testing` comment above ActiveMedia() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
cc4de3ef77
commit
70dc391c41
2 changed files with 22 additions and 3 deletions
|
|
@ -61,6 +61,7 @@ public sealed class UiDatElement : UiElement
|
|||
/// falling back to the DirectState (<c>""</c> key) if the named state is absent.
|
||||
/// Returns (0, 0) if neither exists.
|
||||
/// </summary>
|
||||
// exposed for unit testing
|
||||
public (uint File, int DrawMode) ActiveMedia()
|
||||
=> _info.StateMedia.TryGetValue(ActiveState, out var m) ? m
|
||||
: _info.StateMedia.TryGetValue("", out var d) ? d
|
||||
|
|
@ -68,7 +69,7 @@ public sealed class UiDatElement : UiElement
|
|||
|
||||
protected override void OnDraw(UiRenderContext ctx)
|
||||
{
|
||||
var (file, drawMode) = ActiveMedia();
|
||||
var (file, _) = ActiveMedia();
|
||||
if (file == 0) return;
|
||||
|
||||
var (tex, tw, th) = _resolve(file);
|
||||
|
|
@ -78,8 +79,7 @@ public sealed class UiDatElement : UiElement
|
|||
// matching ImgTex::TileCSI. Overlay/Alphablend are the same blit with a blend state; the
|
||||
// sprite shader already alpha-blends, so the quad is identical for all draw modes in Plan 1.
|
||||
// (No Stretch mode exists in DatReaderWriter.Enums.DrawModeType.)
|
||||
// drawMode is not yet branched here — Plan 2 can add per-mode behavior if needed.
|
||||
_ = drawMode; // suppress unused-variable warning until Plan 2 adds per-mode branches
|
||||
// DrawMode is not yet branched here — Plan 2 can add per-mode behavior if needed.
|
||||
float u1 = Width / tw;
|
||||
float v1 = Height / th;
|
||||
ctx.DrawSprite(tex, 0, 0, Width, Height, 0, 0, u1, v1, Vector4.One);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,26 @@ public class UiDatElementTests
|
|||
info.StateMedia["ShowDetail"] = (0x06000002, 3); // named (Alphablend=3)
|
||||
var e = new UiDatElement(info, _ => (0, 0, 0)) { ActiveState = "ShowDetail" };
|
||||
Assert.Equal(0x06000002u, e.ActiveMedia().File);
|
||||
Assert.Equal(3, e.ActiveMedia().DrawMode);
|
||||
e.ActiveState = "";
|
||||
Assert.Equal(0x06000001u, e.ActiveMedia().File);
|
||||
Assert.Equal(1, e.ActiveMedia().DrawMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ActiveMedia_NoMedia_ReturnsZero()
|
||||
{
|
||||
var e = new UiDatElement(new ElementInfo(), _ => (0, 0, 0));
|
||||
Assert.Equal(0u, e.ActiveMedia().File);
|
||||
Assert.Equal(0, e.ActiveMedia().DrawMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ActiveMedia_MissingNamedState_FallsBackToDirect()
|
||||
{
|
||||
var info = new ElementInfo();
|
||||
info.StateMedia[""] = (0x06000005, 1);
|
||||
var e = new UiDatElement(info, _ => (0, 0, 0)) { ActiveState = "NoSuchState" };
|
||||
Assert.Equal(0x06000005u, e.ActiveMedia().File);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue