Skip to content
Open
Changes from 1 commit
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
24 changes: 19 additions & 5 deletions Assets/Scripts/Utility/AssetInjection/WorldDataReplacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,18 +571,32 @@ public static void AssignNewIndex(string blockName)
// If jsonBlockIndex is invalid (less than or equal to nextBlockIndex), use fallback method
if (jsonBlockIndex <= nextBlockIndex)
{
int newIndex = nextBlockIndex;

AssignNextIndex(blockName);

// Cache the full DFBlock
if (!blocks.ContainsKey(blockKey))
blocks[blockKey] = dfBlock.Value;
{
// Update DFBlock index
DFBlock block = dfBlock.Value;
block.Index = newIndex;
blocks[blockKey] = block;
}

return;
}

// Add to cache
newBlockNames[jsonBlockIndex] = blockName;
newBlockIndices[blockName] = jsonBlockIndex;
// Add to cache, but if that jsonBlockIndex or blockName is already taken, fallback again
if (newBlockNames.ContainsKey(jsonBlockIndex) || newBlockIndices.ContainsKey(blockName))
{
AssignNextIndex(blockName);
}
else
{
newBlockNames[jsonBlockIndex] = blockName;
newBlockIndices[blockName] = jsonBlockIndex;
}

Copy link
Contributor

@TwelveEyes TwelveEyes Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably better to handle this up above, since in the fallback the new index still has to be updated in the cached DFBlock:

diff --git a/Assets/Scripts/Utility/AssetInjection/WorldDataReplacement.cs b/Assets/Scripts/Utility/AssetInjection/WorldDataReplacement.cs
index 73875e6e4..18e033bcc 100644
--- a/Assets/Scripts/Utility/AssetInjection/WorldDataReplacement.cs
+++ b/Assets/Scripts/Utility/AssetInjection/WorldDataReplacement.cs
@@ -624,8 +624,8 @@ namespace DaggerfallWorkshop.Utility.AssetInjection
             // Check for the "Index" field and assign its value
             jsonBlockIndex = dfBlock.Value.Index;
 
-            // If jsonBlockIndex is invalid (less than or equal to nextBlockIndex), use fallback method
-            if (jsonBlockIndex <= nextBlockIndex)
+            // If jsonBlockIndex is invalid (less than or equal to nextBlockIndex) or index is already taken, use fallback method
+            if (jsonBlockIndex <= nextBlockIndex || newBlockNames.ContainsKey(jsonBlockIndex) || newBlockIndices.ContainsKey(blockName))
             {
                 int newIndex = nextBlockIndex;

Other than that, looks good!

Debug.LogFormat("Found a new DFBlock: {0}, (assigned index: {1})", blockName, jsonBlockIndex);

// Cache the full DFBlock
Expand Down