Changed serialization manager, all objects serialize in world and inventory. Next is chests.

This commit is contained in:
2017-09-13 13:53:12 -07:00
parent b3193b52fc
commit cf33b0228e
10 changed files with 464 additions and 128 deletions

View File

@ -664,7 +664,7 @@ namespace AdditionalCropsFramework
else
{
// Game1.showRedMessage("STEP 2");
Log.Info(vector);
// Log.Info(vector);
Vector2 newVec = new Vector2(vector.X, vector.Y);
// cObj.boundingBox.Inflate(32, 32);
@ -675,11 +675,11 @@ namespace AdditionalCropsFramework
if (playSound == true) Game1.playSound("woodyStep");
else
{
Log.AsyncG("restoring item from file");
// Log.AsyncG("restoring item from file");
}
//Log.AsyncM("Placed and object");
cObj.locationsName = location.name;
ModCore.serilaizationManager.trackedObjectList.Add(cObj);
StardustCore.ModCore.SerializationManager.trackedObjectList.Add(cObj);
return true;
}
@ -692,7 +692,7 @@ namespace AdditionalCropsFramework
if (Game1.player.isInventoryFull() == false)
{
Game1.player.addItemToInventoryBool(I, false);
ModCore.serilaizationManager.trackedObjectList.Remove(I);
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(I);
return true;
}
else
@ -753,9 +753,9 @@ namespace AdditionalCropsFramework
if (state == 1)
{
c.dayOfCurrentPhase++;
Log.AsyncG("DaY OF CURRRENT PHASE BISCUITS!"+c.dayOfCurrentPhase);
// Log.AsyncG("DaY OF CURRRENT PHASE BISCUITS!"+c.dayOfCurrentPhase);
Log.AsyncC(c.currentPhase);
// Log.AsyncC(c.currentPhase);
if (c.dayOfCurrentPhase >= c.phaseDays[c.currentPhase])
{
c.currentPhase++;
@ -769,10 +769,6 @@ namespace AdditionalCropsFramework
c.dayOfCurrentPhase = 0;
}
foreach(var v in c.phaseDays)
{
Log.AsyncR("PHASE DAY"+v);
}
while (c.currentPhase < c.phaseDays.Count - 1 && c.phaseDays.Count > 0 && c.phaseDays[c.currentPhase] <= 0)
c.currentPhase = c.currentPhase + 1;
if (c.rowInSpriteSheet == 23 && c.phaseToShow == -1 && c.currentPhase > 0)
@ -850,7 +846,9 @@ namespace AdditionalCropsFramework
if (state == 1)
{
c.dayOfCurrentPhase++;
Log.AsyncG(c.dayOfCurrentPhase);
//c.dayOfCurrentPhase = c.fullyGrown ? c.dayOfCurrentPhase - 1 : Math.Min(c.dayOfCurrentPhase + 1, c.phaseDays.Count > 0 ? c.phaseDays[Math.Min(c.phaseDays.Count - 1, c.currentPhase)] : 0);
if (c.dayOfCurrentPhase >= (c.phaseDays.Count > 0 ? c.phaseDays[Math.Min(c.phaseDays.Count - 1, c.currentPhase)] : 0) && c.currentPhase < c.phaseDays.Count - 1)
{
@ -858,10 +856,6 @@ namespace AdditionalCropsFramework
c.dayOfCurrentPhase = 0;
}
foreach (var v in c.phaseDays)
{
Log.AsyncR(v);
}
@ -1123,7 +1117,6 @@ namespace AdditionalCropsFramework
public static bool harvestModularCrop(ModularCrop c, int xTile, int yTile, int fertilizer, JunimoHarvester junimoHarvester = null)
{
Item I = (Item)new ModularCropObject(c.indexOfHarvest, 1, c.cropObjectTexture, c.cropObjectData);
int howMuch = 3;
if (Game1.player.addItemToInventoryBool(I, false))
{
@ -1242,7 +1235,7 @@ namespace AdditionalCropsFramework
ModularCropObject @object;
if (!c.programColored)
{
Log.AsyncG(c.indexOfHarvest);
// Log.AsyncG(c.indexOfHarvest);
try
{
@object = new ModularCropObject(c.indexOfHarvest, 1, c.cropObjectTexture, c.cropObjectData);
@ -1250,7 +1243,7 @@ namespace AdditionalCropsFramework
catch(Exception lol)
{
@object = new ModularCropObject();
Log.AsyncO(lol);
// Log.AsyncO(lol);
}
}
else

View File

@ -39,7 +39,6 @@ namespace AdditionalCropsFramework
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;
private List<Item> shippingList;
@ -49,13 +48,17 @@ namespace AdditionalCropsFramework
ModHelper = helper;
ModMonitor = this.Monitor;
StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave;
if (!Directory.Exists(Path.Combine(ModCore.ModHelper.DirectoryPath, Utilities.EntensionsFolderName)))
{
Directory.CreateDirectory(Path.Combine(ModCore.ModHelper.DirectoryPath, Utilities.EntensionsFolderName));
}
StardustCore.ModCore.SerializationManager.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.
StardustCore.ModCore.SerializationManager.acceptedTypes.Add("AdditionalCropsFramework.ModularCropObject", new SerializerDataNode(new SerializerDataNode.SerializingFunction(ModularCropObject.Serialize), new SerializerDataNode.ParsingFunction(ModularCropObject.ParseIntoInventory), new SerializerDataNode.WorldParsingFunction(ModularCropObject.SerializeFromWorld)));
StardustCore.ModCore.SerializationManager.acceptedTypes.Add("AdditionalCropsFramework.ModularSeeds", new SerializerDataNode(new SerializerDataNode.SerializingFunction(ModularSeeds.Serialize), new SerializerDataNode.ParsingFunction(ModularSeeds.ParseIntoInventory), new SerializerDataNode.WorldParsingFunction(ModularSeeds.SerializeFromWorld)));
// StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick;
this.shippingList = new List<Item>();
}
@ -91,7 +94,7 @@ namespace AdditionalCropsFramework
public void dailyUpdates()
{
foreach (var v in serilaizationManager.trackedObjectList)
foreach (var v in StardustCore.ModCore.SerializationManager.trackedObjectList)
{
if (v is PlanterBox)
{
@ -102,32 +105,15 @@ namespace AdditionalCropsFramework
private void SaveEvents_AfterSave(object sender, EventArgs e)
{
serilaizationManager.restoreAllModObjects(serilaizationManager.trackedObjectList);
dailyUpdates();
}
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);
dailyUpdates();
}
}
}

View File

@ -1,12 +1,14 @@

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 StardustCore.Animations;
using System;
using System.Collections.Generic;
using System.IO;
@ -41,7 +43,7 @@ namespace AdditionalCropsFramework
[XmlIgnore]
public Texture2D TextureSheet;
public string dataFileName;
public new bool flipped;
@ -50,7 +52,7 @@ namespace AdditionalCropsFramework
public bool lightGlowAdded;
public string texturePath;
public bool itemReadyForHarvest;
@ -66,6 +68,9 @@ namespace AdditionalCropsFramework
public string cropType;
public string dataFileName;
public string texturePath;
public override string Name
{
get
@ -87,8 +92,8 @@ namespace AdditionalCropsFramework
public ModularCropObject(int which, int initalStack, string ObjectTextureSheetName, string DataFileName)
{
if (File.Exists(ObjectTextureSheetName)) Log.AsyncC("YAY");
this.serializationName = this.GetType().ToString();
// if (File.Exists(ObjectTextureSheetName)) Log.AsyncC("YAY");
this.tileLocation = Vector2.Zero;
this.stack = initalStack;
@ -98,13 +103,26 @@ namespace AdditionalCropsFramework
}
catch(Exception err)
{
Log.AsyncM(err);
// Log.AsyncM(err);
}
texturePath = ObjectTextureSheetName;
this.dataFileName = DataFileName;
this.canBeSetDown = false;
// Log.AsyncG(Path.Combine(Utilities.EntensionsFolderName,DataFileName));
// Log.AsyncC(which);
Dictionary<int, string> dictionary = new Dictionary<int, string>();
try
{
dictionary = ModCore.ModHelper.Content.Load<Dictionary<int, string>>(Path.Combine(Utilities.EntensionsFolderName, DataFileName));
}
catch(Exception err)
{
// Log.AsyncC(err);
}
Dictionary<int, string> dictionary = ModCore.ModHelper.Content.Load<Dictionary<int, string>>(Path.Combine(Utilities.EntensionsFolderName, DataFileName));
string[] array = dictionary[which].Split(new char[]
{
'/'
@ -139,13 +157,24 @@ namespace AdditionalCropsFramework
this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 16, 16);
this.sourceRect = this.defaultSourceRect;
Log.AsyncC(this.sourceRect);
this.defaultBoundingBox = new Rectangle(0, 0, 16, 16);
this.boundingBox = this.defaultBoundingBox;
this.updateDrawPosition();
this.parentSheetIndex = which;
try
{
this.animationManager = new StardustCore.Animations.AnimationManager(this.TextureSheet, new StardustCore.Animations.Animation(this.defaultSourceRect, -1), AnimationManager.parseAnimationsFromXNB(array[3]), "default");
this.animationManager.setAnimation("Default", 0);
//Log.AsyncC("Using animation manager");
}
catch (Exception errr)
{
this.animationManager = new StardustCore.Animations.AnimationManager(this.TextureSheet, new StardustCore.Animations.Animation(this.defaultSourceRect, -1));
}
}
public override string getDescription()
@ -1254,6 +1283,130 @@ namespace AdditionalCropsFramework
}
public static new void Serialize(Item I)
{
StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.playerInventoryPath, I.Name + ".json"), (ModularCropObject)I);
}
public static Item ParseIntoInventory(string s)
{
// PlanterBox p = new PlanterBox();
// return p;
dynamic obj = JObject.Parse(s);
ModularCropObject d = new ModularCropObject();
d.dataFileName= obj.dataFileName;
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;
d.TextureSheet = ModCore.ModHelper.Content.Load<Texture2D>(Path.Combine(Utilities.EntensionsFolderName, t));
d.texturePath = t;
d.itemReadyForHarvest = obj.itemReadyForHarvest;
d.lightsOn = obj.lightsOn;
d.lightColor = obj.lightColor;
d.thisType = obj.thisType;
d.removable = obj.removable;
d.locationsName = obj.locationsName;
d.cropType = obj.cropType;
d.drawColor = obj.drawColor;
d.serializationName = obj.serializationName;
//ANIMATIONS
var q = obj.animationManager;
dynamic obj1 = q;
ModularCropObject dummy = new ModularCropObject(d.parentSheetIndex, d.stack, d.texturePath, d.dataFileName);
d.animationManager = dummy.animationManager;
try
{
string name = Convert.ToString(obj1.currentAnimationName);
int frame = Convert.ToInt32(obj1.currentAnimationListIndex);
bool f = d.animationManager.setAnimation(name, frame);
bool f2;
if (f == false)
{
f2 = d.animationManager.setAnimation(name, 0);
if (f2 == false) d.animationManager.currentAnimation = d.animationManager.defaultDrawFrame;
}
}
catch(Exception err)
{
}
try
{
return d;
}
catch (Exception e)
{
// Log.AsyncM(e);
return null;
}
//return base.ParseIntoInventory();
}
public static void SerializeFromWorld(Item I)
{
// ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, (c as CoreObject).thisLocation.name, c.Name + ".json"), (PlanterBox)c);
StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.objectsInWorldPath, I.Name + ".json"), (ModularCropObject)I);
}

