Figured some weird serialization issues. Now to recreate the data after a save...
This commit is contained in:
parent
b3f0659f9f
commit
198a908c01
|
@ -31,7 +31,7 @@ namespace Revitalize.Framework.Objects.Furniture
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChairMultiTiledObject(BasicItemInformation Info,Vector2 TilePosition,Dictionary<Vector2,MultiTiledComponent> Objects) : base(Info, TilePosition, Objects) {
|
public ChairMultiTiledObject(BasicItemInformation Info,Vector2 TilePosition,Dictionary<Vector2, StardewValley.Object> Objects) : base(Info, TilePosition, Objects) {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,11 @@ namespace Revitalize.Framework.Objects.Furniture
|
||||||
public override void rotate()
|
public override void rotate()
|
||||||
{
|
{
|
||||||
Revitalize.ModCore.log("Rotate!");
|
Revitalize.ModCore.log("Rotate!");
|
||||||
foreach(KeyValuePair<Vector2,MultiTiledComponent> pair in this.objects)
|
foreach(KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
{
|
{
|
||||||
pair.Value.rotate();
|
(pair.Value as ChairTileComponent).rotate();
|
||||||
}
|
}
|
||||||
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
{
|
{
|
||||||
(pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation();
|
(pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace Revitalize.Framework.Objects.Furniture
|
||||||
if (this.CanSitHere)
|
if (this.CanSitHere)
|
||||||
{
|
{
|
||||||
Revitalize.ModCore.playerInfo.sittingInfo.sit(this.containerObject, this.TileLocation*Game1.tileSize);
|
Revitalize.ModCore.playerInfo.sittingInfo.sit(this.containerObject, this.TileLocation*Game1.tileSize);
|
||||||
foreach(KeyValuePair<Vector2,MultiTiledComponent>pair in this.containerObject.objects)
|
foreach(KeyValuePair<Vector2, StardewValley.Object> pair in this.containerObject.objects)
|
||||||
{
|
{
|
||||||
(pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation();
|
(pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,11 +109,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
|
||||||
|
|
||||||
if (this.offsetKey.X == 0 && this.offsetKey.Y == 0)
|
Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"]));
|
||||||
|
|
||||||
|
if (offsetKey.X == 0 && offsetKey.Y == 0)
|
||||||
{
|
{
|
||||||
Revitalize.ModCore.log(recreateParentId(additionalSaveData["id"]) + ".Object");
|
Revitalize.ModCore.log(recreateParentId(additionalSaveData["id"]) + ".Object");
|
||||||
var obj=(Revitalize.ModCore.customObjects[recreateParentId(additionalSaveData["id"])+".Object"].getOne());
|
CustomObject obj=(CustomObject)(Revitalize.ModCore.customObjects[recreateParentId(additionalSaveData["id"])+".Object"].getOne());
|
||||||
obj.Stack =Convert.ToInt32( additionalSaveData["stack"]);
|
obj.Stack =Convert.ToInt32( additionalSaveData["stack"]);
|
||||||
|
|
||||||
|
string saveLocation = additionalSaveData["GameLocationName"];
|
||||||
|
|
||||||
|
|
||||||
|
Enums.Direction facingDirection = (Enums.Direction)Convert.ToInt32(additionalSaveData["Rotation"]);
|
||||||
|
while (obj.info.facingDirection != facingDirection)
|
||||||
|
{
|
||||||
|
obj.rotate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(saveLocation))
|
||||||
|
{
|
||||||
|
obj.placementAction(Game1.getLocationFromName(saveLocation), (int)(replacement as Chest).TileLocation.X, (int)(replacement as Chest).TileLocation.Y);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (ICustomObject)obj;
|
return (ICustomObject)obj;
|
||||||
BasicItemInformation data = Revitalize.ModCore.customObjects[additionalSaveData["id"]].info;
|
BasicItemInformation data = Revitalize.ModCore.customObjects[additionalSaveData["id"]].info;
|
||||||
return new MultiTiledComponent(data, (replacement as Chest).TileLocation)
|
return new MultiTiledComponent(data, (replacement as Chest).TileLocation)
|
||||||
|
@ -129,6 +147,31 @@ namespace Revitalize.Framework.Objects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Dictionary<string, string> getAdditionalSaveData()
|
||||||
|
{
|
||||||
|
Dictionary<string,string> saveData= base.getAdditionalSaveData();
|
||||||
|
saveData.Add("offsetKeyX", this.offsetKey.X.ToString());
|
||||||
|
saveData.Add("offsetKeyY", this.offsetKey.Y.ToString());
|
||||||
|
string saveLocation = "";
|
||||||
|
if (this.location == null)
|
||||||
|
{
|
||||||
|
saveLocation = "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(this.location.uniqueName.Value)) saveLocation = this.location.uniqueName.Value;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saveLocation = this.location.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveData.Add("GameLocationName", saveLocation);
|
||||||
|
saveData.Add("Rotation", ((int)this.info.facingDirection).ToString());
|
||||||
|
|
||||||
|
return saveData;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected string recreateParentId(string id)
|
protected string recreateParentId(string id)
|
||||||
{
|
{
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace Revitalize.Framework.Objects
|
||||||
{
|
{
|
||||||
public class MultiTiledObject : CustomObject
|
public class MultiTiledObject : CustomObject
|
||||||
{
|
{
|
||||||
public Dictionary<Vector2, MultiTiledComponent> objects;
|
public Dictionary<Vector2, StardewValley.Object> objects;
|
||||||
public Dictionary<MultiTiledComponent, Vector2> offSets;
|
public Dictionary<MultiTiledComponent, Vector2> offSets;
|
||||||
|
|
||||||
private int width;
|
private int width;
|
||||||
|
@ -31,28 +31,28 @@ namespace Revitalize.Framework.Objects
|
||||||
|
|
||||||
public MultiTiledObject()
|
public MultiTiledObject()
|
||||||
{
|
{
|
||||||
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
|
this.objects = new Dictionary<Vector2, StardewValley.Object>();
|
||||||
this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
|
this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiTiledObject(BasicItemInformation info)
|
public MultiTiledObject(BasicItemInformation info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
|
this.objects = new Dictionary<Vector2, StardewValley.Object>();
|
||||||
this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
|
this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation)
|
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation)
|
||||||
: base(info, TileLocation)
|
: base(info, TileLocation)
|
||||||
{
|
{
|
||||||
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
|
this.objects = new Dictionary<Vector2, StardewValley.Object>();
|
||||||
this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
|
this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, MultiTiledComponent> ObjectsList)
|
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, StardewValley.Object> ObjectsList)
|
||||||
: base(info, TileLocation)
|
: base(info, TileLocation)
|
||||||
{
|
{
|
||||||
this.objects = new Dictionary<Vector2, MultiTiledComponent>();
|
this.objects = new Dictionary<Vector2, StardewValley.Object>();
|
||||||
this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
|
this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
|
||||||
foreach (var v in ObjectsList)
|
foreach (var v in ObjectsList)
|
||||||
{
|
{
|
||||||
|
@ -87,13 +87,13 @@ namespace Revitalize.Framework.Objects
|
||||||
|
|
||||||
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1)
|
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
pair.Value.draw(spriteBatch, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, alpha);
|
pair.Value.draw(spriteBatch, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1)
|
public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
pair.Value.draw(spriteBatch, xNonTile + (int)pair.Key.X * Game1.tileSize, yNonTile + (int)pair.Key.Y * Game1.tileSize, layerDepth, alpha);
|
pair.Value.draw(spriteBatch, xNonTile + (int)pair.Key.X * Game1.tileSize, yNonTile + (int)pair.Key.Y * Game1.tileSize, layerDepth, alpha);
|
||||||
|
|
||||||
//base.draw(spriteBatch, xNonTile, yNonTile, layerDepth, alpha);
|
//base.draw(spriteBatch, xNonTile, yNonTile, layerDepth, alpha);
|
||||||
|
@ -101,14 +101,14 @@ namespace Revitalize.Framework.Objects
|
||||||
|
|
||||||
public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow)
|
public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
pair.Value.drawInMenu(spriteBatch, location + (pair.Key * 16), 1.0f, transparency, layerDepth, drawStackNumber, c, drawShadow);
|
pair.Value.drawInMenu(spriteBatch, location + (pair.Key * 16), 1.0f, transparency, layerDepth, drawStackNumber, c, drawShadow);
|
||||||
//base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, c, drawShadow);
|
//base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, c, drawShadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, Farmer f)
|
public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, Farmer f)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
pair.Value.drawWhenHeld(spriteBatch, objectPosition + (pair.Key * Game1.tileSize), f);
|
pair.Value.drawWhenHeld(spriteBatch, objectPosition + (pair.Key * Game1.tileSize), f);
|
||||||
//base.drawWhenHeld(spriteBatch, objectPosition, f);
|
//base.drawWhenHeld(spriteBatch, objectPosition, f);
|
||||||
}
|
}
|
||||||
|
@ -121,8 +121,8 @@ namespace Revitalize.Framework.Objects
|
||||||
bool canPickUp = this.removeAndAddToPlayersInventory();
|
bool canPickUp = this.removeAndAddToPlayersInventory();
|
||||||
if (canPickUp)
|
if (canPickUp)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
pair.Value.removeFromLocation(pair.Value.location, pair.Key);
|
(pair.Value as MultiTiledComponent).removeFromLocation((pair.Value as MultiTiledComponent).location, pair.Key);
|
||||||
this.location = null;
|
this.location = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -142,7 +142,7 @@ namespace Revitalize.Framework.Objects
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
{
|
{
|
||||||
pair.Value.placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who);
|
pair.Value.placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who);
|
||||||
ModCore.log(pair.Value.TileLocation);
|
ModCore.log(pair.Value.TileLocation);
|
||||||
|
@ -154,7 +154,7 @@ namespace Revitalize.Framework.Objects
|
||||||
|
|
||||||
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
|
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
{
|
{
|
||||||
if (!pair.Value.canBePlacedHere(l, tile + pair.Key))
|
if (!pair.Value.canBePlacedHere(l, tile + pair.Key))
|
||||||
return false;
|
return false;
|
||||||
|
@ -200,12 +200,12 @@ namespace Revitalize.Framework.Objects
|
||||||
|
|
||||||
public void setAllAnimationsToDefault()
|
public void setAllAnimationsToDefault()
|
||||||
{
|
{
|
||||||
foreach(KeyValuePair<Vector2,MultiTiledComponent> pair in this.objects)
|
foreach(KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
{
|
{
|
||||||
string animationKey = pair.Value.generateDefaultRotationalAnimationKey();
|
string animationKey = (pair.Value as MultiTiledComponent) .generateDefaultRotationalAnimationKey();
|
||||||
if (pair.Value.animationManager.animations.ContainsKey(animationKey))
|
if ((pair.Value as MultiTiledComponent).animationManager.animations.ContainsKey(animationKey))
|
||||||
{
|
{
|
||||||
pair.Value.animationManager.setAnimation(animationKey);
|
(pair.Value as MultiTiledComponent).animationManager.setAnimation(animationKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue