diff --git a/GeneralMods/StardustCore/Animations/Animation.cs b/GeneralMods/StardustCore/Animations/Animation.cs index 58fb17c4..04f2561e 100644 --- a/GeneralMods/StardustCore/Animations/Animation.cs +++ b/GeneralMods/StardustCore/Animations/Animation.cs @@ -1,9 +1,11 @@ using Microsoft.Xna.Framework; +using Netcode; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Serialization; namespace StardustCore.Animations { @@ -12,18 +14,21 @@ namespace StardustCore.Animations /// public class Animation { - /// - /// The source rectangle on the texture to display. - /// + /// + /// The source rectangle on the texture to display. + /// public Rectangle sourceRectangle; - /// - /// The duration of the frame in length. - /// - public readonly int frameDuration; - /// - /// The duration until the next frame. - /// - public int frameCountUntilNextAnimation; + /// + /// 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(); diff --git a/GeneralMods/StardustCore/Animations/AnimationManager.cs b/GeneralMods/StardustCore/Animations/AnimationManager.cs index dfcb03b2..a93d818e 100644 --- a/GeneralMods/StardustCore/Animations/AnimationManager.cs +++ b/GeneralMods/StardustCore/Animations/AnimationManager.cs @@ -16,15 +16,17 @@ namespace StardustCore.Animations /// public class AnimationManager { - public Dictionary> animations = new Dictionary>(); + public Dictionary> animations = new SerializableDictionary>(); 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 Animation defaultDrawFrame; public Animation currentAnimation; - bool enabled; + public bool enabled; + + public string animationDataString; /// /// Constructor for Animation Manager class. /// @@ -38,16 +40,19 @@ namespace StardustCore.Animations this.defaultDrawFrame = DefaultFrame; this.enabled = EnabledByDefault; currentAnimation = this.defaultDrawFrame; + this.currentAnimationName = ""; + this.animationDataString = ""; } - public AnimationManager(Texture2DExtended ObjectTexture,Animation DefaultFrame ,Dictionary> animationsToPlay, string startingAnimationKey, int startingAnimationFrame=0,bool EnabledByDefault=true) + public AnimationManager(Texture2DExtended ObjectTexture,Animation DefaultFrame ,string animationString, string startingAnimationKey, int startingAnimationFrame=0,bool EnabledByDefault=true) { currentAnimationListIndex = 0; this.objectTexture = ObjectTexture; this.defaultDrawFrame = DefaultFrame; this.enabled = EnabledByDefault; - this.animations = animationsToPlay; + this.animationDataString = animationString; + this.animations = parseAnimationsFromXNB(animationString); bool f = animations.TryGetValue(startingAnimationKey, out currentAnimationList); if (f == true) { setAnimation(startingAnimationKey, startingAnimationFrame); @@ -55,6 +60,22 @@ namespace StardustCore.Animations else currentAnimation = this.defaultDrawFrame; } + public AnimationManager(Texture2DExtended ObjectTexture, Animation DefaultFrame, Dictionary> animationString, string startingAnimationKey, int startingAnimationFrame = 0, bool EnabledByDefault = true) + { + currentAnimationListIndex = 0; + this.objectTexture = ObjectTexture; + this.defaultDrawFrame = DefaultFrame; + this.enabled = EnabledByDefault; + + this.animations = animationString; + bool f = animations.TryGetValue(startingAnimationKey, out currentAnimationList); + if (f == true) + { + setAnimation(startingAnimationKey, startingAnimationFrame); + } + else currentAnimation = this.defaultDrawFrame; + } + /// /// Update the animation frame once after drawing the object. /// @@ -223,6 +244,16 @@ namespace StardustCore.Animations 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/StardustCore/ModCore.cs b/GeneralMods/StardustCore/ModCore.cs index 3ac57511..9bcfe760 100644 --- a/GeneralMods/StardustCore/ModCore.cs +++ b/GeneralMods/StardustCore/ModCore.cs @@ -176,6 +176,8 @@ namespace StardustCore tile1.Name = "test"; tile1.displayName = "test"; Game1.player.addItemToInventory(tile1); + + } private void SaveEvents_AfterSave(object sender, EventArgs e) diff --git a/GeneralMods/StardustCore/NetCode/Graphics/NetTexure2DExtended.cs b/GeneralMods/StardustCore/NetCode/Graphics/NetTexure2DExtended.cs deleted file mode 100644 index 14830335..00000000 --- a/GeneralMods/StardustCore/NetCode/Graphics/NetTexure2DExtended.cs +++ /dev/null @@ -1,143 +0,0 @@ -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 Netcode; -using StardewValley; -using StardustCore.UIUtilities; - -namespace StardustCore.NetCode.Graphics -{ - /* - public class NetTexture2DExtended : Netcode.NetField - { - - public string Name; - public Texture2D texture; - public string path; - - - public NetTexture2DExtended() - { - - } - - public NetTexture2DExtended(Texture2DExtended value) : base(value) - { - } - - public void ReadData(BinaryReader reader,NetVersion version) - { - ReadDelta(reader, version); - } - - public void WriteData(BinaryWriter writer) - { - WriteDelta(writer); - } - - protected override void ReadDelta(BinaryReader reader, NetVersion version) - { - /* - int width = reader.ReadInt32(); - int height = reader.ReadInt32(); - Byte[] colorsOne = new byte[width*height*4]; - colorsOne = reader.ReadBytes(width*height*4); - texture = new Texture2D(Game1.graphics.GraphicsDevice,width,height); - texture.SetData(colorsOne); - - - string Name = reader.ReadString(); - string path = reader.ReadString(); - string modID = reader.ReadString(); - Value.Name = Name; - Value.path = path; - Value.ModID = modID; - Value.setTexture(ModCore.getTextureFromManager(Value.ModID, Value.Name).getTexture()); - } - - protected override void WriteDelta(BinaryWriter writer) - { - /* - - int size = base.Value.getTexture().Width * base.Value.getTexture().Height * 4; - writer.Write(base.Value.getTexture().Width); - writer.Write(base.Value.getTexture().Height); - //writer.Write(size); - texture = Value.getTexture(); - Byte[] colorsOne = new byte[size]; //The hard to read,1D array - texture.GetData(colorsOne); - writer.Write(colorsOne); - - NetString name = new NetString(Value.Name); - name.Write(writer); - - NetString path = new NetString(Value.path); - path.Write(writer); - - NetString id = new NetString(Value.ModID); - id.Write(writer); - } - - - }*/ - - public class NetTexture2DExtended : Netcode.NetField - { - - public string Name; - public Texture2D texture; - public string path; - public int width; - public int height; - - - public NetTexture2DExtended() - { - - } - - public NetTexture2DExtended(Texture2DExtended value) : base(value) - { - } - - protected override void ReadDelta(BinaryReader reader, NetVersion version) - { - int width = reader.ReadInt32(); - int height = reader.ReadInt32(); - Byte[] colorsOne = new byte[width * height * 4]; - colorsOne = reader.ReadBytes(width * height * 4); - texture = new Texture2D(Game1.graphics.GraphicsDevice, width, height); - texture.SetData(colorsOne); - - string Name = reader.ReadString(); - string path = reader.ReadString(); - - if (version.IsPriorityOver(this.ChangeVersion)) - { - this.CleanSet(new UIUtilities.Texture2DExtended(ModCore.ModHelper,ModCore.Manifest, path), true); - } - } - - protected override void WriteDelta(BinaryWriter writer) - { - - int size = base.Value.getTexture().Width * base.Value.getTexture().Height * 4; - writer.Write(base.Value.getTexture().Width); - writer.Write(base.Value.getTexture().Height); - //writer.Write(size); - texture = Value.getTexture(); - Byte[] colorsOne = new byte[size]; //The hard to read,1D array - texture.GetData(colorsOne); - writer.Write(colorsOne); - writer.Write(base.Value.Name); - writer.Write(base.Value.path); - } - - - } -} diff --git a/GeneralMods/StardustCore/NetCode/NetCoreObject.cs b/GeneralMods/StardustCore/NetCode/NetCoreObject.cs index 47bfdf7f..69a07b64 100644 --- a/GeneralMods/StardustCore/NetCode/NetCoreObject.cs +++ b/GeneralMods/StardustCore/NetCode/NetCoreObject.cs @@ -6,19 +6,54 @@ using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Threading.Tasks; using Netcode; +using StardewValley; +using StardustCore.NetCode.Graphics; using StardustCore.UIUtilities; namespace StardustCore.NetCode { - class NetCoreObject : Netcode.NetField + public class NetCoreObject : Netcode.NetField { - public NetTexture2DExtended texture; + public NetInt which; public NetVector2 tilePos; - public NetInt InventoryMaxSize; - public NetRectangle sourceRect; + + public NetRectangle boundingBox; + + + + public NetVector2 position; + public NetInt Decoration_type; + public NetInt rotations; + public NetInt currentRotation; + public NetInt sourceIndexOffset; + public NetVector2 drawPosition; + public NetRectangle sourceRect; + public NetRectangle defaultSourceRect; + public NetRectangle defaultBoundingBox; + public NetString description; + public NetTexture2DExtended texture; + public NetBool flipped; + public NetBool flaggedForPickup; + public NetBool lightGlowAdded; + public NetObjectList inventory; + public NetInt InventoryMaxSize; + public NetBool itemReadyForHarvest; + public NetBool lightsOn; + public NetString locationName; + public NetColor lightColor; + public NetBool removable; + public NetColor drawColor; + public NetBool useXML; + public NetString serializationName; + + //Animation Manager..... + public NetAnimationManager animationManager; + + + public NetCoreObject() { @@ -56,7 +91,15 @@ namespace StardustCore.NetCode boundingBox = new NetRectangle(); boundingBox.Read(reader, version); Value.boundingBox.Value = boundingBox.Value; - + + drawPosition = new NetVector2(); + drawPosition.Read(reader, version); + Value.drawPosition = drawPosition.Value; + + animationManager = new NetAnimationManager(); + animationManager.Read(reader, version); + Value.animationManager = animationManager.Value; + } protected override void WriteDelta(BinaryWriter writer) @@ -79,7 +122,15 @@ namespace StardustCore.NetCode boundingBox = new NetRectangle(Value.boundingBox.Value); sourceRect.Write(writer); - + + drawPosition = new NetVector2(Value.drawPosition); + drawPosition.Write(writer); + + if (Value.animationManager != null) + { + animationManager = new NetAnimationManager(Value.animationManager); + animationManager.Write(writer); + } } } } diff --git a/GeneralMods/StardustCore/Objects/CoreObject.cs b/GeneralMods/StardustCore/Objects/CoreObject.cs index 14abe0d9..491f1c91 100644 --- a/GeneralMods/StardustCore/Objects/CoreObject.cs +++ b/GeneralMods/StardustCore/Objects/CoreObject.cs @@ -54,8 +54,6 @@ namespace StardustCore public bool lightGlowAdded; - public string texturePath; - public List inventory; public int inventoryMaxSize; @@ -68,8 +66,6 @@ namespace StardustCore public Color lightColor; - public string thisType; - public bool removable; public string locationsName; @@ -106,7 +102,6 @@ namespace StardustCore lightsOn = false; lightColor = Color.Black; - thisType = this.GetType().ToString(); base.initNetFields(); this.NetFields.AddField(new NetCode.NetCoreObject(this)); @@ -148,7 +143,6 @@ namespace StardustCore if (TextureSheet == null) { TextureSheet = texture; - this.texturePath = texture.path; } Dictionary dictionary = Game1.content.Load>("Data\\Furniture"); string[] array = dictionary[which].Split(new char[] diff --git a/GeneralMods/StardustCore/Objects/MultiTileComponent.cs b/GeneralMods/StardustCore/Objects/MultiTileComponent.cs index f9feb37a..ddce05ac 100644 --- a/GeneralMods/StardustCore/Objects/MultiTileComponent.cs +++ b/GeneralMods/StardustCore/Objects/MultiTileComponent.cs @@ -26,7 +26,6 @@ namespace StardustCore.Objects this.name = part.name; this.description = part.description; this.TextureSheet = part.getExtendedTexture(); - this.texturePath = this.TextureSheet.path; if (part.animationManager != null) { this.animationManager = part.animationManager; diff --git a/GeneralMods/StardustCore/Objects/MultiTileObject.cs b/GeneralMods/StardustCore/Objects/MultiTileObject.cs index 50642c70..2700b10c 100644 --- a/GeneralMods/StardustCore/Objects/MultiTileObject.cs +++ b/GeneralMods/StardustCore/Objects/MultiTileObject.cs @@ -27,7 +27,6 @@ namespace StardustCore.Objects { this.objects = Objects; this.TextureSheet = texture; - this.texturePath = texture.path; this.categoryColor = CategoryColor; this.categoryName = CategoryName; this.name = Name; @@ -51,7 +50,6 @@ namespace StardustCore.Objects this.animationManager = animationManager; this.objects = Objects; this.TextureSheet =animationManager.getExtendedTexture(); - this.texturePath = animationManager.getExtendedTexture().path; this.name = Name; this.displayName = Name; this.description = Description; diff --git a/GeneralMods/StardustCore/Serialization/Serialization.cs b/GeneralMods/StardustCore/Serialization/Serialization.cs index 1b858e0b..0e289b0e 100644 --- a/GeneralMods/StardustCore/Serialization/Serialization.cs +++ b/GeneralMods/StardustCore/Serialization/Serialization.cs @@ -390,7 +390,7 @@ namespace StardustCore.Serialization { //THE ERROR LIES HERE AS IT THINKS IT CAN TRY TO BE A CORE OBJECT WHEN IT IS NOT!!!! CoreObject core_obj = StardustCore.ModCore.ModHelper.ReadJsonFile(path); //FIND A WAY TO FIX THIS!!!! - type = (core_obj as CoreObject).thisType; + type = (core_obj as CoreObject).serializationName; //ModCore.ModMonitor.Log("UMM THIS CAN't BE RIGHT 1" + type); } @@ -705,7 +705,7 @@ namespace StardustCore.Serialization { //THE ERROR LIES HERE AS IT THINKS IT CAN TRY TO BE A CORE OBJECT WHEN IT IS NOT!!!! CoreObject core_obj = StardustCore.ModCore.ModHelper.ReadJsonFile(path); //FIND A WAY TO FIX THIS!!!! - type = (core_obj as CoreObject).thisType; + type = (core_obj as CoreObject).serializationName; //ModCore.ModMonitor.Log("UMM THIS CAN't BE RIGHT 1" + type); } diff --git a/GeneralMods/StardustCore/StardustCore.csproj b/GeneralMods/StardustCore/StardustCore.csproj index e07c8a51..a25593e4 100644 --- a/GeneralMods/StardustCore/StardustCore.csproj +++ b/GeneralMods/StardustCore/StardustCore.csproj @@ -93,11 +93,14 @@ + + + @@ -447,6 +450,10 @@ PreserveNewest + + + +