From a4b2bf4bcf2bd64815be14e37dd8549db84eb852 Mon Sep 17 00:00:00 2001 From: Yui Date: Tue, 4 Nov 2025 15:33:50 -0300 Subject: [PATCH] refactor(mod): changed hardcode items and locale to JSON controlled one --- .../Enums/ESightsMbus.cs | 23 --- moe.yuyui.weebsights-port/Enums/ESightsMcx.cs | 16 -- .../Interfaces/IWeebSightEnum.cs | 7 - .../Locales/EnglishLocale.cs | 128 ---------------- moe.yuyui.weebsights-port/Mod.cs | 33 ++-- .../Models/WeebItemConfig.cs | 22 +++ .../Models/WeebLocaleConfig.cs | 16 ++ moe.yuyui.weebsights-port/Models/WeebSight.cs | 5 - .../WeebItemService.cs} | 134 +++++++++------- .../Services/WeebLocaleService.cs | 29 ++++ .../WeebTraderService.cs} | 25 ++- moe.yuyui.weebsights-port/db/items.jsonc | 143 ++++++++++++++++++ moe.yuyui.weebsights-port/db/locales/en.json | 107 +++++++++++++ .../moe.yuyui.weebsights-port.csproj | 5 + 14 files changed, 431 insertions(+), 262 deletions(-) delete mode 100644 moe.yuyui.weebsights-port/Enums/ESightsMbus.cs delete mode 100644 moe.yuyui.weebsights-port/Enums/ESightsMcx.cs delete mode 100644 moe.yuyui.weebsights-port/Interfaces/IWeebSightEnum.cs delete mode 100644 moe.yuyui.weebsights-port/Locales/EnglishLocale.cs create mode 100644 moe.yuyui.weebsights-port/Models/WeebItemConfig.cs create mode 100644 moe.yuyui.weebsights-port/Models/WeebLocaleConfig.cs delete mode 100644 moe.yuyui.weebsights-port/Models/WeebSight.cs rename moe.yuyui.weebsights-port/{Items/ItemGenerator.cs => Services/WeebItemService.cs} (53%) create mode 100644 moe.yuyui.weebsights-port/Services/WeebLocaleService.cs rename moe.yuyui.weebsights-port/{Assorts/MechanicAssort.cs => Services/WeebTraderService.cs} (63%) create mode 100644 moe.yuyui.weebsights-port/db/items.jsonc create mode 100644 moe.yuyui.weebsights-port/db/locales/en.json diff --git a/moe.yuyui.weebsights-port/Enums/ESightsMbus.cs b/moe.yuyui.weebsights-port/Enums/ESightsMbus.cs deleted file mode 100644 index 4fea785..0000000 --- a/moe.yuyui.weebsights-port/Enums/ESightsMbus.cs +++ /dev/null @@ -1,23 +0,0 @@ -using moe.yuyui.weebsights_port.Interfaces; -using moe.yuyui.weebsights_port.Models; -using SPTarkov.Server.Core.Models.Common; - -namespace moe.yuyui.weebsights_port.Enums; - -public class ESightsMbus : IWeebSightEnum -{ - public static readonly WeebSight Anti = new("6753d006cec7fc449f055445", "sight_rear_all_magpul_mbus_anti", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight Anti2 = new("6753d006cec7fc449f05544a", "sight_rear_all_magpul_mbus_gen2_anti2", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight FdeAnti = new("6753d006cec7fc449f055450","sight_rear_all_magpul_mbus_gen2_fde_anti", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight FdeAnti2 = new("6753d006cec7fc449f055451", "sight_rear_all_magpul_mbus_gen2_fde_anti2", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight Fuyuumi = new("6753d006cec7fc449f055446", "sight_rear_all_magpul_mbus_gen2_anime", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight FdeFuyuumi = new("6753d006cec7fc449f05544c","sight_rear_all_magpul_mbus_gen2_fde_anime", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight M4Sopmod = new("6753d006cec7fc449f055447","sight_rear_all_magpul_mbus_gen2_anime2", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight FdeM4Sopmod = new("6753d006cec7fc449f05544d","sight_rear_all_magpul_mbus_gen2_fde_anime2", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight Animu3 = new("6753d006cec7fc449f055448","sight_rear_all_magpul_mbus_gen2_anime3", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight FdeAnimu3 = new("6753d006cec7fc449f05544e","sight_rear_all_magpul_mbus_gen2_fde_anime3", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight Animu3V2 = new("6753d006cec7fc449f055449","sight_rear_all_magpul_mbus_gen2_anime3v2", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight FdeAnimu3V2 = new("6753d006cec7fc449f05544f","sight_rear_all_magpul_mbus_gen2_fde_anime3v2", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight Ramrem = new("6753d006cec7fc449f05544b","sight_rear_all_magpul_mbus_gen2_ramrem", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); - public static readonly WeebSight FdeRamrem = new("6753d006cec7fc449f055452","sight_rear_all_magpul_mbus_gen2_fde_ramrem", ItemTpl.IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT); -} \ No newline at end of file diff --git a/moe.yuyui.weebsights-port/Enums/ESightsMcx.cs b/moe.yuyui.weebsights-port/Enums/ESightsMcx.cs deleted file mode 100644 index de9db2a..0000000 --- a/moe.yuyui.weebsights-port/Enums/ESightsMcx.cs +++ /dev/null @@ -1,16 +0,0 @@ -using moe.yuyui.weebsights_port.Interfaces; -using moe.yuyui.weebsights_port.Models; -using SPTarkov.Server.Core.Models.Common; - -namespace moe.yuyui.weebsights_port.Enums; - -public class ESightsMcx : IWeebSightEnum -{ - public static readonly WeebSight Fuyuumi = new("6753d006cec7fc449f055453", "sight_rear_all_sig_flip_up_anime", ItemTpl.IRONSIGHT_MCX_FLIPUP_REAR_SIGHT); - public static readonly WeebSight M4Sopmod = new("6753d006cec7fc449f055454", "sight_rear_all_sig_flip_up_anime2", ItemTpl.IRONSIGHT_MCX_FLIPUP_REAR_SIGHT); - public static readonly WeebSight Animu3 = new("6753d006cec7fc449f055455", "sight_rear_all_sig_flip_up_anime3", ItemTpl.IRONSIGHT_MCX_FLIPUP_REAR_SIGHT); - public static readonly WeebSight Animu3V2 = new("6753d006cec7fc449f055456", "sight_rear_all_sig_flip_up_anime3v2", ItemTpl.IRONSIGHT_MCX_FLIPUP_REAR_SIGHT); - public static readonly WeebSight Anti = new("6753d006cec7fc449f055457", "sight_rear_all_sig_flip_up_anti", ItemTpl.IRONSIGHT_MCX_FLIPUP_REAR_SIGHT); - public static readonly WeebSight Anti2 = new("6753d006cec7fc449f055458", "sight_rear_all_sig_flip_up_anti2", ItemTpl.IRONSIGHT_MCX_FLIPUP_REAR_SIGHT); - public static readonly WeebSight Ramrem = new("6753d006cec7fc449f055459", "sight_rear_all_sig_flip_up_ramrem", ItemTpl.IRONSIGHT_MCX_FLIPUP_REAR_SIGHT); -} \ No newline at end of file diff --git a/moe.yuyui.weebsights-port/Interfaces/IWeebSightEnum.cs b/moe.yuyui.weebsights-port/Interfaces/IWeebSightEnum.cs deleted file mode 100644 index 1fb9fa6..0000000 --- a/moe.yuyui.weebsights-port/Interfaces/IWeebSightEnum.cs +++ /dev/null @@ -1,7 +0,0 @@ -using SPTarkov.Server.Core.Models.Common; - -namespace moe.yuyui.weebsights_port.Interfaces; - -public interface IWeebSightEnum -{ -} \ No newline at end of file diff --git a/moe.yuyui.weebsights-port/Locales/EnglishLocale.cs b/moe.yuyui.weebsights-port/Locales/EnglishLocale.cs deleted file mode 100644 index 8a81fdd..0000000 --- a/moe.yuyui.weebsights-port/Locales/EnglishLocale.cs +++ /dev/null @@ -1,128 +0,0 @@ -using SPTarkov.DI.Annotations; -using SPTarkov.Server.Core.DI; -using SPTarkov.Server.Core.Models.Utils; -using SPTarkov.Server.Core.Services; - -namespace moe.yuyui.weebsights_port.Locales; - -[Injectable(TypePriority = OnLoadOrder.PostSptModLoader + 1)] -public class EnglishLocale( - DatabaseService databaseService, - LocaleService localeService, - ServerLocalisationService serverLocalisationService) -{ - public bool LoadLocales() - { - if (!databaseService.GetLocales().Global.TryGetValue("en", out var localeEn)) - { - return false; - } - localeEn.AddTransformer(l => - { - l.Add("6753d006cec7fc449f055445 Name", "Magpul MBUS Gen2 rear flip-up sight [Anti]"); - l.Add("6753d006cec7fc449f055445 ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f055445 Description", "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Your personal waifu giving her neko love to support you in combat."); - - l.Add("6753d006cec7fc449f055446 Name", "Magpul MBUS Gen2 rear flip-up sight [Ai Fuyuumi]"); - l.Add("6753d006cec7fc449f055446 ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f055446 Description", "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul."); - - l.Add("6753d006cec7fc449f055447 Name", "Magpul MBUS Gen2 rear flip-up sight [GF M4 SOPMOD II]"); - l.Add("6753d006cec7fc449f055447 ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f055447 Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul."); - - l.Add("6753d006cec7fc449f055448 Name", "Magpul MBUS Gen2 rear flip-up sight [Animu 3]"); - l.Add("6753d006cec7fc449f055448 ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f055448 Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul."); - - l.Add("6753d006cec7fc449f055449 Name", "Magpul MBUS Gen2 rear flip-up sight [Animu 3 v2]"); - l.Add("6753d006cec7fc449f055449 ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f055449 Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul."); - - l.Add("6753d006cec7fc449f05544a Name", "Magpul MBUS Gen2 rear flip-up sight [Anti 2]"); - l.Add("6753d006cec7fc449f05544a ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f05544a Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. The personal sight used by Anti, the war Neko! Nya!!"); - - l.Add("6753d006cec7fc449f05544b Name", "Magpul MBUS Gen2 rear flip-up sight [Ram & Rem]"); - l.Add("6753d006cec7fc449f05544b ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f05544b Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul."); - - l.Add("6753d006cec7fc449f05544c Name", "Magpul MBUS Gen2 rear flip-up sight (FDE) [Ai Fuyuumi]"); - l.Add("6753d006cec7fc449f05544c ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f05544c Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color."); - - l.Add("6753d006cec7fc449f05544d Name", "Magpul MBUS Gen2 rear flip-up sight (FDE) [GF M4 SOPMOD II]"); - l.Add("6753d006cec7fc449f05544d ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f05544d Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color."); - - l.Add("6753d006cec7fc449f05544e Name", "Magpul MBUS Gen2 rear flip-up sight (FDE) [Animu 3]"); - l.Add("6753d006cec7fc449f05544e ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f05544e Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color."); - - l.Add("6753d006cec7fc449f05544f Name", "Magpul MBUS Gen2 rear flip-up sight (FDE) [Animu 3 v2]"); - l.Add("6753d006cec7fc449f05544f ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f05544f Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color."); - - l.Add("6753d006cec7fc449f055450 Name", "Magpul MBUS Gen2 rear flip-up sight (FDE) [Anti]"); - l.Add("6753d006cec7fc449f055450 ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f055450 Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color. Your personal waifu giving her neko love to support you in combat."); - - l.Add("6753d006cec7fc449f055451 Name", "Magpul MBUS Gen2 rear flip-up sight (FDE) [Anti 2]"); - l.Add("6753d006cec7fc449f055451 ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f055451 Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color. The personal sight used by Anti, the war Neko! Nya!!"); - - l.Add("6753d006cec7fc449f055452 Name", "Magpul MBUS Gen2 rear flip-up sight (FDE) [Ram & Rem]"); - l.Add("6753d006cec7fc449f055452 ShortName", "MBUS RS"); - l.Add("6753d006cec7fc449f055452 Description", - "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color."); - - l.Add("6753d006cec7fc449f055453 Name", "MCX flip-up rear sight [Ai Fuyuumi]"); - l.Add("6753d006cec7fc449f055453 ShortName", "MCX RS"); - l.Add("6753d006cec7fc449f055453 Description", - "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer."); - - l.Add("6753d006cec7fc449f055454 Name", "MCX flip-up rear sight [GF M4 SOPMOD II]"); - l.Add("6753d006cec7fc449f055454 ShortName", "MCX RS"); - l.Add("6753d006cec7fc449f055454 Description", - "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer."); - - l.Add("6753d006cec7fc449f055455 Name", "MCX flip-up rear sight [Animu 3]"); - l.Add("6753d006cec7fc449f055455 ShortName", "MCX RS"); - l.Add("6753d006cec7fc449f055455 Description", - "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer."); - - l.Add("6753d006cec7fc449f055456 Name", "MCX flip-up rear sight [Animu 3 v2]"); - l.Add("6753d006cec7fc449f055456 ShortName", "MCX RS"); - l.Add("6753d006cec7fc449f055456 Description", - "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer."); - - l.Add("6753d006cec7fc449f055457 Name", "MCX flip-up rear sight [Anti]"); - l.Add("6753d006cec7fc449f055457 ShortName", "MCX RS"); - l.Add("6753d006cec7fc449f055457 Description", - "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer. Your personal waifu giving her neko love to support you in combat."); - - l.Add("6753d006cec7fc449f055458 Name", "MCX flip-up rear sight [Anti 2]"); - l.Add("6753d006cec7fc449f055458 ShortName", "MCX RS"); - l.Add("6753d006cec7fc449f055458 Description", - "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer. The personal sight used by Anti, the war Neko! Nya!!"); - - l.Add("6753d006cec7fc449f055459 Name", "MCX flip-up rear sight [Ram & Rem]"); - l.Add("6753d006cec7fc449f055459 ShortName", "MCX RS"); - l.Add("6753d006cec7fc449f055459 Description", - "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer."); - return l; - }); - return true; - } -} \ No newline at end of file diff --git a/moe.yuyui.weebsights-port/Mod.cs b/moe.yuyui.weebsights-port/Mod.cs index bc9aab7..de0967f 100644 --- a/moe.yuyui.weebsights-port/Mod.cs +++ b/moe.yuyui.weebsights-port/Mod.cs @@ -1,10 +1,9 @@ using System.Diagnostics; -using moe.yuyui.weebsights_port.Assorts; -using moe.yuyui.weebsights_port.Enums; -using moe.yuyui.weebsights_port.Items; -using moe.yuyui.weebsights_port.Locales; +using System.Reflection; +using moe.yuyui.weebsights_port.Services; using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.DI; +using SPTarkov.Server.Core.Models.Enums; using SPTarkov.Server.Core.Models.Utils; using SPTarkov.Server.Core.Services; @@ -12,23 +11,31 @@ namespace moe.yuyui.weebsights_port; [Injectable(TypePriority = OnLoadOrder.PostSptModLoader + 1)] public class Mod(ISptLogger logger, - MechanicAssort mechanicAssort, - ItemGenerator itemGenerator): IOnLoad + WeebItemService weebItemService, + WeebTraderService weebTraderService, + WeebLocaleService weebLocaleService): IOnLoad { public Task OnLoad() { var stopWatch = Stopwatch.StartNew(); - var sightsMbus = itemGenerator.GenerateWeebSights(); - var sightsMcx = itemGenerator.GenerateWeebSights(); - if (!mechanicAssort.InjectAssortFromItemClone(sightsMbus)) + var currentAssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + logger.Info($"[Weeb Iron Sights] Loaded in {currentAssemblyPath}"); + if (!weebLocaleService.TryLoadLocales(Path.Join(currentAssemblyPath, "/db/locales/en.json"), out var locales)) { - logger.Critical("[Weeb Iron Sights] Failed to inject MBUS Sights"); + logger.Error("[Weeb Iron Sights] Failed to load locales. Names might be weird"); + } + + if(!weebItemService.TryLoadConfig(Path.Join(currentAssemblyPath, "/db/items.jsonc"), out var items)) + { + logger.Critical("[Weeb Iron Sights] Failed to load items. MOD WILL NOT LOAD"); + stopWatch.Stop(); + return Task.CompletedTask; } - - if (!mechanicAssort.InjectAssortFromItemClone(sightsMcx)) + var resultItemCreation = weebItemService.GenerateItems(items, locales); + if (!weebTraderService.AddToAssortFromItemClone(Traders.MECHANIC, resultItemCreation)) { - logger.Critical("[Weeb Iron Sights] Failed to inject MCX Sights"); + logger.Critical("[Weeb Iron Sights] Failed to add items into Mechanic. Sights wont be available for purchase"); } stopWatch.Stop(); diff --git a/moe.yuyui.weebsights-port/Models/WeebItemConfig.cs b/moe.yuyui.weebsights-port/Models/WeebItemConfig.cs new file mode 100644 index 0000000..67a7735 --- /dev/null +++ b/moe.yuyui.weebsights-port/Models/WeebItemConfig.cs @@ -0,0 +1,22 @@ +using System.Text.Json.Serialization; +using SPTarkov.Server.Core.Models.Common; + +namespace moe.yuyui.weebsights_port.Models; + +public record WeebItemConfig() +{ + [JsonPropertyName("id")] + public MongoId Id { get; set; } + + [JsonPropertyName("clone_from_tpl")] + public MongoId CloneFromTpl { get; set; } + + [JsonPropertyName("bundle_path")] + public string BundlePath { get; set; } + + [JsonPropertyName("price")] + public int Price { get; set; } + + [JsonPropertyName("ergonomics")] + public int Ergonomics { get; set; } +} \ No newline at end of file diff --git a/moe.yuyui.weebsights-port/Models/WeebLocaleConfig.cs b/moe.yuyui.weebsights-port/Models/WeebLocaleConfig.cs new file mode 100644 index 0000000..1474ea7 --- /dev/null +++ b/moe.yuyui.weebsights-port/Models/WeebLocaleConfig.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using SPTarkov.Server.Core.Models.Common; + +namespace moe.yuyui.weebsights_port.Models; + +public record WeebLocaleConfig() +{ + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("short_name")] + public string ShortName { get; set; } + + [JsonPropertyName("description")] + public string Description { get; set; } +} \ No newline at end of file diff --git a/moe.yuyui.weebsights-port/Models/WeebSight.cs b/moe.yuyui.weebsights-port/Models/WeebSight.cs deleted file mode 100644 index da5a490..0000000 --- a/moe.yuyui.weebsights-port/Models/WeebSight.cs +++ /dev/null @@ -1,5 +0,0 @@ -using SPTarkov.Server.Core.Models.Common; - -namespace moe.yuyui.weebsights_port.Models; - -public record WeebSight(MongoId Id, string Asset, MongoId CloneFromTpl); diff --git a/moe.yuyui.weebsights-port/Items/ItemGenerator.cs b/moe.yuyui.weebsights-port/Services/WeebItemService.cs similarity index 53% rename from moe.yuyui.weebsights-port/Items/ItemGenerator.cs rename to moe.yuyui.weebsights-port/Services/WeebItemService.cs index f081309..0ac5d15 100644 --- a/moe.yuyui.weebsights-port/Items/ItemGenerator.cs +++ b/moe.yuyui.weebsights-port/Services/WeebItemService.cs @@ -1,74 +1,39 @@ -using System.Reflection; -using Microsoft.Extensions.Logging; -using moe.yuyui.weebsights_port.Interfaces; using moe.yuyui.weebsights_port.Models; using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.DI; using SPTarkov.Server.Core.Models.Common; using SPTarkov.Server.Core.Models.Eft.Common.Tables; +using SPTarkov.Server.Core.Models.Spt.Config; using SPTarkov.Server.Core.Models.Spt.Mod; using SPTarkov.Server.Core.Models.Utils; using SPTarkov.Server.Core.Services; using SPTarkov.Server.Core.Services.Mod; +using SPTarkov.Server.Core.Utils; -namespace moe.yuyui.weebsights_port.Items; +namespace moe.yuyui.weebsights_port.Services; -[Injectable(TypePriority = OnLoadOrder.PostDBModLoader + 2)] -public class ItemGenerator(ISptLogger logger, CustomItemService customItemService, DatabaseService databaseService) +[Injectable(TypePriority = OnLoadOrder.PostDBModLoader + 3)] +public class WeebItemService(ISptLogger logger, JsonUtil jsonUtil, CustomItemService customItemService, DatabaseService databaseService) { - public IEnumerable GenerateWeebSights() where T : IWeebSightEnum + public bool TryLoadConfig(string filePath, out List outputObject) { - FieldInfo[] fields = typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static ).Where(f => f.FieldType == typeof(WeebSight)).ToArray(); - foreach (var field in fields) + var json = LoadConfig(filePath); + if (json is null) { - WeebSight? sight = field.GetValue(typeof(WeebSight)) as WeebSight; - if (sight == null) - { - logger.Error($"[Weeb Iron Sights] Failed to convert field {field.Name} of type {field.FieldType} into WeebSight"); - continue; - } - - NewItemFromCloneDetails clonedItem = new() - { - NewId = sight.Id, - ItemTplToClone = sight.CloneFromTpl, - ParentId = "55818ac54bdc2d5b648b456e", // Ironsight - HandbookParentId = "5b5f746686f77447ec5d7708", // CATEGORY - HandbookPriceRoubles = 4000, - OverrideProperties = new TemplateItemProperties() - { - Ergonomics = 3, - CreditsPrice = 4000, - Prefab = new Prefab() - { - Path = $"assets/content/items/mods/sights rear/{sight.Asset}.bundle" - }, - }, - Locales = new Dictionary - { - { - "en", new LocaleDetails() - { - Name = $"{sight.Id} TODO LOCALE LOADER FROM JSON", - ShortName = "WEEBSIGHT", - Description = "DESCRIPTION", - } - } - } - }; - var itemCreation = customItemService.CreateItemFromClone(clonedItem); - if (itemCreation.Success is false or null) - { - logger.Error($"[Weeb Iron Sights] Failed to clone item {sight.CloneFromTpl} into {sight.Id}"); - itemCreation.Errors?.ForEach(e => logger.Critical("[Weeb Iron Sights] " + e)); - continue; - } - AddItemToFilters(sight); - yield return itemCreation; + outputObject = []; + return false; } + + outputObject = json; + return true; + } + + public List? LoadConfig(string filePath) + { + return jsonUtil.DeserializeFromFile>(filePath); } - private void AddItemToFilters(WeebSight sight) + public void AddIronSightToFilters(WeebItemConfig sight) { var itemsWithSlots = databaseService.GetTemplates().Items.Where(i => i.Value.Properties?.Slots?.Count() > 0); foreach (var item in itemsWithSlots) @@ -93,4 +58,65 @@ public class ItemGenerator(ISptLogger logger, CustomItemService c logger.Success($"[Weeb Iron Sights] Added {sight.Id} to filter on item {item.Key}"); } } + + public IEnumerable GenerateItems(List items, Dictionary locales) + { + if (items.Count == 0) + { + yield break; + } + + foreach (var item in items) + { + if (!locales.TryGetValue(item.Id, out var localeConfig)) + { + logger.Error($"[Weeb Iron Sights] Failed to load locale for {item.Id}, using IDs for name"); + localeConfig = new WeebLocaleConfig() + { + Name = item.Id, + Description = "FAILED TO LOAD LOCALES", + ShortName = "WEEBSIGHT", + }; + } + + NewItemFromCloneDetails clonedItem = new() + { + NewId = item.Id, + ItemTplToClone = item.CloneFromTpl, + ParentId = "55818ac54bdc2d5b648b456e", // Ironsight + HandbookParentId = "5b5f746686f77447ec5d7708", // CATEGORY + HandbookPriceRoubles = item.Price, + OverrideProperties = new TemplateItemProperties() + { + Ergonomics = item.Ergonomics, + CreditsPrice = item.Price, + Prefab = new Prefab() + { + Path = item.BundlePath + }, + }, + Locales = new Dictionary + { + { + "en", new LocaleDetails() + { + Name = localeConfig.Name, + ShortName = localeConfig.ShortName, + Description = localeConfig.Description, + } + } + } + }; + var itemCreation = customItemService.CreateItemFromClone(clonedItem); + if (itemCreation.Success is false or null) + { + logger.Error($"[Weeb Iron Sights] Failed to clone item {item.CloneFromTpl} into {item.Id}"); + itemCreation.Errors?.ForEach(e => logger.Critical("[Weeb Iron Sights] " + e)); + continue; + } + + AddIronSightToFilters(item); + yield return itemCreation; + } + } } \ No newline at end of file diff --git a/moe.yuyui.weebsights-port/Services/WeebLocaleService.cs b/moe.yuyui.weebsights-port/Services/WeebLocaleService.cs new file mode 100644 index 0000000..8295b53 --- /dev/null +++ b/moe.yuyui.weebsights-port/Services/WeebLocaleService.cs @@ -0,0 +1,29 @@ +using moe.yuyui.weebsights_port.Models; +using SPTarkov.DI.Annotations; +using SPTarkov.Server.Core.DI; +using SPTarkov.Server.Core.Models.Common; +using SPTarkov.Server.Core.Utils; + +namespace moe.yuyui.weebsights_port.Services; + +[Injectable(TypePriority = OnLoadOrder.PostDBModLoader + 4)] +public class WeebLocaleService(JsonUtil jsonUtil) +{ + public bool TryLoadLocales(string filePath, out Dictionary outputObject) + { + var json = LoadLocales(filePath); + if (json == null) + { + outputObject = new Dictionary(); + return false; + } + + outputObject = json; + return true; + } + + public Dictionary? LoadLocales(string filePath) + { + return jsonUtil.DeserializeFromFile>(filePath); + } +} \ No newline at end of file diff --git a/moe.yuyui.weebsights-port/Assorts/MechanicAssort.cs b/moe.yuyui.weebsights-port/Services/WeebTraderService.cs similarity index 63% rename from moe.yuyui.weebsights-port/Assorts/MechanicAssort.cs rename to moe.yuyui.weebsights-port/Services/WeebTraderService.cs index cf4d7c9..5ac5daa 100644 --- a/moe.yuyui.weebsights-port/Assorts/MechanicAssort.cs +++ b/moe.yuyui.weebsights-port/Services/WeebTraderService.cs @@ -1,7 +1,3 @@ -using System.Reflection; -using Microsoft.Extensions.Logging; -using moe.yuyui.weebsights_port.Enums; -using moe.yuyui.weebsights_port.Models; using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.DI; using SPTarkov.Server.Core.Extensions; @@ -10,24 +6,21 @@ using SPTarkov.Server.Core.Models.Eft.Common.Tables; using SPTarkov.Server.Core.Models.Enums; using SPTarkov.Server.Core.Models.Spt.Mod; using SPTarkov.Server.Core.Models.Utils; -using SPTarkov.Server.Core.Servers; using SPTarkov.Server.Core.Services; -using SPTarkov.Server.Core.Services.Mod; -using SPTarkov.Server.Core.Utils; -namespace moe.yuyui.weebsights_port.Assorts; +namespace moe.yuyui.weebsights_port.Services; -[Injectable(TypePriority = OnLoadOrder.PostDBModLoader + 1)] -public class MechanicAssort(ISptLoggerlogger, JsonUtil jsonUtil, DatabaseService databaseService, CustomItemService customItemService) +[Injectable(TypePriority = OnLoadOrder.PostDBModLoader + 2)] +public class WeebTraderService(ISptLogger logger, DatabaseService databaseService) { - public bool InjectAssortFromItemClone(IEnumerable itemCloneResults) + public bool AddToAssortFromItemClone(MongoId traderId, IEnumerable itemCloneResults) { - if (!databaseService.GetTables().Traders.TryGetValue(Traders.MECHANIC, out var mechanic)) + if (!databaseService.GetTables().Traders.TryGetValue(traderId, out var trader)) { - logger.Error("[Weeb Iron Sights] Failed to find MECHANIC trader"); + logger.Error($"[Weeb Iron Sights] Failed to find trader with ID {traderId}"); return false; } - + foreach (var itemResult in itemCloneResults) { var item = databaseService.GetItems().FirstOrDefault(i => i.Key == itemResult.ItemId); @@ -38,8 +31,8 @@ public class MechanicAssort(ISptLoggerlogger, JsonUtil jsonUtil, Template = CurrencyType.RUB.GetCurrencyTpl() }; - mechanic.Assort.Items.Add(traderItem); - if (!mechanic.Assort.BarterScheme.TryAdd(item.Key, [[traderBarter]])) + trader.Assort.Items.Add(traderItem); + if (!trader.Assort.BarterScheme.TryAdd(item.Key, [[traderBarter]])) { logger.Error($"[Weeb Iron Sights] Failed to add barter for item {item.Value.Name} with ID {item.Value.Id} in MECHANIC"); } diff --git a/moe.yuyui.weebsights-port/db/items.jsonc b/moe.yuyui.weebsights-port/db/items.jsonc new file mode 100644 index 0000000..3dada09 --- /dev/null +++ b/moe.yuyui.weebsights-port/db/items.jsonc @@ -0,0 +1,143 @@ +[ + { + "id": "6753d006cec7fc449f055445", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_anti.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f05544a", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_anti2.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055450", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_fde_anti.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055451", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_fde_anti2.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055446", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_anime.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055447", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_anime2.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f05544d", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_fde_anime2.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055448", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_anime3.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f05544e", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_fde_anime3.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055449", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_anime3v2.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f05544f", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_fde_anime3v2.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f05544b", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_ramrem.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055452", + "clone_from_tpl": "5bc09a18d4351e003562b68e", //IRONSIGHT_MAGPUL_MBUS_GEN2_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_magpul_mbus_gen2_fde_ramrem.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055453", + "clone_from_tpl": "5fc0fa957283c4046c58147e", //IRONSIGHT_MCX_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_sig_flip_up_anime.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055454", + "clone_from_tpl": "5fc0fa957283c4046c58147e", //IRONSIGHT_MCX_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_sig_flip_up_anime2.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055455", + "clone_from_tpl": "5fc0fa957283c4046c58147e", //IRONSIGHT_MCX_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_sig_flip_up_anime3.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055456", + "clone_from_tpl": "5fc0fa957283c4046c58147e", //IRONSIGHT_MCX_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_sig_flip_up_anime3v2.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055457", + "clone_from_tpl": "5fc0fa957283c4046c58147e", //IRONSIGHT_MCX_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_sig_flip_up_anti.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055458", + "clone_from_tpl": "5fc0fa957283c4046c58147e", //IRONSIGHT_MCX_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_sig_flip_up_anti2.bundle", + "price": 4000, + "ergonomics": 3 + }, + { + "id": "6753d006cec7fc449f055459", + "clone_from_tpl": "5fc0fa957283c4046c58147e", //IRONSIGHT_MCX_FLIPUP_REAR_SIGHT + "bundle_path": "assets/content/items/mods/sights rear/sight_rear_all_sig_flip_up_ramrem.bundle", + "price": 4000, + "ergonomics": 3 + } + +] \ No newline at end of file diff --git a/moe.yuyui.weebsights-port/db/locales/en.json b/moe.yuyui.weebsights-port/db/locales/en.json new file mode 100644 index 0000000..ad618f1 --- /dev/null +++ b/moe.yuyui.weebsights-port/db/locales/en.json @@ -0,0 +1,107 @@ +{ + "6753d006cec7fc449f055445": { + "name": "Magpul MBUS Gen2 rear flip-up sight [Anti]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Your personal waifu giving her neko love to support you in combat." + }, + "6753d006cec7fc449f055446": { + "name": "Magpul MBUS Gen2 rear flip-up sight [Ai Fuyuumi]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul." + }, + "6753d006cec7fc449f055447": { + "name": "Magpul MBUS Gen2 rear flip-up sight [GF M4 SOPMOD II]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul." + }, + "6753d006cec7fc449f055448": { + "name": "Magpul MBUS Gen2 rear flip-up sight [Animu 3]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul." + }, + "6753d006cec7fc449f055449": { + "name": "Magpul MBUS Gen2 rear flip-up sight [Animu 3 v2]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul." + }, + "6753d006cec7fc449f05544a": { + "name": "Magpul MBUS Gen2 rear flip-up sight [Anti 2]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. The personal sight used by Anti, the war Neko! Nya!!" + }, + "6753d006cec7fc449f05544b": { + "name": "Magpul MBUS Gen2 rear flip-up sight [Ram & Rem]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul." + }, + "6753d006cec7fc449f05544c": { + "name": "Magpul MBUS Gen2 rear flip-up sight (FDE) [Ai Fuyuumi]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color." + }, + "6753d006cec7fc449f05544d": { + "name": "Magpul MBUS Gen2 rear flip-up sight (FDE) [GF M4 SOPMOD II]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color." + }, + "6753d006cec7fc449f05544e": { + "name": "Magpul MBUS Gen2 rear flip-up sight (FDE) [Animu 3]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color." + }, + "6753d006cec7fc449f05544f": { + "name": "Magpul MBUS Gen2 rear flip-up sight (FDE) [Animu 3 v2]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color." + }, + "6753d006cec7fc449f055450": { + "name": "Magpul MBUS Gen2 rear flip-up sight (FDE) [Anti]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color. Your personal waifu giving her neko love to support you in combat." + }, + "6753d006cec7fc449f055451": { + "name": "Magpul MBUS Gen2 rear flip-up sight (FDE) [Anti 2]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color. The personal sight used by Anti, the war Neko! Nya!!" + }, + "6753d006cec7fc449f055452": { + "name": "Magpul MBUS Gen2 rear flip-up sight (FDE) [Ram & Rem]", + "short_name": "MBUS RS", + "description": "Removable flip-up rear sight MBUS Gen2, installed on the mount. Manufactured by Magpul. Flat Dark Earth color." + }, + "6753d006cec7fc449f055453": { + "name": "MCX flip-up rear sight [Ai Fuyuumi]", + "short_name": "MCX RS", + "description": "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer." + }, + "6753d006cec7fc449f055454": { + "name": "MCX flip-up rear sight [GF M4 SOPMOD II]", + "short_name": "MCX RS", + "description": "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer." + }, + "6753d006cec7fc449f055455": { + "name": "MCX flip-up rear sight [Animu 3]", + "short_name": "MCX RS", + "description": "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer." + }, + "6753d006cec7fc449f055456": { + "name": "MCX flip-up rear sight [Animu 3 v2]", + "short_name": "MCX RS", + "description": "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer." + }, + "6753d006cec7fc449f055457": { + "name": "MCX flip-up rear sight [Anti]", + "short_name": "MCX RS", + "description": "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer. Your personal waifu giving her neko love to support you in combat." + }, + "6753d006cec7fc449f055458": { + "name": "MCX flip-up rear sight [Anti 2]", + "short_name": "MCX RS", + "description": "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer. The personal sight used by Anti, the war Neko! Nya!!" + }, + "6753d006cec7fc449f055459": { + "name": "MCX flip-up rear sight [Ram & Rem]", + "short_name": "MCX RS", + "description": "Removable flip-up rear sight for MCX assault rifles, manufactured by SIG Sauer." + } +} \ No newline at end of file diff --git a/moe.yuyui.weebsights-port/moe.yuyui.weebsights-port.csproj b/moe.yuyui.weebsights-port/moe.yuyui.weebsights-port.csproj index 2a1d805..17a9b77 100644 --- a/moe.yuyui.weebsights-port/moe.yuyui.weebsights-port.csproj +++ b/moe.yuyui.weebsights-port/moe.yuyui.weebsights-port.csproj @@ -20,4 +20,9 @@ Always + + + Always + +