diff --git a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs index d647a6d7..19de257d 100644 --- a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs @@ -357,6 +357,12 @@ namespace Revitalize.Framework.Objects //base.drawWhenHeld(spriteBatch, objectPosition, f); } + public void InitNetFields() + { + this.initNetFields(); + } + + public string getDisplayNameFromStringsFile(string objectID) { //Load in a file that has all object names referenced here or something. diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs index 2a4b5c1a..9519d1df 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs @@ -56,13 +56,26 @@ namespace Revitalize.Framework.Objects.Furniture public override Item getOne() { - return new ChairMultiTiledObject(this.info, this.TileLocation, this.objects); + Dictionary objs = new Dictionary(); + foreach (var pair in this.objects) + { + objs.Add(pair.Key, (MultiTiledComponent)pair.Value); + } + + return new ChairMultiTiledObject(this.info, this.TileLocation, objs); } public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) { BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]]; - return new ChairMultiTiledObject(data, (replacement as Chest).TileLocation, this.objects); + + Dictionary objs = new Dictionary(); + foreach (var pair in this.objects) + { + objs.Add(pair.Key, (MultiTiledComponent)pair.Value); + } + + return new ChairMultiTiledObject(data, (replacement as Chest).TileLocation, objs); } public override bool canBePlacedHere(GameLocation l, Vector2 tile) diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs index d76326bc..310d48f6 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -104,7 +105,11 @@ namespace Revitalize.Framework.Objects return component; } - + public override object getReplacement() + { + return base.getReplacement(); + } + public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) { //instead of using this.offsetkey.x use get additional save data function and store offset key there @@ -121,9 +126,10 @@ namespace Revitalize.Framework.Objects if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["GUID"])) { - //Get new container - CustomObject obj = (CustomObject)(Revitalize.ModCore.customObjects[additionalSaveData["ParentID"]].getOne()); + //Get new container + MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.Deserialize(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, additionalSaveData["GUID"] + ".json")); self = (MultiTiledComponent)(obj as MultiTiledObject).objects[offsetKey]; + self.containerObject = obj; Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], (MultiTiledObject)obj); } else @@ -132,19 +138,6 @@ namespace Revitalize.Framework.Objects self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]]; } - self.TileLocation = (replacement as Chest).TileLocation; - - Enums.Direction facingDirection = (Enums.Direction)Convert.ToInt32(additionalSaveData["Rotation"]); - while (self.info.facingDirection != facingDirection) - { - self.rotate(); - } - - if (!string.IsNullOrEmpty(additionalSaveData["GameLocationName"])) - { - self.location = Game1.getLocationFromName(additionalSaveData["GameLocationName"]); - } - return (ICustomObject)self; BasicItemInformation data = Revitalize.ModCore.customObjects[additionalSaveData["id"]].info; return new MultiTiledComponent(data, (replacement as Chest).TileLocation) @@ -248,5 +241,10 @@ namespace Revitalize.Framework.Objects } } + public static implicit operator MultiTiledComponent(Chest chest) + { + return new MultiTiledComponent(new BasicItemInformation(),chest.TileLocation); + } + } } diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs index 1bdfc0f1..4d240496 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Newtonsoft.Json; @@ -11,8 +12,6 @@ namespace Revitalize.Framework.Objects public class MultiTiledObject : CustomObject { public Dictionary objects; - [JsonIgnore] - public Dictionary offSets; public Guid guid; @@ -36,7 +35,6 @@ namespace Revitalize.Framework.Objects public MultiTiledObject() { this.objects = new Dictionary(); - this.offSets = new Dictionary(); this.guid = Guid.NewGuid(); } @@ -44,7 +42,6 @@ namespace Revitalize.Framework.Objects : base(info) { this.objects = new Dictionary(); - this.offSets = new Dictionary(); this.guid = Guid.NewGuid(); } @@ -52,7 +49,6 @@ namespace Revitalize.Framework.Objects : base(info, TileLocation) { this.objects = new Dictionary(); - this.offSets = new Dictionary(); this.guid = Guid.NewGuid(); } @@ -60,7 +56,6 @@ namespace Revitalize.Framework.Objects : base(info, TileLocation) { this.objects = new Dictionary(); - this.offSets = new Dictionary(); foreach (var v in ObjectsList) { MultiTiledComponent component =(MultiTiledComponent) v.Value.getOne(); @@ -75,8 +70,7 @@ namespace Revitalize.Framework.Objects if (this.objects.ContainsKey(key)) return false; - this.objects.Add(key, (obj as MultiTiledComponent)); - this.offSets.Add((obj as MultiTiledComponent), key); + this.objects.Add(key, obj); if (key.X > this.width) this.width = (int)key.X; if (key.Y > this.height) this.height = (int)key.Y; (obj as MultiTiledComponent).containerObject = this; @@ -202,15 +196,20 @@ namespace Revitalize.Framework.Objects public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) { - - MultiTiledObject self=(MultiTiledObject)Revitalize.ModCore.customObjects[additionalSaveData["id"]].getOne(); + + MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.Deserialize(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, additionalSaveData["GUID"] + ".json")); + + foreach(KeyValuePair pair in this.objects) + { + pair.Value.containerObject = obj; + } if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["GUID"])) { - Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], self); - return self; + Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], obj); + return obj; } else { diff --git a/GeneralMods/Revitalize/Framework/Utilities/Serialization/ContractResolvers/NetFieldContract.cs b/GeneralMods/Revitalize/Framework/Utilities/Serialization/ContractResolvers/NetFieldContract.cs new file mode 100644 index 00000000..b17298fc --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Utilities/Serialization/ContractResolvers/NetFieldContract.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; + +namespace Revitalize.Framework.Utilities.Serialization.ContractResolvers +{ + public class NetFieldContract : DefaultContractResolver + { + public static NetFieldContract Instance { get; } = new NetFieldContract(); + + protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) + { + JsonProperty property = base.CreateProperty(member, memberSerialization); + if (member.Name == nameof(StardewValley.Item.NetFields)) + { + property.Ignored = true; + } + return property; + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/NetFieldConverter.cs b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/NetFieldConverter.cs new file mode 100644 index 00000000..e976fdd6 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Converters/NetFieldConverter.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace Revitalize.Framework.Utilities.Serialization.Converters +{ + + public class NetFieldConverter:JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + writer.WriteValue("NetFields"); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, + JsonSerializer serializer) + { + + string str = (string)reader.Value; + //string str=jsonObject.ToObject(serializer); + + return new Netcode.NetFields(); + return null; + } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(Netcode.NetFields); + } + + public override bool CanRead => true; + public override bool CanWrite => true; + } +} diff --git a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs index ce15cbcc..87f5dca2 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/Serialization/Serialization.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using Revitalize.Framework.Utilities.Serialization.ContractResolvers; namespace Revitalize.Framework.Utilities { @@ -25,8 +26,11 @@ namespace Revitalize.Framework.Utilities this.serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; this.serializer.NullValueHandling = NullValueHandling.Include; + this.serializer.ContractResolver = new NetFieldContract(); + this.addConverter(new Framework.Utilities.Serialization.Converters.RectangleConverter()); this.addConverter(new Framework.Utilities.Serialization.Converters.Texture2DConverter()); + this.addConverter(new Framework.Utilities.Serialization.Converters.NetFieldConverter()); //this.addConverter(new Framework.Utilities.Serialization.Converters.Vector2Converter()); } diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 3fc3d586..469bc4b7 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -284,6 +284,7 @@ namespace Revitalize MultiTiledObject hello=Serializer.Deserialize(Path.Combine(this.Helper.DirectoryPath, (obj as MultiTiledObject).guid + ".json")); + //(hello as MultiTiledObject).info.drawColor = Color.Blue; customObjects["Omegasis.BigTiledTest"].info.drawColor = hello.info.drawColor; if (hello == null) log("WTF"); @@ -292,9 +293,13 @@ namespace Revitalize log("AHHHH" + hello.name); } hello.info.drawColor = Color.Blue; - - foreach(KeyValuePair pair in hello.objects){ - pair.Value.containerObject = hello; + if (hello.objects == null) + { + log("NEVER MIND"); + } + foreach(KeyValuePair pair in hello.objects){ + pair.Value.containerObject = hello; + //log((pair.Value as CustomObject).name); } Game1.player.items.Add(hello); diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 62ec2c31..653dd888 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -75,6 +75,8 @@ + +