mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-07 02:08:17 +02:00
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Robust.Shared.GameObjects;
|
|
|
|
namespace Robust.Shared.ViewVariables
|
|
{
|
|
internal abstract class ViewVariablesManagerShared
|
|
{
|
|
private readonly Dictionary<Type, HashSet<object>> _cachedTraits = new();
|
|
|
|
/// <summary>
|
|
/// Figures out which VV traits an object type has. This method is in shared so the client and server agree on this mess.
|
|
/// </summary>
|
|
/// <seealso cref="ViewVariablesBlobMetadata.Traits"/>
|
|
public ICollection<object> TraitIdsFor(Type type)
|
|
{
|
|
if (!_cachedTraits.TryGetValue(type, out var traits))
|
|
{
|
|
traits = new HashSet<object>();
|
|
_cachedTraits.Add(type, traits);
|
|
if (ViewVariablesUtility.TypeHasVisibleMembers(type))
|
|
{
|
|
traits.Add(ViewVariablesTraits.Members);
|
|
}
|
|
|
|
if (typeof(IEnumerable).IsAssignableFrom(type))
|
|
{
|
|
traits.Add(ViewVariablesTraits.Enumerable);
|
|
}
|
|
|
|
if (typeof(EntityUid).IsAssignableFrom(type))
|
|
{
|
|
traits.Add(ViewVariablesTraits.Entity);
|
|
}
|
|
}
|
|
|
|
return traits;
|
|
}
|
|
}
|
|
}
|