2018-03-19 07:06:49 +08:00
|
|
|
using CustomNPCFramework.Framework.NPCS;
|
2018-02-24 17:04:35 +08:00
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using StardewValley;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
namespace CustomNPCFramework.Framework.ModularNpcs
|
2018-02-24 17:04:35 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Used as a wrapper for the npcs to hold sprite information.</summary>
|
2018-02-24 17:04:35 +08:00
|
|
|
public class Sprite
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>The actual sprite to draw for the npc.</summary>
|
2018-02-24 17:04:35 +08:00
|
|
|
public AnimatedSprite sprite;
|
2018-12-30 18:00:05 +08:00
|
|
|
|
|
|
|
/// <summary>The path to the texture to use for the animated sprite.</summary>
|
2018-02-24 17:04:35 +08:00
|
|
|
public string relativePath;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
2019-01-06 13:31:40 +08:00
|
|
|
/// <param name="relativePath">The relative path to the file.</param>
|
|
|
|
public Sprite(string relativePath)
|
2018-02-24 17:04:35 +08:00
|
|
|
{
|
2019-01-06 13:31:40 +08:00
|
|
|
this.relativePath = relativePath;
|
2018-03-17 19:04:04 +08:00
|
|
|
try
|
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
this.sprite = new AnimatedSprite();
|
|
|
|
Texture2D text = Class1.ModHelper.Content.Load<Texture2D>(this.relativePath);
|
2018-12-30 18:00:05 +08:00
|
|
|
var reflect = Class1.ModHelper.Reflection.GetField<Texture2D>(this.sprite, "Texture", true);
|
2018-05-01 09:21:31 +08:00
|
|
|
reflect.SetValue(text);
|
2018-12-30 18:00:05 +08:00
|
|
|
|
2018-03-17 19:04:04 +08:00
|
|
|
}
|
2018-12-30 18:00:05 +08:00
|
|
|
catch
|
2018-03-17 19:04:04 +08:00
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
this.sprite = new AnimatedSprite();
|
|
|
|
Texture2D text = Class1.ModHelper.Content.Load<Texture2D>(this.relativePath);
|
|
|
|
var reflect = Class1.ModHelper.Reflection.GetField<Texture2D>(this.sprite, "Texture", true);
|
|
|
|
reflect.SetValue(text);
|
2018-03-17 19:04:04 +08:00
|
|
|
}
|
2018-05-01 09:21:31 +08:00
|
|
|
this.sprite.SpriteWidth = this.sprite.Texture.Width;
|
|
|
|
this.sprite.SpriteHeight = this.sprite.Texture.Height;
|
2018-02-24 17:04:35 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
2018-03-04 20:36:46 +08:00
|
|
|
/// <param name="path">Used to hold the path to the asset.</param>
|
|
|
|
/// <param name="texture">Used to assign the texture to the sprite from a pre-loaded asset.</param>
|
2018-05-01 09:21:31 +08:00
|
|
|
public Sprite(string path, string texture)
|
2018-03-04 20:36:46 +08:00
|
|
|
{
|
|
|
|
this.relativePath = path;
|
|
|
|
this.sprite = new AnimatedSprite(texture);
|
2018-05-01 09:21:31 +08:00
|
|
|
this.sprite.SpriteWidth = this.sprite.Texture.Width;
|
|
|
|
this.sprite.SpriteHeight = this.sprite.Texture.Height;
|
2018-03-04 20:36:46 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Sets the npc's portrait to be this portrait texture.</summary>
|
|
|
|
public void setCharacterSpriteFromThis(ExtendedNpc npc)
|
2018-02-24 17:04:35 +08:00
|
|
|
{
|
|
|
|
npc.Sprite = this.sprite;
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Reloads the texture for the NPC portrait.</summary>
|
2018-02-24 17:04:35 +08:00
|
|
|
public void reload()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
var text = Class1.ModHelper.Reflection.GetField<Texture2D>(this.sprite.Texture, "Texture", true);
|
|
|
|
Texture2D loaded = Class1.ModHelper.Content.Load<Texture2D>(this.relativePath);
|
2018-05-01 09:21:31 +08:00
|
|
|
text.SetValue(loaded);
|
2018-02-24 17:04:35 +08:00
|
|
|
}
|
2018-03-19 07:06:49 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc.</summary>
|
|
|
|
public void setLeft(ExtendedNpc npc)
|
2018-03-19 07:06:49 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
npc.characterRenderer?.setLeft();
|
2018-03-19 07:06:49 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc.</summary>
|
|
|
|
public void setRight(ExtendedNpc npc)
|
2018-03-19 07:06:49 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
npc.characterRenderer?.setRight();
|
2018-03-19 07:06:49 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc.</summary>
|
|
|
|
public void setDown(ExtendedNpc npc)
|
2018-03-19 07:06:49 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
npc.characterRenderer?.setDown();
|
2018-03-19 07:06:49 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc.</summary>
|
|
|
|
public void setUp(ExtendedNpc npc)
|
2018-03-19 07:06:49 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
npc.characterRenderer?.setUp();
|
2018-03-19 07:06:49 +08:00
|
|
|
}
|
2018-02-24 17:04:35 +08:00
|
|
|
}
|
|
|
|
}
|