Bind consumables with typed action bar rows

This commit is contained in:
Meta Vens 2026-06-14 02:49:55 +01:00
commit da27eb39b6
4 changed files with 51 additions and 21 deletions

Binary file not shown.

View file

@ -57,25 +57,27 @@ public abstract class ActionBarBinding
public class ActionBarConsumableBinding : ActionBarBinding
{
public ConsumableItemData Target;
public AetheriaRuntimeCatalogItem Target { get; }
private readonly Func<ConsumableItemData> _resolveLegacyTarget;
public ActionBarConsumableBinding(Entity entity, ActionBarSlot slot, ConsumableItemData target) : base(entity, slot)
public ActionBarConsumableBinding(
Entity entity,
ActionBarSlot slot,
AetheriaRuntimeCatalogItem target,
Func<ConsumableItemData> resolveLegacyTarget) : base(entity, slot)
{
Target = target;
_resolveLegacyTarget = resolveLegacyTarget;
Slot.QuantityRemaining.gameObject.SetActive(true);
var data = Target;
if(!string.IsNullOrEmpty(data.Icon))
{
Slot.Label.gameObject.SetActive(false);
Slot.Icon.gameObject.SetActive(true);
Slot.Icon.texture = Resources.Load<Texture2D>(data.Icon.Substring("Assets/Resources/".Length).Split('.').First());
}
else Slot.Icon.gameObject.SetActive(false);
Slot.Label.gameObject.SetActive(false);
Slot.Icon.gameObject.SetActive(false);
}
public override void Activate()
{
Entity.TryActivateConsumable(Target);
var legacyTarget = ResolveLegacyTarget();
if (legacyTarget != null)
Entity.TryActivateConsumable(legacyTarget);
}
public override void Deactivate()
@ -84,11 +86,26 @@ public class ActionBarConsumableBinding : ActionBarBinding
public override void Update()
{
Slot.QuantityRemaining.text = $"{Entity.CountItemsInCargo(Target.ID)}";
var instance = Entity.FindActiveConsumable(Target);
Slot.QuantityRemaining.text = $"{Entity.CountItemsInCargo(TargetLegacyId)}";
var legacyTarget = ResolveLegacyTarget();
if (legacyTarget == null)
{
Slot.Fill.fillAmount = 0;
return;
}
var instance = Entity.FindActiveConsumable(legacyTarget);
if (instance == null) Slot.Fill.fillAmount = 0;
else Slot.Fill.fillAmount = instance.RemainingDuration / instance.Data.Duration;
}
private Guid TargetLegacyId =>
Guid.TryParse(Target.LegacyId, out var legacyId) ? legacyId : Guid.Empty;
private ConsumableItemData ResolveLegacyTarget()
{
return _resolveLegacyTarget?.Invoke();
}
}
public class ActionBarGearBinding : ActionBarBinding

View file

@ -729,9 +729,13 @@ public class ActionGameManager : MonoBehaviour
slot.Binding = new ActionBarGearBinding(CurrentEntity, slot, equippedItemDragAction.EquippedItem, trigger);
return true;
case ItemInstanceDragObject itemInstanceDragAction:
if (!IsRuntimeConsumableItem(itemInstanceDragAction.Item)) return false;
if (!(ItemManager.GetData(itemInstanceDragAction.Item) is ConsumableItemData consumable)) return false;
slot.Binding = new ActionBarConsumableBinding(CurrentEntity, slot, consumable);
var consumable = FindTypedActionBarConsumable(itemInstanceDragAction.Item);
if (consumable == null) return false;
slot.Binding = new ActionBarConsumableBinding(
CurrentEntity,
slot,
consumable,
() => ItemManager.GetData(itemInstanceDragAction.Item) as ConsumableItemData);
return true;
case WeaponGroupDragObject weaponGroupDragAction:
slot.Binding = new ActionBarWeaponGroupBinding(CurrentEntity, slot, weaponGroupDragAction.Group);
@ -749,11 +753,13 @@ public class ActionGameManager : MonoBehaviour
return slot;
}
bool IsRuntimeConsumableItem(ItemInstance item)
AetheriaRuntimeCatalogItem FindTypedActionBarConsumable(ItemInstance item)
{
var typedItem = FindTypedActionBarItem(item);
return typedItem != null &&
string.Equals(typedItem.Category, nameof(ConsumableItemData), StringComparison.Ordinal);
string.Equals(typedItem.Category, nameof(ConsumableItemData), StringComparison.Ordinal)
? typedItem
: null;
}
AetheriaRuntimeCatalogItem FindTypedActionBarItem(ItemInstance item)

View file

@ -79,9 +79,13 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted.
the durable owner. Binding drag/drop and action-bar remapping both queue the
same typed player-settings commit after mutating the runtime projection. The
action bar also uses typed runtime catalog category rows to reject
non-consumable inventory drops before hydrating the legacy consumable DTO
still required by activation APIs. Missing typed rows are rejected for
consumable binding instead of falling through to legacy DTO classification.
non-consumable inventory drops and creates consumable bindings around typed
catalog rows before hydrating any legacy DTO. Missing typed rows are rejected
for consumable binding instead of falling through to legacy DTO classification.
Consumable activation and active-duration fill still resolve legacy
`ConsumableItemData` lazily because runtime effects and duration are not typed
execution surfaces yet; consumable icon projection is hidden until typed icon
fields exist.
Gear action-bar bindings use typed weapon and hardpoint facets for fallback
icon selection and fall back to a generic tool icon when typed facets are
incomplete; legacy custom action-bar icon paths remain fallback projection
@ -622,6 +626,9 @@ First Aetheria surfaces to publish:
`TradeRow` fields; legacy `ItemData` hydration is lazy and bounded to
commodity subtype detail, behavior reflection columns, missing typed rows,
and buy mechanics.
- Done: move action-bar consumable drop binding onto typed catalog rows;
legacy `ConsumableItemData` resolution is lazy and bounded to activation
and active-duration fill until typed consumable effect execution exists.
- Done: delete the console `give` command instead of preserving a debug
operator path that hydrated typed item rows back into legacy item DTOs.
- Done: delete `ItemManager.GetCatalogEntries<T>` after all live callers