fix map reloads not updating door warps (#643)

This commit is contained in:
Jesse Plamondon-Willard 2019-06-13 19:35:51 -04:00
parent 93551c0941
commit 31c882c8ce
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 31 additions and 1 deletions

View File

@ -19,6 +19,7 @@ These changes have not been released yet.
* Fixed lag in some cases due to incorrect asset caching when playing in non-English.
* Fixed lag when a mod invalidates many NPC portraits/sprites at once.
* Fixed map reloads resetting tilesheet seasons.
* Fixed map reloads not updating door warps.
* Fixed outdoor tilesheets being seasonalised when added to an indoor location.
* For modders:

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Framework.Reflection;
using StardewValley;
@ -14,6 +15,7 @@ using StardewValley.Objects;
using StardewValley.Projectiles;
using StardewValley.TerrainFeatures;
using xTile;
using xTile.ObjectModel;
using xTile.Tiles;
namespace StardewModdingAPI.Metadata
@ -138,10 +140,37 @@ namespace StardewModdingAPI.Metadata
{
if (!string.IsNullOrWhiteSpace(location.mapPath.Value) && this.GetNormalisedPath(location.mapPath.Value) == key)
{
// general updates
location.reloadMap();
location.updateSeasonalTileSheets();
location.updateWarps();
this.Reflection.GetField<InteriorDoorDictionary>(location, nameof(location.interiorDoors)).SetValue(new InteriorDoorDictionary(location));
// update interior doors
location.interiorDoors.Clear();
foreach (var entry in new InteriorDoorDictionary(location))
location.interiorDoors.Add(entry);
// update doors (derived from GameLocation.loadObjects)
location.doors.Clear();
for (int x = 0; x < location.map.Layers[0].LayerWidth; ++x)
{
for (int y = 0; y < location.map.Layers[0].LayerHeight; ++y)
{
if (location.map.GetLayer("Buildings").Tiles[x, y] != null)
{
location.map.GetLayer("Buildings").Tiles[x, y].Properties.TryGetValue("Action", out PropertyValue action);
if (action != null && action.ToString().Contains("Warp"))
{
string[] strArray = action.ToString().Split(' ');
if (strArray[0] == "WarpCommunityCenter")
location.doors.Add(new Point(x, y), "CommunityCenter");
else if ((location.Name != "Mountain" || x != 8 || y != 20) && strArray.Length > 2)
location.doors.Add(new Point(x, y), strArray[3]);
}
}
}
}
anyChanged = true;
}
}