mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 10:17:23 +01:00
Add DeletePlayerState.
This commit is contained in:
parent
a0d912a395
commit
c604d5dbe5
5 changed files with 39 additions and 10 deletions
|
|
@ -1 +1 @@
|
||||||
Subproject commit 7e8505cd6f8dbc5bcf41b72e16785d62b4d218f3
|
Subproject commit 59a7ab5fa9941eb754757b62e4cb189e455e9514
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
using Glamourer.Api.Enums;
|
using Glamourer.Api.Enums;
|
||||||
using Glamourer.Designs;
|
using Glamourer.Designs;
|
||||||
using Glamourer.State;
|
using Glamourer.State;
|
||||||
using OtterGui;
|
|
||||||
using OtterGui.Extensions;
|
using OtterGui.Extensions;
|
||||||
using OtterGui.Log;
|
using OtterGui.Log;
|
||||||
using OtterGui.Services;
|
using OtterGui.Services;
|
||||||
using Penumbra.GameData.Actors;
|
using Penumbra.GameData.Actors;
|
||||||
using Penumbra.GameData.Enums;
|
using Penumbra.GameData.Enums;
|
||||||
using Penumbra.GameData.Interop;
|
using Penumbra.GameData.Interop;
|
||||||
|
using Penumbra.GameData.Structs;
|
||||||
using Penumbra.String;
|
using Penumbra.String;
|
||||||
|
|
||||||
namespace Glamourer.Api;
|
namespace Glamourer.Api;
|
||||||
|
|
@ -15,15 +15,24 @@ namespace Glamourer.Api;
|
||||||
public class ApiHelpers(ActorObjectManager objects, StateManager stateManager, ActorManager actors) : IApiService
|
public class ApiHelpers(ActorObjectManager objects, StateManager stateManager, ActorManager actors) : IApiService
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
internal IEnumerable<ActorState> FindExistingStates(string actorName)
|
internal IEnumerable<ActorState> FindExistingStates(string actorName, ushort worldId = ushort.MaxValue)
|
||||||
{
|
{
|
||||||
if (actorName.Length == 0 || !ByteString.FromString(actorName, out var byteString))
|
if (actorName.Length == 0 || !ByteString.FromString(actorName, out var byteString))
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
|
if (worldId == WorldId.AnyWorld.Id)
|
||||||
|
{
|
||||||
foreach (var state in stateManager.Values.Where(state
|
foreach (var state in stateManager.Values.Where(state
|
||||||
=> state.Identifier.Type is IdentifierType.Player && state.Identifier.PlayerName == byteString))
|
=> state.Identifier.Type is IdentifierType.Player && state.Identifier.PlayerName == byteString))
|
||||||
yield return state;
|
yield return state;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var identifier = actors.CreatePlayer(byteString, worldId);
|
||||||
|
if (stateManager.TryGetValue(identifier, out var state))
|
||||||
|
yield return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
internal GlamourerApiEc FindExistingState(int objectIndex, out ActorState? state)
|
internal GlamourerApiEc FindExistingState(int objectIndex, out ActorState? state)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ namespace Glamourer.Api;
|
||||||
public class GlamourerApi(DesignsApi designs, StateApi state, ItemsApi items) : IGlamourerApi, IApiService
|
public class GlamourerApi(DesignsApi designs, StateApi state, ItemsApi items) : IGlamourerApi, IApiService
|
||||||
{
|
{
|
||||||
public const int CurrentApiVersionMajor = 1;
|
public const int CurrentApiVersionMajor = 1;
|
||||||
public const int CurrentApiVersionMinor = 6;
|
public const int CurrentApiVersionMinor = 7;
|
||||||
|
|
||||||
public (int Major, int Minor) ApiVersion
|
public (int Major, int Minor) ApiVersion
|
||||||
=> (CurrentApiVersionMajor, CurrentApiVersionMinor);
|
=> (CurrentApiVersionMajor, CurrentApiVersionMinor);
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ public sealed class IpcProviders : IDisposable, IApiService
|
||||||
IpcSubscribers.RevertStateName.Provider(pi, api.State),
|
IpcSubscribers.RevertStateName.Provider(pi, api.State),
|
||||||
IpcSubscribers.UnlockState.Provider(pi, api.State),
|
IpcSubscribers.UnlockState.Provider(pi, api.State),
|
||||||
IpcSubscribers.UnlockStateName.Provider(pi, api.State),
|
IpcSubscribers.UnlockStateName.Provider(pi, api.State),
|
||||||
|
IpcSubscribers.DeletePlayerState.Provider(pi, api.State),
|
||||||
IpcSubscribers.UnlockAll.Provider(pi, api.State),
|
IpcSubscribers.UnlockAll.Provider(pi, api.State),
|
||||||
IpcSubscribers.RevertToAutomation.Provider(pi, api.State),
|
IpcSubscribers.RevertToAutomation.Provider(pi, api.State),
|
||||||
IpcSubscribers.RevertToAutomationName.Provider(pi, api.State),
|
IpcSubscribers.RevertToAutomationName.Provider(pi, api.State),
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using Glamourer.State;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using OtterGui.Services;
|
using OtterGui.Services;
|
||||||
using Penumbra.GameData.Interop;
|
using Penumbra.GameData.Interop;
|
||||||
|
using Penumbra.GameData.Structs;
|
||||||
using StateChanged = Glamourer.Events.StateChanged;
|
using StateChanged = Glamourer.Events.StateChanged;
|
||||||
|
|
||||||
namespace Glamourer.Api;
|
namespace Glamourer.Api;
|
||||||
|
|
@ -17,7 +18,6 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
|
||||||
private readonly ApiHelpers _helpers;
|
private readonly ApiHelpers _helpers;
|
||||||
private readonly StateManager _stateManager;
|
private readonly StateManager _stateManager;
|
||||||
private readonly DesignConverter _converter;
|
private readonly DesignConverter _converter;
|
||||||
private readonly Configuration _config;
|
|
||||||
private readonly AutoDesignApplier _autoDesigns;
|
private readonly AutoDesignApplier _autoDesigns;
|
||||||
private readonly ActorObjectManager _objects;
|
private readonly ActorObjectManager _objects;
|
||||||
private readonly StateChanged _stateChanged;
|
private readonly StateChanged _stateChanged;
|
||||||
|
|
@ -27,7 +27,6 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
|
||||||
public StateApi(ApiHelpers helpers,
|
public StateApi(ApiHelpers helpers,
|
||||||
StateManager stateManager,
|
StateManager stateManager,
|
||||||
DesignConverter converter,
|
DesignConverter converter,
|
||||||
Configuration config,
|
|
||||||
AutoDesignApplier autoDesigns,
|
AutoDesignApplier autoDesigns,
|
||||||
ActorObjectManager objects,
|
ActorObjectManager objects,
|
||||||
StateChanged stateChanged,
|
StateChanged stateChanged,
|
||||||
|
|
@ -37,7 +36,6 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
|
||||||
_helpers = helpers;
|
_helpers = helpers;
|
||||||
_stateManager = stateManager;
|
_stateManager = stateManager;
|
||||||
_converter = converter;
|
_converter = converter;
|
||||||
_config = config;
|
|
||||||
_autoDesigns = autoDesigns;
|
_autoDesigns = autoDesigns;
|
||||||
_objects = objects;
|
_objects = objects;
|
||||||
_stateChanged = stateChanged;
|
_stateChanged = stateChanged;
|
||||||
|
|
@ -202,6 +200,27 @@ public sealed class StateApi : IGlamourerApiState, IApiService, IDisposable
|
||||||
return ApiHelpers.Return(GlamourerApiEc.Success, args);
|
return ApiHelpers.Return(GlamourerApiEc.Success, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GlamourerApiEc DeletePlayerState(string playerName, ushort worldId, uint key)
|
||||||
|
{
|
||||||
|
var args = ApiHelpers.Args("Name", playerName, "World", worldId, "Key", key);
|
||||||
|
var states = _helpers.FindExistingStates(playerName).ToList();
|
||||||
|
if (states.Count is 0)
|
||||||
|
return ApiHelpers.Return(GlamourerApiEc.NothingDone, args);
|
||||||
|
|
||||||
|
var anyLocked = false;
|
||||||
|
foreach (var state in states)
|
||||||
|
{
|
||||||
|
if (state.CanUnlock(key))
|
||||||
|
_stateManager.DeleteState(state.Identifier);
|
||||||
|
else
|
||||||
|
anyLocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ApiHelpers.Return(anyLocked
|
||||||
|
? GlamourerApiEc.InvalidKey
|
||||||
|
: GlamourerApiEc.Success, args);
|
||||||
|
}
|
||||||
|
|
||||||
public int UnlockAll(uint key)
|
public int UnlockAll(uint key)
|
||||||
=> _stateManager.Values.Count(state => state.Unlock(key));
|
=> _stateManager.Values.Count(state => state.Unlock(key));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue