重构
- 统一 ItemDescForm/RewardItem/GoodsItem 的描述格式 - 减少组件属性的 Clone 数量,目前只在合并仓库、组装防御塔时才进行复制 - 删除先前留下的冗余 fallback 代码
This commit is contained in:
@@ -30,7 +30,7 @@ namespace GeometryTD.UI
|
||||
return new ShopFormRawData
|
||||
{
|
||||
PlayerGold = GameEntry.PlayerInventory != null ? GameEntry.PlayerInventory.Gold : 0,
|
||||
GoodsItems = CloneGoodsItems(_currentGoods)
|
||||
GoodsItems = new List<GoodsItemRawData>(_currentGoods)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -93,59 +93,5 @@ namespace GeometryTD.UI
|
||||
return inventory;
|
||||
}
|
||||
|
||||
private static List<GoodsItemRawData> CloneGoodsItems(List<GoodsItemRawData> source)
|
||||
{
|
||||
List<GoodsItemRawData> result = new List<GoodsItemRawData>(source?.Count ?? 0);
|
||||
if (source == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (var item in source)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result.Add(new GoodsItemRawData
|
||||
{
|
||||
GoodsIndex = item.GoodsIndex,
|
||||
Title = item.Title,
|
||||
TypeText = item.TypeText,
|
||||
Description = item.Description,
|
||||
Price = item.Price,
|
||||
Tags = item.Tags != null ? (TagType[])item.Tags.Clone() : Array.Empty<TagType>(),
|
||||
IconAreaContext = item.IconAreaContext == null
|
||||
? null
|
||||
: new IconAreaContext
|
||||
{
|
||||
Rarity = item.IconAreaContext.Rarity,
|
||||
ComponentSlotType = item.IconAreaContext.ComponentSlotType,
|
||||
Color = item.IconAreaContext.Color,
|
||||
Icon = item.IconAreaContext.Icon
|
||||
},
|
||||
SourceItem = CloneSourceItem(item.SourceItem),
|
||||
IsPurchased = item.IsPurchased
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static TowerCompItemData CloneSourceItem(TowerCompItemData item)
|
||||
{
|
||||
switch (item)
|
||||
{
|
||||
case MuzzleCompItemData muzzleComp:
|
||||
return InventoryCloneUtility.CloneMuzzleComp(muzzleComp);
|
||||
case BearingCompItemData bearingComp:
|
||||
return InventoryCloneUtility.CloneBearingComp(bearingComp);
|
||||
case BaseCompItemData baseComp:
|
||||
return InventoryCloneUtility.CloneBaseComp(baseComp);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user