Experimenting with benches and updated serializer to serialize to strings.
This commit is contained in:
parent
d2173bb24b
commit
3931ba81b8
|
@ -0,0 +1,110 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using PyTK.CustomElementHandler;
|
||||||
|
using StardewValley;
|
||||||
|
|
||||||
|
namespace Revitalize.Framework.Objects.Furniture
|
||||||
|
{
|
||||||
|
public class Bench:ChairMultiTiledObject
|
||||||
|
{
|
||||||
|
public Bench() : base()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<long> playersSittingHere = new List<long>();
|
||||||
|
|
||||||
|
public Bench(BasicItemInformation info, Vector2 TilePosition) : base(info, TilePosition)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Bench(BasicItemInformation info,Vector2 TilePosition, Dictionary<Vector2,MultiTiledComponent> Objects): base(info, TilePosition, Objects)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rotate all chair components associated with this chair object.
|
||||||
|
/// </summary>
|
||||||
|
public override void rotate()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (Revitalize.ModCore.playerInfo.sittingInfo.SittingObject == this) return;
|
||||||
|
if (this.playersSittingHere.Count > 0)
|
||||||
|
{
|
||||||
|
Game1.showRedMessage("Can't rotate furniture when people are siting on it.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
|
{
|
||||||
|
(pair.Value as ChairTileComponent).rotate();
|
||||||
|
}
|
||||||
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
|
{
|
||||||
|
(pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation();
|
||||||
|
}
|
||||||
|
|
||||||
|
base.rotate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Item getOne()
|
||||||
|
{
|
||||||
|
Dictionary<Vector2, MultiTiledComponent> objs = new Dictionary<Vector2, MultiTiledComponent>();
|
||||||
|
foreach (var pair in this.objects)
|
||||||
|
{
|
||||||
|
objs.Add(pair.Key, (MultiTiledComponent)pair.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Bench(this.info, this.TileLocation, objs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement)
|
||||||
|
{
|
||||||
|
Bench obj = (Bench)Revitalize.ModCore.Serializer.DeserializeGUID<Bench>(additionalSaveData["GUID"]);
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
|
||||||
|
|
||||||
|
foreach (KeyValuePair<Vector2, Guid> pair in obj.childrenGuids)
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
ChairTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<ChairTileComponent>(pair.Value.ToString());
|
||||||
|
component.InitNetFields();
|
||||||
|
|
||||||
|
obj.addComponent(pair.Key, component);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
obj.InitNetFields();
|
||||||
|
|
||||||
|
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["GUID"]))
|
||||||
|
{
|
||||||
|
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], obj);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -71,6 +71,10 @@ 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);
|
||||||
|
if(this.containerObject is Bench)
|
||||||
|
{
|
||||||
|
(this.containerObject as Bench).playersSittingHere.Add(Game1.player.uniqueMultiplayerID);
|
||||||
|
}
|
||||||
foreach(KeyValuePair<Vector2, StardewValley.Object> 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();
|
||||||
|
|
|
@ -218,6 +218,10 @@ namespace Revitalize.Framework.Objects
|
||||||
addedDepth += (this.containerObject.Height - 1) - ((int)(this.offsetKey.Y));
|
addedDepth += (this.containerObject.Height - 1) - ((int)(this.offsetKey.Y));
|
||||||
if (this.info.ignoreBoundingBox) addedDepth+=1.5f;
|
if (this.info.ignoreBoundingBox) addedDepth+=1.5f;
|
||||||
}
|
}
|
||||||
|
else if (this.info.ignoreBoundingBox)
|
||||||
|
{
|
||||||
|
addedDepth += 1.0f;
|
||||||
|
}
|
||||||
this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), 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 + addedDepth) * Game1.tileSize) / 10000f));
|
this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), 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 + addedDepth) * Game1.tileSize) / 10000f));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,7 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -88,6 +89,8 @@ namespace Revitalize.Framework.Objects
|
||||||
|
|
||||||
public bool removeComponent(Vector2 key)
|
public bool removeComponent(Vector2 key)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (!this.objects.ContainsKey(key))
|
if (!this.objects.ContainsKey(key))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -123,7 +126,33 @@ namespace Revitalize.Framework.Objects
|
||||||
//base.drawWhenHeld(spriteBatch, objectPosition, f);
|
//base.drawWhenHeld(spriteBatch, objectPosition, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
//IMPLEMENT THESE!
|
|
||||||
|
public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location)
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<Vector2, StardewValley.Object> pair in this.objects)
|
||||||
|
{
|
||||||
|
if (!this.isPlaceable())
|
||||||
|
return;
|
||||||
|
int x = Game1.getOldMouseX() + Game1.viewport.X+ (int)((pair.Value as MultiTiledComponent).offsetKey.X*Game1.tileSize);
|
||||||
|
int y = Game1.getOldMouseY() + Game1.viewport.Y+ (int)((pair.Value as MultiTiledComponent).offsetKey.Y * Game1.tileSize);
|
||||||
|
if ((double)Game1.mouseCursorTransparency == 0.0)
|
||||||
|
{
|
||||||
|
x = ((int)Game1.player.GetGrabTile().X+ (int)((pair.Value as MultiTiledComponent).offsetKey.X)) * 64;
|
||||||
|
y = ((int)Game1.player.GetGrabTile().Y + (int)((pair.Value as MultiTiledComponent).offsetKey.Y)) * 64;
|
||||||
|
}
|
||||||
|
if (Game1.player.GetGrabTile().Equals(Game1.player.getTileLocation()) && (double)Game1.mouseCursorTransparency == 0.0)
|
||||||
|
{
|
||||||
|
Vector2 translatedVector2 = Utility.getTranslatedVector2(Game1.player.GetGrabTile(), Game1.player.FacingDirection, 1f);
|
||||||
|
translatedVector2 += (pair.Value as MultiTiledComponent).offsetKey;
|
||||||
|
x = (int)translatedVector2.X * 64;
|
||||||
|
y = (int)translatedVector2.Y * 64;
|
||||||
|
}
|
||||||
|
bool flag = Utility.playerCanPlaceItemHere(location, (Item)pair.Value, x, y, Game1.player);
|
||||||
|
spriteBatch.Draw(Game1.mouseCursors, new Vector2((float)(x / 64 * 64 - Game1.viewport.X), (float)(y / 64 * 64 - Game1.viewport.Y)), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(flag ? 194 : 210, 388, 16, 16)), Color.White, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, 0.01f);
|
||||||
|
this.draw(spriteBatch, x / 64, y / 64, 0.5f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public virtual void pickUp()
|
public virtual void pickUp()
|
||||||
|
@ -270,6 +299,7 @@ namespace Revitalize.Framework.Objects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool canStackWith(Item other)
|
public override bool canStackWith(Item other)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Revitalize.Framework.Objects;
|
using Revitalize.Framework.Objects;
|
||||||
|
using Revitalize.Framework.Objects.Furniture;
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
|
|
||||||
namespace Revitalize.Framework.Player.Managers
|
namespace Revitalize.Framework.Player.Managers
|
||||||
|
@ -50,12 +51,22 @@ namespace Revitalize.Framework.Player.Managers
|
||||||
{
|
{
|
||||||
this.isSitting = false;
|
this.isSitting = false;
|
||||||
this.elapsedTime = 0;
|
this.elapsedTime = 0;
|
||||||
if(this.sittingObject is MultiTiledObject)
|
if(this.sittingObject is MultiTiledObject && (this.sittingObject.GetType()!=typeof(Bench)))
|
||||||
|
{
|
||||||
|
(this.sittingObject as MultiTiledObject).setAllAnimationsToDefault();
|
||||||
|
this.sittingObject = null;
|
||||||
|
}
|
||||||
|
else if(this.sittingObject is Bench)
|
||||||
|
{
|
||||||
|
(this.sittingObject as Bench).playersSittingHere.Remove(Game1.player.uniqueMultiplayerID);
|
||||||
|
if((this.sittingObject as Bench).playersSittingHere.Count == 0)
|
||||||
{
|
{
|
||||||
(this.sittingObject as MultiTiledObject).setAllAnimationsToDefault();
|
(this.sittingObject as MultiTiledObject).setAllAnimationsToDefault();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.sittingObject = null;
|
this.sittingObject = null;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (this.isSitting && Game1.player.CanMove)
|
if (this.isSitting && Game1.player.CanMove)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace Revitalize.Framework.Utilities
|
||||||
|
|
||||||
public List<Item> itemsToRemove = new List<Item>();
|
public List<Item> itemsToRemove = new List<Item>();
|
||||||
|
|
||||||
|
private JsonSerializerSettings settings;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
|
@ -48,6 +49,15 @@ namespace Revitalize.Framework.Utilities
|
||||||
|
|
||||||
gatherAllFilesForCleanup();
|
gatherAllFilesForCleanup();
|
||||||
|
|
||||||
|
this.settings = new JsonSerializerSettings();
|
||||||
|
foreach(JsonConverter converter in this.serializer.Converters)
|
||||||
|
{
|
||||||
|
this.settings.Converters.Add(converter);
|
||||||
|
}
|
||||||
|
this.settings.Formatting = Formatting.Indented;
|
||||||
|
this.settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||||
|
this.settings.NullValueHandling = NullValueHandling.Include;
|
||||||
|
this.settings.ContractResolver = new NetFieldContract();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -257,7 +267,37 @@ namespace Revitalize.Framework.Utilities
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts objects to json form.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="o"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string ToJSONString(object o)
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(o, this.settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts from json form to objects.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="info"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T DeserializeFromJSONString<T>(string info)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<T>(info,this.settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts from json form to objects.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info"></param>
|
||||||
|
/// <param name="T"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public object DeserializeFromJSONString(string info, Type T)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject(info, T, this.settings);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
<Compile Include="Framework\Illuminate\LightManager.cs" />
|
<Compile Include="Framework\Illuminate\LightManager.cs" />
|
||||||
<Compile Include="Framework\Objects\BasicItemInformation.cs" />
|
<Compile Include="Framework\Objects\BasicItemInformation.cs" />
|
||||||
<Compile Include="Framework\Objects\CustomObject.cs" />
|
<Compile Include="Framework\Objects\CustomObject.cs" />
|
||||||
|
<Compile Include="Framework\Objects\Furniture\Bench.cs" />
|
||||||
<Compile Include="Framework\Objects\Furniture\ChairMultiTiledObject.cs" />
|
<Compile Include="Framework\Objects\Furniture\ChairMultiTiledObject.cs" />
|
||||||
<Compile Include="Framework\Objects\Furniture\ChairTileComponent.cs" />
|
<Compile Include="Framework\Objects\Furniture\ChairTileComponent.cs" />
|
||||||
<Compile Include="Framework\Objects\Furniture\CustomFurniture.cs" />
|
<Compile Include="Framework\Objects\Furniture\CustomFurniture.cs" />
|
||||||
|
|
Loading…
Reference in New Issue