Skip to content

Commit c763edc

Browse files
Import the 'default option' from PMP files with multiple options
1 parent 01df548 commit c763edc

File tree

2 files changed

+121
-116
lines changed

2 files changed

+121
-116
lines changed

xivModdingFramework/Mods/FileTypes/PMP.cs

Lines changed: 104 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -316,124 +316,124 @@ private static void ValidateOption(PmpStandardOptionJson op)
316316

317317
tx.ModPack = modPack;
318318

319-
if (pmp.Groups == null || pmp.Groups.Count == 0)
319+
var defMod = pmp.DefaultMod as PmpStandardOptionJson;
320+
321+
// Default option is always selected and always applied first, if it is present
322+
if (defMod != null && !defMod.IsEmptyOption)
320323
{
321-
// No options, just default.
322324
var groupRes = await ImportOption(pmp.DefaultMod, unzippedPath, tx, progress);
323325
UnionDict(imported, groupRes.Imported);
324326
notImported.UnionWith(groupRes.NotImported);
325327
}
326-
else
328+
329+
// Order groups by Priority, Lowest => Highest, tiebreaker default order
330+
var orderedGroups = pmp.Groups.OrderBy(x => x.Priority).ToList();
331+
var groupIdx = 0;
332+
foreach (var group in orderedGroups)
327333
{
328-
// Order groups by Priority, Lowest => Highest, tiebreaker default order
329-
var orderedGroups = pmp.Groups.OrderBy(x => x.Priority).ToList();
330-
var groupIdx = 0;
331-
foreach (var group in orderedGroups)
334+
if (group.Options == null || group.Options.Count == 0)
332335
{
333-
if (group.Options == null || group.Options.Count == 0)
334-
{
335-
// No valid options.
336-
groupIdx++;
337-
continue;
338-
}
339-
var optionIdx = 0;
336+
// No valid options.
337+
groupIdx++;
338+
continue;
339+
}
340+
var optionIdx = 0;
341+
342+
// Get Default selection.
343+
var selected = group.DefaultSettings;
340344

341-
// Get Default selection.
342-
var selected = group.DefaultSettings;
345+
// If the user selected custom settings, use those.
346+
if (group.SelectedSettings >= 0)
347+
{
348+
selected = group.SelectedSettings;
349+
}
343350

344-
// If the user selected custom settings, use those.
345-
if (group.SelectedSettings >= 0)
351+
if (group.Type == "Single")
352+
{
353+
if (selected < 0 || selected >= group.Options.Count)
346354
{
347-
selected = group.SelectedSettings;
355+
selected = 0;
348356
}
357+
var groupRes = await ImportOption(group.Options[selected], unzippedPath, tx, progress, groupIdx, optionIdx);
358+
UnionDict(imported, groupRes.Imported);
359+
notImported.UnionWith(groupRes.NotImported);
360+
}
361+
else if(group.Type == "Multi")
362+
{
363+
var ordered = group.Options.OrderBy(x => ((PmpStandardOptionJson)x).Priority).ToList();
349364

350-
if (group.Type == "Single")
365+
// Bitmask options. Install in priority order.
366+
foreach(var op in ordered)
351367
{
352-
if (selected < 0 || selected >= group.Options.Count)
368+
var i = group.Options.IndexOf(op);
369+
var value = 1 << i;
370+
if ((selected & value) > 0)
353371
{
354-
selected = 0;
372+
var groupRes = await ImportOption(group.Options[i], unzippedPath, tx, progress, groupIdx, optionIdx);
373+
UnionDict(imported, groupRes.Imported);
374+
notImported.UnionWith(groupRes.NotImported);
375+
optionIdx++;
355376
}
356-
var groupRes = await ImportOption(group.Options[selected], unzippedPath, tx, progress, groupIdx, optionIdx);
357-
UnionDict(imported, groupRes.Imported);
358-
notImported.UnionWith(groupRes.NotImported);
359377
}
360-
else if(group.Type == "Multi")
361-
{
362-
var ordered = group.Options.OrderBy(x => ((PmpStandardOptionJson)x).Priority).ToList();
363378

364-
// Bitmask options. Install in priority order.
365-
foreach(var op in ordered)
379+
} else if(group.Type == "Imc")
380+
{
381+
// Could do with popping this out to its own function.
382+
var imcGroup = group as PMPImcGroupJson;
383+
var xivImc = imcGroup.DefaultEntry.ToXivImc();
384+
385+
bool disabled = false;
386+
// Bitmask options.
387+
for (int i = 0; i < group.Options.Count; i++)
388+
{
389+
var value = 1 << i;
390+
if ((selected & value) > 0)
366391
{
367-
var i = group.Options.IndexOf(op);
368-
var value = 1 << i;
369-
if ((selected & value) > 0)
392+
var disableOpt = group.Options[i] as PmpDisableImcOptionJson;
393+
if (disableOpt != null)
370394
{
371-
var groupRes = await ImportOption(group.Options[i], unzippedPath, tx, progress, groupIdx, optionIdx);
372-
UnionDict(imported, groupRes.Imported);
373-
notImported.UnionWith(groupRes.NotImported);
374-
optionIdx++;
395+
// No options allowed >:|
396+
disabled = true;
397+
break;
375398
}
399+
400+
var opt = group.Options[i] as PmpImcOptionJson;
401+
optionIdx++;
402+
403+
xivImc.AttributeMask |= opt.AttributeMask;
376404
}
405+
}
377406

378-
} else if(group.Type == "Imc")
407+
if (!disabled)
379408
{
380-
// Could do with popping this out to its own function.
381-
var imcGroup = group as PMPImcGroupJson;
382-
var xivImc = imcGroup.DefaultEntry.ToXivImc();
383-
384-
bool disabled = false;
385-
// Bitmask options.
386-
for (int i = 0; i < group.Options.Count; i++)
409+
var root = imcGroup.GetRoot();
410+
var metaData = await GetImportMetadata(imported, root, tx);
411+
if (metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
387412
{
388-
var value = 1 << i;
389-
if ((selected & value) > 0)
413+
while(metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
390414
{
391-
var disableOpt = group.Options[i] as PmpDisableImcOptionJson;
392-
if (disableOpt != null)
393-
{
394-
// No options allowed >:|
395-
disabled = true;
396-
break;
397-
}
398-
399-
var opt = group.Options[i] as PmpImcOptionJson;
400-
optionIdx++;
401-
402-
xivImc.AttributeMask |= opt.AttributeMask;
415+
metaData.ImcEntries.Add((XivImc)xivImc.Clone());
403416
}
404417
}
405-
406-
if (!disabled)
418+
else
407419
{
408-
var root = imcGroup.GetRoot();
409-
var metaData = await GetImportMetadata(imported, root, tx);
410-
if (metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
411-
{
412-
while(metaData.ImcEntries.Count <= imcGroup.Identifier.Variant)
413-
{
414-
metaData.ImcEntries.Add((XivImc)xivImc.Clone());
415-
}
416-
}
417-
else
418-
{
419-
metaData.ImcEntries[(int)imcGroup.Identifier.Variant] = xivImc;
420-
}
420+
metaData.ImcEntries[(int)imcGroup.Identifier.Variant] = xivImc;
421+
}
421422

422-
if (imcGroup.AllVariants)
423+
if (imcGroup.AllVariants)
424+
{
425+
for (int i = 0; i < metaData.ImcEntries.Count; i++)
423426
{
424-
for (int i = 0; i < metaData.ImcEntries.Count; i++)
425-
{
426-
metaData.ImcEntries[i] = (XivImc)xivImc.Clone();
427-
}
427+
metaData.ImcEntries[i] = (XivImc)xivImc.Clone();
428428
}
429+
}
429430

430-
await ItemMetadata.SaveMetadata(metaData, _Source, tx);
431-
await ItemMetadata.ApplyMetadata(metaData, tx);
431+
await ItemMetadata.SaveMetadata(metaData, _Source, tx);
432+
await ItemMetadata.ApplyMetadata(metaData, tx);
432433

433-
}
434434
}
435-
groupIdx++;
436435
}
436+
groupIdx++;
437437
}
438438

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

913-
if (defMod != null && (defMod.FileSwaps.Count > 0 || defMod.Manipulations.Count > 0 || defMod.Files.Count > 0) && pmp.Groups.Count == 0)
913+
// Default mod is always present, but may be void of any data
914+
if (defMod != null && !defMod.IsEmptyOption)
914915
{
915916
// Valid Default Mod Option
916917
option = defMod;
917918
}
918-
else
919+
920+
if (pmp.Groups.Count == 1)
919921
{
920-
if (pmp.Groups.Count == 1)
922+
var group = pmp.Groups[0];
923+
if (group.Options.Count == 1)
921924
{
922-
var group = pmp.Groups[0];
923-
if (group.Options.Count == 1)
924-
{
925-
option = group.Options[0] as PmpStandardOptionJson;
926-
}
927-
else if (group.Options.Count > 1)
928-
{
925+
// The default option was already found to be valid, leaving us with two valid options
926+
// Return null so it gets treated as a wizard modpack instead
927+
if (option != null)
929928
return null;
930-
}
931-
} else if(pmp.Groups.Count > 1)
929+
option = group.Options[0] as PmpStandardOptionJson;
930+
}
931+
else if (group.Options.Count > 1)
932932
{
933933
return null;
934934
}
935+
} else if(pmp.Groups.Count > 1)
936+
{
937+
return null;
935938
}
936939

937940
if (option == null)
@@ -1401,6 +1404,12 @@ public class PmpStandardOptionJson : PMPOptionJson
14011404
public Dictionary<string, string> FileSwaps;
14021405
public List<PMPManipulationWrapperJson> Manipulations;
14031406
public int Priority;
1407+
1408+
[JsonIgnore] public bool IsEmptyOption => !(
1409+
(FileSwaps != null && FileSwaps.Count > 0) ||
1410+
(Manipulations != null && Manipulations.Count > 0) ||
1411+
(Files != null && Files.Count > 0)
1412+
);
14041413
}
14051414

