Added some documentation, made it so BasicItemInformation, LightManager, and InventoryManager make copies of themselves per new item fixing a duplication glitch. Updated all objects to use the new copy function for BasicItemInformation.

This commit is contained in:
JoshuaNavarro 2019-08-16 15:32:14 -07:00
parent 0cbae77d28
commit ff9aa226f7
25 changed files with 169 additions and 59 deletions

View File

@ -97,7 +97,7 @@ namespace Revitalize.Framework.Factories.Objects
LampTileComponent lampMiddle = new LampTileComponent(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Lamps.OakLamp", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), typeof(LampTileComponent), Color.White), new BasicItemInformation("Oak Lamp", "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "A basic wooden light.", "Lamps", Color.Brown, -300, 0, true, 100, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new Animation(new Rectangle(0, 16, 16, 16))), Color.White, true, new InventoryManager(), new LightManager()));
LampTileComponent lampBottom = new LampTileComponent(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Lamps.OakLamp", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), typeof(LampTileComponent), Color.White), new BasicItemInformation("Oak Lamp", "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "A basic wooden light.", "Lamps", Color.Brown, -300, 0, true, 100 , true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new Animation(new Rectangle(0, 32, 16, 16))), Color.White, false, new InventoryManager(), new LightManager()));
lampMiddle.lights.addLight(new Vector2(Game1.tileSize), new LightSource(4, new Vector2(0, 0), 2.5f, Color.Orange.Invert()), lampMiddle);
lampMiddle.lightManager.addLight(new Vector2(Game1.tileSize), new LightSource(4, new Vector2(0, 0), 2.5f, Color.Orange.Invert()), lampMiddle);
LampMultiTiledObject lamp = new LampMultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Lamps.OakLamp", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), typeof(LampMultiTiledObject), Color.White), new BasicItemInformation("Oak Lamp", "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "A basic wooden light", "Lamps", Color.Brown, -300, 0, true, 300, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "Oak Lamp"), new AnimationManager(), Color.White, false, new InventoryManager(), new LightManager()));
@ -157,13 +157,13 @@ namespace Revitalize.Framework.Factories.Objects
LampTileComponent lampPiece = new LampTileComponent(info.PyTkData,info.info);
//Recreate the lights info.
if (lampPiece.lights != null)
if (lampPiece.lightManager != null)
{
//ModCore.log("Info for file"+Path.GetFileNameWithoutExtension(file)+" has this many lights: " + info.info.lightManager.fakeLights.Count);
lampPiece.lights.lights.Clear();
lampPiece.lightManager.lights.Clear();
foreach (KeyValuePair<Vector2, FakeLightSource> light in info.info.lightManager.fakeLights)
{
lampPiece.lights.addLight(new Vector2(Game1.tileSize), new LightSource(light.Value.id, new Vector2(0, 0), light.Value.radius, light.Value.color.Invert()), lampPiece);
lampPiece.lightManager.addLight(new Vector2(Game1.tileSize), new LightSource(light.Value.id, new Vector2(0, 0), light.Value.radius, light.Value.color.Invert()), lampPiece);
}
}

View File

