diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/Player/Junimo.png b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/Player/Junimo.png new file mode 100644 index 00000000..58494789 Binary files /dev/null and b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/Player/Junimo.png differ diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_Beach.png b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_Beach.png new file mode 100644 index 00000000..50808149 Binary files /dev/null and b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_Beach.png differ diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_DesertTiles.png b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_DesertTiles.png new file mode 100644 index 00000000..ed2de5d9 Binary files /dev/null and b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_DesertTiles.png differ diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_Festivals.png b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_Festivals.png new file mode 100644 index 00000000..6358f6a4 Binary files /dev/null and b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_Festivals.png differ diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_OutdoorsTileSheet.png b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_OutdoorsTileSheet.png new file mode 100644 index 00000000..c73ee218 Binary files /dev/null and b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_OutdoorsTileSheet.png differ diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_Town.png b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_Town.png new file mode 100644 index 00000000..a8e45576 Binary files /dev/null and b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/SSC_Town.png differ diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/TestRoom.tbin b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/TestRoom.tbin new file mode 100644 index 00000000..b1d44873 Binary files /dev/null and b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/TestRoom.tbin differ diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/TestRoom2.tbin b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/TestRoom2.tbin new file mode 100644 index 00000000..79b6e507 Binary files /dev/null and b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Maps/TestRoom2.tbin differ diff --git a/GeneralMods/Revitalize/Framework/Factories/Objects/Furniture/FurnitureFactory.cs b/GeneralMods/Revitalize/Framework/Factories/Objects/Furniture/FurnitureFactory.cs index 69f79e76..c3eb13f7 100644 --- a/GeneralMods/Revitalize/Framework/Factories/Objects/Furniture/FurnitureFactory.cs +++ b/GeneralMods/Revitalize/Framework/Factories/Objects/Furniture/FurnitureFactory.cs @@ -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"); diff --git a/GeneralMods/Revitalize/Framework/Graphics/Animations/Animation.cs b/GeneralMods/Revitalize/Framework/Graphics/Animations/Animation.cs deleted file mode 100644 index eb9341b1..00000000 --- a/GeneralMods/Revitalize/Framework/Graphics/Animations/Animation.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Xml.Serialization; -using Microsoft.Xna.Framework; -using Netcode; - -namespace Revitalize.Framework.Graphics.Animations -{ - /// A custom class used to deal with custom animations/ - public class Animation - { - /// The source rectangle on the texture to display. - public Rectangle sourceRectangle; - - /// The duration of the frame in length. - public int frameDuration; - - /// The duration until the next frame. - 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; - } - - /// Constructor that causes the animation frame count to be set to -1; This forces it to never change. - /// The draw source for this animation. - public Animation(Rectangle SourceRectangle) - { - this.sourceRectangle = SourceRectangle; - this.frameCountUntilNextAnimation = -1; - this.frameDuration = -1; - } - - /// Construct an instance. - /// The draw source for this animation. - /// 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. - public Animation(Rectangle SourceRectangle, int existForXFrames) - { - this.sourceRectangle = SourceRectangle; - this.frameDuration = existForXFrames; - } - - /// Decrements the amount of frames this animation is on the screen for by 1. - public void tickAnimationFrame() - { - this.frameCountUntilNextAnimation--; - } - - /// This sets the animation frame count to be the max duration. I.E restart the timer. - public void startAnimation() - { - this.frameCountUntilNextAnimation = this.frameDuration; - } - } -} diff --git a/GeneralMods/Revitalize/Framework/Graphics/Animations/AnimationManager.cs b/GeneralMods/Revitalize/Framework/Graphics/Animations/AnimationManager.cs deleted file mode 100644 index 5402c3a1..00000000 --- a/GeneralMods/Revitalize/Framework/Graphics/Animations/AnimationManager.cs +++ /dev/null @@ -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 -{ - /// 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. - public class AnimationManager - { - public Dictionary> animations = new SerializableDictionary>(); - public string currentAnimationName; - public int currentAnimationListIndex; - public List currentAnimationList = new List(); - 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; - - /// Construct an instance. - public AnimationManager() { } - - - /// Constructor for Animation Manager class. - /// The texture that will be used for the animation. This is typically the same as the object this class is attached to. - /// This is used if no animations will be available to the animation manager. - /// Whether or not animations play by default. Default value is true. - 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> 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 = ""; - } - } - - /// Update the animation frame once after drawing the object. - 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); - } - } - - /// Get the next animation in the list of animations. - 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(); - } - - /// Gets the animation from the dictionary of all animations available. - /// - /// - public bool setAnimation(string AnimationName, int StartingFrame = 0) - { - if (this.animations.TryGetValue(AnimationName, out List 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; - } - } - - /// Sets the animation manager to an on state, meaning that this animation will update on the draw frame. - public void enableAnimation() - { - this.enabled = true; - } - - /// Sets the animation manager to an off state, meaning that this animation will no longer update on the draw frame. - public void disableAnimation() - { - this.enabled = false; - } - - public static Dictionary> parseAnimationsFromXNB(string s) - { - string[] array = s.Split('*'); - Dictionary> parsedDic = new Dictionary>(); - foreach (string v in array) - { - // Log.AsyncC(v); - string[] animationArray = v.Split(' '); - if (parsedDic.ContainsKey(animationArray[0])) - { - List animations = parseAnimationFromString(v); - foreach (var animation in animations) - { - parsedDic[animationArray[0]].Add(animation); - } - } - else - { - parsedDic.Add(animationArray[0], new List()); - List aniList = new List(); - aniList = parseAnimationFromString(v); - foreach (var ani in aniList) - { - parsedDic[animationArray[0]].Add(ani); - } - } - } - return parsedDic; - } - - public static List parseAnimationFromString(string s) - { - List ok = new List(); - 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; - } - /// Used to handle general drawing functionality using the animation manager. - /// We need a spritebatch to draw. - /// The texture to draw. - /// The onscreen position to draw to. - /// The source rectangle on the texture to draw. - /// The color to draw the thing passed in. - /// The rotation of the animation texture being drawn. - /// The origin of the texture. - /// The scale of the texture. - /// Effects that get applied to the sprite. - /// The dept at which to draw the texture. - 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(); - } - } -} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnums.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnums.cs new file mode 100644 index 00000000..f53a13b1 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnums.cs @@ -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 + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs new file mode 100644 index 00000000..946fbb42 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs @@ -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>{ + {"Idle_F",new List() + { + new Animation(0,0,16,16) + } }, + {"Idle_B",new List() + { + new Animation(0,16*4,16,16) + } }, + {"Idle_L",new List() + { + new Animation(0,16*3,16,16) + } }, + {"Idle_R",new List() + { + 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; + } + } + + /// + /// Checks for moving the player. + /// + /// + 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); + } + } + + + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCTextureUtilities.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCTextureUtilities.cs new file mode 100644 index 00000000..a0e4a6cd --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCTextureUtilities.cs @@ -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 +{ + /// + /// Deals with loading/storing tetxures for Seaside Scramble minigame. + /// + public class SSCTextureUtilities + { + /// + /// A list of all the texture managers. + /// + public Dictionary textureManagers; + /// + /// Constructor. + /// + public SSCTextureUtilities() + { + this.textureManagers = new Dictionary(); + } + + /// + /// Adds a texture manager to the list of texture managers. + /// + /// + public void addTextureManager(TextureManager manager) + { + this.textureManagers.Add(manager.name, manager); + } + /// + /// Gets the texture manager from the dictionary of them. + /// + /// + /// + 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!"); + } + } + + /// + /// Gets a texture2dExtended from the given texture manager. + /// + /// + /// + /// + 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); + } + } + } + + /// + /// Gets a texture2d from the given texture manager. + /// + /// + /// + /// + 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); + } + } + } + + /// + /// Adds a texture to the given texture manager. + /// + /// + /// + /// + public void addTexture(string ManagerName,string TextureName ,Texture2DExtended Texture) + { + TextureManager manager = this.getTextureManager(ManagerName); + if (manager == null) + { + return; + } + else + { + manager.addTexture(TextureName, Texture); + } + } + + + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs new file mode 100644 index 00000000..8c1787a6 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs @@ -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 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(); + this.SeasideScrambleMaps.Add("TestRoom",new SeasideScrambleMap(SeasideScrambleMap.LoadMap("TestRoom.tbin").Value)); + } + private void loadStartingMap() + { + this.currentMap = this.SeasideScrambleMaps["TestRoom"]; + } + + /// + /// What happens when the screen changes size. + /// + public void changeScreenSize() + { + + //throw new NotImplementedException(); + } + + /// + /// Used to update Stardew Valley while this minigame runs. True means SDV updates false means the SDV pauses all update ticks. + /// + /// + public bool doMainGameUpdates() + { + return false; + //throw new NotImplementedException(); + } + + /// + /// Draws all game aspects to the screen. + /// + /// + 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(); + } + + /// + /// What happens when the left click is held. + /// + /// + /// + public void leftClickHeld(int x, int y) + { + //throw new NotImplementedException(); + } + + /// + /// The id of the minigame??? + /// + /// + public string minigameId() + { + return "Seaside Scramble Stardew Lite Edition"; + //throw new NotImplementedException(); + } + + /// + /// Does this override free mous emovements? + /// + /// + public bool overrideFreeMouseMovement() + { + return false; + //throw new NotImplementedException(); + } + + /// + /// ??? Undocumended. + /// + /// + public void receiveEventPoke(int data) + { + //throw new NotImplementedException(); + } + + /// + /// What happens when a key is pressed. + /// + /// + public void receiveKeyPress(Keys k) + { + //throw new NotImplementedException(); + this.checkForMovementInput(k); + } + + /// + /// Checks for player movement. + /// + /// + 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(); + } + + /// + /// Called every update frame. + /// + /// + /// + 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(); + } + + /// + /// Called when the minigame is quit upon. + /// + public void unload() + { + //throw new NotImplementedException(); + ModCore.log("Exit the game!"); + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScrambleMap.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScrambleMap.cs new file mode 100644 index 00000000..ed3cb971 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScrambleMap.cs @@ -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 +{ + /// + /// TODO: + /// Force maps to all have the same layers as SDV maps so we can draw different things on a map. + /// + /// + /* + * 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(); + } + + /// + /// Loads a map from a tbin file from the mod's asset folder. + /// + /// + /// + public static KeyValuePair 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(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(mapAssetKey, map); + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs b/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs index debf067e..6b56a881 100644 --- a/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs +++ b/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs @@ -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; diff --git a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs index efc14a19..5da1e942 100644 --- a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs @@ -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; diff --git a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/Texture2DConverter.cs b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/Texture2DConverter.cs index 302c3b46..c848bcaa 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/Texture2DConverter.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/Texture2DConverter.cs @@ -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; diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index a34bc1af..78687be1 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -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(); diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 83b2a594..f41b47bb 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -61,12 +61,15 @@ - - + + + + + @@ -105,6 +108,12 @@ + + Always + + + Always + @@ -117,6 +126,24 @@ PreserveNewest + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + \ No newline at end of file diff --git a/GeneralMods/StardustCore/Animations/Animation.cs b/GeneralMods/StardustCore/Animations/Animation.cs index b1696695..1180b575 100644 --- a/GeneralMods/StardustCore/Animations/Animation.cs +++ b/GeneralMods/StardustCore/Animations/Animation.cs @@ -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; + } + /// Constructor that causes the animation frame count to be set to -1; This forces it to never change. /// The draw source for this animation. public Animation(Rectangle SourceRectangle) diff --git a/GeneralMods/StardustCore/Animations/AnimationManager.cs b/GeneralMods/StardustCore/Animations/AnimationManager.cs index 6eb9fc61..f642d62a 100644 --- a/GeneralMods/StardustCore/Animations/AnimationManager.cs +++ b/GeneralMods/StardustCore/Animations/AnimationManager.cs @@ -14,16 +14,19 @@ namespace StardustCore.Animations public string currentAnimationName; public int currentAnimationListIndex; public List currentAnimationList = new List(); - 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; - /// Empty constructor. + public bool IsNull => this.defaultDrawFrame == null && this.objectTexture == null; + + /// Construct an instance. public AnimationManager() { } + /// Constructor for Animation Manager class. /// The texture that will be used for the animation. This is typically the same as the object this class is attached to. /// This is used if no animations will be available to the animation manager. @@ -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 } /// Gets the animation from the dictionary of all animations available. + /// + /// public bool setAnimation(string AnimationName, int StartingFrame = 0) { - if (this.animations.TryGetValue(AnimationName, out var dummyList)) + if (this.animations.TryGetValue(AnimationName, out List 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,16 +159,21 @@ namespace StardustCore.Animations string[] animationArray = v.Split(' '); if (parsedDic.ContainsKey(animationArray[0])) { - List aniList = parseAnimationFromString(v); - foreach (var ani in aniList) - parsedDic[animationArray[0]].Add(ani); + List animations = parseAnimationFromString(v); + foreach (var animation in animations) + { + parsedDic[animationArray[0]].Add(animation); + } } else { parsedDic.Add(animationArray[0], new List()); - List aniList = parseAnimationFromString(v); + List aniList = new List(); + aniList = parseAnimationFromString(v); foreach (var ani in aniList) + { parsedDic[animationArray[0]].Add(ani); + } } } return parsedDic; @@ -187,7 +196,6 @@ namespace StardustCore.Animations } return ok; } - /// Used to handle general drawing functionality using the animation manager. /// We need a spritebatch to draw. /// The texture to draw. @@ -214,6 +222,29 @@ namespace StardustCore.Animations } } + /// + /// Used to draw the current animation to the screen. + /// + /// + /// + /// + /// + /// + /// + 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;