-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
561 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Mutagen.Bethesda.Core/Plugins/Analysis/RecordCompactionCompatibilityDetection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Mutagen.Bethesda.Plugins.Analysis.DI; | ||
using Mutagen.Bethesda.Plugins.Records; | ||
using Noggog; | ||
|
||
namespace Mutagen.Bethesda.Plugins.Analysis; | ||
|
||
public static class RecordCompactionCompatibilityDetection | ||
{ | ||
private static RecordCompactionCompatibilityDetector _detector = new(); | ||
|
||
public static bool IsSmallMasterCompatible(IModGetter mod) | ||
{ | ||
return _detector.IsSmallMasterCompatible(mod); | ||
} | ||
|
||
public static bool CouldBeSmallMasterCompatible(IModGetter mod) | ||
{ | ||
return _detector.CouldBeSmallMasterCompatible(mod); | ||
} | ||
|
||
public static bool IsMediumMasterCompatible(IModGetter mod) | ||
{ | ||
return _detector.IsMediumMasterCompatible(mod); | ||
} | ||
|
||
public static bool CouldBeMediumMasterCompatible(IModGetter mod) | ||
{ | ||
return _detector.CouldBeMediumMasterCompatible(mod); | ||
} | ||
|
||
public static RangeUInt32? GetSmallMasterRange(IModGetter mod) | ||
{ | ||
return _detector.GetSmallMasterRange(mod); | ||
} | ||
|
||
public static RangeUInt32? GetMediumMasterRange(IModGetter mod) | ||
{ | ||
return _detector.GetMediumMasterRange(mod); | ||
} | ||
|
||
public static RangeUInt32 GetFullMasterRange(IModGetter mod, bool potential) | ||
{ | ||
return _detector.GetFullMasterRange(mod, potential); | ||
} | ||
|
||
public static RangeUInt32? GetAllowedRange(IModGetter mod, bool potential) | ||
{ | ||
return _detector.GetAllowedRange(mod, potential); | ||
} | ||
|
||
public static void IterateAndThrowIfIncompatible(IModGetter mod, bool potential) | ||
{ | ||
_detector.IterateAndThrowIfIncompatible(mod, potential); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Mutagen.Bethesda.Plugins.Analysis.DI; | ||
using Mutagen.Bethesda.Plugins.Records; | ||
using Mutagen.Bethesda.Plugins.Utility.DI; | ||
|
||
namespace Mutagen.Bethesda.Plugins.Utility; | ||
|
||
public static class ModCompaction | ||
{ | ||
private static readonly ModCompactor _compactor = new( | ||
new RecordCompactionCompatibilityDetector()); | ||
|
||
public static void CompactToSmallMaster(IMod mod) | ||
{ | ||
_compactor.CompactToSmallMaster(mod); | ||
} | ||
|
||
public static void CompactToMediumMaster(IMod mod) | ||
{ | ||
_compactor.CompactToMediumMaster(mod); | ||
} | ||
|
||
public static void CompactToFullMaster(IMod mod) | ||
{ | ||
_compactor.CompactToFullMaster(mod); | ||
} | ||
|
||
public static void CompactTo(IMod mod, MasterStyle style) | ||
{ | ||
_compactor.CompactTo(mod, style); | ||
} | ||
|
||
public static void CompactToWithFallback(IMod mod, MasterStyle style) | ||
{ | ||
_compactor.CompactToWithFallback(mod, style); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Exception Enrichment | ||
|
||
Mutagen's code is written in a lightweight way that means its exceptions are not fully filled out with all the extra information that might be interesting. Often, an exception will just print the very specific field that failed, but not include other important details such as: | ||
|
||
- FormKey of the record it was from | ||
- ModKey of the mod it was from | ||
|
||
It is recommended that you wrap access code in a try/catch that enriches the exception with that extra information. | ||
|
||
## RecordException Enrichment | ||
|
||
This enriches an exception relative to a major record's information | ||
|
||
```cs | ||
foreach (var npc in state.LoadOrder.PriorityOrder.Npc().WinningOverrides()) | ||
{ | ||
try | ||
{ | ||
var overrideNpc = state.PatchMod.Npcs.GetOrAddAsOverride(npc); | ||
overrideNpc.Height *= 1.3f; | ||
} | ||
catch (Exception e) | ||
{ | ||
throw RecordException.Enrich(e, npc); | ||
} | ||
} | ||
``` | ||
|
||
This will make the exception include: | ||
|
||
- EditorID | ||
- RecordType (NPC_) | ||
- FormKey | ||
|
||
### ModKey Inclusion | ||
The above code will -NOT- include `ModKey`. The ModKey that the record override originated from cannot be inferred automatically and so must be passed in. The above call has a `modKey` parameter that you can pass this information to if you have it. | ||
|
||
More than likely, though, the best way to do this is to use [ModContexts](../linkcache/ModContexts.md), which contain the information about what Mod the record originated from. | ||
```cs | ||
foreach (var npcContext in state.LoadOrder.PriorityOrder.Npc().WinningContextOverrides()) | ||
{ | ||
try | ||
{ | ||
var overrideNpc = npcContext.GetOrAddAsOverride(state.PatchMod); | ||
overrideNpc.Height *= 1.3f; | ||
} | ||
catch (Exception e) | ||
{ | ||
throw RecordException.Enrich(e, npcContext); | ||
} | ||
} | ||
``` | ||
|
||
## Subrecord Exception | ||
|
||
This is an even more specialized version of RecordException that also includes the Subrecord type. Typically this is just used by the Mutagen engine itself, and not applicable to user code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.