mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Added a basic server simulation framework for help with tests. * Moved as much as possible to Robust.Shared/Containers. Moved ContainerSlot from content to engine. * Moved ClientContainer to shared. * Merged client/server ContainerManagerComponents into a single shared version. * ContainerManagerComponent is now implicitly registered with the attributes. * Migrated to 2021 serialization technology. * Existing Unit Tests work. * More tests coverage. Fixed bug with transferring items between containers. * Container Type info is now sent over the network. * Merge client/server container systems. * Code cleanup. * Attempted to fix dictionary serialization. Logs warning when trying to check if an unknown GridId is paused. * Remove OldCode.
95 lines
2.7 KiB
C#
95 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.GameObjects;
|
|
|
|
namespace Robust.Client.GameObjects
|
|
{
|
|
public class ClientContainerSystem : ContainerSystem
|
|
{
|
|
private readonly HashSet<IEntity> _updateQueue = new();
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<UpdateContainerOcclusionMessage>(UpdateContainerOcclusion);
|
|
|
|
UpdatesBefore.Add(typeof(SpriteSystem));
|
|
}
|
|
|
|
private void UpdateContainerOcclusion(UpdateContainerOcclusionMessage ev)
|
|
{
|
|
_updateQueue.Add(ev.Entity);
|
|
}
|
|
|
|
public override void FrameUpdate(float frameTime)
|
|
{
|
|
base.FrameUpdate(frameTime);
|
|
|
|
foreach (var toUpdate in _updateQueue)
|
|
{
|
|
if (toUpdate.Deleted)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
UpdateEntityRecursively(toUpdate);
|
|
}
|
|
|
|
_updateQueue.Clear();
|
|
}
|
|
|
|
private static void UpdateEntityRecursively(IEntity entity)
|
|
{
|
|
// TODO: Since we are recursing down,
|
|
// we could cache ShowContents data here to speed it up for children.
|
|
// Am lazy though.
|
|
UpdateEntity(entity);
|
|
|
|
foreach (var child in entity.Transform.Children)
|
|
{
|
|
UpdateEntityRecursively(child.Owner);
|
|
}
|
|
}
|
|
|
|
private static void UpdateEntity(IEntity entity)
|
|
{
|
|
if (entity.TryGetComponent(out SpriteComponent? sprite))
|
|
{
|
|
sprite.ContainerOccluded = false;
|
|
|
|
// We have to recursively scan for containers upwards in case of nested containers.
|
|
var tempParent = entity;
|
|
while (tempParent.TryGetContainer(out var container))
|
|
{
|
|
if (!container.ShowContents)
|
|
{
|
|
sprite.ContainerOccluded = true;
|
|
break;
|
|
}
|
|
|
|
tempParent = container.Owner;
|
|
}
|
|
}
|
|
|
|
if (entity.TryGetComponent(out PointLightComponent? light))
|
|
{
|
|
light.ContainerOccluded = false;
|
|
|
|
// We have to recursively scan for containers upwards in case of nested containers.
|
|
var tempParent = entity;
|
|
while (tempParent.TryGetContainer(out var container))
|
|
{
|
|
if (container.OccludesLight)
|
|
{
|
|
light.ContainerOccluded = true;
|
|
break;
|
|
}
|
|
|
|
tempParent = container.Owner;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|