NPC handler implemented for custom characters.
This commit is contained in:
parent
065a88e310
commit
c9f21d2772
|
@ -50,6 +50,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Framework\NPCHandler.cs" />
|
||||
<Compile Include="Framework\IInformationHandler.cs" />
|
||||
<Compile Include="Framework\LocationHandler.cs" />
|
||||
<Compile Include="ISaveCoreAPI.cs" />
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace UnifiedSaveCore.Framework
|
|||
Game1.locations.Add(loc);
|
||||
}
|
||||
locations.Clear();
|
||||
//Game1.warpFarmer(oldLocation.name, (int)position.X*Game1.tileSize, (int)position.Y*Game1.tileSize, oldFacingDirection);
|
||||
Game1.warpFarmer(oldLocation.name, (int)position.X/Game1.tileSize, (int)position.Y/Game1.tileSize, oldFacingDirection);
|
||||
}
|
||||
|
||||
//Removes all game locations for the game to save.
|
||||
|
@ -46,7 +46,7 @@ namespace UnifiedSaveCore.Framework
|
|||
oldFacingDirection = Game1.player.facingDirection;
|
||||
|
||||
Vector2 bed = Game1.player.mostRecentBed;
|
||||
//Game1.warpFarmer("Farmhouse", (int)bed.X, (int)bed.Y, 2);
|
||||
Game1.warpFarmer("Farmhouse", (int)bed.X/Game1.tileSize, (int)bed.Y/Game1.tileSize, 2);
|
||||
foreach (var loc in Game1.locations)
|
||||
{
|
||||
//UnifiedSaveCore.monitor.Log(loc.GetType().ToString());
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
using StardewValley;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace UnifiedSaveCore.Framework
|
||||
{
|
||||
public class NPCHandler:IInformationHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Deals with characters at specific locations.
|
||||
/// </summary>
|
||||
Dictionary<GameLocation, List<NPC>> characterLocations;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
public NPCHandler()
|
||||
{
|
||||
characterLocations = new Dictionary<GameLocation, List<NPC>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all custom characters before saving.
|
||||
/// </summary>
|
||||
public void beforeSave()
|
||||
{
|
||||
foreach (var loc in Game1.locations)
|
||||
{
|
||||
List<NPC> characters = new List<NPC>();
|
||||
foreach (var character in loc.characters)
|
||||
{
|
||||
foreach (Type t in UnifiedSaveCore.modTypes)
|
||||
{
|
||||
if (character.GetType().ToString() == t.ToString())
|
||||
{
|
||||
characters.Add(character);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
foreach (var character in characters)
|
||||
{
|
||||
loc.characters.Remove(character);
|
||||
}
|
||||
characterLocations.Add(loc, characters);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores all custom characters after saving.
|
||||
/// </summary>
|
||||
public void afterSave()
|
||||
{
|
||||
foreach(KeyValuePair<GameLocation,List<NPC>> pair in characterLocations)
|
||||
{
|
||||
foreach(var npc in pair.Value)
|
||||
{
|
||||
pair.Key.characters.Add(npc);
|
||||
}
|
||||
}
|
||||
characterLocations.Clear();
|
||||
}
|
||||
|
||||
public void afterLoad()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -75,6 +75,7 @@ namespace UnifiedSaveCore
|
|||
"xTile",
|
||||
};
|
||||
|
||||
//taken from attribute example.
|
||||
foreach (Assembly asm in assemblies)
|
||||
{
|
||||
|
||||
|
@ -127,13 +128,14 @@ namespace UnifiedSaveCore
|
|||
//Console.WriteLine("{0} VERSIONS: (A){1} (F){2} (P){3}", name, asmV, fileV, prodV);
|
||||
}
|
||||
|
||||
StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
|
||||
StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave;
|
||||
StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
|
||||
//StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
|
||||
//StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave;
|
||||
//StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
|
||||
saveCoreAPI = new SaveCoreAPI();
|
||||
|
||||
dataHandlers = new List<IInformationHandler>();
|
||||
dataHandlers.Add(new LocationHandler());
|
||||
dataHandlers.Add(new NPCHandler());
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue