mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-21 15:27:51 +01:00
Turn Settings and Priority into their own types.
This commit is contained in:
parent
77bf441e62
commit
b1ca073276
29 changed files with 422 additions and 298 deletions
|
|
@ -27,6 +27,7 @@ using Penumbra.UI;
|
|||
using TextureType = Penumbra.Api.Enums.TextureType;
|
||||
using Penumbra.Interop.ResourceTree;
|
||||
using Penumbra.Mods.Editor;
|
||||
using Penumbra.Mods.Subclasses;
|
||||
|
||||
namespace Penumbra.Api;
|
||||
|
||||
|
|
@ -39,13 +40,13 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
{
|
||||
add => _communicator.PreSettingsTabBarDraw.Subscribe(value!, Communication.PreSettingsTabBarDraw.Priority.Default);
|
||||
remove => _communicator.PreSettingsTabBarDraw.Unsubscribe(value!);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<string>? PreSettingsPanelDraw
|
||||
{
|
||||
add => _communicator.PreSettingsPanelDraw.Subscribe(value!, Communication.PreSettingsPanelDraw.Priority.Default);
|
||||
remove => _communicator.PreSettingsPanelDraw.Unsubscribe(value!);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<string>? PostEnabledDraw
|
||||
{
|
||||
|
|
@ -649,7 +650,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
|
||||
var shareSettings = settings.ConvertToShareable(mod);
|
||||
return (PenumbraApiEc.Success,
|
||||
(shareSettings.Enabled, shareSettings.Priority, shareSettings.Settings, collection.Settings[mod.Index] != null));
|
||||
(shareSettings.Enabled, shareSettings.Priority.Value, shareSettings.Settings, collection.Settings[mod.Index] != null));
|
||||
}
|
||||
|
||||
public PenumbraApiEc ReloadMod(string modDirectory, string modName)
|
||||
|
|
@ -791,7 +792,9 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
if (!_modManager.TryGetMod(modDirectory, modName, out var mod))
|
||||
return PenumbraApiEc.ModMissing;
|
||||
|
||||
return _collectionEditor.SetModPriority(collection, mod, priority) ? PenumbraApiEc.Success : PenumbraApiEc.NothingChanged;
|
||||
return _collectionEditor.SetModPriority(collection, mod, new ModPriority(priority))
|
||||
? PenumbraApiEc.Success
|
||||
: PenumbraApiEc.NothingChanged;
|
||||
}
|
||||
|
||||
public PenumbraApiEc TrySetModSetting(string collectionName, string modDirectory, string modName, string optionGroupName,
|
||||
|
|
@ -820,7 +823,12 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
Args("CollectionName", collectionName, "ModDirectory", modDirectory, "ModName", modName, "OptionGroupName", optionGroupName,
|
||||
"OptionName", optionName));
|
||||
|
||||
var setting = mod.Groups[groupIdx].Type == GroupType.Multi ? 1u << optionIdx : (uint)optionIdx;
|
||||
var setting = mod.Groups[groupIdx].Type switch
|
||||
{
|
||||
GroupType.Multi => Setting.Multi(optionIdx),
|
||||
GroupType.Single => Setting.Single(optionIdx),
|
||||
_ => Setting.Zero,
|
||||
};
|
||||
|
||||
return Return(
|
||||
_collectionEditor.SetModSetting(collection, mod, groupIdx, setting) ? PenumbraApiEc.Success : PenumbraApiEc.NothingChanged,
|
||||
|
|
@ -850,7 +858,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
|
||||
var group = mod.Groups[groupIdx];
|
||||
|
||||
uint setting = 0;
|
||||
var setting = Setting.Zero;
|
||||
if (group.Type == GroupType.Single)
|
||||
{
|
||||
var optionIdx = optionNames.Count == 0 ? -1 : group.IndexOf(o => o.Name == optionNames[^1]);
|
||||
|
|
@ -859,7 +867,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
Args("CollectionName", collectionName, "ModDirectory", modDirectory, "ModName", modName, "OptionGroupName", optionGroupName,
|
||||
"#optionNames", optionNames.Count.ToString()));
|
||||
|
||||
setting = (uint)optionIdx;
|
||||
setting = Setting.Single(optionIdx);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -871,7 +879,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
Args("CollectionName", collectionName, "ModDirectory", modDirectory, "ModName", modName, "OptionGroupName",
|
||||
optionGroupName, "#optionNames", optionNames.Count.ToString()));
|
||||
|
||||
setting |= 1u << optionIdx;
|
||||
setting |= Setting.Multi(optionIdx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -993,7 +1001,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
if (!ConvertManips(manipString, out var m))
|
||||
return PenumbraApiEc.InvalidManipulation;
|
||||
|
||||
return _tempMods.Register(tag, null, p, m, priority) switch
|
||||
return _tempMods.Register(tag, null, p, m, new ModPriority(priority)) switch
|
||||
{
|
||||
RedirectResult.Success => PenumbraApiEc.Success,
|
||||
_ => PenumbraApiEc.UnknownError,
|
||||
|
|
@ -1014,7 +1022,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
if (!ConvertManips(manipString, out var m))
|
||||
return PenumbraApiEc.InvalidManipulation;
|
||||
|
||||
return _tempMods.Register(tag, collection, p, m, priority) switch
|
||||
return _tempMods.Register(tag, collection, p, m, new ModPriority(priority)) switch
|
||||
{
|
||||
RedirectResult.Success => PenumbraApiEc.Success,
|
||||
_ => PenumbraApiEc.UnknownError,
|
||||
|
|
@ -1024,7 +1032,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
public PenumbraApiEc RemoveTemporaryModAll(string tag, int priority)
|
||||
{
|
||||
CheckInitialized();
|
||||
return _tempMods.Unregister(tag, null, priority) switch
|
||||
return _tempMods.Unregister(tag, null, new ModPriority(priority)) switch
|
||||
{
|
||||
RedirectResult.Success => PenumbraApiEc.Success,
|
||||
RedirectResult.NotRegistered => PenumbraApiEc.NothingChanged,
|
||||
|
|
@ -1039,7 +1047,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
&& !_collectionManager.Storage.ByName(collectionName, out collection))
|
||||
return PenumbraApiEc.CollectionMissing;
|
||||
|
||||
return _tempMods.Unregister(tag, collection, priority) switch
|
||||
return _tempMods.Unregister(tag, collection, new ModPriority(priority)) switch
|
||||
{
|
||||
RedirectResult.Success => PenumbraApiEc.Success,
|
||||
RedirectResult.NotRegistered => PenumbraApiEc.NothingChanged,
|
||||
|
|
@ -1089,7 +1097,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
|
||||
public IReadOnlyDictionary<string, string[]>?[] GetGameObjectResourcePaths(ushort[] gameObjects)
|
||||
{
|
||||
var characters = gameObjects.Select(index => _objects.GetDalamudObject((int) index)).OfType<Character>();
|
||||
var characters = gameObjects.Select(index => _objects.GetDalamudObject((int)index)).OfType<Character>();
|
||||
var resourceTrees = _resourceTreeFactory.FromCharacters(characters, 0);
|
||||
var pathDictionaries = ResourceTreeApiHelper.GetResourcePathDictionaries(resourceTrees);
|
||||
|
||||
|
|
@ -1153,7 +1161,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
var collection = _tempCollections.Collections.TryGetCollection(identifier, out var c)
|
||||
? c
|
||||
: _collectionManager.Active.Individual(identifier);
|
||||
var set = collection.MetaCache?.Manipulations.ToArray() ?? Array.Empty<MetaManipulation>();
|
||||
var set = collection.MetaCache?.Manipulations.ToArray() ?? [];
|
||||
return Functions.ToCompressedBase64(set, MetaManipulation.CurrentVersion);
|
||||
}
|
||||
|
||||
|
|
@ -1161,7 +1169,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
{
|
||||
CheckInitialized();
|
||||
AssociatedCollection(gameObjectIdx, out var collection);
|
||||
var set = collection.MetaCache?.Manipulations.ToArray() ?? Array.Empty<MetaManipulation>();
|
||||
var set = collection.MetaCache?.Manipulations.ToArray() ?? [];
|
||||
return Functions.ToCompressedBase64(set, MetaManipulation.CurrentVersion);
|
||||
}
|
||||
|
||||
|
|
@ -1190,7 +1198,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
private unsafe ActorIdentifier AssociatedIdentifier(int gameObjectIdx)
|
||||
private ActorIdentifier AssociatedIdentifier(int gameObjectIdx)
|
||||
{
|
||||
if (gameObjectIdx < 0 || gameObjectIdx >= _objects.TotalCount)
|
||||
return ActorIdentifier.Invalid;
|
||||
|
|
@ -1217,10 +1225,9 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
CheckInitialized();
|
||||
try
|
||||
{
|
||||
if (Path.IsPathRooted(resolvedPath))
|
||||
return _lumina?.GetFileFromDisk<T>(resolvedPath);
|
||||
|
||||
return _gameData.GetFile<T>(resolvedPath);
|
||||
return Path.IsPathRooted(resolvedPath)
|
||||
? _lumina?.GetFileFromDisk<T>(resolvedPath)
|
||||
: _gameData.GetFile<T>(resolvedPath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
@ -1295,7 +1302,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
return _actors.CreatePlayer(b, worldId);
|
||||
}
|
||||
|
||||
private void OnModSettingChange(ModCollection collection, ModSettingChange type, Mod? mod, int _1, int _2, bool inherited)
|
||||
private void OnModSettingChange(ModCollection collection, ModSettingChange type, Mod? mod, Setting _1, int _2, bool inherited)
|
||||
=> ModSettingChanged?.Invoke(type, collection.Name, mod?.ModPath.Name ?? string.Empty, inherited);
|
||||
|
||||
private void OnCreatedCharacterBase(nint gameObject, ModCollection collection, nint drawObject)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using Penumbra.Services;
|
|||
using Penumbra.String.Classes;
|
||||
using Penumbra.Collections.Manager;
|
||||
using Penumbra.Communication;
|
||||
using Penumbra.Mods.Subclasses;
|
||||
|
||||
namespace Penumbra.Api;
|
||||
|
||||
|
|
@ -21,8 +22,8 @@ public class TempModManager : IDisposable
|
|||
{
|
||||
private readonly CommunicatorService _communicator;
|
||||
|
||||
private readonly Dictionary<ModCollection, List<TemporaryMod>> _mods = new();
|
||||
private readonly List<TemporaryMod> _modsForAllCollections = new();
|
||||
private readonly Dictionary<ModCollection, List<TemporaryMod>> _mods = [];
|
||||
private readonly List<TemporaryMod> _modsForAllCollections = [];
|
||||
|
||||
public TempModManager(CommunicatorService communicator)
|
||||
{
|
||||
|
|
@ -42,7 +43,7 @@ public class TempModManager : IDisposable
|
|||
=> _modsForAllCollections;
|
||||
|
||||
public RedirectResult Register(string tag, ModCollection? collection, Dictionary<Utf8GamePath, FullPath> dict,
|
||||
HashSet<MetaManipulation> manips, int priority)
|
||||
HashSet<MetaManipulation> manips, ModPriority priority)
|
||||
{
|
||||
var mod = GetOrCreateMod(tag, collection, priority, out var created);
|
||||
Penumbra.Log.Verbose($"{(created ? "Created" : "Changed")} temporary Mod {mod.Name}.");
|
||||
|
|
@ -51,10 +52,10 @@ public class TempModManager : IDisposable
|
|||
return RedirectResult.Success;
|
||||
}
|
||||
|
||||
public RedirectResult Unregister(string tag, ModCollection? collection, int? priority)
|
||||
public RedirectResult Unregister(string tag, ModCollection? collection, ModPriority? priority)
|
||||
{
|
||||
Penumbra.Log.Verbose($"Removing temporary mod with tag {tag}...");
|
||||
var list = collection == null ? _modsForAllCollections : _mods.TryGetValue(collection, out var l) ? l : null;
|
||||
var list = collection == null ? _modsForAllCollections : _mods.GetValueOrDefault(collection);
|
||||
if (list == null)
|
||||
return RedirectResult.NotRegistered;
|
||||
|
||||
|
|
@ -85,13 +86,13 @@ public class TempModManager : IDisposable
|
|||
{
|
||||
Penumbra.Log.Verbose($"Removing temporary Mod {mod.Name} from {collection.AnonymizedName}.");
|
||||
collection.Remove(mod);
|
||||
_communicator.ModSettingChanged.Invoke(collection, ModSettingChange.TemporaryMod, null, 0, 0, false);
|
||||
_communicator.ModSettingChanged.Invoke(collection, ModSettingChange.TemporaryMod, null, Setting.False, 0, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Penumbra.Log.Verbose($"Adding {(created ? "new " : string.Empty)}temporary Mod {mod.Name} to {collection.AnonymizedName}.");
|
||||
collection.Apply(mod, created);
|
||||
_communicator.ModSettingChanged.Invoke(collection, ModSettingChange.TemporaryMod, null, 1, 0, false);
|
||||
_communicator.ModSettingChanged.Invoke(collection, ModSettingChange.TemporaryMod, null, Setting.True, 0, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -116,7 +117,7 @@ public class TempModManager : IDisposable
|
|||
|
||||
// Find or create a mod with the given tag as name and the given priority, for the given collection (or all collections).
|
||||
// Returns the found or created mod and whether it was newly created.
|
||||
private TemporaryMod GetOrCreateMod(string tag, ModCollection? collection, int priority, out bool created)
|
||||
private TemporaryMod GetOrCreateMod(string tag, ModCollection? collection, ModPriority priority, out bool created)
|
||||
{
|
||||
List<TemporaryMod> list;
|
||||
if (collection == null)
|
||||
|
|
@ -129,14 +130,14 @@ public class TempModManager : IDisposable
|
|||
}
|
||||
else
|
||||
{
|
||||
list = new List<TemporaryMod>();
|
||||
list = [];
|
||||
_mods.Add(collection, list);
|
||||
}
|
||||
|
||||
var mod = list.Find(m => m.Priority == priority && m.Name == tag);
|
||||
if (mod == null)
|
||||
{
|
||||
mod = new TemporaryMod()
|
||||
mod = new TemporaryMod
|
||||
{
|
||||
Name = tag,
|
||||
Priority = priority,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue