ItemMapper ECS (#9867)

This commit is contained in:
metalgearsloth
2022-08-08 12:35:57 +10:00
committed by GitHub
parent b55b806c6b
commit 189d49a51f
13 changed files with 112 additions and 156 deletions

View File

@@ -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;
}
}
}