162 lines
7.5 KiB
C#
162 lines
7.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Newtonsoft.Json;
|
|
using PyTK.CustomElementHandler;
|
|
using Revitalize.Framework.Objects.InformationFiles;
|
|
using Revitalize.Framework.Utilities;
|
|
using StardewValley;
|
|
|
|
namespace Revitalize.Framework.Objects.Machines
|
|
{
|
|
public class Wire: Machine
|
|
{
|
|
|
|
public Wire() { }
|
|
|
|
public Wire(CustomObjectData PyTKData, BasicItemInformation info) : base(PyTKData, info,null,0,0,true,"")
|
|
{
|
|
}
|
|
|
|
public Wire(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, MultiTiledObject obj = null) : base(PyTKData, info, TileLocation,null,0,0,true,"",obj)
|
|
{
|
|
}
|
|
|
|
public Wire(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, Vector2 offsetKey, MultiTiledObject obj = null) : base(PyTKData, info, TileLocation,offsetKey,null,0,0,true,"",obj)
|
|
{
|
|
}
|
|
|
|
|
|
public override bool minutesElapsed(int minutes, GameLocation environment)
|
|
{
|
|
this.updateInfo();
|
|
return false;
|
|
}
|
|
|
|
public override bool rightClicked(Farmer who)
|
|
{
|
|
if (this.location == null)
|
|
this.location = Game1.player.currentLocation;
|
|
if (Game1.menuUp || Game1.currentMinigame != null) return false;
|
|
|
|
//ModCore.playerInfo.sittingInfo.sit(this, Vector2.Zero);
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates the necessary components to display the machine menu properly.
|
|
/// </summary>
|
|
|
|
public override Item getOne()
|
|
{
|
|
Wire component = new Wire(this.data, this.info.Copy(), this.TileLocation, this.offsetKey,this.containerObject);
|
|
return component;
|
|
}
|
|
|
|
public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement)
|
|
{
|
|
//instead of using this.offsetkey.x use get additional save data function and store offset key there
|
|
|
|
Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"]));
|
|
Wire self = Revitalize.ModCore.Serializer.DeserializeGUID<Wire>(additionalSaveData["GUID"]);
|
|
if (self == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"]))
|
|
{
|
|
//Get new container
|
|
WireMultiTiledObject obj = (WireMultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<WireMultiTiledObject>(additionalSaveData["ParentGUID"]);
|
|
self.containerObject = obj;
|
|
obj.addComponent(offsetKey, self);
|
|
//Revitalize.ModCore.log("ADD IN AN OBJECT!!!!");
|
|
Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], (WireMultiTiledObject)obj);
|
|
}
|
|
else
|
|
{
|
|
self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["ParentGUID"]];
|
|
Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]].addComponent(offsetKey, self);
|
|
//Revitalize.ModCore.log("READD AN OBJECT!!!!");
|
|
}
|
|
|
|
return (ICustomObject)self;
|
|
}
|
|
|
|
public override void rebuild(Dictionary<string, string> additionalSaveData, object replacement)
|
|
{
|
|
base.rebuild(additionalSaveData, replacement);
|
|
}
|
|
|
|
public override Dictionary<string, string> getAdditionalSaveData()
|
|
{
|
|
Dictionary<string, string> saveData = base.getAdditionalSaveData();
|
|
Revitalize.ModCore.Serializer.SerializeGUID(this.containerObject.childrenGuids[this.offsetKey].ToString(), this);
|
|
this.containerObject.getAdditionalSaveData();
|
|
return saveData;
|
|
|
|
}
|
|
|
|
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
|
|
{
|
|
this.updateInfo();
|
|
|
|
if (this.info == null)
|
|
{
|
|
Revitalize.ModCore.log("info is null");
|
|
if (this.syncObject == null) Revitalize.ModCore.log("DEAD SYNC");
|
|
}
|
|
if (this.animationManager == null) Revitalize.ModCore.log("Animation Manager Null");
|
|
if (this.displayTexture == null) Revitalize.ModCore.log("Display texture is null");
|
|
|
|
//The actual planter box being drawn.
|
|
if (this.animationManager == null)
|
|
{
|
|
if (this.animationManager.getExtendedTexture() == null)
|
|
ModCore.ModMonitor.Log("Tex Extended is null???");
|
|
|
|
spriteBatch.Draw(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)(y * Game1.tileSize) / 10000f));
|
|
// Log.AsyncG("ANIMATION IS NULL?!?!?!?!");
|
|
}
|
|
|
|
else
|
|
{
|
|
//Log.AsyncC("Animation Manager is working!");
|
|
float addedDepth = 0;
|
|
|
|
|
|
if (Revitalize.ModCore.playerInfo.sittingInfo.SittingObject == this.containerObject && this.info.facingDirection == Enums.Direction.Up)
|
|
{
|
|
addedDepth += (this.containerObject.Height - 1) - ((int)(this.offsetKey.Y));
|
|
if (this.info.ignoreBoundingBox) addedDepth += 1.5f;
|
|
}
|
|
//this.determineWireOrientation();
|
|
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)((y + addedDepth) * Game1.tileSize) / 10000f) + .00001f);
|
|
try
|
|
{
|
|
this.animationManager.tickAnimation();
|
|
// Log.AsyncC("Tick animation");
|
|
}
|
|
catch (Exception err)
|
|
{
|
|
ModCore.ModMonitor.Log(err.ToString());
|
|
}
|
|
}
|
|
|
|
// spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)((double)tileLocation.X * (double)Game1.tileSize + (((double)tileLocation.X * 11.0 + (double)tileLocation.Y * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2), (float)((double)tileLocation.Y * (double)Game1.tileSize + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2))), new Rectangle?(new Rectangle((int)((double)tileLocation.X * 51.0 + (double)tileLocation.Y * 77.0) % 3 * 16, 128 + this.whichForageCrop * 16, 16, 16)), Color.White, 0.0f, new Vector2(8f, 8f), (float)Game1.pixelZoom, SpriteEffects.None, (float)(((double)tileLocation.Y * (double)Game1.tileSize + (double)(Game1.tileSize / 2) + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) / 10000.0));
|
|
|
|
}
|
|
|
|
private void determineWireOrientation()
|
|
{
|
|
//TODO: Make this so that the correct wire orientation is used if I want to get fancy with wires and their graphics.
|
|
}
|
|
|
|
|
|
}
|
|
}
|