Changed animations and animation managers to use Stardust Core. Also started working on Seaside Scramble Lite Edition.

This commit is contained in:
JoshuaNavarro 2019-07-17 10:18:51 -07:00
parent d8e7fa3ddb
commit 01f239f371
23 changed files with 741 additions and 334 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 KiB

View File

@ -6,8 +6,6 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Revitalize.Framework.Factories.Objects.Furniture;
using Revitalize.Framework.Graphics;
using Revitalize.Framework.Graphics.Animations;
using Revitalize.Framework.Illuminate;
using Revitalize.Framework.Objects;
using Revitalize.Framework.Objects.Furniture;
@ -15,6 +13,7 @@ using Revitalize.Framework.Objects.InformationFiles.Furniture;
using Revitalize.Framework.Utilities;
using StardewValley;
using StardustCore.UIUtilities;
using StardustCore.Animations;
namespace Revitalize.Framework.Factories.Objects
{
@ -24,6 +23,7 @@ namespace Revitalize.Framework.Factories.Objects
//Create portable beds???
public class FurnitureFactory
{
public static string ChairFolder = Path.Combine("Data", "Furniture", "Chairs");
public static string TablesFolder = Path.Combine("Data", "Furniture", "Tables");
public static string LampsFolder = Path.Combine("Data", "Furniture", "Lamps");

View File

@ -1,66 +0,0 @@
using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Netcode;
namespace Revitalize.Framework.Graphics.Animations
{
/// <summary>A custom class used to deal with custom animations/</summary>
public class Animation
{
/// <summary>The source rectangle on the texture to display.</summary>
public Rectangle sourceRectangle;
/// <summary>The duration of the frame in length.</summary>
public int frameDuration;
/// <summary>The duration until the next frame.</summary>
public int frameCountUntilNextAnimation;
[XmlIgnore]
public NetFields NetFields { get; } = new NetFields();
public Animation()
{
this.sourceRectangle = new Rectangle(0, 0, 16, 16);
this.frameCountUntilNextAnimation = -1;
this.frameDuration = -1;
}
public Animation(int xPos, int yPos, int width, int height)
{
this.sourceRectangle = new Rectangle(xPos, yPos, width, height);
this.frameCountUntilNextAnimation = -1;
this.frameDuration = -1;
}
/// <summary>Constructor that causes the animation frame count to be set to -1; This forces it to never change.</summary>
/// <param name="SourceRectangle">The draw source for this animation.</param>
public Animation(Rectangle SourceRectangle)
{
this.sourceRectangle = SourceRectangle;
this.frameCountUntilNextAnimation = -1;
this.frameDuration = -1;
}
/// <summary>Construct an instance.</summary>
/// <param name="SourceRectangle">The draw source for this animation.</param>
/// <param name="existForXFrames">How many on screen frames this animation stays for. Every draw frame decrements an active animation by 1 frame. Set this to -1 to have it be on the screen infinitely.</param>
public Animation(Rectangle SourceRectangle, int existForXFrames)
{
this.sourceRectangle = SourceRectangle;
this.frameDuration = existForXFrames;
}
/// <summary>Decrements the amount of frames this animation is on the screen for by 1.</summary>
public void tickAnimationFrame()
{
this.frameCountUntilNextAnimation--;
}
/// <summary>This sets the animation frame count to be the max duration. I.E restart the timer.</summary>
public void startAnimation()
{
this.frameCountUntilNextAnimation = this.frameDuration;
}
}
}

View File

@ -1,245 +0,0 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;
using StardustCore.UIUtilities;
namespace Revitalize.Framework.Graphics.Animations
{
/// <summary>Used to play animations for Stardust.CoreObject type objects and all objects that extend from it. In draw code of object make sure to use this info instead.</summary>
public class AnimationManager
{
public Dictionary<string, List<Animation>> animations = new SerializableDictionary<string, List<Animation>>();
public string currentAnimationName;
public int currentAnimationListIndex;
public List<Animation> currentAnimationList = new List<Animation>();
public Texture2DExtended objectTexture; ///Might not be necessary if I use the CoreObject texture sheet.
public Animation defaultDrawFrame;
public Animation currentAnimation;
public bool enabled;
public string animationDataString;
public bool IsNull => this.defaultDrawFrame == null && this.objectTexture == null;
/// <summary>Construct an instance.</summary>
public AnimationManager() { }
/// <summary>Constructor for Animation Manager class.</summary>
/// <param name="ObjectTexture">The texture that will be used for the animation. This is typically the same as the object this class is attached to.</param>
/// <param name="DefaultFrame">This is used if no animations will be available to the animation manager.</param>
/// <param name="EnabledByDefault">Whether or not animations play by default. Default value is true.</param>
public AnimationManager(Texture2DExtended ObjectTexture, Animation DefaultFrame, bool EnabledByDefault = true)
{
this.currentAnimationListIndex = 0;
this.objectTexture = ObjectTexture;
this.defaultDrawFrame = DefaultFrame;
this.enabled = EnabledByDefault;
this.currentAnimation = this.defaultDrawFrame;
this.currentAnimationName = "";
this.animationDataString = "";
}
public AnimationManager(Texture2DExtended ObjectTexture, Animation DefaultFrame, string animationString, string startingAnimationKey, int startingAnimationFrame = 0, bool EnabledByDefault = true)
{
this.currentAnimationListIndex = 0;
this.objectTexture = ObjectTexture;
this.defaultDrawFrame = DefaultFrame;
this.enabled = EnabledByDefault;
this.animationDataString = animationString;
this.animations = parseAnimationsFromXNB(animationString);
if (this.animations.TryGetValue(startingAnimationKey, out this.currentAnimationList))
this.setAnimation(startingAnimationKey, startingAnimationFrame);
else
{
this.currentAnimation = this.defaultDrawFrame;
this.currentAnimationName = "";
}
}
public AnimationManager(Texture2DExtended ObjectTexture, Animation DefaultFrame, Dictionary<string, List<Animations.Animation>> animationString, string startingAnimationKey, int startingAnimationFrame = 0, bool EnabledByDefault = true)
{
this.currentAnimationListIndex = 0;
this.objectTexture = ObjectTexture;
this.defaultDrawFrame = DefaultFrame;
this.enabled = EnabledByDefault;
this.animations = animationString;
if (this.animations.TryGetValue(startingAnimationKey, out this.currentAnimationList))
this.setAnimation(startingAnimationKey, startingAnimationFrame);
else
{
this.currentAnimation = this.defaultDrawFrame;
this.currentAnimationName = "";
}
}
/// <summary>Update the animation frame once after drawing the object.</summary>
public void tickAnimation()
{
try
{
if (this.currentAnimation.frameDuration == -1 || !this.enabled || this.currentAnimation == this.defaultDrawFrame)
return; //This is if this is a default animation or the animation stops here.
if (this.currentAnimation.frameCountUntilNextAnimation == 0)
this.getNextAnimation();
this.currentAnimation.tickAnimationFrame();
}
catch (Exception err)
{
ModCore.ModMonitor.Log("An internal error occured when trying to tick the animation.");
ModCore.ModMonitor.Log(err.ToString(), StardewModdingAPI.LogLevel.Error);
}
}
/// <summary>Get the next animation in the list of animations.</summary>
public void getNextAnimation()
{
this.currentAnimationListIndex++;
if (this.currentAnimationListIndex == this.currentAnimationList.Count) //If the animation frame I'm tryting to get is 1 outside my list length, reset the list.
this.currentAnimationListIndex = 0;
//Get the next animation from the list and reset it's counter to the starting frame value.
this.currentAnimation = this.currentAnimationList[this.currentAnimationListIndex];
this.currentAnimation.startAnimation();
}
/// <summary>Gets the animation from the dictionary of all animations available.</summary>
/// <param name="AnimationName"></param>
/// <param name="StartingFrame"></param>
public bool setAnimation(string AnimationName, int StartingFrame = 0)
{
if (this.animations.TryGetValue(AnimationName, out List<Animation> dummyList))
{
if (dummyList.Count != 0 || StartingFrame >= dummyList.Count)
{
this.currentAnimationList = dummyList;
this.currentAnimation = this.currentAnimationList[StartingFrame];
this.currentAnimationName = AnimationName;
return true;
}
else
{
if (dummyList.Count == 0)
ModCore.ModMonitor.Log("Error: Current animation " + AnimationName + " has no animation frames associated with it.");
if (dummyList.Count > dummyList.Count)
ModCore.ModMonitor.Log("Error: Animation frame " + StartingFrame + " is outside the range of provided animations. Which has a maximum count of " + dummyList.Count);
return false;
}
}
else
{
ModCore.ModMonitor.Log("Error setting animation: " + AnimationName + " animation does not exist in list of available animations. Did you make sure to add it in?");
return false;
}
}
/// <summary>Sets the animation manager to an on state, meaning that this animation will update on the draw frame.</summary>
public void enableAnimation()
{
this.enabled = true;
}
/// <summary>Sets the animation manager to an off state, meaning that this animation will no longer update on the draw frame.</summary>
public void disableAnimation()
{
this.enabled = false;
}
public static Dictionary<string, List<Animation>> parseAnimationsFromXNB(string s)
{
string[] array = s.Split('*');
Dictionary<string, List<Animation>> parsedDic = new Dictionary<string, List<Animation>>();
foreach (string v in array)
{
// Log.AsyncC(v);
string[] animationArray = v.Split(' ');
if (parsedDic.ContainsKey(animationArray[0]))
{
List<Animation> animations = parseAnimationFromString(v);
foreach (var animation in animations)
{
parsedDic[animationArray[0]].Add(animation);
}
}
else
{
parsedDic.Add(animationArray[0], new List<Animation>());
List<Animation> aniList = new List<Animation>();
aniList = parseAnimationFromString(v);
foreach (var ani in aniList)
{
parsedDic[animationArray[0]].Add(ani);
}
}
}
return parsedDic;
}
public static List<Animation> parseAnimationFromString(string s)
{
List<Animation> ok = new List<Animation>();
string[] array2 = s.Split('>');
foreach (string q in array2)
{
string[] array = q.Split(' ');
try
{
Animation ani = new Animation(new Rectangle(Convert.ToInt32(array[1]), Convert.ToInt32(array[2]), Convert.ToInt32(array[3]), Convert.ToInt32(array[4])), Convert.ToInt32(array[5]));
// ModCore.ModMonitor.Log(ani.sourceRectangle.ToString());
ok.Add(ani);
}
catch { }
}
return ok;
}
/// <summary>Used to handle general drawing functionality using the animation manager.</summary>
/// <param name="spriteBatch">We need a spritebatch to draw.</param>
/// <param name="texture">The texture to draw.</param>
/// <param name="Position">The onscreen position to draw to.</param>
/// <param name="sourceRectangle">The source rectangle on the texture to draw.</param>
/// <param name="drawColor">The color to draw the thing passed in.</param>
/// <param name="rotation">The rotation of the animation texture being drawn.</param>
/// <param name="origin">The origin of the texture.</param>
/// <param name="scale">The scale of the texture.</param>
/// <param name="spriteEffects">Effects that get applied to the sprite.</param>
/// <param name="LayerDepth">The dept at which to draw the texture.</param>
public void draw(SpriteBatch spriteBatch, Texture2D texture, Vector2 Position, Rectangle? sourceRectangle, Color drawColor, float rotation, Vector2 origin, float scale, SpriteEffects spriteEffects, float LayerDepth)
{
//Log.AsyncC("Animation Manager is working!");
spriteBatch.Draw(texture, Position, sourceRectangle, drawColor, rotation, origin, scale, spriteEffects, LayerDepth);
try
{
this.tickAnimation();
// Log.AsyncC("Tick animation");
}
catch (Exception err)
{
ModCore.ModMonitor.Log(err.ToString());
}
}
public Texture2DExtended getExtendedTexture()
{
return this.objectTexture;
}
public void setExtendedTexture(Texture2DExtended texture)
{
this.objectTexture = texture;
}
public void setEnabled(bool enabled)
{
this.enabled = enabled;
}
public Texture2D getTexture()
{
return this.objectTexture.getTexture();
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{
public class SSCEnums
{
public enum FacingDirection
{
Down,
Left,
Up,
Right
}
}
}

View File

@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StardustCore.Animations;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{
public class SSCPlayer
{
//TODO: Hint when left animations are played make sure to FLIP THE SPRITE;
public AnimationManager characterSpriteController;
public bool flipSprite;
public SSCEnums.FacingDirection facingDirection;
public Microsoft.Xna.Framework.Vector2 position;
public bool isMoving;
public SSCPlayer()
{
this.facingDirection = SSCEnums.FacingDirection.Down;
this.characterSpriteController = new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCPlayer", "Junimo"), new Animation(0, 0, 16, 16), new Dictionary<string, List<Animation>>{
{"Idle_F",new List<Animation>()
{
new Animation(0,0,16,16)
} },
{"Idle_B",new List<Animation>()
{
new Animation(0,16*4,16,16)
} },
{"Idle_L",new List<Animation>()
{
new Animation(0,16*3,16,16)
} },
{"Idle_R",new List<Animation>()
{
new Animation(0,16*3,16,16)
} },
},"Idle_F",0,true);
}
public void playAnimation(string name)
{
this.characterSpriteController.setAnimation(name);
}
public void draw(Microsoft.Xna.Framework.Graphics.SpriteBatch b)
{
this.characterSpriteController.draw(b, this.position, Color.White, 4f, this.flipSprite == true ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (this.position.Y) / 10000f));
}
public void update(GameTime Time)
{
if (this.isMoving == false)
{
if(this.facingDirection== SSCEnums.FacingDirection.Down)
{
this.characterSpriteController.setAnimation("Idle_F");
}
if (this.facingDirection == SSCEnums.FacingDirection.Right)
{
this.characterSpriteController.setAnimation("Idle_R");
}
if (this.facingDirection == SSCEnums.FacingDirection.Left)
{
this.characterSpriteController.setAnimation("Idle_L");
this.flipSprite = true;
return;
}
if (this.facingDirection == SSCEnums.FacingDirection.Up)
{
this.characterSpriteController.setAnimation("Idle_B");
}
this.flipSprite = false;
}
else
{
if (this.facingDirection == SSCEnums.FacingDirection.Down)
{
this.characterSpriteController.setAnimation("Idle_F");
}
if (this.facingDirection == SSCEnums.FacingDirection.Right)
{
this.characterSpriteController.setAnimation("Idle_R");
}
if (this.facingDirection == SSCEnums.FacingDirection.Left)
{
this.characterSpriteController.setAnimation("Idle_L");
this.flipSprite = true;
return;
}
if (this.facingDirection == SSCEnums.FacingDirection.Up)
{
this.characterSpriteController.setAnimation("Idle_B");
}
this.flipSprite = false;
}
}
/// <summary>
/// Checks for moving the player.
/// </summary>
/// <param name="direction"></param>
public void movePlayer(SSCEnums.FacingDirection direction)
{
this.isMoving = true;
if(direction== SSCEnums.FacingDirection.Up)
{
this.facingDirection = direction;
this.position += new Vector2(0, -1);
}
if (direction == SSCEnums.FacingDirection.Down)
{
this.facingDirection = direction;
this.position += new Vector2(0, 1);
}
if (direction == SSCEnums.FacingDirection.Left)
{
this.facingDirection = direction;
this.position += new Vector2(-1, 0);
}
if (direction == SSCEnums.FacingDirection.Right)
{
this.facingDirection = direction;
this.position += new Vector2(1, 0);
}
}
}
}

View File

@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StardustCore.UIUtilities;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{
/// <summary>
/// Deals with loading/storing tetxures for Seaside Scramble minigame.
/// </summary>
public class SSCTextureUtilities
{
/// <summary>
/// A list of all the texture managers.
/// </summary>
public Dictionary<string, TextureManager> textureManagers;
/// <summary>
/// Constructor.
/// </summary>
public SSCTextureUtilities()
{
this.textureManagers = new Dictionary<string, TextureManager>();
}
/// <summary>
/// Adds a texture manager to the list of texture managers.
/// </summary>
/// <param name="manager"></param>
public void addTextureManager(TextureManager manager)
{
this.textureManagers.Add(manager.name, manager);
}
/// <summary>
/// Gets the texture manager from the dictionary of them.
/// </summary>
/// <param name="Name"></param>
/// <returns></returns>
public TextureManager getTextureManager(string Name)
{
if (this.textureManagers.ContainsKey(Name))
{
return this.textureManagers[Name];
}
else
{
throw new Exception("Sea Side Scramble: Texture Manager:"+Name+"does not exist!");
}
}
/// <summary>
/// Gets a texture2dExtended from the given texture manager.
/// </summary>
/// <param name="ManagerName"></param>
/// <param name="TextureName"></param>
/// <returns></returns>
public Texture2DExtended getExtendedTexture (string ManagerName, string TextureName)
{
TextureManager manager = this.getTextureManager(ManagerName);
if (manager == null)
{
return null;
}
else
{
if (manager.textures.ContainsKey(TextureName))
{
return manager.getTexture(TextureName);
}
else
{
throw new Exception("Sea Side Scramble: Texture " + TextureName + " does not exist in texture manager: " + ManagerName);
}
}
}
/// <summary>
/// Gets a texture2d from the given texture manager.
/// </summary>
/// <param name="ManagerName"></param>
/// <param name="TextureName"></param>
/// <returns></returns>
public Microsoft.Xna.Framework.Graphics.Texture2D getTexture(string ManagerName, string TextureName)
{
TextureManager manager = this.getTextureManager(ManagerName);
if (manager == null)
{
return null;
}
else
{
if (manager.textures.ContainsKey(TextureName))
{
return manager.getTexture(TextureName).texture;
}
else
{
throw new Exception("Sea Side Scramble: Texture " + TextureName + " does not exist in texture manager: " + ManagerName);
}
}
}
/// <summary>
/// Adds a texture to the given texture manager.
/// </summary>
/// <param name="ManagerName"></param>
/// <param name="TextureName"></param>
/// <param name="Texture"></param>
public void addTexture(string ManagerName,string TextureName ,Texture2DExtended Texture)
{
TextureManager manager = this.getTextureManager(ManagerName);
if (manager == null)
{
return;
}
else
{
manager.addTexture(TextureName, Texture);
}
}
}
}

View File

@ -0,0 +1,274 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Revitalize.Framework.Minigame.SeasideScrambleMinigame;
using StardustCore.UIUtilities;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{
public class SeasideScramble : StardewValley.Minigames.IMinigame
{
public static SeasideScramble self;
SeasideScrambleMap currentMap;
public int currentNumberOfPlayers = 0;
public const int maxPlayers = 4;
public Dictionary<string, SeasideScrambleMap> SeasideScrambleMaps;
public bool quitGame;
public SSCTextureUtilities textureUtils;
public SSCPlayer player;
public SeasideScramble()
{
self = this;
this.textureUtils = new SSCTextureUtilities();
TextureManager playerManager = new TextureManager("SSCPlayer");
playerManager.searchForTextures(ModCore.ModHelper, ModCore.Manifest, Path.Combine("Content", "Minigames", "SeasideScramble", "Graphics", "Player"));
this.textureUtils.addTextureManager(playerManager);
this.LoadTextures();
this.LoadMaps();
this.loadStartingMap();
this.quitGame = false;
this.player = new SSCPlayer();
}
private void LoadTextures()
{
}
private void LoadMaps()
{
this.SeasideScrambleMaps = new Dictionary<string, SeasideScrambleMap>();
this.SeasideScrambleMaps.Add("TestRoom",new SeasideScrambleMap(SeasideScrambleMap.LoadMap("TestRoom.tbin").Value));
}
private void loadStartingMap()
{
this.currentMap = this.SeasideScrambleMaps["TestRoom"];
}
/// <summary>
/// What happens when the screen changes size.
/// </summary>
public void changeScreenSize()
{
//throw new NotImplementedException();
}
/// <summary>
/// Used to update Stardew Valley while this minigame runs. True means SDV updates false means the SDV pauses all update ticks.
/// </summary>
/// <returns></returns>
public bool doMainGameUpdates()
{
return false;
//throw new NotImplementedException();
}
/// <summary>
/// Draws all game aspects to the screen.
/// </summary>
/// <param name="b"></param>
public void draw(SpriteBatch b)
{
if (this.currentMap!=null){
this.currentMap.draw(b);
}
b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
if (this.player != null)
{
this.player.draw(b);
}
b.End();
}
/// <summary>
/// What happens when the left click is held.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void leftClickHeld(int x, int y)
{
//throw new NotImplementedException();
}
/// <summary>
/// The id of the minigame???
/// </summary>
/// <returns></returns>
public string minigameId()
{
return "Seaside Scramble Stardew Lite Edition";
//throw new NotImplementedException();
}
/// <summary>
/// Does this override free mous emovements?
/// </summary>
/// <returns></returns>
public bool overrideFreeMouseMovement()
{
return false;
//throw new NotImplementedException();
}
/// <summary>
/// ??? Undocumended.
/// </summary>
/// <param name="data"></param>
public void receiveEventPoke(int data)
{
//throw new NotImplementedException();
}
/// <summary>
/// What happens when a key is pressed.
/// </summary>
/// <param name="k"></param>
public void receiveKeyPress(Keys k)
{
//throw new NotImplementedException();
this.checkForMovementInput(k);
}
/// <summary>
/// Checks for player movement.
/// </summary>
/// <param name="K"></param>
private void checkForMovementInput(Keys K)
{
Microsoft.Xna.Framework.Input.GamePadState state = this.getGamepadState(PlayerIndex.One);
if(K== Keys.A)
{
ModCore.log("A pressed for Seaside Scramble!");
this.player.movePlayer(SSCEnums.FacingDirection.Left);
}
if (K == Keys.W)
{
ModCore.log("W pressed for Seaside Scramble!");
this.player.movePlayer(SSCEnums.FacingDirection.Up);
}
if(K== Keys.S)
{
ModCore.log("S pressed for Seaside Scramble!");
this.player.movePlayer(SSCEnums.FacingDirection.Down);
}
if(K== Keys.D)
{
ModCore.log("D pressed for Seaside Scramble!");
this.player.movePlayer(SSCEnums.FacingDirection.Right);
}
if(K== Keys.Escape)
{
this.quitGame = true;
}
}
private GamePadState getGamepadState(PlayerIndex index)
{
return Microsoft.Xna.Framework.Input.GamePad.GetState(PlayerIndex.One);
}
public void receiveKeyRelease(Keys K)
{
//throw new NotImplementedException();
if (K == Keys.A)
{
ModCore.log("A released for Seaside Scramble!");
this.player.isMoving = false;
}
if (K == Keys.W)
{
ModCore.log("W pressed for Seaside Scramble!");
this.player.isMoving = false;
}
if (K == Keys.S)
{
ModCore.log("S pressed for Seaside Scramble!");
this.player.isMoving = false;
}
if (K == Keys.D)
{
ModCore.log("D pressed for Seaside Scramble!");
this.player.isMoving = false;
}
}
public void receiveLeftClick(int x, int y, bool playSound = true)
{
//throw new NotImplementedException();
}
public void receiveRightClick(int x, int y, bool playSound = true)
{
//throw new NotImplementedException();
}
public void releaseLeftClick(int x, int y)
{
//throw new NotImplementedException();
}
public void releaseRightClick(int x, int y)
{
//throw new NotImplementedException();
}
/// <summary>
/// Called every update frame.
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public bool tick(GameTime time)
{
KeyboardState state = Keyboard.GetState();
foreach (Keys k in state.GetPressedKeys())
{
this.receiveKeyPress(k);
}
if (this.quitGame)
{
return true;
}
if (this.currentMap != null)
{
this.currentMap.update(time);
}
if (this.player != null)
{
this.player.update(time);
}
return false;
//throw new NotImplementedException();
}
/// <summary>
/// Called when the minigame is quit upon.
/// </summary>
public void unload()
{
//throw new NotImplementedException();
ModCore.log("Exit the game!");
}
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewValley;
using xTile;
using xTile.Dimensions;
using xTile.Display;
using xTile.Layers;
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{
/// <summary>
/// TODO:
/// Force maps to all have the same layers as SDV maps so we can draw different things on a map.
///
/// </summary>
/*
* Back: Terrain, water, and basic features (like permanent paths).
Buildings: Placeholders for buildings (like the farmhouse). Any tiles placed on this layer will act like a wall unless the tile property has a "Passable" "T".
Paths: Flooring, paths, grass, and debris (like stones, weeds, and stumps from the 'paths' tilesheet) which can be removed by the player.
Front: Objects that are drawn on top of things behind them, like most trees. These objects will be drawn on top of the player if the player is North of them but behind the player if the player is south of them.
AlwaysFront: Objects that are always drawn on top of other layers as well as the player. This is typically used for foreground effects like foliage cover.
*/
public class SeasideScrambleMap
{
public xTile.Map map;
public SeasideScrambleMap()
{
}
public SeasideScrambleMap(Map Map)
{
this.map = Map;
//this.map.LoadTileSheets(Game1.mapDisplayDevice);
}
public virtual void update(GameTime time)
{
this.map.Update(time.TotalGameTime.Ticks);
}
public virtual void draw(SpriteBatch b)
{
b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
Game1.mapDisplayDevice.BeginScene(b);
for (int i = 0; i < this.map.Layers.Count; i++)
{
this.map.Layers[i].Draw(Game1.mapDisplayDevice, Game1.viewport, Location.Origin, false, 4);
}
Game1.mapDisplayDevice.EndScene();
b.End();
}
/// <summary>
/// Loads a map from a tbin file from the mod's asset folder.
/// </summary>
/// <param name="MapName"></param>
/// <returns></returns>
public static KeyValuePair<string, xTile.Map> LoadMap(string MapName)
{
// load the map file from your mod folder
string pathToMaps = Path.Combine("Content", "Minigames", "SeasideScramble", "Maps", MapName);
xTile.Map map = ModCore.ModHelper.Content.Load<Map>(pathToMaps, ContentSource.ModFolder);
for (int index = 0; index < map.TileSheets.Count; ++index)
{
string imageSource = map.TileSheets[index].ImageSource;
string fileName = Path.GetFileName(imageSource);
string path1 = Path.GetDirectoryName(imageSource);
map.TileSheets[index].ImageSource = Path.Combine(path1, fileName);
}
map.LoadTileSheets(Game1.mapDisplayDevice);
// get the internal asset key for the map file
string mapAssetKey = ModCore.ModHelper.Content.GetActualAssetKey(MapName, ContentSource.ModFolder);
return new KeyValuePair<string, Map>(mapAssetKey, map);
}
}
}

View File

@ -2,7 +2,7 @@ using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PyTK.CustomElementHandler;
using Revitalize.Framework.Graphics.Animations;
using StardustCore.Animations;
using Revitalize.Framework.Illuminate;
using Revitalize.Framework.Utilities;
using StardewValley;

View File

@ -5,7 +5,7 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Newtonsoft.Json;
using PyTK.CustomElementHandler;
using Revitalize.Framework.Graphics.Animations;
using StardustCore.Animations;
using StardewValley;
using StardewValley.Objects;

View File

@ -6,7 +6,6 @@ using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;
using Revitalize.Framework.Graphics;
using StardewValley;
using StardustCore.UIUtilities;

View File

@ -8,8 +8,6 @@ using Revitalize.Framework;
using Revitalize.Framework.Crafting;
using Revitalize.Framework.Environment;
using Revitalize.Framework.Factories.Objects;
using Revitalize.Framework.Graphics;
using Revitalize.Framework.Graphics.Animations;
using Revitalize.Framework.Illuminate;
using Revitalize.Framework.Objects;
using Revitalize.Framework.Objects.Furniture;
@ -19,6 +17,7 @@ using StardewModdingAPI;
using StardewValley;
using StardewValley.Objects;
using StardustCore.UIUtilities;
using StardustCore.Animations;
namespace Revitalize
{
@ -157,6 +156,7 @@ namespace Revitalize
ModHelper.Events.GameLoop.TimeChanged += this.GameLoop_TimeChanged;
ModHelper.Events.GameLoop.UpdateTicked += this.GameLoop_UpdateTicked;
ModHelper.Events.GameLoop.ReturnedToTitle += this.GameLoop_ReturnedToTitle;
ModHelper.Events.Input.ButtonPressed += this.Input_ButtonPressed;
playerInfo = new PlayerInfo();
TextureManager.AddTextureManager(Manifest,"Furniture");
@ -183,6 +183,14 @@ namespace Revitalize
}
private void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e)
{
if(e.Button== SButton.U)
{
Game1.currentMinigame = new Revitalize.Framework.Minigame.SeasideScrambleMinigame.SeasideScramble();
}
}
private void GameLoop_ReturnedToTitle(object sender, StardewModdingAPI.Events.ReturnedToTitleEventArgs e)
{
Serializer.returnToTitle();

View File

@ -61,12 +61,15 @@
<Compile Include="Framework\Factories\Objects\Furniture\ChairFactoryInfo.cs" />
<Compile Include="Framework\Factories\Objects\FactoryInfo.cs" />
<Compile Include="Framework\Factories\Objects\Furniture\TableFactoryInfo.cs" />
<Compile Include="Framework\Graphics\Animations\Animation.cs" />
<Compile Include="Framework\Graphics\Animations\AnimationManager.cs" />
<Compile Include="Framework\Illuminate\ColorExtensions.cs" />
<Compile Include="Framework\Illuminate\FakeLightSource.cs" />
<Compile Include="Framework\Illuminate\LightManager.cs" />
<Compile Include="Framework\Menus\SimpleItemGrabMenu.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SeasideScramble.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SeasideScrambleMap.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCEnums.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCPlayer.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCTextureUtilities.cs" />
<Compile Include="Framework\Objects\BasicItemInformation.cs" />
<Compile Include="Framework\Objects\CustomObject.cs" />
<Compile Include="Framework\Objects\Furniture\Bench.cs" />
@ -105,6 +108,12 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Content\Minigames\SeasideScramble\Maps\TestRoom.tbin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Content\Minigames\SeasideScramble\Maps\TestRoom2.tbin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="manifest.json" />
</ItemGroup>
<ItemGroup>
@ -117,6 +126,24 @@
<Content Include="Content\Graphics\Furniture\Tables\Oak Table.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\Player\Junimo.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Maps\SSC_Beach.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Maps\SSC_DesertTiles.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Maps\SSC_Festivals.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Maps\SSC_OutdoorsTileSheet.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Maps\SSC_Town.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -26,6 +26,18 @@ namespace StardustCore.Animations
this.frameDuration = -1;
}
public Animation(int xPos, int yPos, int width, int height)
{
this.sourceRectangle = new Rectangle(xPos, yPos, width, height);
this.frameCountUntilNextAnimation = -1;
this.frameDuration = -1;
}
public Animation(int xPos, int yPos, int width, int height,int existsForXFrames)
{
this.sourceRectangle = new Rectangle(xPos, yPos, width, height);
this.frameDuration = existsForXFrames;
}
/// <summary>Constructor that causes the animation frame count to be set to -1; This forces it to never change.</summary>
/// <param name="SourceRectangle">The draw source for this animation.</param>
public Animation(Rectangle SourceRectangle)

View File

@ -14,16 +14,19 @@ namespace StardustCore.Animations
public string currentAnimationName;
public int currentAnimationListIndex;
public List<Animation> currentAnimationList = new List<Animation>();
private Texture2DExtended objectTexture; ///Might not be necessary if I use the CoreObject texture sheet.
public Texture2DExtended objectTexture; ///Might not be necessary if I use the CoreObject texture sheet.
public Animation defaultDrawFrame;
public Animation currentAnimation;
public bool enabled;
public string animationDataString;
/// <summary>Empty constructor.</summary>
public bool IsNull => this.defaultDrawFrame == null && this.objectTexture == null;
/// <summary>Construct an instance.</summary>
public AnimationManager() { }
/// <summary>Constructor for Animation Manager class.</summary>
/// <param name="ObjectTexture">The texture that will be used for the animation. This is typically the same as the object this class is attached to.</param>
/// <param name="DefaultFrame">This is used if no animations will be available to the animation manager.</param>
@ -48,11 +51,8 @@ namespace StardustCore.Animations
this.animationDataString = animationString;
this.animations = parseAnimationsFromXNB(animationString);
bool f = this.animations.TryGetValue(startingAnimationKey, out this.currentAnimationList);
if (f)
{
if (this.animations.TryGetValue(startingAnimationKey, out this.currentAnimationList))
this.setAnimation(startingAnimationKey, startingAnimationFrame);
}
else
{
this.currentAnimation = this.defaultDrawFrame;
@ -108,9 +108,11 @@ namespace StardustCore.Animations
}
/// <summary>Gets the animation from the dictionary of all animations available.</summary>
/// <param name="AnimationName"></param>
/// <param name="StartingFrame"></param>
public bool setAnimation(string AnimationName, int StartingFrame = 0)
{
if (this.animations.TryGetValue(AnimationName, out var dummyList))
if (this.animations.TryGetValue(AnimationName, out List<Animation> dummyList))
{
if (dummyList.Count != 0 || StartingFrame >= dummyList.Count)
{
@ -121,8 +123,10 @@ namespace StardustCore.Animations
}
else
{
if (dummyList.Count == 0) ModCore.ModMonitor.Log("Error: Current animation " + AnimationName + " has no animation frames associated with it.");
//if (dummyList.Count > dummyList.Count) ModCore.ModMonitor.Log("Error: Animation frame " + StartingFrame + " is outside the range of provided animations. Which has a maximum count of " + dummyList.Count);
if (dummyList.Count == 0)
ModCore.ModMonitor.Log("Error: Current animation " + AnimationName + " has no animation frames associated with it.");
if (dummyList.Count > dummyList.Count)
ModCore.ModMonitor.Log("Error: Animation frame " + StartingFrame + " is outside the range of provided animations. Which has a maximum count of " + dummyList.Count);
return false;
}
}
@ -155,18 +159,23 @@ namespace StardustCore.Animations
string[] animationArray = v.Split(' ');
if (parsedDic.ContainsKey(animationArray[0]))
{
List<Animation> aniList = parseAnimationFromString(v);
foreach (var ani in aniList)
parsedDic[animationArray[0]].Add(ani);
List<Animation> animations = parseAnimationFromString(v);
foreach (var animation in animations)
{
parsedDic[animationArray[0]].Add(animation);
}
}
else
{
parsedDic.Add(animationArray[0], new List<Animation>());
List<Animation> aniList = parseAnimationFromString(v);
List<Animation> aniList = new List<Animation>();
aniList = parseAnimationFromString(v);
foreach (var ani in aniList)
{
parsedDic[animationArray[0]].Add(ani);
}
}
}
return parsedDic;
}
@ -187,7 +196,6 @@ namespace StardustCore.Animations
}
return ok;
}
/// <summary>Used to handle general drawing functionality using the animation manager.</summary>
/// <param name="spriteBatch">We need a spritebatch to draw.</param>
/// <param name="texture">The texture to draw.</param>
@ -214,6 +222,29 @@ namespace StardustCore.Animations
}
}
/// <summary>
/// Used to draw the current animation to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="Position"></param>
/// <param name="drawColor"></param>
/// <param name="scale"></param>
/// <param name="flipped"></param>
/// <param name="depth"></param>
public void draw(SpriteBatch b,Vector2 Position,Color drawColor,float scale,SpriteEffects flipped,float depth)
{
b.Draw(this.objectTexture.texture, Position, this.currentAnimation.sourceRectangle, drawColor, 0f, Vector2.Zero, scale, flipped, depth);
try
{
this.tickAnimation();
// Log.AsyncC("Tick animation");
}
catch (Exception err)
{
ModCore.ModMonitor.Log(err.ToString());
}
}
public Texture2DExtended getExtendedTexture()
{
return this.objectTexture;