Add a toggle to keep metadata changes to the default value when importing TTMPs.

This commit is contained in:
Ottermandias 2022-12-26 18:36:52 +01:00
parent 707ae090bf
commit ef19af481b
6 changed files with 26 additions and 14 deletions

View file

@ -69,6 +69,7 @@ public partial class Configuration : IPluginConfiguration
public string DefaultModImportPath { get; set; } = string.Empty;
public bool AlwaysOpenDefaultImport { get; set; } = false;
public bool KeepDefaultMetaChanges { get; set; } = false;
public string DefaultModAuthor { get; set; } = DefaultTexToolsData.Author;
public Dictionary< ColorId, uint > Colors { get; set; }

View file

@ -22,7 +22,7 @@ public partial class TexToolsMeta
var value = Eqp.FromSlotAndBytes( metaFileInfo.EquipSlot, data );
var def = new EqpManipulation( ExpandedEqpFile.GetDefault( metaFileInfo.PrimaryId ), metaFileInfo.EquipSlot, metaFileInfo.PrimaryId );
var manip = new EqpManipulation( value, metaFileInfo.EquipSlot, metaFileInfo.PrimaryId );
if( def.Entry != manip.Entry )
if( _keepDefault || def.Entry != manip.Entry )
{
MetaManipulations.Add( manip );
}
@ -53,7 +53,7 @@ public partial class TexToolsMeta
metaFileInfo.EquipSlot,
gr.Split().Item1, gr.Split().Item2, metaFileInfo.PrimaryId );
var manip = new EqdpManipulation( value, metaFileInfo.EquipSlot, gr.Split().Item1, gr.Split().Item2, metaFileInfo.PrimaryId );
if( def.Entry != manip.Entry )
if( _keepDefault || def.Entry != manip.Entry )
{
MetaManipulations.Add( manip );
}
@ -72,7 +72,7 @@ public partial class TexToolsMeta
var value = ( GmpEntry )reader.ReadUInt32();
value.UnknownTotal = reader.ReadByte();
var def = ExpandedGmpFile.GetDefault( metaFileInfo.PrimaryId );
if( value != def )
if( _keepDefault || value != def )
{
MetaManipulations.Add( new GmpManipulation( value, metaFileInfo.PrimaryId ) );
}
@ -107,7 +107,7 @@ public partial class TexToolsMeta
}
var def = EstFile.GetDefault( type, gr, id );
if( def != value )
if( _keepDefault || def != value )
{
MetaManipulations.Add( new EstManipulation( gr.Split().Item1, gr.Split().Item2, type, id, value ) );
}
@ -136,7 +136,7 @@ public partial class TexToolsMeta
var partIdx = ImcFile.PartIndex( manip.EquipSlot ); // Gets turned to unknown for things without equip, and unknown turns to 0.
foreach( var value in values )
{
if( !value.Equals( def.GetEntry( partIdx, i ) ) )
if( _keepDefault || !value.Equals( def.GetEntry( partIdx, i ) ) )
{
MetaManipulations.Add( new ImcManipulation( manip.ObjectType, manip.BodySlot, manip.PrimaryId, manip.SecondaryId, i, manip.EquipSlot, value ) );
}

View file

@ -9,7 +9,7 @@ namespace Penumbra.Import;
public partial class TexToolsMeta
{
// Parse a single rgsp file.
public static TexToolsMeta FromRgspFile( string filePath, byte[] data )
public static TexToolsMeta FromRgspFile( string filePath, byte[] data, bool keepDefault )
{
if( data.Length != 45 && data.Length != 42 )
{
@ -47,7 +47,7 @@ public partial class TexToolsMeta
void Add( RspAttribute attribute, float value )
{
var def = CmpFile.GetDefault( subRace, attribute );
if( value != def )
if( keepDefault || value != def )
{
ret.MetaManipulations.Add( new RspManipulation( subRace, attribute, value ) );
}

View file

@ -26,9 +26,11 @@ public partial class TexToolsMeta
public readonly uint Version;
public readonly string FilePath;
public readonly List< MetaManipulation > MetaManipulations = new();
private readonly bool _keepDefault = false;
public TexToolsMeta( byte[] data )
public TexToolsMeta( byte[] data, bool keepDefault )
{
_keepDefault = keepDefault;
try
{
using var reader = new BinaryReader( new MemoryStream( data ) );

View file

@ -201,7 +201,7 @@ public partial class Mod
continue;
}
var meta = new TexToolsMeta( File.ReadAllBytes( file.FullName ) );
var meta = new TexToolsMeta( File.ReadAllBytes( file.FullName ), Penumbra.Config.KeepDefaultMetaChanges );
Penumbra.Log.Verbose( $"Incorporating {file} as Metadata file of {meta.MetaManipulations.Count} manipulations {deleteString}" );
deleteList.Add( file.FullName );
ManipulationData.UnionWith( meta.MetaManipulations );
@ -214,7 +214,7 @@ public partial class Mod
continue;
}
var rgsp = TexToolsMeta.FromRgspFile( file.FullName, File.ReadAllBytes( file.FullName ) );
var rgsp = TexToolsMeta.FromRgspFile( file.FullName, File.ReadAllBytes( file.FullName ), Penumbra.Config.KeepDefaultMetaChanges );
Penumbra.Log.Verbose( $"Incorporating {file} as racial scaling file of {rgsp.MetaManipulations.Count} manipulations {deleteString}" );
deleteList.Add( file.FullName );
@ -274,7 +274,9 @@ public partial class Mod
{
try
{
var x = file.EndsWith( "rgsp" ) ? TexToolsMeta.FromRgspFile( file, data ) : new TexToolsMeta( data );
var x = file.EndsWith( "rgsp" )
? TexToolsMeta.FromRgspFile( file, data, Penumbra.Config.KeepDefaultMetaChanges )
: new TexToolsMeta( data, Penumbra.Config.KeepDefaultMetaChanges );
meta.UnionWith( x.MetaManipulations );
}
catch

View file

@ -19,10 +19,17 @@ public partial class ConfigWindow
OpenTutorial( BasicTutorialSteps.AdvancedSettings );
if( !header )
{
return;
}
Checkbox( "Auto Deduplicate on Import",
"Automatically deduplicate mod files on import. This will make mod file sizes smaller, but deletes (binary identical) files.",
Penumbra.Config.AutoDeduplicateOnImport, v => Penumbra.Config.AutoDeduplicateOnImport = v );
Checkbox( "Keep Default Metadata Changes on Import",
"Normally, metadata changes that equal their default values, which are sometimes exported by TexTools, are discarded. "
+ "Toggle this to keep them, for example if an option in a mod is supposed to disable a metadata change from a prior option.",
Penumbra.Config.KeepDefaultMetaChanges, v => Penumbra.Config.KeepDefaultMetaChanges = v );
DrawRequestedResourceLogging();
DrawEnableHttpApiBox();
DrawEnableDebugModeBox();