mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-21 15:27:51 +01:00
A few comments, further cleanup. A few TODOs handled.
This commit is contained in:
parent
dbb9931189
commit
c78725d7d5
47 changed files with 347 additions and 3664 deletions
|
|
@ -12,14 +12,19 @@ public partial class Mod
|
|||
public delegate void ModPathChangeDelegate( ModPathChangeType type, Mod mod, DirectoryInfo? oldDirectory,
|
||||
DirectoryInfo? newDirectory );
|
||||
|
||||
public event ModPathChangeDelegate? ModPathChanged;
|
||||
public event ModPathChangeDelegate ModPathChanged;
|
||||
|
||||
// Rename/Move a mod directory.
|
||||
// Updates all collection settings and sort order settings.
|
||||
public void MoveModDirectory( Index idx, DirectoryInfo newDirectory )
|
||||
{
|
||||
var mod = this[ idx ];
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Delete a mod by its index.
|
||||
// Deletes from filesystem as well as from internal data.
|
||||
// Updates indices of later mods.
|
||||
public void DeleteMod( int idx )
|
||||
{
|
||||
var mod = this[ idx ];
|
||||
|
|
@ -41,9 +46,10 @@ public partial class Mod
|
|||
--remainingMod.Index;
|
||||
}
|
||||
|
||||
ModPathChanged?.Invoke( ModPathChangeType.Deleted, mod, mod.BasePath, null );
|
||||
ModPathChanged.Invoke( ModPathChangeType.Deleted, mod, mod.BasePath, null );
|
||||
}
|
||||
|
||||
// Load a new mod and add it to the manager if successful.
|
||||
public void AddMod( DirectoryInfo modFolder )
|
||||
{
|
||||
if( _mods.Any( m => m.BasePath.Name == modFolder.Name ) )
|
||||
|
|
@ -59,7 +65,22 @@ public partial class Mod
|
|||
|
||||
mod.Index = _mods.Count;
|
||||
_mods.Add( mod );
|
||||
ModPathChanged?.Invoke( ModPathChangeType.Added, mod, null, mod.BasePath );
|
||||
ModPathChanged.Invoke( ModPathChangeType.Added, mod, null, mod.BasePath );
|
||||
}
|
||||
|
||||
// Add new mods to NewMods and remove deleted mods from NewMods.
|
||||
private void OnModPathChange( ModPathChangeType type, Mod mod, DirectoryInfo? oldDirectory,
|
||||
DirectoryInfo? newDirectory )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case ModPathChangeType.Added:
|
||||
NewMods.Add( mod );
|
||||
break;
|
||||
case ModPathChangeType.Deleted:
|
||||
NewMods.Remove( mod );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -197,6 +197,14 @@ public sealed partial class Mod
|
|||
return;
|
||||
}
|
||||
|
||||
if( mod._groups[ groupIdx ].Count > 63 )
|
||||
{
|
||||
PluginLog.Error(
|
||||
$"Could not add option {option.Name} to {mod._groups[ groupIdx ].Name} for mod {mod.Name}, "
|
||||
+ "since only up to 64 options are supported in one group." );
|
||||
return;
|
||||
}
|
||||
|
||||
switch( mod._groups[ groupIdx ] )
|
||||
{
|
||||
case SingleModGroup s:
|
||||
|
|
|
|||
|
|
@ -11,16 +11,19 @@ public sealed partial class Mod
|
|||
public DirectoryInfo BasePath { get; private set; } = null!;
|
||||
public bool Valid { get; private set; }
|
||||
|
||||
|
||||
public event Action? ModDiscoveryStarted;
|
||||
public event Action? ModDiscoveryFinished;
|
||||
|
||||
// Change the mod base directory and discover available mods.
|
||||
public void DiscoverMods( string newDir )
|
||||
{
|
||||
SetBaseDirectory( newDir, false );
|
||||
DiscoverMods();
|
||||
}
|
||||
|
||||
// Set the mod base directory.
|
||||
// If its not the first time, check if it is the same directory as before.
|
||||
// Also checks if the directory is available and tries to create it if it is not.
|
||||
private void SetBaseDirectory( string newPath, bool firstTime )
|
||||
{
|
||||
if( !firstTime && string.Equals( newPath, Penumbra.Config.ModDirectory, StringComparison.InvariantCultureIgnoreCase ) )
|
||||
|
|
@ -59,8 +62,10 @@ public sealed partial class Mod
|
|||
}
|
||||
}
|
||||
|
||||
// Discover new mods.
|
||||
public void DiscoverMods()
|
||||
{
|
||||
NewMods.Clear();
|
||||
ModDiscoveryStarted?.Invoke();
|
||||
_mods.Clear();
|
||||
BasePath.Refresh();
|
||||
|
|
|
|||
|
|
@ -6,16 +6,22 @@ namespace Penumbra.Mods;
|
|||
|
||||
public sealed partial class Mod
|
||||
{
|
||||
public sealed partial class Manager : IEnumerable< Mod >
|
||||
public sealed partial class Manager : IReadOnlyList< Mod >
|
||||
{
|
||||
// An easily accessible set of new mods.
|
||||
// Mods are added when they are created or imported.
|
||||
// Mods are removed when they are deleted or when they are toggled in any collection.
|
||||
// Also gets cleared on mod rediscovery.
|
||||
public readonly HashSet< Mod > NewMods = new();
|
||||
|
||||
private readonly List< Mod > _mods = new();
|
||||
|
||||
public Mod this[ int idx ]
|
||||
=> _mods[ idx ];
|
||||
|
||||
public Mod this[ Index idx ]
|
||||
=> _mods[ idx ];
|
||||
|
||||
public IReadOnlyList< Mod > Mods
|
||||
=> _mods;
|
||||
|
||||
public int Count
|
||||
=> _mods.Count;
|
||||
|
||||
|
|
@ -29,6 +35,7 @@ public sealed partial class Mod
|
|||
{
|
||||
SetBaseDirectory( modDirectory, true );
|
||||
ModOptionChanged += OnModOptionChange;
|
||||
ModPathChanged += OnModPathChange;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue