diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index 7aa175586..c152c0d3a 100644 Binary files a/.voidbot/state/aetheria.cc and b/.voidbot/state/aetheria.cc differ diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 772ba2cfc..5f097e4d9 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -18,6 +18,7 @@ RequireRuntimeSimulationTuningCommits(root); RequireHullConductivityCommitAuthority(root); RequireInventoryEntityRenameCommitAuthority(root); RequireWeaponGroupCommitAuthority(root); +RequireInventoryDoubleClickTransferCommitAuthority(root); await using var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-state-verify"); @@ -465,6 +466,7 @@ Console.WriteLine("Runtime simulation tuning authority: UI writes flow through g Console.WriteLine("Hull conductivity authority: inventory UI toggles flow through gameplay checkpoint commits"); Console.WriteLine("Inventory entity rename authority: UI rename flows through gameplay checkpoint commits"); Console.WriteLine("Weapon group authority: UI assignment flows through gameplay checkpoint commits"); +Console.WriteLine("Inventory double-click transfer authority: UI transfer requests flow through gameplay checkpoint commits"); static void RequireCount(AetheriaMigrationLedger ledger, string documentType, int actual) { @@ -917,6 +919,78 @@ static void RequireWeaponGroupCommitAuthority(string root) } } +static void RequireInventoryDoubleClickTransferCommitAuthority(string root) +{ + var actionGameManagerPath = Path.Combine(root, "Assets", "Scripts", "Gameplay", "ActionGameManager.cs"); + var actionGameManager = File.Exists(actionGameManagerPath) + ? File.ReadAllText(actionGameManagerPath) + : throw new InvalidOperationException("Cannot verify inventory transfer authority; ActionGameManager.cs is missing."); + + var requiredCommits = new[] + { + "CommitCargoItemTransfer", + "CommitCargoItemEquip", + "CommitEquippedItemStore", + "QueueRunCheckpoint(\"cargo-item-transfer\")", + "QueueRunCheckpoint(\"cargo-item-equip\")", + "QueueRunCheckpoint(\"equipped-item-store\")" + }; + + var missingCommits = requiredCommits + .Where(symbol => !actionGameManager.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + + if (missingCommits.Length > 0) + { + throw new InvalidOperationException( + "Inventory transfer no longer has complete gameplay-owned checkpoint commit primitives: " + + string.Join(", ", missingCommits)); + } + + var inventoryMenuPath = Path.Combine(root, "Assets", "Scripts", "UI", "Menu", "InventoryMenu.cs"); + var inventoryMenu = File.Exists(inventoryMenuPath) + ? File.ReadAllText(inventoryMenuPath) + : throw new InvalidOperationException("Cannot verify inventory transfer authority; InventoryMenu.cs is missing."); + + var forbiddenSymbols = new[] + { + ".DropItem(", + ".CargoBay.Remove(", + ".TryUnequip(" + }; + + var hits = File.ReadLines(inventoryMenuPath) + .Select((line, index) => new { LineNumber = index + 1, Line = line }) + .Where(line => forbiddenSymbols.Any(symbol => line.Line.Contains(symbol, StringComparison.Ordinal))) + .Select(line => $"{Path.GetRelativePath(root, inventoryMenuPath)}:{line.LineNumber}: {line.Line.Trim()}") + .ToArray(); + + if (hits.Length > 0) + { + throw new InvalidOperationException( + "InventoryMenu double-click transfer still owns direct inventory mutation: " + + string.Join("; ", hits)); + } + + var requiredUiCalls = new[] + { + "GameManager.CommitCargoItemTransfer", + "GameManager.CommitCargoItemEquip", + "GameManager.CommitEquippedItemStore" + }; + + var missingUiCalls = requiredUiCalls + .Where(symbol => !inventoryMenu.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + + if (missingUiCalls.Length > 0) + { + throw new InvalidOperationException( + "InventoryMenu no longer routes double-click transfers through ActionGameManager: " + + string.Join(", ", missingUiCalls)); + } +} + static string ExtractMethodBody(string source, string methodName) { var signature = "private void " + methodName + "()"; diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 8c51d2153..99c33b95a 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -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) diff --git a/Assets/Scripts/UI/Menu/InventoryMenu.cs b/Assets/Scripts/UI/Menu/InventoryMenu.cs index 18d1c1022..b3055326e 100644 --- a/Assets/Scripts/UI/Menu/InventoryMenu.cs +++ b/Assets/Scripts/UI/Menu/InventoryMenu.cs @@ -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) diff --git a/Assets/Scripts/UI/Menu/InventoryPanel.cs b/Assets/Scripts/UI/Menu/InventoryPanel.cs index 6a87542f7..417e1a8d4 100644 --- a/Assets/Scripts/UI/Menu/InventoryPanel.cs +++ b/Assets/Scripts/UI/Menu/InventoryPanel.cs @@ -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() { diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 949277752..6593efd84 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -1389,6 +1389,13 @@ First Aetheria surfaces to publish: remains a uGUI control for now, but it no longer adds/removes items or weapons from `Entity.WeaponGroups` directly; gameplay owns the membership mutation and typed checkpoint. + - Done: route inventory double-click transfer through gameplay-owned + checkpoint commits. `InventoryMenu` no longer drops items, removes cargo, + or unequips gear directly for the double-click path; it asks + `ActionGameManager` to commit cargo-to-cargo, cargo-to-equipment, or + equipment-to-cargo movement and then refreshes display. The deeper + `InventoryPanel` drag/drop path still has direct mutation and is the next + inventory cut. - Replace the next concrete uGUI screen with an Eve-owned surface. - Move the staged packages into the Eve repo once its worktree is clean, then import them back into Aetheria from Eve instead of carrying a local copy. @@ -1710,7 +1717,10 @@ conductivity changes follow the same rule: UI requests the toggle, gameplay owns the grid mutation and checkpoint. Entity renames follow the same rule: UI collects text, gameplay owns the name mutation and checkpoint. Weapon group assignment follows the same rule: UI requests membership, gameplay owns the -group mutation and checkpoint. Any +group mutation and checkpoint. Inventory double-click transfer follows the same +rule: UI requests cargo/equipment movement, gameplay owns the move and queues +the checkpoint. Drag/drop inventory placement is not pure yet and should be cut +through the same commit primitive family next. Any predicate that still needs legacy DTO objects must earn that dependency by using behavior objects or simulation-only methods that typed facets do not yet expose.