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 path, Direction direction = Direction.down)
{
string leftString = Class1.getShortenedDirectory(Path.Combine(path, info.leftString + ".png")).Remove(0, 1);
string rightString = Class1.getShortenedDirectory(Path.Combine(path, info.rightString + ".png")).Remove(0, 1);
string upString = Class1.getShortenedDirectory(Path.Combine(path, info.upString + ".png")).Remove(0, 1);
string downString = Class1.getShortenedDirectory(Path.Combine(path, info.downString + ".png")).Remove(0, 1);
this.leftTexture = new Texture2DExtended(helper, leftString);
this.rightTexture = new Texture2DExtended(helper, rightString);
this.upTexture = new Texture2DExtended(helper, upString);
this.downTexture = new Texture2DExtended(helper, downString);
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;
}
}
}
}