mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-08-02 15:42:36 +00:00
Core - Add 'DLCPackageRegistry.cs'
This commit is contained in:
@@ -40,8 +40,7 @@ namespace PckStudio.Core.DLC
|
||||
/// </summary>
|
||||
public string PreferredLanguage { get; private set; }
|
||||
|
||||
private readonly IDictionary<int, IDLCPackage> _openPackages = new Dictionary<int, IDLCPackage>();
|
||||
private readonly IDictionary<int, LOCFile> _localisationFiles = new Dictionary<int, LOCFile>();
|
||||
private readonly DLCPackageRegistry _packageRegistry = new DLCPackageRegistry();
|
||||
private readonly Random _rng = new Random();
|
||||
private ByteOrder _byteOrder;
|
||||
private ConsolePlatform _platform;
|
||||
@@ -86,8 +85,7 @@ namespace PckStudio.Core.DLC
|
||||
LOCFile localisation = new LOCFile();
|
||||
localisation.AddLanguage(PreferredLanguage);
|
||||
localisation.AddLocKey(PACKAGE_DISPLAYNAME_ID, name);
|
||||
_localisationFiles.Add(identifier, localisation);
|
||||
_openPackages.Add(identifier, package);
|
||||
_packageRegistry.RegisterPackage(identifier, package, localisation);
|
||||
|
||||
return package;
|
||||
}
|
||||
@@ -121,8 +119,8 @@ namespace PckStudio.Core.DLC
|
||||
return new UnknownDLCPackage(fileInfo.Name, pckFile);
|
||||
}
|
||||
|
||||
if (_openPackages.ContainsKey(identifier))
|
||||
return _openPackages[identifier];
|
||||
if (_packageRegistry.ContainsPackage(identifier))
|
||||
return _packageRegistry[identifier];
|
||||
|
||||
LOCFile localisation = pckFile.GetAssetsByType(PckAssetType.LocalisationFile).FirstOrDefault()?.GetData(new LOCFileReader());
|
||||
if (localisation is null)
|
||||
@@ -131,15 +129,14 @@ namespace PckStudio.Core.DLC
|
||||
IDLCPackage package = ScanForPackageType(fileInfo, identifier, pckFile, localisation, fileReader);
|
||||
if (package.GetDLCPackageType() != DLCPackageType.Invalid)
|
||||
{
|
||||
_localisationFiles.Add(identifier, localisation);
|
||||
_openPackages.Add(identifier, package);
|
||||
_packageRegistry.RegisterPackage(identifier, package, localisation);
|
||||
}
|
||||
return package;
|
||||
}
|
||||
|
||||
internal LOCFile GetLocalisation(int identifier)
|
||||
{
|
||||
return _localisationFiles.ContainsKey(identifier) ? _localisationFiles[identifier] : default;
|
||||
return _packageRegistry.ContainsPackage(identifier) ? _packageRegistry.GetLocalisation(identifier) : default;
|
||||
}
|
||||
|
||||
private bool IsValidPckFile(FileInfo fileInfo)
|
||||
|
||||
33
PckStudio.Core/DLC/DLCPackageRegistry.cs
Normal file
33
PckStudio.Core/DLC/DLCPackageRegistry.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.Languages;
|
||||
using PckStudio.Core.Interfaces;
|
||||
|
||||
namespace PckStudio.Core.DLC
|
||||
{
|
||||
internal sealed class DLCPackageRegistry
|
||||
{
|
||||
private readonly IDictionary<int, IDLCPackage> _openPackages = new Dictionary<int, IDLCPackage>();
|
||||
private readonly IDictionary<int, LOCFile> _localisationFiles = new Dictionary<int, LOCFile>();
|
||||
|
||||
public IDLCPackage this[int id] => _openPackages[id];
|
||||
|
||||
public bool RegisterPackage(int identifier, IDLCPackage package, LOCFile localisation)
|
||||
{
|
||||
if (_openPackages.ContainsKey(identifier))
|
||||
return false;
|
||||
if (_localisationFiles.ContainsKey(identifier))
|
||||
_localisationFiles.Remove(identifier);
|
||||
_localisationFiles.Add(identifier, localisation);
|
||||
_openPackages.Add(identifier, package);
|
||||
return true;
|
||||
}
|
||||
|
||||
internal bool ContainsPackage(int identifier) => _openPackages.ContainsKey(identifier) && _localisationFiles.ContainsKey(identifier);
|
||||
|
||||
internal LOCFile GetLocalisation(int identifier) => _localisationFiles[identifier];
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,7 @@
|
||||
<Compile Include="DLC\DLCMashUpPackage.cs" />
|
||||
<Compile Include="DLC\DLCMiniGamePackage.cs" />
|
||||
<Compile Include="DLC\DLCPackage.cs" />
|
||||
<Compile Include="DLC\DLCPackageRegistry.cs" />
|
||||
<Compile Include="DLC\DLCSkinPackage.cs" />
|
||||
<Compile Include="DLC\DLCTexturePackage.cs" />
|
||||
<Compile Include="DLC\UnknownDLCPackage.cs" />
|
||||
|
||||
Reference in New Issue
Block a user