ItemTplGenerator
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace ItemTplGenerator;
|
||||
|
||||
public class ItemOverrides
|
||||
{
|
||||
public static readonly ReadOnlyDictionary<string, string> ItemOverridesDictionary = new(
|
||||
new Dictionary<string, string>()
|
||||
{
|
||||
// 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" },
|
||||
{ "5937fd0086f7742bf33fc198", "Watch Bronze" },
|
||||
{ "638cbb3ba63f1b49be6a300e", "FlashDrive Car Service" },
|
||||
{ "5eff135be0d3331e9d282b7b", "FlashDrive TerraGroup Employee" },
|
||||
{ "638e9d5536b3b72c944e2fc7", "FlashDrive Watching You" },
|
||||
{ "5a29357286f77409c705e025", "Flashdrive Wet Job Pt 4" },
|
||||
{ "5939e9b286f77462a709572c", "Letter Terragroup" },
|
||||
{ "591093bb86f7747caa7bb2ee", "Letter Postman Pat" },
|
||||
{ "61904c9df62c89219a56e034", "Letter Hermit" },
|
||||
{ "638cbc68a63f1b49be6a3010", "Letter Got Mail" },
|
||||
{ "619252352be33f26043400a7", "Toughbook Seaside Vacation" },
|
||||
{ "5a29284f86f77463ef3db363", "Toughbook Cargo" },
|
||||
{ "64b91627dd13d43b9d01d6d1", "Toughbook Terragroup" },
|
||||
{ "5a29276886f77435ed1b117c", "HDD Wet Job" },
|
||||
{ "628393620d8524273e7eb028", "HDD Top Secret" },
|
||||
{ "638dfc803083a019d447768e", "HDD Surveillance" },
|
||||
{ "66760b3deb51b08bd40c2b08", "HDD Unused" },
|
||||
{ "638e0057ab150a5f56238960", "Housing Journal" },
|
||||
{ "6393262086e646067c176aa2", "Medical Record" },
|
||||
{ "63989ced706b793c7d60cfef", "Informant Journal" },
|
||||
{ "6398a072e301557ae24cec92", "Lightkeeper Intel" },
|
||||
{ "6398a0861c712b1e1d4dadf1", "Lightkeeper Intel (Forged)" },
|
||||
{ "638e0752ab150a5f56238962", "Lightkeeper Intel 2" },
|
||||
{ "638e06c4b8bac37a110ed56d", "Lightkeeper Intel 2 (Forged)" },
|
||||
{ "63927b29c115f907b14700b9", "ChemCont Samples" },
|
||||
{ "5939e5a786f77461f11c0098", "Secure Folder 0013" },
|
||||
{ "591092ef86f7747bb8703422", "Secure Folder 0022" },
|
||||
{ "5938188786f77474f723e87f", "Secure Folder 0031" },
|
||||
{ "593965cf86f774087a77e1b6", "Secure Folder 0048" },
|
||||
{ "5938878586f7741b797c562f", "Secure Folder 0052" },
|
||||
{ "5a6860d886f77411cd3a9e47", "Secure Folder 0060" },
|
||||
{ "638cbb0f7f97256fac16167a", "Accountant's journal" },
|
||||
{ "664a5775f3d3570fba06be64", "Arena Poster Bison" },
|
||||
{ "664b69c5a082271bc46c4e11", "Arena Poster Killa" },
|
||||
{ "664b69e8e1238e506d3630af", "Arena Poster Easy Money" },
|
||||
{ "6575a6ca8778e96ded05a802", "Hard Drive TerraGroup Scientist" },
|
||||
{ "6614217b6d9d5abcad0ff098", "Unheard phone" },
|
||||
{ "6614230055afee107f05e998", "Unheard phone 2" },
|
||||
{ "661421c7c1f2f548c50ee649", "Unheard laptop" },
|
||||
{ "661423200d240a5f5d0f679b", "Unheard laptop 2" },
|
||||
{ "66a0f0926fee20fa70036da6", "Quest blood sample nf2024" },
|
||||
|
||||
// Weapon Parts
|
||||
{ "5d1340b3d7ad1a0b52682ed7", "GEN M3 FDE" },
|
||||
{ "55802d5f4bdc2dac148b458e", "GEN M3 Window" },
|
||||
{ "5d1340cad7ad1a0b0b249869", "GEN M3 Window FDE" },
|
||||
{ "5d1340bdd7ad1a0e8d245aab", "GEN M3 FDE" },
|
||||
{ "5cbdaf89ae9215000e5b9c94", "6L23 Plum" },
|
||||
{ "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" },
|
||||
{ "6759e19a8367ee2b0c0f4b92", "Girl poster 1" },
|
||||
{ "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" },
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Core.Callbacks;
|
||||
using Core.DI;
|
||||
using Core.Helpers;
|
||||
using Core.Models.Eft.Common.Tables;
|
||||
@@ -23,22 +24,24 @@ public class ItemTplGenerator(
|
||||
{
|
||||
private string enumDir;
|
||||
private Dictionary<string, TemplateItem> items;
|
||||
private Dictionary<string, string> itemOverrides;
|
||||
private List<string> collidedEnumKeys = [];
|
||||
private IDictionary<string, string> itemOverrides;
|
||||
private HashSet<string> collidedEnumKeys = [];
|
||||
|
||||
public async Task Run()
|
||||
{
|
||||
itemOverrides = ItemOverrides.ItemOverridesDictionary;
|
||||
// Load all of the onload components, this gives us access to most of SPTs injections
|
||||
foreach (var onLoad in _onLoadComponents)
|
||||
{
|
||||
if (onLoad is HttpCallbacks)
|
||||
continue;
|
||||
await onLoad.OnLoad();
|
||||
}
|
||||
|
||||
// Figure out our source and target directories
|
||||
var projectDir = Directory.GetParent("./").Parent;
|
||||
enumDir = Path.Combine(projectDir.FullName, "Core", "Models", "Enums");
|
||||
var projectDir = Directory.GetParent("./").Parent.Parent.Parent.Parent.Parent;
|
||||
enumDir = Path.Combine(projectDir.FullName, "Libraries", "Core", "Models", "Enums");
|
||||
items = _databaseServer.GetTables().Templates.Items;
|
||||
itemOverrides = new Dictionary<string, string>();
|
||||
|
||||
// Generate an object containing all item name to ID associations
|
||||
var orderedItemsObject = GenerateItemsObject();
|
||||
@@ -79,9 +82,11 @@ public class ItemTplGenerator(
|
||||
var itemPrefix = GetItemPrefix(item);
|
||||
var itemName = GetItemName(item);
|
||||
var itemSuffix = GetItemSuffix(item);
|
||||
|
||||
|
||||
// Handle the case where the item starts with the parent category name. Avoids things like 'POCKETS_POCKETS'
|
||||
if (itemParentName == itemName.Substring(1, itemParentName.Length + 1) && 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] != '_')
|
||||
@@ -91,7 +96,8 @@ public class ItemTplGenerator(
|
||||
}
|
||||
|
||||
// Handle the case where the item ends with the parent category name. Avoids things like 'KEY_DORM_ROOM_103_KEY'
|
||||
if (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);
|
||||
|
||||
@@ -113,14 +119,14 @@ public class ItemTplGenerator(
|
||||
collidedEnumKeys.Add(itemKey);
|
||||
|
||||
var itemNameSuffix = GetItemNameSuffix(item);
|
||||
if (itemNameSuffix != null)
|
||||
if (!string.IsNullOrEmpty(itemNameSuffix))
|
||||
{
|
||||
// Try to update the old key reference if we haven't already
|
||||
if (itemsObject.ContainsKey(itemKey))
|
||||
{
|
||||
var oldItemId = itemsObject[itemKey];
|
||||
var oldItemNameSuffix = GetItemNameSuffix(items[oldItemId]);
|
||||
if (oldItemNameSuffix != null)
|
||||
if (!string.IsNullOrEmpty(oldItemNameSuffix))
|
||||
{
|
||||
var oldItemNewKey = SanitizeEnumKey($"{itemKey}_{oldItemNameSuffix}");
|
||||
itemsObject.Remove(itemKey);
|
||||
@@ -140,9 +146,10 @@ public class ItemTplGenerator(
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Error(
|
||||
$"New itemOverride entry required: itemsObject already contains {itemKey} {itemsObject[itemKey]} => {item.Id}"
|
||||
);
|
||||
var val = itemsObject.ContainsKey(itemKey) ?
|
||||
itemsObject[itemKey] :
|
||||
itemKey;
|
||||
_logger.Error($"New itemOverride entry required: itemsObject already contains {itemKey} {val} => {item.Id}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -154,14 +161,6 @@ public class ItemTplGenerator(
|
||||
var itemList = itemsObject.ToList();
|
||||
itemList.Sort((kv1, kv2) => kv1.Key.CompareTo(kv2.Key));
|
||||
var orderedItemsObject = itemList.ToDictionary(kv => kv.Key, kv => kv.Value);
|
||||
/* I think the above should be the same?
|
||||
var orderedItemsObject = Object.keys(itemsObject)
|
||||
.sort()
|
||||
.reduce((obj, key) => {
|
||||
obj[key] = itemsObject[key];
|
||||
return obj;
|
||||
}, {});
|
||||
*/
|
||||
return orderedItemsObject;
|
||||
}
|
||||
|
||||
@@ -181,7 +180,6 @@ public class ItemTplGenerator(
|
||||
}
|
||||
|
||||
var caliber = CleanCaliber(kv.Value.Properties.AmmoCaliber.ToUpper());
|
||||
var localeDb = _localeService.GetLocaleDb();
|
||||
var weaponShortName = _localeService.GetLocaleDb()[$"{kv.Key} ShortName"]?.ToUpper();
|
||||
|
||||
// Special case for the weird duplicated grenade launcher
|
||||
@@ -193,9 +191,9 @@ 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.Captures[1].Value))
|
||||
!weaponShortName.EndsWith(itemNameBracketSuffix.Groups[1].Value))
|
||||
{
|
||||
weaponShortName += $"_{itemNameBracketSuffix.Captures[1].Value}";
|
||||
weaponShortName += $"_{itemNameBracketSuffix.Groups[1].Value}";
|
||||
}
|
||||
|
||||
var parentName = GetParentName(kv.Value);
|
||||
@@ -219,14 +217,6 @@ public class ItemTplGenerator(
|
||||
var itemList = weaponsObject.ToList();
|
||||
itemList.Sort((kv1, kv2) => kv1.Key.CompareTo(kv2.Key));
|
||||
var orderedWeaponsObject = itemList.ToDictionary(kv => kv.Key, kv => kv.Value);
|
||||
/* I think the above should be the same?
|
||||
var orderedWeaponsObject = Object.keys(weaponsObject.Keys)
|
||||
.sort()
|
||||
.reduce((obj, key) => {
|
||||
obj[key] = weaponsObject[key];
|
||||
return obj;
|
||||
}, {});
|
||||
*/
|
||||
return orderedWeaponsObject;
|
||||
}
|
||||
|
||||
@@ -444,7 +434,7 @@ public class ItemTplGenerator(
|
||||
[
|
||||
BaseClasses.RANDOM_LOOT_CONTAINER,
|
||||
BaseClasses.BUILT_IN_INSERTS,
|
||||
BaseClasses.STASH,
|
||||
BaseClasses.STASH
|
||||
]
|
||||
)
|
||||
)
|
||||
@@ -455,28 +445,28 @@ public class ItemTplGenerator(
|
||||
else if (_itemHelper.IsOfBaseclasses(item.Id, [BaseClasses.AMMO, BaseClasses.AMMO_BOX, BaseClasses.MAGAZINE]))
|
||||
{
|
||||
if (localeDb.TryGetValue($"{item.Id} ShortName", out itemName))
|
||||
itemName.ToUpper();
|
||||
itemName = itemName.ToUpper();
|
||||
}
|
||||
// For everything else, use the full name
|
||||
else
|
||||
{
|
||||
if (localeDb.TryGetValue($"{item.Id} Name", out itemName))
|
||||
itemName.ToUpper();
|
||||
itemName = itemName.ToUpper();
|
||||
}
|
||||
|
||||
// Fall back in the event we couldn't find a name
|
||||
if (itemName == null)
|
||||
if (string.IsNullOrEmpty(itemName))
|
||||
{
|
||||
if (localeDb.TryGetValue("{item.Id} Name", out itemName))
|
||||
itemName.ToUpper();
|
||||
if (localeDb.TryGetValue($"{item.Id} Name", out itemName))
|
||||
itemName = itemName.ToUpper();
|
||||
}
|
||||
|
||||
if (itemName == null)
|
||||
if (string.IsNullOrEmpty(itemName))
|
||||
{
|
||||
itemName = item.Name?.ToUpper() ?? null;
|
||||
}
|
||||
|
||||
if (itemName == null)
|
||||
if (string.IsNullOrEmpty(itemName))
|
||||
{
|
||||
Console.WriteLine($"Unable to get shortname for {item.Id}");
|
||||
return "";
|
||||
@@ -496,7 +486,7 @@ public class ItemTplGenerator(
|
||||
// Add grid size for lootable containers
|
||||
if (_itemHelper.IsOfBaseclass(item.Id, BaseClasses.LOOT_CONTAINER))
|
||||
{
|
||||
return $"{item.Properties.Grids[0]?.Props.CellsH}X${item.Properties.Grids[0]?.Props.CellsV}";
|
||||
return $"{item.Properties.Grids[0]?.Props.CellsH}X{item.Properties.Grids[0]?.Props.CellsV}";
|
||||
}
|
||||
|
||||
// Add ammo caliber to conflicting weapons
|
||||
@@ -507,14 +497,14 @@ public class ItemTplGenerator(
|
||||
// If the item has a bracketed section at the end of its name, include that
|
||||
if (itemName?.RegexMatch("\\((.+?)\\)$", out var itemNameBracketSuffix) ?? false)
|
||||
{
|
||||
return $"{caliber}_{itemNameBracketSuffix.Captures[1].Value}";
|
||||
return $"{caliber}_{itemNameBracketSuffix.Groups[1].Value}";
|
||||
}
|
||||
|
||||
return caliber;
|
||||
}
|
||||
|
||||
// Make sure we have a full name
|
||||
if (itemName == null)
|
||||
if (string.IsNullOrEmpty(itemName))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
@@ -522,13 +512,13 @@ public class ItemTplGenerator(
|
||||
// If the item has a bracketed section at the end of its name, use that
|
||||
if (itemName.RegexMatch("\\((.+?)\\)$", out var itemNameBracker))
|
||||
{
|
||||
return itemNameBracker.Captures[1].Value;
|
||||
return itemNameBracker.Groups[1].Value;
|
||||
}
|
||||
|
||||
// If the item has a number at the end of its name, use that
|
||||
if (itemName.RegexMatch("#([0-9]+)$", out var itemNameNumberSuffix))
|
||||
{
|
||||
return itemNameNumberSuffix.Captures[1].Value;
|
||||
return itemNameNumberSuffix.Groups[1].Value;
|
||||
}
|
||||
|
||||
return "";
|
||||
@@ -572,6 +562,7 @@ public class ItemTplGenerator(
|
||||
enumFileData += "}\n";
|
||||
}
|
||||
|
||||
// TODO: enable once we dont get any more errors
|
||||
// this.fileSystemSync.write(outputPath, enumFileData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"profiles": {
|
||||
"ItemTplGenerator": {
|
||||
"commandName": "Project",
|
||||
"hotReloadEnabled": true
|
||||
"hotReloadEnabled": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user