Use HashSet to store texture guids instead of List

This commit is contained in:
Slendy 2023-12-23 20:07:03 -06:00
commit b39038008d
No known key found for this signature in database
GPG key ID: 7288D68361B91428

View file

@ -1,5 +1,4 @@
using System.Collections.Immutable;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types.Logging;
using LBPUnion.ProjectLighthouse.Types.Resources;
@ -8,11 +7,10 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
public static class GameResourceHelper
{
private static readonly ImmutableList<string> textureGuids = ImmutableList<string>.Empty;
private static readonly HashSet<string> textureGuids = new();
static GameResourceHelper()
{
List<string> guids = new();
using Stream? guidStream = typeof(GameResourceHelper).Assembly.GetManifestResourceStream("LBPUnion.ProjectLighthouse.Servers.GameServer.textureGuids.txt");
if (guidStream == null)
{
@ -26,21 +24,17 @@ public static class GameResourceHelper
string? guid = reader.ReadLine();
if (guid == null) continue;
guids.Add(guid);
textureGuids.Add(guid);
}
textureGuids = ImmutableList.Create(guids.ToArray());
}
public static bool IsValidTexture(string resource)
{
if (!FileHelper.IsResourceValid(resource)) return false;
if (resource.StartsWith("g"))
{
return textureGuids.Contains(resource[1..]);
}
if (resource.StartsWith("g")) return textureGuids.Contains(resource[1..]);
return LbpFile.FromHash(resource)?.FileType is LbpFileType.Png or LbpFileType.Jpeg or LbpFileType.Plan
or LbpFileType.Painting or LbpFileType.Texture;
return LbpFile.FromHash(resource)?.FileType is LbpFileType.Png or LbpFileType.Jpeg or LbpFileType.Painting
or LbpFileType.Texture;
}
}