Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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