Clean itemmapper (#29983)
* File scoped namespace * Format file * Fix param name in doc comment * Reflow doc comment --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -4,8 +4,8 @@ using Content.Shared.Whitelist;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Shared.Storage.EntitySystems
|
||||
{
|
||||
namespace Content.Shared.Storage.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// <c>ItemMapperSystem</c> is a system that on each initialization, insertion, removal of an entity from
|
||||
/// given <see cref="ItemMapperComponent"/> (with appropriate storage attached) will check each stored item to see
|
||||
@@ -44,8 +44,7 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
UpdateAppearance(uid, component);
|
||||
}
|
||||
|
||||
private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper,
|
||||
EntRemovedFromContainerMessage args)
|
||||
private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper, EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if (itemMapper.ContainerWhitelist != null && !itemMapper.ContainerWhitelist.Contains(args.Container.ID))
|
||||
return;
|
||||
@@ -53,7 +52,8 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
UpdateAppearance(uid, itemMapper);
|
||||
}
|
||||
|
||||
private void MapperEntityInserted(EntityUid uid, ItemMapperComponent itemMapper,
|
||||
private void MapperEntityInserted(EntityUid uid,
|
||||
ItemMapperComponent itemMapper,
|
||||
EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
if (itemMapper.ContainerWhitelist != null && !itemMapper.ContainerWhitelist.Contains(args.Container.ID))
|
||||
@@ -70,27 +70,30 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearanceComponent)
|
||||
&& TryGetLayers(uid, itemMapper, out var containedLayers))
|
||||
{
|
||||
_appearance.SetData(uid, StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers), appearanceComponent);
|
||||
_appearance.SetData(uid,
|
||||
StorageMapVisuals.LayerChanged,
|
||||
new ShowLayerData(containedLayers),
|
||||
appearanceComponent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method that iterates over storage of the entity in <paramref name="uid"/> and sets <paramref name="containedLayers"/> according to
|
||||
/// <paramref name="itemMapper"/> definition. It will have O(n*m) time behavior (n - number of entities in container, and m - number of
|
||||
/// definitions in <paramref name="containedLayers"/>.
|
||||
/// Method that iterates over storage of the entity in <paramref name="uid"/> and sets <paramref name="showLayers"/>
|
||||
/// according to <paramref name="itemMapper"/> definition. It will have O(n*m) time behavior
|
||||
/// (n - number of entities in container, and m - number of definitions in <paramref name="showLayers"/>).
|
||||
/// </summary>
|
||||
/// <param name="uid">EntityUid used to search the storage</param>
|
||||
/// <param name="itemMapper">component that contains definition used to map <see cref="Content.Shared.Whitelist.EntityWhitelist">whitelist</see> in
|
||||
/// <c>mapLayers</c> to string.
|
||||
/// <param name="itemMapper">component that contains definition used to map
|
||||
/// <see cref="EntityWhitelist">Whitelist</see> in <see cref="ItemMapperComponent.MapLayers"/> to string.
|
||||
/// </param>
|
||||
/// <param name="containedLayers">list of <paramref name="itemMapper"/> layers that should be visible</param>
|
||||
/// <param name="showLayers">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>
|
||||
private bool TryGetLayers(EntityUid uid,
|
||||
ItemMapperComponent itemMapper,
|
||||
out List<string> showLayers)
|
||||
private bool TryGetLayers(EntityUid uid, ItemMapperComponent itemMapper, out List<string> showLayers)
|
||||
{
|
||||
var containedLayers = _container.GetAllContainers(uid)
|
||||
.Where(c => itemMapper.ContainerWhitelist?.Contains(c.ID) ?? true).SelectMany(cont => cont.ContainedEntities).ToArray();
|
||||
.Where(c => itemMapper.ContainerWhitelist?.Contains(c.ID) ?? true)
|
||||
.SelectMany(cont => cont.ContainedEntities)
|
||||
.ToArray();
|
||||
|
||||
var list = new List<string>();
|
||||
foreach (var mapLayerData in itemMapper.MapLayers.Values)
|
||||
@@ -107,4 +110,3 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user