mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-06 17:58:05 +02:00
58 lines
2.0 KiB
C#
58 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Utility;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.Server.ViewVariables.Traits
|
|
{
|
|
internal sealed class ViewVariablesTraitEntity : ViewVariablesTrait
|
|
{
|
|
private readonly IEntity _entity;
|
|
|
|
public ViewVariablesTraitEntity(IViewVariablesSession session) : base(session)
|
|
{
|
|
_entity = (IEntity) Session.Object;
|
|
}
|
|
|
|
public override ViewVariablesBlob? DataRequest(ViewVariablesRequest viewVariablesRequest)
|
|
{
|
|
if (viewVariablesRequest is ViewVariablesRequestEntityComponents)
|
|
{
|
|
var list = new List<ViewVariablesBlobEntityComponents.Entry>();
|
|
// See engine#636 for why the Distinct() call.
|
|
foreach (var component in _entity.GetAllComponents())
|
|
{
|
|
var type = component.GetType();
|
|
list.Add(new ViewVariablesBlobEntityComponents.Entry
|
|
{Stringified = TypeAbbreviation.Abbreviate(type), FullName = type.FullName, ComponentName = component.Name});
|
|
}
|
|
|
|
return new ViewVariablesBlobEntityComponents
|
|
{
|
|
ComponentTypes = list
|
|
};
|
|
}
|
|
|
|
if (viewVariablesRequest is ViewVariablesRequestAllValidComponents)
|
|
{
|
|
var list = new List<string>();
|
|
|
|
var componentFactory = IoCManager.Resolve<IComponentFactory>();
|
|
|
|
foreach (var type in componentFactory.AllRegisteredTypes)
|
|
{
|
|
if (_entity.HasComponent(type))
|
|
continue;
|
|
|
|
list.Add(componentFactory.GetRegistration(type).Name);
|
|
}
|
|
|
|
return new ViewVariablesBlobAllValidComponents(){ComponentTypes = list};
|
|
}
|
|
|
|
return base.DataRequest(viewVariablesRequest);
|
|
}
|
|
}
|
|
}
|