14061415
public class PmpDisableImcOptionJson : PMPOptionJson

xivModdingFramework/Mods/WizardData.cs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,30 +1088,26 @@ public static async Task<WizardData> FromPmp(PMPJson pmp, string unzipPath)
10881088
data.ModPack = mp;
10891089
data.RawSource = pmp;
10901090

1091-
var def = pmp.DefaultMod as PmpStandardOptionJson;
1092-
if (def != null)
1091+
var defMod = pmp.DefaultMod as PmpStandardOptionJson;
1092+
if (defMod != null && !defMod.IsEmptyOption)
10931093
{
1094-
var anyData = (def.Manipulations != null && def.Manipulations.Count > 0) || def.FileSwaps.Count > 0 || def.Files.Count > 0;
1095-
if (anyData)
1096-
{
1097-
// Just drum up a basic group containing the default option.
1098-
var fakeGroup = new PMPGroupJson();
1099-
fakeGroup.Name = "Default";
1100-
fakeGroup.Options = new List<PMPOptionJson>() { pmp.DefaultMod };
1101-
fakeGroup.SelectedSettings = 1;
1102-
fakeGroup.Type = "Single";
1103-
1104-
if (string.IsNullOrWhiteSpace(pmp.DefaultMod.Name))
1105-
{
1106-
pmp.DefaultMod.Name = "Default";
1107-
}
1094+
// Just drum up a basic group containing the default option.
1095+
var fakeGroup = new PMPGroupJson();
1096+
fakeGroup.Name = "Default";
1097+
fakeGroup.Options = new List<PMPOptionJson>() { pmp.DefaultMod };
1098+
fakeGroup.SelectedSettings = 1;
1099+
fakeGroup.Type = "Single";
11081100

1109-
var page = new WizardPageEntry();
1110-
page.Name = "Page 1";
1111-
page.Groups = new List<WizardGroupEntry>();
1112-
page.Groups.Add(await WizardGroupEntry.FromPMPGroup(fakeGroup, unzipPath));
1113-
data.DataPages.Add(page);
1101+
if (string.IsNullOrWhiteSpace(pmp.DefaultMod.Name))
1102+
{
1103+
pmp.DefaultMod.Name = "Default";
11141104
}
1105+
1106+
var page = new WizardPageEntry();
1107+
page.Name = "Page 1";
1108+
page.Groups = new List<WizardGroupEntry>();
1109+
page.Groups.Add(await WizardGroupEntry.FromPMPGroup(fakeGroup, unzipPath));
1110+
data.DataPages.Add(page);
11151111
}
11161112

11171113
if (pmp.Groups.Count > 0)

0 commit comments

Comments
 (0)