using Godot; using FileAccess = Godot.FileAccess; namespace Polonium.DataStructures; /// /// Represents a complete set of textures for UI button states. /// Automatically loads textures for Normal, Pressed, Disabled, Hover, and Focused states from a directory. /// public class TextureSet { /// /// Initializes a new instance of the class by loading textures from the specified path. /// /// The base path where texture files are located. public TextureSet(string path) { Normal = LoadTexture($"{path}/Normal"); Pressed = LoadTexture($"{path}/Pressed"); Disabled = LoadTexture($"{path}/Disabled"); Hover = LoadTexture($"{path}/Hover"); Focused = LoadTexture($"{path}/Focused"); } /// /// Gets the texture for the normal button state. /// public Texture2D Normal { get; init; } /// /// Gets the texture for the pressed button state. /// public Texture2D Pressed { get; init; } /// /// Gets the texture for the hover button state. /// public Texture2D Hover { get; init; } /// /// Gets the texture for the disabled button state. /// public Texture2D Disabled { get; init; } /// /// Gets the texture for the focused button state. /// public Texture2D Focused { get; init; } /// /// Loads a texture from the specified path, supporting both static PNG files and animated texture directories. /// /// The path to the texture file or directory. /// The loaded texture, or an empty texture if not found. private static Texture2D LoadTexture(string path) { Texture2D res = new(); if(FileAccess.FileExists($"{path}.png")) res = ResourceLoader.Load($"{path}.png"); else if(DirAccess.DirExistsAbsolute($"{path}.at_dir")) res = Utils.LoadAnimatedTextureFromDirectory($"{path}.at_dir"); return res; } }