Skip to content

Commit

Permalink
Mod importing doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Aug 20, 2024
1 parent 1f38ab8 commit 6384e11
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions docs/plugins/Mod-Construction-and-Importing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ If you know the game you will be working with at compile time, this is the typic
var newMod = new SkyrimMod(ModKey.FromFileName("MyMod.esp"), SkyrimRelease.SkyrimSE);
```

### Generic
In more complex setups, often the game type is a generic that is not known at compile time
### Unknown Game
In more complex setups, often the game type is not known at compile time

```cs
var newMod = ModInstantiator<TMod>.Activator(ModKey.FromFileName("MyMod.esp"), release);
```
=== "Untyped"
```cs
var newMod = ModInstantiator.Activator(ModKey.FromFileName("MyMod.esp"), release);
```

=== "Generic"
```cs
var newMod = ModInstantiator<TMod>.Activator(ModKey.FromFileName("MyMod.esp"), release);
```

## Importing
It is usually preferable to import as readonly initially. As such, importing a mod as readonly is usually preferable.
Expand All @@ -33,23 +39,21 @@ If you know the game you will be working with at compile time, this is the typic
=== "Mutable"
```cs
var mutableInputMod = SkyrimMod.CreateFromBinary(inputPath, SkyrimRelease.SkyrimSE);
```

### Generic
In more complex setups, often the game type is a generic that is not known at compile time. When in this mode functionality does not need to know whether it's a SkyrimMod, or a Fallout4Mod if that's more useful.

This of course, comes with the downside of only being able to interact with the object as much as the TMod constraint allows. You would not be able to access the Water group, for example, as it's uncertain if the mod in question has those.

```cs
public void SomeFunction<TMod>(GameRelease release, ModPath inputPath)
where TMod : IModGetter
{
using var importedMod = ModInstantiator<TMod>.Importer(inputPath, release);
// Limited but reusable generic functionality
}
```
```

### Unknown Game
In more complex setups, often the game type is not known at compile time.

There is no explicit specification of mutable vs readonly in the function's definition. It's up to the caller to decide if `TMod` will be a settable type or not, and an overlay or mutable class will be made under the hood as needed.
=== "Untyped"
```cs
using var readOnlyInputMod = ModInstantiator.ImportGetter(pathToMod, release);
var mutableMod = ModInstantiator.ImportSetter(pathToMod, release);
```

!!! success "Dispose Appropriately"
Since the compile time does not know if it will be an overlay, it always returns a disposable object. Make sure to utilize `using` statements.
=== "Generic"
```cs
var mod = ModInstantiator<TMod>.Importer(ModKey.FromFileName("MyMod.esp"), release);
```

!!! success "Dispose Appropriately"
Binary overlays are disposable, as they can keep streams open as they are accessed. Make sure to utilize `using` statements to dispose of them appropriately.

0 comments on commit 6384e11

Please sign in to comment.