Add support for ActorIdentifier.FromUserString returning multiple identifiers.

This commit is contained in:
Ottermandias 2023-10-03 01:42:28 +02:00
parent 3d2ce1f4bb
commit e5427858e0
2 changed files with 64 additions and 52 deletions

View file

@ -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<ActorIdentifier>();
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,13 +312,16 @@ public class CommandHandler : IDisposable
}
}
var anySuccess = false;
foreach (var identifier in identifiers.Distinct())
{
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}." : ".")}");
return false;
continue;
}
var individualIndex = _collectionManager.Active.Individuals.Index(identifier);
@ -325,9 +334,9 @@ public class CommandHandler : IDisposable
}
else if (identifier.IsValid)
{
var identifiers = _collectionManager.Active.Individuals.GetGroup(identifier);
var identifierGroup = _collectionManager.Active.Individuals.GetGroup(identifier);
individualIndex = _collectionManager.Active.Individuals.Count;
_collectionManager.Active.CreateIndividualCollection(identifiers);
_collectionManager.Active.CreateIndividualCollection(identifierGroup);
}
}
else if (collection == null)
@ -344,17 +353,19 @@ public class CommandHandler : IDisposable
{
_chat.Print(
$"Can not remove the {type.ToName()} Collection assignment {(identifier.IsValid ? $" for {identifier}." : ".")}");
return false;
continue;
}
Print(
$"Removed {oldCollection.Name} as {type.ToName()} Collection assignment {(identifier.IsValid ? $" for {identifier}." : ".")}");
return true;
anySuccess = 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)

View file

@ -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;