Serialization works a bit, just need to incorporate that into the recreate functions for objects.

This commit is contained in:
Joshua Navarro 2019-01-10 09:14:16 -08:00
parent 5b6d02babd
commit 49f06533b3
7 changed files with 58 additions and 30 deletions

View File

@ -13,7 +13,7 @@ namespace Revitalize.Framework.Graphics.Animations
public string currentAnimationName; public string currentAnimationName;
public int currentAnimationListIndex; public int currentAnimationListIndex;
public List<Animation> currentAnimationList = new List<Animation>(); public List<Animation> currentAnimationList = new List<Animation>();
private Texture2DExtended objectTexture; ///Might not be necessary if I use the CoreObject texture sheet. public Texture2DExtended objectTexture; ///Might not be necessary if I use the CoreObject texture sheet.
public Animation defaultDrawFrame; public Animation defaultDrawFrame;
public Animation currentAnimation; public Animation currentAnimation;
public bool enabled; public bool enabled;

View File

@ -49,7 +49,7 @@ namespace Revitalize.Framework.Objects
this.canBeSetIndoors = false; this.canBeSetIndoors = false;
this.canBeSetOutdoors = false; this.canBeSetOutdoors = false;
this.animationManager = null; this.animationManager = new AnimationManager();
this.drawPosition = Vector2.Zero; this.drawPosition = Vector2.Zero;
this.drawColor = Color.White; this.drawColor = Color.White;
this.inventory = new InventoryManager(); this.inventory = new InventoryManager();

View File

@ -31,7 +31,7 @@ namespace Revitalize.Framework.Objects.Furniture
} }
public ChairMultiTiledObject(BasicItemInformation Info,Vector2 TilePosition,Dictionary<Vector2, StardewValley.Object> Objects) : base(Info, TilePosition, Objects) { public ChairMultiTiledObject(BasicItemInformation Info,Vector2 TilePosition,Dictionary<Vector2, MultiTiledComponent> 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, StardewValley.Object> pair in this.objects) foreach(KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
{ {
(pair.Value as ChairTileComponent).rotate(); (pair.Value as ChairTileComponent).rotate();
} }
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects) foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
{ {
(pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation(); (pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation();
} }

View File

@ -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, StardewValley.Object> pair in this.containerObject.objects) foreach(KeyValuePair<Vector2, MultiTiledComponent> pair in this.containerObject.objects)
{ {
(pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation(); (pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation();
} }

View File

@ -203,6 +203,8 @@ 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!!!");
if (x <= -1) if (x <= -1)
{ {
spriteBatch.Draw(this.info.animationManager.getTexture(), Game1.GlobalToLocal(Game1.viewport, this.info.drawPosition), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(this.TileLocation.Y * Game1.tileSize) / 10000f)); spriteBatch.Draw(this.info.animationManager.getTexture(), Game1.GlobalToLocal(Game1.viewport, this.info.drawPosition), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(this.TileLocation.Y * Game1.tileSize) / 10000f));

View File

@ -5,13 +5,12 @@ using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json; using Newtonsoft.Json;
using PyTK.CustomElementHandler; using PyTK.CustomElementHandler;
using StardewValley; using StardewValley;
using StardewValley.Objects;
namespace Revitalize.Framework.Objects namespace Revitalize.Framework.Objects
{ {
public class MultiTiledObject : CustomObject public class MultiTiledObject : CustomObject
{ {
public Dictionary<Vector2, StardewValley.Object> objects; public Dictionary<Vector2, MultiTiledComponent> objects;
[JsonIgnore] [JsonIgnore]
public Dictionary<MultiTiledComponent, Vector2> offSets; public Dictionary<MultiTiledComponent, Vector2> offSets;
@ -36,7 +35,7 @@ namespace Revitalize.Framework.Objects
public MultiTiledObject() public MultiTiledObject()
{ {
this.objects = new Dictionary<Vector2, StardewValley.Object>(); this.objects = new Dictionary<Vector2, MultiTiledComponent>();
this.offSets = new Dictionary<MultiTiledComponent, Vector2>(); this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
this.guid = Guid.NewGuid(); this.guid = Guid.NewGuid();
} }
@ -44,7 +43,7 @@ namespace Revitalize.Framework.Objects
public MultiTiledObject(BasicItemInformation info) public MultiTiledObject(BasicItemInformation info)
: base(info) : base(info)
{ {
this.objects = new Dictionary<Vector2, StardewValley.Object>(); this.objects = new Dictionary<Vector2, MultiTiledComponent>();
this.offSets = new Dictionary<MultiTiledComponent, Vector2>(); this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
this.guid = Guid.NewGuid(); this.guid = Guid.NewGuid();
} }
@ -52,20 +51,20 @@ namespace Revitalize.Framework.Objects
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation) public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation)
: base(info, TileLocation) : base(info, TileLocation)
{ {
this.objects = new Dictionary<Vector2, StardewValley.Object>(); this.objects = new Dictionary<Vector2, MultiTiledComponent>();
this.offSets = new Dictionary<MultiTiledComponent, Vector2>(); this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
this.guid = Guid.NewGuid(); this.guid = Guid.NewGuid();
} }
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, StardewValley.Object> ObjectsList) public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, MultiTiledComponent> ObjectsList)
: base(info, TileLocation) : base(info, TileLocation)
{ {
this.objects = new Dictionary<Vector2, StardewValley.Object>(); this.objects = new Dictionary<Vector2, MultiTiledComponent>();
this.offSets = new Dictionary<MultiTiledComponent, Vector2>(); this.offSets = new Dictionary<MultiTiledComponent, Vector2>();
foreach (var v in ObjectsList) foreach (var v in ObjectsList)
{ {
MultiTiledComponent component = (MultiTiledComponent)v.Value.getOne(); MultiTiledComponent component =(MultiTiledComponent) v.Value.getOne();
this.addComponent(v.Key, component); this.addComponent(v.Key, (component as MultiTiledComponent));
} }
this.guid = Guid.NewGuid(); this.guid = Guid.NewGuid();
@ -76,12 +75,12 @@ namespace Revitalize.Framework.Objects
if (this.objects.ContainsKey(key)) if (this.objects.ContainsKey(key))
return false; return false;
this.objects.Add(key, obj); this.objects.Add(key, (obj as MultiTiledComponent));
this.offSets.Add(obj, key); this.offSets.Add((obj as MultiTiledComponent), key);
if (key.X > this.width) this.width = (int)key.X; if (key.X > this.width) this.width = (int)key.X;
if (key.Y > this.height) this.height = (int)key.Y; if (key.Y > this.height) this.height = (int)key.Y;
obj.containerObject = this; (obj as MultiTiledComponent).containerObject = this;
obj.offsetKey = key; (obj as MultiTiledComponent).offsetKey = key;
return true; return true;
} }
@ -96,13 +95,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, StardewValley.Object> pair in this.objects) foreach (KeyValuePair<Vector2, MultiTiledComponent> 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, StardewValley.Object> pair in this.objects) foreach (KeyValuePair<Vector2, MultiTiledComponent> 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);
@ -110,14 +109,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, StardewValley.Object> pair in this.objects) foreach (KeyValuePair<Vector2, MultiTiledComponent> 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, StardewValley.Object> pair in this.objects) foreach (KeyValuePair<Vector2, MultiTiledComponent> 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);
} }
@ -130,7 +129,7 @@ namespace Revitalize.Framework.Objects
bool canPickUp = this.removeAndAddToPlayersInventory(); bool canPickUp = this.removeAndAddToPlayersInventory();
if (canPickUp) if (canPickUp)
{ {
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects) foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
(pair.Value as MultiTiledComponent).removeFromLocation((pair.Value as MultiTiledComponent).location, pair.Key); (pair.Value as MultiTiledComponent).removeFromLocation((pair.Value as MultiTiledComponent).location, pair.Key);
this.location = null; this.location = null;
} }
@ -151,10 +150,10 @@ 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, StardewValley.Object> pair in this.objects) foreach (KeyValuePair<Vector2, MultiTiledComponent> 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);
} }
this.location = location; this.location = location;
return true; return true;
@ -163,7 +162,7 @@ namespace Revitalize.Framework.Objects
public override bool canBePlacedHere(GameLocation l, Vector2 tile) public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{ {
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects) foreach (KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
{ {
if (!pair.Value.canBePlacedHere(l, tile + pair.Key)) if (!pair.Value.canBePlacedHere(l, tile + pair.Key))
return false; return false;
@ -230,7 +229,7 @@ namespace Revitalize.Framework.Objects
public void setAllAnimationsToDefault() public void setAllAnimationsToDefault()
{ {
foreach(KeyValuePair<Vector2, StardewValley.Object> pair in this.objects) foreach(KeyValuePair<Vector2, MultiTiledComponent> pair in this.objects)
{ {
string animationKey = (pair.Value as MultiTiledComponent) .generateDefaultRotationalAnimationKey(); string animationKey = (pair.Value as MultiTiledComponent) .generateDefaultRotationalAnimationKey();
if ((pair.Value as MultiTiledComponent).animationManager.animations.ContainsKey(animationKey)) if ((pair.Value as MultiTiledComponent).animationManager.animations.ContainsKey(animationKey))
@ -239,5 +238,15 @@ namespace Revitalize.Framework.Objects
} }
} }
} }
public override bool canStackWith(Item other)
{
return false;
}
public override int maximumStackSize()
{
return 1;
}
} }
} }

