using System.IO; using CustomNPCFramework.Framework.Enums; using StardewModdingAPI; using StardustCore.UIUtilities; namespace CustomNPCFramework.Framework.Graphics { /// A class that's used to hold textures for different directions. public class DirectionalTexture { /// The left texture for this group. public Texture2DExtended leftTexture; /// The right texture for this group. public Texture2DExtended rightTexture; /// The down textiure for this group. public Texture2DExtended downTexture; /// The up texture for this group. public Texture2DExtended upTexture; /// The current texture for this group. public Texture2DExtended currentTexture; /// Construct an instance. /// The left texture to use. /// The right texture to use. /// The up texture to use. /// The down texture to use. /// The direction texture for the sprite to face. public DirectionalTexture(Texture2DExtended left, Texture2DExtended right, Texture2DExtended up, Texture2DExtended down, Direction direction = Direction.down) { this.leftTexture = left; this.rightTexture = right; this.upTexture = up; this.downTexture = down; switch (direction) { case Direction.left: this.currentTexture = this.leftTexture; break; case Direction.right: this.currentTexture = this.rightTexture; break; case Direction.up: this.currentTexture = this.upTexture; break; case Direction.down: this.currentTexture = this.downTexture; break; } } public DirectionalTexture(IModHelper helper, NamePairings info, string relativePath, Direction direction = Direction.down) { this.leftTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.leftString}.png")); this.rightTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.rightString}.png")); this.upTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.upString}.png")); this.downTexture = new Texture2DExtended(helper, Path.Combine(relativePath, $"{info.downString}.png")); switch (direction) { case Direction.left: this.currentTexture = this.leftTexture; break; case Direction.right: this.currentTexture = this.rightTexture; break; case Direction.up: this.currentTexture = this.upTexture; break; case Direction.down: this.currentTexture = this.downTexture; break; } } /// Sets the direction of this current texture to left. public void setLeft() { this.currentTexture = this.leftTexture; } /// Sets the direction of this current texture to up. public void setUp() { this.currentTexture = this.upTexture; } /// Sets the direction of this current texture to down. public void setDown() { this.currentTexture = this.downTexture; } /// Sets the direction of this current texture to right. public void setRight() { this.currentTexture = this.rightTexture; } /// Gets the texture from this texture group depending on the direction. /// The facing direction. public virtual Texture2DExtended getTextureFromDirection(Direction direction) { switch (direction) { case Direction.left: return this.leftTexture; case Direction.right: return this.rightTexture; case Direction.up: return this.upTexture; case Direction.down: return this.downTexture; default: return null; } } } }