mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
feat: plugin config WIP
This commit is contained in:
parent
942893400f
commit
43d514ab9b
5 changed files with 62 additions and 10 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Dalamud.Configuration;
|
||||||
using Dalamud.DiscordBot;
|
using Dalamud.DiscordBot;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using XIVLauncher.Dalamud;
|
using XIVLauncher.Dalamud;
|
||||||
|
|
@ -31,6 +32,8 @@ namespace Dalamud
|
||||||
|
|
||||||
public string LastVersion { get; set; }
|
public string LastVersion { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<string, IPluginConfiguration> PluginConfigurations { get; set; }
|
||||||
|
|
||||||
public static DalamudConfiguration Load(string path) {
|
public static DalamudConfiguration Load(string path) {
|
||||||
return JsonConvert.DeserializeObject<DalamudConfiguration>(File.ReadAllText(path));
|
return JsonConvert.DeserializeObject<DalamudConfiguration>(File.ReadAllText(path));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
Dalamud/Configuration/IPluginConfiguration.cs
Normal file
13
Dalamud/Configuration/IPluginConfiguration.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Dalamud.Configuration
|
||||||
|
{
|
||||||
|
public interface IPluginConfiguration
|
||||||
|
{
|
||||||
|
int Version { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup Label="Target">
|
<PropertyGroup Label="Target">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<TargetFramework>net471</TargetFramework>
|
<TargetFramework>net471</TargetFramework>
|
||||||
|
|
@ -65,7 +65,4 @@
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Configuration\" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Dalamud.Configuration;
|
||||||
using Dalamud.Game.ClientState;
|
using Dalamud.Game.ClientState;
|
||||||
using Dalamud.Game.Command;
|
using Dalamud.Game.Command;
|
||||||
using Dalamud.Game.Internal;
|
using Dalamud.Game.Internal;
|
||||||
|
|
@ -29,14 +32,51 @@ namespace Dalamud.Plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly Framework Framework;
|
public readonly Framework Framework;
|
||||||
|
|
||||||
|
private readonly Dalamud dalamud;
|
||||||
|
private readonly string pluginName;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set up the interface and populate all fields needed.
|
/// Set up the interface and populate all fields needed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dalamud"></param>
|
/// <param name="dalamud"></param>
|
||||||
public DalamudPluginInterface(Dalamud dalamud) {
|
public DalamudPluginInterface(Dalamud dalamud, string pluginName) {
|
||||||
this.CommandManager = dalamud.CommandManager;
|
this.CommandManager = dalamud.CommandManager;
|
||||||
this.Framework = dalamud.Framework;
|
this.Framework = dalamud.Framework;
|
||||||
this.ClientState = dalamud.ClientState;
|
this.ClientState = dalamud.ClientState;
|
||||||
|
|
||||||
|
this.dalamud = dalamud;
|
||||||
|
this.pluginName = pluginName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Save a plugin configuration(inheriting IPluginConfiguration).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentConfig">The current configuration.</param>
|
||||||
|
public void SavePluginConfig(IPluginConfiguration currentConfig) {
|
||||||
|
if (this.dalamud.Configuration.PluginConfigurations == null)
|
||||||
|
this.dalamud.Configuration.PluginConfigurations = new Dictionary<string, IPluginConfiguration>();
|
||||||
|
|
||||||
|
if (this.dalamud.Configuration.PluginConfigurations.ContainsKey(this.pluginName)) {
|
||||||
|
this.dalamud.Configuration.PluginConfigurations[this.pluginName] = currentConfig;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dalamud.Configuration.PluginConfigurations.Add(this.pluginName, currentConfig);
|
||||||
|
this.dalamud.Configuration.Save(this.dalamud.StartInfo.ConfigurationPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a previously saved plugin configuration or null if none was saved before.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A previously saved config or null if none was saved before.</returns>
|
||||||
|
public IPluginConfiguration GetPluginConfig() {
|
||||||
|
if (this.dalamud.Configuration.PluginConfigurations == null)
|
||||||
|
this.dalamud.Configuration.PluginConfigurations = new Dictionary<string, IPluginConfiguration>();
|
||||||
|
|
||||||
|
if (!this.dalamud.Configuration.PluginConfigurations.ContainsKey(this.pluginName))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return this.dalamud.Configuration.PluginConfigurations[this.pluginName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,12 @@ namespace Dalamud.Plugin
|
||||||
private readonly string pluginDirectory;
|
private readonly string pluginDirectory;
|
||||||
private readonly string defaultPluginDirectory;
|
private readonly string defaultPluginDirectory;
|
||||||
|
|
||||||
private readonly DalamudPluginInterface dalamudInterface;
|
|
||||||
|
|
||||||
private List<IDalamudPlugin> plugins;
|
private List<IDalamudPlugin> plugins;
|
||||||
|
|
||||||
public PluginManager(Dalamud dalamud, string pluginDirectory, string defaultPluginDirectory) {
|
public PluginManager(Dalamud dalamud, string pluginDirectory, string defaultPluginDirectory) {
|
||||||
this.dalamud = dalamud;
|
this.dalamud = dalamud;
|
||||||
this.pluginDirectory = pluginDirectory;
|
this.pluginDirectory = pluginDirectory;
|
||||||
this.defaultPluginDirectory = defaultPluginDirectory;
|
this.defaultPluginDirectory = defaultPluginDirectory;
|
||||||
|
|
||||||
this.dalamudInterface = new DalamudPluginInterface(dalamud);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnloadPlugins() {
|
public void UnloadPlugins() {
|
||||||
|
|
@ -79,7 +75,10 @@ namespace Dalamud.Plugin
|
||||||
foreach (var pluginType in foundImplementations)
|
foreach (var pluginType in foundImplementations)
|
||||||
{
|
{
|
||||||
var plugin = (IDalamudPlugin)Activator.CreateInstance(pluginType);
|
var plugin = (IDalamudPlugin)Activator.CreateInstance(pluginType);
|
||||||
plugin.Initialize(this.dalamudInterface);
|
|
||||||
|
var dalamudInterface = new DalamudPluginInterface(this.dalamud, pluginType.Assembly.GetName().Name);
|
||||||
|
|
||||||
|
plugin.Initialize(dalamudInterface);
|
||||||
Log.Information("Loaded plugin: {0}", plugin.Name);
|
Log.Information("Loaded plugin: {0}", plugin.Name);
|
||||||
this.plugins.Add(plugin);
|
this.plugins.Add(plugin);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue