Skip to content

Commit

Permalink
Import the 'default option' from PMP files with multiple options
Browse files Browse the repository at this point in the history
helpful-fox-senko-san committed Oct 9, 2024
1 parent 01df548 commit c763edc
Showing 2 changed files with 121 additions and 116 deletions.
199 changes: 104 additions & 95 deletions xivModdingFramework/Mods/FileTypes/PMP.cs
Original file line number Diff line number Diff line change
@@ -316,124 +316,124 @@ private static void ValidateOption(PmpStandardOptionJson op)

tx.ModPack = modPack;

if (pmp.Groups == null || pmp.Groups.Count == 0)
var defMod = pmp.DefaultMod as PmpStandardOptionJson;

// Default option is always selected and always applied first, if it is present
if (defMod != null && !defMod.IsEmptyOption)
{
// No options, just default.
var groupRes = await ImportOption(pmp.DefaultMod, unzippedPath, tx, progress);
UnionDict(imported, groupRes.Imported);
notImported.UnionWith(groupRes.NotImported);
}
else

// Order groups by Priority, Lowest => Highest, tiebreaker default order
var orderedGroups = pmp.Groups.OrderBy(x => x.Priority).ToList();
var groupIdx = 0;
foreach (var group in orderedGroups)
{
// Order groups by Priority, Lowest => Highest, tiebreaker default order
var orderedGroups = pmp.Groups.OrderBy(x => x.Priority).ToList();
var groupIdx = 0;
foreach (var group in orderedGroups)
if (group.Options == null || group.Options.Count == 0)
{
if (group.Options == null || group.Options.Count == 0)
{
// No valid options.
groupIdx++;
continue;
}
var optionIdx = 0;
// No valid options.
groupIdx++;
continue;
}
var optionIdx = 0;

// Get Default selection.
var selected = group.DefaultSettings;

// Get Default selection.
var selected = group.DefaultSettings;
// If the user selected custom settings, use those.
if (group.SelectedSettings >= 0)
{
selected = group.SelectedSettings;
}

// If the user selected custom settings, use those.
if (group.SelectedSettings >= 0)
if (group.Type == "Single")
{
if (selected < 0 || selected >= group.Options.Count)
{
selected = group.SelectedSettings;
selected = 0;
}
var groupRes = await ImportOption(group.Options[selected], unzippedPath, tx, progress, groupIdx, optionIdx);
UnionDict(imported, groupRes.Imported);
notImported.UnionWith(groupRes.NotImported);
}
else if(group.Type == "Multi")
{
var ordered = group.Options.OrderBy(x => ((PmpStandardOptionJson)x).Priority).ToList();

if (group.Type == "Single")
// Bitmask options. Install in priority order.
foreach(var op in ordered)
{
if (selected < 0 || selected >= group.Options.Count)
var i = group.Options.IndexOf(op);
var value = 1 << i;
if ((selected & value) > 0)
{
selected = 0;
var groupRes = await ImportOption(group.Options[i], unzippedPath, tx, progress, groupIdx, optionIdx);
UnionDict(imported, groupRes.Imported);
notImported.UnionWith(groupRes.NotImported);
optionIdx++;
}
var groupRes = await ImportOption(group.Options[selected], unzippedPath, tx, progress, groupIdx, optionIdx);
UnionDict(imported, groupRes.Imported);
notImported.UnionWith(groupRes.NotImported);
}
else if(group.Type == "Multi")
{
var ordered = group.Options.OrderBy(x => ((PmpStandardOptionJson)x).Priority).ToList();

// Bitmask options. Install in priority order.
foreach(var op in ordered)
} else if(group.Type == "Imc")
{
// Could do with popping this out to its own function.
var imcGroup = group as PMPImcGroupJson;
var xivImc = imcGroup.DefaultEntry.ToXivImc();

bool disabled = false;
// Bitmask options.
for (int i = 0; i < group.Options.Count; i++)
{
var value = 1 << i;
if ((selected & value) > 0)
{
var i = group.Options.IndexOf(op);
var value = 1 << i;
if ((selected & value) > 0)
var disableOpt = group.Options[i] as PmpDisableImcOptionJson;
if (disableOpt != null)
{
var groupRes = await ImportOption(group.Options[i], unzippedPath, tx, progress, groupIdx, optionIdx);
UnionDict(imported, groupRes.Imported);
notImported.UnionWith(groupRes.NotImported);
optionIdx++;
// No options allowed >:|
disabled = true;
break;
}

var opt = group.Options[i] as PmpImcOptionJson;
optionIdx++;

xivImc.AttributeMask |= opt.AttributeMask;
}
}

} else if(group.Type == "Imc")
if (!disabled)
{
// Could do with popping this out to its own function.
var imcGroup = group as PMPImcGroupJson;
var xivImc = imcGroup.DefaultEntry.ToXivImc();

bool disabled = false;
// Bitmask options.
for (int i = 0; i < group.Options.Count; i++)
var root = imcGroup.GetRoot();
var metaData = await GetImportMetadata(imported, root, tx);
if (metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
{
var value = 1 << i;
if ((selected & value) > 0)
while(metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
{
var disableOpt = group.Options[i] as PmpDisableImcOptionJson;
if (disableOpt != null)
{
// No options allowed >:|
disabled = true;
break;
}

var opt = group.Options[i] as PmpImcOptionJson;
optionIdx++;

xivImc.AttributeMask |= opt.AttributeMask;
metaData.ImcEntries.Add((XivImc)xivImc.Clone());
}
}

if (!disabled)
else
{
var root = imcGroup.GetRoot();
var metaData = await GetImportMetadata(imported, root, tx);
if (metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
{
while(metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
{
metaData.ImcEntries.Add((XivImc)xivImc.Clone());
}
}
else
{
metaData.ImcEntries[(int)imcGroup.Identifier.Variant] = xivImc;
}
metaData.ImcEntries[(int)imcGroup.Identifier.Variant] = xivImc;
}

if (imcGroup.AllVariants)
if (imcGroup.AllVariants)
{
for (int i = 0; i < metaData.ImcEntries.Count; i++)
{
for (int i = 0; i < metaData.ImcEntries.Count; i++)
{
metaData.ImcEntries[i] = (XivImc)xivImc.Clone();
}
metaData.ImcEntries[i] = (XivImc)xivImc.Clone();
}
}

await ItemMetadata.SaveMetadata(metaData, _Source, tx);
await ItemMetadata.ApplyMetadata(metaData, tx);
await ItemMetadata.SaveMetadata(metaData, _Source, tx);
await ItemMetadata.ApplyMetadata(metaData, tx);

}
}
groupIdx++;
}
groupIdx++;
}

var preRootTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
@@ -910,28 +910,31 @@ internal static async Task<Dictionary<string, FileStorageInformation>> UnpackPMP
var defMod = pmp.DefaultMod as PmpStandardOptionJson;
PmpStandardOptionJson option = null;

if (defMod != null && (defMod.FileSwaps.Count > 0 || defMod.Manipulations.Count > 0 || defMod.Files.Count > 0) && pmp.Groups.Count == 0)
// Default mod is always present, but may be void of any data
if (defMod != null && !defMod.IsEmptyOption)
{
// Valid Default Mod Option
option = defMod;
}
else

if (pmp.Groups.Count == 1)
{
if (pmp.Groups.Count == 1)
var group = pmp.Groups[0];
if (group.Options.Count == 1)
{
var group = pmp.Groups[0];
if (group.Options.Count == 1)
{
option = group.Options[0] as PmpStandardOptionJson;
}
else if (group.Options.Count > 1)
{
// The default option was already found to be valid, leaving us with two valid options
// Return null so it gets treated as a wizard modpack instead
if (option != null)
return null;
}
} else if(pmp.Groups.Count > 1)
option = group.Options[0] as PmpStandardOptionJson;
}
else if (group.Options.Count > 1)
{
return null;
}
} else if(pmp.Groups.Count > 1)
{
return null;
}

if (option == null)
@@ -1401,6 +1404,12 @@ public class PmpStandardOptionJson : PMPOptionJson
public Dictionary<string, string> FileSwaps;
public List<PMPManipulationWrapperJson> Manipulations;
public int Priority;

[JsonIgnore] public bool IsEmptyOption => !(
(FileSwaps != null && FileSwaps.Count > 0) ||
(Manipulations != null && Manipulations.Count > 0) ||
(Files != null && Files.Count > 0)
);
}

public class PmpDisableImcOptionJson : PMPOptionJson
38 changes: 17 additions & 21 deletions xivModdingFramework/Mods/WizardData.cs
Original file line number Diff line number Diff line change
@@ -1088,30 +1088,26 @@ public static async Task<WizardData> FromPmp(PMPJson pmp, string unzipPath)
data.ModPack = mp;
data.RawSource = pmp;

var def = pmp.DefaultMod as PmpStandardOptionJson;
if (def != null)
var defMod = pmp.DefaultMod as PmpStandardOptionJson;
if (defMod != null && !defMod.IsEmptyOption)
{
var anyData = (def.Manipulations != null && def.Manipulations.Count > 0) || def.FileSwaps.Count > 0 || def.Files.Count > 0;
if (anyData)
{
// Just drum up a basic group containing the default option.
var fakeGroup = new PMPGroupJson();
fakeGroup.Name = "Default";
fakeGroup.Options = new List<PMPOptionJson>() { pmp.DefaultMod };
fakeGroup.SelectedSettings = 1;
fakeGroup.Type = "Single";

if (string.IsNullOrWhiteSpace(pmp.DefaultMod.Name))
{
pmp.DefaultMod.Name = "Default";
}
// Just drum up a basic group containing the default option.
var fakeGroup = new PMPGroupJson();
fakeGroup.Name = "Default";
fakeGroup.Options = new List<PMPOptionJson>() { pmp.DefaultMod };
fakeGroup.SelectedSettings = 1;
fakeGroup.Type = "Single";

var page = new WizardPageEntry();
page.Name = "Page 1";
page.Groups = new List<WizardGroupEntry>();
page.Groups.Add(await WizardGroupEntry.FromPMPGroup(fakeGroup, unzipPath));
data.DataPages.Add(page);
if (string.IsNullOrWhiteSpace(pmp.DefaultMod.Name))
{
pmp.DefaultMod.Name = "Default";
}

var page = new WizardPageEntry();
page.Name = "Page 1";
page.Groups = new List<WizardGroupEntry>();
page.Groups.Add(await WizardGroupEntry.FromPMPGroup(fakeGroup, unzipPath));
data.DataPages.Add(page);
}

if (pmp.Groups.Count > 0)

0 comments on commit c763edc

Please sign in to comment.