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>
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
{
ModCore.ModMonitor.Log("SCREAMING!!!!");
this.updateDrawPosition(x, y);
this.location = location;
@ -115,13 +114,11 @@ namespace Revitalize.Framework.Objects
//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"]));
//do same container creation logic in multitiled object
MultiTiledComponent self = Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>( additionalSaveData["GUID"]);
if (self == null) return null;
if (self == null)
{
return null;
}
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"]))
{
@ -140,13 +137,6 @@ namespace Revitalize.Framework.Objects
}
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()
@ -158,7 +148,7 @@ namespace Revitalize.Framework.Objects
string saveLocation = "";
if (this.location == null)
{
Revitalize.ModCore.log("WHY IS LOCTION NULL???");
//Revitalize.ModCore.log("WHY IS LOCTION NULL???");
saveLocation = "";
}
else
@ -170,7 +160,6 @@ namespace Revitalize.Framework.Objects
}
}
Revitalize.ModCore.log("SAVE LOCATION: " + saveLocation);
saveData.Add("GameLocationName", saveLocation);
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>
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.animationManager == null) Revitalize.ModCore.log("Animation Manager 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)
{
ModCore.log("WTF IS HAPPENING???");
bool cleanUp = this.clicked(who);
if (cleanUp)
this.pickUp();
@ -213,7 +212,10 @@ namespace Revitalize.Framework.Objects
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>();

View File

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

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Newtonsoft.Json;
using Revitalize.Framework.Utilities.Serialization.ContractResolvers;
using StardewValley;
using StardewValley.Objects;
namespace Revitalize.Framework.Utilities
{
@ -24,7 +25,7 @@ namespace Revitalize.Framework.Utilities
/// </summary>
private Dictionary<string, List<string>> filesToDelete = new Dictionary<string, List<string>>();
public List<Item> itemsToRemove = new List<Item>();
/// <summary>
@ -54,7 +55,7 @@ namespace Revitalize.Framework.Utilities
/// </summary>
private void gatherAllFilesForCleanup()
{
this.filesToDelete.Clear();
string[] directories = Directory.GetDirectories(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, "SaveData"));
foreach (string playerData in directories)
{
@ -85,6 +86,30 @@ namespace Revitalize.Framework.Utilities
public void afterLoad()
{
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>

View File

@ -20,9 +20,6 @@ using StardewValley.Objects;
namespace Revitalize
{
// TODO:
// Find a way to delete unnecessary files in SaveData/Player/SaveObjectInformation
//
//
//
// -Multiple Lights On Object
// -Illumination Colors
@ -119,6 +116,7 @@ namespace Revitalize
ModHelper.Events.GameLoop.SaveLoaded += this.GameLoop_SaveLoaded;
ModHelper.Events.GameLoop.TimeChanged += this.GameLoop_TimeChanged;
ModHelper.Events.GameLoop.UpdateTicked += this.GameLoop_UpdateTicked;
ModHelper.Events.GameLoop.ReturnedToTitle += this.GameLoop_ReturnedToTitle;
playerInfo = new PlayerInfo();
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()
{
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));