From e5427858e0e91d7e590b74fa2843d474ab477df4 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Tue, 3 Oct 2023 01:42:28 +0200 Subject: [PATCH] Add support for ActorIdentifier.FromUserString returning multiple identifiers. --- Penumbra/CommandHandler.cs | 113 +++++++++++--------- Penumbra/Interop/PathResolving/MetaState.cs | 3 +- 2 files changed, 64 insertions(+), 52 deletions(-) diff --git a/Penumbra/CommandHandler.cs b/Penumbra/CommandHandler.cs index 3249cc43..71bd19c2 100644 --- a/Penumbra/CommandHandler.cs +++ b/Penumbra/CommandHandler.cs @@ -21,7 +21,7 @@ public class CommandHandler : IDisposable private readonly ICommandManager _commandManager; private readonly RedrawService _redrawService; - private readonly IChatGui _chat; + private readonly IChatGui _chat; private readonly Configuration _config; private readonly ConfigWindow _configWindow; private readonly ActorManager _actors; @@ -30,7 +30,8 @@ public class CommandHandler : IDisposable private readonly Penumbra _penumbra; private readonly CollectionEditor _collectionEditor; - public CommandHandler(IFramework framework, ICommandManager commandManager, IChatGui chat, RedrawService redrawService, Configuration config, + public CommandHandler(IFramework framework, ICommandManager commandManager, IChatGui chat, RedrawService redrawService, + Configuration config, ConfigWindow configWindow, ModManager modManager, CollectionManager collectionManager, ActorService actors, Penumbra penumbra, CollectionEditor collectionEditor) { @@ -270,7 +271,7 @@ public class CommandHandler : IDisposable if (!GetModCollection(split[1], out var collection)) return false; - var identifier = ActorIdentifier.Invalid; + var identifiers = Array.Empty(); if (type is CollectionType.Individual) { if (split.Length == 2) @@ -284,17 +285,22 @@ public class CommandHandler : IDisposable { if (_redrawService.GetName(split[2].ToLowerInvariant(), out var obj)) { - identifier = _actors.FromObject(obj, false, true, true); + var identifier = _actors.FromObject(obj, false, true, true); if (!identifier.IsValid) { _chat.Print(new SeStringBuilder().AddText("The placeholder ").AddGreen(split[2]) .AddText(" did not resolve to a game object with a valid identifier.").BuiltString); return false; } + + identifiers = new[] + { + identifier, + }; } else { - identifier = _actors.FromUserString(split[2]); + identifiers = _actors.FromUserString(split[2], false); } } catch (ActorManager.IdentifierParseError e) @@ -306,55 +312,60 @@ public class CommandHandler : IDisposable } } - var oldCollection = _collectionManager.Active.ByType(type, identifier); - if (collection == oldCollection) + var anySuccess = false; + foreach (var identifier in identifiers.Distinct()) { - _chat.Print(collection == null - ? $"The {type.ToName()} Collection{(identifier.IsValid ? $" for {identifier}" : string.Empty)} is already unassigned" - : $"{collection.Name} already is the {type.ToName()} Collection{(identifier.IsValid ? $" for {identifier}." : ".")}"); - return false; + var oldCollection = _collectionManager.Active.ByType(type, identifier); + if (collection == oldCollection) + { + _chat.Print(collection == null + ? $"The {type.ToName()} Collection{(identifier.IsValid ? $" for {identifier}" : string.Empty)} is already unassigned" + : $"{collection.Name} already is the {type.ToName()} Collection{(identifier.IsValid ? $" for {identifier}." : ".")}"); + continue; + } + + var individualIndex = _collectionManager.Active.Individuals.Index(identifier); + + if (oldCollection == null) + { + if (type.IsSpecial()) + { + _collectionManager.Active.CreateSpecialCollection(type); + } + else if (identifier.IsValid) + { + var identifierGroup = _collectionManager.Active.Individuals.GetGroup(identifier); + individualIndex = _collectionManager.Active.Individuals.Count; + _collectionManager.Active.CreateIndividualCollection(identifierGroup); + } + } + else if (collection == null) + { + if (type.IsSpecial()) + { + _collectionManager.Active.RemoveSpecialCollection(type); + } + else if (individualIndex >= 0) + { + _collectionManager.Active.RemoveIndividualCollection(individualIndex); + } + else + { + _chat.Print( + $"Can not remove the {type.ToName()} Collection assignment {(identifier.IsValid ? $" for {identifier}." : ".")}"); + continue; + } + + Print( + $"Removed {oldCollection.Name} as {type.ToName()} Collection assignment {(identifier.IsValid ? $" for {identifier}." : ".")}"); + anySuccess = true; + } + + _collectionManager.Active.SetCollection(collection!, type, individualIndex); + Print($"Assigned {collection!.Name} as {type.ToName()} Collection{(identifier.IsValid ? $" for {identifier}." : ".")}"); } - var individualIndex = _collectionManager.Active.Individuals.Index(identifier); - - if (oldCollection == null) - { - if (type.IsSpecial()) - { - _collectionManager.Active.CreateSpecialCollection(type); - } - else if (identifier.IsValid) - { - var identifiers = _collectionManager.Active.Individuals.GetGroup(identifier); - individualIndex = _collectionManager.Active.Individuals.Count; - _collectionManager.Active.CreateIndividualCollection(identifiers); - } - } - else if (collection == null) - { - if (type.IsSpecial()) - { - _collectionManager.Active.RemoveSpecialCollection(type); - } - else if (individualIndex >= 0) - { - _collectionManager.Active.RemoveIndividualCollection(individualIndex); - } - else - { - _chat.Print( - $"Can not remove the {type.ToName()} Collection assignment {(identifier.IsValid ? $" for {identifier}." : ".")}"); - return false; - } - - Print( - $"Removed {oldCollection.Name} as {type.ToName()} Collection assignment {(identifier.IsValid ? $" for {identifier}." : ".")}"); - return true; - } - - _collectionManager.Active.SetCollection(collection!, type, individualIndex); - Print($"Assigned {collection!.Name} as {type.ToName()} Collection{(identifier.IsValid ? $" for {identifier}." : ".")}"); - return true; + return anySuccess; } private bool SetMod(string arguments) diff --git a/Penumbra/Interop/PathResolving/MetaState.cs b/Penumbra/Interop/PathResolving/MetaState.cs index c41d651e..0048dc8c 100644 --- a/Penumbra/Interop/PathResolving/MetaState.cs +++ b/Penumbra/Interop/PathResolving/MetaState.cs @@ -60,7 +60,8 @@ public unsafe class MetaState : IDisposable private DisposableContainer _characterBaseCreateMetaChanges = DisposableContainer.Empty; public MetaState(PerformanceTracker performance, CommunicatorService communicator, CollectionResolver collectionResolver, - ResourceLoader resources, GameEventManager gameEventManager, CharacterUtility characterUtility, Configuration config, IGameInteropProvider interop) + ResourceLoader resources, GameEventManager gameEventManager, CharacterUtility characterUtility, Configuration config, + IGameInteropProvider interop) { _performance = performance; _communicator = communicator;