Use strongly typed ids in most places.

This commit is contained in:
Ottermandias 2023-07-29 02:22:31 +02:00
parent dccd347432
commit 18b6b87e6b
26 changed files with 192 additions and 193 deletions

View file

@ -15,7 +15,7 @@ public static class CustomizationSwap
/// The .mdl file for customizations is unique per racecode, slot and id, thus the .mdl redirection itself is independent of the mode.
public static FileSwap CreateMdl( MetaFileManager manager, Func< Utf8GamePath, FullPath > redirections, BodySlot slot, GenderRace race, SetId idFrom, SetId idTo )
{
if( idFrom.Value > byte.MaxValue )
if( idFrom.Id > byte.MaxValue )
{
throw new Exception( $"The Customization ID {idFrom} is too large for {slot}." );
}
@ -51,9 +51,9 @@ public static class CustomizationSwap
var newFileName = fileName;
newFileName = ItemSwap.ReplaceRace( newFileName, gameRaceTo, race, gameRaceTo != race );
newFileName = ItemSwap.ReplaceBody( newFileName, slot, idTo, idFrom, idFrom.Value != idTo.Value );
newFileName = ItemSwap.ReplaceBody( newFileName, slot, idTo, idFrom, idFrom != idTo );
newFileName = ItemSwap.AddSuffix( newFileName, ".mtrl", $"_c{race.ToRaceCode()}", gameRaceFrom != race || MaterialHandling.IsSpecialCase( race, idFrom ) );
newFileName = ItemSwap.AddSuffix( newFileName, ".mtrl", $"_{slot.ToAbbreviation()}{idFrom.Value:D4}", gameSetIdFrom.Value != idFrom.Value );
newFileName = ItemSwap.AddSuffix( newFileName, ".mtrl", $"_{slot.ToAbbreviation()}{idFrom.Id:D4}", gameSetIdFrom != idFrom );
var actualMtrlFromPath = mtrlFromPath;
if( newFileName != fileName )

View file

@ -54,11 +54,11 @@ public static class EquipmentSwap
throw new ItemSwap.InvalidItemTypeException();
var (imcFileFrom, variants, affectedItems) = GetVariants(manager, identifier, slotFrom, idFrom, idTo, variantFrom);
var imcManip = new ImcManipulation(slotTo, variantTo, idTo.Value, default);
var imcManip = new ImcManipulation(slotTo, variantTo.Id, idTo.Id, default);
var imcFileTo = new ImcFile(manager, imcManip);
var skipFemale = false;
var skipMale = false;
var mtrlVariantTo = manips(imcManip.Copy(imcFileTo.GetEntry(ImcFile.PartIndex(slotTo), variantTo))).Imc.Entry.MaterialId;
var mtrlVariantTo = manips(imcManip.Copy(imcFileTo.GetEntry(ImcFile.PartIndex(slotTo), variantTo.Id))).Imc.Entry.MaterialId;
foreach (var gr in Enum.GetValues<GenderRace>())
{
switch (gr.Split().Item1)
@ -124,7 +124,7 @@ public static class EquipmentSwap
foreach (var slot in ConvertSlots(slotFrom, rFinger, lFinger))
{
(var imcFileFrom, var variants, affectedItems) = GetVariants(manager, identifier, slot, idFrom, idTo, variantFrom);
var imcManip = new ImcManipulation(slot, variantTo, idTo.Value, default);
var imcManip = new ImcManipulation(slot, variantTo.Id, idTo, default);
var imcFileTo = new ImcFile(manager, imcManip);
var isAccessory = slot.IsAccessory();
@ -198,10 +198,10 @@ public static class EquipmentSwap
SetId idTo, byte mtrlTo)
{
var (gender, race) = gr.Split();
var eqdpFrom = new EqdpManipulation(ExpandedEqdpFile.GetDefault(manager, gr, slotFrom.IsAccessory(), idFrom.Value), slotFrom, gender,
race, idFrom.Value);
var eqdpTo = new EqdpManipulation(ExpandedEqdpFile.GetDefault(manager, gr, slotTo.IsAccessory(), idTo.Value), slotTo, gender, race,
idTo.Value);
var eqdpFrom = new EqdpManipulation(ExpandedEqdpFile.GetDefault(manager, gr, slotFrom.IsAccessory(), idFrom), slotFrom, gender,
race, idFrom);
var eqdpTo = new EqdpManipulation(ExpandedEqdpFile.GetDefault(manager, gr, slotTo.IsAccessory(), idTo), slotTo, gender, race,
idTo);
var meta = new MetaSwap(manips, eqdpFrom, eqdpTo);
var (ownMtrl, ownMdl) = meta.SwapApplied.Eqdp.Entry.ToBits(slotFrom);
if (ownMdl)
@ -240,7 +240,7 @@ public static class EquipmentSwap
return mdl;
}
private static void LookupItem(EquipItem i, out EquipSlot slot, out SetId modelId, out byte variant)
private static void LookupItem(EquipItem i, out EquipSlot slot, out SetId modelId, out Variant variant)
{
slot = i.Type.ToSlot();
if (!slot.IsEquipmentPiece())
@ -250,14 +250,14 @@ public static class EquipmentSwap
variant = i.Variant;
}
private static (ImcFile, byte[], EquipItem[]) GetVariants(MetaFileManager manager, IObjectIdentifier identifier, EquipSlot slotFrom,
SetId idFrom, SetId idTo, byte variantFrom)
private static (ImcFile, Variant[], EquipItem[]) GetVariants(MetaFileManager manager, IObjectIdentifier identifier, EquipSlot slotFrom,
SetId idFrom, SetId idTo, Variant variantFrom)
{
var entry = new ImcManipulation(slotFrom, variantFrom, idFrom.Value, default);
var entry = new ImcManipulation(slotFrom, variantFrom.Id, idFrom, default);
var imc = new ImcFile(manager, entry);
EquipItem[] items;
byte[] variants;
if (idFrom.Value == idTo.Value)
Variant[] variants;
if (idFrom == idTo)
{
items = identifier.Identify(idFrom, variantFrom, slotFrom).ToArray();
variants = new[]
@ -270,7 +270,7 @@ public static class EquipmentSwap
items = identifier.Identify(slotFrom.IsEquipment()
? GamePaths.Equipment.Mdl.Path(idFrom, GenderRace.MidlanderMale, slotFrom)
: GamePaths.Accessory.Mdl.Path(idFrom, GenderRace.MidlanderMale, slotFrom)).Select(kvp => kvp.Value).OfType<EquipItem>().ToArray();
variants = Enumerable.Range(0, imc.Count + 1).Select(i => (byte)i).ToArray();
variants = Enumerable.Range(0, imc.Count + 1).Select(i => (Variant)i).ToArray();
}
return (imc, variants, items);
@ -282,24 +282,23 @@ public static class EquipmentSwap
if (slot is not EquipSlot.Head)
return null;
var manipFrom = new GmpManipulation(ExpandedGmpFile.GetDefault(manager, idFrom.Value), idFrom.Value);
var manipTo = new GmpManipulation(ExpandedGmpFile.GetDefault(manager, idTo.Value), idTo.Value);
var manipFrom = new GmpManipulation(ExpandedGmpFile.GetDefault(manager, idFrom), idFrom);
var manipTo = new GmpManipulation(ExpandedGmpFile.GetDefault(manager, idTo), idTo);
return new MetaSwap(manips, manipFrom, manipTo);
}
public static MetaSwap CreateImc(MetaFileManager manager, Func<Utf8GamePath, FullPath> redirections, Func<MetaManipulation, MetaManipulation> manips, EquipSlot slot,
SetId idFrom, SetId idTo,
byte variantFrom, byte variantTo, ImcFile imcFileFrom, ImcFile imcFileTo)
SetId idFrom, SetId idTo, Variant variantFrom, Variant variantTo, ImcFile imcFileFrom, ImcFile imcFileTo)
=> CreateImc(manager, redirections, manips, slot, slot, idFrom, idTo, variantFrom, variantTo, imcFileFrom, imcFileTo);
public static MetaSwap CreateImc(MetaFileManager manager, Func<Utf8GamePath, FullPath> redirections, Func<MetaManipulation, MetaManipulation> manips,
EquipSlot slotFrom, EquipSlot slotTo, SetId idFrom, SetId idTo,
byte variantFrom, byte variantTo, ImcFile imcFileFrom, ImcFile imcFileTo)
Variant variantFrom, Variant variantTo, ImcFile imcFileFrom, ImcFile imcFileTo)
{
var entryFrom = imcFileFrom.GetEntry(ImcFile.PartIndex(slotFrom), variantFrom);
var entryTo = imcFileTo.GetEntry(ImcFile.PartIndex(slotTo), variantTo);
var manipulationFrom = new ImcManipulation(slotFrom, variantFrom, idFrom.Value, entryFrom);
var manipulationTo = new ImcManipulation(slotTo, variantTo, idTo.Value, entryTo);
var manipulationFrom = new ImcManipulation(slotFrom, variantFrom.Id, idFrom, entryFrom);
var manipulationTo = new ImcManipulation(slotTo, variantTo.Id, idTo, entryTo);
var imc = new MetaSwap(manips, manipulationFrom, manipulationTo);
var decal = CreateDecal(manager, redirections, imc.SwapToModded.Imc.Entry.DecalId);
@ -332,8 +331,8 @@ public static class EquipmentSwap
if (vfxId == 0)
return null;
var vfxPathFrom = GamePaths.Equipment.Avfx.Path(idFrom.Value, vfxId);
var vfxPathTo = GamePaths.Equipment.Avfx.Path(idTo.Value, vfxId);
var vfxPathFrom = GamePaths.Equipment.Avfx.Path(idFrom, vfxId);
var vfxPathTo = GamePaths.Equipment.Avfx.Path(idTo, vfxId);
var avfx = FileSwap.CreateSwap(manager, ResourceType.Avfx, redirections, vfxPathFrom, vfxPathTo);
foreach (ref var filePath in avfx.AsAvfx()!.Textures.AsSpan())
@ -351,10 +350,10 @@ public static class EquipmentSwap
if (slot.IsAccessory())
return null;
var eqpValueFrom = ExpandedEqpFile.GetDefault(manager, idFrom.Value);
var eqpValueTo = ExpandedEqpFile.GetDefault(manager, idTo.Value);
var eqpFrom = new EqpManipulation(eqpValueFrom, slot, idFrom.Value);
var eqpTo = new EqpManipulation(eqpValueTo, slot, idFrom.Value);
var eqpValueFrom = ExpandedEqpFile.GetDefault(manager, idFrom);
var eqpValueTo = ExpandedEqpFile.GetDefault(manager, idTo);
var eqpFrom = new EqpManipulation(eqpValueFrom, slot, idFrom);
var eqpTo = new EqpManipulation(eqpValueTo, slot, idFrom);
return new MetaSwap(manips, eqpFrom, eqpTo);
}
@ -368,7 +367,7 @@ public static class EquipmentSwap
ref bool dataWasChanged)
{
var prefix = slotTo.IsAccessory() ? 'a' : 'e';
if (!fileName.Contains($"{prefix}{idTo.Value:D4}"))
if (!fileName.Contains($"{prefix}{idTo.Id:D4}"))
return null;
var folderTo = slotTo.IsAccessory()

View file

@ -9,7 +9,6 @@ using Penumbra.GameData.Structs;
using Penumbra.Meta;
using Penumbra.Meta.Files;
using Penumbra.Meta.Manipulations;
using Penumbra.Services;
using Penumbra.String.Classes;
namespace Penumbra.Mods.ItemSwap;
@ -163,8 +162,8 @@ public static class ItemSwap
}
var (gender, race) = genderRace.Split();
var fromDefault = new EstManipulation( gender, race, type, idFrom.Value, EstFile.GetDefault( manager, type, genderRace, idFrom.Value ) );
var toDefault = new EstManipulation( gender, race, type, idTo.Value, EstFile.GetDefault( manager, type, genderRace, idTo.Value ) );
var fromDefault = new EstManipulation( gender, race, type, idFrom, EstFile.GetDefault( manager, type, genderRace, idFrom ) );
var toDefault = new EstManipulation( gender, race, type, idTo, EstFile.GetDefault( manager, type, genderRace, idTo ) );
var est = new MetaSwap( manips, fromDefault, toDefault );
if( ownMdl && est.SwapApplied.Est.Entry >= 2 )
@ -206,7 +205,7 @@ public static class ItemSwap
public static string ReplaceAnyId( string path, char idType, SetId id, bool condition = true )
=> condition
? Regex.Replace( path, $"{idType}\\d{{4}}", $"{idType}{id.Value:D4}" )
? Regex.Replace( path, $"{idType}\\d{{4}}", $"{idType}{id.Id:D4}" )
: path;
public static string ReplaceAnyRace( string path, GenderRace to, bool condition = true )
@ -217,7 +216,7 @@ public static class ItemSwap
public static string ReplaceId( string path, char type, SetId idFrom, SetId idTo, bool condition = true )
=> condition
? path.Replace( $"{type}{idFrom.Value:D4}", $"{type}{idTo.Value:D4}" )
? path.Replace( $"{type}{idFrom.Id:D4}", $"{type}{idTo.Id:D4}" )
: path;
public static string ReplaceSlot( string path, EquipSlot from, EquipSlot to, bool condition = true )