feat: port retail magic lifecycle and retained spell UI
Complete the retail cast-intent, target, component, enchantment, and busy-state paths; mount the DAT-authored spell bar, spellbook, component book, effects panels, and shared panel lifecycle; and add scoped input plus conformance coverage. Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
parent
7b7ffcd278
commit
07be994d97
84 changed files with 17822 additions and 1051 deletions
|
|
@ -4,6 +4,7 @@ using System.Numerics;
|
|||
using AcDream.App.Rendering;
|
||||
using AcDream.Core.Items;
|
||||
using AcDream.Core.Textures;
|
||||
using AcDream.Core.Spells;
|
||||
using DatReaderWriter;
|
||||
using DatReaderWriter.DBObjs;
|
||||
|
||||
|
|
@ -35,6 +36,8 @@ public sealed class IconComposer
|
|||
private readonly TextureCache _cache;
|
||||
private readonly Dictionary<(uint, uint, uint, uint, uint), uint> _byTuple = new();
|
||||
private readonly Dictionary<(uint, uint, uint), ComposedIcon> _dragByTuple = new();
|
||||
private readonly Dictionary<uint, uint> _spellIcons = new();
|
||||
private readonly Dictionary<uint, uint> _componentIcons = new();
|
||||
|
||||
private sealed record ComposedIcon(byte[] Rgba, int Width, int Height, uint Texture);
|
||||
|
||||
|
|
@ -298,4 +301,71 @@ public sealed class IconComposer
|
|||
var decoded = SurfaceDecoder.DecodeRenderSurface(rs, palette: null);
|
||||
layers.Add((decoded.Rgba8, decoded.Width, decoded.Height));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retail ClientMagicSystem::CompositeSpellIcon (0x00567550): power-level
|
||||
/// backing, spell art, reversed/normal recolor, then self/fellow overlay.
|
||||
/// </summary>
|
||||
public uint GetSpellIcon(uint spellId)
|
||||
{
|
||||
if (_spellIcons.TryGetValue(spellId, out uint cached)) return cached;
|
||||
DatReaderWriter.DBObjs.SpellTable? table =
|
||||
_dats.Get<DatReaderWriter.DBObjs.SpellTable>(0x0E00000Eu);
|
||||
if (table is null || !table.Spells.TryGetValue(spellId, out var spell)) return 0u;
|
||||
|
||||
uint power = spell.Components.Count == 0
|
||||
? 0u
|
||||
: RetailSpellFormula.DeterminePowerLevelOfComponent(spell.Components[0]);
|
||||
uint powerBacking = RetailDataIdResolver.Resolve(_dats, power, 0x10000006u);
|
||||
var layers = new List<(byte[] rgba, int w, int h)>();
|
||||
AddLayer(layers, powerBacking);
|
||||
AddLayer(layers, spell.Icon);
|
||||
if (layers.Count == 0) return 0u;
|
||||
|
||||
var composed = Compose(layers);
|
||||
uint tintIndex = (spell.Bitfield & DatReaderWriter.Enums.SpellIndex.Reversed) != 0
|
||||
? 1u : 2u;
|
||||
uint tintDid = RetailDataIdResolver.Resolve(_dats, tintIndex, 0x10000007u);
|
||||
if (TryDecode(tintDid, out DecodedTexture tint))
|
||||
ReplaceWhiteFromSurface(composed.rgba, composed.w, composed.h,
|
||||
tint.Rgba8, tint.Width, tint.Height);
|
||||
|
||||
uint overlayIndex = (spell.Bitfield & DatReaderWriter.Enums.SpellIndex.FellowshipSpell) != 0
|
||||
? 4u
|
||||
: (spell.Bitfield & DatReaderWriter.Enums.SpellIndex.SelfTargeted) != 0
|
||||
? 3u : 0u;
|
||||
if (overlayIndex != 0u)
|
||||
{
|
||||
uint overlayDid = RetailDataIdResolver.Resolve(_dats, overlayIndex, 0x10000007u);
|
||||
if (TryDecode(overlayDid, out DecodedTexture overlay))
|
||||
composed = Compose([
|
||||
(composed.rgba, composed.w, composed.h),
|
||||
(overlay.Rgba8, overlay.Width, overlay.Height)]);
|
||||
}
|
||||
|
||||
uint texture = _cache.UploadRgba8(composed.rgba, composed.w, composed.h, nearest: true);
|
||||
_spellIcons[spellId] = texture;
|
||||
return texture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retail ClientMagicSystem::CompositeSpellComponentIcon (0x00567720).
|
||||
/// Components use their raw DAT art with pure white replaced by black.
|
||||
/// </summary>
|
||||
public uint GetSpellComponentIcon(uint iconId)
|
||||
{
|
||||
if (iconId == 0u) return 0u;
|
||||
if (_componentIcons.TryGetValue(iconId, out uint cached)) return cached;
|
||||
if (!TryDecode(iconId, out DecodedTexture icon)) return 0u;
|
||||
byte[] rgba = (byte[])icon.Rgba8.Clone();
|
||||
for (int i = 0; i + 3 < rgba.Length; i += 4)
|
||||
{
|
||||
if (rgba[i] != 255 || rgba[i + 1] != 255 || rgba[i + 2] != 255 || rgba[i + 3] != 255)
|
||||
continue;
|
||||
rgba[i] = rgba[i + 1] = rgba[i + 2] = 0;
|
||||
}
|
||||
uint texture = _cache.UploadRgba8(rgba, icon.Width, icon.Height, nearest: true);
|
||||
_componentIcons[iconId] = texture;
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue