Questionable/Questionable/QuestionablePlugin.cs

139 lines
6.6 KiB
C#
Raw Normal View History

2024-05-26 19:45:26 +00:00
using System;
2024-06-08 19:16:57 +00:00
using System.Diagnostics.CodeAnalysis;
using Dalamud.Extensions.MicrosoftLogging;
2024-05-25 21:51:37 +00:00
using Dalamud.Game;
using Dalamud.Game.ClientState.Objects;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
2024-06-08 19:16:57 +00:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
2024-05-25 21:51:37 +00:00
using Questionable.Controller;
using Questionable.Controller.Steps;
using Questionable.Controller.Steps.BaseFactory;
using Questionable.Controller.Steps.BaseTasks;
using Questionable.Controller.Steps.InteractionFactory;
2024-05-27 19:54:34 +00:00
using Questionable.Data;
2024-05-25 21:51:37 +00:00
using Questionable.External;
using Questionable.Windows;
using Action = Questionable.Controller.Steps.InteractionFactory.Action;
2024-05-25 21:51:37 +00:00
namespace Questionable;
2024-06-08 19:16:57 +00:00
[SuppressMessage("ReSharper", "UnusedType.Global")]
2024-05-27 19:54:34 +00:00
public sealed class QuestionablePlugin : IDalamudPlugin
2024-05-25 21:51:37 +00:00
{
2024-06-08 19:16:57 +00:00
private readonly ServiceProvider? _serviceProvider;
2024-07-03 19:00:04 +00:00
public QuestionablePlugin(IDalamudPluginInterface pluginInterface,
2024-06-08 19:16:57 +00:00
IClientState clientState,
ITargetManager targetManager,
IFramework framework,
IGameGui gameGui,
IDataManager dataManager,
ISigScanner sigScanner,
IObjectTable objectTable,
IPluginLog pluginLog,
ICondition condition,
IChatGui chatGui,
ICommandManager commandManager,
IAddonLifecycle addonLifecycle,
IKeyState keyState)
2024-05-25 21:51:37 +00:00
{
2024-05-26 19:45:26 +00:00
ArgumentNullException.ThrowIfNull(pluginInterface);
2024-05-25 21:51:37 +00:00
2024-06-08 19:16:57 +00:00
ServiceCollection serviceCollection = new();
serviceCollection.AddLogging(builder => builder.SetMinimumLevel(LogLevel.Trace)
.ClearProviders()
.AddDalamudLogger(pluginLog, t => t[(t.LastIndexOf('.') + 1)..]));
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton<IDalamudPlugin>(this);
serviceCollection.AddSingleton(pluginInterface);
serviceCollection.AddSingleton(clientState);
serviceCollection.AddSingleton(targetManager);
serviceCollection.AddSingleton(framework);
serviceCollection.AddSingleton(gameGui);
serviceCollection.AddSingleton(dataManager);
serviceCollection.AddSingleton(sigScanner);
serviceCollection.AddSingleton(objectTable);
serviceCollection.AddSingleton(pluginLog);
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton(condition);
serviceCollection.AddSingleton(chatGui);
serviceCollection.AddSingleton(commandManager);
serviceCollection.AddSingleton(addonLifecycle);
serviceCollection.AddSingleton(keyState);
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton(new WindowSystem(nameof(Questionable)));
serviceCollection.AddSingleton((Configuration?)pluginInterface.GetPluginConfig() ?? new Configuration());
serviceCollection.AddSingleton<GameFunctions>();
serviceCollection.AddSingleton<ChatFunctions>();
serviceCollection.AddSingleton<AetherCurrentData>();
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton<AetheryteData>();
serviceCollection.AddSingleton<QuestData>();
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton<TerritoryData>();
serviceCollection.AddSingleton<NavmeshIpc>();
serviceCollection.AddSingleton<LifestreamIpc>();
2024-06-16 15:43:42 +00:00
serviceCollection.AddSingleton<YesAlreadyIpc>();
2024-06-08 19:16:57 +00:00
// individual tasks
serviceCollection.AddTransient<MountTask>();
serviceCollection.AddTransient<UnmountTask>();
// tasks with factories
serviceCollection.AddTaskWithFactory<StepDisabled.Factory, StepDisabled.Task>();
serviceCollection.AddTaskWithFactory<AetheryteShortcut.Factory, AetheryteShortcut.UseAetheryteShortcut>();
serviceCollection.AddTaskWithFactory<SkipCondition.Factory, SkipCondition.CheckTask>();
serviceCollection.AddTaskWithFactory<AethernetShortcut.Factory, AethernetShortcut.UseAethernetShortcut>();
2024-06-18 15:51:23 +00:00
serviceCollection.AddTaskWithFactory<WaitAtStart.Factory, WaitAtStart.WaitDelay>();
serviceCollection.AddTaskWithFactory<Move.Factory, Move.MoveInternal, Move.ExpectToBeNearDataId>();
serviceCollection.AddTransient<Move.MoveBuilder>();
serviceCollection.AddTaskWithFactory<AetherCurrent.Factory, AetherCurrent.DoAttune>();
serviceCollection.AddTaskWithFactory<AethernetShard.Factory, AethernetShard.DoAttune>();
serviceCollection.AddTaskWithFactory<Aetheryte.Factory, Aetheryte.DoAttune>();
serviceCollection.AddSingleton<ITaskFactory, Combat.Factory>();
serviceCollection.AddTaskWithFactory<Duty.Factory, Duty.OpenDutyFinder>();
serviceCollection.AddTaskWithFactory<Emote.Factory, Emote.UseOnObject, Emote.Use>();
serviceCollection.AddTaskWithFactory<Action.Factory, Action.UseOnObject>();
serviceCollection.AddTaskWithFactory<Interact.Factory, Interact.DoInteract>();
serviceCollection.AddTaskWithFactory<Jump.Factory, Jump.DoJump>();
serviceCollection.AddTaskWithFactory<Say.Factory, Say.UseChat>();
serviceCollection.AddTaskWithFactory<UseItem.Factory, UseItem.UseOnGround, UseItem.UseOnObject, UseItem.Use>();
serviceCollection.AddTaskWithFactory<EquipItem.Factory, EquipItem.DoEquip>();
serviceCollection
.AddTaskWithFactory<SinglePlayerDuty.Factory, SinglePlayerDuty.DisableYesAlready,
SinglePlayerDuty.RestoreYesAlready>();
serviceCollection
.AddTaskWithFactory<WaitAtEnd.Factory,
WaitAtEnd.WaitDelay,
WaitAtEnd.WaitNextStepOrSequence,
WaitAtEnd.WaitForCompletionFlags,
WaitAtEnd.WaitObjectAtPosition>();
serviceCollection.AddTransient<WaitAtEnd.WaitQuestAccepted>();
serviceCollection.AddTransient<WaitAtEnd.WaitQuestCompleted>();
serviceCollection.AddTaskWithFactory<NextQuest.Factory, NextQuest.SetQuest>();
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton<MovementController>();
serviceCollection.AddSingleton<QuestRegistry>();
serviceCollection.AddSingleton<QuestController>();
serviceCollection.AddSingleton<GameUiController>();
serviceCollection.AddSingleton<NavigationShortcutController>();
2024-06-18 15:51:23 +00:00
serviceCollection.AddSingleton<QuestWindow>();
2024-06-12 16:03:48 +00:00
serviceCollection.AddSingleton<ConfigWindow>();
2024-06-18 15:51:23 +00:00
serviceCollection.AddSingleton<DebugOverlay>();
serviceCollection.AddSingleton<CommandHandler>();
2024-06-08 19:16:57 +00:00
serviceCollection.AddSingleton<DalamudInitializer>();
_serviceProvider = serviceCollection.BuildServiceProvider();
_serviceProvider.GetRequiredService<QuestRegistry>().Reload();
_serviceProvider.GetRequiredService<CommandHandler>();
2024-06-08 19:16:57 +00:00
_serviceProvider.GetRequiredService<DalamudInitializer>();
2024-05-25 21:51:37 +00:00
}
public void Dispose()
{
2024-06-08 19:16:57 +00:00
_serviceProvider?.Dispose();
2024-05-25 21:51:37 +00:00
}
}