View File

@ -9,6 +9,7 @@ using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.IO;
using Newtonsoft.Json.Linq;
namespace AdditionalCropsFramework
{
@ -52,6 +53,7 @@ namespace AdditionalCropsFramework
TextureSheet = ModCore.ModHelper.Content.Load<Texture2D>(Path.Combine(Utilities.EntensionsFolderName, ObjectSpriteSheet)); //Game1.content.Load<Texture2D>("Revitalize\\CropsNSeeds\\Graphics\\seeds");
texturePath = ObjectSpriteSheet;
}
this.serializationName = this.GetType().ToString();
Dictionary<int, string> dictionary = ModCore.ModHelper.Content.Load<Dictionary<int, string>>(Path.Combine(Utilities.EntensionsFolderName, ObjectDataFile));//Game1.content.Load<Dictionary<int, string>>("Revitalize\\CropsNSeeds\\Data\\seeds");
dataFilePath = ObjectDataFile;
cropDataFilePath = AssociatedCropDataFile;
@ -60,9 +62,6 @@ namespace AdditionalCropsFramework
cropObjectDataFilePath = AssociatedCropObjectDataFile;
cropObjectTextureFilePath = AssociatedCropObjectTexture;
Log.AsyncC(cropDataFilePath);
Log.AsyncG(cropTextureFilePath);
//Log.AsyncC(which);
string[] array = dictionary[which].Split(new char[]
@ -395,10 +394,6 @@ namespace AdditionalCropsFramework
return this.stack;
}
public override int addToStack(int amount)
{
return 1;
}
private float getScaleSize()
{
@ -446,6 +441,15 @@ namespace AdditionalCropsFramework
{
//spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(this.defaultSourceRect), Color.White * transparency, 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * this.getScaleSize() * scaleSize, SpriteEffects.None, layerDepth);
spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(this.defaultSourceRect), Color.White * transparency, 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * this.getScaleSize() * scaleSize * 1.5f, SpriteEffects.None, layerDepth);
if (drawStackNumber && this.maximumStackSize() > 1 && ((double)scaleSize > 0.3 && this.Stack != int.MaxValue) && this.Stack > 1)
Utility.drawTinyDigits(this.stack, spriteBatch, location + new Vector2((float)(Game1.tileSize - Utility.getWidthOfTinyDigitString(this.stack, 3f * scaleSize)) + 3f * scaleSize, (float)((double)Game1.tileSize - 18.0 * (double)scaleSize + 2.0)), 3f * scaleSize, 1f, Color.White);
if (drawStackNumber && this.quality > 0)
{
float num = this.quality < 4 ? 0.0f : (float)((Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1.0) * 0.0500000007450581);
spriteBatch.Draw(Game1.mouseCursors, location + new Vector2(12f, (float)(Game1.tileSize - 12) + num), new Microsoft.Xna.Framework.Rectangle?(this.quality < 4 ? new Microsoft.Xna.Framework.Rectangle(338 + (this.quality - 1) * 8, 400, 8, 8) : new Microsoft.Xna.Framework.Rectangle(346, 392, 8, 8)), Color.White * transparency, 0.0f, new Vector2(4f, 4f), (float)(3.0 * (double)scaleSize * (1.0 + (double)num)), SpriteEffects.None, layerDepth);
}
}
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
@ -503,13 +507,13 @@ namespace AdditionalCropsFramework
public override int maximumStackSize()
{
return base.maximumStackSize();
return 999;
}
public ModularCrop parseCropInfo(int seedIndex)
{
ModularCrop c = new ModularCrop();
Log.AsyncC(this.cropDataFilePath);
// Log.AsyncC(this.cropDataFilePath);
Dictionary<int, string> dictionary = ModCore.ModHelper.Content.Load<Dictionary<int, string>>(Path.Combine(Utilities.EntensionsFolderName, this.cropDataFilePath)); //Game1.content.Load<Dictionary<int, string>>("Data\\Crops");
if (dictionary.ContainsKey(seedIndex))
@ -576,5 +580,143 @@ namespace AdditionalCropsFramework
return c;
}
public static new void Serialize(Item I)
{
StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.playerInventoryPath, I.Name + ".json"), (ModularSeeds)I);
}
public static Item ParseIntoInventory(string s)
{
// PlanterBox p = new PlanterBox();
// return p;
dynamic obj = JObject.Parse(s);
ModularSeeds d = new ModularSeeds();
d.dataFilePath = obj.dataFilePath;
d.cropDataFilePath = obj.cropDataFilePath;
d.cropObjectDataFilePath = obj.cropObjectDataFilePath;
d.texturePath = obj.texturePath;
d.cropTextureFilePath = obj.cropTextureFilePath;
d.cropObjectTextureFilePath = obj.cropObjectTextureFilePath;
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;
d.TextureSheet = ModCore.ModHelper.Content.Load<Texture2D>(Path.Combine(Utilities.EntensionsFolderName, t));
d.texturePath = t;
d.itemReadyForHarvest = obj.itemReadyForHarvest;
d.lightsOn = obj.lightsOn;
d.lightColor = obj.lightColor;
d.thisType = obj.thisType;
d.removable = obj.removable;
d.locationsName = obj.locationsName;
d.drawColor = obj.drawColor;
d.serializationName = obj.serializationName;
/*
//ANIMATIONS
var q = obj.animationManager;
dynamic obj1 = q;
string name = Convert.ToString(obj1.currentAnimationName);
int frame = Convert.ToInt32(obj1.currentAnimationListIndex);
PlanterBox dummy = new PlanterBox(d.parentSheetIndex, d.tileLocation, d.texturePath, d.dataPath, d.removable, d.IsSolid);
d.animationManager = dummy.animationManager;
bool f = d.animationManager.setAnimation(name, frame);
bool f2;
if (f == false)
{
f2 = d.animationManager.setAnimation(name, 0);
if (f2 == false) d.animationManager.currentAnimation = d.animationManager.defaultDrawFrame;
}
// Log.AsyncC(d.cropInformationString);
*/
//ModularCrop f= j.ToObject<ModularCrop>();
//ModularCrop f = obj.modularCrop;
// Log.AsyncG("THIS IS CROP: " + c.indexOfHarvest);
//Log.AsyncG(cropString);
// d.crop = obj.crop;
// d.modularCrop = obj.modularCrop;
try
{
return d;
}
catch (Exception e)
{
// Log.AsyncM(e);
return null;
}
//return base.ParseIntoInventory();
}
public static void SerializeFromWorld(Item I)
{
// ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, (c as CoreObject).thisLocation.name, c.Name + ".json"), (PlanterBox)c);
StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.objectsInWorldPath, I.Name + ".json"), (ModularSeeds)I);
}
}
}

View File

@ -22,9 +22,6 @@ namespace AdditionalCropsFramework
public class PlanterBox : CoreObject
{
public new int price;
public int Decoration_type;
public int rotations;
@ -65,7 +62,6 @@ namespace AdditionalCropsFramework
public string normalCropSeedName;
public int normalCropSeedIndex;
public string serializationName="AdditionalCropsFramework.PlanterBox";
public override string Name
{
@ -226,8 +222,8 @@ namespace AdditionalCropsFramework
this.defaultSourceRect = this.sourceRect;
try
{
this.animationManager = new StardustCore.Animations.AnimationManager(this.TextureSheet, new StardustCore.Animations.Animation(this.defaultSourceRect, -1), AnimationManager.parseAnimationsFromXNB(array[3]), "default");
this.animationManager.setAnimation("default", 0);
this.animationManager = new StardustCore.Animations.AnimationManager(this.TextureSheet, new StardustCore.Animations.Animation(this.defaultSourceRect, -1), AnimationManager.parseAnimationsFromXNB(array[3]), "Default");
this.animationManager.setAnimation("Default", 0);
//Log.AsyncC("Using animation manager");
}
catch (Exception errr)
@ -315,21 +311,21 @@ namespace AdditionalCropsFramework
}
if (this.modularCrop != null)
{
Log.AsyncM("HELLO MOD CROP");
// Log.AsyncM("HELLO MOD CROP");
if (this.modularCrop.isFullyGrown() == true)
{
Log.AsyncM("FULL BLOW");
// Log.AsyncM("FULL BLOW");
bool f = Utilities.harvestModularCrop(this.modularCrop, (int)this.tileLocation.X, (int)this.tileLocation.Y, 0);
if (f == true)
{
//this.modularCrop = null;
if (f == true && this.modularCrop.regrowAfterHarvest == -1) this.modularCrop = null;
Log.AsyncO("HARVEST");
// Log.AsyncO("HARVEST");
return false;
}
else
{
Log.AsyncC("failed to harvest crop. =/");
// Log.AsyncC("failed to harvest crop. =/");
}
}
}
@ -359,7 +355,7 @@ namespace AdditionalCropsFramework
{
if (this.modularCrop != null) return;
this.modularCrop = new ModularCrop(seeds.parentSheetIndex, (int)Game1.currentCursorTile.X, (int)Game1.currentCursorTile.Y, seeds.cropDataFilePath, seeds.cropTextureFilePath, seeds.cropObjectTextureFilePath, seeds.cropObjectDataFilePath);
// Game1.player.reduceActiveItemByOne();
Game1.player.reduceActiveItemByOne();
Game1.playSound("dirtyHit");
}
@ -375,12 +371,12 @@ namespace AdditionalCropsFramework
}
catch(Exception e)
{
Log.AsyncM(e);
// Log.AsyncM(e);
}
foreach (var v in this.crop.phaseDays)
{
Log.AsyncC("I grow! " + v);
// Log.AsyncC("I grow! " + v);
}
Game1.player.reduceActiveItemByOne();
Game1.playSound("dirtyHit");
@ -395,7 +391,7 @@ namespace AdditionalCropsFramework
if (Game1.player.getToolFromName(Game1.player.CurrentItem.Name) is StardewValley.Tools.WateringCan)
{
this.isWatered = true;
this.animationManager.setAnimation("watered", 0);
this.animationManager.setAnimation("Watered", 0);
return false;
}
}
@ -478,7 +474,7 @@ namespace AdditionalCropsFramework
public void dayUpdate()
{
Log.AsyncC("HELLO?!?!?");
if (this.isWatered==true)
{
if (this.crop != null)
@ -491,14 +487,14 @@ namespace AdditionalCropsFramework
{
Utilities.cropNewDayModded(this.modularCrop,1, 0, (int)this.tileLocation.X, (int)this.tileLocation.Y, this.thisLocation);
}
Log.AsyncC("DRINK YOUR WATER");
this.isWatered = false;
this.animationManager.setAnimation("default", 0);
this.animationManager.setAnimation("Default", 0);
}
else
{
Log.AsyncC("No Water Here");
this.animationManager.setAnimation("default", 0);
this.animationManager.setAnimation("Default", 0);
}
}
@ -900,7 +896,7 @@ namespace AdditionalCropsFramework
public static new void Serialize(Item I)
{
makeCropInformationString(I);
ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.playerInventoryPath, I.Name + ".json"), (PlanterBox)I);
StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.playerInventoryPath, I.Name + ".json"), (PlanterBox)I);
}
public static Item ParseIntoInventory(string s)
@ -981,11 +977,11 @@ namespace AdditionalCropsFramework
d.drawColor = obj.drawColor;
d.normalCropSeedIndex = obj.normalCropSeedIndex;
d.cropInformationString = obj.cropInformationString;
d.serializationName = obj.serializationName;
d.IsSolid = obj.IsSolid;
string IsWatered = obj.isWatered;
Log.AsyncC("AM I WATERED OR NOT?!?!?: "+IsWatered);
// Log.AsyncC("AM I WATERED OR NOT?!?!?: "+IsWatered);
d.isWatered = Convert.ToBoolean(IsWatered);
//ANIMATIONS
var q = obj.animationManager;
@ -1027,10 +1023,10 @@ namespace AdditionalCropsFramework
}
d.modularCrop = c;
Log.AsyncM("PARSED MODULAR CROP!");
Log.AsyncG(cropInfo[8]);
Log.AsyncG(cropInfo[9]);
Log.AsyncG(cropInfo[10]);
// Log.AsyncM("PARSED MODULAR CROP!");
// Log.AsyncG(cropInfo[8]);
// Log.AsyncG(cropInfo[9]);
// Log.AsyncG(cropInfo[10]);
}
if (cropInfo[0] == "false") //non-modular crop
{
@ -1051,7 +1047,7 @@ namespace AdditionalCropsFramework
}
else
{
Log.AsyncR("AOSIDHA(IUDGUDIUBGDLIUGDOIHDO:IHDOIHDIOHDIOP");
}
c.currentPhase = Convert.ToInt32(cropInfo[4]);
@ -1065,17 +1061,12 @@ namespace AdditionalCropsFramework
{
}
Log.AsyncM("PARSED Regular CROP!");
Log.AsyncG(cropInfo[1]);
Log.AsyncG(cropInfo[2]);
Log.AsyncG(cropInfo[3]);
Log.AsyncR(c.phaseDays.Count);
Log.AsyncM("PARSED REGULAR CROP! FINISH");
foreach(var v in c.phaseDays)
{
Log.AsyncG("THIS IS THE FINAL COUNT DOWN " + v);
}
// Log.AsyncM("PARSED Regular CROP!");
// Log.AsyncG(cropInfo[1]);
// Log.AsyncG(cropInfo[2]);
// Log.AsyncG(cropInfo[3]);
// Log.AsyncR(c.phaseDays.Count);
// Log.AsyncM("PARSED REGULAR CROP! FINISH");
d.crop = c;
}
@ -1112,7 +1103,7 @@ namespace AdditionalCropsFramework
{
makeCropInformationString(I);
// ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, (c as CoreObject).thisLocation.name, c.Name + ".json"), (PlanterBox)c);
ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, I.Name + ".json"), (PlanterBox)I);
StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.objectsInWorldPath, I.Name + ".json"), (PlanterBox)I);
}
public static void makeCropInformationString(Item I)

