Better saving for objects but need a way to delete them.
This commit is contained in:
parent
77fec4be31
commit
08847c6bb1
|
@ -122,12 +122,12 @@ namespace Revitalize.Framework.Objects
|
|||
//do same container creation logic in multitiled object
|
||||
|
||||
|
||||
MultiTiledComponent self = Revitalize.ModCore.Serializer.Deserialize<MultiTiledComponent>(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, additionalSaveData["GUID"] + ".json"));
|
||||
MultiTiledComponent self = Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>( additionalSaveData["GUID"]);
|
||||
|
||||
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"]))
|
||||
{
|
||||
//Get new container
|
||||
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.Deserialize<MultiTiledObject>(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, additionalSaveData["ParentGUID"] + ".json"));
|
||||
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledObject>(additionalSaveData["ParentGUID"]);
|
||||
self.containerObject = obj;
|
||||
obj.addComponent(offsetKey, self);
|
||||
Revitalize.ModCore.log("ADD IN AN OBJECT!!!!");
|
||||
|
@ -178,7 +178,7 @@ namespace Revitalize.Framework.Objects
|
|||
|
||||
saveData.Add("ParentGUID", this.containerObject.guid.ToString());
|
||||
saveData.Add("GUID", this.guid.ToString());
|
||||
Revitalize.ModCore.Serializer.Serialize(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, this.containerObject.childrenGuids[this.offsetKey].ToString() + ".json"),this);
|
||||
Revitalize.ModCore.Serializer.SerializeGUID(this.containerObject.childrenGuids[this.offsetKey].ToString(),this);
|
||||
|
||||
return saveData;
|
||||
|
||||
|
|
|
@ -212,9 +212,8 @@ namespace Revitalize.Framework.Objects
|
|||
|
||||
|
||||
|
||||
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.Deserialize<MultiTiledObject>(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, additionalSaveData["GUID"] + ".json"));
|
||||
|
||||
Revitalize.ModCore.log("OK I SUPPOSE");
|
||||
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledObject>(additionalSaveData["GUID"]);
|
||||
|
||||
|
||||
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
|
||||
|
||||
|
@ -226,8 +225,8 @@ namespace Revitalize.Framework.Objects
|
|||
foreach(KeyValuePair<Vector2,Guid> pair in guids)
|
||||
{
|
||||
obj.childrenGuids.Remove(pair.Key);
|
||||
Revitalize.ModCore.log("DESERIALIZE: " + pair.Value.ToString());
|
||||
MultiTiledComponent component= (MultiTiledComponent)Revitalize.ModCore.Serializer.Deserialize<MultiTiledComponent>(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, pair.Value + ".json"));
|
||||
//Revitalize.ModCore.log("DESERIALIZE: " + pair.Value.ToString());
|
||||
MultiTiledComponent component= Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>(pair.Value.ToString());
|
||||
component.InitNetFields();
|
||||
|
||||
obj.addComponent(pair.Key, component);
|
||||
|
@ -254,7 +253,7 @@ namespace Revitalize.Framework.Objects
|
|||
Dictionary<string,string> saveData= base.getAdditionalSaveData();
|
||||
saveData.Add("GUID", this.guid.ToString());
|
||||
|
||||
Revitalize.ModCore.Serializer.Serialize(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, this.guid.ToString() + ".json"), this);
|
||||
Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this);
|
||||
return saveData;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Revitalize.Framework.Utilities.Serialization.ContractResolvers;
|
||||
using StardewValley;
|
||||
|
||||
namespace Revitalize.Framework.Utilities
|
||||
{
|
||||
|
@ -96,5 +97,24 @@ namespace Revitalize.Framework.Utilities
|
|||
this.serializer.Serialize(writer, o);
|
||||
}
|
||||
}
|
||||
|
||||
public void SerializeGUID(string fileName,object obj)
|
||||
{
|
||||
string path = Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, "SaveData", Game1.player.name + "_" + Game1.player.uniqueMultiplayerID, "SavedObjectInformation", fileName + ".json");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
Serialize(path, obj);
|
||||
}
|
||||
|
||||
public object DeserializeGUID(string fileName,Type T)
|
||||
{
|
||||
string path=Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, "SaveData", Game1.player.name + "_" + Game1.player.uniqueMultiplayerID, "SavedObjectInformation", fileName + ".json");
|
||||
return Deserialize(path, T);
|
||||
}
|
||||
|
||||
public T DeserializeGUID<T>(string fileName)
|
||||
{
|
||||
string path = Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, "SaveData", Game1.player.name + "_" + Game1.player.uniqueMultiplayerID, "SavedObjectInformation", fileName + ".json");
|
||||
return Deserialize<T>(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue