refactor: update to net5 and bump version to 2.0.0
This commit is contained in:
parent
6d2f03091e
commit
44d50614d4
|
@ -1,5 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Dalamud.IoC;
|
||||
using Dalamud.Plugin;
|
||||
|
||||
namespace DalamudPython {
|
||||
public class Commands {
|
||||
|
@ -65,14 +69,22 @@ namespace DalamudPython {
|
|||
}
|
||||
|
||||
private void Execute(string script, bool print) {
|
||||
var services = typeof(IDalamudPlugin).Assembly.GetTypes()
|
||||
.Where(t => t.GetCustomAttribute(typeof(PluginInterfaceAttribute)) != null)
|
||||
.Where(t => t.Namespace != null)
|
||||
.Select(t => $"from {t.Namespace!} import {t.Name}");
|
||||
|
||||
var scope = this.Plugin.Engine.CreateScope();
|
||||
scope.SetVariable("interface", this.Plugin.Interface);
|
||||
scope.SetVariable("store", this.Store);
|
||||
var fullScript = $@"import clr
|
||||
from DalamudPython.Util import *
|
||||
from Dalamud import *
|
||||
from Dalamud.Plugin import *
|
||||
{string.Join('\n', services)}
|
||||
from Lumina import *
|
||||
from Lumina.Excel.GeneratedSheets import *
|
||||
### begin custom
|
||||
{script}";
|
||||
var result = this.Plugin.Engine.Execute(fullScript, scope);
|
||||
|
||||
|
@ -80,7 +92,7 @@ from Lumina.Excel.GeneratedSheets import *
|
|||
return;
|
||||
}
|
||||
|
||||
this.Plugin.Interface.Framework.Gui.Chat.Print(result.ToString());
|
||||
this.Plugin.ChatGui.Print(result.ToString());
|
||||
}
|
||||
|
||||
private void OneLiner(string name, string args) {
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<TargetFramework>net5-windows</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>1.1.2</Version>
|
||||
<Version>2.0.0</Version>
|
||||
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -24,13 +26,11 @@
|
|||
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Costura.Fody" Version="5.3.0" PrivateAssets="all"/>
|
||||
<PackageReference Include="DalamudPackager" Version="1.2.1"/>
|
||||
<PackageReference Include="Fody" Version="6.5.1" PrivateAssets="all"/>
|
||||
<PackageReference Include="DalamudLinter" Version="1.0.3"/>
|
||||
<PackageReference Include="DalamudPackager" Version="2.1.2"/>
|
||||
<PackageReference Include="IronPython" Version="2.7.11"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<Costura />
|
||||
</Weavers>
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Target Name="ILRepacker" AfterTargets="Build">
|
||||
<ItemGroup>
|
||||
<InputAssemblies Include="$(OutputPath)\*.dll"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ILRepack
|
||||
Parallel="true"
|
||||
Internalize="false"
|
||||
InputAssemblies="@(InputAssemblies)"
|
||||
TargetKind="Dll"
|
||||
TargetPlatformVersion="v4"
|
||||
LibraryPath="$(OutputPath)"
|
||||
OutputFile="$(OutputPath)\$(AssemblyName).dll"/>
|
||||
</Target>
|
||||
</Project>
|
|
@ -2,6 +2,8 @@
|
|||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Dalamud.Game.Command;
|
||||
using Dalamud.Game.Gui;
|
||||
using Dalamud.IoC;
|
||||
using Dalamud.Plugin;
|
||||
using IronPython.Hosting;
|
||||
using Microsoft.Scripting.Hosting;
|
||||
|
@ -10,11 +12,18 @@ namespace DalamudPython {
|
|||
public class Plugin : IDalamudPlugin {
|
||||
public string Name => "DalamudPython";
|
||||
|
||||
public DalamudPluginInterface Interface { get; private set; } = null!;
|
||||
[PluginService]
|
||||
public DalamudPluginInterface Interface { get; private init; } = null!;
|
||||
|
||||
[PluginService]
|
||||
internal ChatGui ChatGui { get; private init; } = null!;
|
||||
|
||||
[PluginService]
|
||||
internal CommandManager CommandManager { get; private init; } = null!;
|
||||
|
||||
public ScriptEngine Engine { get; } = Python.CreateEngine();
|
||||
|
||||
private Commands Commands { get; set; } = null!;
|
||||
private Commands Commands { get; }
|
||||
|
||||
public string ConfigDirectory => Path.Combine(new[] {
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
|
@ -23,12 +32,11 @@ namespace DalamudPython {
|
|||
this.Name,
|
||||
});
|
||||
|
||||
public void Initialize(DalamudPluginInterface pluginInterface) {
|
||||
this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface));
|
||||
|
||||
public Plugin() {
|
||||
// set a global variable for the plugin interface
|
||||
this.Engine.Runtime.Globals.SetVariable("interface", this.Interface);
|
||||
// load Dalamud, Lumina, and ImGuiNET
|
||||
this.Engine.Runtime.LoadAssembly(this.GetType().Assembly);
|
||||
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(DalamudPluginInterface)));
|
||||
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(Lumina.GameData)));
|
||||
this.Engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(Lumina.Excel.ExcelRow)));
|
||||
|
@ -37,9 +45,9 @@ namespace DalamudPython {
|
|||
|
||||
this.Commands = new Commands(this);
|
||||
|
||||
foreach (var command in Commands.All) {
|
||||
this.Interface.CommandManager.AddHandler(command.Key, new CommandInfo(this.Commands.OnCommand) {
|
||||
HelpMessage = command.Value,
|
||||
foreach (var (name, desc) in Commands.All) {
|
||||
this.CommandManager.AddHandler(name, new CommandInfo(this.Commands.OnCommand) {
|
||||
HelpMessage = desc,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -48,7 +56,7 @@ namespace DalamudPython {
|
|||
|
||||
public void Dispose() {
|
||||
foreach (var name in Commands.All.Keys) {
|
||||
this.Interface.CommandManager.RemoveHandler(name);
|
||||
this.CommandManager.RemoveHandler(name);
|
||||
}
|
||||
|
||||
this.Engine.Runtime.Shutdown();
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
using System.Reflection;
|
||||
using Dalamud.Logging;
|
||||
using Dalamud.Plugin;
|
||||
|
||||
namespace DalamudPython {
|
||||
public static class Util {
|
||||
public static T GetService<T>() {
|
||||
PluginLog.Log($"Requesting {typeof(T)}");
|
||||
var service = typeof(IDalamudPlugin).Assembly.GetType("Dalamud.Service`1")!.MakeGenericType(typeof(T));
|
||||
var get = service.GetMethod("Get", BindingFlags.Public | BindingFlags.Static)!;
|
||||
return (T) get.Invoke(null, null)!;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue