ItemMapper ECS (#9867)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Storage.Components;
|
||||
using System.Linq;
|
||||
using Content.Shared.Storage.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
@@ -12,6 +13,8 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
[UsedImplicitly]
|
||||
public abstract class SharedItemMapperSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -23,6 +26,11 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
|
||||
private void InitLayers(EntityUid uid, ItemMapperComponent component, ComponentInit args)
|
||||
{
|
||||
foreach (var (layerName, val) in component.MapLayers)
|
||||
{
|
||||
val.Layer = layerName;
|
||||
}
|
||||
|
||||
if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
var list = new List<string>(component.MapLayers.Keys);
|
||||
@@ -61,8 +69,25 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
/// </param>
|
||||
/// <param name="containedLayers">list of <paramref name="itemMapper"/> layers that should be visible</param>
|
||||
/// <returns>false if <c>msg.Container.Owner</c> is not a storage, true otherwise.</returns>
|
||||
protected abstract bool TryGetLayers(ContainerModifiedMessage msg,
|
||||
private bool TryGetLayers(ContainerModifiedMessage msg,
|
||||
ItemMapperComponent itemMapper,
|
||||
out IReadOnlyList<string> containedLayers);
|
||||
out IReadOnlyList<string> showLayers)
|
||||
{
|
||||
var containedLayers = _container.GetAllContainers(msg.Container.Owner)
|
||||
.SelectMany(cont => cont.ContainedEntities).ToArray();
|
||||
|
||||
var list = new List<string>();
|
||||
foreach (var mapLayerData in itemMapper.MapLayers.Values)
|
||||
{
|
||||
var count = containedLayers.Count(uid => mapLayerData.ServerWhitelist.IsValid(uid));
|
||||
if (count >= mapLayerData.MinCount && count <= mapLayerData.MaxCount)
|
||||
{
|
||||
list.Add(mapLayerData.Layer);
|
||||
}
|
||||
}
|
||||
|
||||
showLayers = list;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user