Rename runtime item reader around typed catalog
This commit is contained in:
parent
16c9ee3a5f
commit
1a7ea0a0e5
8 changed files with 43 additions and 43 deletions
|
|
@ -6,13 +6,13 @@ using System.Reflection;
|
|||
using GameCult.Aetheria.State.Unity;
|
||||
using Unity.Mathematics;
|
||||
|
||||
public interface IRuntimeItemProjectionReader
|
||||
public interface IRuntimeItemCatalogReader
|
||||
{
|
||||
AetheriaRuntimeCatalogItem GetRuntimeItem(Guid guid);
|
||||
IReadOnlyList<BehaviorData> GetBehaviorProjections(Guid guid);
|
||||
IReadOnlyList<BehaviorData> GetRuntimeBehaviorConfigs(Guid guid);
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
||||
public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemCatalogReader
|
||||
{
|
||||
private readonly Dictionary<Guid, AetheriaRuntimeCatalogItem> _typedItems;
|
||||
private static readonly IReadOnlyDictionary<int, Type> BehaviorTypesByUnionKey = new Dictionary<int, Type>
|
||||
|
|
@ -65,18 +65,18 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
|||
return item;
|
||||
}
|
||||
|
||||
public IReadOnlyList<BehaviorData> GetBehaviorProjections(Guid guid)
|
||||
public IReadOnlyList<BehaviorData> GetRuntimeBehaviorConfigs(Guid guid)
|
||||
{
|
||||
var item = GetRuntimeItem(guid);
|
||||
return item == null
|
||||
? Array.Empty<BehaviorData>()
|
||||
: ProjectBehaviors(item);
|
||||
: BuildBehaviorConfigs(item);
|
||||
}
|
||||
|
||||
private static BehaviorData[] ProjectBehaviors(AetheriaRuntimeCatalogItem item)
|
||||
private static BehaviorData[] BuildBehaviorConfigs(AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
return item.BehaviorPayloads
|
||||
.Select(ProjectBehavior)
|
||||
.Select(BuildBehaviorConfig)
|
||||
.Where(behavior => behavior != null)
|
||||
.ToArray();
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ public sealed class AetheriaRuntimeItemCatalog : IRuntimeItemProjectionReader
|
|||
};
|
||||
}
|
||||
|
||||
private static BehaviorData ProjectBehavior(AetheriaRuntimeBehaviorPayload payload)
|
||||
private static BehaviorData BuildBehaviorConfig(AetheriaRuntimeBehaviorPayload payload)
|
||||
{
|
||||
if (!BehaviorTypesByUnionKey.TryGetValue(payload.UnionKey, out var behaviorType))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class StatModifier : Behavior, IInitializableBehavior, IDisposable, IAlwa
|
|||
_stats = Entity.Equipment
|
||||
.Select(hp => hp.EquippableItem)
|
||||
.Where(HasRequiredBehavior)
|
||||
.SelectMany(gear => ItemManager.GetRuntimeBehaviorProjections(gear))
|
||||
.SelectMany(gear => ItemManager.GetRuntimeBehaviorConfigs(gear))
|
||||
.Where(behaviorData => behaviorData.GetType() == targetType)
|
||||
.Select(behaviorData => statField.GetValue(behaviorData) as PerformanceStat)
|
||||
.ToArray();
|
||||
|
|
@ -77,7 +77,7 @@ public class StatModifier : Behavior, IInitializableBehavior, IDisposable, IAlwa
|
|||
private bool HasRequiredBehavior(EquippableItem gear)
|
||||
{
|
||||
return _data.RequireBehavior == null ||
|
||||
ItemManager.GetRuntimeBehaviorProjections(gear)
|
||||
ItemManager.GetRuntimeBehaviorConfigs(gear)
|
||||
.Any(behavior => behavior.GetType() == _data.RequireBehavior);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1188,7 +1188,7 @@ public class ConsumableItemEffect
|
|||
_effectiveness = CreateEffectivenessCurve(RuntimeItem);
|
||||
RemainingDuration = _duration;
|
||||
|
||||
Behaviors = entity.ItemManager.GetRuntimeBehaviorProjections(item)
|
||||
Behaviors = entity.ItemManager.GetRuntimeBehaviorConfigs(item)
|
||||
.Select(bd => bd.CreateInstance(this))
|
||||
.ToArray();
|
||||
}
|
||||
|
|
@ -1393,7 +1393,7 @@ public class EquippedItem
|
|||
.CombineLatest(Online, (enabled, online) => enabled && online).DistinctUntilChanged());
|
||||
|
||||
|
||||
Behaviors = ItemManager.GetRuntimeBehaviorProjections(item)
|
||||
Behaviors = ItemManager.GetRuntimeBehaviorConfigs(item)
|
||||
.Select(bd => bd.CreateInstance(this))
|
||||
.ToArray();
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class ItemManager
|
|||
|
||||
// private Guid _forceLoadZone;
|
||||
|
||||
private readonly IRuntimeItemProjectionReader _itemProjections;
|
||||
private readonly IRuntimeItemCatalogReader _runtimeItems;
|
||||
public GameplaySettings GameplaySettings { get; }
|
||||
|
||||
// public double Time
|
||||
|
|
@ -46,9 +46,9 @@ public class ItemManager
|
|||
|
||||
// private readonly Dictionary<CraftedItemData, int> Tier = new Dictionary<CraftedItemData, int>();
|
||||
|
||||
public ItemManager(IRuntimeItemProjectionReader itemProjections, GameplaySettings settings, Action<string> logger)
|
||||
public ItemManager(IRuntimeItemCatalogReader runtimeItems, GameplaySettings settings, Action<string> logger)
|
||||
{
|
||||
_itemProjections = itemProjections;
|
||||
_runtimeItems = runtimeItems;
|
||||
GameplaySettings = settings;
|
||||
_logger = logger;
|
||||
}
|
||||
|
|
@ -61,15 +61,15 @@ public class ItemManager
|
|||
|
||||
public AetheriaRuntimeCatalogItem GetRuntimeItem(Guid itemId)
|
||||
{
|
||||
return itemId == Guid.Empty ? null : _itemProjections.GetRuntimeItem(itemId);
|
||||
return itemId == Guid.Empty ? null : _runtimeItems.GetRuntimeItem(itemId);
|
||||
}
|
||||
|
||||
public IReadOnlyList<BehaviorData> GetRuntimeBehaviorProjections(ItemInstance item)
|
||||
public IReadOnlyList<BehaviorData> GetRuntimeBehaviorConfigs(ItemInstance item)
|
||||
{
|
||||
var itemId = item?.Data?.ItemId ?? Guid.Empty;
|
||||
return itemId == Guid.Empty
|
||||
? Array.Empty<BehaviorData>()
|
||||
: _itemProjections.GetBehaviorProjections(itemId);
|
||||
: _runtimeItems.GetRuntimeBehaviorConfigs(itemId);
|
||||
}
|
||||
|
||||
public Shape GetRuntimeShape(ItemInstance item)
|
||||
|
|
|
|||
Loading…
Reference in a new issue