Collapse runtime item catalog links

This commit is contained in:
Meta Vens 2026-06-13 20:02:41 +01:00
commit c38be9ee5c
8 changed files with 55 additions and 50 deletions

View file

@ -377,7 +377,7 @@ public abstract class Entity
public void GenerateWeaponGroups()
{
foreach (var group in Weapons
.GroupBy(w => w.Item.EquippableItem.Data.LinkID)
.GroupBy(w => w.Item.EquippableItem.Data.ItemId)
.OrderBy(wg=>wg.Average(w=>w.Range))
.Select((weapons, index) => (weapons, index)))
{
@ -1523,9 +1523,9 @@ public class EquippedCargoBay : EquippedItem
}
Cargo[item] = cargoCoord;
if(!ItemsOfType.ContainsKey(item.Data.LinkID))
ItemsOfType[item.Data.LinkID] = new List<ItemInstance>();
ItemsOfType[item.Data.LinkID].Add(item);
if(!ItemsOfType.ContainsKey(item.Data.ItemId))
ItemsOfType[item.Data.ItemId] = new List<ItemInstance>();
ItemsOfType[item.Data.ItemId].Add(item);
}
else if (Occupancy[cargoCoord.x, cargoCoord.y] is SimpleCommodity cargoCommodity && cargoCommodity.Data == item.Data)
{
@ -1567,9 +1567,9 @@ public class EquippedCargoBay : EquippedItem
}
Cargo[item] = cargoCoord;
if(!ItemsOfType.ContainsKey(item.Data.LinkID))
ItemsOfType[item.Data.LinkID] = new List<ItemInstance>();
ItemsOfType[item.Data.LinkID].Add(item);
if(!ItemsOfType.ContainsKey(item.Data.ItemId))
ItemsOfType[item.Data.ItemId] = new List<ItemInstance>();
ItemsOfType[item.Data.ItemId].Add(item);
Mass += ItemManager.GetMass(item);
ThermalMass += ItemManager.GetThermalMass(item);
@ -1592,9 +1592,9 @@ public class EquippedCargoBay : EquippedItem
Occupancy[v.x, v.y] = null;
Cargo.Remove(item);
ItemsOfType[item.Data.LinkID].Remove(item);
if (!ItemsOfType[item.Data.LinkID].Any())
ItemsOfType.Remove(item.Data.LinkID);
ItemsOfType[item.Data.ItemId].Remove(item);
if (!ItemsOfType[item.Data.ItemId].Any())
ItemsOfType.Remove(item.Data.ItemId);
Mass -= ItemManager.GetMass(item);
ThermalMass -= ItemManager.GetThermalMass(item);
@ -1621,9 +1621,9 @@ public class EquippedCargoBay : EquippedItem
Occupancy[v.x, v.y] = null;
Cargo.Remove(item);
ItemsOfType[item.Data.LinkID].Remove(item);
if (!ItemsOfType[item.Data.LinkID].Any())
ItemsOfType.Remove(item.Data.LinkID);
ItemsOfType[item.Data.ItemId].Remove(item);
if (!ItemsOfType[item.Data.ItemId].Any())
ItemsOfType.Remove(item.Data.ItemId);
Mass -= ItemManager.GetMass(item);
ThermalMass -= ItemManager.GetThermalMass(item);

View file

@ -12,7 +12,7 @@ using static Unity.Mathematics.math;
public abstract class ItemInstance
{
public RuntimeCatalogLink<ItemData> Data;
public RuntimeItemReference Data;
public ItemRotation Rotation;
}

View file

@ -57,9 +57,9 @@ public class ItemManager
return _itemData.Get<T>(id);
}
public RuntimeCatalogLink<ItemData> CreateLink(ItemData item)
public RuntimeItemReference CreateReference(ItemData item)
{
return new RuntimeCatalogLink<ItemData>(item);
return new RuntimeItemReference(item);
}
public ItemData GetData(ItemInstance item)
@ -75,10 +75,10 @@ public class ItemManager
return;
}
var data = _itemData.Get(item.Data.LinkID);
var data = _itemData.Get(item.Data.ItemId);
if (data == null)
{
_logger($"Attempted to hydrate missing item id {item.Data.LinkID}");
_logger($"Attempted to hydrate missing item id {item.Data.ItemId}");
return;
}
@ -155,7 +155,7 @@ public class ItemManager
{
var newItem = new SimpleCommodity
{
Data = CreateLink(item),
Data = CreateReference(item),
Quantity = count
};
//ItemData.Add(newItem);
@ -190,13 +190,13 @@ public class ItemManager
{
return new EquippableItem
{
Data = CreateLink(item), Quality = quality, Durability = equippableItemData.Durability
Data = CreateReference(item), Quality = quality, Durability = equippableItemData.Durability
};
}
var newCommodity = new CompoundCommodity
{
Data = CreateLink(item),
Data = CreateReference(item),
Quality = quality
};
return newCommodity;

View file

@ -26,31 +26,27 @@ public abstract class RuntimeCatalogEntry
}
}
public class RuntimeCatalogLink<T> : RuntimeCatalogLinkBase where T : ItemData
public class RuntimeItemReference
{
public T Value { get; private set; }
public ItemData Value { get; private set; }
public Guid ItemId;
public RuntimeCatalogLink()
public RuntimeItemReference()
{
}
public RuntimeCatalogLink(T value)
public RuntimeItemReference(ItemData value)
{
SetValue(value);
}
public void SetValue(T value)
public void SetValue(ItemData value)
{
Value = value;
LinkID = value?.ID ?? Guid.Empty;
ItemId = value?.ID ?? Guid.Empty;
}
}
public class RuntimeCatalogLinkBase
{
public Guid LinkID;
}
public interface ITintInspector
{
float3 TintColor { get; }