using System.Diagnostics.CodeAnalysis; using Robust.Client.Graphics; using Robust.Client.ResourceManagement; using Robust.Shared.Utility; namespace Content.Client.Stylesheets; public abstract partial class BaseStylesheet { #region Texture helpers /// /// Attempts to locate a texture within the stylesheet's roots. /// /// The relative path of the target resource. /// The retrieved texture, if any. /// Whether is null. public bool TryGetTexture(ResPath target, [NotNullWhen(true)] out Texture? texture) { if (TryGetResource(target, out TextureResource? resource)) { texture = resource.Texture; return true; } texture = null; return false; } /// /// Retrieves a texture, or throws. /// /// The relative path of the target texture. /// The retrieved texture /// Thrown if the texture does not exist within the stylesheet's roots. public Texture GetTexture(ResPath target) { return GetResource(target).Texture; } /// /// Retrieves a texture, or falls back to the specified root. The resource should be present at the fallback /// root, or else it throws /// /// /// This should be used to allow common sheetlets to be generic over multiple stylesheets without forcing other /// styles to have the resource present, if your sheetlet is stylesheet-specific you should not use this. /// /// The relative path of the target texture. /// The root that this resource will always exist at /// The retrieved texture /// Thrown if the texture does not exist in the fallback root. public Texture GetTextureOr(ResPath target, ResPath fallbackRoot) { return GetResourceOr(target, fallbackRoot).Texture; } #endregion }