It compiles in single player but does not like multiplayer.

This commit is contained in:
Joshua Navarro 2019-01-10 12:44:10 -08:00
parent 20c7ba8ad5
commit 7799834f46
6 changed files with 77 additions and 66 deletions

View File

@ -25,6 +25,8 @@ namespace Revitalize.Framework.Objects
public BasicItemInformation info; public BasicItemInformation info;
public GameLocation location; public GameLocation location;
public Guid guid;
/// <summary>The animation manager.</summary> /// <summary>The animation manager.</summary>
public AnimationManager animationManager => this.info.animationManager; public AnimationManager animationManager => this.info.animationManager;
@ -36,7 +38,9 @@ namespace Revitalize.Framework.Objects
/// <summary>Empty constructor.</summary> /// <summary>Empty constructor.</summary>
public CustomObject() { } public CustomObject() {
this.guid = Guid.NewGuid();
}
/// <summary>Construct an instance.</summary> /// <summary>Construct an instance.</summary>
public CustomObject(BasicItemInformation info) public CustomObject(BasicItemInformation info)
@ -44,6 +48,7 @@ namespace Revitalize.Framework.Objects
{ {
this.info = info; this.info = info;
this.initializeBasics(); this.initializeBasics();
this.guid = Guid.NewGuid();
} }
/// <summary>Construct an instance.</summary> /// <summary>Construct an instance.</summary>
@ -52,6 +57,7 @@ namespace Revitalize.Framework.Objects
{ {
this.info = info; this.info = info;
this.initializeBasics(); this.initializeBasics();
this.guid = Guid.NewGuid();
} }
/// <summary>Sets some basic information up.</summary> /// <summary>Sets some basic information up.</summary>
@ -334,6 +340,8 @@ namespace Revitalize.Framework.Objects
/// <summary>What happens when the object is drawn when held by a player.</summary> /// <summary>What happens when the object is drawn when held by a player.</summary>
public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, StardewValley.Farmer f) public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, StardewValley.Farmer f)
{ {
if (this.animationManager == null) Revitalize.ModCore.log("Animation Manager Null");
if (this.displayTexture == null) Revitalize.ModCore.log("Display texture is null");
if (f.ActiveObject.bigCraftable.Value) if (f.ActiveObject.bigCraftable.Value)
{ {
spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, this.info.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, this.info.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f));

View File

@ -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 as ChairTileComponent).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();
} }

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, 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();
} }

View File

