重构
- 统一 ItemDescForm/RewardItem/GoodsItem 的描述格式 - 减少组件属性的 Clone 数量,目前只在合并仓库、组装防御塔时才进行复制 - 删除先前留下的冗余 fallback 代码
This commit is contained in:
@@ -148,8 +148,8 @@ namespace GeometryTD.UI
|
||||
GoodsIndex = item?.GoodsIndex ?? i,
|
||||
Title = item?.Title ?? string.Empty,
|
||||
TypeText = item?.TypeText ?? string.Empty,
|
||||
Description = item?.Description ?? string.Empty,
|
||||
TagTexts = BuildTagTexts(item?.Tags),
|
||||
Description = BuildDescription(item),
|
||||
TagTexts = BuildTagTexts(item),
|
||||
PurchaseButtonText = item != null && item.IsPurchased ? "已购买" : $"购买 {item?.Price ?? 0}",
|
||||
CanPurchase = item != null && !item.IsPurchased,
|
||||
IconAreaContext = item?.IconAreaContext
|
||||
@@ -164,9 +164,26 @@ namespace GeometryTD.UI
|
||||
};
|
||||
}
|
||||
|
||||
private static string[] BuildTagTexts(TagType[] tags)
|
||||
private static string BuildDescription(GoodsItemRawData rawData)
|
||||
{
|
||||
return TagDisplayUtility.BuildTagTexts(tags);
|
||||
string baseDescription = rawData?.Description ?? string.Empty;
|
||||
string tagDescription = TagDisplayUtility.BuildTagDescriptionText(rawData?.Tags);
|
||||
if (string.IsNullOrWhiteSpace(tagDescription))
|
||||
{
|
||||
return baseDescription;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(baseDescription))
|
||||
{
|
||||
return tagDescription;
|
||||
}
|
||||
|
||||
return $"{baseDescription}\n{tagDescription}";
|
||||
}
|
||||
|
||||
private static string[] BuildTagTexts(GoodsItemRawData rawData)
|
||||
{
|
||||
return TagDisplayUtility.BuildTagTexts(rawData?.Tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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