Skip to content

Commit 45557be

Browse files
committed
Fix for concurrency in ReduceEmbeddedTexturePages
1 parent 8eae0ec commit 45557be

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

UndertaleModTool/Scripts/Resource Importers/ReduceEmbeddedTexturePages.csx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using System;
66
using System.IO;
77
using System.Collections;
88
using System.Collections.Generic;
9+
using System.Collections.Concurrent;
910
using System.Linq;
1011
using System.Text;
1112
using System.Threading;
@@ -28,8 +29,8 @@ foreach (DirectoryInfo di in dir.GetDirectories())
2829

2930
string exportedTexturesFolder = Path.Combine(dir.FullName, "Textures");
3031
TextureWorker worker = null;
31-
Dictionary<string, int[]> assetCoordinateDict = new();
32-
Dictionary<string, string> assetTypeDict = new();
32+
ConcurrentDictionary<string, int[]> assetCoordinateDict = new();
33+
ConcurrentDictionary<string, string> assetTypeDict = new();
3334
using (worker = new())
3435
{
3536
Directory.CreateDirectory(exportedTexturesFolder);
@@ -70,8 +71,8 @@ void DumpSprite(UndertaleSprite sprite)
7071
{
7172
UndertaleTexturePageItem tex = sprite.Textures[i].Texture;
7273
worker.ExportAsPNG(tex, Path.Combine(exportedTexturesFolder, $"{sprite.Name.Content}_{i}.png"));
73-
assetCoordinateDict.Add($"{sprite.Name.Content}_{i}", new int[] { tex.TargetX, tex.TargetY, tex.SourceWidth, tex.SourceHeight, tex.TargetWidth, tex.TargetHeight, tex.BoundingWidth, tex.BoundingHeight });
74-
assetTypeDict.Add($"{sprite.Name.Content}_{i}", "spr");
74+
assetCoordinateDict.TryAdd($"{sprite.Name.Content}_{i}", new int[] { tex.TargetX, tex.TargetY, tex.SourceWidth, tex.SourceHeight, tex.TargetWidth, tex.TargetHeight, tex.BoundingWidth, tex.BoundingHeight });
75+
assetTypeDict.TryAdd($"{sprite.Name.Content}_{i}", "spr");
7576
}
7677
}
7778
}
@@ -87,8 +88,8 @@ void DumpFont(UndertaleFont font)
8788
{
8889
UndertaleTexturePageItem tex = font.Texture;
8990
worker.ExportAsPNG(tex, Path.Combine(exportedTexturesFolder, $"{font.Name.Content}.png"));
90-
assetCoordinateDict.Add(font.Name.Content, new int[] { tex.TargetX, tex.TargetY, tex.SourceWidth, tex.SourceHeight, tex.TargetWidth, tex.TargetHeight, tex.BoundingWidth, tex.BoundingHeight });
91-
assetTypeDict.Add(font.Name.Content, "fnt");
91+
assetCoordinateDict.TryAdd(font.Name.Content, new int[] { tex.TargetX, tex.TargetY, tex.SourceWidth, tex.SourceHeight, tex.TargetWidth, tex.TargetHeight, tex.BoundingWidth, tex.BoundingHeight });
92+
assetTypeDict.TryAdd(font.Name.Content, "fnt");
9293

9394
IncrementProgressParallel();
9495
}
@@ -102,8 +103,8 @@ void DumpBackground(UndertaleBackground background)
102103
{
103104
UndertaleTexturePageItem tex = background.Texture;
104105
worker.ExportAsPNG(tex, Path.Combine(exportedTexturesFolder, $"{background.Name.Content}.png"));
105-
assetCoordinateDict.Add(background.Name.Content, new int[] { tex.TargetX, tex.TargetY, tex.SourceWidth, tex.SourceHeight, tex.TargetWidth, tex.TargetHeight, tex.BoundingWidth, tex.BoundingHeight });
106-
assetTypeDict.Add(background.Name.Content, "bg");
106+
assetCoordinateDict.TryAdd(background.Name.Content, new int[] { tex.TargetX, tex.TargetY, tex.SourceWidth, tex.SourceHeight, tex.TargetWidth, tex.TargetHeight, tex.BoundingWidth, tex.BoundingHeight });
107+
assetTypeDict.TryAdd(background.Name.Content, "bg");
107108
IncrementProgressParallel();
108109
}
109110
}

0 commit comments

Comments
 (0)