refactor(mod): changed hardcode items and locale to JSON controlled one
This commit is contained in:
@@ -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<Mod> logger,
|
||||
MechanicAssort mechanicAssort,
|
||||
ItemGenerator itemGenerator): IOnLoad
|
||||
WeebItemService weebItemService,
|
||||
WeebTraderService weebTraderService,
|
||||
WeebLocaleService weebLocaleService): IOnLoad
|
||||
{
|
||||
public Task OnLoad()
|
||||
{
|
||||
var stopWatch = Stopwatch.StartNew();
|
||||
var sightsMbus = itemGenerator.GenerateWeebSights<ESightsMbus>();
|
||||
var sightsMcx = itemGenerator.GenerateWeebSights<ESightsMcx>();
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user