Removed some logs and cleaned up inventory on failed deserialization of non-existent files.
This commit is contained in:
parent
50577ea889
commit
80bdc98640
|
@ -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,38 +114,29 @@ 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;
|
||||
MultiTiledComponent self = Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>( additionalSaveData["GUID"]);
|
||||
if (self == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"]))
|
||||
{
|
||||
{
|
||||
//Get new container
|
||||
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledObject>(additionalSaveData["ParentGUID"]);
|
||||
self.containerObject = obj;
|
||||
obj.addComponent(offsetKey, self);
|
||||
//Revitalize.ModCore.log("ADD IN AN OBJECT!!!!");
|
||||
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], (MultiTiledObject)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["ParentGUID"]];
|
||||
}
|
||||
else
|
||||
{
|
||||
self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["ParentGUID"]];
|
||||
Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]].addComponent(offsetKey, self);
|
||||
//Revitalize.ModCore.log("READD AN OBJECT!!!!");
|
||||
}
|
||||
}
|
||||
|
||||
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"])
|
||||
};
|
||||
return (ICustomObject)self;
|
||||
}
|
||||
|
||||
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");
|
||||
|
|
|
@ -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>();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue