Got objects to sync across locations even when not present!

This commit is contained in:
JoshuaNavarro 2019-08-27 16:47:22 -07:00
parent e0d61f19cc
commit 19732ad2bf
8 changed files with 408 additions and 43 deletions

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;
using StardewValley; using StardewValley;
namespace Revitalize.Framework.Illuminate namespace Revitalize.Framework.Illuminate
@ -29,6 +30,9 @@ namespace Revitalize.Framework.Illuminate
/// </summary> /// </summary>
public const int lightBigNumber= 1000000; public const int lightBigNumber= 1000000;
[JsonIgnore]
public bool requiresUpdate;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
@ -55,6 +59,7 @@ namespace Revitalize.Framework.Illuminate
this.lights.Add(IdKey, light); this.lights.Add(IdKey, light);
if (this.fakeLights.ContainsKey(IdKey)) return true; if (this.fakeLights.ContainsKey(IdKey)) return true;
this.fakeLights.Add(IdKey, new FakeLightSource(light.Identifier, light.position.Value, light.color.Value.Invert(), light.radius.Value)); this.fakeLights.Add(IdKey, new FakeLightSource(light.Identifier, light.position.Value, light.color.Value.Invert(), light.radius.Value));
this.requiresUpdate = true;
return true; return true;
} }
@ -80,6 +85,7 @@ namespace Revitalize.Framework.Illuminate
this.lights.Add(IdKey, light); this.lights.Add(IdKey, light);
if (this.fakeLights.ContainsKey(IdKey)) return true; if (this.fakeLights.ContainsKey(IdKey)) return true;
this.fakeLights.Add(IdKey, new FakeLightSource(light.Identifier, light.position.Value, light.color.Value.Invert(), light.radius.Value)); this.fakeLights.Add(IdKey, new FakeLightSource(light.Identifier, light.position.Value, light.color.Value.Invert(), light.radius.Value));
this.requiresUpdate = true;
return true; return true;
} }
@ -121,6 +127,7 @@ namespace Revitalize.Framework.Illuminate
Game1.currentLightSources.Add(light); Game1.currentLightSources.Add(light);
location.sharedLights.Add((int)IdKey.X*lightBigNumber+(int)IdKey.Y,light); location.sharedLights.Add((int)IdKey.X*lightBigNumber+(int)IdKey.Y,light);
this.repositionLight(light, IdKey, gameObject); this.repositionLight(light, IdKey, gameObject);
this.requiresUpdate = true;
return true; return true;
} }
@ -161,6 +168,7 @@ namespace Revitalize.Framework.Illuminate
{ {
Vector2 initialPosition = gameObject.TileLocation * Game1.tileSize; Vector2 initialPosition = gameObject.TileLocation * Game1.tileSize;
light.position.Value = initialPosition + offset; light.position.Value = initialPosition + offset;
this.requiresUpdate = true;
} }
/// <summary> /// <summary>

View File

@ -7,40 +7,305 @@ using Revitalize.Framework.Illuminate;
using Revitalize.Framework.Utilities; using Revitalize.Framework.Utilities;
using StardewValley; using StardewValley;
using StardustCore.UIUtilities; using StardustCore.UIUtilities;
using Newtonsoft.Json;
namespace Revitalize.Framework.Objects namespace Revitalize.Framework.Objects
{ {
public class BasicItemInformation public class BasicItemInformation
{ {
public string name; private string _name;
public string id; public string name
public string description; {
public string categoryName; get
public Color categoryColor; {
public int price; return this._name;
public int edibility; }
public int fragility; set
public bool canBeSetIndoors; {
public bool canBeSetOutdoors; this._name = value;
public bool isLamp; this.requiresUpdate = true;
public string locationName; }
}
private string _id;
public string id
{
get
{
return this._id;
}
set
{
this._id = value;
this.requiresUpdate = true;
}
}
public AnimationManager animationManager; private string _description;
public Vector2 drawPosition; public string description
{
get
{
return this._description;
}
set
{
this._description = value;
this.requiresUpdate = true;
}
}
public Color drawColor; private string _categoryName;
public string categoryName
{
get
{
return this._categoryName;
}
set
{
this._categoryName = value;
this.requiresUpdate = true;
}
}
public bool ignoreBoundingBox; private Color _categoryColor;
public Color categoryColor
{
get
{
return this._categoryColor;
}
set
{
this._categoryColor = value;
this.requiresUpdate = true;
}
}
public InventoryManager inventory; private int _price;
public int price
{
get
{
return this._price;
}
set
{
this._price = value;
this.requiresUpdate = true;
}
}
public LightManager lightManager; private int _edibility;
public int edibility
{
get
{
return this._edibility;
}
set
{
this._edibility = value;
this.requiresUpdate = true;
}
}
public Enums.Direction facingDirection;
public int shakeTimer;
private int _fragility;
public int fragility
{
get
{
return this._fragility;
}
set
{
this._fragility = value;
this.requiresUpdate = true;
}
}
private bool _canBeSetIndoors;
public bool canBeSetIndoors
{
get
{
return this._canBeSetIndoors;
}
set
{
this._canBeSetIndoors = value;
this.requiresUpdate = true;
}
}
private bool _canBeSetOutdoors;
public bool canBeSetOutdoors
{
get
{
return this._canBeSetOutdoors;
}
set
{
this._canBeSetOutdoors = value;
this.requiresUpdate = true;
}
}
private bool _isLamp;
public bool isLamp
{
get
{
return this._isLamp;
}
set
{
this._isLamp = value;
this.requiresUpdate = true;
}
}
private string _locationName;
public string locationName
{
get
{
return this._locationName;
}
set
{
this._locationName = value;
this.requiresUpdate = true;
}
}
private AnimationManager _animationManager;
public AnimationManager animationManager
{
get
{
return this._animationManager;
}
set
{
this._animationManager = value;
this.requiresUpdate = true;
}
}
private Vector2 _drawPosition;
public Vector2 drawPosition
{
get
{
return this._drawPosition;
}
set
{
this._drawPosition = value;
this.requiresUpdate = true;
}
}
private Color _drawColor;
public Color drawColor
{
get
{
return this._drawColor;
}
set
{
this._drawColor = value;
this.requiresUpdate = true;
}
}
private bool _ignoreBoundingBox;
public bool ignoreBoundingBox
{
get
{
return this._ignoreBoundingBox;
}
set
{
this._ignoreBoundingBox = value;
this.requiresUpdate = true;
}
}
private InventoryManager _inventory;
public InventoryManager inventory
{
get
{
return this._inventory;
}
set
{
this._inventory = value;
this.requiresUpdate = true;
}
}
private LightManager _lightManager;
public LightManager lightManager
{
get
{
return this._lightManager;
}
set
{
this._lightManager = value;
this.requiresUpdate = true;
}
}
private Enums.Direction _facingDirection;
public Enums.Direction facingDirection
{
get
{
return this._facingDirection;
}
set
{
this._facingDirection = value;
this.requiresUpdate = true;
}
}
private int _shakeTimer;
public int shakeTimer
{
get
{
return this._shakeTimer;
}
set
{
this._shakeTimer = value;
this.requiresUpdate = true;
}
}
[JsonIgnore]
public bool requiresUpdate;
public BasicItemInformation() public BasicItemInformation()
{ {
this.name = ""; this.name = "";
@ -61,7 +326,6 @@ namespace Revitalize.Framework.Objects
this.facingDirection = Enums.Direction.Down; this.facingDirection = Enums.Direction.Down;
this.id = ""; this.id = "";
this.shakeTimer = 0; this.shakeTimer = 0;
} }
public BasicItemInformation(string name, string id, string description, string categoryName, Color categoryColor,int edibility, int fragility, bool isLamp, int price, bool canBeSetOutdoors, bool canBeSetIndoors, Texture2D texture, AnimationManager animationManager, Color drawColor, bool ignoreBoundingBox, InventoryManager Inventory, LightManager Lights) public BasicItemInformation(string name, string id, string description, string categoryName, Color categoryColor,int edibility, int fragility, bool isLamp, int price, bool canBeSetOutdoors, bool canBeSetIndoors, Texture2D texture, AnimationManager animationManager, Color drawColor, bool ignoreBoundingBox, InventoryManager Inventory, LightManager Lights)
@ -116,7 +380,35 @@ namespace Revitalize.Framework.Objects
public bool requiresSyncUpdate() public bool requiresSyncUpdate()
{ {
return true; return this.requiresUpdate || this.animationManagerRequiresUpdate() || this.inventoryManagerRequiresUpdate() || this.lightManagerRequiresUpdate();
}
public void forceUpdate()
{
this.requiresUpdate = true;
}
private bool animationManagerRequiresUpdate()
{
if (this._animationManager == null) return false;
else return this._animationManager.requiresUpdate;
}
private bool inventoryManagerRequiresUpdate()
{
if (this._inventory == null) return false;
else return this._inventory.requiresUpdate;
}
private bool lightManagerRequiresUpdate()
{
if (this._lightManager == null) return false;
else return this._lightManager.requiresUpdate;
}
public void cleanAfterUpdate()
{
this.requiresUpdate = false;
this._inventory.requiresUpdate = false;
this._animationManager.requiresUpdate = false;
this._lightManager.requiresUpdate = false;
} }
} }

View File

@ -629,8 +629,38 @@ namespace Revitalize.Framework.Objects
return; return;
} }
if (this.requiresUpdate())
{
this.ItemInfo = this.text;
this.text = this.ItemInfo;
this.info.cleanAfterUpdate();
}
}
public virtual void forceUpdate()
{
if (this.info == null)
{
this.ItemInfo = this.text;
ModCore.log("Updated item info!");
return;
}
this.ItemInfo = this.text; this.ItemInfo = this.text;
this.text = this.ItemInfo; this.text = this.ItemInfo;
this.info.cleanAfterUpdate();
this.info.forceUpdate();
}
public virtual bool requiresUpdate()
{
if (this.info.requiresSyncUpdate())
{
return true;
}
else
{
return false;
}
} }
//~~~~~~~~~~~~~~~~~~~~~~~~~// //~~~~~~~~~~~~~~~~~~~~~~~~~//

View File

@ -271,6 +271,8 @@ namespace Revitalize.Framework.Objects
{ {
Revitalize.ModCore.Serializer.SerializeGUID(this.containerObject.childrenGuids[this.offsetKey].ToString(), this); Revitalize.ModCore.Serializer.SerializeGUID(this.containerObject.childrenGuids[this.offsetKey].ToString(), this);
} }
this.containerObject.getAdditionalSaveData(); this.containerObject.getAdditionalSaveData();
return saveData; return saveData;
@ -360,11 +362,23 @@ namespace Revitalize.Framework.Objects
public override void updateInfo() public override void updateInfo()
{ {
if (this.containerObject != null) if (this.info == null || this.containerObject==null)
{ {
this.containerObject.updateInfo(); this.ItemInfo = this.text;
ModCore.log("Updated item info!");
return;
} }
base.updateInfo();
if (this.requiresUpdate())
{
this.ItemInfo = this.text;
this.text = this.ItemInfo;
this.info.cleanAfterUpdate();
}
}
public override bool requiresUpdate()
{
return base.requiresUpdate();
} }
} }
} }

View File

@ -425,19 +425,12 @@ namespace Revitalize.Framework.Objects
return; return;
} }
this.ItemInfo = this.text; if (this.requiresUpdate())
this.text = this.ItemInfo;
if (this.objects == null)
{ {
return; this.ItemInfo = this.text;
this.text = this.ItemInfo;
this.info.cleanAfterUpdate();
} }
/*
foreach(CustomObject c in this.objects.Values)
{
c.updateInfo();
}
*/
} }
} }

View File

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Newtonsoft.Json;
using StardewValley; using StardewValley;
namespace Revitalize.Framework.Utilities namespace Revitalize.Framework.Utilities
@ -25,6 +26,8 @@ namespace Revitalize.Framework.Utilities
/// <summary>Checks to see if this core object actually has a valid inventory.</summary> /// <summary>Checks to see if this core object actually has a valid inventory.</summary>
public bool HasInventory => this.capacity > 0; public bool HasInventory => this.capacity > 0;
[JsonIgnore]
public bool requiresUpdate;
public InventoryManager() public InventoryManager()
{ {
this.capacity = 0; this.capacity = 0;
@ -77,9 +80,11 @@ namespace Revitalize.Framework.Utilities
if (self != null && self.canStackWith(item)) if (self != null && self.canStackWith(item))
{ {
self.addToStack(item.Stack); self.addToStack(item.Stack);
this.requiresUpdate = true;
return true; return true;
} }
} }
this.requiresUpdate = true;
this.items.Add(item); this.items.Add(item);
return true; return true;
} }
@ -108,6 +113,7 @@ namespace Revitalize.Framework.Utilities
if (item.Stack == 1) if (item.Stack == 1)
return item; return item;
this.requiresUpdate = true;
item.Stack = item.Stack - 1; item.Stack = item.Stack - 1;
return item.getOne(); return item.getOne();
} }
@ -115,6 +121,7 @@ namespace Revitalize.Framework.Utilities
/// <summary>Empty the inventory.</summary> /// <summary>Empty the inventory.</summary>
public void clear() public void clear()
{ {
this.requiresUpdate = true;
this.items.Clear(); this.items.Clear();
} }
@ -128,13 +135,17 @@ namespace Revitalize.Framework.Utilities
public void resizeCapacity(int Amount) public void resizeCapacity(int Amount)
{ {
if (this.capacity + Amount < this.MaxCapacity) if (this.capacity + Amount < this.MaxCapacity)
{
this.capacity += Amount; this.capacity += Amount;
this.requiresUpdate = true;
}
} }
/// <summary>Sets the upper limity of the capacity size for the inventory.</summary> /// <summary>Sets the upper limity of the capacity size for the inventory.</summary>
public void setMaxLimit(int amount) public void setMaxLimit(int amount)
{ {
this.MaxCapacity = amount; this.MaxCapacity = amount;
this.requiresUpdate = true;
} }
/// <summary> /// <summary>

View File

@ -28,14 +28,16 @@ namespace Revitalize.Framework.Utilities
{ {
ModCore.log("Receieve GUID Request"); ModCore.log("Receieve GUID Request");
string objStr = e.ReadAs <string>(); string objStr = e.ReadAs <string>();
var v=ModCore.Serializer.DeserializeFromJSONString<Item>(objStr); CustomObject v=(CustomObject)ModCore.Serializer.DeserializeFromJSONString<Item>(objStr);
if (ModCore.CustomObjects.ContainsKey((v as CustomObject).guid) == false) if (ModCore.CustomObjects.ContainsKey((v as CustomObject).guid) == false)
{ {
ModCore.CustomObjects.Add((v as CustomObject).guid, (v as CustomObject)); ModCore.CustomObjects.Add((v as CustomObject).guid, v);
//v.forceUpdate();
} }
else else
{ {
ModCore.CustomObjects[(v as CustomObject).guid] = (v as CustomObject); ModCore.CustomObjects[(v as CustomObject).guid] = v;
//v.forceUpdate();
} }
} }
@ -49,14 +51,16 @@ namespace Revitalize.Framework.Utilities
{ {
ModCore.log("Receieve GUID Request FOR TILE"); ModCore.log("Receieve GUID Request FOR TILE");
string objStr = e.ReadAs<string>(); string objStr = e.ReadAs<string>();
var v = ModCore.Serializer.DeserializeFromJSONString<Item>(objStr); CustomObject v =(CustomObject)ModCore.Serializer.DeserializeFromJSONString<Item>(objStr);
if (ModCore.CustomObjects.ContainsKey((v as CustomObject).guid) == false) if (ModCore.CustomObjects.ContainsKey((v as CustomObject).guid) == false)
{ {
ModCore.CustomObjects.Add((v as CustomObject).guid, (v as CustomObject)); ModCore.CustomObjects.Add((v as CustomObject).guid, v);
//v.forceUpdate();
} }
else else
{ {
ModCore.CustomObjects[(v as CustomObject).guid] = (v as CustomObject); ModCore.CustomObjects[(v as CustomObject).guid] = v;
//v.forceUpdate();
} }
} }
} }
@ -66,6 +70,7 @@ namespace Revitalize.Framework.Utilities
if (ModCore.CustomObjects.ContainsKey(request)) if (ModCore.CustomObjects.ContainsKey(request))
{ {
ModCore.log("Send guid request!"); ModCore.log("Send guid request!");
//ModCore.CustomObjects[request].forceUpdate();
ModCore.ModHelper.Multiplayer.SendMessage<string>(ModCore.Serializer.ToJSONString(ModCore.CustomObjects[request]), ReceieveGUIDMessage, new string[] { Revitalize.ModCore.Manifest.UniqueID.ToString() }); ModCore.ModHelper.Multiplayer.SendMessage<string>(ModCore.Serializer.ToJSONString(ModCore.CustomObjects[request]), ReceieveGUIDMessage, new string[] { Revitalize.ModCore.Manifest.UniqueID.ToString() });
} }
else else
@ -79,6 +84,8 @@ namespace Revitalize.Framework.Utilities
if (ModCore.CustomObjects.ContainsKey(request)) if (ModCore.CustomObjects.ContainsKey(request))
{ {
ModCore.log("Send guid tile request!"); ModCore.log("Send guid tile request!");
//(ModCore.CustomObjects[request] as MultiTiledComponent).forceUpdate();
//(ModCore.CustomObjects[request] as MultiTiledComponent).containerObject.forceUpdate();
ModCore.ModHelper.Multiplayer.SendMessage<string>(ModCore.Serializer.ToJSONString( (ModCore.CustomObjects[request] as MultiTiledComponent).containerObject), ReceieveGUIDMessage_Tile , new string[] { Revitalize.ModCore.Manifest.UniqueID.ToString() }); ModCore.ModHelper.Multiplayer.SendMessage<string>(ModCore.Serializer.ToJSONString( (ModCore.CustomObjects[request] as MultiTiledComponent).containerObject), ReceieveGUIDMessage_Tile , new string[] { Revitalize.ModCore.Manifest.UniqueID.ToString() });
} }
else else

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;
using StardewValley; using StardewValley;
using StardustCore.UIUtilities; using StardustCore.UIUtilities;
@ -22,6 +23,8 @@ namespace StardustCore.Animations
public string animationDataString; public string animationDataString;
[JsonIgnore]
public bool requiresUpdate;
public bool IsNull => this.defaultDrawFrame == null && this.objectTexture == null; public bool IsNull => this.defaultDrawFrame == null && this.objectTexture == null;
/// <summary> /// <summary>
@ -99,6 +102,7 @@ namespace StardustCore.Animations
if (this.currentAnimation.frameCountUntilNextAnimation == 0) if (this.currentAnimation.frameCountUntilNextAnimation == 0)
this.getNextAnimation(); this.getNextAnimation();
this.currentAnimation.tickAnimationFrame(); this.currentAnimation.tickAnimationFrame();
this.requiresUpdate = true;
} }
catch (Exception err) catch (Exception err)
{ {
@ -108,7 +112,7 @@ namespace StardustCore.Animations
} }
/// <summary>Get the next animation frame in the list of animations.</summary> /// <summary>Get the next animation frame in the list of animations.</summary>
public void getNextAnimation() private void getNextAnimation()
{ {
this.currentAnimationListIndex++; this.currentAnimationListIndex++;
if (this.currentAnimationListIndex == this.currentAnimationList.Count) //If the animation frame I'm tryting to get is 1 outside my list length, reset the list. if (this.currentAnimationListIndex == this.currentAnimationList.Count) //If the animation frame I'm tryting to get is 1 outside my list length, reset the list.
@ -118,6 +122,7 @@ namespace StardustCore.Animations
} }
else else
{ {
this.requiresUpdate = true;
this.playDefaultAnimation(); this.playDefaultAnimation();
return; return;
} }
@ -125,6 +130,7 @@ namespace StardustCore.Animations
//Get the next animation from the list and reset it's counter to the starting frame value. //Get the next animation from the list and reset it's counter to the starting frame value.
this.currentAnimation = this.currentAnimationList[this.currentAnimationListIndex]; this.currentAnimation = this.currentAnimationList[this.currentAnimationListIndex];
this.currentAnimation.startAnimation(); this.currentAnimation.startAnimation();
this.requiresUpdate = true;
} }
/// <summary>Gets the animation from the dictionary of all animations available.</summary> /// <summary>Gets the animation from the dictionary of all animations available.</summary>
@ -139,6 +145,7 @@ namespace StardustCore.Animations
this.currentAnimationList = dummyList; this.currentAnimationList = dummyList;
this.currentAnimation = this.currentAnimationList[StartingFrame]; this.currentAnimation = this.currentAnimationList[StartingFrame];
this.currentAnimationName = AnimationName; this.currentAnimationName = AnimationName;
this.requiresUpdate = true;
return true; return true;
} }
else else
@ -179,6 +186,7 @@ namespace StardustCore.Animations
this.currentAnimationName = AnimationName; this.currentAnimationName = AnimationName;
this.currentAnimation.startAnimation(); this.currentAnimation.startAnimation();
this.loopAnimation = true; this.loopAnimation = true;
this.requiresUpdate = true;
return true; return true;
} }
else else
@ -219,6 +227,7 @@ namespace StardustCore.Animations
this.currentAnimationName = AnimationName; this.currentAnimationName = AnimationName;
this.currentAnimation.startAnimation(); this.currentAnimation.startAnimation();
this.loopAnimation = false; this.loopAnimation = false;
this.requiresUpdate = true;
return true; return true;
} }
else else
@ -245,6 +254,7 @@ namespace StardustCore.Animations
this.currentAnimation = this.defaultDrawFrame; this.currentAnimation = this.defaultDrawFrame;
this.currentAnimationName = ""; this.currentAnimationName = "";
this.currentAnimationListIndex = 0; this.currentAnimationListIndex = 0;
this.requiresUpdate = true;
} }
/// <summary>Sets the animation manager to an on state, meaning that this animation will update on the draw frame.</summary> /// <summary>Sets the animation manager to an on state, meaning that this animation will update on the draw frame.</summary>