mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Implement DI for scratchpad
This commit is contained in:
parent
c864cae087
commit
506731d7fe
4 changed files with 135 additions and 31 deletions
|
|
@ -4,7 +4,6 @@ using System.Linq;
|
|||
|
||||
using Dalamud.IoC.Internal;
|
||||
using Dalamud.Plugin;
|
||||
using ImGuiNET;
|
||||
using Microsoft.CodeAnalysis.CSharp.Scripting;
|
||||
using Microsoft.CodeAnalysis.Scripting;
|
||||
using Serilog;
|
||||
|
|
@ -60,21 +59,46 @@ namespace Dalamud.Interface.Internal.Scratchpad
|
|||
var code = doc.IsMacro ? this.MacroProcessor.Process(doc.Content) : doc.Content;
|
||||
|
||||
var options = ScriptOptions.Default
|
||||
.AddReferences(typeof(ImGui).Assembly)
|
||||
.AddReferences(typeof(Dalamud).Assembly)
|
||||
.AddReferences(typeof(FFXIVClientStructs.Resolver).Assembly) // FFXIVClientStructs
|
||||
.AddReferences(typeof(Lumina.GameData).Assembly) // Lumina
|
||||
.AddReferences(typeof(Lumina.Excel.GeneratedSheets.TerritoryType).Assembly) // Lumina.Excel
|
||||
// .WithReferences(MetadataReference.CreateFromFile(typeof(ScratchExecutionManager).Assembly.Location))
|
||||
.AddImports("System")
|
||||
.AddImports("System.IO")
|
||||
.AddImports("System.Reflection")
|
||||
.AddImports("System.Runtime.InteropServices")
|
||||
.AddImports("Dalamud")
|
||||
.AddImports("Dalamud.Plugin")
|
||||
.AddImports("Dalamud.Game.Command")
|
||||
.AddImports("Dalamud.Hooking")
|
||||
.AddImports("ImGuiNET");
|
||||
// Dalamud
|
||||
.AddReferences(typeof(Dalamud).Assembly)
|
||||
// ImGui
|
||||
.AddReferences(typeof(ImGuiNET.ImGui).Assembly)
|
||||
// ImGuiScene
|
||||
.AddReferences(typeof(ImGuiScene.RawDX11Scene).Assembly)
|
||||
// FFXIVClientStructs
|
||||
.AddReferences(typeof(FFXIVClientStructs.Resolver).Assembly)
|
||||
// Lumina
|
||||
.AddReferences(typeof(Lumina.GameData).Assembly)
|
||||
// Lumina.Excel
|
||||
.AddReferences(typeof(Lumina.Excel.GeneratedSheets.TerritoryType).Assembly)
|
||||
.AddImports("System")
|
||||
.AddImports("System.IO")
|
||||
.AddImports("System.Reflection")
|
||||
.AddImports("System.Runtime.InteropServices")
|
||||
.AddImports("Dalamud")
|
||||
.AddImports("Dalamud.Data")
|
||||
.AddImports("Dalamud.Game")
|
||||
.AddImports("Dalamud.Game.ClientState")
|
||||
.AddImports("Dalamud.Game.ClientState.Buddy")
|
||||
.AddImports("Dalamud.Game.ClientState.Conditions")
|
||||
.AddImports("Dalamud.Game.ClientState.Fates")
|
||||
.AddImports("Dalamud.Game.ClientState.JobGauge")
|
||||
.AddImports("Dalamud.Game.ClientState.Keys")
|
||||
.AddImports("Dalamud.Game.ClientState.Objects")
|
||||
.AddImports("Dalamud.Game.ClientState.Party")
|
||||
.AddImports("Dalamud.Game.Command")
|
||||
.AddImports("Dalamud.Game.Gui")
|
||||
.AddImports("Dalamud.Game.Gui.FlyText")
|
||||
.AddImports("Dalamud.Game.Gui.PartyFinder")
|
||||
.AddImports("Dalamud.Game.Gui.Toast")
|
||||
.AddImports("Dalamud.Hooking")
|
||||
.AddImports("Dalamud.Game.Libc")
|
||||
.AddImports("Dalamud.Game.Network")
|
||||
.AddImports("Dalamud.Game.Text.SeStringHandling")
|
||||
.AddImports("Dalamud.Logging")
|
||||
.AddImports("Dalamud.Plugin")
|
||||
.AddImports("Dalamud.Utility")
|
||||
.AddImports("ImGuiNET");
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,14 +17,83 @@ namespace Dalamud.Interface.Internal.Scratchpad
|
|||
public class ScratchPlugin : IDalamudPlugin {
|
||||
|
||||
public string Name => ""ScratchPlugin"";
|
||||
private DalamudPluginInterface pi;
|
||||
|
||||
private readonly DalamudPluginInterface pi;
|
||||
private readonly BuddyList buddies;
|
||||
private readonly ChatGui chat;
|
||||
private readonly ChatHandlers chatHandlers;
|
||||
private readonly ClientState clientState;
|
||||
private readonly CommandManager commands;
|
||||
private readonly Condition condition;
|
||||
private readonly DataManager data;
|
||||
private readonly FateTable fates;
|
||||
private readonly FlyTextGui flyText;
|
||||
private readonly Framework framework;
|
||||
private readonly GameGui gameGui;
|
||||
private readonly GameNetwork gameNetwork;
|
||||
private readonly JobGauges gauges;
|
||||
private readonly KeyState keyState;
|
||||
private readonly LibcFunction libc;
|
||||
private readonly ObjectTable objects;
|
||||
private readonly PartyFinderGui pfGui;
|
||||
private readonly PartyList party;
|
||||
private readonly SeStringManager seStringManager;
|
||||
private readonly SigScanner sigScanner;
|
||||
private readonly TargetManager targets;
|
||||
private readonly ToastGui toasts;
|
||||
|
||||
{SETUPBODY}
|
||||
|
||||
public ScratchPlugin(DalamudPluginInterface pluginInterface)
|
||||
public ScratchPlugin(
|
||||
DalamudPluginInterface pluginInterface,
|
||||
BuddyList buddies,
|
||||
ChatGui chat,
|
||||
ChatHandlers chatHandlers,
|
||||
ClientState clientState,
|
||||
CommandManager commands,
|
||||
Condition condition,
|
||||
DataManager data,
|
||||
FateTable fates,
|
||||
FlyTextGui flyText,
|
||||
Framework framework,
|
||||
GameGui gameGui,
|
||||
GameNetwork gameNetwork,
|
||||
JobGauges gauges,
|
||||
KeyState keyState,
|
||||
LibcFunction libcFunction,
|
||||
ObjectTable objects,
|
||||
PartyFinderGui pfGui,
|
||||
PartyList party,
|
||||
SeStringManager seStringManager,
|
||||
SigScanner sigScanner,
|
||||
TargetManager targets,
|
||||
ToastGui toasts)
|
||||
{
|
||||
this.pi = pluginInterface;
|
||||
|
||||
|
||||
this.buddies = buddies;
|
||||
this.chat = chat;
|
||||
this.chatHandlers = chatHandlers;
|
||||
this.clientState = clientState;
|
||||
this.commands = commands;
|
||||
this.condition = condition;
|
||||
this.data = data;
|
||||
this.fates = fates;
|
||||
this.flyText = flyText;
|
||||
this.framework = framework;
|
||||
this.gameGui = gameGui;
|
||||
this.gameNetwork = gameNetwork;
|
||||
this.gauges = gauges;
|
||||
this.keyState = keyState;
|
||||
this.libc = libcFunction;
|
||||
this.objects = objects;
|
||||
this.pfGui = pfGui;
|
||||
this.party = party;
|
||||
this.seStringManager = seStringManager;
|
||||
this.sigScanner = sigScanner;
|
||||
this.targets = targets;
|
||||
this.toasts = toasts;
|
||||
|
||||
this.pi.UiBuilder.Draw += DrawUI;
|
||||
|
||||
{INITBODY}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace Dalamud.IoC.Internal
|
|||
var ctor = this.FindApplicableCtor(objectType, scopedObjects);
|
||||
if (ctor == null)
|
||||
{
|
||||
Log.Error("Failed to create {TypeName}, unable to find any services to satisfy the dependencies in the ctor", objectType.FullName);
|
||||
Log.Error("Failed to create {TypeName}, unable to find one or more services to satisfy the dependencies in the ctor", objectType.FullName);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ namespace Dalamud.IoC.Internal
|
|||
|
||||
if (service == null)
|
||||
{
|
||||
Log.Error("Requested service type {TypeName} could not be satisfied", p.parameterType.FullName);
|
||||
Log.Error("Requested service type {TypeName} was not available (null)", p.parameterType.FullName);
|
||||
}
|
||||
|
||||
return service;
|
||||
|
|
@ -142,20 +142,35 @@ namespace Dalamud.IoC.Internal
|
|||
// get a list of all the available types: scoped and singleton
|
||||
var types = scopedObjects
|
||||
.Select(o => o.GetType())
|
||||
.Union(this.instances.Keys);
|
||||
.Union(this.instances.Keys)
|
||||
.ToArray();
|
||||
|
||||
var ctors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
|
||||
foreach (var ctor in ctors)
|
||||
{
|
||||
var parameters = ctor.GetParameters();
|
||||
|
||||
var success = parameters.All(p => types.Contains(p.ParameterType));
|
||||
|
||||
if (success)
|
||||
if (this.ValidateCtor(ctor, types))
|
||||
{
|
||||
return ctor;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool ValidateCtor(ConstructorInfo ctor, Type[] types)
|
||||
{
|
||||
var parameters = ctor.GetParameters();
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
var contains = types.Contains(parameter.ParameterType);
|
||||
if (!contains)
|
||||
{
|
||||
Log.Error("Failed to validate {TypeName}, unable to find any services that satisfy the type", parameter.ParameterType.FullName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Dynamic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -8,9 +7,6 @@ using System.Reflection;
|
|||
using Dalamud.Configuration;
|
||||
using Dalamud.Configuration.Internal;
|
||||
using Dalamud.Data;
|
||||
using Dalamud.Game;
|
||||
using Dalamud.Game.ClientState;
|
||||
using Dalamud.Game.Command;
|
||||
using Dalamud.Game.Gui;
|
||||
using Dalamud.Game.Text;
|
||||
using Dalamud.Game.Text.Sanitizer;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue