6 using Microsoft.Xna.Framework;
10 internal readonly record
struct ItemSlotIndexPair(int Slot, int StackIndex)
12 public static Option<ItemSlotIndexPair> TryDeserializeFromXML(ContentXElement element,
string elementName)
14 string? elementStr = element.GetAttributeString(elementName,
string.Empty);
15 if (
string.IsNullOrEmpty(elementStr)) {
return Option.None; }
17 var point = XMLExtensions.ParsePoint(elementStr);
18 return Option.Some(
new ItemSlotIndexPair(point.X, point.Y));
21 public static string Serialize(Item item)
23 Inventory parent = item.ParentInventory;
24 if (item.ParentInventory is
null)
26 throw new Exception($
"Item \"{item.Name}\" is not in an inventory.");
29 int slotIndex = parent.FindIndex(item);
31 int stackIndex = parent.GetItemStackSlotIndex(item, slotIndex);
33 if (slotIndex < 0 || stackIndex < 0)
35 throw new Exception($
"Unable to find item \"{item.Name}\" in its parent inventory.");
38 return XMLExtensions.PointToString(
new Point(slotIndex, stackIndex));
44 if (items !=
null && StackIndex >= 0 && StackIndex < items.Count())
46 return items.ElementAt(StackIndex);
51 $
"Circuit box error: failed to find an item in the container {container?.Item.Name ?? "null"}.";
52 DebugConsole.ThrowError(
54 $
" Items: {items?.Count().ToString() ?? "null"}, " +
55 $
" Slot: {Slot}, StackIndex: {StackIndex}");
56 GameAnalyticsManager.AddErrorEventOnce(
"ItemSlotIndexPair.FindItemInContainer", GameAnalyticsManager.ErrorSeverity.Error, errorMsg);
IEnumerable< Item > GetItemsAt(int index)
Get all the item stored in the specified inventory slot. Can return more than one item if the slot co...
readonly ItemInventory Inventory