mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Partial sprite component ECS * release notes * tests * Why * SetSnapCardinals * NoRotation * DirectionOverride * This is why I love distinct overrides that take in object * LayerSetData * ISerializationHooks continue to haunt me * Relocate SetShader * LayerSetSprite * LayerSetTexture * yipeeeee * LayerSetRsi * Remove GetFallbackState * LayerSet Scale,Rotation,Color,Visible * Fix LayerSetRsi * LayerSetOffset * LayerSetDirOffset * Add overrides that take in a Layer * LayerSetAnimationTime * LayerSetRenderingStrategy * Reduce Resolves, Add Layer.Index * Access * Try fix NREs * Asserts * LayerGetState * Cleanup * Merge helper partial classes * partial rendering * GetLayerDirectionCount * Cache local bounds * RenderLayer * RefreshCachedState * RoundToCardinalAngle * Fix the pr * Fix debug assert --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
88 lines
3.4 KiB
C#
88 lines
3.4 KiB
C#
using System;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.ResourceManagement;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Graphics;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Client.Utility
|
|
{
|
|
/// <summary>
|
|
/// Helper methods for resolving <see cref="SpriteSpecifier"/>s.
|
|
/// </summary>
|
|
public static class SpriteSpecifierExt
|
|
{
|
|
[Obsolete("Use SpriteSystem.GetTexture() instead")]
|
|
public static Texture GetTexture(this SpriteSpecifier.Texture texSpecifier, IResourceCache cache)
|
|
{
|
|
return cache
|
|
.GetResource<TextureResource>(SpriteSpecifierSerializer.TextureRoot / texSpecifier.TexturePath)
|
|
.Texture;
|
|
}
|
|
|
|
[Obsolete("Use SpriteSystem.GetState() instead")]
|
|
public static RSI.State GetState(this SpriteSpecifier.Rsi rsiSpecifier, IResourceCache cache)
|
|
{
|
|
if (!cache.TryGetResource<RSIResource>(SpriteSpecifierSerializer.TextureRoot / rsiSpecifier.RsiPath, out var theRsi))
|
|
{
|
|
var sys = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>();
|
|
Logger.Error("SpriteSpecifier failed to load RSI {0}", rsiSpecifier.RsiPath);
|
|
return sys.GetFallbackState();
|
|
}
|
|
|
|
if (theRsi.RSI.TryGetState(rsiSpecifier.RsiState, out var state))
|
|
{
|
|
return state;
|
|
}
|
|
|
|
Logger.Error($"SpriteSpecifier has invalid RSI state '{rsiSpecifier.RsiState}' for RSI: {rsiSpecifier.RsiPath}");
|
|
return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>().GetFallbackState();
|
|
}
|
|
|
|
[Obsolete("Use SpriteSystem.Frame0() instead")]
|
|
public static Texture Frame0(this SpriteSpecifier specifier)
|
|
{
|
|
return specifier.RsiStateLike().Default;
|
|
}
|
|
|
|
[Obsolete("Use SpriteSystem.RsiStateLike() instead")]
|
|
public static IDirectionalTextureProvider DirFrame0(this SpriteSpecifier specifier)
|
|
{
|
|
return specifier.RsiStateLike();
|
|
}
|
|
|
|
[Obsolete("Use SpriteSystem.RsiStateLike() instead")]
|
|
public static IRsiStateLike RsiStateLike(this SpriteSpecifier specifier)
|
|
{
|
|
var resC = IoCManager.Resolve<IResourceCache>();
|
|
switch (specifier)
|
|
{
|
|
case SpriteSpecifier.Texture tex:
|
|
return tex.GetTexture(resC);
|
|
|
|
case SpriteSpecifier.Rsi rsi:
|
|
return rsi.GetState(resC);
|
|
|
|
case SpriteSpecifier.EntityPrototype prototypeIcon:
|
|
var protMgr = IoCManager.Resolve<IPrototypeManager>();
|
|
var sys = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>();
|
|
if (!protMgr.TryIndex<EntityPrototype>(prototypeIcon.EntityPrototypeId, out var prototype))
|
|
{
|
|
Logger.Error("Failed to load PrototypeIcon {0}", prototypeIcon.EntityPrototypeId);
|
|
return sys.GetFallbackState();
|
|
}
|
|
|
|
return SpriteComponent.GetPrototypeIcon(prototype, resC);
|
|
|
|
default:
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
}
|
|
}
|