Route inventory transfers through checkpoints

This commit is contained in:
Meta Vens 2026-06-16 01:59:18 +01:00
commit 4f6643b00f
6 changed files with 193 additions and 17 deletions

View file

@ -1455,6 +1455,88 @@ public class ActionGameManager : MonoBehaviour
return true;
}
public bool CommitCargoItemTransfer(EquippedCargoBay origin, EquippedCargoBay destination, ItemInstance item)
{
if (origin == null ||
destination == null ||
item == null ||
origin == destination ||
!origin.Cargo.ContainsKey(item) ||
!destination.TryFindSpace(item))
{
return false;
}
if (item is SimpleCommodity commodity)
{
var quantity = commodity.Quantity;
var transferItem = new SimpleCommodity
{
Reference = commodity.Reference,
Quantity = quantity,
Rotation = commodity.Rotation
};
if (!destination.TryStore(transferItem))
return false;
origin.Remove(commodity, quantity);
QueueRunCheckpoint("cargo-item-transfer");
return true;
}
if (!destination.TryStore(item))
return false;
origin.Remove(item);
QueueRunCheckpoint("cargo-item-transfer");
return true;
}
public bool CommitCargoItemEquip(EquippedCargoBay origin, Entity destination, EquippableItem item)
{
if (origin == null ||
destination == null ||
item == null ||
!origin.Cargo.ContainsKey(item) ||
!destination.TryFindSpace(item, out _))
{
return false;
}
if (!destination.TryEquip(item))
return false;
origin.Remove(item);
QueueRunCheckpoint("cargo-item-equip");
return true;
}
public bool CommitEquippedItemStore(Entity origin, EquippedItem equippedItem, EquippedCargoBay destination)
{
if (origin == null ||
equippedItem?.EquippableItem == null ||
destination == null ||
!origin.Equipment.Contains(equippedItem) ||
!destination.TryFindSpace(equippedItem.EquippableItem))
{
return false;
}
var item = origin.TryUnequip(equippedItem);
if (item == null)
return false;
if (!destination.TryStore(item))
{
origin.TryEquip(item, equippedItem.Position);
return false;
}
QueueRunCheckpoint("equipped-item-store");
return true;
}
public void CommitEquippedItemOverrideShutdown(EquippedItem item, bool enabled)
{
if (item?.EquippableItem == null)

View file

@ -88,11 +88,9 @@ public class InventoryMenu : MonoBehaviour
if (e.clickCount == 2)
{
var otherPanel = panel == InventoryPanels[0] ? InventoryPanels[1] : InventoryPanels[0];
if (otherPanel.CanDropItem(item))
if (CommitCargoItemTransfer(cargoEvent.CargoBay, otherPanel, item))
{
otherPanel.DropItem(item);
// TODO: SFX: Equip
cargoEvent.CargoBay.Remove(item);
panel.RefreshCells();
otherPanel.RefreshCells();
}
@ -122,20 +120,11 @@ public class InventoryMenu : MonoBehaviour
if (e.clickCount == 2)
{
var otherPanel = panel == InventoryPanels[0] ? InventoryPanels[1] : InventoryPanels[0];
if (otherPanel.CanDropItem(item.EquippableItem))
if (CommitEquippedItemTransfer(entityEvent.Entity, item, otherPanel))
{
if (!entityEvent.Entity.Active)
{
if (entityEvent.Entity.TryUnequip(item) != null)
{
otherPanel.DropItem(item.EquippableItem);
// TODO: SFX: Unequip
panel.RefreshCells();
otherPanel.RefreshCells();
}
// else
// TODO: SFX: Fail
}
// TODO: SFX: Unequip
panel.RefreshCells();
otherPanel.RefreshCells();
// else
// TODO: SFX: Fail
}
@ -170,6 +159,25 @@ public class InventoryMenu : MonoBehaviour
}
}
private bool CommitCargoItemTransfer(EquippedCargoBay origin, InventoryPanel destination, ItemInstance item)
{
if (destination.DisplayedEntity != null && item is EquippableItem equippableItem)
return GameManager.CommitCargoItemEquip(origin, destination.DisplayedEntity, equippableItem);
if (destination.DisplayedCargo != null)
return GameManager.CommitCargoItemTransfer(origin, destination.DisplayedCargo, item);
return false;
}
private bool CommitEquippedItemTransfer(Entity origin, EquippedItem item, InventoryPanel destination)
{
if (destination.DisplayedCargo != null)
return GameManager.CommitEquippedItemStore(origin, item, destination.DisplayedCargo);
return false;
}
void Update()
{
// if (Keyboard.current.qKey.wasPressedThisFrame && _dragItem != null)

View file

@ -98,6 +98,8 @@ public class InventoryPanel : MonoBehaviour, IPointerClickHandler
public InventoryPanelTarget Target =>
_displayedEntity != null ? InventoryPanelTarget.Equipment :
_displayedCargo != null ? InventoryPanelTarget.Cargo : InventoryPanelTarget.None;
public Entity DisplayedEntity => _displayedEntity;
public EquippedCargoBay DisplayedCargo => _displayedCargo;
private void Start()
{