Construction graph improvements (#17960)
This commit is contained in:
committed by
GitHub
parent
fbf1d476f2
commit
9243050e1a
@@ -32,11 +32,14 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
val.Layer = layerName;
|
||||
}
|
||||
|
||||
if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent))
|
||||
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearanceComponent))
|
||||
{
|
||||
var list = new List<string>(component.MapLayers.Keys);
|
||||
_appearance.SetData(component.Owner, StorageMapVisuals.InitLayers, new ShowLayerData(list), appearanceComponent);
|
||||
_appearance.SetData(uid, StorageMapVisuals.InitLayers, new ShowLayerData(list), appearanceComponent);
|
||||
}
|
||||
|
||||
// Ensure appearance is correct with current contained entities.
|
||||
UpdateAppearance(uid, component);
|
||||
}
|
||||
|
||||
private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper,
|
||||
@@ -45,7 +48,7 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
if (itemMapper.ContainerWhitelist != null && !itemMapper.ContainerWhitelist.Contains(args.Container.ID))
|
||||
return;
|
||||
|
||||
UpdateAppearance(uid, itemMapper, args);
|
||||
UpdateAppearance(uid, itemMapper);
|
||||
}
|
||||
|
||||
private void MapperEntityInserted(EntityUid uid, ItemMapperComponent itemMapper,
|
||||
@@ -54,40 +57,43 @@ namespace Content.Shared.Storage.EntitySystems
|
||||
if (itemMapper.ContainerWhitelist != null && !itemMapper.ContainerWhitelist.Contains(args.Container.ID))
|
||||
return;
|
||||
|
||||
UpdateAppearance(uid, itemMapper, args);
|
||||
UpdateAppearance(uid, itemMapper);
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, ItemMapperComponent itemMapper, ContainerModifiedMessage message)
|
||||
private void UpdateAppearance(EntityUid uid, ItemMapperComponent? itemMapper = null)
|
||||
{
|
||||
if (EntityManager.TryGetComponent(itemMapper.Owner, out AppearanceComponent? appearanceComponent)
|
||||
&& TryGetLayers(message, itemMapper, out var containedLayers))
|
||||
if(!Resolve(uid, ref itemMapper))
|
||||
return;
|
||||
|
||||
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearanceComponent)
|
||||
&& TryGetLayers(uid, itemMapper, out var containedLayers))
|
||||
{
|
||||
_appearance.SetData(itemMapper.Owner, 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="msg"/> and sets <paramref name="containedLayers"/> according to
|
||||
/// 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"/>.
|
||||
/// </summary>
|
||||
/// <param name="msg">event with 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
|
||||
/// <c>mapLayers</c> to string.
|
||||
/// </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>
|
||||
private bool TryGetLayers(ContainerModifiedMessage msg,
|
||||
private bool TryGetLayers(EntityUid uid,
|
||||
ItemMapperComponent itemMapper,
|
||||
out List<string> showLayers)
|
||||
{
|
||||
var containedLayers = _container.GetAllContainers(msg.Container.Owner)
|
||||
var containedLayers = _container.GetAllContainers(uid)
|
||||
.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)
|
||||
{
|
||||
var count = containedLayers.Count(uid => mapLayerData.ServerWhitelist.IsValid(uid));
|
||||
var count = containedLayers.Count(ent => mapLayerData.ServerWhitelist.IsValid(ent));
|
||||
if (count >= mapLayerData.MinCount && count <= mapLayerData.MaxCount)
|
||||
{
|
||||
list.Add(mapLayerData.Layer);
|
||||
|
||||
Reference in New Issue
Block a user