From 6fa79c62c45d37ebcc41aac8c9d639296be7beaf Mon Sep 17 00:00:00 2001 From: Yuki Date: Sun, 20 Mar 2022 16:16:27 +1100 Subject: [PATCH] Add redraw route to http api --- Penumbra/Api/RedrawController.cs | 35 ++++++++++++++++++++++++++++++++ Penumbra/Penumbra.cs | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Penumbra/Api/RedrawController.cs diff --git a/Penumbra/Api/RedrawController.cs b/Penumbra/Api/RedrawController.cs new file mode 100644 index 00000000..4f55c69c --- /dev/null +++ b/Penumbra/Api/RedrawController.cs @@ -0,0 +1,35 @@ +using System.Threading.Tasks; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using Penumbra.GameData.Enums; + +namespace Penumbra.Api +{ + public class RedrawController : WebApiController + { + private readonly Penumbra _penumbra; + + public RedrawController( Penumbra penumbra ) + => _penumbra = penumbra; + + [Route( HttpVerbs.Post, "/redraw" )] + public async Task Redraw() + { + RedrawData data = await HttpContext.GetRequestDataAsync(); + _penumbra.Api.RedrawObject( data.Name, data.Type ); + } + + [Route( HttpVerbs.Post, "/redrawAll" )] + public void RedrawAll() + { + _penumbra.Api.RedrawAll(RedrawType.WithoutSettings); + } + + public class RedrawData + { + public string Name { get; set; } = string.Empty; + public RedrawType Type { get; set; } = RedrawType.WithSettings; + } + } +} \ No newline at end of file diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 6a7157b8..683ad296 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -166,7 +166,8 @@ public class Penumbra : IDalamudPlugin .WithMode( HttpListenerMode.EmbedIO ) ) .WithCors( prefix ) .WithWebApi( "/api", m => m - .WithController( () => new ModsController( this ) ) ); + .WithController( () => new ModsController( this ) ) + .WithController( () => new RedrawController( this ) ) ); _webServer.StateChanged += ( _, e ) => PluginLog.Information( $"WebServer New State - {e.NewState}" );