Moved around soem files, made a core library mod that will include a bunch of things in the future. For the moment, a custom serializer/deserializer. Implemented it with AdditionalCrops. Needs some more work.
This commit is contained in:
parent
4fd79dae21
commit
fa5970661b
|
@ -32,6 +32,13 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="StardustCore">
|
||||
<HintPath>..\StardustCore\bin\Release\StardustCore.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
|
@ -42,7 +49,6 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CoreObject.cs" />
|
||||
<Compile Include="Framework\TerrainDataNode.cs" />
|
||||
<Compile Include="ModCore.cs" />
|
||||
<Compile Include="Framework\Utilities.cs" />
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using AdditionalCropsFramework.Framework;
|
||||
using Microsoft.Xna.Framework;
|
||||
using StardewModdingAPI;
|
||||
using StardewValley;
|
||||
using StardewValley.Locations;
|
||||
using StardewValley.Objects;
|
||||
using StardewValley.TerrainFeatures;
|
||||
using StardustCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -11,12 +13,12 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using xTile.Dimensions;
|
||||
|
||||
namespace AdditionalCropsFramework.Framework
|
||||
namespace AdditionalCropsFramework
|
||||
{
|
||||
class Utilities
|
||||
{
|
||||
public static List<TerrainDataNode> trackedTerrainFeatures= new List<TerrainDataNode>();
|
||||
public static List<CoreObject> trackedObjectList = new List<CoreObject>();
|
||||
|
||||
public static List<CoreObject> NonSolidThingsToDraw = new List<CoreObject>();
|
||||
|
||||
|
||||
|
@ -684,7 +686,7 @@ namespace AdditionalCropsFramework.Framework
|
|||
}
|
||||
//Log.AsyncM("Placed and object");
|
||||
cObj.locationsName = location.name;
|
||||
trackedObjectList.Add(cObj);
|
||||
ModCore.serilaizationManager.trackedObjectList.Add(cObj);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
@ -697,7 +699,7 @@ namespace AdditionalCropsFramework.Framework
|
|||
if (Game1.player.isInventoryFull() == false)
|
||||
{
|
||||
Game1.player.addItemToInventoryBool(I, false);
|
||||
trackedObjectList.Remove(I);
|
||||
ModCore.serilaizationManager.trackedObjectList.Remove(I);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -712,5 +714,22 @@ namespace AdditionalCropsFramework.Framework
|
|||
}
|
||||
|
||||
|
||||
public static Microsoft.Xna.Framework.Rectangle parseRectFromJson(string s)
|
||||
{
|
||||
|
||||
|
||||
|
||||
s = s.Replace('{', ' ');
|
||||
s = s.Replace('}', ' ');
|
||||
s = s.Replace('^', ' ');
|
||||
s = s.Replace(':', ' ');
|
||||
string[] parsed = s.Split(' ');
|
||||
foreach (var v in parsed)
|
||||
{
|
||||
//Log.AsyncY(v);
|
||||
}
|
||||
return new Microsoft.Xna.Framework.Rectangle(Convert.ToInt32(parsed[2]), Convert.ToInt32(parsed[4]), Convert.ToInt32(parsed[6]), Convert.ToInt32(parsed[8]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,15 @@ using Microsoft.Xna.Framework;
|
|||
using Microsoft.Xna.Framework.Input;
|
||||
using StardewModdingAPI;
|
||||
using StardewValley;
|
||||
using StardustCore.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace AdditionalCropsFramework
|
||||
{
|
||||
|
||||
|
@ -21,15 +24,21 @@ namespace AdditionalCropsFramework
|
|||
! Add way for crops to be watered and to ensure that there is a graphical update when the crop is being watered.
|
||||
! Add way to harvest crop from planterbox without removing planterbox.
|
||||
! Fix invisible planterbox so that it does get removed when planting seeds on tillable soil and keep that soil as HoeDirt instead of reverting to normal. This can also be used to just make the dirt look wet.
|
||||
* * */
|
||||
! Add in Multiple layers to the Planter Boxes: SoilLayer->CropLayer->BoxLayer is the draw order. Mainly for aesthetics. Box on top, dry dirt below, and wet dirt below that.
|
||||
* * * */
|
||||
public class ModCore : Mod
|
||||
{
|
||||
public static IModHelper ModHelper;
|
||||
|
||||
|
||||
|
||||
|
||||
public static readonly List<ModularCropObject> SpringWildCrops = new List<ModularCropObject>();
|
||||
public static readonly List<ModularCropObject> SummerWildCrops = new List<ModularCropObject>();
|
||||
public static readonly List<ModularCropObject> FallWildCrops = new List<ModularCropObject>();
|
||||
public static readonly List<ModularCropObject> WinterWildCrops = new List<ModularCropObject>();
|
||||
public static SerializationManager serilaizationManager;
|
||||
|
||||
|
||||
|
||||
public override void Entry(IModHelper helper)
|
||||
|
@ -37,10 +46,36 @@ namespace AdditionalCropsFramework
|
|||
ModHelper = helper;
|
||||
|
||||
StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed;
|
||||
StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
|
||||
StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
|
||||
StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void SaveEvents_AfterSave(object sender, EventArgs e)
|
||||
{
|
||||
serilaizationManager.restoreAllModObjects(serilaizationManager.trackedObjectList);
|
||||
}
|
||||
|
||||
private void SaveEvents_BeforeSave(object sender, EventArgs e)
|
||||
{
|
||||
serilaizationManager.cleanUpInventory();
|
||||
serilaizationManager.cleanUpWorld();
|
||||
}
|
||||
|
||||
private void SaveEvents_AfterLoad(object sender, EventArgs e)
|
||||
{
|
||||
string invPath = Path.Combine(ModCore.ModHelper.DirectoryPath,Game1.player.name,"PlayerInventory");
|
||||
string worldPath = Path.Combine(ModCore.ModHelper.DirectoryPath, Game1.player.name, "ObjectsInWorld"); ;
|
||||
string trashPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "ModTrashFolder");
|
||||
serilaizationManager = new SerializationManager(invPath,trashPath,worldPath);
|
||||
|
||||
serilaizationManager.acceptedTypes.Add("AdditionalCropsFramework.PlanterBox", new SerializerDataNode(new SerializerDataNode.SerializingFunction(PlanterBox.Serialize), new SerializerDataNode.ParsingFunction(PlanterBox.ParseIntoInventory), new SerializerDataNode.WorldParsingFunction(PlanterBox.SerializeFromWorld))); //need serialize, deserialize, and world deserialize functions.
|
||||
|
||||
serilaizationManager.restoreAllModObjects(serilaizationManager.trackedObjectList);
|
||||
}
|
||||
|
||||
|
||||
private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e)
|
||||
|
@ -50,7 +85,7 @@ namespace AdditionalCropsFramework
|
|||
List<Item> shopInventory = new List<Item>();
|
||||
shopInventory.Add((Item)new ModularSeeds(1, "SeedsGraphics", "SeedsData", "CropsGraphics", "CropsData","CropsObjectTexture","CropsObjectData"));
|
||||
shopInventory.Add((Item)new PlanterBox(0, Vector2.Zero));
|
||||
shopInventory.Add((Item)new PlanterBox(1, Vector2.Zero, "PlanterBox.png", "PlanterBox"));
|
||||
shopInventory.Add((Item)new PlanterBox(1, Vector2.Zero, "PlanterBox.png", "PlanterBox.xnb"));
|
||||
Game1.activeClickableMenu = new StardewValley.Menus.ShopMenu(shopInventory);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ namespace StardewValley
|
|||
if (junimoHarvester != null)
|
||||
junimoHarvester.tryToAddItemToHut((Item)new ModularCropObject(this.indexOfHarvest, 1, this.cropObjectTexture, this.cropObjectData));
|
||||
else
|
||||
AdditionalCropsFramework.Framework.Utilities.createObjectDebris((Item)new ModularCropObject(this.indexOfHarvest, this.getAmountForHarvest(), this.cropObjectTexture, this.cropObjectData), xTile, yTile, xTile, yTile, -1, this.getQualityOfCrop(), 1);
|
||||
AdditionalCropsFramework.Utilities.createObjectDebris((Item)new ModularCropObject(this.indexOfHarvest, this.getAmountForHarvest(), this.cropObjectTexture, this.cropObjectData), xTile, yTile, xTile, yTile, -1, this.getQualityOfCrop(), 1);
|
||||
|
||||
//Game1.createObjectDebris(this.indexOfHarvest, xTile, yTile, -1, num2, 1f, (GameLocation)null);
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ namespace StardewValley
|
|||
for (int index = 0; index < num1 - 1; ++index)
|
||||
{
|
||||
if (junimoHarvester == null)
|
||||
AdditionalCropsFramework.Framework.Utilities.createObjectDebris((Item)new ModularCropObject(this.indexOfHarvest, this.getAmountForHarvest(), this.cropObjectTexture, this.cropObjectData), xTile, yTile, xTile, yTile, -1, this.getQualityOfCrop(), 1);
|
||||
AdditionalCropsFramework.Utilities.createObjectDebris((Item)new ModularCropObject(this.indexOfHarvest, this.getAmountForHarvest(), this.cropObjectTexture, this.cropObjectData), xTile, yTile, xTile, yTile, -1, this.getQualityOfCrop(), 1);
|
||||
else
|
||||
junimoHarvester.tryToAddItemToHut((Item)new ModularCropObject(this.indexOfHarvest, this.getAmountForHarvest(), this.cropObjectTexture, this.cropObjectData));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using StardewValley;
|
|||
using StardewValley.Locations;
|
||||
using StardewValley.Menus;
|
||||
using StardewValley.Objects;
|
||||
using StardustCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
@ -16,7 +17,7 @@ namespace AdditionalCropsFramework
|
|||
/// Revitalize ModularCropObject Class. This is a core class and should only be extended upon.
|
||||
/// </summary>
|
||||
///
|
||||
public class ModularCropObject : StardewValley.Object
|
||||
public class ModularCropObject : CoreObject
|
||||
{
|
||||
|
||||
public new int price;
|
||||
|
@ -100,7 +101,6 @@ namespace AdditionalCropsFramework
|
|||
});
|
||||
this.name = array[0];
|
||||
|
||||
this.Decoration_type = this.getTypeNumberFromName(array[1]);
|
||||
this.description = "Can be placed inside your house.";
|
||||
this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 1, 1);
|
||||
if (array[2].Equals("-1"))
|
||||
|
@ -1244,41 +1244,6 @@ namespace AdditionalCropsFramework
|
|||
return new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, num * Game1.tileSize, num2 * Game1.tileSize);
|
||||
}
|
||||
|
||||
private int getTypeNumberFromName(string typeName)
|
||||
{
|
||||
string key;
|
||||
switch (key = typeName.ToLower())
|
||||
{
|
||||
case "chair":
|
||||
return 0;
|
||||
case "bench":
|
||||
return 1;
|
||||
case "couch":
|
||||
return 2;
|
||||
case "armchair":
|
||||
return 3;
|
||||
case "dresser":
|
||||
return 4;
|
||||
case "long table":
|
||||
return 5;
|
||||
case "painting":
|
||||
return 6;
|
||||
case "lamp":
|
||||
return 7;
|
||||
case "decor":
|
||||
return 8;
|
||||
case "bookcase":
|
||||
return 10;
|
||||
case "table":
|
||||
return 11;
|
||||
case "rug":
|
||||
return 12;
|
||||
case "window":
|
||||
return 13;
|
||||
}
|
||||
return 9;
|
||||
}
|
||||
|
||||
public override int salePrice()
|
||||
{
|
||||
return this.price;
|
||||
|
@ -1406,8 +1371,10 @@ namespace AdditionalCropsFramework
|
|||
public override Color getCategoryColor()
|
||||
{
|
||||
return Color.DarkBlue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
using StardustCore;
|
||||
using StardewModdingAPI;
|
||||
using StardewValley;
|
||||
using StardewValley.Locations;
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
using AdditionalCropsFramework.Framework;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
using StardewModdingAPI;
|
||||
using StardewValley;
|
||||
using StardewValley.Locations;
|
||||
using StardewValley.Menus;
|
||||
using StardewValley.Objects;
|
||||
using StardustCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace AdditionalCropsFramework
|
||||
|
@ -58,6 +60,8 @@ namespace AdditionalCropsFramework
|
|||
public ModularCrop modularCrop;
|
||||
public bool isWatered;
|
||||
|
||||
public string serializationName="AdditionalCropsFramework.PlanterBox";
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
|
@ -79,6 +83,7 @@ namespace AdditionalCropsFramework
|
|||
public PlanterBox(int which, Vector2 tile, bool isRemovable = true, int price = 0, bool isSolid = false)
|
||||
{
|
||||
removable = isRemovable;
|
||||
this.serializationName =Convert.ToString(GetType());
|
||||
// this.thisType = GetType();
|
||||
this.tileLocation = tile;
|
||||
this.InitializeBasics(0, tile);
|
||||
|
@ -122,6 +127,7 @@ namespace AdditionalCropsFramework
|
|||
public PlanterBox(int which, Vector2 tile, string ObjectTexture, bool isRemovable = true, int price = 0, bool isSolid = false)
|
||||
{
|
||||
removable = isRemovable;
|
||||
this.serializationName = Convert.ToString(GetType());
|
||||
// this.thisType = GetType();
|
||||
this.tileLocation = tile;
|
||||
this.InitializeBasics(0, tile);
|
||||
|
@ -130,7 +136,7 @@ namespace AdditionalCropsFramework
|
|||
TextureSheet = ModCore.ModHelper.Content.Load<Texture2D>(ObjectTexture); //Game1.content.Load<Texture2D>("TileSheets\\furniture");
|
||||
texturePath = ObjectTexture;
|
||||
}
|
||||
|
||||
this.dataPath = "";
|
||||
|
||||
this.name = "Planter Box";
|
||||
this.description = "A planter box that can be used to grow many different crops in many different locations.";
|
||||
|
@ -164,16 +170,23 @@ namespace AdditionalCropsFramework
|
|||
|
||||
public PlanterBox(int which, Vector2 tile, string ObjectTexture, string DataPath, bool isRemovable = true, bool isSolid = false)
|
||||
{
|
||||
this.serializationName = Convert.ToString(GetType());
|
||||
removable = isRemovable;
|
||||
// this.thisType = GetType();
|
||||
this.tileLocation = tile;
|
||||
this.InitializeBasics(0, tile);
|
||||
TextureSheet = ModCore.ModHelper.Content.Load<Texture2D>(ObjectTexture); //Game1.content.Load<Texture2D>("TileSheets\\furniture");
|
||||
texturePath = ObjectTexture;
|
||||
Dictionary<int, string> dictionary = ModCore.ModHelper.Content.Load<Dictionary<int, string>>(DataPath);
|
||||
Dictionary<int, string> dictionary;
|
||||
try
|
||||
{
|
||||
|
||||
dictionary = ModCore.ModHelper.Content.Load<Dictionary<int, string>>(DataPath);
|
||||
dataPath = DataPath;
|
||||
string s="";
|
||||
dictionary.TryGetValue(which,out s);
|
||||
|
||||
|
||||
string s = "";
|
||||
dictionary.TryGetValue(which, out s);
|
||||
string[] array = s.Split('/');
|
||||
this.name = array[0];
|
||||
this.description = array[1];
|
||||
|
@ -200,9 +213,15 @@ namespace AdditionalCropsFramework
|
|||
}
|
||||
this.defaultBoundingBox = this.boundingBox;
|
||||
this.updateDrawPosition();
|
||||
this.price =Convert.ToInt32(array[2]);
|
||||
this.price = Convert.ToInt32(array[2]);
|
||||
this.parentSheetIndex = which;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.AsyncC(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override string getDescription()
|
||||
|
@ -305,6 +324,7 @@ namespace AdditionalCropsFramework
|
|||
Utilities.addItemToInventoryAndCleanTrackedList(this);
|
||||
this.flaggedForPickUp = true;
|
||||
this.thisLocation = null;
|
||||
this.locationsName = "";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -324,6 +344,7 @@ namespace AdditionalCropsFramework
|
|||
// this.heldObject = null;
|
||||
Game1.playSound("coin");
|
||||
this.thisLocation = null;
|
||||
this.locationsName = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -337,6 +358,7 @@ namespace AdditionalCropsFramework
|
|||
Utilities.addItemToInventoryAndCleanTrackedList(this);
|
||||
Game1.playSound("coin");
|
||||
this.thisLocation = null;
|
||||
this.locationsName = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -678,15 +700,15 @@ namespace AdditionalCropsFramework
|
|||
this.modularCrop.draw(Game1.spriteBatch, this.tileLocation, Color.White, 0);
|
||||
Log.AsyncM("draw a modular crop now");
|
||||
}
|
||||
Log.AsyncC("wait WTF");
|
||||
// Log.AsyncC("wait WTF");
|
||||
|
||||
if (this.crop != null)
|
||||
{
|
||||
this.crop.draw(Game1.spriteBatch, this.tileLocation, Color.White, 0);
|
||||
Log.AsyncG("COWS GO MOO");
|
||||
// Log.AsyncG("COWS GO MOO");
|
||||
}
|
||||
}
|
||||
else Log.AsyncM("I DONT UNDERSTAND");
|
||||
//else Log.AsyncM("I DONT UNDERSTAND");
|
||||
}
|
||||
|
||||
public void drawAtNonTileSpot(SpriteBatch spriteBatch, Vector2 location, float layerDepth, float alpha = 1f)
|
||||
|
@ -720,5 +742,112 @@ namespace AdditionalCropsFramework
|
|||
{
|
||||
return Color.Purple;
|
||||
}
|
||||
|
||||
public static new void Serialize(Item I)
|
||||
{
|
||||
ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.playerInventoryPath, I.Name + ".json"), (PlanterBox)I);
|
||||
}
|
||||
|
||||
public static Item ParseIntoInventory(string s)
|
||||
{
|
||||
// PlanterBox p = new PlanterBox();
|
||||
// return p;
|
||||
|
||||
|
||||
|
||||
dynamic obj = JObject.Parse(s);
|
||||
|
||||
PlanterBox d = new PlanterBox();
|
||||
|
||||
d.dataPath = obj.dataPath;
|
||||
d.price = obj.price;
|
||||
d.Decoration_type = obj.Decoration_type;
|
||||
d.rotations = obj.rotations;
|
||||
d.currentRotation = obj.currentRotation;
|
||||
string s1 = Convert.ToString(obj.sourceRect);
|
||||
d.sourceRect = Utilities.parseRectFromJson(s1);
|
||||
string s2 = Convert.ToString(obj.defaultSourceRect);
|
||||
d.defaultSourceRect = Utilities.parseRectFromJson(s2);
|
||||
string s3 = Convert.ToString(obj.defaultBoundingBox);
|
||||
d.defaultBoundingBox = Utilities.parseRectFromJson(s3);
|
||||
d.description = obj.description;
|
||||
d.flipped = obj.flipped;
|
||||
d.flaggedForPickUp = obj.flaggedForPickUp;
|
||||
d.tileLocation = obj.tileLocation;
|
||||
d.parentSheetIndex = obj.parentSheetIndex;
|
||||
d.owner = obj.owner;
|
||||
d.name = obj.name;
|
||||
d.type = obj.type;
|
||||
d.canBeSetDown = obj.canBeSetDown;
|
||||
d.canBeGrabbed = obj.canBeGrabbed;
|
||||
d.isHoedirt = obj.isHoedirt;
|
||||
d.isSpawnedObject = obj.isSpawnedObject;
|
||||
d.questItem = obj.questItem;
|
||||
d.isOn = obj.isOn;
|
||||
d.fragility = obj.fragility;
|
||||
d.edibility = obj.edibility;
|
||||
d.stack = obj.stack;
|
||||
d.quality = obj.quality;
|
||||
d.bigCraftable = obj.bigCraftable;
|
||||
d.setOutdoors = obj.setOutdoors;
|
||||
d.setIndoors = obj.setIndoors;
|
||||
d.readyForHarvest = obj.readyForHarvest;
|
||||
d.showNextIndex = obj.showNextIndex;
|
||||
d.hasBeenPickedUpByFarmer = obj.hasBeenPickedUpByFarmer;
|
||||
d.isRecipe = obj.isRecipe;
|
||||
d.isLamp = obj.isLamp;
|
||||
d.heldObject = obj.heldObject;
|
||||
d.minutesUntilReady = obj.minutesUntilReady;
|
||||
string s4 = Convert.ToString(obj.boundingBox);
|
||||
d.boundingBox = Utilities.parseRectFromJson(s4);
|
||||
d.scale = obj.scale;
|
||||
d.lightSource = obj.lightSource;
|
||||
d.shakeTimer = obj.shakeTimer;
|
||||
d.internalSound = obj.internalSound;
|
||||
d.specialVariable = obj.specialVariable;
|
||||
d.category = obj.category;
|
||||
d.specialItem = obj.specialItem;
|
||||
d.hasBeenInInventory = obj.hasBeenInInventory;
|
||||
string t = obj.texturePath;
|
||||
|
||||
// Log.AsyncC(t);
|
||||
|
||||
d.TextureSheet = ModCore.ModHelper.Content.Load<Texture2D>(t);
|
||||
d.texturePath = t;
|
||||
JArray array = obj.inventory;
|
||||
d.inventory = array.ToObject<List<Item>>();
|
||||
d.inventoryMaxSize = obj.inventoryMaxSize;
|
||||
d.itemReadyForHarvest = obj.itemReadyForHarvest;
|
||||
d.lightsOn = obj.lightsOn;
|
||||
// d.thisLocation = Game1.getLocationFromName(loc);
|
||||
// d.thisLocation = obj.thisLocation;
|
||||
// Log.AsyncC(d.thisLocation);
|
||||
d.lightColor = obj.lightColor;
|
||||
d.thisType = obj.thisType;
|
||||
d.removable = obj.removable;
|
||||
d.locationsName = obj.locationsName;
|
||||
|
||||
d.drawColor = obj.drawColor;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
return d;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.AsyncM(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
//return base.ParseIntoInventory();
|
||||
}
|
||||
|
||||
public static void SerializeFromWorld(Item c)
|
||||
{
|
||||
ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, (c as CoreObject).thisLocation.name, c.Name + ".json"), (PlanterBox)c);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
|
||||
<package id="Pathoschild.Stardew.ModBuildConfig" version="1.7.1" targetFramework="net45" />
|
||||
</packages>
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OmegasisCoreLibrary
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>da14f02d-8949-45a3-8023-dd07ac53fa8b</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>OmegasisCoreLibrary</RootNamespace>
|
||||
<AssemblyName>OmegasisCoreLibrary</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System"/>
|
||||
|
||||
<Reference Include="System.Core"/>
|
||||
<Reference Include="System.Xml.Linq"/>
|
||||
<Reference Include="System.Data.DataSetExtensions"/>
|
||||
|
||||
|
||||
<Reference Include="Microsoft.CSharp"/>
|
||||
|
||||
<Reference Include="System.Data"/>
|
||||
|
||||
<Reference Include="System.Net.Http"/>
|
||||
|
||||
<Reference Include="System.Xml"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Class1.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("OmegasisCoreLibrary")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("OmegasisCoreLibrary")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("da14f02d-8949-45a3-8023-dd07ac53fa8b")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,19 @@
|
|||
using StardewModdingAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serialization
|
||||
{
|
||||
public class ModCore: Mod
|
||||
{
|
||||
public override void Entry(IModHelper helper)
|
||||
{
|
||||
//base.Entry(helper);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace AdditionalCropsFramework
|
||||
namespace Omegasis.CoreLibraries
|
||||
{
|
||||
/// <summary>
|
||||
/// Extends StardewValley.Object. Might be broken and just mainly uses a ton of junk code.
|
||||
|
@ -1547,5 +1547,22 @@ namespace AdditionalCropsFramework
|
|||
}
|
||||
|
||||
|
||||
public static void Serialize(Item I)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static Item ParseIntoInventory()
|
||||
{
|
||||
Item I = new CoreObject(0, Vector2.Zero, 0);
|
||||
return I;
|
||||
}
|
||||
|
||||
public static void ParseIntoWorld()
|
||||
{
|
||||
//Item I = new CoreObject(0, Vector2.Zero, 0);
|
||||
//return I;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Serialization")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Serialization")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("e61753a9-057d-4495-b904-133269a802ea")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,293 @@
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Omegasis.CoreLibraries;
|
||||
using StardewValley;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace Serialization
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// TODO: Find a way to serialize objects and tools.
|
||||
/// </summary>
|
||||
|
||||
|
||||
public class SerializationManager
|
||||
{
|
||||
public string objectsInWorldPath;
|
||||
public string playerInventoryPath;
|
||||
public string SerializerTrashPath;
|
||||
|
||||
public Dictionary<string, SerializerDataNode> acceptedTypes = new Dictionary<string, SerializerDataNode>();
|
||||
|
||||
public SerializationManager(string PlayerInventoryPath,string SerializerTrashPath,string ObjectsInWorldPath)
|
||||
{
|
||||
this.objectsInWorldPath = ObjectsInWorldPath;
|
||||
this.playerInventoryPath = PlayerInventoryPath;
|
||||
this.SerializerTrashPath = SerializerTrashPath;
|
||||
|
||||
verifyAllDirectoriesExist();
|
||||
}
|
||||
|
||||
private void verifyAllDirectoriesExist()
|
||||
{
|
||||
if (!Directory.Exists(this.playerInventoryPath)) Directory.CreateDirectory(this.playerInventoryPath);
|
||||
//if (!Directory.Exists(this.SerializerTrashPath)) Directory.CreateDirectory(this.playerInventoryPath);
|
||||
if (!Directory.Exists(this.objectsInWorldPath)) Directory.CreateDirectory(this.playerInventoryPath);
|
||||
}
|
||||
|
||||
public void cleanUpInventory()
|
||||
{
|
||||
ProcessDirectoryForDeletion(playerInventoryPath);
|
||||
|
||||
//ProcessDirectoryForDeletion(SerializerTrashPath);
|
||||
|
||||
List<Item> removalList = new List<Item>();
|
||||
foreach (Item d in Game1.player.items)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (d == null)
|
||||
{
|
||||
//Log.AsyncG("WTF");
|
||||
continue;
|
||||
}
|
||||
// Log.AsyncC(d.GetType());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
string s = Convert.ToString((d.GetType()));
|
||||
|
||||
|
||||
|
||||
|
||||
if (acceptedTypes.ContainsKey(s))
|
||||
{
|
||||
SerializerDataNode t;
|
||||
|
||||
bool works = acceptedTypes.TryGetValue(s, out t);
|
||||
if (works == true)
|
||||
{
|
||||
t.serialize.Invoke(d);
|
||||
removalList.Add(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var i in removalList)
|
||||
{
|
||||
Game1.player.removeItemFromInventory(i);
|
||||
}
|
||||
removalList.Clear();
|
||||
}
|
||||
|
||||
|
||||
public void ProcessDirectoryForDeletion(string targetDirectory)
|
||||
{
|
||||
// Process the list of files found in the directory.
|
||||
string[] fileEntries = Directory.GetFiles(targetDirectory);
|
||||
foreach (string fileName in fileEntries)
|
||||
{
|
||||
File.Delete(fileName);
|
||||
// File.Delete(fileName);
|
||||
}
|
||||
|
||||
// Recurse into subdirectories of this directory.
|
||||
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
|
||||
foreach (string subdirectory in subdirectoryEntries)
|
||||
ProcessDirectoryForDeletion(subdirectory);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void WriteToJsonFile<T>(string filePath, T objectToWrite, bool append = false) where T : new()
|
||||
{
|
||||
TextWriter writer = null;
|
||||
try
|
||||
{
|
||||
JsonSerializerSettings settings = new JsonSerializerSettings();
|
||||
//settings.TypeNameHandling = TypeNameHandling.Auto;
|
||||
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
settings.TypeNameHandling = TypeNameHandling.Auto;
|
||||
// settings.Formatting = Formatting.Indented;
|
||||
var contentsToWriteToFile = JsonConvert.SerializeObject(objectToWrite, settings);
|
||||
int i = 0;
|
||||
string s = filePath;
|
||||
while (File.Exists(s) == true)
|
||||
{
|
||||
s = filePath;
|
||||
s = (s + Convert.ToString(i));
|
||||
i++;
|
||||
}
|
||||
filePath = s;
|
||||
|
||||
writer = new StreamWriter(filePath, append);
|
||||
|
||||
writer.Write(contentsToWriteToFile);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (writer != null)
|
||||
writer.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void serializeXML<T>(Item I)
|
||||
{
|
||||
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
|
||||
var newWriter = new StringWriter();
|
||||
using (var writer = XmlWriter.Create(newWriter))
|
||||
{
|
||||
xmlSerializer.Serialize(writer,I);
|
||||
}
|
||||
}
|
||||
|
||||
public void processDirectoryForDeserialization(string pathToXML,List<Item> thingsToAddBackIn)
|
||||
{
|
||||
string[] fileEntries = Directory.GetFiles(pathToXML);
|
||||
foreach(var fileName in fileEntries)
|
||||
{
|
||||
ProcessFileForCleanUp(fileName,thingsToAddBackIn);
|
||||
}
|
||||
|
||||
string[] subDirectories = Directory.GetDirectories(pathToXML);
|
||||
foreach(var folder in subDirectories)
|
||||
{
|
||||
processDirectoryForDeserialization(folder,thingsToAddBackIn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void ProcessFileForCleanUp(string path, List<Item> thingsToAddBackIn)
|
||||
{
|
||||
string[] ehh = File.ReadAllLines(path);
|
||||
string data = ehh[0];
|
||||
Item cObj;
|
||||
string a;
|
||||
string[] b;
|
||||
string s = "";
|
||||
// Log.AsyncC(path);
|
||||
// Log.AsyncC(data);
|
||||
try
|
||||
{
|
||||
dynamic obj = JObject.Parse(data);
|
||||
|
||||
|
||||
// Log.AsyncC(obj.thisType);
|
||||
|
||||
a = obj.serializationName;
|
||||
b = a.Split(',');
|
||||
s = b.ElementAt(0);
|
||||
// Log.AsyncC(s);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
//USE XML STYLE DESERIALIZING
|
||||
foreach (KeyValuePair<string, SerializerDataNode> pair in acceptedTypes)
|
||||
{
|
||||
var word = ParseXMLType(path);
|
||||
if (pair.Key == word.ToString())
|
||||
{
|
||||
cObj = pair.Value.parse.Invoke(path);
|
||||
(cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName);
|
||||
(cObj as CoreObject).resetTexture();
|
||||
if ((cObj as CoreObject).thisLocation == null)
|
||||
{
|
||||
Game1.player.addItemToInventory(cObj);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
(cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).tileLocation, (StardewValley.Object)cObj);
|
||||
thingsToAddBackIn.Add(cObj);
|
||||
//Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log.AsyncG("attempting to parse from path and value of s is " + s);
|
||||
}
|
||||
|
||||
// var cObj = parseBagOfHolding(path); //pair.Value.parse.Invoke(path);
|
||||
// cObj.TextureSheet = Game1.content.Load<Texture2D>(Path.Combine("Revitalize", "CropsNSeeds", "Graphics", "seeds"));
|
||||
/*
|
||||
cObj.thisLocation = Game1.getLocationFromName(cObj.locationsName);
|
||||
if (cObj.thisLocation == null)
|
||||
{
|
||||
Game1.player.addItemToInventory(cObj);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
cObj.thisLocation.objects.Add(cObj.tileLocation, cObj);
|
||||
Lists.trackedObjectList.Add(cObj);
|
||||
//Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
|
||||
}
|
||||
*/
|
||||
|
||||
//USE JSON STYLE DESERIALIZNG
|
||||
if (acceptedTypes.ContainsKey(s))
|
||||
{
|
||||
// Log.AsyncC("FUUUUU");
|
||||
foreach (KeyValuePair<string, SerializerDataNode> pair in acceptedTypes)
|
||||
{
|
||||
if (pair.Key == s)
|
||||
{
|
||||
try
|
||||
{
|
||||
//parse from Json Style
|
||||
cObj = (CoreObject)pair.Value.parse.Invoke(data);
|
||||
(cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName);
|
||||
|
||||
if ((cObj as CoreObject).thisLocation == null)
|
||||
{
|
||||
Game1.player.addItemToInventory(cObj);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
(cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).tileLocation,(StardewValley.Object)cObj);
|
||||
thingsToAddBackIn.Add(cObj);
|
||||
//Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public string ParseXMLType(string path)
|
||||
{
|
||||
string[] s = File.ReadAllLines(path);
|
||||
string returnString = "";
|
||||
foreach (string v in s)
|
||||
{
|
||||
// Log.AsyncC(v);
|
||||
if (v.Contains("serializationName"))
|
||||
{
|
||||
returnString = v.Remove(0, 12);
|
||||
returnString = returnString.Remove(returnString.Length - 11, 11);
|
||||
}
|
||||
|
||||
}
|
||||
return returnString;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{E61753A9-057D-4495-B904-133269A802EA}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Serialization</RootNamespace>
|
||||
<AssemblyName>Serialization</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Class1.cs" />
|
||||
<Compile Include="CoreObject.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Serialization.cs" />
|
||||
<Compile Include="SerializerDataNode.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,27 @@
|
|||
using StardewValley;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serialization
|
||||
{
|
||||
public class SerializerDataNode
|
||||
{
|
||||
public delegate Item ParsingFunction(string data);
|
||||
public delegate void SerializingFunction(Item item);
|
||||
public delegate void WorldParsingFunction(Item obj);
|
||||
|
||||
public SerializingFunction serialize;
|
||||
public ParsingFunction parse;
|
||||
public WorldParsingFunction worldObj;
|
||||
|
||||
public SerializerDataNode(SerializingFunction serializeFunction, ParsingFunction parsingFunction, WorldParsingFunction worldObjectParsingFunction)
|
||||
{
|
||||
serialize = serializeFunction;
|
||||
parse = parsingFunction;
|
||||
worldObj = worldObjectParsingFunction;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using StardewModdingAPI;
|
||||
using StardewValley;
|
||||
using StardewValley.Locations;
|
||||
using StardewValley.Objects;
|
||||
using StardewValley.TerrainFeatures;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using xTile.Dimensions;
|
||||
|
||||
namespace Serialization
|
||||
{
|
||||
class Utilities
|
||||
{
|
||||
|
||||
public static Microsoft.Xna.Framework.Rectangle parseRectFromJson(string s)
|
||||
{
|
||||
|
||||
|
||||
|
||||
s = s.Replace('{', ' ');
|
||||
s = s.Replace('}', ' ');
|
||||
s = s.Replace('^', ' ');
|
||||
s = s.Replace(':', ' ');
|
||||
string[] parsed = s.Split(' ');
|
||||
foreach (var v in parsed)
|
||||
{
|
||||
//Log.AsyncY(v);
|
||||
}
|
||||
return new Microsoft.Xna.Framework.Rectangle(Convert.ToInt32(parsed[2]), Convert.ToInt32(parsed[4]), Convert.ToInt32(parsed[6]), Convert.ToInt32(parsed[8]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"Name": "Serialization",
|
||||
"Author": "Alpha_Omegasis",
|
||||
"Version": {
|
||||
"MajorVersion": 1,
|
||||
"MinorVersion": 0,
|
||||
"PatchVersion": 0,
|
||||
"Build": null
|
||||
},
|
||||
"MinimumApiVersion": "1.15",
|
||||
"Description": "A simple serializer that allows easily adding custom items into the game.",
|
||||
"UniqueID": "Omegasis.Serialization",
|
||||
"EntryDll": "Serialization.dll"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
|
||||
<package id="Pathoschild.Stardew.ModBuildConfig" version="1.7.1" targetFramework="net45" />
|
||||
</packages>
|
|
@ -49,6 +49,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleSoundManager", "Simpl
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdditionalCropsFramework", "AdditionalCropsFramework\AdditionalCropsFramework.csproj", "{C5F88D48-EA20-40CD-91E2-C8725DC11795}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StardustCore", "StardustCore\StardustCore.csproj", "{0756D36A-95C8-480D-8EA6-4584C03010C6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -131,6 +133,10 @@ Global
|
|||
{C5F88D48-EA20-40CD-91E2-C8725DC11795}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C5F88D48-EA20-40CD-91E2-C8725DC11795}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C5F88D48-EA20-40CD-91E2-C8725DC11795}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0756D36A-95C8-480D-8EA6-4584C03010C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0756D36A-95C8-480D-8EA6-4584C03010C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0756D36A-95C8-480D-8EA6-4584C03010C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0756D36A-95C8-480D-8EA6-4584C03010C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,14 @@
|
|||
using StardewModdingAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StardustCore
|
||||
{
|
||||
public class ModCore : Mod
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("StardustCore")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("StardustCore")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("0756d36a-95c8-480d-8ea6-4584c03010c6")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,417 @@
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using StardewModdingAPI;
|
||||
using StardewValley;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace StardustCore.Serialization
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// TODO: Find a way to serialize objects and tools.
|
||||
/// </summary>
|
||||
|
||||
|
||||
public class SerializationManager
|
||||
{
|
||||
public string objectsInWorldPath;
|
||||
public string playerInventoryPath;
|
||||
public string SerializerTrashPath;
|
||||
|
||||
public Dictionary<string, SerializerDataNode> acceptedTypes = new Dictionary<string, SerializerDataNode>();
|
||||
public List<CoreObject> trackedObjectList = new List<CoreObject>();
|
||||
|
||||
|
||||
|
||||
public SerializationManager(string PlayerInventoryPath,string SerializerTrashPath,string ObjectsInWorldPath)
|
||||
{
|
||||
this.objectsInWorldPath = ObjectsInWorldPath;
|
||||
this.playerInventoryPath = PlayerInventoryPath;
|
||||
this.SerializerTrashPath = SerializerTrashPath;
|
||||
|
||||
verifyAllDirectoriesExist();
|
||||
}
|
||||
|
||||
private void verifyAllDirectoriesExist()
|
||||
{
|
||||
if (!Directory.Exists(this.playerInventoryPath)) Directory.CreateDirectory(this.playerInventoryPath);
|
||||
if (!Directory.Exists(this.SerializerTrashPath)) Directory.CreateDirectory(this.SerializerTrashPath);
|
||||
if (!Directory.Exists(this.objectsInWorldPath)) Directory.CreateDirectory(this.objectsInWorldPath);
|
||||
}
|
||||
|
||||
public void cleanUpInventory()
|
||||
{
|
||||
ProcessDirectoryForDeletion(playerInventoryPath);
|
||||
|
||||
//ProcessDirectoryForDeletion(SerializerTrashPath);
|
||||
|
||||
List<Item> removalList = new List<Item>();
|
||||
foreach (Item d in Game1.player.items)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (d == null)
|
||||
{
|
||||
//Log.AsyncG("WTF");
|
||||
continue;
|
||||
}
|
||||
// Log.AsyncC(d.GetType());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
string s = Convert.ToString((d.GetType()));
|
||||
|
||||
|
||||
|
||||
|
||||
if (acceptedTypes.ContainsKey(s))
|
||||
{
|
||||
SerializerDataNode t;
|
||||
|
||||
bool works = acceptedTypes.TryGetValue(s, out t);
|
||||
if (works == true)
|
||||
{
|
||||
t.serialize.Invoke(d);
|
||||
removalList.Add(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var i in removalList)
|
||||
{
|
||||
Game1.player.removeItemFromInventory(i);
|
||||
}
|
||||
removalList.Clear();
|
||||
}
|
||||
|
||||
public void cleanUpWorld()
|
||||
{
|
||||
ProcessDirectoryForDeletion(objectsInWorldPath);
|
||||
List<CoreObject> removalList = new List<CoreObject>();
|
||||
int countProcessed = 0;
|
||||
List<Item> idk = new List<Item>();
|
||||
foreach (CoreObject d in trackedObjectList)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (d == null)
|
||||
{
|
||||
//Log.AsyncG("WTF");
|
||||
continue;
|
||||
}
|
||||
// Log.AsyncC(d.GetType());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
string s = Convert.ToString((d.GetType()));
|
||||
|
||||
if (acceptedTypes.ContainsKey(s))
|
||||
{
|
||||
SerializerDataNode t;
|
||||
|
||||
bool works = acceptedTypes.TryGetValue(s, out t);
|
||||
if (works == true)
|
||||
{
|
||||
countProcessed++;
|
||||
if (d.useXML == false)
|
||||
{
|
||||
t.worldObj.Invoke(d);
|
||||
}
|
||||
else
|
||||
{
|
||||
idk.Add(d);
|
||||
}
|
||||
// Log.AsyncC("Progress on saving objects: " + countProcessed + "/" + Lists.trackedObjectList.Count);
|
||||
removalList.Add(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var i in removalList)
|
||||
{
|
||||
i.thisLocation.removeObject(i.tileLocation, false);
|
||||
}
|
||||
foreach (var v in idk)
|
||||
{
|
||||
string s = Convert.ToString((v.GetType()));
|
||||
|
||||
if (acceptedTypes.ContainsKey(s))
|
||||
{
|
||||
SerializerDataNode t;
|
||||
|
||||
bool works = acceptedTypes.TryGetValue(s, out t);
|
||||
if (works == true)
|
||||
{
|
||||
countProcessed++;
|
||||
if ((v as CoreObject).useXML == true)
|
||||
{
|
||||
t.worldObj.Invoke(v as CoreObject);
|
||||
}
|
||||
//Log.AsyncG("Progress on saving objects: " + countProcessed + "/" + Lists.trackedObjectList.Count);
|
||||
removalList.Add(v as CoreObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
removalList.Clear();
|
||||
// Log.AsyncM("Revitalize: Done cleaning world for saving.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void restoreAllModObjects(List<CoreObject> thingsToAddBackIn)
|
||||
{
|
||||
processDirectoryForDeserialization(this.playerInventoryPath,thingsToAddBackIn);
|
||||
Log.AsyncG("DESERIALIZE???");
|
||||
try
|
||||
{
|
||||
trackedObjectList.Clear(); //clear whatever mod objects I'm tracking
|
||||
processDirectoryForDeserialization(objectsInWorldPath,thingsToAddBackIn); //restore whatever I'm tracking here when I replace the object back into the world. This also works when loading up the game, not just when saving/loading
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ProcessDirectoryForDeletion(string targetDirectory)
|
||||
{
|
||||
// Process the list of files found in the directory.
|
||||
string[] fileEntries = Directory.GetFiles(targetDirectory);
|
||||
foreach (string fileName in fileEntries)
|
||||
{
|
||||
File.Delete(fileName);
|
||||
// File.Delete(fileName);
|
||||
}
|
||||
|
||||
// Recurse into subdirectories of this directory.
|
||||
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
|
||||
foreach (string subdirectory in subdirectoryEntries)
|
||||
ProcessDirectoryForDeletion(subdirectory);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void WriteToJsonFile<T>(string filePath, T objectToWrite, bool append = false) where T : new()
|
||||
{
|
||||
TextWriter writer = null;
|
||||
try
|
||||
{
|
||||
JsonSerializerSettings settings = new JsonSerializerSettings();
|
||||
//settings.TypeNameHandling = TypeNameHandling.Auto;
|
||||
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
settings.TypeNameHandling = TypeNameHandling.Auto;
|
||||
// settings.Formatting = Formatting.Indented;
|
||||
var contentsToWriteToFile = JsonConvert.SerializeObject(objectToWrite, settings);
|
||||
int i = 0;
|
||||
string s = filePath;
|
||||
while (File.Exists(s) == true)
|
||||
{
|
||||
s = filePath;
|
||||
s = (s + Convert.ToString(i));
|
||||
i++;
|
||||
}
|
||||
filePath = s;
|
||||
|
||||
writer = new StreamWriter(filePath, append);
|
||||
|
||||
writer.Write(contentsToWriteToFile);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (writer != null)
|
||||
writer.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void serializeXML<T>(Item I)
|
||||
{
|
||||
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
|
||||
var newWriter = new StringWriter();
|
||||
using (var writer = XmlWriter.Create(newWriter))
|
||||
{
|
||||
xmlSerializer.Serialize(writer,I);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pathToFile"></param>
|
||||
/// <param name="thingsToAddBackIn">Typically this would be the trackedObjectList.</param>
|
||||
public void processDirectoryForDeserialization(string pathToFile,List<CoreObject> thingsToAddBackIn)
|
||||
{
|
||||
string[] fileEntries = Directory.GetFiles(pathToFile);
|
||||
foreach(var fileName in fileEntries)
|
||||
{
|
||||
ProcessFileForCleanUp(fileName,thingsToAddBackIn);
|
||||
}
|
||||
|
||||
string[] subDirectories = Directory.GetDirectories(pathToFile);
|
||||
foreach(var folder in subDirectories)
|
||||
{
|
||||
processDirectoryForDeserialization(folder,thingsToAddBackIn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void ProcessFileForCleanUp(string path, List<CoreObject> thingsToAddBackIn)
|
||||
{
|
||||
|
||||
Log.AsyncC(path);
|
||||
|
||||
string[] ehh = File.ReadAllLines(path);
|
||||
string data = ehh[0];
|
||||
CoreObject cObj;
|
||||
string a;
|
||||
string[] b;
|
||||
string s = "";
|
||||
// Log.AsyncC(path);
|
||||
// Log.AsyncC(data);
|
||||
try
|
||||
{
|
||||
dynamic obj = JObject.Parse(data);
|
||||
|
||||
|
||||
// Log.AsyncC(obj.thisType);
|
||||
|
||||
a = obj.serializationName;
|
||||
b = a.Split(',');
|
||||
s = b.ElementAt(0);
|
||||
Log.AsyncC(s);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
//USE XML STYLE DESERIALIZING
|
||||
foreach (KeyValuePair<string, SerializerDataNode> pair in acceptedTypes)
|
||||
{
|
||||
var word = ParseXMLType(path);
|
||||
if (pair.Key == word.ToString())
|
||||
{
|
||||
cObj =(CoreObject) pair.Value.parse.Invoke(path);
|
||||
(cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName);
|
||||
(cObj as CoreObject).resetTexture();
|
||||
if ((cObj as CoreObject).thisLocation == null)
|
||||
{
|
||||
Game1.player.addItemToInventory(cObj);
|
||||
Log.AsyncY("ADDED ITEM TO INVENTORY");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
(cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).tileLocation, (StardewValley.Object)cObj);
|
||||
thingsToAddBackIn.Add(cObj);
|
||||
//Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log.AsyncG("attempting to parse from path and value of s is " + s);
|
||||
}
|
||||
|
||||
// var cObj = parseBagOfHolding(path); //pair.Value.parse.Invoke(path);
|
||||
// cObj.TextureSheet = Game1.content.Load<Texture2D>(Path.Combine("Revitalize", "CropsNSeeds", "Graphics", "seeds"));
|
||||
/*
|
||||
cObj.thisLocation = Game1.getLocationFromName(cObj.locationsName);
|
||||
if (cObj.thisLocation == null)
|
||||
{
|
||||
Game1.player.addItemToInventory(cObj);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
cObj.thisLocation.objects.Add(cObj.tileLocation, cObj);
|
||||
Lists.trackedObjectList.Add(cObj);
|
||||
//Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
|
||||
}
|
||||
*/
|
||||
|
||||
//USE JSON STYLE DESERIALIZNG
|
||||
if (acceptedTypes.ContainsKey(s))
|
||||
{
|
||||
Log.AsyncC("FUUUUU");
|
||||
foreach (KeyValuePair<string, SerializerDataNode> pair in acceptedTypes)
|
||||
{
|
||||
Log.AsyncY(pair.Key);
|
||||
if (pair.Key == s)
|
||||
{
|
||||
try
|
||||
{
|
||||
//parse from Json Style
|
||||
Log.AsyncR("1");
|
||||
cObj = (CoreObject)pair.Value.parse.Invoke(data);
|
||||
(cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName);
|
||||
|
||||
if ((cObj as CoreObject).thisLocation == null)
|
||||
{
|
||||
Game1.player.addItemToInventory(cObj);
|
||||
Log.AsyncY("ADDED ITEM TO INVENTORY");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
(cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).tileLocation,(StardewValley.Object)cObj);
|
||||
thingsToAddBackIn.Add(cObj);
|
||||
//Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.AsyncO(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.AsyncM("Error parsing unknown object type: " + s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public string ParseXMLType(string path)
|
||||
{
|
||||
string[] s = File.ReadAllLines(path);
|
||||
string returnString = "";
|
||||
foreach (string v in s)
|
||||
{
|
||||
// Log.AsyncC(v);
|
||||
if (v.Contains("serializationName"))
|
||||
{
|
||||
returnString = v.Remove(0, 12);
|
||||
returnString = returnString.Remove(returnString.Length - 11, 11);
|
||||
}
|
||||
|
||||
}
|
||||
return returnString;
|
||||
}
|
||||
|
||||
public static Microsoft.Xna.Framework.Rectangle parseRectFromJson(string s)
|
||||
{
|
||||
s = s.Replace('{', ' ');
|
||||
s = s.Replace('}', ' ');
|
||||
s = s.Replace('^', ' ');
|
||||
s = s.Replace(':', ' ');
|
||||
string[] parsed = s.Split(' ');
|
||||
foreach (var v in parsed)
|
||||
{
|
||||
//Log.AsyncY(v);
|
||||
}
|
||||
return new Microsoft.Xna.Framework.Rectangle(Convert.ToInt32(parsed[2]), Convert.ToInt32(parsed[4]), Convert.ToInt32(parsed[6]), Convert.ToInt32(parsed[8]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
using StardewValley;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StardustCore.Serialization
|
||||
{
|
||||
public class SerializerDataNode
|
||||
{
|
||||
public delegate Item ParsingFunction(string data);
|
||||
public delegate void SerializingFunction(Item item);
|
||||
public delegate void WorldParsingFunction(Item obj);
|
||||
|
||||
public SerializingFunction serialize;
|
||||
public ParsingFunction parse;
|
||||
public WorldParsingFunction worldObj;
|
||||
|
||||
public SerializerDataNode(SerializingFunction serializeFunction, ParsingFunction parsingFunction, WorldParsingFunction worldObjectParsingFunction)
|
||||
{
|
||||
serialize = serializeFunction;
|
||||
parse = parsingFunction;
|
||||
worldObj = worldObjectParsingFunction;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{0756D36A-95C8-480D-8EA6-4584C03010C6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>StardustCore</RootNamespace>
|
||||
<AssemblyName>StardustCore</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ModCore.cs" />
|
||||
<Compile Include="CoreObject.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Serialization\Serialization.cs" />
|
||||
<Compile Include="Serialization\SerializerDataNode.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\deploy.targets" />
|
||||
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Pathoschild.Stardew.ModBuildConfig.1.7.1\build\Pathoschild.Stardew.ModBuildConfig.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"Name": "StardustCore",
|
||||
"Author": "Alpha_Omegasis",
|
||||
"Version": {
|
||||
"MajorVersion": 2,
|
||||
"MinorVersion": 0,
|
||||
"PatchVersion": 0,
|
||||
"Build": null
|
||||
},
|
||||
"MinimumApiVersion": "1.15",
|
||||
"Description": "A core mod that allows for other mods to be run.",
|
||||
"UniqueID": "Omegasis.StardustCore",
|
||||
"EntryDll": "StardustCore.dll"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
|
||||
<package id="Pathoschild.Stardew.ModBuildConfig" version="1.7.1" targetFramework="net45" />
|
||||
</packages>
|
|
@ -0,0 +1 @@
|
|||
Transfer these mods over to the general mod folder.
|
Loading…
Reference in New Issue