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:
ShadowCommander
2024-07-13 20:27:39 -07:00
committed by GitHub
parent 922be64290
commit bdf7293cfb

View File

@@ -4,8 +4,8 @@ using Content.Shared.Whitelist;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Containers; using Robust.Shared.Containers;
namespace Content.Shared.Storage.EntitySystems namespace Content.Shared.Storage.EntitySystems;
{
/// <summary> /// <summary>
/// <c>ItemMapperSystem</c> is a system that on each initialization, insertion, removal of an entity from /// <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 /// 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); UpdateAppearance(uid, component);
} }
private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper, private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper, EntRemovedFromContainerMessage args)
EntRemovedFromContainerMessage args)
{ {
if (itemMapper.ContainerWhitelist != null && !itemMapper.ContainerWhitelist.Contains(args.Container.ID)) if (itemMapper.ContainerWhitelist != null && !itemMapper.ContainerWhitelist.Contains(args.Container.ID))
return; return;
@@ -53,7 +52,8 @@ namespace Content.Shared.Storage.EntitySystems
UpdateAppearance(uid, itemMapper); UpdateAppearance(uid, itemMapper);
} }
private void MapperEntityInserted(EntityUid uid, ItemMapperComponent itemMapper, private void MapperEntityInserted(EntityUid uid,
ItemMapperComponent itemMapper,
EntInsertedIntoContainerMessage args) EntInsertedIntoContainerMessage args)
{ {
if (itemMapper.ContainerWhitelist != null && !itemMapper.ContainerWhitelist.Contains(args.Container.ID)) 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) if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearanceComponent)
&& TryGetLayers(uid, itemMapper, out var containedLayers)) && 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> /// <summary>
/// Method that iterates over storage of the entity in <paramref name="uid"/> and sets <paramref name="containedLayers"/> according to /// Method that iterates over storage of the entity in <paramref name="uid"/> and sets <paramref name="showLayers"/>
/// <paramref name="itemMapper"/> definition. It will have O(n*m) time behavior (n - number of entities in container, and m - number of /// according to <paramref name="itemMapper"/> definition. It will have O(n*m) time behavior
/// definitions in <paramref name="containedLayers"/>. /// (n - number of entities in container, and m - number of definitions in <paramref name="showLayers"/>).
/// </summary> /// </summary>
/// <param name="uid">EntityUid used to search the storage</param> /// <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 /// <param name="itemMapper">component that contains definition used to map
/// <c>mapLayers</c> to string. /// <see cref="EntityWhitelist">Whitelist</see> in <see cref="ItemMapperComponent.MapLayers"/> to string.
/// </param> /// </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> /// <returns>false if <c>msg.Container.Owner</c> is not a storage, true otherwise.</returns>
private bool TryGetLayers(EntityUid uid, private bool TryGetLayers(EntityUid uid, ItemMapperComponent itemMapper, out List<string> showLayers)
ItemMapperComponent itemMapper,
out List<string> showLayers)
{ {
var containedLayers = _container.GetAllContainers(uid) 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>(); var list = new List<string>();
foreach (var mapLayerData in itemMapper.MapLayers.Values) foreach (var mapLayerData in itemMapper.MapLayers.Values)
@@ -107,4 +110,3 @@ namespace Content.Shared.Storage.EntitySystems
return true; return true;
} }
} }
}