Merge branch 'Development' of https://github.com/janavarro95/Stardew_Valley_Mods into Development

This commit is contained in:
2018-08-08 00:24:56 -07:00
commit 713ec38603
10 changed files with 119 additions and 175 deletions

View File

@ -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
{
@ -19,12 +21,15 @@ namespace StardustCore.Animations
/// <summary>
/// The duration of the frame in length.
/// </summary>
public readonly int frameDuration;
public int frameDuration;
/// <summary>
/// The duration until the next frame.
/// </summary>
public int frameCountUntilNextAnimation;
[XmlIgnore]
public NetFields NetFields { get; } = new NetFields();
/// <summary>

View File

@ -16,15 +16,17 @@ namespace StardustCore.Animations
/// </summary>
public class AnimationManager
{
public Dictionary<string, List<Animation>> animations = new Dictionary<string, List<Animation>>();
public Dictionary<string, List<Animation>> animations = new SerializableDictionary<string, List<Animation>>();
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 Animation defaultDrawFrame;
public Animation currentAnimation;
bool enabled;
public bool enabled;
public string animationDataString;
/// <summary>
/// Constructor for Animation Manager class.
/// </summary>
@ -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<string, List<Animation>> 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<string,List<Animations.Animation>> 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;
}
/// <summary>
/// Update the animation frame once after drawing the object.
/// </summary>
@ -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();

View File

@ -176,6 +176,8 @@ namespace StardustCore
tile1.Name = "test";
tile1.displayName = "test";
Game1.player.addItemToInventory(tile1);
}
private void SaveEvents_AfterSave(object sender, EventArgs e)

View File

@ -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<UIUtilities.Texture2DExtended, NetTexture2DExtended>
{
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<UIUtilities.Texture2DExtended, NetTexture2DExtended>
{
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);
}
}
}

View File

@ -6,20 +6,55 @@ 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<CoreObject,NetCoreObject>
public class NetCoreObject : Netcode.NetField<CoreObject,NetCoreObject>
{
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<Item> 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()
{
@ -57,6 +92,14 @@ namespace StardustCore.NetCode
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)
@ -80,6 +123,14 @@ 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);
}
}
}
}

View File

@ -54,8 +54,6 @@ namespace StardustCore
public bool lightGlowAdded;
public string texturePath;
public List<Item> 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<int, string> dictionary = Game1.content.Load<Dictionary<int, string>>("Data\\Furniture");
string[] array = dictionary[which].Split(new char[]

View File

@ -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;

View File

@ -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;

View File

@ -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<CoreObject>(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<CoreObject>(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);
}

View File

@ -93,11 +93,14 @@
<Compile Include="Interfaces\IToolSerializer.cs" />
<Compile Include="Math\Hex.cs" />
<Compile Include="Math\Hex32.cs" />
<Compile Include="NetCode\Graphics\NetAnimation.cs" />
<Compile Include="NetCode\Graphics\NetAnimationManager.cs" />
<Compile Include="NetCode\ModdedClient.cs" />
<Compile Include="NetCode\ModdedGameServer.cs" />
<Compile Include="NetCode\NetBufferReadStream.cs" />
<Compile Include="NetCode\NetBufferWriteStream.cs" />
<Compile Include="NetCode\NetCoreObject.cs" />
<Compile Include="NetCode\NetKeyValuePair.cs" />
<Compile Include="NetCode\NetTexure2DExtended.cs" />
<Compile Include="Objects\MultiTileComponent.cs" />
<Compile Include="Objects\MultiTileObject.cs" />
@ -447,6 +450,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="NetCode\NetDictionaries\" />
<Folder Include="NetCode\NetLists\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\deploy.targets" />
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.2.1.0-beta-20180428\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.2.1.0-beta-20180428\build\Pathoschild.Stardew.ModBuildConfig.targets')" />