@ -7,19 +7,43 @@ using Microsoft.Xna.Framework;
namespace Revitalize.Framework.Illuminate
{
/// <summary>
/// Deals with recreating light sources in SDV.
/// </summary>
public class FakeLightSource
{
/// <summary>
/// The id for the light. Refers to the type of texture used.
/// </summary>
public int id;
/// <summary>
/// The position offset from the source object this is attached to.
/// </summary>
public Vector2 positionOffset;
/// <summary>
/// The color for the light.
/// </summary>
public Color color;
/// <summary>
/// The radius for the light.
/// </summary>
public float radius;
/// <summary>
/// Empty constructor.
/// </summary>
public FakeLightSource()
{
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="ID">The id for the light source.</param>
/// <param name="Position">The position for the light source.</param>
/// <param name="Color">The color for the light.</param>
/// <param name="Raidus">The radius for the light.</param>
public FakeLightSource(int ID, Vector2 Position, Color Color, float Raidus)
{
this.id = ID;
@ -28,5 +52,14 @@ namespace Revitalize.Framework.Illuminate
this.radius = Raidus;
}
/// <summary>
/// Gets a copy of the fake light source.
/// </summary>
/// <returns></returns>
public FakeLightSource Copy()
{
return new FakeLightSource(this.id, new Vector2(this.positionOffset.X, this.positionOffset.Y), new Color(this.color.R, this.color.G, this.color.B, this.color.A), this.radius);
}
}
}

View File

@ -6,14 +6,32 @@ using StardewValley;
namespace Revitalize.Framework.Illuminate
{
/// <summary>
/// Deals with handling lights on custom objects.
/// </summary>
public class LightManager
{
/// <summary>
/// The lights held by this object.
/// </summary>
public Dictionary<Vector2, LightSource> lights;
/// <summary>
/// Used to recreate lights at run time.
/// </summary>
public Dictionary<Vector2, FakeLightSource> fakeLights;
/// <summary>
/// Are the lights on this object on?
/// </summary>
public bool lightsOn;
/// <summary>
/// Magic number for positioning.
/// </summary>
public const int lightBigNumber= 1000000;
/// <summary>
/// Constructor.
/// </summary>
public LightManager()
{
this.lights = new Dictionary<Vector2, LightSource>();
@ -40,6 +58,31 @@ namespace Revitalize.Framework.Illuminate
return true;
}
/// <summary>
/// Adds in a light at the given tile location in the world.
/// </summary>
/// <param name="IdKey"></param>
/// <param name="light"></param>
/// <param name="gameObjectTileLocation"></param>
/// <returns></returns>
public bool addLight(Vector2 IdKey, LightSource light, Vector2 gameObjectTileLocation)
{
if (gameObjectTileLocation.X < 0) gameObjectTileLocation = new Vector2(gameObjectTileLocation.X * -1, gameObjectTileLocation.Y);
if (gameObjectTileLocation.Y < 0) gameObjectTileLocation = new Vector2(gameObjectTileLocation.X, gameObjectTileLocation.Y * -1);
Vector2 initialPosition = gameObjectTileLocation * Game1.tileSize;
initialPosition += IdKey;
if (this.lights.ContainsKey(IdKey))
return false;
light.position.Value = initialPosition;
this.lights.Add(IdKey, light);
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));
return true;
}
/// <summary>Turn off a single light.</summary>
public bool turnOffLight(Vector2 IdKey, GameLocation location)
{
@ -69,7 +112,6 @@ namespace Revitalize.Framework.Illuminate
if (location.sharedLights == null)
throw new Exception("Locational lights is null!");
Game1.showRedMessage("TURN ON!");
if (light.lightTexture == null)
{
@ -99,18 +141,33 @@ namespace Revitalize.Framework.Illuminate
this.turnOffLight(pair.Key, environment);
}
/// <summary>
/// Repositions all lights for this object.
/// </summary>
/// <param name="gameObject"></param>
public void repositionLights(StardewValley.Object gameObject)
{
foreach (KeyValuePair<Vector2, LightSource> pair in this.lights)
this.repositionLight(pair.Value, pair.Key, gameObject);
}
/// <summary>
/// Reposition a light for this object.
/// </summary>
/// <param name="light"></param>
/// <param name="offset"></param>
/// <param name="gameObject"></param>
public void repositionLight(LightSource light, Vector2 offset, StardewValley.Object gameObject)
{
Vector2 initialPosition = gameObject.TileLocation * Game1.tileSize;
light.position.Value = initialPosition + offset;
}
/// <summary>
/// Toggles the lights for this object.
/// </summary>
/// <param name="location"></param>
/// <param name="gameObject"></param>
public virtual void toggleLights(GameLocation location, StardewValley.Object gameObject)
{
if (!this.lightsOn)
@ -127,11 +184,20 @@ namespace Revitalize.Framework.Illuminate
}
}
/// <summary>
/// Removes the lights from the world when this object needs to be cleaned up.
/// </summary>
/// <param name="loc"></param>
public virtual void removeForCleanUp(GameLocation loc)
{
this.turnOffLights(loc);
}
/// <summary>
/// Loads in the appropriate texture from sdv depending on the int value used.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private Texture2D loadTextureFromConstantValue(int value)
{
switch (value)
@ -154,5 +220,30 @@ namespace Revitalize.Framework.Illuminate
}
return Game1.sconceLight;
}
/// <summary>
/// Gets a copy of all of the
/// </summary>
/// <returns></returns>
public LightManager Copy()
{
LightManager copy= new LightManager();
if (this.lights != null)
{
//ModCore.log("Info for file"+Path.GetFileNameWithoutExtension(file)+" has this many lights: " + info.info.lightManager.fakeLights.Count);
copy.lights.Clear();
foreach (KeyValuePair<Vector2, FakeLightSource> light in this.fakeLights)
{
Vector2 position = light.Value.positionOffset;
position -= light.Key;
position /= Game1.tileSize;
position = new Vector2((float)Math.Round(position.X), (float)Math.Round(position.Y));
copy.addLight(light.Key, new LightSource(light.Value.id, new Vector2(0, 0), light.Value.radius, light.Value.color.Invert()), position);
}
}
return copy;
}
}
}

View File

@ -110,7 +110,7 @@ namespace Revitalize.Framework.Objects
/// <returns></returns>
public BasicItemInformation Copy()
{
return new BasicItemInformation(this.name, this.id,this.description, this.categoryName, this.categoryColor, this.edibility, this.fragility, this.isLamp, this.price, this.canBeSetOutdoors, this.canBeSetIndoors, this.animationManager.getTexture(), this.animationManager, this.drawColor, this.ignoreBoundingBox, this.inventory, this.lightManager);
return new BasicItemInformation(this.name, this.id,this.description, this.categoryName, this.categoryColor, this.edibility, this.fragility, this.isLamp, this.price, this.canBeSetOutdoors, this.canBeSetIndoors, this.animationManager.getTexture(), this.animationManager, this.drawColor, this.ignoreBoundingBox, this.inventory.Copy(), this.lightManager.Copy());
}
}

View File

@ -47,7 +47,7 @@ namespace Revitalize.Framework.Objects.Extras
}
return new ArcadeCabinetOBJ(this.data, this.info, this.TileLocation, objs);
return new ArcadeCabinetOBJ(this.data, this.info.Copy(), this.TileLocation, objs);
}

View File

@ -123,7 +123,7 @@ namespace Revitalize.Framework.Objects.Extras
public override Item getOne()
{
ArcadeCabinetTile component = new ArcadeCabinetTile(this.data, this.info, this.arcadeInfo);
ArcadeCabinetTile component = new ArcadeCabinetTile(this.data, this.info.Copy(), this.arcadeInfo);
component.containerObject = this.containerObject;
component.offsetKey = this.offsetKey;
return component;

View File

@ -62,7 +62,7 @@ namespace Revitalize.Framework.Objects.Furniture
objs.Add(pair.Key, (MultiTiledComponent)pair.Value);
}
return new Bench(this.data,this.info, this.TileLocation, objs);
return new Bench(this.data,this.info.Copy(), this.TileLocation, objs);
}

View File

@ -63,7 +63,7 @@ namespace Revitalize.Framework.Objects.Furniture
}
return new ChairMultiTiledObject(this.data,this.info, this.TileLocation, objs);
return new ChairMultiTiledObject(this.data,this.info.Copy(), this.TileLocation, objs);
}

View File

@ -88,7 +88,7 @@ namespace Revitalize.Framework.Objects.Furniture
public override Item getOne()
{
ChairTileComponent component = new ChairTileComponent(this.data,this.info, (ChairInformation)this.furnitureInfo);
ChairTileComponent component = new ChairTileComponent(this.data,this.info.Copy(), (ChairInformation)this.furnitureInfo);
component.containerObject = this.containerObject;
component.offsetKey = this.offsetKey;
return component;

View File

@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using PyTK.CustomElementHandler;
using Revitalize.Framework.Objects.InformationFiles.Furniture;
namespace Revitalize.Framework.Objects.Furniture
{
public class CustomFurniture:CustomObject
{
public FurnitureInformation furnitureInfo;
public CustomFurniture() : base()
{
}
public CustomFurniture(CustomObjectData PyTKData,BasicItemInformation itemInfo, FurnitureInformation furnitureInfo) : base(PyTKData,itemInfo)
{
this.furnitureInfo = furnitureInfo;
}
public CustomFurniture(CustomObjectData PyTKData, BasicItemInformation itemInfo, Vector2 TileLocation, FurnitureInformation furnitureInfo) : base(PyTKData,itemInfo, TileLocation)
{
this.furnitureInfo = furnitureInfo;
}
}
}

View File

@ -47,7 +47,7 @@ namespace Revitalize.Framework.Objects.Furniture
}
return new LampMultiTiledObject(this.data,this.info, this.TileLocation, objs);
return new LampMultiTiledObject(this.data,this.info.Copy(), this.TileLocation, objs);
}

View File

@ -23,7 +23,7 @@ namespace Revitalize.Framework.Objects.Furniture
}
}
public LightManager lights
public LightManager lightManager
{
get
{
@ -124,7 +124,7 @@ namespace Revitalize.Framework.Objects.Furniture
public override Item getOne()
{
LampTileComponent component = new LampTileComponent(this.data,this.info);
LampTileComponent component = new LampTileComponent(this.data,this.info.Copy());
component.containerObject = this.containerObject;
component.offsetKey = this.offsetKey;
return component;

View File

@ -49,7 +49,7 @@ namespace Revitalize.Framework.Objects.Furniture
}
return new RugMultiTiledObject(this.data,this.info, this.TileLocation, objs);
return new RugMultiTiledObject(this.data,this.info.Copy(), this.TileLocation, objs);
}

View File

@ -44,7 +44,7 @@ namespace Revitalize.Framework.Objects.Furniture
public override Item getOne()
{
RugTileComponent component = new RugTileComponent(this.data,this.info);
RugTileComponent component = new RugTileComponent(this.data,this.info.Copy());
component.containerObject = this.containerObject;
component.offsetKey = this.offsetKey;
return component;

View File

@ -47,7 +47,7 @@ namespace Revitalize.Framework.Objects.Furniture
}
return new StorageFurnitureOBJ(this.data, this.info, this.TileLocation, objs);
return new StorageFurnitureOBJ(this.data, this.info.Copy(), this.TileLocation, objs);
}

