.NET Format Style Fixes

This commit is contained in:
refringe
2025-06-18 17:09:20 +00:00
committed by Format Bot
parent ca0a7d6345
commit 6e01428b2b
774 changed files with 23507 additions and 40003 deletions
@@ -28,13 +28,13 @@ public class HideoutCraftQuestIdGenerator(
"66140c4a9688754de10dac07", // Old event quest production "Documents with decrypted data"
"661e6c26750e453380391f55", // Old event quest production "Documents with decrypted data"
"660c2dbaa2a92e70cc074863", // Old event quest production "Decrypted flash drive"
"67093210d514d26f8408612b" // Old event quest production "TG-Vi-24 true vaccine"
"67093210d514d26f8408612b", // Old event quest production "TG-Vi-24 true vaccine"
];
private static readonly Dictionary<string, string> _forcedQuestToProductionAssociations = new()
{
// KEY = PRODUCTION, VALUE = QUEST
{ "63a571802116d261d2336cd1", "625d6ffaf7308432be1d44c5" } // Network Provider - Part 2
{ "63a571802116d261d2336cd1", "625d6ffaf7308432be1d44c5" }, // Network Provider - Part 2
};
private readonly Dictionary<string, string> _questProductionMap = new();
@@ -50,10 +50,14 @@ public class HideoutCraftQuestIdGenerator(
// Figure out our source and target directories
var projectDir = Directory.GetParent("./").Parent.Parent.Parent.Parent.Parent;
const string productionPath = "Libraries\\SPTarkov.Server.Assets\\Assets\\database\\hideout\\production.json";
const string productionPath =
"Libraries\\SPTarkov.Server.Assets\\Assets\\database\\hideout\\production.json";
var productionFilePath = Path.Combine(projectDir.FullName, productionPath);
var updatedProductionJson = _jsonUtil.Serialize(_databaseServer.GetTables().Hideout.Production, true);
var updatedProductionJson = _jsonUtil.Serialize(
_databaseServer.GetTables().Hideout.Production,
true
);
_fileUtil.WriteFile(productionFilePath, updatedProductionJson);
}
@@ -62,7 +66,9 @@ public class HideoutCraftQuestIdGenerator(
{
foreach (var (questId, quest) in _databaseServer.GetTables().Templates.Quests)
{
var combinedRewards = CombineRewards(quest.Rewards).Where(x => x.Type == RewardType.ProductionScheme).ToList();
var combinedRewards = CombineRewards(quest.Rewards)
.Where(x => x.Type == RewardType.ProductionScheme)
.ToList();
foreach (var reward in combinedRewards)
{
// Assume all productions only output a single item template
@@ -70,7 +76,7 @@ public class HideoutCraftQuestIdGenerator(
{
QuestId = questId,
ItemTemplate = reward.Items[0].Template,
Quantity = 0
Quantity = 0,
};
// Loop over root items only, ignore children
@@ -79,8 +85,8 @@ public class HideoutCraftQuestIdGenerator(
if (item.Template != output.ItemTemplate)
{
_logger.Error(
$"Production scheme has multiple output items. " +
$"{output.ItemTemplate} != {item.Template}"
$"Production scheme has multiple output items. "
+ $"{output.ItemTemplate} != {item.Template}"
);
continue;
@@ -106,7 +112,9 @@ public class HideoutCraftQuestIdGenerator(
}
// Look for a 'quest completion' requirement
var questCompleteRequirements = production.Requirements.Where(req => req.Type == "QuestComplete").ToList();
var questCompleteRequirements = production
.Requirements.Where(req => req.Type == "QuestComplete")
.ToList();
if (questCompleteRequirements.Count == 0)
{
// Production has no quest requirement
@@ -115,14 +123,21 @@ public class HideoutCraftQuestIdGenerator(
if (questCompleteRequirements.Count > 1)
{
_logger.Error($"Error, production: {production.Id} contains multiple QuestComplete requirements");
_logger.Error(
$"Error, production: {production.Id} contains multiple QuestComplete requirements"
);
// Production has no multiple quest requirements
continue;
}
// Check for forced ids
if (_forcedQuestToProductionAssociations.TryGetValue(production.Id, out var associatedQuestIdToComplete))
if (
_forcedQuestToProductionAssociations.TryGetValue(
production.Id,
out var associatedQuestIdToComplete
)
)
{
// Found one, move to next production
_logger.Success(
@@ -134,13 +149,21 @@ public class HideoutCraftQuestIdGenerator(
}
// Try to find the quest that matches this production
var questProductionOutputs = _questProductionOutputList.Where(output =>
output.ItemTemplate == production.EndProduct && output.Quantity == production.Count
var questProductionOutputs = _questProductionOutputList
.Where(output =>
output.ItemTemplate == production.EndProduct
&& output.Quantity == production.Count
)
.ToList();
// Make sure we found valid data
if (!IsValidQuestProduction(production, questProductionOutputs, questCompleteRequirements[0]))
if (
!IsValidQuestProduction(
production,
questProductionOutputs,
questCompleteRequirements[0]
)
)
{
continue;
}
@@ -154,8 +177,11 @@ public class HideoutCraftQuestIdGenerator(
}
}
private bool IsValidQuestProduction(HideoutProduction production,
List<QuestProductionOutput> questProductionOutputs, Requirement questComplete)
private bool IsValidQuestProduction(
HideoutProduction production,
List<QuestProductionOutput> questProductionOutputs,
Requirement questComplete
)
{
// A lot of error handling for edge cases
if (!questProductionOutputs.Any())
@@ -174,7 +200,10 @@ public class HideoutCraftQuestIdGenerator(
return false;
}
if (questComplete.QuestId is not null && questComplete.QuestId != questProductionOutputs[0].QuestId)
if (
questComplete.QuestId is not null
&& questComplete.QuestId != questProductionOutputs[0].QuestId
)
{
_logger.Error(
$"Multiple productions match quest.EndProduct {production.EndProduct} with quantity {production.Count}, existing quest: {questComplete.QuestId}"
@@ -211,21 +240,9 @@ public class HideoutCraftQuestIdGenerator(
public class QuestProductionOutput
{
public string QuestId
{
get;
set;
}
public string QuestId { get; set; }
public string ItemTemplate
{
get;
set;
}
public string ItemTemplate { get; set; }
public double Quantity
{
get;
set;
}
public double Quantity { get; set; }
}
@@ -1,19 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\Build.props"/>
<Import Project="..\..\Build.props" />
<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<ImplicitUsings>enable</ImplicitUsings>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\SPTarkov.Server.Core\SPTarkov.Server.Core.csproj"/>
<ProjectReference Include="..\..\Libraries\SPTarkov.Server.Assets\SPTarkov.Server.Assets.csproj"/>
<ProjectReference Include="..\..\Libraries\SPTarkov.Common\SPTarkov.Common.csproj"/>
<ProjectReference Include="..\..\Libraries\SPTarkov.DI\SPTarkov.DI.csproj"/>
<ProjectReference Include="..\..\Libraries\SPTarkov.Server.Core\SPTarkov.Server.Core.csproj" />
<ProjectReference Include="..\..\Libraries\SPTarkov.Server.Assets\SPTarkov.Server.Assets.csproj" />
<ProjectReference Include="..\..\Libraries\SPTarkov.Common\SPTarkov.Common.csproj" />
<ProjectReference Include="..\..\Libraries\SPTarkov.DI\SPTarkov.DI.csproj" />
</ItemGroup>
</Project>
@@ -12,7 +12,9 @@ public class HideoutCraftQuestIdGeneratorLauncher
{
var serviceCollection = new ServiceCollection();
var diHandler = new DependencyInjectionHandler(serviceCollection);
diHandler.AddInjectableTypesFromTypeAssembly(typeof(HideoutCraftQuestIdGeneratorLauncher));
diHandler.AddInjectableTypesFromTypeAssembly(
typeof(HideoutCraftQuestIdGeneratorLauncher)
);
diHandler.AddInjectableTypesFromTypeAssembly(typeof(App));
diHandler.InjectAll();
var serviceProvider = serviceCollection.BuildServiceProvider();
@@ -15,8 +15,12 @@ public class SptBasicLogger<T> : ISptLogger<T>
categoryName = typeof(T).Name;
}
public void LogWithColor(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null,
Exception? ex = null)
public void LogWithColor(
string data,
LogTextColor? textColor = null,
LogBackgroundColor? backgroundColor = null,
Exception? ex = null
)
{
Console.WriteLine($"{categoryName}: {data}");
}
+1 -14
View File
@@ -10,23 +10,19 @@ public class ItemOverrides
// Stashes
{ "5963866b86f7747bfa1c4462", "QuestOffline" },
{ "5963866286f7747bf429b572", "QuestRaid" },
// Usables
{ "614451b71e5874611e2c7ae5", "Bottle of Tarkovskaya vodka (Bad)" },
// Special
{ "557ffd194bdc2d28148b457f", "Pockets 1x4" },
{ "627a4e6b255f7527fb05a0f6", "Pockets 1x4 Special" },
{ "65e080be269cbd5c5005e529", "Pockets 1x4 TUE" },
{ "64cbd95a29b9b4283e216ff5", "Pockets 2x3" },
{ "665ee77ccf2d642e98220bca", "Secure container Gamma TUE" },
// Misc
{ "6662e9f37fa79a6d83730fa0", "Dogtag USEC EOD" },
{ "6662ea05f6259762c56f3189", "Dogtag USEC TUE" },
{ "6662e9aca7e0b43baa3d5f74", "Dogtag BEAR EOD" },
{ "6662e9cda7e0b43baa3d5f76", "Dogtag BEAR TUE" },
// Quest Items
{ "590de92486f77423d9312a33", "Watch Gold" },
{ "5937fc6786f7742cab753590", "Watch Silver" },
@@ -70,7 +66,6 @@ public class ItemOverrides
{ "661421c7c1f2f548c50ee649", "Unheard laptop" },
{ "661423200d240a5f5d0f679b", "Unheard laptop 2" },
{ "66a0f0926fee20fa70036da6", "Quest blood sample nf2024" },
// Weapon Parts
{ "5d1340b3d7ad1a0b52682ed7", "GEN M3 FDE" },
{ "55802d5f4bdc2dac148b458e", "GEN M3 Window" },
@@ -80,30 +75,25 @@ public class ItemOverrides
{ "5e21a3c67e40bd02257a008a", "GEN M3 Banana" },
{ "6241c2c2117ad530666a5108", "GEN M3 AIRSOFT" },
{ "61840d85568c120fdd2962a5", "MK16 FDE" },
// Lootable Containers
{ "5914944186f774189e5e76c2", "Jacket 204Key" },
{ "5937ef2b86f77408a47244b3", "Jacket MachineryKey" },
{ "59387ac686f77401442ddd61", "Jacket 114Key" },
{ "61aa1e9a32a4743c3453d2cf", "Duffle bag Adv" },
{ "61aa1ead84ea0800645777fd", "Medbag SMU06 Adv" },
// Storage Containers
{ "5b6d9ce188a4501afc1b2b25", "THICC Weapon case" },
{ "5c0a840b86f7742ffa4f2482", "THICC Item case" },
{ "5d235bb686f77443f4331278", "SICC" },
{ "61aa1e6984ea0800645777f9", "Long Weapon Box" },
// Grenade launchers, they are weird, so just number them
{ "5e81ebcd8e146c7080625e15", "FN40GL 01" },
{ "639c3fbbd0446708ee622ee9", "FN40GL 02" },
{ "639af924d0446708ee62294e", "FN40GL 03" },
// Airdrop crates
{ "66da1b49099cf6adcc07a36b", "Airdrop technical supply crate event 1" },
{ "66da1b546916142b3b022777", "Airdrop technical supply crate event 2" },
{ "61a89e5445a2672acf66c877", "Airdrop technical supply crate event 3" },
// Posters
{ "6759e7a44ff23436160d7ff5", "Girl poster 4" },
{ "6759e8b1c3102563bd01c985", "Girl poster 5" },
@@ -111,20 +101,17 @@ public class ItemOverrides
{ "675a046b8f547d6cae01922e", "Arena poster 2" },
{ "6759e61067c8eb5cd10352f1", "Girl poster 2" },
{ "6759e6c39422e1708e0e9b81", "Girl poster 3" },
// Keys
{ "63a71f1a0aa9fb29da61c537", "City key 26" },
{ "590de52486f774226a0c24c2", "Machinery tech key" },
{ "590de4a286f77423d9312a32", "Folding automobile key" },
{ "63a39e0f64283b5e9c56b282", "City key x" },
{ "67499d2c69a58fceba104a43", "Lightkeeper btr quest rpg ammo case" },
{ "67499d4deca8acb2d206163b", "BTR quest electronic jamming device" },
{ "6764207f2fa5e32733055c4a", "Dogtag USEC Prestige 1" },
{ "675dc9d37ae1a8792107ca96", "Dogtag BEAR Prestige 1" },
{ "675dcb0545b1a2d108011b2b", "Dogtag BEAR Prestige 2" },
{ "6764202ae307804338014c1a", "Dogtag USEC Prestige 2" }
{ "6764202ae307804338014c1a", "Dogtag USEC Prestige 2" },
}
);
}
+52 -26
View File
@@ -44,7 +44,13 @@ public class ItemTplGenerator(
// Figure out our source and target directories
var projectDir = Directory.GetParent("./").Parent.Parent.Parent.Parent.Parent;
enumDir = Path.Combine(projectDir.FullName, "Libraries", "SPTarkov.Server.Core", "Models", "Enums");
enumDir = Path.Combine(
projectDir.FullName,
"Libraries",
"SPTarkov.Server.Core",
"Models",
"Enums"
);
items = _databaseServer.GetTables().Templates.Items;
// Generate an object containing all item name to ID associations
@@ -57,7 +63,7 @@ public class ItemTplGenerator(
itemTplOutPath,
new Dictionary<string, Dictionary<string, string>>
{
{ nameof(ItemTpl), orderedItemsObject }
{ nameof(ItemTpl), orderedItemsObject },
}
);
@@ -69,7 +75,7 @@ public class ItemTplGenerator(
weaponTypeOutPath,
new Dictionary<string, Dictionary<string, string>>
{
{ nameof(Weapons), weaponsObject }
{ nameof(Weapons), weaponsObject },
}
);
@@ -97,9 +103,11 @@ public class ItemTplGenerator(
var itemSuffix = GetItemSuffix(item);
// Handle the case where the item starts with the parent category name. Avoids things like 'POCKETS_POCKETS'
if (itemName.Length > itemParentName.Length &&
itemParentName == itemName.Substring(1, itemParentName.Length) &&
itemPrefix == "")
if (
itemName.Length > itemParentName.Length
&& itemParentName == itemName.Substring(1, itemParentName.Length)
&& itemPrefix == ""
)
{
itemName = itemName.Substring(itemParentName.Length + 1);
if (itemName.Length > 0 && itemName[0] != '_')
@@ -109,8 +117,10 @@ public class ItemTplGenerator(
}
// Handle the case where the item ends with the parent category name. Avoids things like 'KEY_DORM_ROOM_103_KEY'
if (itemName.Length >= itemParentName.Length &&
itemParentName == itemName.Substring(itemName.Length - itemParentName.Length))
if (
itemName.Length >= itemParentName.Length
&& itemParentName == itemName.Substring(itemName.Length - itemParentName.Length)
)
{
itemName = itemName.Substring(0, itemName.Length - itemParentName.Length);
@@ -160,7 +170,9 @@ public class ItemTplGenerator(
else
{
var val = itemsObject.ContainsKey(itemKey) ? itemsObject[itemKey] : itemKey;
_logger.Error($"New itemOverride entry required: itemsObject already contains {itemKey} {val} => {item.Id}");
_logger.Error(
$"New itemOverride entry required: itemsObject already contains {itemKey} {val} => {item.Id}"
);
continue;
}
}
@@ -178,7 +190,10 @@ public class ItemTplGenerator(
private Dictionary<string, string> GenerateWeaponsObject()
{
var weaponsObject = new Dictionary<string, string>();
foreach (var kv /*[itemId, item]*/ in items)
foreach (
var kv /*[itemId, item]*/
in items
)
{
if (!_itemHelper.IsOfBaseclass(kv.Key, BaseClasses.WEAPON))
{
@@ -196,8 +211,10 @@ public class ItemTplGenerator(
// Include any bracketed suffixes that exist, handles the case of colored gun variants
var weaponFullName = _localeService.GetLocaleDb()[$"{kv.Key} Name"]?.ToUpper();
if (weaponFullName.RegexMatch(@"\((.+?)\)$", out var itemNameBracketSuffix) &&
!weaponShortName.EndsWith(itemNameBracketSuffix.Groups[1].Value))
if (
weaponFullName.RegexMatch(@"\((.+?)\)$", out var itemNameBracketSuffix)
&& !weaponShortName.EndsWith(itemNameBracketSuffix.Groups[1].Value)
)
{
weaponShortName += $"_{itemNameBracketSuffix.Groups[1].Value}";
}
@@ -233,10 +250,7 @@ public class ItemTplGenerator(
/// <returns>The sanitized enum key</returns>
private string SanitizeEnumKey(string enumKey)
{
return enumKey
.ToUpper()
.RegexReplace("[^A-Z0-9_]", "")
.RegexReplace("_+", "_");
return enumKey.ToUpper().RegexReplace("[^A-Z0-9_]", "").RegexReplace("_+", "_");
}
private string GetParentName(TemplateItem item)
@@ -406,14 +420,18 @@ public class ItemTplGenerator(
private string GetAmmoBoxPrefix(TemplateItem item)
{
var ammoItem = item.Properties?.StackSlots?[0]?.Props?.Filters?[0]?.Filter?.FirstOrDefault();
var ammoItem = item.Properties?.StackSlots?[0]?.Props?.Filters?[
0
]?.Filter?.FirstOrDefault();
return GetAmmoPrefix(items[ammoItem]);
}
private string GetMagazinePrefix(TemplateItem item)
{
var ammoItem = item.Properties?.Cartridges?[0]?.Props?.Filters?[0]?.Filter?.FirstOrDefault();
var ammoItem = item.Properties?.Cartridges?[0]?.Props?.Filters?[
0
]?.Filter?.FirstOrDefault();
return GetAmmoPrefix(items[ammoItem]);
}
@@ -437,18 +455,19 @@ public class ItemTplGenerator(
else if (
_itemHelper.IsOfBaseclasses(
item.Id,
[
BaseClasses.RANDOM_LOOT_CONTAINER,
BaseClasses.BUILT_IN_INSERTS,
BaseClasses.STASH
]
[BaseClasses.RANDOM_LOOT_CONTAINER, BaseClasses.BUILT_IN_INSERTS, BaseClasses.STASH]
)
)
{
itemName = item.Name.ToUpper();
}
// For the listed types, use the short name
else if (_itemHelper.IsOfBaseclasses(item.Id, [BaseClasses.AMMO, BaseClasses.AMMO_BOX, BaseClasses.MAGAZINE]))
else if (
_itemHelper.IsOfBaseclasses(
item.Id,
[BaseClasses.AMMO, BaseClasses.AMMO_BOX, BaseClasses.MAGAZINE]
)
)
{
if (localeDb.TryGetValue($"{item.Id} ShortName", out itemName))
{
@@ -536,7 +555,11 @@ public class ItemTplGenerator(
return "";
}
private void LogEnumValueChanges(Dictionary<string, string> data, string enumName, Type originalEnum)
private void LogEnumValueChanges(
Dictionary<string, string> data,
string enumName,
Type originalEnum
)
{
// First generate a mapping of the original enum values to names
var originalEnumValues = new Dictionary<string, string>();
@@ -557,7 +580,10 @@ public class ItemTplGenerator(
}
}
private void WriteEnumsToFile(string outputPath, Dictionary<string, Dictionary<string, string>> enumEntries)
private void WriteEnumsToFile(
string outputPath,
Dictionary<string, Dictionary<string, string>> enumEntries
)
{
var enumFileData =
"// This is an auto generated file, do not modify. Re-generate by running ItemTplGenerator.exe";
@@ -1,19 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\Build.props"/>
<Import Project="..\..\Build.props" />
<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<ImplicitUsings>enable</ImplicitUsings>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\SPTarkov.Server.Core\SPTarkov.Server.Core.csproj"/>
<ProjectReference Include="..\..\Libraries\SPTarkov.Server.Assets\SPTarkov.Server.Assets.csproj"/>
<ProjectReference Include="..\..\Libraries\SPTarkov.Common\SPTarkov.Common.csproj"/>
<ProjectReference Include="..\..\Libraries\SPTarkov.DI\SPTarkov.DI.csproj"/>
<ProjectReference Include="..\..\Libraries\SPTarkov.Server.Core\SPTarkov.Server.Core.csproj" />
<ProjectReference Include="..\..\Libraries\SPTarkov.Server.Assets\SPTarkov.Server.Assets.csproj" />
<ProjectReference Include="..\..\Libraries\SPTarkov.Common\SPTarkov.Common.csproj" />
<ProjectReference Include="..\..\Libraries\SPTarkov.DI\SPTarkov.DI.csproj" />
</ItemGroup>
</Project>
+6 -2
View File
@@ -15,8 +15,12 @@ public class SptBasicLogger<T> : ISptLogger<T>
categoryName = typeof(T).Name;
}
public void LogWithColor(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null,
Exception? ex = null)
public void LogWithColor(
string data,
LogTextColor? textColor = null,
LogBackgroundColor? backgroundColor = null,
Exception? ex = null
)
{
Console.WriteLine($"{categoryName}: {data}");
}
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -4,16 +4,19 @@ namespace JsonExtensionDataGenerator;
public class JsonExtensionDataGeneratorLauncher
{
private static readonly Regex _recordAndClassRegex = new("^(public record |public class )", RegexOptions.Multiline);
private static readonly Regex _recordAndClassRegex = new(
"^(public record |public class )",
RegexOptions.Multiline
);
private static readonly Regex _endRecordClassRegex = new("^}", RegexOptions.Multiline);
private static readonly Regex _startRecordClassRegex = new("^{", RegexOptions.Multiline);
private const int StartRecordClassOffset = 3;
private static readonly Regex _extensionFinding =
new(
// https://regexr.com/8f5gf
"^(public){0,1} (record|class) (\\w+(<(\\w+(,){0,1})+>){0,1})(\\(.*\\)){0,1}[\r\n ]*:[\r\n ]*(\\w+(<(\\w+(,){0,1})+>){0,1}([\r\n ]*,[\r\n ]*)*)+"
, RegexOptions.Multiline);
private static readonly Regex _extensionFinding = new(
// https://regexr.com/8f5gf
"^(public){0,1} (record|class) (\\w+(<(\\w+(,){0,1})+>){0,1})(\\(.*\\)){0,1}[\r\n ]*:[\r\n ]*(\\w+(<(\\w+(,){0,1})+>){0,1}([\r\n ]*,[\r\n ]*)*)+",
RegexOptions.Multiline
);
private static readonly Regex _extensionCleanup = new(",.*");
@@ -22,7 +25,6 @@ public class JsonExtensionDataGeneratorLauncher
private const string Using = "using System.Text.Json.Serialization;\r\n";
public static void Main(string[] args)
{
var modelFiles = LoadModelFiles();
@@ -39,13 +41,17 @@ public class JsonExtensionDataGeneratorLauncher
var content = File.ReadAllText(modelFile);
if (!content.Contains("public record ") && !content.Contains("public class "))
{
Console.WriteLine($"File {fileName} doesn't contain any records or classes, skipping...");
Console.WriteLine(
$"File {fileName} doesn't contain any records or classes, skipping..."
);
// Probably an enum or interface
return;
}
var classesAndRecordsToProcessCount = _recordAndClassRegex.Matches(content).Count;
Console.WriteLine($"Found {classesAndRecordsToProcessCount} records or classes for {fileName}");
Console.WriteLine(
$"Found {classesAndRecordsToProcessCount} records or classes for {fileName}"
);
var firstTimeFlag = false;
var currentIndex = 0;
try
@@ -56,9 +62,15 @@ public class JsonExtensionDataGeneratorLauncher
var endIndex = FindEndClassIndex(content, startIndex);
currentIndex = endIndex;
// Check if this class already has the tag anywhere
if (content.Substring(startIndex, endIndex - startIndex).Contains("[JsonExtensionData]"))
if (
content
.Substring(startIndex, endIndex - startIndex)
.Contains("[JsonExtensionData]")
)
{
Console.WriteLine($"Class index {i} for {fileName} already contains [JsonExtensionData], skipping class...");
Console.WriteLine(
$"Class index {i} for {fileName} already contains [JsonExtensionData], skipping class..."
);
continue;
}
@@ -66,7 +78,9 @@ public class JsonExtensionDataGeneratorLauncher
{
if (extensions.Any(e => !e.StartsWith("I")))
{
Console.WriteLine($"Class index {i} for {fileName} extends a parent class, skipping...");
Console.WriteLine(
$"Class index {i} for {fileName} extends a parent class, skipping..."
);
continue;
}
}
@@ -76,7 +90,9 @@ public class JsonExtensionDataGeneratorLauncher
{
if (!content.Contains("using System.Text.Json.Serialization;"))
{
Console.WriteLine($"Class index {i} for {fileName} doesn't contain using for Json.Serialization. Adding.");
Console.WriteLine(
$"Class index {i} for {fileName} doesn't contain using for Json.Serialization. Adding."
);
// insert the using and adjust the indexes
content = Using + content;
startIndex += Using.Length;
@@ -88,8 +104,9 @@ public class JsonExtensionDataGeneratorLauncher
}
// We need to add StartRecordClassOffset to offset the EOL
var insertionIndex = _startRecordClassRegex.Match(content, startIndex, endIndex - startIndex).Index +
StartRecordClassOffset;
var insertionIndex =
_startRecordClassRegex.Match(content, startIndex, endIndex - startIndex).Index
+ StartRecordClassOffset;
content = content.Insert(insertionIndex, Insertion);
Console.WriteLine($"Class index {i} for {fileName} processed.");
currentIndex += Insertion.Length;
@@ -117,7 +134,9 @@ public class JsonExtensionDataGeneratorLauncher
if (match.Success)
{
var extensionsGroup = match.Groups[8];
extensions = extensionsGroup.Captures.Select(c => _extensionCleanup.Replace(c.Value, ""));
extensions = extensionsGroup.Captures.Select(c =>
_extensionCleanup.Replace(c.Value, "")
);
return true;
}
@@ -138,7 +157,12 @@ public class JsonExtensionDataGeneratorLauncher
private static IEnumerable<string> LoadModelFiles()
{
var projectDir = Directory.GetParent("./").Parent.Parent.Parent.Parent.Parent;
var modelsDir = Path.Combine(projectDir.FullName, "Libraries", "SPTarkov.Server.Core", "Models");
var modelsDir = Path.Combine(
projectDir.FullName,
"Libraries",
"SPTarkov.Server.Core",
"Models"
);
return Directory.GetFiles(modelsDir, "*.cs", SearchOption.AllDirectories);
}
}