@ -116,26 +116,28 @@ namespace Revitalize.Framework.Objects
Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"])); Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"]));
Revitalize.ModCore.log("HELLO WORLD!");
//do same container creation logic in multitiled object //do same container creation logic in multitiled object
MultiTiledComponent self = null; MultiTiledComponent self = Revitalize.ModCore.Serializer.Deserialize<MultiTiledComponent>(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, additionalSaveData["GUID"] + ".json"));
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["GUID"])) if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"]))
{ {
//Get new container //Get new container
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.Deserialize<MultiTiledObject>(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, additionalSaveData["GUID"] + ".json")); MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.Deserialize<MultiTiledObject>(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, additionalSaveData["ParentGUID"] + ".json"));
self = (MultiTiledComponent)(obj as MultiTiledObject).objects[offsetKey]; self.containerObject = obj;
self.containerObject = obj; obj.addComponent(offsetKey, self);
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], (MultiTiledObject)obj); Revitalize.ModCore.log("ADD IN AN OBJECT!!!!");
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], (MultiTiledObject)obj);
} }
else else
{ {
self =(MultiTiledComponent)Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]].objects[offsetKey];
self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]]; self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]];
Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]].addComponent(offsetKey, self);
Revitalize.ModCore.log("READD AN OBJECT!!!!");
} }
return (ICustomObject)self; return (ICustomObject)self;
@ -174,7 +176,9 @@ namespace Revitalize.Framework.Objects
saveData.Add("GameLocationName", saveLocation); saveData.Add("GameLocationName", saveLocation);
saveData.Add("Rotation", ((int)this.info.facingDirection).ToString()); saveData.Add("Rotation", ((int)this.info.facingDirection).ToString());
saveData.Add("GUID", this.containerObject.guid.ToString()); saveData.Add("ParentGUID", this.containerObject.guid.ToString());
saveData.Add("GUID", this.guid.ToString());
Revitalize.ModCore.Serializer.Serialize(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, this.containerObject.childrenGuids[this.offsetKey].ToString() + ".json"),this);
return saveData; return saveData;
@ -197,7 +201,9 @@ namespace Revitalize.Framework.Objects
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("DRAW THE THING!!!");
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");
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));
@ -241,10 +247,7 @@ namespace Revitalize.Framework.Objects
} }
} }
public static implicit operator MultiTiledComponent(Chest chest)
{
return new MultiTiledComponent(new BasicItemInformation(),chest.TileLocation);
}
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -11,9 +12,10 @@ namespace Revitalize.Framework.Objects
{ {
public class MultiTiledObject : CustomObject public class MultiTiledObject : CustomObject
{ {
public Dictionary<Vector2, MultiTiledComponent> objects; [JsonIgnore]
public Dictionary<Vector2, StardewValley.Object> objects;
public Guid guid; public Dictionary<Vector2,Guid> childrenGuids;
private int width; private int width;
private int height; private int height;
@ -34,28 +36,32 @@ namespace Revitalize.Framework.Objects
public MultiTiledObject() public MultiTiledObject()
{ {
this.objects = new Dictionary<Vector2, MultiTiledComponent>(); this.objects = new Dictionary<Vector2, StardewValley.Object>();
this.childrenGuids = new Dictionary<Vector2, Guid>();
this.guid = Guid.NewGuid(); this.guid = Guid.NewGuid();
} }
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.childrenGuids = new Dictionary<Vector2, Guid>();
this.guid = Guid.NewGuid(); this.guid = Guid.NewGuid();
} }
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.childrenGuids = new Dictionary<Vector2, Guid>();
this.guid = Guid.NewGuid(); this.guid = Guid.NewGuid();
} }
public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, MultiTiledComponent> ObjectsList) public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary<Vector2, MultiTiledComponent> ObjectsList)
: base(info, TileLocation) : base(info, TileLocation)
{ {
this.objects = new Dictionary<Vector2, MultiTiledComponent>(); this.objects = new Dictionary<Vector2, StardewValley.Object>();
this.childrenGuids = new Dictionary<Vector2, Guid>();
foreach (var v in ObjectsList) foreach (var v in ObjectsList)
{ {
MultiTiledComponent component =(MultiTiledComponent) v.Value.getOne(); MultiTiledComponent component =(MultiTiledComponent) v.Value.getOne();
@ -71,6 +77,8 @@ namespace Revitalize.Framework.Objects
return false; return false;
this.objects.Add(key, obj); this.objects.Add(key, obj);
this.childrenGuids.Add(key, Guid.NewGuid());
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 as MultiTiledComponent).containerObject = this; (obj as MultiTiledComponent).containerObject = this;
@ -89,13 +97,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);
@ -103,14 +111,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);
} }
@ -123,7 +131,7 @@ 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 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;
} }
@ -144,7 +152,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);
@ -156,7 +164,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;
@ -191,7 +199,12 @@ namespace Revitalize.Framework.Objects
public override Item getOne() public override Item getOne()
{ {
return new MultiTiledObject(this.info, this.TileLocation, this.objects); Dictionary<Vector2, MultiTiledComponent> objs = new Dictionary<Vector2, MultiTiledComponent>();
foreach (var pair in this.objects)
{
objs.Add(pair.Key, (MultiTiledComponent)pair.Value);
}
return new MultiTiledObject(this.info, this.TileLocation, objs);
} }
public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement) public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement)
@ -201,11 +214,26 @@ namespace Revitalize.Framework.Objects
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.Deserialize<MultiTiledObject>(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, additionalSaveData["GUID"] + ".json")); MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.Deserialize<MultiTiledObject>(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, additionalSaveData["GUID"] + ".json"));
foreach(KeyValuePair<Vector2,MultiTiledComponent> pair in this.objects) Revitalize.ModCore.log("OK I SUPPOSE");
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach(KeyValuePair<Vector2,Guid> pair in obj.childrenGuids)
{ {
pair.Value.containerObject = obj; guids.Add(pair.Key, pair.Value);
} }
foreach(KeyValuePair<Vector2,Guid> pair in guids)
{
obj.childrenGuids.Remove(pair.Key);
Revitalize.ModCore.log("DESERIALIZE: " + pair.Value.ToString());
MultiTiledComponent component= (MultiTiledComponent)Revitalize.ModCore.Serializer.Deserialize<MultiTiledComponent>(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, pair.Value + ".json"));
obj.addComponent(pair.Key, component);
}
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["GUID"])) if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["GUID"]))
{ {
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], obj); Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], obj);
@ -223,12 +251,14 @@ namespace Revitalize.Framework.Objects
{ {
Dictionary<string,string> saveData= base.getAdditionalSaveData(); Dictionary<string,string> saveData= base.getAdditionalSaveData();
saveData.Add("GUID", this.guid.ToString()); saveData.Add("GUID", this.guid.ToString());
Revitalize.ModCore.Serializer.Serialize(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, this.guid.ToString() + ".json"), this);
return saveData; return saveData;
} }
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 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))

View File

@ -277,39 +277,9 @@ namespace Revitalize
{ {
Game1.player.addItemToInventory(customObjects["Omegasis.BigTiledTest"]); Game1.player.addItemToInventory(customObjects["Omegasis.BigTiledTest"]);
var obj = customObjects["Omegasis.BigTiledTest"];
Serializer.Serialize(Path.Combine(this.Helper.DirectoryPath, (obj as MultiTiledObject).guid + ".json"), obj);
MultiTiledObject hello=Serializer.Deserialize<MultiTiledObject>(Path.Combine(this.Helper.DirectoryPath, (obj as MultiTiledObject).guid + ".json"));
//(hello as MultiTiledObject).info.drawColor = Color.Blue;
customObjects["Omegasis.BigTiledTest"].info.drawColor = hello.info.drawColor;
if (hello == null) log("WTF");
else
{
log("AHHHH" + hello.name);
}
hello.info.drawColor = Color.Blue;
if (hello.objects == null)
{
log("NEVER MIND");
}
foreach(KeyValuePair<Vector2, MultiTiledComponent> pair in hello.objects){
pair.Value.containerObject = hello;
//log((pair.Value as CustomObject).name);
}
Game1.player.items.Add(hello);
Game1.activeClickableMenu = new StardewValley.Menus.ItemGrabMenu(new List<Item>()
{
hello
});
} }