fixes based on feedback

This commit is contained in:
Chris Adamson
2025-04-28 12:43:11 -05:00
parent 7ed081d305
commit 723e616e80
2 changed files with 59 additions and 60 deletions
@@ -859,65 +859,6 @@ public class ItemHelper(
return _dogTagTpls.Contains(tpl);
}
/// <summary>
/// Given that the R field of item location can be string enum or int, provide a method to get the exact type
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public static (ItemLocation? itemLocation, LocationInGrid? locationInGrid) TryParseItemLocation(Item item)
{
if (item.Location is not JsonElement jsonLocation)
{
return ((ItemLocation?) item.Location, null);
}
var itemLocation = TryParseItemLocation(jsonLocation);
if (itemLocation != null)
{
return (itemLocation, null);
}
var locationInGrid = TryParseLocationInGrid(jsonLocation);
if (locationInGrid == null)
{
return (null, null);
}
itemLocation = new ItemLocation
{
X = locationInGrid.X,
Y = locationInGrid.Y,
IsSearched = locationInGrid.IsSearched,
R = locationInGrid.R == ItemRotation.Vertical ? 1 : 0
};
return (itemLocation, locationInGrid);
ItemLocation? TryParseItemLocation(JsonElement element)
{
try
{
return element.ToObject<ItemLocation>();
}
catch
{
return null;
}
}
LocationInGrid? TryParseLocationInGrid(JsonElement element)
{
try
{
return element.ToObject<LocationInGrid>();
}
catch
{
return null;
}
}
}
/// <summary>
/// Gets the identifier for a child using slotId, locationX and locationY.
/// </summary>
@@ -2241,6 +2182,64 @@ public class ItemHelper(
}
}
}
/// <summary>
/// Given that the R field of item location can be string enum or int, provide a method to get the exact type
/// </summary>
/// <param name="item"></param>
/// <returns>ItemLocation possible null</returns>
public static ItemLocation? TryParseItemLocation(Item item)
{
if (item.Location is not JsonElement jsonLocation)
{
return (ItemLocation?) item.Location;
}
var itemLocation = TryParseItemLocation(jsonLocation);
if (itemLocation != null)
{
return itemLocation;
}
var locationInGrid = TryParseLocationInGrid(jsonLocation);
if (locationInGrid == null)
{
return null;
}
itemLocation = new ItemLocation
{
X = locationInGrid.X,
Y = locationInGrid.Y,
IsSearched = locationInGrid.IsSearched,
R = locationInGrid.R == ItemRotation.Vertical ? 1 : 0
};
return itemLocation;
}
private static ItemLocation? TryParseItemLocation(JsonElement element)
{
try
{
return element.ToObject<ItemLocation>();
}
catch
{
return null;
}
}
private static LocationInGrid? TryParseLocationInGrid(JsonElement element)
{
try
{
return element.ToObject<LocationInGrid>();
}
catch
{
return null;
}
}
}
public class ItemSize