Skip to content

Commit

Permalink
Make everything services.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Jun 18, 2024
1 parent cf1dcfc commit e05dbe9
Show file tree
Hide file tree
Showing 81 changed files with 220 additions and 317 deletions.
3 changes: 2 additions & 1 deletion Penumbra/Api/TempModManager.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using OtterGui.Services;
using Penumbra.Api.Enums;
using Penumbra.Collections;
using Penumbra.Meta.Manipulations;
Expand All @@ -18,7 +19,7 @@ public enum RedirectResult
FilteredGamePath = 3,
}

public class TempModManager : IDisposable
public class TempModManager : IDisposable, IService
{
private readonly CommunicatorService _communicator;

Expand Down
3 changes: 2 additions & 1 deletion Penumbra/Collections/Cache/CollectionCacheManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dalamud.Plugin.Services;
using OtterGui.Classes;
using OtterGui.Services;
using Penumbra.Api;
using Penumbra.Api.Enums;
using Penumbra.Collections.Manager;
Expand All @@ -17,7 +18,7 @@

namespace Penumbra.Collections.Cache;

public class CollectionCacheManager : IDisposable
public class CollectionCacheManager : IDisposable, IService
{
private readonly FrameworkManager _framework;
private readonly CommunicatorService _communicator;
Expand Down
5 changes: 3 additions & 2 deletions Penumbra/Collections/Manager/ActiveCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Newtonsoft.Json.Linq;
using OtterGui;
using OtterGui.Classes;
using OtterGui.Services;
using Penumbra.Communication;
using Penumbra.GameData.Actors;
using Penumbra.GameData.Enums;
Expand All @@ -11,7 +12,7 @@

namespace Penumbra.Collections.Manager;

public class ActiveCollectionData
public class ActiveCollectionData : IService
{
public ModCollection Current { get; internal set; } = ModCollection.Empty;
public ModCollection Default { get; internal set; } = ModCollection.Empty;
Expand All @@ -20,7 +21,7 @@ public class ActiveCollectionData
public readonly ModCollection?[] SpecialCollections = new ModCollection?[Enum.GetValues<Api.Enums.ApiCollectionType>().Length - 3];
}

public class ActiveCollections : ISavable, IDisposable
public class ActiveCollections : ISavable, IDisposable, IService
{
public const int Version = 2;

Expand Down
3 changes: 2 additions & 1 deletion Penumbra/Collections/Manager/CollectionEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OtterGui;
using OtterGui.Services;
using Penumbra.Api.Enums;
using Penumbra.Mods;
using Penumbra.Mods.Manager;
Expand All @@ -7,7 +8,7 @@

namespace Penumbra.Collections.Manager;

public class CollectionEditor(SaveService saveService, CommunicatorService communicator, ModStorage modStorage)
public class CollectionEditor(SaveService saveService, CommunicatorService communicator, ModStorage modStorage) : IService
{
/// <summary> Enable or disable the mod inheritance of mod idx. </summary>
public bool SetModInheritance(ModCollection collection, Mod mod, bool inherit)
Expand Down
3 changes: 2 additions & 1 deletion Penumbra/Collections/Manager/CollectionManager.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using OtterGui.Services;
using Penumbra.Collections.Cache;

namespace Penumbra.Collections.Manager;
Expand All @@ -8,7 +9,7 @@ public class CollectionManager(
InheritanceManager inheritances,
CollectionCacheManager caches,
TempCollectionManager temp,
CollectionEditor editor)
CollectionEditor editor) : IService
{
public readonly CollectionStorage Storage = storage;
public readonly ActiveCollections Active = active;
Expand Down
5 changes: 2 additions & 3 deletions Penumbra/Collections/Manager/CollectionStorage.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Dalamud.Interface.Internal.Notifications;
using OtterGui;
using OtterGui.Classes;
using OtterGui.Services;
using Penumbra.Communication;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
Expand All @@ -11,7 +11,6 @@
using Penumbra.Mods.Settings;
using Penumbra.Mods.SubMods;
using Penumbra.Services;
using Penumbra.UI.CollectionTab;

namespace Penumbra.Collections.Manager;

Expand All @@ -24,7 +23,7 @@ public readonly record struct LocalCollectionId(int Id) : IAdditionOperators<Loc
=> new(left.Id + right);
}

public class CollectionStorage : IReadOnlyList<ModCollection>, IDisposable
public class CollectionStorage : IReadOnlyList<ModCollection>, IDisposable, IService
{
private readonly CommunicatorService _communicator;
private readonly SaveService _saveService;
Expand Down
14 changes: 8 additions & 6 deletions Penumbra/Collections/Manager/InheritanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
using OtterGui;
using OtterGui.Classes;
using OtterGui.Filesystem;
using OtterGui.Services;
using Penumbra.Communication;
using Penumbra.Mods.Manager;
using Penumbra.Services;
using Penumbra.UI.CollectionTab;
using Penumbra.Util;

namespace Penumbra.Collections.Manager;

Expand All @@ -15,7 +14,7 @@ namespace Penumbra.Collections.Manager;
/// This is transitive, so a collection A inheriting from B also inherits from everything B inherits.
/// Circular dependencies are resolved by distinctness.
/// </summary>
public class InheritanceManager : IDisposable
public class InheritanceManager : IDisposable, IService
{
public enum ValidInheritance
{
Expand Down Expand Up @@ -144,7 +143,8 @@ private void ApplyInheritances()
continue;

changes = true;
Penumbra.Messager.NotificationMessage($"{collection.Name} can not inherit from {subCollection.Name}, removed.", NotificationType.Warning);
Penumbra.Messager.NotificationMessage($"{collection.Name} can not inherit from {subCollection.Name}, removed.",
NotificationType.Warning);
}
else if (_storage.ByName(subCollectionName, out subCollection))
{
Expand All @@ -153,12 +153,14 @@ private void ApplyInheritances()
if (AddInheritance(collection, subCollection, false))
continue;

Penumbra.Messager.NotificationMessage($"{collection.Name} can not inherit from {subCollection.Name}, removed.", NotificationType.Warning);
Penumbra.Messager.NotificationMessage($"{collection.Name} can not inherit from {subCollection.Name}, removed.",
NotificationType.Warning);
}
else
{
Penumbra.Messager.NotificationMessage(
$"Inherited collection {subCollectionName} for {collection.AnonymizedName} does not exist, it was removed.", NotificationType.Warning);
$"Inherited collection {subCollectionName} for {collection.AnonymizedName} does not exist, it was removed.",
NotificationType.Warning);
changes = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion Penumbra/Collections/Manager/TempCollectionManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OtterGui;
using OtterGui.Services;
using Penumbra.Api;
using Penumbra.Communication;
using Penumbra.GameData.Actors;
Expand All @@ -8,7 +9,7 @@

namespace Penumbra.Collections.Manager;

public class TempCollectionManager : IDisposable
public class TempCollectionManager : IDisposable, IService
{
public int GlobalChangeCounter { get; private set; }
public readonly IndividualCollections Collections;
Expand Down
4 changes: 2 additions & 2 deletions Penumbra/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
using Dalamud.Plugin.Services;
using ImGuiNET;
using OtterGui.Classes;
using OtterGui.Services;
using Penumbra.Api.Enums;
using Penumbra.Collections;
using Penumbra.Collections.Manager;
using Penumbra.GameData.Actors;
using Penumbra.Interop.Services;
using Penumbra.Mods;
using Penumbra.Mods.Manager;
using Penumbra.Services;
using Penumbra.UI;

namespace Penumbra;

public class CommandHandler : IDisposable
public class CommandHandler : IDisposable, IApiService
{
private const string CommandName = "/penumbra";

Expand Down
3 changes: 2 additions & 1 deletion Penumbra/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OtterGui;
using OtterGui.Classes;
using OtterGui.Filesystem;
using OtterGui.Services;
using OtterGui.Widgets;
using Penumbra.Import.Structs;
using Penumbra.Interop.Services;
Expand All @@ -18,7 +19,7 @@
namespace Penumbra;

[Serializable]
public class Configuration : IPluginConfiguration, ISavable
public class Configuration : IPluginConfiguration, ISavable, IService
{
[JsonIgnore]
private readonly SaveService _saveService;
Expand Down
3 changes: 2 additions & 1 deletion Penumbra/EphemeralConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Interface.Internal.Notifications;
using Newtonsoft.Json;
using OtterGui.Classes;
using OtterGui.Services;
using Penumbra.Api.Enums;
using Penumbra.Communication;
using Penumbra.Enums;
Expand All @@ -14,7 +15,7 @@

namespace Penumbra;

public class EphemeralConfig : ISavable, IDisposable
public class EphemeralConfig : ISavable, IDisposable, IService
{
[JsonIgnore]
private readonly SaveService _saveService;
Expand Down
4 changes: 3 additions & 1 deletion Penumbra/Import/Models/ModelManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Plugin.Services;
using Lumina.Data.Parsing;
using OtterGui;
using OtterGui.Services;
using OtterGui.Tasks;
using Penumbra.Collections.Manager;
using Penumbra.GameData;
Expand All @@ -21,7 +22,8 @@ namespace Penumbra.Import.Models;
using Schema2 = SharpGLTF.Schema2;
using LuminaMaterial = Lumina.Models.Materials.Material;

public sealed class ModelManager(IFramework framework, ActiveCollections collections, GamePathParser parser) : SingleTaskQueue, IDisposable
public sealed class ModelManager(IFramework framework, ActiveCollections collections, GamePathParser parser)
: SingleTaskQueue, IDisposable, IService
{
private readonly IFramework _framework = framework;

Expand Down
26 changes: 10 additions & 16 deletions Penumbra/Import/Textures/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Dalamud.Plugin.Services;
using Lumina.Data.Files;
using OtterGui.Log;
using OtterGui.Services;
using OtterGui.Tasks;
using OtterTex;
using SixLabors.ImageSharp;
Expand All @@ -12,22 +13,14 @@

namespace Penumbra.Import.Textures;

public sealed class TextureManager : SingleTaskQueue, IDisposable
public sealed class TextureManager(UiBuilder uiBuilder, IDataManager gameData, Logger logger)
: SingleTaskQueue, IDisposable, IService
{
private readonly Logger _logger;
private readonly UiBuilder _uiBuilder;
private readonly IDataManager _gameData;
private readonly Logger _logger = logger;

private readonly ConcurrentDictionary<IAction, (Task, CancellationTokenSource)> _tasks = new();
private readonly ConcurrentDictionary<IAction, (Task, CancellationTokenSource)> _tasks = new();
private bool _disposed;

public TextureManager(UiBuilder uiBuilder, IDataManager gameData, Logger logger)
{
_uiBuilder = uiBuilder;
_gameData = gameData;
_logger = logger;
}

public IReadOnlyDictionary<IAction, (Task, CancellationTokenSource)> Tasks
=> _tasks;

Expand Down Expand Up @@ -64,7 +57,8 @@ private Task Enqueue(IAction action)
{
var token = new CancellationTokenSource();
var task = Enqueue(a, token.Token);
task.ContinueWith(_ => _tasks.TryRemove(a, out var unused), CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default);
task.ContinueWith(_ => _tasks.TryRemove(a, out var unused), CancellationToken.None, TaskContinuationOptions.None,
TaskScheduler.Default);
return (task, token);
}).Item1;
}
Expand Down Expand Up @@ -217,7 +211,7 @@ public IDalamudTextureWrap LoadTextureWrap(BaseImage image, byte[]? rgba = null,

/// <summary> Load a texture wrap for a given image. </summary>
public IDalamudTextureWrap LoadTextureWrap(byte[] rgba, int width, int height)
=> _uiBuilder.LoadImageRaw(rgba, width, height, 4);
=> uiBuilder.LoadImageRaw(rgba, width, height, 4);

/// <summary> Load any supported file from game data or drive depending on extension and if the path is rooted. </summary>
public (BaseImage, TextureType) Load(string path)
Expand Down Expand Up @@ -326,7 +320,7 @@ public static BaseImage ConvertToDds(byte[] rgba, int width, int height)
}

public bool GameFileExists(string path)
=> _gameData.FileExists(path);
=> gameData.FileExists(path);

/// <summary> Add up to 13 mip maps to the input if mip maps is true, otherwise return input. </summary>
public static ScratchImage AddMipMaps(ScratchImage input, bool mipMaps)
Expand Down Expand Up @@ -382,7 +376,7 @@ private Stream OpenTexStream(string path)
if (Path.IsPathRooted(path))
return File.OpenRead(path);

var file = _gameData.GetFile(path);
var file = gameData.GetFile(path);
return file != null ? new MemoryStream(file.Data) : throw new Exception($"Unable to obtain \"{path}\" from game files.");
}

Expand Down
3 changes: 1 addition & 2 deletions Penumbra/Interop/PathResolving/CutsceneService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using OtterGui.Services;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Interop;
Expand All @@ -9,7 +8,7 @@

namespace Penumbra.Interop.PathResolving;

public sealed class CutsceneService : IService, IDisposable
public sealed class CutsceneService : IRequiredService, IDisposable
{
public const int CutsceneStartIdx = (int)ScreenActor.CutsceneStart;
public const int CutsceneEndIdx = (int)ScreenActor.CutsceneEnd;
Expand Down
4 changes: 3 additions & 1 deletion Penumbra/Interop/PathResolving/IdentifiedCollectionCache.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using OtterGui.Services;
using Penumbra.Collections;
using Penumbra.Collections.Manager;
using Penumbra.Communication;
Expand All @@ -10,7 +11,8 @@

namespace Penumbra.Interop.PathResolving;

public unsafe class IdentifiedCollectionCache : IDisposable, IEnumerable<(nint Address, ActorIdentifier Identifier, ModCollection Collection)>
public unsafe class IdentifiedCollectionCache : IDisposable, IEnumerable<(nint Address, ActorIdentifier Identifier, ModCollection Collection)>,
IService
{
private readonly CommunicatorService _communicator;
private readonly CharacterDestructor _characterDestructor;
Expand Down
3 changes: 2 additions & 1 deletion Penumbra/Interop/PathResolving/MetaState.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using OtterGui.Classes;
using OtterGui.Services;
using Penumbra.Collections;
using Penumbra.Api.Enums;
using Penumbra.GameData.Structs;
Expand Down Expand Up @@ -34,7 +35,7 @@ namespace Penumbra.Interop.PathResolving;
// ChangeCustomize and RspSetupCharacter, which is hooked here, as well as Character.CalculateHeight.

// GMP Entries seem to be only used by "48 8B ?? 53 55 57 48 83 ?? ?? 48 8B", which is SetupVisor.
public sealed unsafe class MetaState : IDisposable
public sealed unsafe class MetaState : IDisposable, IService
{
private readonly Configuration _config;
private readonly CommunicatorService _communicator;
Expand Down
3 changes: 2 additions & 1 deletion Penumbra/Interop/PathResolving/PathResolver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FFXIVClientStructs.FFXIV.Client.System.Resource;
using OtterGui.Services;
using Penumbra.Api.Enums;
using Penumbra.Collections;
using Penumbra.Collections.Manager;
Expand All @@ -9,7 +10,7 @@

namespace Penumbra.Interop.PathResolving;

public class PathResolver : IDisposable
public class PathResolver : IDisposable, IService
{
private readonly PerformanceTracker _performance;
private readonly Configuration _config;
Expand Down
Loading

0 comments on commit e05dbe9

Please sign in to comment.