View File

@ -107,7 +107,7 @@ namespace Revitalize.Framework.Objects.Furniture
public override Item getOne()
{
StorageFurnitureTile component = new StorageFurnitureTile(this.data, this.info);
StorageFurnitureTile component = new StorageFurnitureTile(this.data, this.info.Copy());
component.containerObject = this.containerObject;
component.offsetKey = this.offsetKey;
return component;

View File

@ -48,7 +48,7 @@ namespace Revitalize.Framework.Objects.Furniture
}
return new TableMultiTiledObject(this.data,this.info, this.TileLocation,objs);
return new TableMultiTiledObject(this.data,this.info.Copy(), this.TileLocation,objs);
}

View File

@ -180,7 +180,7 @@ namespace Revitalize.Framework.Objects.Furniture
public override Item getOne()
{
TableTileComponent component = new TableTileComponent(this.data,this.info, (TableInformation)this.furnitureInfo);
TableTileComponent component = new TableTileComponent(this.data,this.info.Copy(), (TableInformation)this.furnitureInfo);
component.containerObject = this.containerObject;
component.offsetKey = this.offsetKey;
return component;

View File

@ -114,7 +114,7 @@ namespace Revitalize.Framework.Objects
public override Item getOne()
{
MultiTiledComponent component = new MultiTiledComponent(this.data,this.info, this.TileLocation,this.offsetKey,this.containerObject);
MultiTiledComponent component = new MultiTiledComponent(this.data,this.info.Copy(), this.TileLocation,this.offsetKey,this.containerObject);
return component;
}

View File

@ -268,7 +268,7 @@ namespace Revitalize.Framework.Objects
{
objs.Add(pair.Key, (MultiTiledComponent)pair.Value);
}
return new MultiTiledObject(this.data,this.info, this.TileLocation, objs);
return new MultiTiledObject(this.data,this.info.Copy(), this.TileLocation, objs);
}
public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement)

View File

@ -60,7 +60,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
}
return new OreVeinObj(this.data, this.info, this.TileLocation, objs);
return new OreVeinObj(this.data, this.info.Copy(), this.TileLocation, objs);
}

View File

@ -231,7 +231,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
public override Item getOne()
{
OreVeinTile component = new OreVeinTile(this.data, this.info,this.resourceInfo,this.extraDrops,this.healthValue);
OreVeinTile component = new OreVeinTile(this.data, this.info.Copy(),this.resourceInfo,this.extraDrops,this.healthValue);
component.containerObject = this.containerObject;
component.offsetKey = this.offsetKey;
return component;

View File

@ -129,5 +129,14 @@ namespace Revitalize.Framework.Utilities
{
this.MaxCapacity = amount;
}
/// <summary>
/// Returns a new inventory manager without the items but with the capacity limits.
/// </summary>
/// <returns></returns>
public InventoryManager Copy()
{
return new InventoryManager(this.capacity, this.MaxCapacity);
}
}
}

View File

@ -10,9 +10,20 @@ using StardewValley;
namespace Revitalize.Framework.Utilities.Serialization
{
/// <summary>
/// Utilities for dealing with the XNA/Monogames spritebatch class.
/// </summary>
public class SpriteBatchUtilities
{
/// <summary>
/// Used to draw SDV items to the screen.
/// </summary>
/// <param name="spriteBatch"></param>
/// <param name="obj"></param>
/// <param name="itemToDraw"></param>
/// <param name="alpha"></param>
/// <param name="addedDepth"></param>
public static void Draw(SpriteBatch spriteBatch, CustomObject obj, StardewValley.Item itemToDraw,float alpha,float addedDepth)
{
if (itemToDraw.GetType()==typeof(StardewValley.Object))

View File

@ -110,7 +110,6 @@
<Compile Include="Framework\Objects\Furniture\Bench.cs" />
<Compile Include="Framework\Objects\Furniture\ChairMultiTiledObject.cs" />
<Compile Include="Framework\Objects\Furniture\ChairTileComponent.cs" />
<Compile Include="Framework\Objects\Furniture\CustomFurniture.cs" />
<Compile Include="Framework\Objects\Furniture\FurnitureTileComponent.cs" />
<Compile Include="Framework\Objects\Furniture\LampMultiTiledObject.cs" />
<Compile Include="Framework\Objects\Furniture\LampTileComponent.cs" />