acdream/src/AcDream.Core/Items/ShortcutStore.cs
Erik 3281e0acb4 fix(ui): port source-aware toolbar drops
Plan retail shortcut drops from a complete post-lift snapshot so fresh inventory items use cyclic-right displacement while toolbar aliases restore to their vacated slot. Apply local mutations atomically, preserve raw shortcut fields, emit exact Remove/Add ordering, and retire AP-102 after the live ACE gate.

Co-Authored-By: Codex <codex@openai.com>
2026-07-11 09:26:57 +02:00

59 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
namespace AcDream.Core.Items;
/// <summary>
/// Mutable client-side model of retail <c>ShortCutManager::shortCuts_[18]</c>
/// (<c>acclient.h:36492</c>). Every present entry retains all three raw
/// <see cref="ShortcutEntry"/> fields, including non-object records that the object-only
/// <c>gmToolbarUI</c> does not render.
/// </summary>
public sealed class ShortcutStore
{
public const int SlotCount = 18;
private readonly ShortcutEntry?[] _entries = new ShortcutEntry?[SlotCount];
/// <summary>
/// Replace all slots from packed entries. Invalid signed indices are rejected exactly
/// like <c>ShortCutManager::AddShortCut @ 0x005D5790</c>; valid entries are retained
/// even when their object id is zero.
/// </summary>
public void Load(IEnumerable<ShortcutEntry> entries)
{
Array.Clear(_entries);
foreach (var entry in entries)
Set(entry);
}
/// <summary>Raw entry at <paramref name="slot"/>, or null for absent/out-of-range.</summary>
public ShortcutEntry? GetEntry(int slot)
=> (uint)slot < SlotCount ? _entries[slot] : null;
/// <summary>Detached raw snapshot for planning a complete mutation before applying it.</summary>
public ShortcutEntry?[] Snapshot() => (ShortcutEntry?[])_entries.Clone();
/// <summary>Visible object id at <paramref name="slot"/>, or zero.</summary>
public uint Get(int slot) => GetEntry(slot)?.ObjectId ?? 0u;
/// <summary>
/// Visual availability used by <c>gmToolbarUI</c>. A retained non-object entry remains
/// invisible and therefore counts as an empty toolbar cell.
/// </summary>
public bool IsEmpty(int slot) => Get(slot) == 0u;
public void Set(ShortcutEntry entry)
{
if ((uint)entry.Index < SlotCount)
_entries[entry.Index] = entry;
}
/// <summary>Create/replace a retail object shortcut; toolbar-created records use spell word zero.</summary>
public void SetItem(int slot, uint objectId) => Set(new ShortcutEntry(slot, objectId, 0u));
public void Remove(int slot)
{
if ((uint)slot < SlotCount)
_entries[slot] = null;
}
}