Skip to content

Commit

Permalink
Merge pull request #2586 from KABoissonneault/fix/worlddata-new-locat…
Browse files Browse the repository at this point in the history
…ion-caching

Fixed caching of new WorldData locations
  • Loading branch information
KABoissonneault authored Feb 19, 2024
2 parents e5528ba + e98bc06 commit bd11b24
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Assets/Scripts/Utility/AssetInjection/WorldDataReplacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static bool GetDFRegionAdditionalLocationData(int regionIndex, ref DFRegi
uint dataLocationCount = dfRegion.LocationCount;
List<string> mapNames = new List<string>(dfRegion.MapNames);
List<DFRegion.RegionMapTable> mapTable = new List<DFRegion.RegionMapTable>(dfRegion.MapTable);
bool newBlocksAssigned = false;
bool locationAssignmentSuccess = true;

// Seek from loose files
string locationPattern = string.Format("locationnew-*-{0}.json", regionIndex);
Expand All @@ -150,8 +150,9 @@ public static bool GetDFRegionAdditionalLocationData(int regionIndex, ref DFRegi
{
string locationReplacementJson = File.ReadAllText(Path.Combine(worldDataPath, fileName));
DFLocation dfLocation = (DFLocation)SaveLoadManager.Deserialize(typeof(DFLocation), locationReplacementJson);
newBlocksAssigned = AddLocationToRegion(regionIndex, ref dfRegion, ref mapNames, ref mapTable, ref dfLocation);
locationAssignmentSuccess &= AddLocationToRegion(regionIndex, ref dfRegion, ref mapNames, ref mapTable, ref dfLocation);
}

// Seek from mods
string locationExtension = string.Format("-{0}.json", regionIndex);
List<TextAsset> assets = ModManager.Instance.FindAssets<TextAsset>(worldData, locationExtension);
Expand All @@ -162,10 +163,11 @@ public static bool GetDFRegionAdditionalLocationData(int regionIndex, ref DFRegi
if (locationReplacementJsonAsset.name.StartsWith("locationnew-"))
{
DFLocation dfLocation = (DFLocation)SaveLoadManager.Deserialize(typeof(DFLocation), locationReplacementJsonAsset.text);
newBlocksAssigned &= AddLocationToRegion(regionIndex, ref dfRegion, ref mapNames, ref mapTable, ref dfLocation);
locationAssignmentSuccess &= AddLocationToRegion(regionIndex, ref dfRegion, ref mapNames, ref mapTable, ref dfLocation);
}
}
}

// If found any new locations for this region,
if (dfRegion.LocationCount > dataLocationCount)
{
Expand All @@ -174,11 +176,13 @@ public static bool GetDFRegionAdditionalLocationData(int regionIndex, ref DFRegi
dfRegion.MapTable = mapTable.ToArray();

#if !UNITY_EDITOR // Cache region data for added locations if new blocks have been assigned indices (unless running in editor)
if (newBlocksAssigned)
if (locationAssignmentSuccess)
regions.Add(regionIndex, dfRegion);
#endif

Debug.LogFormat("Added {0} new DFLocation's to region {1}, indexes: {2} - {3}",
dfRegion.LocationCount - dataLocationCount, regionIndex, dataLocationCount, dfRegion.LocationCount-1);

return true;
}

Expand Down

0 comments on commit bd11b24

Please sign in to comment.