2017-09-05 19:13:42 +08:00
|
|
|
|
using StardewValley;
|
2018-06-13 09:42:31 +08:00
|
|
|
|
using StardustCore.Objects.Tools.SerializationInformation;
|
2017-09-05 19:13:42 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace StardustCore.Serialization
|
|
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A class that handles saving/loading custom objects to and from the world.
|
|
|
|
|
/// </summary>
|
2017-09-05 19:13:42 +08:00
|
|
|
|
public class SerializerDataNode
|
|
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A function that handles loading an object back into it's Item form.
|
|
|
|
|
/// </summary>
|
2018-06-13 09:42:31 +08:00
|
|
|
|
/// <param name="path">The path to the file.</param>
|
2018-05-01 09:21:31 +08:00
|
|
|
|
/// <returns></returns>
|
2018-06-13 09:42:31 +08:00
|
|
|
|
public delegate Item ParsingFunction(string path);
|
2018-05-01 09:21:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A function that handles saving an item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item"></param>
|
2017-09-05 19:13:42 +08:00
|
|
|
|
public delegate void SerializingFunction(Item item);
|
2018-05-01 09:21:31 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A function that handles saving an item from/to a container.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item"></param>
|
|
|
|
|
/// <param name="s"></param>
|
2017-09-14 08:11:05 +08:00
|
|
|
|
public delegate void SerializingToContainerFunction(Item item, string s);
|
2018-05-01 09:21:31 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A function that handles saving.loading items into the world.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj"></param>
|
2017-09-05 19:13:42 +08:00
|
|
|
|
public delegate void WorldParsingFunction(Item obj);
|
|
|
|
|
|
2018-05-01 09:21:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves an object to an inventory.
|
|
|
|
|
/// </summary>
|
2017-09-05 19:13:42 +08:00
|
|
|
|
public SerializingFunction serialize;
|
2018-05-01 09:21:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves an object to a container
|
|
|
|
|
/// </summary>
|
2017-09-14 08:11:05 +08:00
|
|
|
|
public SerializingToContainerFunction serializeToContainer;
|
2018-05-01 09:21:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads in an object.
|
|
|
|
|
/// </summary>
|
2017-09-05 19:13:42 +08:00
|
|
|
|
public ParsingFunction parse;
|
2018-05-01 09:21:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads in an object to the game world.
|
|
|
|
|
/// </summary>
|
2017-09-05 19:13:42 +08:00
|
|
|
|
public WorldParsingFunction worldObj;
|
|
|
|
|
|
2018-05-01 09:21:31 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serializeFunction">A function to be ran to save this object.</param>
|
|
|
|
|
/// <param name="parsingFunction">A function to be ran to load this object.</param>
|
|
|
|
|
/// <param name="worldObjectParsingFunction">A function to be ran to load this object to the world.</param>
|
|
|
|
|
/// <param name="containerSerializationFunction">A function to be ran to save/load objects to storage containers such as chests.</param>
|
2017-09-14 08:11:05 +08:00
|
|
|
|
public SerializerDataNode(SerializingFunction serializeFunction, ParsingFunction parsingFunction, WorldParsingFunction worldObjectParsingFunction, SerializingToContainerFunction containerSerializationFunction)
|
2017-09-05 19:13:42 +08:00
|
|
|
|
{
|
|
|
|
|
serialize = serializeFunction;
|
|
|
|
|
parse = parsingFunction;
|
2017-09-14 08:11:05 +08:00
|
|
|
|
worldObj = worldObjectParsingFunction;
|
|
|
|
|
serializeToContainer = containerSerializationFunction;
|
2017-09-05 19:13:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|