Finished commenting on all functions in the mod. Now just to write up some documentation.
This commit is contained in:
parent
a915a06460
commit
44d2f4e7e9
|
@ -42,14 +42,30 @@ namespace CustomNPCFramework
|
|||
|
||||
/// </summary>
|
||||
|
||||
|
||||
public class Class1 : Mod
|
||||
{
|
||||
/// <summary>
|
||||
/// The mod helper for the mod.
|
||||
/// </summary>
|
||||
public static IModHelper ModHelper;
|
||||
/// <summary>
|
||||
/// The mod monitor for the mod.
|
||||
/// </summary>
|
||||
public static IMonitor ModMonitor;
|
||||
|
||||
/// <summary>
|
||||
/// The npc tracker for the mod. Keeps track of all npcs added by the custom framework and cleans them up during saving.
|
||||
/// </summary>
|
||||
public static NPCTracker npcTracker;
|
||||
/// <summary>
|
||||
/// Keeps track of all of the asets/textures added in by the framework. Also manages all of the asset managers that are the ones actually managing the textures.
|
||||
/// </summary>
|
||||
public static AssetPool assetPool;
|
||||
|
||||
/// <summary>
|
||||
/// Ran when loading the SMAPI. Used to initialize data.
|
||||
/// </summary>
|
||||
/// <param name="helper"></param>
|
||||
public override void Entry(IModHelper helper)
|
||||
{
|
||||
ModHelper = this.Helper;
|
||||
|
@ -71,24 +87,43 @@ namespace CustomNPCFramework
|
|||
assetPool.loadAllAssets();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the asset pool with some test variables.
|
||||
/// </summary>
|
||||
public void initializeAssetPool()
|
||||
{
|
||||
string path = Path.Combine(ModHelper.DirectoryPath, "Content", "Graphics", "NPCS");
|
||||
assetPool.getAssetManager("testNPC").addPathCreateDirectory(new KeyValuePair<string, string>("characters", path));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A function that is called when the game finishes saving.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SaveEvents_AfterSave(object sender, EventArgs e)
|
||||
{
|
||||
npcTracker.afterSave();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A function that is called when the game is about to load. Used to clean up all the npcs from the game world to prevent it from crashing.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SaveEvents_BeforeSave(object sender, EventArgs e)
|
||||
{
|
||||
npcTracker.cleanUpBeforeSave();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called upon 60 times a second. For testing purposes only. Will remove in future release.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void GameEvents_UpdateTick(object sender, EventArgs e)
|
||||
{
|
||||
/*
|
||||
if (Game1.player.currentLocation == null) return;
|
||||
if (Game1.activeClickableMenu != null) return;
|
||||
foreach (var v in Game1.player.currentLocation.characters)
|
||||
|
@ -101,8 +136,14 @@ namespace CustomNPCFramework
|
|||
//v.MovePosition(Game1.currentGameTime, Game1.viewport, Game1.player.currentLocation);
|
||||
//ModMonitor.Log(v.sprite.spriteHeight.ToString());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the player's location changes.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LocationEvents_CurrentLocationChanged(object sender, StardewModdingAPI.Events.EventArgsCurrentLocationChanged e)
|
||||
{
|
||||
|
||||
|
@ -124,6 +165,9 @@ namespace CustomNPCFramework
|
|||
npcTracker.addNewNPCToLocation(Game1.getLocationFromName("BusStop", false), merch,new Vector2(2,23));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to initialize examples for other modders to look at as reference.
|
||||
/// </summary>
|
||||
public void initializeExamples()
|
||||
{
|
||||
return;
|
||||
|
@ -153,6 +197,11 @@ namespace CustomNPCFramework
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to splice the mod directory to get relative paths.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static string getShortenedDirectory(string path)
|
||||
{
|
||||
string lol = (string)path.Clone();
|
||||
|
@ -167,6 +216,11 @@ namespace CustomNPCFramework
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to finish cleaning up absolute asset paths into a shortened relative path.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static string getRelativeDirectory(string path)
|
||||
{
|
||||
string s = getShortenedDirectory(path);
|
||||
|
|
|
@ -37,7 +37,6 @@ namespace CustomNPCFramework.Framework.Graphics
|
|||
public Rectangle currentAsset;
|
||||
|
||||
public int index;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
|
@ -59,7 +58,6 @@ namespace CustomNPCFramework.Framework.Graphics
|
|||
|
||||
this.index = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the path to the current texture.
|
||||
/// </summary>
|
||||
|
|
|
@ -16,11 +16,26 @@ namespace CustomNPCFramework.Framework.ModularNPCS
|
|||
/// </summary>
|
||||
public class AnimatedSpriteCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// The left sprite for this sprite asset part.
|
||||
/// </summary>
|
||||
AnimatedSpriteExtended leftSprite;
|
||||
/// <summary>
|
||||
/// The right sprite for this sprite asset part.
|
||||
/// </summary>
|
||||
AnimatedSpriteExtended rightSprite;
|
||||
/// <summary>
|
||||
/// The up sprite for this sprite asset part.
|
||||
/// </summary>
|
||||
AnimatedSpriteExtended upSprite;
|
||||
/// <summary>
|
||||
/// The down sprite for this sprite asset part.
|
||||
/// </summary>
|
||||
AnimatedSpriteExtended downSprite;
|
||||
|
||||
/// <summary>
|
||||
/// The current sprite for this sprite collection. This is one of the four directions for this collection.
|
||||
/// </summary>
|
||||
public AnimatedSpriteExtended currentSprite;
|
||||
|
||||
/// <summary>
|
||||
|
@ -55,6 +70,9 @@ namespace CustomNPCFramework.Framework.ModularNPCS
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reloads all of the directional textures for this texture collection.
|
||||
/// </summary>
|
||||
public virtual void reload()
|
||||
{
|
||||
this.leftSprite.reload();
|
||||
|
@ -64,23 +82,32 @@ namespace CustomNPCFramework.Framework.ModularNPCS
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current
|
||||
/// Sets the current sprite direction to face left.
|
||||
/// </summary>
|
||||
public void setLeft()
|
||||
{
|
||||
this.currentSprite = leftSprite;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current sprite direction to face right.
|
||||
/// </summary>
|
||||
public void setRight()
|
||||
{
|
||||
this.currentSprite = rightSprite;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current sprite direction to face down.
|
||||
/// </summary>
|
||||
public void setDown()
|
||||
{
|
||||
this.currentSprite = downSprite;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current sprite direction to face up.
|
||||
/// </summary>
|
||||
public void setUp()
|
||||
{
|
||||
this.currentSprite = upSprite;
|
||||
|
@ -140,18 +167,22 @@ namespace CustomNPCFramework.Framework.ModularNPCS
|
|||
/// <summary>
|
||||
/// Animate the current sprite. Theoreticlly works from index offset to how many frames
|
||||
/// </summary>
|
||||
/// <param name="intervalFromCharacter"></param>
|
||||
public void Animate(float intervalFromCharacter,bool loop=true)
|
||||
/// <param name="intervalDelay">The delay in milliseconds between frames.</param>
|
||||
public void Animate(float intervalDelay,bool loop=true)
|
||||
{
|
||||
//ANIMATE AND UPDATE SOURCE RECTANGLE NOT WORKING!!!! FIGURE THIS OUT!!!!
|
||||
//Class1.ModMonitor.Log("Current sprite frame:"+this.currentSprite.sprite.currentFrame.ToString());
|
||||
//Class1.ModMonitor.Log("Am I ignoring something??: " + this.currentSprite.sprite.ignoreSourceRectUpdates);
|
||||
//Class1.ModMonitor.Log("Current Sprite Source Rect:" + this.currentSprite.sprite.sourceRect);
|
||||
//Class1.ModMonitor.Log("Sprite width: " + this.currentSprite.sprite.spriteWidth);
|
||||
//Class1.ModMonitor.Log("Sprite width: " + this.currentSprite.sprite.spriteHeight);
|
||||
this.Animate(Game1.currentGameTime, 0,2, intervalFromCharacter,this.currentSprite.sprite,loop);
|
||||
this.Animate(Game1.currentGameTime, 0,2, intervalDelay,this.currentSprite.sprite,loop);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Animate the current sprite.
|
||||
/// </summary>
|
||||
/// <param name="gameTime">The game time from Monogames/XNA</param>
|
||||
/// <param name="startFrame">The starting frame of the animation on the sprite sheet.</param>
|
||||
/// <param name="numberOfFrames">The number of frames to animate the sprite.</param>
|
||||
/// <param name="interval">The delay between frames in milliseconds.</param>
|
||||
/// <param name="sprite">The animated sprite from the npc.</param>
|
||||
/// <param name="loop">If true, the animation plays over and over again.</param>
|
||||
/// <returns></returns>
|
||||
public virtual bool Animate(GameTime gameTime, int startFrame, int numberOfFrames, float interval, AnimatedSprite sprite, bool loop=true)
|
||||
{
|
||||
if (sprite.CurrentFrame >= startFrame + numberOfFrames + 1 || sprite.CurrentFrame < startFrame)
|
||||
|
@ -173,6 +204,10 @@ namespace CustomNPCFramework.Framework.ModularNPCS
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the source rectangle on the sprite sheet. Needed for animation.
|
||||
/// </summary>
|
||||
/// <param name="sprite"></param>
|
||||
public virtual void UpdateSourceRect(AnimatedSprite sprite)
|
||||
{
|
||||
if (sprite.ignoreSourceRectUpdates)
|
||||
|
|
|
@ -8,9 +8,18 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace CustomNPCFramework.Framework.ModularNPCS
|
||||
{
|
||||
/// <summary>
|
||||
/// Used as a wrapper for the AnimatedSprite class.
|
||||
/// </summary>
|
||||
public class AnimatedSpriteExtended
|
||||
{
|
||||
/// <summary>
|
||||
/// The actual sprite of the object.
|
||||
/// </summary>
|
||||
public AnimatedSprite sprite;
|
||||
/// <summary>
|
||||
/// The path to the texture to load the sprite from.
|
||||
/// </summary>
|
||||
public string path;
|
||||
|
||||
|
||||
|
|
|
@ -11,17 +11,52 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases
|
||||
{
|
||||
/// <summary>
|
||||
/// A class used to reference the different textures used to comprise the different parts for character rendering.
|
||||
/// </summary>
|
||||
public class StandardCharacterAnimation :CharacterAnimationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to hold all of the information for the npc hair part.
|
||||
/// </summary>
|
||||
public AnimatedSpriteCollection hair;
|
||||
/// <summary>
|
||||
/// Used to hold all of the information for the npc body part.
|
||||
/// </summary>
|
||||
public AnimatedSpriteCollection body;
|
||||
/// <summary>
|
||||
/// Used to hold all of the information for the npc eyes part.
|
||||
/// </summary>
|
||||
public AnimatedSpriteCollection eyes;
|
||||
/// <summary>
|
||||
/// Used to hold all of the information for the npc shirt part.
|
||||
/// </summary>
|
||||
public AnimatedSpriteCollection shirt;
|
||||
/// <summary>
|
||||
/// Used to hold all of the information for the npc pants part.
|
||||
/// </summary>
|
||||
public AnimatedSpriteCollection pants;
|
||||
/// <summary>
|
||||
/// Used to hold all of the information for the npc shoes part.
|
||||
/// </summary>
|
||||
public AnimatedSpriteCollection shoes;
|
||||
/// <summary>
|
||||
/// Used to hold all of the information for draw colors for the different parts.
|
||||
/// </summary>
|
||||
public StandardColorCollection drawColors;
|
||||
public List<AnimatedSpriteCollection> accessories;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="bodyAnimation">The collection of textures to be used for the body part for the npc.</param>
|
||||
/// <param name="eyeAnimation">The collection of textures to be used for the eyes part for the npc.</param>
|
||||
/// <param name="hairAnimation">The collection of textures to be used for the hair part for the npc.</param>
|
||||
/// <param name="shirtAnimation">The collection of textures to be used for the shirt part for the npc.</param>
|
||||
/// <param name="pantsAnimation">The collection of textures to be used for the pants part for the npc.</param>
|
||||
/// <param name="shoesAnimation">The collection of textures to be used for the shoes part for the npc.</param>
|
||||
/// <param name="accessoriesWithAnimations">The collection of textures to be used for the accessories part for the npc.</param>
|
||||
/// <param name="DrawColors">The collection of draw colors for the different parts for the npc.</param>
|
||||
public StandardCharacterAnimation(AnimatedSpriteCollection bodyAnimation, AnimatedSpriteCollection eyeAnimation, AnimatedSpriteCollection hairAnimation, AnimatedSpriteCollection shirtAnimation, AnimatedSpriteCollection pantsAnimation, AnimatedSpriteCollection shoesAnimation,List<AnimatedSpriteCollection> accessoriesWithAnimations, StandardColorCollection DrawColors) :base()
|
||||
{
|
||||
this.body = bodyAnimation;
|
||||
|
@ -34,6 +69,9 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases
|
|||
this.drawColors = DrawColors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets all of the different textures to face left.
|
||||
/// </summary>
|
||||
public override void setLeft()
|
||||
{
|
||||
this.body.setLeft();
|
||||
|
@ -48,6 +86,9 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases
|
|||
accessory.setLeft();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets all of the different textures to face right.
|
||||
/// </summary>
|
||||
public override void setRight()
|
||||
{
|
||||
this.body.setRight();
|
||||
|
@ -62,6 +103,9 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases
|
|||
accessory.setRight();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets all of the different textures to face up.
|
||||
/// </summary>
|
||||
public override void setUp()
|
||||
{
|
||||
this.body.setUp();
|
||||
|
@ -76,6 +120,9 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases
|
|||
accessory.setUp();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets all of the different textures to face down.
|
||||
/// </summary>
|
||||
public override void setDown()
|
||||
{
|
||||
this.body.setDown();
|
||||
|
@ -91,6 +138,9 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reloads all of the sprite textures.
|
||||
/// </summary>
|
||||
public override void reload()
|
||||
{
|
||||
this.body.reload();
|
||||
|
@ -101,6 +151,11 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases
|
|||
this.shoes.reload();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Animates all of the textures for this sprite.
|
||||
/// </summary>
|
||||
/// <param name="animationInterval">The delay in milliseconds between animation frames.</param>
|
||||
/// <param name="loop">Determines if the animation continuously plays over and over.</param>
|
||||
public override void Animate(float animationInterval,bool loop=true)
|
||||
{
|
||||
this.body.Animate(animationInterval,loop);
|
||||
|
|
|
@ -12,11 +12,29 @@ namespace CustomNPCFramework.Framework.ModularNPCS.ColorCollections
|
|||
/// </summary>
|
||||
public class StandardColorCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// The draw color to be used for the body sprite for the npc.
|
||||
/// </summary>
|
||||
public Color bodyColor;
|
||||
/// <summary>
|
||||
/// The draw color to be used for the eye sprite for the npc.
|
||||
/// </summary>
|
||||
public Color eyeColor;
|
||||
/// <summary>
|
||||
/// The draw color to be used for the hair sprite for the npc.
|
||||
/// </summary>
|
||||
public Color hairColor;
|
||||
/// <summary>
|
||||
/// The draw color to be used for the shirt sprite for the npc.
|
||||
/// </summary>
|
||||
public Color shirtColor;
|
||||
/// <summary>
|
||||
/// The draw color to be used for the bottoms/pants sprite for the npc.
|
||||
/// </summary>
|
||||
public Color bottomsColor;
|
||||
/// <summary>
|
||||
/// The draw color to be used for the shoes sprite for the npc.
|
||||
/// </summary>
|
||||
public Color shoesColor;
|
||||
|
||||
/// <summary>
|
||||
|
@ -67,6 +85,12 @@ namespace CustomNPCFramework.Framework.ModularNPCS.ColorCollections
|
|||
if (color == null) color = Color.White;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to mix colors together.
|
||||
/// </summary>
|
||||
/// <param name="cBase">The base color to mix.</param>
|
||||
/// <param name="cMult">The modifier color to mix.</param>
|
||||
/// <returns>A color that is a mix between the two colors passed in.</returns>
|
||||
public static Color colorMult(Color cBase, Color cMult)
|
||||
{
|
||||
Vector3 color1 = cBase.ToVector3();
|
||||
|
|
|
@ -6,11 +6,26 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace CustomNPCFramework.Framework.ModularNPCS.ModularRenderers
|
||||
{
|
||||
class AnimationKeys
|
||||
/// <summary>
|
||||
/// A class used instead of an enum to hold keys for all of the different animations.
|
||||
/// </summary>
|
||||
public class AnimationKeys
|
||||
{
|
||||
/// <summary>
|
||||
/// The string that is used for the standing animation.
|
||||
/// </summary>
|
||||
public static string standingKey = "standing";
|
||||
/// <summary>
|
||||
/// The string that is used for the walking/moving animation.
|
||||
/// </summary>
|
||||
public static string walkingKey = "walking";
|
||||
/// <summary>
|
||||
/// The string that is used for the sitting animation.
|
||||
/// </summary>
|
||||
public static string sittingKey = "sitting";
|
||||
/// <summary>
|
||||
/// The string that is used for the swimming animation.
|
||||
/// </summary>
|
||||
public static string swimmingKey = "swimming";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases;
|
||||
using CustomNPCFramework.Framework.Enums;
|
||||
using CustomNPCFramework.Framework.Graphics;
|
||||
using CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases;
|
||||
using CustomNPCFramework.Framework.NPCS;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
@ -11,11 +13,26 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace CustomNPCFramework.Framework.ModularNPCS.ModularRenderers
|
||||
{
|
||||
/// <summary>
|
||||
/// A class used to hold all of the textures/animations/information to make modular npc rendering possible.
|
||||
/// </summary>
|
||||
public class BasicRenderer
|
||||
{
|
||||
/// <summary>
|
||||
/// Dictionary that holds key pair values of (animationName,Animation). USed to manage multiple animations.
|
||||
/// </summary>
|
||||
public Dictionary<string, StandardCharacterAnimation> animationList;
|
||||
/// <summary>
|
||||
/// Used to keep track of what animation is currently being used.
|
||||
/// </summary>
|
||||
public StandardCharacterAnimation currentAnimation;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="standingAnimation">The animation information to be used when the character is standing.</param>
|
||||
/// <param name="walkingAnimation">The animation information to be used when the character is walking/moving.</param>
|
||||
/// <param name="swimmingAnimation">The animation information to be used when the character is walking/moving.</param>
|
||||
public BasicRenderer(StandardCharacterAnimation standingAnimation,StandardCharacterAnimation walkingAnimation, StandardCharacterAnimation swimmingAnimation)
|
||||
{
|
||||
animationList = new Dictionary<string, StandardCharacterAnimation>();
|
||||
|
@ -28,7 +45,7 @@ namespace CustomNPCFramework.Framework.ModularNPCS.ModularRenderers
|
|||
/// <summary>
|
||||
/// Sets the animation associated with the key name; If it fails the npc will just default to standing.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="key">The name of the animation to swap the current animation to.</param>
|
||||
public virtual void setAnimation(string key)
|
||||
{
|
||||
this.currentAnimation = animationList[key];
|
||||
|
@ -39,6 +56,10 @@ namespace CustomNPCFramework.Framework.ModularNPCS.ModularRenderers
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the direction of the current animated sprite respectively.
|
||||
/// </summary>
|
||||
/// <param name="facingDirection">The direction to face. 0=up, 1=right, 2= down, 3=left.</param>
|
||||
public virtual void setDirection(int facingDirection)
|
||||
{
|
||||
if (facingDirection == 0) setUp();
|
||||
|
@ -47,26 +68,54 @@ namespace CustomNPCFramework.Framework.ModularNPCS.ModularRenderers
|
|||
if (facingDirection == 2) setLeft();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the direction of the current animated sprite respectively to the direction passed in.
|
||||
/// </summary>
|
||||
/// <param name="direction">The direction to face.</param>
|
||||
public virtual void setDirection(Direction direction)
|
||||
{
|
||||
if (direction == Direction.up) setUp();
|
||||
if (direction == Direction.right) setRight();
|
||||
if (direction == Direction.down) setDown();
|
||||
if (direction == Direction.left) setLeft();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current animated sprite to face left.
|
||||
/// </summary>
|
||||
public virtual void setLeft()
|
||||
{
|
||||
this.currentAnimation.setLeft();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current animated sprite to face right.
|
||||
/// </summary>
|
||||
public virtual void setRight()
|
||||
{
|
||||
this.currentAnimation.setRight();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current animated sprite to face up.
|
||||
/// </summary>
|
||||
public virtual void setUp()
|
||||
{
|
||||
this.currentAnimation.setUp();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current animated sprite to face down.
|
||||
/// </summary>
|
||||
public virtual void setDown()
|
||||
{
|
||||
this.currentAnimation.setDown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to reload all of the sprites pertaining to all of the animations stored in this renderer.
|
||||
/// </summary>
|
||||
public virtual void reloadSprites()
|
||||
{
|
||||
foreach(var v in this.animationList)
|
||||
|
@ -124,6 +173,11 @@ namespace CustomNPCFramework.Framework.ModularNPCS.ModularRenderers
|
|||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Animates the current animation for the current sprite.
|
||||
/// </summary>
|
||||
/// <param name="interval"></param>
|
||||
/// <param name="loop"></param>
|
||||
public virtual void Animate(float interval, bool loop=true)
|
||||
{
|
||||
this.currentAnimation.Animate(interval,loop);
|
||||
|
|
|
@ -8,9 +8,18 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace CustomNPCFramework.Framework.ModularNPCS
|
||||
{
|
||||
/// <summary>
|
||||
/// Used as a wrapper for npc portraits.
|
||||
/// </summary>
|
||||
public class Portrait
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to display the npc portrait.
|
||||
/// </summary>
|
||||
public Texture2D portrait;
|
||||
/// <summary>
|
||||
/// Used to hold the path to the texture to use for the npc portrait.
|
||||
/// </summary>
|
||||
public string relativePath;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -10,9 +10,18 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace CustomNPCFramework.Framework.ModularNPCS
|
||||
{
|
||||
/// <summary>
|
||||
/// Used as a wrapper for the npcs to hold sprite information.
|
||||
/// </summary>
|
||||
public class Sprite
|
||||
{
|
||||
/// <summary>
|
||||
/// The actual sprite to draw for the npc.
|
||||
/// </summary>
|
||||
public AnimatedSprite sprite;
|
||||
/// <summary>
|
||||
/// The path to the texture to use for the animated sprite.
|
||||
/// </summary>
|
||||
public string relativePath;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -8,6 +8,9 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace CustomNPCFramework.Framework
|
||||
{
|
||||
/// <summary>
|
||||
/// Used as a class to hold all of the possible npc names.
|
||||
/// </summary>
|
||||
public class NPCNames
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
@ -27,6 +27,9 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
/// </summary>
|
||||
public class ExtendedNPC :StardewValley.NPC
|
||||
{
|
||||
/// <summary>
|
||||
/// The custom character renderer for this npc.
|
||||
/// </summary>
|
||||
public BasicRenderer characterRenderer;
|
||||
public bool hasBeenKissedToday;
|
||||
public Point previousEndPoint;
|
||||
|
@ -34,16 +37,35 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
public bool hasSaidAfternoonDialogue;
|
||||
public int timeAfterSquare;
|
||||
|
||||
/// <summary>
|
||||
/// Used to hold sprite information to be used in the case the npc renderer is null.
|
||||
/// </summary>
|
||||
public Sprite spriteInformation;
|
||||
|
||||
/// <summary>
|
||||
/// Used to hold the portrait information for the npc and display it.
|
||||
/// </summary>
|
||||
public Portrait portraitInformation;
|
||||
|
||||
/// <summary>
|
||||
/// The default location for this npc to reside in.
|
||||
/// </summary>
|
||||
public GameLocation defaultLocation;
|
||||
|
||||
/// <summary>
|
||||
/// Empty Constructor.
|
||||
/// </summary>
|
||||
public ExtendedNPC() :base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Non modular npc Constructor.
|
||||
/// </summary>
|
||||
/// <param name="sprite">The sprite for the character.</param>
|
||||
/// <param name="position">The position of the npc on the map.</param>
|
||||
/// <param name="facingDirection">The direction of the npc</param>
|
||||
/// <param name="name">The name of the npc.</param>
|
||||
public ExtendedNPC(Sprite sprite, Vector2 position, int facingDirection, string name) : base(sprite.sprite, position, facingDirection, name, null)
|
||||
{
|
||||
this.characterRenderer = null;
|
||||
|
@ -57,6 +79,14 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
this.swimming = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Non modular npc Constructor.
|
||||
/// </summary>
|
||||
/// <param name="sprite">The sprite for the character.</param>
|
||||
/// <param name="portrait">The portrait texture for this npc.</param>
|
||||
/// <param name="position">The position of the npc on the map.</param>
|
||||
/// <param name="facingDirection">The direction of the npc</param>
|
||||
/// <param name="name">The name of the npc.</param>
|
||||
public ExtendedNPC(Sprite sprite, Portrait portrait, Vector2 position, int facingDirection, string name) : base(sprite.sprite, position, facingDirection, name, null)
|
||||
{
|
||||
this.characterRenderer = null;
|
||||
|
@ -70,6 +100,15 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
this.swimming = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modular npc constructor.
|
||||
/// </summary>
|
||||
/// <param name="sprite">The sprite for the character to use incase the renderer is null.</param>
|
||||
/// <param name="renderer">The custom npc render. Used to draw the npcfrom a collection of assets.</param>
|
||||
/// <param name="portrait">The portrait texture for this npc.</param>
|
||||
/// <param name="position">The position of the npc on the map.</param>
|
||||
/// <param name="facingDirection">The direction of the npc</param>
|
||||
/// <param name="name">The name of the npc.</param>
|
||||
public ExtendedNPC(Sprite sprite,BasicRenderer renderer,Vector2 position,int facingDirection,string name): base(sprite.sprite, position, facingDirection, name, null)
|
||||
{
|
||||
this.characterRenderer = renderer;
|
||||
|
@ -83,6 +122,15 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
this.swimming = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modular constructor for the npc.
|
||||
/// </summary>
|
||||
/// <param name="sprite">The sprite for the npc to use incase the renderer is null.</param>
|
||||
/// <param name="renderer">The custom npc renderer used to draw the npc from the collection of textures.</param>
|
||||
/// <param name="portrait">The portrait texture for the npc.</param>
|
||||
/// <param name="position">The positon for the npc to be.</param>
|
||||
/// <param name="facingDirection">The direction for the npc to face.</param>
|
||||
/// <param name="name">The name for the npc.</param>
|
||||
public ExtendedNPC(Sprite sprite,BasicRenderer renderer,Portrait portrait, Vector2 position, int facingDirection, string name) : base(sprite.sprite, position, facingDirection, name, null)
|
||||
{
|
||||
this.characterRenderer = renderer;
|
||||
|
@ -99,7 +147,9 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
this.swimming = false;
|
||||
}
|
||||
|
||||
//ERROR NEED FIXING
|
||||
/// <summary>
|
||||
/// Used to reload the sprite for the npc.
|
||||
/// </summary>
|
||||
public override void reloadSprite()
|
||||
{
|
||||
if (this.characterRenderer == null)
|
||||
|
@ -150,13 +200,24 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Functionality used when interacting with the npc.
|
||||
/// </summary>
|
||||
/// <param name="who"></param>
|
||||
/// <param name="l"></param>
|
||||
/// <returns></returns>
|
||||
public override bool checkAction(StardewValley.Farmer who, GameLocation l)
|
||||
{
|
||||
base.checkAction(who, l);
|
||||
return false;
|
||||
}
|
||||
|
||||
//ERROR NEED FIXING
|
||||
/// <summary>
|
||||
/// Used to move the npc. Different code is used depending if the character renderer is null or not.
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <param name="viewport"></param>
|
||||
/// <param name="currentLocation"></param>
|
||||
public override void MovePosition(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation currentLocation)
|
||||
{
|
||||
if (this.characterRenderer != null)
|
||||
|
@ -188,12 +249,23 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
this.MovePosition(time, viewport, currentLocation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// USed to move the npc if the character renderer is null.
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <param name="viewport"></param>
|
||||
/// <param name="location"></param>
|
||||
public virtual void NonModularMovement(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation location)
|
||||
{
|
||||
base.MovePosition(time, viewport, currentLocation);
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to determine if the npc can move past the next location.
|
||||
/// </summary>
|
||||
/// <param name="viewport"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool canMovePastNextLocation(xTile.Dimensions.Rectangle viewport)
|
||||
{
|
||||
//Up
|
||||
|
@ -219,9 +291,15 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to move the npc if the character renderer is valid. Handles animating all of the sprites associated with the renderer.
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <param name="viewport"></param>
|
||||
/// <param name="location"></param>
|
||||
/// <param name="interval"></param>
|
||||
public virtual void ModularMovement(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation location, float interval = 1000f)
|
||||
{
|
||||
interval /= 2;
|
||||
this.characterRenderer.setAnimation(AnimationKeys.walkingKey);
|
||||
if (this.canMovePastNextLocation(viewport) == false)
|
||||
{
|
||||
|
@ -369,17 +447,32 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to halt the npc sprite. Sets the npc's animation to the standing animation if the character renderer is not null.
|
||||
/// </summary>
|
||||
public override void Halt()
|
||||
{
|
||||
this.characterRenderer.setAnimation(AnimationKeys.standingKey);
|
||||
if (this.characterRenderer != null)
|
||||
{
|
||||
this.characterRenderer.setAnimation(AnimationKeys.standingKey);
|
||||
}
|
||||
base.Halt();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to update npc information.
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <param name="location"></param>
|
||||
public override void update(GameTime time, GameLocation location)
|
||||
{
|
||||
base.update(time, location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pathfinding code.
|
||||
/// </summary>
|
||||
/// <param name="who"></param>
|
||||
public virtual void routeEndAnimationFinished(StardewValley.Farmer who)
|
||||
{
|
||||
this.doingEndOfRouteAnimation = false;
|
||||
|
@ -397,11 +490,20 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
this.timeAfterSquare = Game1.timeOfDay;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pathfinding code.
|
||||
/// </summary>
|
||||
/// <param name="c"></param>
|
||||
/// <param name="l"></param>
|
||||
public virtual void doAnimationAtEndOfScheduleRoute(Character c, GameLocation l)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Pathfinding code.
|
||||
/// </summary>
|
||||
/// <param name="behaviorName"></param>
|
||||
public virtual void startRouteBehavior(string behaviorName)
|
||||
{
|
||||
if (behaviorName.Length > 0 && (int)behaviorName[0] == 34)
|
||||
|
@ -429,6 +531,11 @@ namespace CustomNPCFramework.Framework.NPCS
|
|||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the npc gets hit by the player.
|
||||
/// </summary>
|
||||
/// <param name="who"></param>
|
||||
/// <param name="location"></param>
|
||||
public new void getHitByPlayer(StardewValley.Farmer who, GameLocation location)
|
||||
{
|
||||
this.doEmote(12, true);
|
||||
|
|
|
@ -10,20 +10,46 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace CustomNPCFramework.Framework.NPCS
|
||||
{
|
||||
/// <summary>
|
||||
/// Extended merchant npc from ExtendedNPC.
|
||||
/// </summary>
|
||||
class MerchantNPC: ExtendedNPC
|
||||
{
|
||||
/// <summary>
|
||||
/// Thelist of items this npc has for sale.
|
||||
/// </summary>
|
||||
public List<Item> stock;
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="Stock">The list of items this npc will sell.</param>
|
||||
/// <param name="sprite">The sprite for the npc to use.</param>
|
||||
/// <param name="renderer">The renderer for the npc to use.</param>
|
||||
/// <param name="position">The position for the npc to use.</param>
|
||||
/// <param name="facingDirection">The facing direction for the player to face.</param>
|
||||
/// <param name="name">The name for the npc.</param>
|
||||
public MerchantNPC(List<Item> Stock, Sprite sprite, BasicRenderer renderer,Vector2 position,int facingDirection,string name): base(sprite,renderer,position,facingDirection,name)
|
||||
{
|
||||
this.stock = Stock;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="Stock">The list of items for the npc to sell.</param>
|
||||
/// <param name="npcBase">The npc base for the character to be expanded upon.</param>
|
||||
public MerchantNPC(List<Item> Stock, ExtendedNPC npcBase) : base(npcBase.spriteInformation, npcBase.characterRenderer, npcBase.portraitInformation, npcBase.position, npcBase.facingDirection, npcBase.name)
|
||||
{
|
||||
this.stock = Stock;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to interact with the npc. When interacting pulls up a shop menu for the npc with their current stock.
|
||||
/// </summary>
|
||||
/// <param name="who"></param>
|
||||
/// <param name="l"></param>
|
||||
/// <returns></returns>
|
||||
public override bool checkAction(StardewValley.Farmer who, GameLocation l)
|
||||
{
|
||||
if (Game1.activeClickableMenu == null)
|
||||
|
|
|
@ -9,6 +9,9 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace CustomNPCFramework.Framework.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to keep track of all of the custom npcs.
|
||||
/// </summary>
|
||||
public class NPCTracker
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -27,8 +30,8 @@ namespace CustomNPCFramework.Framework.Utilities
|
|||
/// <summary>
|
||||
/// Use this to add a new npc into the game.
|
||||
/// </summary>
|
||||
/// <param name="loc"></param>
|
||||
/// <param name="npc"></param>
|
||||
/// <param name="loc">The game location to add the npc to.</param>
|
||||
/// <param name="npc">The extended npc to add to the location.</param>
|
||||
public void addNewNPCToLocation(GameLocation loc,ExtendedNPC npc)
|
||||
{
|
||||
this.moddedNPCS.Add(npc);
|
||||
|
@ -37,6 +40,12 @@ namespace CustomNPCFramework.Framework.Utilities
|
|||
loc.addCharacter(npc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a npc to a location.
|
||||
/// </summary>
|
||||
/// <param name="loc">The game location to add an npc to.</param>
|
||||
/// <param name="npc">The extended npc to add to the location.</param>
|
||||
/// <param name="tilePosition">The tile position at the game location to add the mpc to.</param>
|
||||
public void addNewNPCToLocation(GameLocation loc, ExtendedNPC npc, Vector2 tilePosition)
|
||||
{
|
||||
this.moddedNPCS.Add(npc);
|
||||
|
@ -59,7 +68,7 @@ namespace CustomNPCFramework.Framework.Utilities
|
|||
/// <summary>
|
||||
/// Use this to completly remove and npc from the game as it is removed from the location and is no longer tracked.
|
||||
/// </summary>
|
||||
/// <param name="npc"></param>
|
||||
/// <param name="npc">The npc to remove from the location.</param>
|
||||
public void removeFromLocationAndTrackingList(ExtendedNPC npc)
|
||||
{
|
||||
if (npc.currentLocation != null)
|
||||
|
|
Loading…
Reference in New Issue