mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Add IPC for querying temporary settings.
This commit is contained in:
parent
82689467aa
commit
30a4b90e84
4 changed files with 128 additions and 9 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit de0f281fbf9d8d9d3aa8463a28025d54877cde8d
|
||||
Subproject commit b4e716f86d94cd4d98d8f58e580ed5f619ea87ae
|
||||
|
|
@ -130,11 +130,54 @@ public class TemporaryApi(
|
|||
return ApiHelpers.Return(ret, args);
|
||||
}
|
||||
|
||||
public (PenumbraApiEc, (bool, bool, int, Dictionary<string, List<string>>)?, string) QueryTemporaryModSettings(Guid collectionId, string modDirectory,
|
||||
string modName, int key)
|
||||
{
|
||||
var args = ApiHelpers.Args("CollectionId", collectionId, "ModDirectory", modDirectory, "ModName", modName);
|
||||
if (!collectionManager.Storage.ById(collectionId, out var collection))
|
||||
return (ApiHelpers.Return(PenumbraApiEc.CollectionMissing, args), null, string.Empty);
|
||||
|
||||
public PenumbraApiEc SetTemporaryModSettings(Guid collectionId, string modDirectory, string modName, bool inherit, bool enabled, int priority,
|
||||
return QueryTemporaryModSettings(args, collection, modDirectory, modName, key);
|
||||
}
|
||||
|
||||
public (PenumbraApiEc ErrorCode, (bool, bool, int, Dictionary<string, List<string>>)? Settings, string Source)
|
||||
QueryTemporaryModSettingsPlayer(int objectIndex,
|
||||
string modDirectory, string modName, int key)
|
||||
{
|
||||
var args = ApiHelpers.Args("ObjectIndex", objectIndex, "ModDirectory", modDirectory, "ModName", modName);
|
||||
if (!apiHelpers.AssociatedCollection(objectIndex, out var collection))
|
||||
return (ApiHelpers.Return(PenumbraApiEc.InvalidArgument, args), null, string.Empty);
|
||||
|
||||
return QueryTemporaryModSettings(args, collection, modDirectory, modName, key);
|
||||
}
|
||||
|
||||
private (PenumbraApiEc ErrorCode, (bool, bool, int, Dictionary<string, List<string>>)? Settings, string Source) QueryTemporaryModSettings(
|
||||
in LazyString args, ModCollection collection, string modDirectory, string modName, int key)
|
||||
{
|
||||
if (!modManager.TryGetMod(modDirectory, modName, out var mod))
|
||||
return (ApiHelpers.Return(PenumbraApiEc.ModMissing, args), null, string.Empty);
|
||||
|
||||
if (collection.Identity.Index <= 0)
|
||||
return (ApiHelpers.Return(PenumbraApiEc.Success, args), null, string.Empty);
|
||||
|
||||
var settings = collection.GetTempSettings(mod.Index);
|
||||
if (settings == null)
|
||||
return (ApiHelpers.Return(PenumbraApiEc.Success, args), null, string.Empty);
|
||||
|
||||
if (settings.Lock > 0 && settings.Lock != key)
|
||||
return (ApiHelpers.Return(PenumbraApiEc.TemporarySettingDisallowed, args), null, settings.Source);
|
||||
|
||||
return (ApiHelpers.Return(PenumbraApiEc.Success, args),
|
||||
(settings.ForceInherit, settings.Enabled, settings.Priority.Value, settings.ConvertToShareable(mod).Settings), settings.Source);
|
||||
}
|
||||
|
||||
|
||||
public PenumbraApiEc SetTemporaryModSettings(Guid collectionId, string modDirectory, string modName, bool inherit, bool enabled,
|
||||
int priority,
|
||||
IReadOnlyDictionary<string, IReadOnlyList<string>> options, string source, int key)
|
||||
{
|
||||
var args = ApiHelpers.Args("CollectionId", collectionId, "ModDirectory", modDirectory, "ModName", modName, "Inherit", inherit, "Enabled", enabled,
|
||||
var args = ApiHelpers.Args("CollectionId", collectionId, "ModDirectory", modDirectory, "ModName", modName, "Inherit", inherit,
|
||||
"Enabled", enabled,
|
||||
"Priority", priority, "Options", options, "Source", source, "Key", key);
|
||||
if (!collectionManager.Storage.ById(collectionId, out var collection))
|
||||
return ApiHelpers.Return(PenumbraApiEc.CollectionMissing, args);
|
||||
|
|
@ -142,10 +185,12 @@ public class TemporaryApi(
|
|||
return SetTemporaryModSettings(args, collection, modDirectory, modName, inherit, enabled, priority, options, source, key);
|
||||
}
|
||||
|
||||
public PenumbraApiEc SetTemporaryModSettingsPlayer(int objectIndex, string modDirectory, string modName, bool inherit, bool enabled, int priority,
|
||||
public PenumbraApiEc SetTemporaryModSettingsPlayer(int objectIndex, string modDirectory, string modName, bool inherit, bool enabled,
|
||||
int priority,
|
||||
IReadOnlyDictionary<string, IReadOnlyList<string>> options, string source, int key)
|
||||
{
|
||||
var args = ApiHelpers.Args("ObjectIndex", objectIndex, "ModDirectory", modDirectory, "ModName", modName, "Inherit", inherit, "Enabled", enabled,
|
||||
var args = ApiHelpers.Args("ObjectIndex", objectIndex, "ModDirectory", modDirectory, "ModName", modName, "Inherit", inherit, "Enabled",
|
||||
enabled,
|
||||
"Priority", priority, "Options", options, "Source", source, "Key", key);
|
||||
if (!apiHelpers.AssociatedCollection(objectIndex, out var collection))
|
||||
return ApiHelpers.Return(PenumbraApiEc.InvalidArgument, args);
|
||||
|
|
@ -254,7 +299,8 @@ public class TemporaryApi(
|
|||
var numRemoved = 0;
|
||||
for (var i = 0; i < collection.Settings.Count; ++i)
|
||||
{
|
||||
if (collection.GetTempSettings(i) is {} tempSettings && tempSettings.Lock == key
|
||||
if (collection.GetTempSettings(i) is { } tempSettings
|
||||
&& tempSettings.Lock == key
|
||||
&& collectionManager.Editor.SetTemporarySettings(collection, modManager[i], null, key))
|
||||
++numRemoved;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,6 +103,8 @@ public sealed class IpcProviders : IDisposable, IApiService
|
|||
IpcSubscribers.RemoveTemporaryModSettingsPlayer.Provider(pi, api.Temporary),
|
||||
IpcSubscribers.RemoveAllTemporaryModSettings.Provider(pi, api.Temporary),
|
||||
IpcSubscribers.RemoveAllTemporaryModSettingsPlayer.Provider(pi, api.Temporary),
|
||||
IpcSubscribers.QueryTemporaryModSettings.Provider(pi, api.Temporary),
|
||||
IpcSubscribers.QueryTemporaryModSettingsPlayer.Provider(pi, api.Temporary),
|
||||
|
||||
IpcSubscribers.ChangedItemTooltip.Provider(pi, api.Ui),
|
||||
IpcSubscribers.ChangedItemClicked.Provider(pi, api.Ui),
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class TemporaryIpcTester(
|
|||
ImGuiUtil.GuidInput("##guid", "Collection GUID...", string.Empty, ref _tempGuid, ref _tempCollectionGuidName);
|
||||
ImGui.InputInt("##tempActorIndex", ref _tempActorIndex, 0, 0);
|
||||
ImGui.InputTextWithHint("##tempMod", "Temporary Mod Name...", ref _tempModName, 32);
|
||||
ImGui.InputTextWithHint("##mod", "Existing Mod Name...", ref _modDirectory, 256);
|
||||
ImGui.InputTextWithHint("##mod", "Existing Mod Name...", ref _modDirectory, 256);
|
||||
ImGui.InputTextWithHint("##tempGame", "Game Path...", ref _tempGamePath, 256);
|
||||
ImGui.InputTextWithHint("##tempFile", "File Path...", ref _tempFilePath, 256);
|
||||
ImUtf8.InputText("##tempManip"u8, ref _tempManipulation, "Manipulation Base64 String..."u8);
|
||||
|
|
@ -126,12 +126,14 @@ public class TemporaryIpcTester(
|
|||
|
||||
IpcTester.DrawIntro(SetTemporaryModSettings.Label, "Set Temporary Mod Settings (to default) in specific Collection");
|
||||
if (ImUtf8.Button("Set##SetTemporary"u8))
|
||||
_lastTempError = new SetTemporaryModSettings(pi).Invoke(guid, _modDirectory, false, true, 1337, new Dictionary<string, IReadOnlyList<string>>(),
|
||||
_lastTempError = new SetTemporaryModSettings(pi).Invoke(guid, _modDirectory, false, true, 1337,
|
||||
new Dictionary<string, IReadOnlyList<string>>(),
|
||||
"IPC Tester", 1337);
|
||||
|
||||
IpcTester.DrawIntro(SetTemporaryModSettingsPlayer.Label, "Set Temporary Mod Settings (to default) in game object collection");
|
||||
if (ImUtf8.Button("Set##SetTemporaryPlayer"u8))
|
||||
_lastTempError = new SetTemporaryModSettingsPlayer(pi).Invoke(_tempActorIndex, _modDirectory, false, true, 1337, new Dictionary<string, IReadOnlyList<string>>(),
|
||||
_lastTempError = new SetTemporaryModSettingsPlayer(pi).Invoke(_tempActorIndex, _modDirectory, false, true, 1337,
|
||||
new Dictionary<string, IReadOnlyList<string>>(),
|
||||
"IPC Tester", 1337);
|
||||
|
||||
IpcTester.DrawIntro(RemoveTemporaryModSettings.Label, "Remove Temporary Mod Settings from specific Collection");
|
||||
|
|
@ -161,6 +163,75 @@ public class TemporaryIpcTester(
|
|||
ImGui.SameLine();
|
||||
if (ImUtf8.Button("Remove (Wrong Key)##RemoveAllTemporaryPlayer"u8))
|
||||
_lastTempError = new RemoveAllTemporaryModSettingsPlayer(pi).Invoke(_tempActorIndex, 1338);
|
||||
|
||||
IpcTester.DrawIntro(QueryTemporaryModSettings.Label, "Query Temporary Mod Settings from specific Collection");
|
||||
ImUtf8.Button("Query##QueryTemporaryModSettings"u8);
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
_lastTempError = new QueryTemporaryModSettings(pi).Invoke(guid, _modDirectory, out var settings, out var source, 1337);
|
||||
DrawTooltip(settings, source);
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
ImUtf8.Button("Query (Wrong Key)##RemoveAllTemporary"u8);
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
_lastTempError = new QueryTemporaryModSettings(pi).Invoke(guid, _modDirectory, out var settings, out var source, 1338);
|
||||
DrawTooltip(settings, source);
|
||||
}
|
||||
|
||||
IpcTester.DrawIntro(QueryTemporaryModSettingsPlayer.Label, "Query Temporary Mod Settings from game object Collection");
|
||||
ImUtf8.Button("Query##QueryTemporaryModSettingsPlayer"u8);
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
_lastTempError =
|
||||
new QueryTemporaryModSettingsPlayer(pi).Invoke(_tempActorIndex, _modDirectory, out var settings, out var source, 1337);
|
||||
DrawTooltip(settings, source);
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
ImUtf8.Button("Query (Wrong Key)##RemoveAllTemporaryPlayer"u8);
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
_lastTempError =
|
||||
new QueryTemporaryModSettingsPlayer(pi).Invoke(_tempActorIndex, _modDirectory, out var settings, out var source, 1338);
|
||||
DrawTooltip(settings, source);
|
||||
}
|
||||
|
||||
void DrawTooltip((bool ForceInherit, bool Enabled, int Priority, Dictionary<string, List<string>> Settings)? settings, string source)
|
||||
{
|
||||
using var tt = ImUtf8.Tooltip();
|
||||
ImUtf8.Text($"Query returned {_lastTempError}");
|
||||
if (settings != null)
|
||||
ImUtf8.Text($"Settings created by {(source.Length == 0 ? "Unknown Source" : source)}:");
|
||||
else
|
||||
ImUtf8.Text(source.Length > 0 ? $"Locked by {source}." : "No settings exist.");
|
||||
ImGui.Separator();
|
||||
if (settings == null)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
using (ImUtf8.Group())
|
||||
{
|
||||
ImUtf8.Text("Force Inherit"u8);
|
||||
ImUtf8.Text("Enabled"u8);
|
||||
ImUtf8.Text("Priority"u8);
|
||||
foreach (var group in settings.Value.Settings.Keys)
|
||||
ImUtf8.Text(group);
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
using (ImUtf8.Group())
|
||||
{
|
||||
ImUtf8.Text($"{settings.Value.ForceInherit}");
|
||||
ImUtf8.Text($"{settings.Value.Enabled}");
|
||||
ImUtf8.Text($"{settings.Value.Priority}");
|
||||
foreach (var group in settings.Value.Settings.Values)
|
||||
ImUtf8.Text(string.Join("; ", group));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawCollections()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue