mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
CS API update and add http API routes.
This commit is contained in:
parent
e9f67a009b
commit
a59689ebfe
2 changed files with 53 additions and 9 deletions
|
|
@ -5,6 +5,7 @@ using EmbedIO.WebApi;
|
||||||
using OtterGui.Services;
|
using OtterGui.Services;
|
||||||
using Penumbra.Api.Api;
|
using Penumbra.Api.Api;
|
||||||
using Penumbra.Api.Enums;
|
using Penumbra.Api.Enums;
|
||||||
|
using Penumbra.Mods.Settings;
|
||||||
|
|
||||||
namespace Penumbra.Api;
|
namespace Penumbra.Api;
|
||||||
|
|
||||||
|
|
@ -13,13 +14,15 @@ public class HttpApi : IDisposable, IApiService
|
||||||
private partial class Controller : WebApiController
|
private partial class Controller : WebApiController
|
||||||
{
|
{
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
[Route( HttpVerbs.Get, "/mods" )] public partial object? GetMods();
|
[Route( HttpVerbs.Get, "/moddirectory" )] public partial string GetModDirectory();
|
||||||
[Route( HttpVerbs.Post, "/redraw" )] public partial Task Redraw();
|
[Route( HttpVerbs.Get, "/mods" )] public partial object? GetMods();
|
||||||
[Route( HttpVerbs.Post, "/redrawAll" )] public partial Task RedrawAll();
|
[Route( HttpVerbs.Post, "/redraw" )] public partial Task Redraw();
|
||||||
[Route( HttpVerbs.Post, "/reloadmod" )] public partial Task ReloadMod();
|
[Route( HttpVerbs.Post, "/redrawAll" )] public partial Task RedrawAll();
|
||||||
[Route( HttpVerbs.Post, "/installmod" )] public partial Task InstallMod();
|
[Route( HttpVerbs.Post, "/reloadmod" )] public partial Task ReloadMod();
|
||||||
[Route( HttpVerbs.Post, "/openwindow" )] public partial void OpenWindow();
|
[Route( HttpVerbs.Post, "/installmod" )] public partial Task InstallMod();
|
||||||
[Route( HttpVerbs.Post, "/focusmod" )] public partial Task FocusMod();
|
[Route( HttpVerbs.Post, "/openwindow" )] public partial void OpenWindow();
|
||||||
|
[Route( HttpVerbs.Post, "/focusmod" )] public partial Task FocusMod();
|
||||||
|
[Route( HttpVerbs.Post, "/setmodsettings")] public partial Task SetModSettings();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,6 +68,12 @@ public class HttpApi : IDisposable, IApiService
|
||||||
|
|
||||||
private partial class Controller(IPenumbraApi api, IFramework framework)
|
private partial class Controller(IPenumbraApi api, IFramework framework)
|
||||||
{
|
{
|
||||||
|
public partial string GetModDirectory()
|
||||||
|
{
|
||||||
|
Penumbra.Log.Debug($"[HTTP] {nameof(GetModDirectory)} triggered.");
|
||||||
|
return api.PluginState.GetModDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
public partial object? GetMods()
|
public partial object? GetMods()
|
||||||
{
|
{
|
||||||
Penumbra.Log.Debug($"[HTTP] {nameof(GetMods)} triggered.");
|
Penumbra.Log.Debug($"[HTTP] {nameof(GetMods)} triggered.");
|
||||||
|
|
@ -116,6 +125,7 @@ public class HttpApi : IDisposable, IApiService
|
||||||
Penumbra.Log.Debug($"[HTTP] {nameof(OpenWindow)} triggered.");
|
Penumbra.Log.Debug($"[HTTP] {nameof(OpenWindow)} triggered.");
|
||||||
api.Ui.OpenMainWindow(TabType.Mods, string.Empty, string.Empty);
|
api.Ui.OpenMainWindow(TabType.Mods, string.Empty, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async partial Task FocusMod()
|
public async partial Task FocusMod()
|
||||||
{
|
{
|
||||||
var data = await HttpContext.GetRequestDataAsync<ModFocusData>().ConfigureAwait(false);
|
var data = await HttpContext.GetRequestDataAsync<ModFocusData>().ConfigureAwait(false);
|
||||||
|
|
@ -124,6 +134,30 @@ public class HttpApi : IDisposable, IApiService
|
||||||
api.Ui.OpenMainWindow(TabType.Mods, data.Path, data.Name);
|
api.Ui.OpenMainWindow(TabType.Mods, data.Path, data.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async partial Task SetModSettings()
|
||||||
|
{
|
||||||
|
var data = await HttpContext.GetRequestDataAsync<SetModSettingsData>().ConfigureAwait(false);
|
||||||
|
Penumbra.Log.Debug($"[HTTP] {nameof(SetModSettings)} triggered.");
|
||||||
|
await framework.RunOnFrameworkThread(() =>
|
||||||
|
{
|
||||||
|
var collection = data.CollectionId ?? api.Collection.GetCollection(ApiCollectionType.Current)!.Value.Id;
|
||||||
|
if (data.Inherit.HasValue)
|
||||||
|
{
|
||||||
|
api.ModSettings.TryInheritMod(collection, data.ModPath, data.ModName, data.Inherit.Value);
|
||||||
|
if (data.Inherit.Value)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.State.HasValue)
|
||||||
|
api.ModSettings.TrySetMod(collection, data.ModPath, data.ModName, data.State.Value);
|
||||||
|
if (data.Priority.HasValue)
|
||||||
|
api.ModSettings.TrySetModPriority(collection, data.ModPath, data.ModName, data.Priority.Value.Value);
|
||||||
|
foreach (var (group, settings) in data.Settings ?? [])
|
||||||
|
api.ModSettings.TrySetModSettings(collection, data.ModPath, data.ModName, group, settings);
|
||||||
|
}
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
private record ModReloadData(string Path, string Name)
|
private record ModReloadData(string Path, string Name)
|
||||||
{
|
{
|
||||||
public ModReloadData()
|
public ModReloadData()
|
||||||
|
|
@ -151,5 +185,15 @@ public class HttpApi : IDisposable, IApiService
|
||||||
: this(string.Empty, RedrawType.Redraw, -1)
|
: this(string.Empty, RedrawType.Redraw, -1)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record SetModSettingsData(
|
||||||
|
Guid? CollectionId,
|
||||||
|
string ModPath,
|
||||||
|
string ModName,
|
||||||
|
bool? Inherit,
|
||||||
|
bool? State,
|
||||||
|
ModPriority? Priority,
|
||||||
|
Dictionary<string, List<string>>? Settings)
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -421,9 +421,9 @@ public sealed unsafe partial class RedrawService : IDisposable
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
foreach (ref var f in currentTerritory->Furniture)
|
foreach (ref var f in currentTerritory->FurnitureManager.FurnitureMemory)
|
||||||
{
|
{
|
||||||
var gameObject = f.Index >= 0 ? currentTerritory->HousingObjectManager.Objects[f.Index].Value : null;
|
var gameObject = f.Index >= 0 ? currentTerritory->FurnitureManager.ObjectManager.ObjectArray.Objects[f.Index].Value : null;
|
||||||
if (gameObject == null)
|
if (gameObject == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue