diff --git a/GeneralMods/Revitalize/Framework/Illuminate/ColorExtensions.cs b/GeneralMods/Revitalize/Framework/Illuminate/ColorExtensions.cs index 1cc17128..c3a03831 100644 --- a/GeneralMods/Revitalize/Framework/Illuminate/ColorExtensions.cs +++ b/GeneralMods/Revitalize/Framework/Illuminate/ColorExtensions.cs @@ -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); + } + } } diff --git a/GeneralMods/Revitalize/Framework/Illuminate/LightManager.cs b/GeneralMods/Revitalize/Framework/Illuminate/LightManager.cs new file mode 100644 index 00000000..0dbb3efe --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Illuminate/LightManager.cs @@ -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 lights; + public bool lightsOn; + + public LightManager() + { + this.lights = new Dictionary(); + lightsOn = false; + } + + /// + /// Add a light to the list of tracked lights. + /// + /// + /// + /// + /// + 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; + } + } + + /// + /// Turn off a single light. + /// + /// + /// + /// + 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; + } + } + + /// + /// Turn on a single light. + /// + /// + /// + /// + 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; + } + } + + + + + /// + /// Add a light source to this location. + /// + /// The game location to add the light source in. + /// The color of the light to be added + public virtual void turnOnLights(GameLocation environment,StardewValley.Object gameObject) + { + foreach(KeyValuePair pair in this.lights) + { + turnOnLight(pair.Key, environment,gameObject); + } + repositionLights(gameObject); + } + + /// + /// Removes a lightsource from the game location. + /// + /// The game location to remove the light source from. + public void turnOffLights(GameLocation environment) + { + foreach (KeyValuePair pair in this.lights) + { + turnOffLight(pair.Key, environment); + } + + } + + public void repositionLights(StardewValley.Object gameObject) + { + foreach (KeyValuePair 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; + } + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs b/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs index 207feb90..bccfe455 100644 --- a/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs +++ b/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs @@ -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() diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs index 1502278c..9ac9a47e 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs @@ -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); diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index ad634fe0..8c59dd2d 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -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(); } } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 64b1d86a..b08233ee 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -52,6 +52,7 @@ + diff --git a/GeneralMods/StardustCore/Objects/CoreObject.cs b/GeneralMods/StardustCore/Objects/CoreObject.cs index 913fcfde..73d76bf5 100644 --- a/GeneralMods/StardustCore/Objects/CoreObject.cs +++ b/GeneralMods/StardustCore/Objects/CoreObject.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);