mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +01:00
Added AddDesign to Design API
This commit is contained in:
parent
4e0a9f62b9
commit
302426ddd1
1 changed files with 28 additions and 1 deletions
|
|
@ -2,11 +2,12 @@
|
||||||
using Glamourer.Api.Enums;
|
using Glamourer.Api.Enums;
|
||||||
using Glamourer.Designs;
|
using Glamourer.Designs;
|
||||||
using Glamourer.State;
|
using Glamourer.State;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using OtterGui.Services;
|
using OtterGui.Services;
|
||||||
|
|
||||||
namespace Glamourer.Api;
|
namespace Glamourer.Api;
|
||||||
|
|
||||||
public class DesignsApi(ApiHelpers helpers, DesignManager designs, StateManager stateManager, DesignFileSystem fileSystem, DesignColors color)
|
public class DesignsApi(ApiHelpers helpers, DesignManager designs, StateManager stateManager, DesignFileSystem fileSystem, DesignColors color, DesignConverter converter)
|
||||||
: IGlamourerApiDesigns, IApiService
|
: IGlamourerApiDesigns, IApiService
|
||||||
{
|
{
|
||||||
public Dictionary<Guid, string> GetDesignList()
|
public Dictionary<Guid, string> GetDesignList()
|
||||||
|
|
@ -71,4 +72,30 @@ public class DesignsApi(ApiHelpers helpers, DesignManager designs, StateManager
|
||||||
|
|
||||||
return ApiHelpers.Return(GlamourerApiEc.Success, args);
|
return ApiHelpers.Return(GlamourerApiEc.Success, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public (GlamourerApiEc, Guid?) AddDesign(string designInput, string name)
|
||||||
|
{
|
||||||
|
var args = ApiHelpers.Args("Design Input", designInput);
|
||||||
|
|
||||||
|
DesignBase? designBase = converter.FromBase64(designInput, true, true, out _);
|
||||||
|
if (designBase == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var jObj = JObject.Parse(designInput);
|
||||||
|
designBase = converter.FromJObject(jObj, true, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return (ApiHelpers.Return(GlamourerApiEc.CouldNotParse, args), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (designBase == null)
|
||||||
|
return (ApiHelpers.Return(GlamourerApiEc.CouldNotParse, args), null);
|
||||||
|
|
||||||
|
Design design = designs.CreateClone(designBase, name, true);
|
||||||
|
|
||||||
|
return (ApiHelpers.Return(GlamourerApiEc.Success, args), design.Identifier);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue