Removed some logs and cleaned up inventory on failed deserialization of non-existent files.

This commit is contained in:
Joshua Navarro 2019-01-12 11:25:45 -08:00
parent 50577ea889
commit 80bdc98640
5 changed files with 51 additions and 33 deletions

View File

@ -77,7 +77,6 @@ namespace Revitalize.Framework.Objects
/// <summary>Places an object down.</summary> /// <summary>Places an object down.</summary>
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
{ {
ModCore.ModMonitor.Log("SCREAMING!!!!");
this.updateDrawPosition(x, y); this.updateDrawPosition(x, y);
this.location = location; this.location = location;
@ -115,38 +114,29 @@ namespace Revitalize.Framework.Objects
//instead of using this.offsetkey.x use get additional save data function and store offset key there //instead of using this.offsetkey.x use get additional save data function and store offset key there
Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"])); Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"]));
MultiTiledComponent self = Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>( additionalSaveData["GUID"]);
if (self == null)
//do same container creation logic in multitiled object {
return null;
}
MultiTiledComponent self = Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>( additionalSaveData["GUID"]);
if (self == null) return null;
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"])) if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"]))
{ {
//Get new container //Get new container
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledObject>(additionalSaveData["ParentGUID"]); MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledObject>(additionalSaveData["ParentGUID"]);
self.containerObject = obj; self.containerObject = obj;
obj.addComponent(offsetKey, self); obj.addComponent(offsetKey, self);
//Revitalize.ModCore.log("ADD IN AN OBJECT!!!!"); //Revitalize.ModCore.log("ADD IN AN OBJECT!!!!");
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], (MultiTiledObject)obj); Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], (MultiTiledObject)obj);
} }
else else
{ {
self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["ParentGUID"]]; self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["ParentGUID"]];
Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]].addComponent(offsetKey, self); Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]].addComponent(offsetKey, self);
//Revitalize.ModCore.log("READD AN OBJECT!!!!"); //Revitalize.ModCore.log("READD AN OBJECT!!!!");
} }
return (ICustomObject)self; return (ICustomObject)self;
BasicItemInformation data = Revitalize.ModCore.customObjects[additionalSaveData["id"]].info;
return new MultiTiledComponent(data, (replacement as Chest).TileLocation)
{
containerObject = this.containerObject,
offsetKey = this.offsetKey,
Stack = Convert.ToInt32(additionalSaveData["stack"])
};
} }
public override Dictionary<string, string> getAdditionalSaveData() public override Dictionary<string, string> getAdditionalSaveData()
@ -158,7 +148,7 @@ namespace Revitalize.Framework.Objects
string saveLocation = ""; string saveLocation = "";
if (this.location == null) if (this.location == null)
{ {
Revitalize.ModCore.log("WHY IS LOCTION NULL???"); //Revitalize.ModCore.log("WHY IS LOCTION NULL???");
saveLocation = ""; saveLocation = "";
} }
else else
@ -170,7 +160,6 @@ namespace Revitalize.Framework.Objects
} }
} }
Revitalize.ModCore.log("SAVE LOCATION: " + saveLocation);
saveData.Add("GameLocationName", saveLocation); saveData.Add("GameLocationName", saveLocation);
saveData.Add("Rotation", ((int)this.info.facingDirection).ToString()); saveData.Add("Rotation", ((int)this.info.facingDirection).ToString());
@ -199,8 +188,6 @@ namespace Revitalize.Framework.Objects
/// <summary>What happens when the object is drawn at a tile location.</summary> /// <summary>What happens when the object is drawn at a tile location.</summary>
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
{ {
Revitalize.ModCore.log("DRAW THE THING!!!");
Revitalize.ModCore.log(this.Name);
if (this.info == null) Revitalize.ModCore.log("info is null"); if (this.info == null) Revitalize.ModCore.log("info is null");
if (this.animationManager == null) Revitalize.ModCore.log("Animation Manager Null"); if (this.animationManager == null) Revitalize.ModCore.log("Animation Manager Null");
if (this.displayTexture == null) Revitalize.ModCore.log("Display texture is null"); if (this.displayTexture == null) Revitalize.ModCore.log("Display texture is null");

View File

@ -174,7 +174,6 @@ namespace Revitalize.Framework.Objects
} }
public override bool clicked(Farmer who) public override bool clicked(Farmer who)
{ {
ModCore.log("WTF IS HAPPENING???");
bool cleanUp = this.clicked(who); bool cleanUp = this.clicked(who);
if (cleanUp) if (cleanUp)
this.pickUp(); this.pickUp();
@ -213,7 +212,10 @@ namespace Revitalize.Framework.Objects
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledObject>(additionalSaveData["GUID"]); MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledObject>(additionalSaveData["GUID"]);
if (obj == null) return null; if (obj == null)
{
return null;
}
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>(); Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();

View File

@ -25,6 +25,7 @@ namespace Revitalize.Framework.Utilities.Serialization.Converters
{ {
string textureName = reader.Value as string; string textureName = reader.Value as string;
//ModCore.log(textureName); //ModCore.log(textureName);
if (string.IsNullOrEmpty(textureName)) return new Texture2D(Game1.graphics.GraphicsDevice, 2, 2);
string[] names = textureName.Split('.'); string[] names = textureName.Split('.');
if (names.Length == 0) return null; if (names.Length == 0) return null;

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using Revitalize.Framework.Utilities.Serialization.ContractResolvers; using Revitalize.Framework.Utilities.Serialization.ContractResolvers;
using StardewValley; using StardewValley;
using StardewValley.Objects;
namespace Revitalize.Framework.Utilities namespace Revitalize.Framework.Utilities
{ {
@ -24,7 +25,7 @@ namespace Revitalize.Framework.Utilities
/// </summary> /// </summary>
private Dictionary<string, List<string>> filesToDelete = new Dictionary<string, List<string>>(); private Dictionary<string, List<string>> filesToDelete = new Dictionary<string, List<string>>();
public List<Item> itemsToRemove = new List<Item>();
/// <summary> /// <summary>
@ -54,7 +55,7 @@ namespace Revitalize.Framework.Utilities
/// </summary> /// </summary>
private void gatherAllFilesForCleanup() private void gatherAllFilesForCleanup()
{ {
this.filesToDelete.Clear();
string[] directories = Directory.GetDirectories(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, "SaveData")); string[] directories = Directory.GetDirectories(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, "SaveData"));
foreach (string playerData in directories) foreach (string playerData in directories)
{ {
@ -85,6 +86,30 @@ namespace Revitalize.Framework.Utilities
public void afterLoad() public void afterLoad()
{ {
deleteAllUnusedFiles(); deleteAllUnusedFiles();
removeNullObjects();
}
public void returnToTitle()
{
gatherAllFilesForCleanup();
}
private void removeNullObjects()
{
List<Item> removalList = new List<Item>();
foreach(Item I in Game1.player.items)
{
if (I == null) continue;
if (I.DisplayName.Contains("Revitalize.Framework") && (I is Chest))
{
removalList.Add(I);
}
}
foreach(Item I in removalList)
{
Game1.player.items.Remove(I);
}
} }
/// <summary> /// <summary>

View File

@ -20,9 +20,6 @@ using StardewValley.Objects;
namespace Revitalize namespace Revitalize
{ {
// TODO: // TODO:
// Find a way to delete unnecessary files in SaveData/Player/SaveObjectInformation
//
//
// //
// -Multiple Lights On Object // -Multiple Lights On Object
// -Illumination Colors // -Illumination Colors
@ -119,6 +116,7 @@ namespace Revitalize
ModHelper.Events.GameLoop.SaveLoaded += this.GameLoop_SaveLoaded; ModHelper.Events.GameLoop.SaveLoaded += this.GameLoop_SaveLoaded;
ModHelper.Events.GameLoop.TimeChanged += this.GameLoop_TimeChanged; ModHelper.Events.GameLoop.TimeChanged += this.GameLoop_TimeChanged;
ModHelper.Events.GameLoop.UpdateTicked += this.GameLoop_UpdateTicked; ModHelper.Events.GameLoop.UpdateTicked += this.GameLoop_UpdateTicked;
ModHelper.Events.GameLoop.ReturnedToTitle += this.GameLoop_ReturnedToTitle;
playerInfo = new PlayerInfo(); playerInfo = new PlayerInfo();
Framework.Graphics.TextureManager.TextureManagers.Add("Furniture", new TextureManager()); Framework.Graphics.TextureManager.TextureManagers.Add("Furniture", new TextureManager());
@ -132,6 +130,11 @@ namespace Revitalize
} }
private void GameLoop_ReturnedToTitle(object sender, StardewModdingAPI.Events.ReturnedToTitleEventArgs e)
{
Serializer.returnToTitle();
}
private void loadContent() private void loadContent()
{ {
MultiTiledComponent obj = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest", "YAY FUN!", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair"), new Animation(new Rectangle(0, 0, 16, 16))), Color.Red, true, null, null)); MultiTiledComponent obj = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest", "YAY FUN!", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair"), new Animation(new Rectangle(0, 0, 16, 16))), Color.Red, true, null, null));