View File

@ -26,7 +26,9 @@ namespace RuneFactoryCropsMod
{
List<Item> shopInventory = new List<Item>();
string ModdedCropsFolderName = "RuneFactoryCropsMod";
shopInventory.Add((Item)new ModularSeeds(1, Path.Combine(ModdedCropsFolderName,"SeedsGraphics.xnb"), Path.Combine(ModdedCropsFolderName,"SeedsData.xnb"), Path.Combine(ModdedCropsFolderName,"CropsGraphics.xnb"), Path.Combine(ModdedCropsFolderName,"CropsData.xnb"),Path.Combine(ModdedCropsFolderName,"CropsObjectTexture.xnb"), Path.Combine(ModdedCropsFolderName,"CropsObjectData.xnb")));
shopInventory.Add((Item)new ModularSeeds(1, Path.Combine(ModdedCropsFolderName, "SeedsGraphics.xnb"), Path.Combine(ModdedCropsFolderName, "SeedsData.xnb"), Path.Combine(ModdedCropsFolderName, "CropsGraphics.xnb"), Path.Combine(ModdedCropsFolderName, "CropsData.xnb"), Path.Combine(ModdedCropsFolderName, "CropsObjectTexture.xnb"), Path.Combine(ModdedCropsFolderName, "CropsObjectData.xnb")){
stack = 5
});
shopInventory.Add((Item)new PlanterBox(1, Vector2.Zero, Path.Combine(ModdedCropsFolderName, "PlanterBox.png"), Path.Combine(ModdedCropsFolderName, "PlanterBox.xnb")));
shopInventory.Add((Item)new ModularCropObject(816, 1, Path.Combine(ModdedCropsFolderName, "CropsObjectTexture.xnb"), Path.Combine(ModdedCropsFolderName, "CropsObjectData.xnb")));
Game1.activeClickableMenu = new StardewValley.Menus.ShopMenu(shopInventory);

View File

@ -74,6 +74,8 @@ namespace StardustCore
public AnimationManager animationManager;
public string serializationName;
public override string Name
{
get

View File

@ -3,8 +3,10 @@ using StardewModdingAPI;
using StardewValley;
using StardewValley.Menus;
using StardustCore.ModInfo;
using StardustCore.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -15,6 +17,7 @@ namespace StardustCore
{
public static IModHelper ModHelper;
public static IMonitor ModMonitor;
public static Serialization.SerializationManager SerializationManager;
public override void Entry(IModHelper helper)
{
ModHelper = helper;
@ -23,7 +26,32 @@ namespace StardustCore
// StardewModdingAPI.Events.GraphicsEvents.OnPostRenderGuiEvent += Metadata.GameEvents_UpdateTick;
// StardewModdingAPI.Events.ControlEvents.MouseChanged += ControlEvents_MouseChanged;
string invPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "PlayerData", Game1.player.name, "PlayerInventory");
string worldPath = Path.Combine(ModCore.ModHelper.DirectoryPath, Game1.player.name, "ObjectsInWorld"); ;
string trashPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "ModTrashFolder");
string chestPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "StorageContainers");
SerializationManager = new SerializationManager(invPath, trashPath, worldPath,chestPath);
StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave;
StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
}
private void SaveEvents_AfterLoad(object sender, EventArgs e)
{
SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList);
}
private void SaveEvents_AfterSave(object sender, EventArgs e)
{
SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList);
}
private void SaveEvents_BeforeSave(object sender, EventArgs e)
{
SerializationManager.cleanUpInventory();
SerializationManager.cleanUpWorld();
}
private void ControlEvents_MouseChanged(object sender, StardewModdingAPI.Events.EventArgsMouseStateChanged e)

