Got lamps working with a furniture factory.

This commit is contained in:
JoshuaNavarro 2019-05-17 11:04:16 -07:00
parent 6c02af4596
commit c026702f09
7 changed files with 166 additions and 29 deletions

View File

@ -11,6 +11,7 @@ using Revitalize.Framework.Graphics.Animations;
using Revitalize.Framework.Illuminate;
using Revitalize.Framework.Objects;
using Revitalize.Framework.Objects.Furniture;
using StardewValley;
namespace Revitalize.Framework.Factories.Objects
{
@ -18,11 +19,13 @@ namespace Revitalize.Framework.Factories.Objects
{
public static string ChairFolder = Path.Combine("Objects", "Furniture", "Chairs");
public static string TablesFolder = Path.Combine("Objects", "Furniture", "Tables");
public static string LampsFolder = Path.Combine("Objects", "Furniture", "Lamps");
public static void LoadFurnitureFiles()
{
LoadChairFiles();
LoadTableFiles();
LoadLampFiles();
}
private static void LoadChairFiles()
@ -37,11 +40,91 @@ namespace Revitalize.Framework.Factories.Objects
DeserializeTableFiles();
}
private static void LoadLampFiles()
{
SerializeLamps();
DeserializeLamps();
}
private static void SerializeLamps()
{
LampTileComponent lampTop = new LampTileComponent(new BasicItemInformation("Oak Chair", "A basic wooden chair", "Chairs", Color.Brown, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Chairs.OakChair", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0, true, typeof(Framework.Objects.Furniture.ChairTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair"), new Animation(new Rectangle(0, 0, 16, 16))), Color.White, true, new Framework.Utilities.InventoryManager(), new LightManager()));
LampTileComponent lampTop = new LampTileComponent(new BasicItemInformation("Oak Lamp", "A basic wooden light", "Lamps", Color.Brown, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Lamp").texture, Color.White, 0, true, typeof(Framework.Objects.Furniture.LampTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Lamp"), new Animation(new Rectangle(0, 0, 16, 16))), Color.White, true, new Framework.Utilities.InventoryManager(), new LightManager()));
LampTileComponent lampMiddle = new LampTileComponent(new BasicItemInformation("Oak Lamp", "A basic wooden light", "Lamps", Color.Brown, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Lamp").texture, Color.White, 0, true, typeof(Framework.Objects.Furniture.LampTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Lamp"), new Animation(new Rectangle(0, 16, 16, 16))), Color.White, false, new Framework.Utilities.InventoryManager(), new LightManager()));
LampTileComponent lampBottom = new LampTileComponent(new BasicItemInformation("Oak Lamp", "A basic wooden light", "Lamps", Color.Brown, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Lamp").texture, Color.White, 0, true, typeof(Framework.Objects.Furniture.LampTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Lamp"), new Animation(new Rectangle(0, 32, 16, 16))), Color.White, false, new Framework.Utilities.InventoryManager(), new LightManager()));
lampMiddle.lights.addLight(new Vector2(Game1.tileSize), new LightSource(4, new Vector2(0, 0), 2.5f, Color.Orange.Invert()), lampMiddle);
LampMultiTiledObject lamp = new LampMultiTiledObject(new BasicItemInformation("Oak Lamp", "A basic wooden light", "Lamps", Color.Brown, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Lamps.OakLamp", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Lamp").texture, Color.White, 0, true, typeof(Framework.Objects.Furniture.LampTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Lamp"), new Animation(new Rectangle(0, 0, 16, 16))), Color.White, true, new Framework.Utilities.InventoryManager(), new LightManager()));
lamp.addComponent(new Vector2(0, -2), lampTop);
lamp.addComponent(new Vector2(0, -1), lampMiddle);
lamp.addComponent(new Vector2(0, 0), lampBottom);
FactoryInfo lT = new FactoryInfo(lampTop);
FactoryInfo lM = new FactoryInfo(lampMiddle);
FactoryInfo lB = new FactoryInfo(lampBottom);
FactoryInfo lO = new FactoryInfo(lamp);
ModCore.Serializer.SerializeContentFile("OakLamp_0_-2", lT, LampsFolder);
ModCore.Serializer.SerializeContentFile("OakLamp_0_-1", lM, LampsFolder);
ModCore.Serializer.SerializeContentFile("OakLamp_0_0", lB, LampsFolder);
ModCore.Serializer.SerializeContentFile("OakLamp", lO, LampsFolder);
//ModCore.customObjects.Add(lamp.info.id, lamp);
}
private static void DeserializeLamps()
{
if (!Directory.Exists(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", LampsFolder))) Directory.CreateDirectory(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", LampsFolder));
string[] files = Directory.GetFiles(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", LampsFolder));
Dictionary<string, LampMultiTiledObject> objs = new Dictionary<string, LampMultiTiledObject>();
//Deserialize container.
foreach (string file in files)
{
if ((Path.GetFileName(file)).Contains("_") == true) continue;
else
{
objs.Add(Path.GetFileNameWithoutExtension(file), new LampMultiTiledObject(ModCore.Serializer.DeserializeContentFile<FactoryInfo>(file).info));
}
}
//Deseralize components
foreach (string file in files)
{
if ((Path.GetFileName(file)).Contains("_") == false) continue;
else
{
string[] splits = Path.GetFileNameWithoutExtension(file).Split('_');
string name = splits[0];
Vector2 offset = new Vector2(Convert.ToInt32(splits[1]), Convert.ToInt32(splits[2]));
FactoryInfo info = ModCore.Serializer.DeserializeContentFile<FactoryInfo>(file);
LampTileComponent lampPiece = new LampTileComponent(info.info);
//Recreate the lights info.
if (lampPiece.lights != null)
{
//ModCore.log("Info for file"+Path.GetFileNameWithoutExtension(file)+" has this many lights: " + info.info.lightManager.fakeLights.Count);
lampPiece.lights.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);
}
}
objs[name].addComponent(offset,lampPiece );
}
}
foreach (var v in objs)
{
ModCore.customObjects.Add(v.Value.info.id, v.Value);
}
}
private static void SerializeChairs()
{
@ -150,7 +233,7 @@ namespace Revitalize.Framework.Factories.Objects
//Deserialize container.
foreach (string file in files)
{
if ((Path.GetFileName(file)).Contains("_")==true) continue;
if ((Path.GetFileName(file)).Contains("_") == true) continue;
else
{
chairObjects.Add(Path.GetFileNameWithoutExtension(file), new ChairMultiTiledObject(ModCore.Serializer.DeserializeContentFile<ChairFactoryInfo>(file).info));
@ -159,10 +242,10 @@ namespace Revitalize.Framework.Factories.Objects
//Deseralize components
foreach (string file in files)
{
if ((Path.GetFileName(file)).Contains("_")==false) continue;
if ((Path.GetFileName(file)).Contains("_") == false) continue;
else
{
string[] splits = Path.GetFileNameWithoutExtension(file).Split('_');
string name = splits[0];
Vector2 offset = new Vector2(Convert.ToInt32(splits[1]), Convert.ToInt32(splits[2]));
@ -178,7 +261,7 @@ namespace Revitalize.Framework.Factories.Objects
private static void SerializeTableFiles()
{
TableTileComponent upperLeft = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"),new Animation(new Rectangle(0,0,16,16),-1)),Color.White,true, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));
TableTileComponent upperLeft = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(0, 0, 16, 16), -1)), Color.White, true, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));
TableTileComponent upperRight = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(16, 0, 16, 16), -1)), Color.White, true, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));
TableTileComponent centerLeft = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(0, 16, 16, 16), -1)), Color.White, false, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));
TableTileComponent centerRight = new TableTileComponent(new BasicItemInformation("Oak Table", "A simple oak table to hold things.", "Tables", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.Revitalize.Furniture.Tables.OakTable", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", TextureManager.TextureManagers["Furniture"].getTexture("Oak Table").texture, Color.White, 0, true, typeof(TableTileComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Table"), new Animation(new Rectangle(16, 16, 16, 16), -1)), Color.White, false, new Utilities.InventoryManager(), new LightManager()), new Framework.Objects.InformationFiles.Furniture.TableInformation(true));

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
namespace Revitalize.Framework.Illuminate
{
public class FakeLightSource
{
public int id;
public Vector2 positionOffset;
public Color color;
public float radius;
public FakeLightSource()
{
}
public FakeLightSource(int ID, Vector2 Position, Color Color, float Raidus)
{
this.id = ID;
this.positionOffset = Position;
this.color = Color;
this.radius = Raidus;
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;
namespace Revitalize.Framework.Illuminate
@ -8,6 +9,7 @@ namespace Revitalize.Framework.Illuminate
public class LightManager
{
public Dictionary<Vector2, LightSource> lights;
public Dictionary<Vector2, FakeLightSource> fakeLights;
public bool lightsOn;
public const int lightBigNumber= 1000000;
@ -15,12 +17,16 @@ namespace Revitalize.Framework.Illuminate
public LightManager()
{
this.lights = new Dictionary<Vector2, LightSource>();
this.fakeLights = new Dictionary<Vector2, FakeLightSource>();
this.lightsOn = false;
}
/// <summary>Add a light to the list of tracked lights.</summary>
public bool addLight(Vector2 IdKey, LightSource light, StardewValley.Object gameObject)
{
if (gameObject.TileLocation.X < 0) gameObject.TileLocation = new Vector2(gameObject.TileLocation.X * -1, gameObject.TileLocation.Y);
if (gameObject.TileLocation.Y < 0) gameObject.TileLocation = new Vector2(gameObject.TileLocation.X, gameObject.TileLocation.Y*-1);
Vector2 initialPosition = gameObject.TileLocation * Game1.tileSize;
initialPosition += IdKey;
@ -29,6 +35,8 @@ namespace Revitalize.Framework.Illuminate
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;
}
@ -62,6 +70,12 @@ namespace Revitalize.Framework.Illuminate
throw new Exception("Locational lights is null!");
Game1.showRedMessage("TURN ON!");
if (light.lightTexture == null)
{
light.lightTexture = this.loadTextureFromConstantValue(light.Identifier);
}
Game1.currentLightSources.Add(light);
location.sharedLights.Add((int)IdKey.X*lightBigNumber+(int)IdKey.Y,light);
this.repositionLight(light, IdKey, gameObject);
@ -117,5 +131,28 @@ namespace Revitalize.Framework.Illuminate
{
this.turnOffLights(loc);
}
private Texture2D loadTextureFromConstantValue(int value)
{
switch (value)
{
case 1:
return Game1.lantern;
break;
case 2:
return Game1.windowLight;
break;
case 4:
return Game1.sconceLight;
break;
case 5:
return Game1.cauldronLight;
break;
case 6:
return Game1.indoorWindowLight;
break;
}
return Game1.sconceLight;
}
}
}

View File

@ -47,25 +47,6 @@ namespace Revitalize.Framework.Objects.Furniture
}
/// <summary>
/// Forcefully clears the held object without much fuss.
/// </summary>
public void clearHeldObject()
{
if (this.heldObject.Value != null)
{
if (Game1.player.isInventoryFull() == false)
{
Game1.player.addItemToInventoryBool(this.heldObject.Value, false);
this.heldObject.Value = null;
return;
}
else
{
Game1.createItemDebris(this.heldObject.Value, Vector2.Zero, 0);
}
}
}
public override bool performObjectDropInAction(Item dropInItem, bool probe, Farmer who)
{

View File

@ -52,7 +52,6 @@ namespace Revitalize.Framework.Objects
{
if (this.location == null)
this.location = Game1.player.currentLocation;
if(this.info.lightManager!=null)this.info.lightManager.toggleLights(this.location, this);
//ModCore.playerInfo.sittingInfo.sit(this, Vector2.Zero);

View File

@ -27,7 +27,9 @@ namespace Revitalize
// -load content MUST be enabled for the table to be placed?????? WTF
// TODO:
//
//
// -Get way to read in textures at runtime without having to load them in...
// -Make this mod able to load content packs for easier future modding
// -Make deserialize/serialize look through sub directories instead of just one directory.
//
// -Multiple Lights On Object
// -Illumination Colors
@ -139,13 +141,14 @@ namespace Revitalize
Framework.Graphics.TextureManager.TextureManagers.Add("Furniture", new TextureManager());
TextureManager.addTexture("Furniture","Oak Chair", new Texture2DExtended(this.Helper, this.ModManifest, Path.Combine("Content","Graphics","Furniture", "Chairs", "OakChair.png")));
TextureManager.addTexture("Furniture", "Oak Table", new Texture2DExtended(this.Helper, this.ModManifest, Path.Combine("Content", "Graphics", "Furniture", "Tables", "OakTable.png")));
TextureManager.addTexture("Furniture", "Oak Lamp", new Texture2DExtended(this.Helper, this.ModManifest, Path.Combine("Content", "Graphics", "Furniture", "Lamps", "OakLamp.png")));
customObjects = new Dictionary<string, CustomObject>();
ObjectGroups = new Dictionary<string, MultiTiledObject>();
Serializer = new Serializer();
ObjectsToDraw = new Dictionary<GameLocation, MultiTiledObject>();
this.loadContent();
}
@ -165,7 +168,7 @@ namespace Revitalize
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", TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair"), new Animation(new Rectangle(0, 32, 16, 16))), Color.Red, false, null, null));
obj3.info.lightManager.addLight(new Vector2(Game1.tileSize), new LightSource(4, new Vector2(0, 0), 2.5f, Color.Orange.Invert()), obj);
obj3.info.lightManager.addLight(new Vector2(Game1.tileSize), new LightSource(4, new Vector2(0, 0), 2.5f, Color.Orange.Invert()), obj3);
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", TextureManager.TextureManagers["Furniture"].getTexture("Oak Chair").texture, Color.White, 0, true, typeof(MultiTiledObject), null, new AnimationManager(), Color.White, false, null, null));
bigObject.addComponent(new Vector2(0, 0), obj);
@ -219,7 +222,7 @@ namespace Revitalize
private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e)
{
this.loadContent();
Serializer.afterLoad();
@ -232,6 +235,7 @@ namespace Revitalize
//Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Chairs.OakChair"));
//Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Rugs.RugTest"));
Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Tables.OakTable"));
Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Lamps.OakLamp"));
/*
StardewValley.Tools.Axe axe = new StardewValley.Tools.Axe();
Serializer.Serialize(Path.Combine(this.Helper.DirectoryPath, "AXE.json"), axe);

View File

@ -63,6 +63,7 @@
<Compile Include="Framework\Graphics\Texture2DExtended.cs" />
<Compile Include="Framework\Graphics\TextureManager.cs" />
<Compile Include="Framework\Illuminate\ColorExtensions.cs" />
<Compile Include="Framework\Illuminate\FakeLightSource.cs" />
<Compile Include="Framework\Illuminate\LightManager.cs" />
<Compile Include="Framework\Objects\BasicItemInformation.cs" />
<Compile Include="Framework\Objects\CustomObject.cs" />