Add documentation to API.

This commit is contained in:
Ottermandias 2024-04-15 16:54:02 +02:00
parent ee78a2a983
commit fb64315d51
4 changed files with 33 additions and 21 deletions

@ -1 +1 @@
Subproject commit f58482079a2ebe6b2958ff2432b245bcf180d3c2 Subproject commit 1529863ecb33d85ea88dc2cf3c749a245b11cf55

View file

@ -39,16 +39,16 @@ public class DesignsApi(ApiHelpers helpers, DesignManager designs, StateManager
stateManager.ApplyDesign(state, design, settings); stateManager.ApplyDesign(state, design, settings);
} }
public GlamourerApiEc ApplyDesignName(Guid designId, string objectName, uint key, ApplyFlag flags) public GlamourerApiEc ApplyDesignName(Guid designId, string playerName, uint key, ApplyFlag flags)
{ {
var args = ApiHelpers.Args("Design", designId, "Name", objectName, "Key", key, "Flags", flags); var args = ApiHelpers.Args("Design", designId, "Name", playerName, "Key", key, "Flags", flags);
var design = designs.Designs.ByIdentifier(designId); var design = designs.Designs.ByIdentifier(designId);
if (design == null) if (design == null)
return ApiHelpers.Return(GlamourerApiEc.DesignNotFound, args); return ApiHelpers.Return(GlamourerApiEc.DesignNotFound, args);
var any = false; var any = false;
var anyUnlocked = false; var anyUnlocked = false;
foreach (var state in helpers.FindStates(objectName)) foreach (var state in helpers.FindStates(playerName))
{ {
any = true; any = true;
if (!state.CanUnlock(key)) if (!state.CanUnlock(key))

View file

@ -32,9 +32,9 @@ public class ItemsApi(ApiHelpers helpers, ItemManager itemManager, StateManager
return GlamourerApiEc.Success; return GlamourerApiEc.Success;
} }
public GlamourerApiEc SetItemName(string objectName, ApiEquipSlot slot, ulong itemId, byte stain, uint key, ApplyFlag flags) public GlamourerApiEc SetItemName(string playerName, ApiEquipSlot slot, ulong itemId, byte stain, uint key, ApplyFlag flags)
{ {
var args = ApiHelpers.Args("Name", objectName, "Slot", slot, "ID", itemId, "Stain", stain, "Key", key, "Flags", flags); var args = ApiHelpers.Args("Name", playerName, "Slot", slot, "ID", itemId, "Stain", stain, "Key", key, "Flags", flags);
if (!ResolveItem(slot, itemId, out var item)) if (!ResolveItem(slot, itemId, out var item))
return ApiHelpers.Return(GlamourerApiEc.ItemInvalid, args); return ApiHelpers.Return(GlamourerApiEc.ItemInvalid, args);
@ -42,7 +42,7 @@ public class ItemsApi(ApiHelpers helpers, ItemManager itemManager, StateManager
var anyHuman = false; var anyHuman = false;
var anyFound = false; var anyFound = false;
var anyUnlocked = false; var anyUnlocked = false;
foreach (var state in helpers.FindStates(objectName)) foreach (var state in helpers.FindStates(playerName))
{ {
anyFound = true; anyFound = true;
if (!state.ModelData.IsHuman) if (!state.ModelData.IsHuman)

View file

@ -54,8 +54,14 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
public (GlamourerApiEc, JObject?) GetState(int objectIndex, uint key) public (GlamourerApiEc, JObject?) GetState(int objectIndex, uint key)
=> Convert(_helpers.FindState(objectIndex), key); => Convert(_helpers.FindState(objectIndex), key);
public (GlamourerApiEc, JObject?) GetStateName(string objectName, uint key) public (GlamourerApiEc, JObject?) GetStateName(string playerName, uint key)
=> Convert(_helpers.FindStates(objectName).FirstOrDefault(), key); => Convert(_helpers.FindStates(playerName).FirstOrDefault(), key);
public (GlamourerApiEc, string?) GetStateBase64(int objectIndex, uint key)
=> ConvertBase64(_helpers.FindState(objectIndex), key);
public (GlamourerApiEc, string?) GetStateBase64Name(string objectName, uint key)
=> ConvertBase64(_helpers.FindStates(objectName).FirstOrDefault(), key);
public GlamourerApiEc ApplyState(object applyState, int objectIndex, uint key, ApplyFlag flags) public GlamourerApiEc ApplyState(object applyState, int objectIndex, uint key, ApplyFlag flags)
{ {
@ -76,13 +82,13 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
return ApiHelpers.Return(GlamourerApiEc.Success, args); return ApiHelpers.Return(GlamourerApiEc.Success, args);
} }
public GlamourerApiEc ApplyStateName(object applyState, string objectName, uint key, ApplyFlag flags) public GlamourerApiEc ApplyStateName(object applyState, string playerName, uint key, ApplyFlag flags)
{ {
var args = ApiHelpers.Args("Name", objectName, "Key", key, "Flags", flags); var args = ApiHelpers.Args("Name", playerName, "Key", key, "Flags", flags);
if (Convert(applyState, flags, out var version) is not { } design) if (Convert(applyState, flags, out var version) is not { } design)
return ApiHelpers.Return(GlamourerApiEc.InvalidState, args); return ApiHelpers.Return(GlamourerApiEc.InvalidState, args);
var states = _helpers.FindExistingStates(objectName); var states = _helpers.FindExistingStates(playerName);
var any = false; var any = false;
var anyUnlocked = false; var anyUnlocked = false;
@ -129,10 +135,10 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
return ApiHelpers.Return(GlamourerApiEc.Success, args); return ApiHelpers.Return(GlamourerApiEc.Success, args);
} }
public GlamourerApiEc RevertStateName(string objectName, uint key, ApplyFlag flags) public GlamourerApiEc RevertStateName(string playerName, uint key, ApplyFlag flags)
{ {
var args = ApiHelpers.Args("Name", objectName, "Key", key, "Flags", flags); var args = ApiHelpers.Args("Name", playerName, "Key", key, "Flags", flags);
var states = _helpers.FindExistingStates(objectName); var states = _helpers.FindExistingStates(playerName);
var any = false; var any = false;
var anyUnlocked = false; var anyUnlocked = false;
@ -170,10 +176,10 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
return ApiHelpers.Return(GlamourerApiEc.Success, args); return ApiHelpers.Return(GlamourerApiEc.Success, args);
} }
public GlamourerApiEc UnlockStateName(string objectName, uint key) public GlamourerApiEc UnlockStateName(string playerName, uint key)
{ {
var args = ApiHelpers.Args("Name", objectName, "Key", key); var args = ApiHelpers.Args("Name", playerName, "Key", key);
var states = _helpers.FindExistingStates(objectName); var states = _helpers.FindExistingStates(playerName);
var any = false; var any = false;
var anyUnlocked = false; var anyUnlocked = false;
@ -211,10 +217,10 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
return ApiHelpers.Return(GlamourerApiEc.Success, args); return ApiHelpers.Return(GlamourerApiEc.Success, args);
} }
public GlamourerApiEc RevertToAutomationName(string objectName, uint key, ApplyFlag flags) public GlamourerApiEc RevertToAutomationName(string playerName, uint key, ApplyFlag flags)
{ {
var args = ApiHelpers.Args("Name", objectName, "Key", key, "Flags", flags); var args = ApiHelpers.Args("Name", playerName, "Key", key, "Flags", flags);
var states = _helpers.FindExistingStates(objectName); var states = _helpers.FindExistingStates(playerName);
var any = false; var any = false;
var anyUnlocked = false; var anyUnlocked = false;
@ -303,6 +309,12 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
return (GlamourerApiEc.Success, _converter.ShareJObject(state, ApplicationRules.AllWithConfig(_config))); return (GlamourerApiEc.Success, _converter.ShareJObject(state, ApplicationRules.AllWithConfig(_config)));
} }
private (GlamourerApiEc, string?) ConvertBase64(ActorState? state, uint key)
{
var (ec, jObj) = Convert(state, key);
return (ec, jObj != null ? DesignConverter.ToBase64(jObj) : null);
}
private DesignBase? Convert(object? state, ApplyFlag flags, out byte version) private DesignBase? Convert(object? state, ApplyFlag flags, out byte version)
{ {
version = DesignConverter.Version; version = DesignConverter.Version;