From 43c9a42d47daf49adac88d7aae09d2c5e85d39d5 Mon Sep 17 00:00:00 2001 From: CWX Date: Wed, 5 Feb 2025 06:39:41 +0000 Subject: [PATCH] added alternative keys to mapping of location, should be able to resolve all types we deal with then --- Libraries/Core/Models/Spt/Server/Locations.cs | 45 ++++++++++++++++--- Libraries/Core/Services/PostDbLoadService.cs | 5 ++- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/Libraries/Core/Models/Spt/Server/Locations.cs b/Libraries/Core/Models/Spt/Server/Locations.cs index 200c700a..512df15b 100644 --- a/Libraries/Core/Models/Spt/Server/Locations.cs +++ b/Libraries/Core/Models/Spt/Server/Locations.cs @@ -66,28 +66,39 @@ public record Locations private Dictionary? _locationDictionaryCache; /// - /// Get map locations as a dictionary, keyed by its name e.g. factory4_day + /// Get map locations as a dictionary, keyed by its name e.g. Factory4Day /// /// public Dictionary GetDictionary() { if (_locationDictionaryCache is null) - { - var classProps = typeof(Locations).GetProperties().Where(p => p.PropertyType == typeof(Eft.Common.Location) && p.Name != "Item"); - _locationDictionaryCache = classProps - .ToDictionary(propertyInfo => propertyInfo.Name, propertyInfo => propertyInfo.GetValue(this, null) as Eft.Common.Location); - } + HydrateDictionary(); return _locationDictionaryCache; } + /// + /// Convert any type of key to Locations actual Property name. + /// "factory4_day" or "Factory4Day" returns "Factory4Day" + /// + /// public string GetMappedKey(string key) { return _locationMappings.TryGetValue(key, out var value) ? value : key; } + private void HydrateDictionary() + { + var classProps = typeof(Locations).GetProperties().Where(p => p.PropertyType == typeof(Eft.Common.Location) && p.Name != "Item"); + _locationDictionaryCache = classProps + .ToDictionary(propertyInfo => propertyInfo.Name, propertyInfo => propertyInfo.GetValue(this, null) as Eft.Common.Location); + } + + // sometimes we get the key or value given so save changing logic in each place + // have it key both private Dictionary _locationMappings = new() { + // EFT { "factory4_day", "Factory4Day" }, { "bigmap", "Bigmap" }, { "develop", "Develop" }, @@ -105,6 +116,26 @@ public record Locations { "town", "Town" }, { "woods", "Woods" }, { "sandbox", "Sandbox" }, - { "sandbox_high", "SandboxHigh" } + { "sandbox_high", "SandboxHigh" }, + + // SPT + { "Factory4Day", "Factory4Day" }, + { "Bigmap", "Bigmap" }, + { "Develop", "Develop" }, + { "Factory4Night", "Factory4Night" }, + { "Hideout", "Hideout" }, + { "Interchange", "Interchange" }, + { "Laboratory", "Laboratory" }, + { "Lighthouse", "Lighthouse" }, + { "PrivateArea", "PrivateArea" }, + { "RezervBase", "RezervBase" }, + { "Shoreline", "Shoreline" }, + { "Suburbs", "Suburbs" }, + { "TarkovStreets", "TarkovStreets" }, + { "Terminal", "Terminal" }, + { "Town", "Town" }, + { "Woods", "Woods" }, + { "Sandbox", "Sandbox" }, + { "SandboxHigh", "SandboxHigh" } }; } diff --git a/Libraries/Core/Services/PostDbLoadService.cs b/Libraries/Core/Services/PostDbLoadService.cs index 2516c37d..f5b7a322 100644 --- a/Libraries/Core/Services/PostDbLoadService.cs +++ b/Libraries/Core/Services/PostDbLoadService.cs @@ -287,9 +287,10 @@ public class PostDbLoadService( // TODO: CWX Change the way we get Maps protected void AdjustLocationBotValues() { - var mapsDb = _databaseService.GetLocations().GetDictionary(); + var mapsDb = _databaseService.GetLocations(); + var mapsDict = mapsDb.GetDictionary(); foreach (var (key, cap) in _botConfig.MaxBotCap) { - if (!mapsDb.TryGetValue(_databaseService.GetLocations().GetMappedKey(key), out var map)) + if (!mapsDict.TryGetValue(mapsDb.GetMappedKey(key), out var map)) { continue; }