Got light manager working for adding light sources to custom objects.
This commit is contained in:
parent
a8e457a5ff
commit
1efe48b4d6
|
@ -15,5 +15,13 @@ namespace Revitalize.Framework.Illuminate
|
|||
return new Color(new Vector3(value));
|
||||
}
|
||||
|
||||
public static Color Invert(this Color color)
|
||||
{
|
||||
int r = Math.Abs(255 - color.R);
|
||||
int g = Math.Abs(255 - color.G);
|
||||
int b = Math.Abs(255 - color.B);
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using StardewValley;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Revitalize.Framework.Illuminate
|
||||
{
|
||||
public class LightManager
|
||||
{
|
||||
public Dictionary<Vector2,LightSource> lights;
|
||||
public bool lightsOn;
|
||||
|
||||
public LightManager()
|
||||
{
|
||||
this.lights = new Dictionary<Vector2, LightSource>();
|
||||
lightsOn = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a light to the list of tracked lights.
|
||||
/// </summary>
|
||||
/// <param name="IdKey"></param>
|
||||
/// <param name="light"></param>
|
||||
/// <param name="gameObject"></param>
|
||||
/// <returns></returns>
|
||||
public bool addLight(Vector2 IdKey,LightSource light,StardewValley.Object gameObject)
|
||||
{
|
||||
Vector2 initialPosition = gameObject.TileLocation*Game1.tileSize;
|
||||
initialPosition += IdKey;
|
||||
|
||||
if (this.lights.ContainsKey(IdKey))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
light.position.Value = initialPosition;
|
||||
this.lights.Add(IdKey, light);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn off a single light.
|
||||
/// </summary>
|
||||
/// <param name="IdKey"></param>
|
||||
/// <param name="location"></param>
|
||||
/// <returns></returns>
|
||||
public bool turnOffLight(Vector2 IdKey, GameLocation location)
|
||||
{
|
||||
if (!lights.ContainsKey(IdKey))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LightSource light = new LightSource();
|
||||
this.lights.TryGetValue(IdKey, out light);
|
||||
Game1.currentLightSources.Remove(light);
|
||||
location.sharedLights.Remove(light);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn on a single light.
|
||||
/// </summary>
|
||||
/// <param name="IdKey"></param>
|
||||
/// <param name="location"></param>
|
||||
/// <returns></returns>
|
||||
public bool turnOnLight(Vector2 IdKey, GameLocation location,StardewValley.Object gameObject)
|
||||
{
|
||||
if (!lights.ContainsKey(IdKey))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LightSource light = new LightSource();
|
||||
this.lights.TryGetValue(IdKey, out light);
|
||||
if (light == null)
|
||||
{
|
||||
throw new Exception("Light is null????");
|
||||
}
|
||||
Game1.currentLightSources.Add(light);
|
||||
if (location == null)
|
||||
{
|
||||
throw new Exception("WHY IS LOC NULL???");
|
||||
}
|
||||
if (location.sharedLights == null)
|
||||
{
|
||||
throw new Exception("Locational lights is null!");
|
||||
|
||||
}
|
||||
Game1.showRedMessage("TURN ON!");
|
||||
Game1.currentLightSources.Add(light);
|
||||
location.sharedLights.Add(light);
|
||||
repositionLight(light,IdKey,gameObject);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Add a light source to this location.
|
||||
/// </summary>
|
||||
/// <param name="environment">The game location to add the light source in.</param>
|
||||
/// <param name="c">The color of the light to be added</param>
|
||||
public virtual void turnOnLights(GameLocation environment,StardewValley.Object gameObject)
|
||||
{
|
||||
foreach(KeyValuePair<Vector2,LightSource> pair in this.lights)
|
||||
{
|
||||
turnOnLight(pair.Key, environment,gameObject);
|
||||
}
|
||||
repositionLights(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a lightsource from the game location.
|
||||
/// </summary>
|
||||
/// <param name="environment">The game location to remove the light source from.</param>
|
||||
public void turnOffLights(GameLocation environment)
|
||||
{
|
||||
foreach (KeyValuePair<Vector2, LightSource> pair in this.lights)
|
||||
{
|
||||
turnOffLight(pair.Key, environment);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void repositionLights(StardewValley.Object gameObject)
|
||||
{
|
||||
foreach (KeyValuePair<Vector2, LightSource> pair in this.lights)
|
||||
{
|
||||
repositionLight(pair.Value, pair.Key, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void repositionLight(LightSource light,Vector2 offset,StardewValley.Object gameObject)
|
||||
{
|
||||
Vector2 initialPosition = gameObject.TileLocation * Game1.tileSize;
|
||||
light.position.Value = initialPosition + offset;
|
||||
}
|
||||
|
||||
public virtual void toggleLights(GameLocation location,StardewValley.Object gameObject)
|
||||
{
|
||||
|
||||
if (lightsOn == false)
|
||||
{
|
||||
this.turnOnLights(location,gameObject);
|
||||
lightsOn = true;
|
||||
}
|
||||
else if (lightsOn == true)
|
||||
{
|
||||
|
||||
this.turnOffLights(Game1.player.currentLocation);
|
||||
lightsOn = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using Microsoft.Xna.Framework.Graphics;
|
||||
using PyTK.CustomElementHandler;
|
||||
using Revitalize.Framework.Graphics.Animations;
|
||||
using Revitalize.Framework.Illuminate;
|
||||
using Revitalize.Framework.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -34,6 +35,8 @@ namespace Revitalize.Framework.Objects
|
|||
|
||||
public InventoryManager inventory;
|
||||
|
||||
public LightManager lightManager;
|
||||
|
||||
public BasicItemInformation() : base()
|
||||
{
|
||||
name = "";
|
||||
|
@ -50,9 +53,10 @@ namespace Revitalize.Framework.Objects
|
|||
this.drawPosition = Vector2.Zero;
|
||||
this.drawColor = Color.White;
|
||||
this.inventory = new InventoryManager();
|
||||
this.lightManager = new LightManager();
|
||||
}
|
||||
|
||||
public BasicItemInformation(string name, string description, string categoryName, Color categoryColor,int edibility,int fragility,bool isLamp,int price, Vector2 TileLocation,bool canBeSetOutdoors,bool canBeSetIndoors,string id, string data, Texture2D texture, Color color,int tileIndex, bool bigCraftable, Type type, CraftingData craftingData, AnimationManager animationManager,Color DrawColor,bool ignoreBoundingBox, InventoryManager Inventory):base(id,data,texture,color,tileIndex,bigCraftable,type,craftingData)
|
||||
public BasicItemInformation(string name, string description, string categoryName, Color categoryColor,int edibility,int fragility,bool isLamp,int price, Vector2 TileLocation,bool canBeSetOutdoors,bool canBeSetIndoors,string id, string data, Texture2D texture, Color color,int tileIndex, bool bigCraftable, Type type, CraftingData craftingData, AnimationManager animationManager,Color DrawColor,bool ignoreBoundingBox, InventoryManager Inventory,LightManager Lights):base(id,data,texture,color,tileIndex,bigCraftable,type,craftingData)
|
||||
{
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
|
@ -100,6 +104,15 @@ namespace Revitalize.Framework.Objects
|
|||
{
|
||||
this.inventory = Inventory;
|
||||
}
|
||||
|
||||
if (Lights == null)
|
||||
{
|
||||
this.lightManager = new LightManager();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.lightManager = Lights;
|
||||
}
|
||||
}
|
||||
|
||||
public void recreateDataString()
|
||||
|
|
|
@ -46,16 +46,28 @@ namespace Revitalize.Framework.Objects
|
|||
//return base.clicked(who);
|
||||
}
|
||||
|
||||
|
||||
public override bool rightClicked(Farmer who)
|
||||
{
|
||||
if (this.location == null)
|
||||
{
|
||||
this.location = Game1.player.currentLocation;
|
||||
}
|
||||
this.info.lightManager.toggleLights(this.location, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void performRemoveAction(Vector2 tileLocation, GameLocation environment)
|
||||
{
|
||||
this.location = null;
|
||||
base.performRemoveAction(this.TileLocation, environment);
|
||||
}
|
||||
|
||||
public virtual void removeFromLocation(GameLocation location,Vector2 offset)
|
||||
{
|
||||
location.removeObject(this.TileLocation,false);
|
||||
this.location = null;
|
||||
//this.performRemoveAction(this.TileLocation,location);
|
||||
}
|
||||
|
||||
|
@ -73,6 +85,7 @@ namespace Revitalize.Framework.Objects
|
|||
this.updateDrawPosition(x,y);
|
||||
this.location = location;
|
||||
|
||||
if (this.location == null) this.location = Game1.player.currentLocation;
|
||||
this.TileLocation = new Vector2((int)(x / Game1.tileSize), (int)(y / Game1.tileSize));
|
||||
|
||||
return base.placementAction(location, x, y, who);
|
||||
|
|
|
@ -15,6 +15,7 @@ using Revitalize.Framework.Environment;
|
|||
using System.IO;
|
||||
using Revitalize.Framework.Crafting;
|
||||
using StardewValley.Objects;
|
||||
using Revitalize.Framework.Illuminate;
|
||||
|
||||
namespace Revitalize
|
||||
{
|
||||
|
@ -77,6 +78,7 @@ namespace Revitalize
|
|||
* Locations:
|
||||
* -Small Island Home?
|
||||
*
|
||||
* More crops
|
||||
*/
|
||||
|
||||
public class ModCore : Mod
|
||||
|
@ -125,11 +127,14 @@ namespace Revitalize
|
|||
|
||||
private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e)
|
||||
{
|
||||
MultiTiledComponent obj = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest","YAY FUN!","Omegasis.Revitalize.MultiTiledComponent",Color.White,-300,0,false,100,Vector2.Zero,true,true,"Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet,Color.White,0,true,typeof(MultiTiledComponent),null,new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet),new Animation(new Rectangle(0,0,16,16))),Color.Red,true,null));
|
||||
MultiTiledComponent obj2 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest2", "SomeFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 16, 16, 16))), Color.Red,false,null));
|
||||
MultiTiledComponent obj3 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest3", "NoFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 32, 16, 16))), Color.Red,false,null));
|
||||
MultiTiledComponent obj = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest","YAY FUN!","Omegasis.Revitalize.MultiTiledComponent",Color.White,-300,0,false,100,Vector2.Zero,true,true,"Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet,Color.White,0,true,typeof(MultiTiledComponent),null,new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet),new Animation(new Rectangle(0,0,16,16))),Color.Red,true,null,null));
|
||||
MultiTiledComponent obj2 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest2", "SomeFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 16, 16, 16))), Color.Red,false,null,null));
|
||||
MultiTiledComponent obj3 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest3", "NoFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 32, 16, 16))), Color.Red,false,null,null));
|
||||
|
||||
MultiTiledObject bigObject= new MultiTiledObject(new BasicItemInformation("MultiTest", "A really big object", "Omegasis.Revitalize.MultiTiledObject", Color.Blue, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.BigTiledTest", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledObject), null, new AnimationManager(), Color.White,false,null));
|
||||
|
||||
obj.info.lightManager.addLight(new Vector2(Game1.tileSize), new LightSource(4, new Vector2(0, 0), 2.5f, Color.Orange.Invert()), obj);
|
||||
|
||||
MultiTiledObject bigObject= new MultiTiledObject(new BasicItemInformation("MultiTest", "A really big object", "Omegasis.Revitalize.MultiTiledObject", Color.Blue, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.BigTiledTest", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledObject), null, new AnimationManager(), Color.White,false,null,null));
|
||||
bigObject.addComponent(new Vector2(0, 0), obj);
|
||||
bigObject.addComponent(new Vector2(1, 0), obj2);
|
||||
bigObject.addComponent(new Vector2(2, 0), obj3);
|
||||
|
@ -142,10 +147,10 @@ namespace Revitalize
|
|||
|
||||
new InventoryItem(bigObject, 100,1).addToNPCShop("Gus");
|
||||
Game1.player.addItemToInventory(bigObject);
|
||||
|
||||
|
||||
if (pie.PlayerCanCraft())
|
||||
{
|
||||
pie.craft();
|
||||
//pie.craft();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
<Compile Include="Framework\Graphics\Animations\AnimationManager.cs" />
|
||||
<Compile Include="Framework\Graphics\Texture2DExtended.cs" />
|
||||
<Compile Include="Framework\Illuminate\ColorExtensions.cs" />
|
||||
<Compile Include="Framework\Illuminate\LightManager.cs" />
|
||||
<Compile Include="Framework\Objects\BasicItemInformation.cs" />
|
||||
<Compile Include="Framework\Objects\CustomObject.cs" />
|
||||
<Compile Include="Framework\Objects\MultiTiledComponent.cs" />
|
||||
|
|
|
@ -894,7 +894,8 @@ namespace StardustCore
|
|||
num2 = 2;
|
||||
goto IL_94;
|
||||
}
|
||||
num = 1;
|
||||
|
||||
num = 1;
|
||||
num2 = 1;
|
||||
IL_94:
|
||||
return new Rectangle((int)this.TileLocation.X * Game1.tileSize, (int)this.TileLocation.Y * Game1.tileSize, num * Game1.tileSize, num2 * Game1.tileSize);
|
||||
|
|
Loading…
Reference in New Issue