View File

@ -20,6 +20,7 @@ using StardewValley.Objects;
namespace Revitalize namespace Revitalize
{ {
// TODO: // TODO:
//Need to find a way to recreate objects again.
//Make guid object list to keep track of container objects on rebuild. Container objects have guid, on getAdditionalSaveData, store it. On rebuild keep a list, get a reference to container object, clear those objects, and reset them as we are rebuilting multiTiledComponents. //Make guid object list to keep track of container objects on rebuild. Container objects have guid, on getAdditionalSaveData, store it. On rebuild keep a list, get a reference to container object, clear those objects, and reset them as we are rebuilting multiTiledComponents.
// //
// -Multiple Lights On Object // -Multiple Lights On Object
@ -282,12 +283,28 @@ namespace Revitalize
var hello=Serializer.Deserialize<MultiTiledObject>(Path.Combine(this.Helper.DirectoryPath, (obj as MultiTiledObject).guid + ".json")); MultiTiledObject hello=Serializer.Deserialize<MultiTiledObject>(Path.Combine(this.Helper.DirectoryPath, (obj as MultiTiledObject).guid + ".json"));
//(hello as MultiTiledObject).info.drawColor = Color.Blue; //(hello as MultiTiledObject).info.drawColor = Color.Blue;
customObjects["Omegasis.BigTiledTest"].info.drawColor = hello.info.drawColor; customObjects["Omegasis.BigTiledTest"].info.drawColor = hello.info.drawColor;
Game1.player.addItemToInventory(hello); if (hello == null) log("WTF");
else
{
log("AHHHH" + hello.name);
}
hello.info.drawColor = Color.Blue;
foreach(KeyValuePair<Vector2,MultiTiledComponent> pair in hello.objects){
pair.Value.containerObject = hello;
}
Game1.player.items.Add(hello);
Game1.activeClickableMenu = new StardewValley.Menus.ItemGrabMenu(new List<Item>()
{
hello
});
} }