View File

@ -2,6 +2,7 @@
using Newtonsoft.Json.Linq;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Buildings;
using System;
using System.Collections.Generic;
using System.IO;
@ -22,27 +23,30 @@ namespace StardustCore.Serialization
{
public string objectsInWorldPath;
public string playerInventoryPath;
public string SerializerTrashPath;
public string serializerTrashPath;
public string storageContainerPath;
public Dictionary<string, SerializerDataNode> acceptedTypes = new Dictionary<string, SerializerDataNode>();
public List<CoreObject> trackedObjectList = new List<CoreObject>();
public SerializationManager(string PlayerInventoryPath,string SerializerTrashPath,string ObjectsInWorldPath)
public SerializationManager(string PlayerInventoryPath,string SerializerTrashPath,string ObjectsInWorldPath,string StorageContainerPath)
{
this.objectsInWorldPath = ObjectsInWorldPath;
this.playerInventoryPath = PlayerInventoryPath;
this.SerializerTrashPath = SerializerTrashPath;
objectsInWorldPath = ObjectsInWorldPath;
playerInventoryPath = PlayerInventoryPath;
serializerTrashPath = SerializerTrashPath;
storageContainerPath = StorageContainerPath;
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);
if (!Directory.Exists(playerInventoryPath)) Directory.CreateDirectory(playerInventoryPath);
if (!Directory.Exists(serializerTrashPath)) Directory.CreateDirectory(serializerTrashPath);
if (!Directory.Exists(objectsInWorldPath)) Directory.CreateDirectory(objectsInWorldPath);
if (!Directory.Exists(storageContainerPath)) Directory.CreateDirectory(storageContainerPath);
}
public void cleanUpInventory()
@ -99,7 +103,7 @@ namespace StardustCore.Serialization
}
catch(Exception e)
{
Log.AsyncC(e);
// Log.AsyncC(e);
}
List<CoreObject> removalList = new List<CoreObject>();
int countProcessed = 0;
@ -123,7 +127,7 @@ namespace StardustCore.Serialization
if (acceptedTypes.ContainsKey(s))
{
Log.AsyncM("Object is of accepted type: " + s);
// Log.AsyncM("Object is of accepted type: " + s);
SerializerDataNode t;
bool works = acceptedTypes.TryGetValue(s, out t);
@ -132,7 +136,7 @@ namespace StardustCore.Serialization
countProcessed++;
if (d.useXML == false)
{
Log.AsyncY("Saving the object");
// Log.AsyncY("Saving the object");
t.worldObj.Invoke(d);
}
else
@ -175,11 +179,43 @@ namespace StardustCore.Serialization
}
public static void cleanUpStorageContainers()
{
foreach (GameLocation loc in Game1.locations)
{
foreach (var obj in loc.objects)
{
if (obj.Value is StardewValley.Objects.Chest) {
foreach(var item in (obj.Value as StardewValley.Objects.Chest).items)
{
if (item is CoreObject) (obj.Value as StardewValley.Objects.Chest).items.Remove(item);
}
}
}
}
foreach (Building building in Game1.getFarm().buildings)
{
GameLocation loc =Game1.getLocationFromName(building.nameOfIndoors,true);
Log.AsyncG("THIS IS MY BUILDING!!!!!");
foreach (var obj in loc.objects)
{
if (obj.Value is StardewValley.Objects.Chest)
{
foreach (var item in (obj.Value as StardewValley.Objects.Chest).items)
{
if (item is CoreObject) (obj.Value as StardewValley.Objects.Chest).items.Remove(item);
}
}
}
}
}
public void restoreAllModObjects(List<CoreObject> thingsToAddBackIn)
{
processDirectoryForDeserialization(this.playerInventoryPath,thingsToAddBackIn);
Log.AsyncG("DESERIALIZE???");
processDirectoryForDeserialization(playerInventoryPath,thingsToAddBackIn);
processDirectoryForDeserialization(storageContainerPath, thingsToAddBackIn);
// Log.AsyncG("Done deserializing player inventory.");
try
{
trackedObjectList.Clear(); //clear whatever mod objects I'm tracking
@ -261,9 +297,12 @@ namespace StardustCore.Serialization
public void processDirectoryForDeserialization(string pathToFile,List<CoreObject> thingsToAddBackIn)
{
string[] fileEntries = Directory.GetFiles(pathToFile);
// Log.AsyncC(pathToFile);
foreach(var fileName in fileEntries)
{
ProcessFileForCleanUp(fileName,thingsToAddBackIn);
// Log.AsyncG(fileName);
}
string[] subDirectories = Directory.GetDirectories(pathToFile);
@ -278,7 +317,7 @@ namespace StardustCore.Serialization
public void ProcessFileForCleanUp(string path, List<CoreObject> thingsToAddBackIn)
{
Log.AsyncC(path);
//Log.AsyncC(path);
string[] ehh = File.ReadAllLines(path);
string data = ehh[0];
@ -298,7 +337,7 @@ namespace StardustCore.Serialization
a = obj.serializationName;
b = a.Split(',');
s = b.ElementAt(0);
Log.AsyncC(s);
// Log.AsyncC(s);
}
catch (Exception e)
{
@ -315,7 +354,7 @@ namespace StardustCore.Serialization
if ((cObj as CoreObject).thisLocation == null)
{
Game1.player.addItemToInventory(cObj);
Log.AsyncY("ADDED ITEM TO INVENTORY");
// Log.AsyncY("ADDED ITEM TO INVENTORY");
return;
}
else
@ -350,23 +389,23 @@ namespace StardustCore.Serialization
//USE JSON STYLE DESERIALIZNG
if (acceptedTypes.ContainsKey(s))
{
Log.AsyncC("FUUUUU");
//Log.AsyncC("FUUUUU");
foreach (KeyValuePair<string, SerializerDataNode> pair in acceptedTypes)
{
Log.AsyncY(pair.Key);
// Log.AsyncY(pair.Key);
if (pair.Key == s)
{
try
{
//parse from Json Style
Log.AsyncR("1");
// 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");
// Log.AsyncY("ADDED ITEM TO INVENTORY");
return;
}
else
@ -378,7 +417,7 @@ namespace StardustCore.Serialization
}
catch (Exception e)
{
Log.AsyncO(e);
// Log.AsyncO(e);
}
}
}