Add GetChangedItems for Mods.

This commit is contained in:
Ottermandias 2024-06-01 23:33:21 +02:00
parent 5101b73fdc
commit e7cf9d35c9
5 changed files with 44 additions and 14 deletions

@ -1 +1 @@
Subproject commit 69d106b457eb0f73d4b4caf1234da5631fd6fbf0 Subproject commit f1e4e520daaa8f23e5c8b71d55e5992b8f6768e2

View file

@ -107,7 +107,7 @@ public class ModsApi : IPenumbraApiMods, IApiService, IDisposable
var fullPath = leaf.FullName(); var fullPath = leaf.FullName();
var isDefault = ModFileSystem.ModHasDefaultPath(mod, fullPath); var isDefault = ModFileSystem.ModHasDefaultPath(mod, fullPath);
var isNameDefault = isDefault || ModFileSystem.ModHasDefaultPath(mod, leaf.Name); var isNameDefault = isDefault || ModFileSystem.ModHasDefaultPath(mod, leaf.Name);
return (PenumbraApiEc.Success, fullPath, !isDefault, !isNameDefault ); return (PenumbraApiEc.Success, fullPath, !isDefault, !isNameDefault);
} }
public PenumbraApiEc SetModPath(string modDirectory, string modName, string newPath) public PenumbraApiEc SetModPath(string modDirectory, string modName, string newPath)
@ -129,4 +129,9 @@ public class ModsApi : IPenumbraApiMods, IApiService, IDisposable
return PenumbraApiEc.PathRenameFailed; return PenumbraApiEc.PathRenameFailed;
} }
} }
public Dictionary<string, object?> GetChangedItems(string modDirectory, string modName)
=> _modManager.TryGetMod(modDirectory, modName, out var mod)
? mod.ChangedItems.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
: [];
} }

View file

@ -22,7 +22,7 @@ public class PenumbraApi(
} }
public (int Breaking, int Feature) ApiVersion public (int Breaking, int Feature) ApiVersion
=> (5, 0); => (5, 1);
public bool Valid { get; private set; } = true; public bool Valid { get; private set; } = true;
public IPenumbraApiCollection Collection { get; } = collection; public IPenumbraApiCollection Collection { get; } = collection;

View file

@ -49,6 +49,7 @@ public sealed class IpcProviders : IDisposable, IApiService
IpcSubscribers.ModMoved.Provider(pi, api.Mods), IpcSubscribers.ModMoved.Provider(pi, api.Mods),
IpcSubscribers.GetModPath.Provider(pi, api.Mods), IpcSubscribers.GetModPath.Provider(pi, api.Mods),
IpcSubscribers.SetModPath.Provider(pi, api.Mods), IpcSubscribers.SetModPath.Provider(pi, api.Mods),
IpcSubscribers.GetChangedItems.Provider(pi, api.Mods),
IpcSubscribers.GetAvailableModSettings.Provider(pi, api.ModSettings), IpcSubscribers.GetAvailableModSettings.Provider(pi, api.ModSettings),
IpcSubscribers.GetCurrentModSettings.Provider(pi, api.ModSettings), IpcSubscribers.GetCurrentModSettings.Provider(pi, api.ModSettings),

View file

@ -3,6 +3,7 @@ using Dalamud.Plugin;
using ImGuiNET; using ImGuiNET;
using OtterGui.Raii; using OtterGui.Raii;
using OtterGui.Services; using OtterGui.Services;
using OtterGui.Text;
using Penumbra.Api.Enums; using Penumbra.Api.Enums;
using Penumbra.Api.Helpers; using Penumbra.Api.Helpers;
using Penumbra.Api.IpcSubscribers; using Penumbra.Api.IpcSubscribers;
@ -23,6 +24,7 @@ public class ModsIpcTester : IUiService, IDisposable
private PenumbraApiEc _lastSetPathEc; private PenumbraApiEc _lastSetPathEc;
private PenumbraApiEc _lastInstallEc; private PenumbraApiEc _lastInstallEc;
private Dictionary<string, string> _mods = []; private Dictionary<string, string> _mods = [];
private Dictionary<string, object?> _changedItems = [];
public readonly EventSubscriber<string> DeleteSubscriber; public readonly EventSubscriber<string> DeleteSubscriber;
public readonly EventSubscriber<string> AddSubscriber; public readonly EventSubscriber<string> AddSubscriber;
@ -120,6 +122,14 @@ public class ModsIpcTester : IUiService, IDisposable
ImGui.SameLine(); ImGui.SameLine();
ImGui.TextUnformatted(_lastDeleteEc.ToString()); ImGui.TextUnformatted(_lastDeleteEc.ToString());
IpcTester.DrawIntro(GetChangedItems.Label, "Get Changed Items");
DrawChangedItemsPopup();
if (ImUtf8.Button("Get##ChangedItems"u8))
{
_changedItems = new GetChangedItems(_pi).Invoke(_modDirectory, _modName);
ImUtf8.OpenPopup("ChangedItems"u8);
}
IpcTester.DrawIntro(GetModPath.Label, "Current Path"); IpcTester.DrawIntro(GetModPath.Label, "Current Path");
var (ec, path, def, nameDef) = new GetModPath(_pi).Invoke(_modDirectory, _modName); var (ec, path, def, nameDef) = new GetModPath(_pi).Invoke(_modDirectory, _modName);
ImGui.TextUnformatted($"{path} ({(def ? "Custom" : "Default")} Path, {(nameDef ? "Custom" : "Default")} Name) [{ec}]"); ImGui.TextUnformatted($"{path} ({(def ? "Custom" : "Default")} Path, {(nameDef ? "Custom" : "Default")} Name) [{ec}]");
@ -157,4 +167,18 @@ public class ModsIpcTester : IUiService, IDisposable
if (ImGui.Button("Close", -Vector2.UnitX) || !ImGui.IsWindowFocused()) if (ImGui.Button("Close", -Vector2.UnitX) || !ImGui.IsWindowFocused())
ImGui.CloseCurrentPopup(); ImGui.CloseCurrentPopup();
} }
private void DrawChangedItemsPopup()
{
ImGui.SetNextWindowSize(ImGuiHelpers.ScaledVector2(500, 500));
using var p = ImUtf8.Popup("ChangedItems"u8);
if (!p)
return;
foreach (var (name, data) in _changedItems)
ImUtf8.Text($"{name}: {data}");
if (ImUtf8.Button("Close"u8, -Vector2.UnitX) || !ImGui.IsWindowFocused())
ImGui.CloseCurrentPopup();
}
} }