mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-01-03 14:23:43 +01:00
Change resolving to possibly work correctly for all materials and load specific materials for each collection.
This commit is contained in:
parent
b6ed27e235
commit
1e5776a481
16 changed files with 408 additions and 172 deletions
|
|
@ -22,7 +22,7 @@ public delegate void CollectionChangeDelegate( ModCollection? oldCollection, Mod
|
|||
string? characterName = null );
|
||||
|
||||
// Contains all collections and respective functions, as well as the collection settings.
|
||||
public class CollectionManager : IDisposable
|
||||
public sealed class CollectionManager : IDisposable
|
||||
{
|
||||
private readonly ModManager _manager;
|
||||
|
||||
|
|
@ -40,10 +40,20 @@ public class CollectionManager : IDisposable
|
|||
=> ByName( ModCollection.DefaultCollection )!;
|
||||
|
||||
public ModCollection? ByName( string name )
|
||||
=> Collections.Find( c => c.Name == name );
|
||||
=> name.Length > 0
|
||||
? Collections.Find( c => string.Equals( c.Name, name, StringComparison.InvariantCultureIgnoreCase ) )
|
||||
: ModCollection.Empty;
|
||||
|
||||
public bool ByName( string name, [NotNullWhen( true )] out ModCollection? collection )
|
||||
=> Collections.FindFirst( c => c.Name == name, out collection );
|
||||
{
|
||||
if( name.Length > 0 )
|
||||
{
|
||||
return Collections.FindFirst( c => string.Equals( c.Name, name, StringComparison.InvariantCultureIgnoreCase ), out collection );
|
||||
}
|
||||
|
||||
collection = ModCollection.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Is invoked after the collections actually changed.
|
||||
public event CollectionChangeDelegate? CollectionChanged;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -21,14 +22,23 @@ public delegate void ModChangeDelegate( ModChangeType type, int modIndex, ModDat
|
|||
|
||||
// The ModManager handles the basic mods installed to the mod directory.
|
||||
// It also contains the CollectionManager that handles all collections.
|
||||
public class ModManager
|
||||
public class ModManager : IEnumerable< ModData >
|
||||
{
|
||||
public DirectoryInfo BasePath { get; private set; } = null!;
|
||||
|
||||
private List< ModData > ModsInternal { get; init; } = new();
|
||||
private readonly List< ModData > _mods = new();
|
||||
|
||||
public ModData this[ int idx ]
|
||||
=> _mods[ idx ];
|
||||
|
||||
public IReadOnlyList< ModData > Mods
|
||||
=> ModsInternal;
|
||||
=> _mods;
|
||||
|
||||
public IEnumerator< ModData > GetEnumerator()
|
||||
=> _mods.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
=> GetEnumerator();
|
||||
|
||||
public ModFolder StructuredMods { get; } = ModFileSystem.Root;
|
||||
|
||||
|
|
@ -37,6 +47,9 @@ public class ModManager
|
|||
|
||||
public bool Valid { get; private set; }
|
||||
|
||||
public int Count
|
||||
=> _mods.Count;
|
||||
|
||||
public Configuration Config
|
||||
=> Penumbra.Config;
|
||||
|
||||
|
|
@ -116,7 +129,7 @@ public class ModManager
|
|||
|
||||
foreach( var (folder, path) in Config.ModSortOrder.ToArray() )
|
||||
{
|
||||
if( path.Length > 0 && ModsInternal.FindFirst( m => m.BasePath.Name == folder, out var mod ) )
|
||||
if( path.Length > 0 && _mods.FindFirst( m => m.BasePath.Name == folder, out var mod ) )
|
||||
{
|
||||
changes |= SetSortOrderPath( mod, path );
|
||||
}
|
||||
|
|
@ -135,7 +148,7 @@ public class ModManager
|
|||
|
||||
public void DiscoverMods()
|
||||
{
|
||||
ModsInternal.Clear();
|
||||
_mods.Clear();
|
||||
BasePath.Refresh();
|
||||
|
||||
StructuredMods.SubFolders.Clear();
|
||||
|
|
@ -150,7 +163,7 @@ public class ModManager
|
|||
continue;
|
||||
}
|
||||
|
||||
ModsInternal.Add( mod );
|
||||
_mods.Add( mod );
|
||||
}
|
||||
|
||||
SetModStructure();
|
||||
|
|
@ -173,12 +186,12 @@ public class ModManager
|
|||
}
|
||||
}
|
||||
|
||||
var idx = ModsInternal.FindIndex( m => m.BasePath.Name == modFolder.Name );
|
||||
var idx = _mods.FindIndex( m => m.BasePath.Name == modFolder.Name );
|
||||
if( idx >= 0 )
|
||||
{
|
||||
var mod = ModsInternal[ idx ];
|
||||
var mod = _mods[ idx ];
|
||||
mod.SortOrder.ParentFolder.RemoveMod( mod );
|
||||
ModsInternal.RemoveAt( idx );
|
||||
_mods.RemoveAt( idx );
|
||||
ModChange?.Invoke( ModChangeType.Removed, idx, mod );
|
||||
}
|
||||
}
|
||||
|
|
@ -199,15 +212,15 @@ public class ModManager
|
|||
}
|
||||
}
|
||||
|
||||
if( ModsInternal.Any( m => m.BasePath.Name == modFolder.Name ) )
|
||||
if( _mods.Any( m => m.BasePath.Name == modFolder.Name ) )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ModsInternal.Add( mod );
|
||||
ModChange?.Invoke( ModChangeType.Added, ModsInternal.Count - 1, mod );
|
||||
_mods.Add( mod );
|
||||
ModChange?.Invoke( ModChangeType.Added, _mods.Count - 1, mod );
|
||||
|
||||
return ModsInternal.Count - 1;
|
||||
return _mods.Count - 1;
|
||||
}
|
||||
|
||||
public bool UpdateMod( int idx, bool reloadMeta = false, bool recomputeMeta = false, bool force = false )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue