mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using Robust.Client.Graphics;
|
|
using Robust.Client.ResourceManagement;
|
|
using Robust.Client.Utility;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Client.GameObjects
|
|
{
|
|
[RegisterComponent]
|
|
public sealed class IconComponent : Component, ISerializationHooks
|
|
{
|
|
public IDirectionalTextureProvider? Icon { get; private set; }
|
|
|
|
[DataField("sprite")]
|
|
private ResourcePath? rsi;
|
|
[DataField("state")]
|
|
private string? stateID;
|
|
|
|
void ISerializationHooks.AfterDeserialization()
|
|
{
|
|
if (rsi != null && stateID != null)
|
|
{
|
|
Icon = new SpriteSpecifier.Rsi(rsi, stateID).Frame0();
|
|
}
|
|
}
|
|
|
|
public const string LogCategory = "go.comp.icon";
|
|
const string SerializationCache = "icon";
|
|
|
|
private static IRsiStateLike TextureForConfig(IconComponent compData, IResourceCache resourceCache)
|
|
{
|
|
return compData.Icon?.Default ?? resourceCache.GetFallback<TextureResource>().Texture;
|
|
}
|
|
|
|
public static IRsiStateLike? GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
|
|
{
|
|
if (!prototype.Components.TryGetValue("Icon", out var compData))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return TextureForConfig((IconComponent)compData, resourceCache);
|
|
}
|
|
}
|
|
}
|