Test for Serializer working on StardewValley items works. Work can continue.
This commit is contained in:
parent
1e9d253281
commit
d4d62123b0
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
@ -10,6 +11,10 @@ using StardewValley;
|
|||
|
||||
namespace Revitalize.Framework.Utilities.Serialization.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// TODO:
|
||||
/// Add support for all vanilla SDV objects in deserialization.
|
||||
/// </summary>
|
||||
public class ItemCoverter:Newtonsoft.Json.JsonConverter
|
||||
{
|
||||
|
||||
|
@ -72,7 +77,20 @@ namespace Revitalize.Framework.Utilities.Serialization.Converters
|
|||
|
||||
string t = jo["Type"].Value<string>();
|
||||
|
||||
if(t== typeof(StardewValley.Tools.Axe).FullName.ToString())
|
||||
|
||||
Assembly asm = typeof(StardewValley.Object).Assembly;
|
||||
Type type = null;
|
||||
|
||||
type = asm.GetType(t);
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
asm = typeof(Revitalize.ModCore).Assembly;
|
||||
type = asm.GetType(t);
|
||||
}
|
||||
return JsonConvert.DeserializeObject(jo["Item"].ToString(),type, this.settings);
|
||||
/*
|
||||
if (t== typeof(StardewValley.Tools.Axe).FullName.ToString())
|
||||
{
|
||||
Revitalize.ModCore.log("DESERIALIZE AXE!!!");
|
||||
//return jo["Item"].Value<StardewValley.Tools.Axe>();
|
||||
|
@ -80,7 +98,7 @@ namespace Revitalize.Framework.Utilities.Serialization.Converters
|
|||
}
|
||||
else if (t == typeof(Revitalize.Framework.Objects.MultiTiledObject).FullName.ToString())
|
||||
{
|
||||
|
||||
|
||||
Revitalize.ModCore.log("DESERIALIZE Multi Tile Object!!!");
|
||||
return JsonConvert.DeserializeObject<Revitalize.Framework.Objects.MultiTiledObject>(jo["Item"].ToString(), this.settings);
|
||||
// return jo["Item"].Value<Revitalize.Framework.Objects.MultiTiledObject>();
|
||||
|
@ -100,6 +118,8 @@ namespace Revitalize.Framework.Utilities.Serialization.Converters
|
|||
|
||||
throw new NotImplementedException("CANT DESERIALIZE: " + t.ToString());
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,21 @@ namespace Revitalize.Framework.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
public object Deserialize(string p,Type T)
|
||||
{
|
||||
string json = "";
|
||||
foreach (string line in File.ReadLines(p))
|
||||
{
|
||||
json += line;
|
||||
}
|
||||
using (StreamReader sw = new StreamReader(p))
|
||||
using (JsonReader reader = new JsonTextReader(sw))
|
||||
{
|
||||
object obj = this.serializer.Deserialize(reader,T);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes an object to a .json file.
|
||||
/// </summary>
|
||||
|
|
|
@ -282,6 +282,10 @@ namespace Revitalize
|
|||
}
|
||||
Game1.player.addItemToInventory(customObjects["Omegasis.BigTiledTest"]);
|
||||
|
||||
StardewValley.Tools.Axe axe = new StardewValley.Tools.Axe();
|
||||
Serializer.Serialize(Path.Combine(this.Helper.DirectoryPath, "AXE.json"), axe);
|
||||
axe =(StardewValley.Tools.Axe)Serializer.Deserialize(Path.Combine(this.Helper.DirectoryPath, "AXE.json"),typeof(StardewValley.Tools.Axe));
|
||||
Game1.player.addItemToInventory(axe);
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue