mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Remove all usages of Add(MetaManipulation)
This commit is contained in:
parent
d9b63320f0
commit
196ca2ce39
4 changed files with 121 additions and 80 deletions
|
|
@ -52,38 +52,6 @@ public sealed class MetaDictionary : IEnumerable<MetaManipulation>
|
|||
IEnumerator IEnumerable.GetEnumerator()
|
||||
=> GetEnumerator();
|
||||
|
||||
public bool TryAdd(IMetaIdentifier identifier, object entry)
|
||||
=> identifier switch
|
||||
{
|
||||
EqdpIdentifier eqdpIdentifier => entry is EqdpEntryInternal e && TryAdd(eqdpIdentifier, e),
|
||||
EqpIdentifier eqpIdentifier => entry is EqpEntryInternal e && TryAdd(eqpIdentifier, e),
|
||||
EstIdentifier estIdentifier => entry is EstEntry e && TryAdd(estIdentifier, e),
|
||||
GlobalEqpManipulation globalEqpManipulation => TryAdd(globalEqpManipulation),
|
||||
GmpIdentifier gmpIdentifier => entry is GmpEntry e && TryAdd(gmpIdentifier, e),
|
||||
ImcIdentifier imcIdentifier => entry is ImcEntry e && TryAdd(imcIdentifier, e),
|
||||
RspIdentifier rspIdentifier => entry is RspEntry e && TryAdd(rspIdentifier, e),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
public bool Add(MetaManipulation manip)
|
||||
{
|
||||
var ret = manip.ManipulationType switch
|
||||
{
|
||||
MetaManipulation.Type.Imc => _imc.TryAdd(manip.Imc.Identifier, manip.Imc.Entry),
|
||||
MetaManipulation.Type.Eqdp => _eqdp.TryAdd(manip.Eqdp.Identifier, new EqdpEntryInternal(manip.Eqdp.Entry, manip.Eqdp.Slot)),
|
||||
MetaManipulation.Type.Eqp => _eqp.TryAdd(manip.Eqp.Identifier, new EqpEntryInternal(manip.Eqp.Entry, manip.Eqp.Slot)),
|
||||
MetaManipulation.Type.Est => _est.TryAdd(manip.Est.Identifier, manip.Est.Entry),
|
||||
MetaManipulation.Type.Gmp => _gmp.TryAdd(manip.Gmp.Identifier, manip.Gmp.Entry),
|
||||
MetaManipulation.Type.Rsp => _rsp.TryAdd(manip.Rsp.Identifier, manip.Rsp.Entry),
|
||||
MetaManipulation.Type.GlobalEqp => _globalEqp.Add(manip.GlobalEqp),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
if (ret)
|
||||
++Count;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool TryAdd(ImcIdentifier identifier, ImcEntry entry)
|
||||
{
|
||||
if (!_imc.TryAdd(identifier, entry))
|
||||
|
|
@ -93,9 +61,29 @@ public sealed class MetaDictionary : IEnumerable<MetaManipulation>
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
public bool TryAdd(EqpIdentifier identifier, EqpEntryInternal entry)
|
||||
{
|
||||
if (!_eqp.TryAdd(identifier, entry))
|
||||
return false;
|
||||
|
||||
++Count;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryAdd(EqpIdentifier identifier, EqpEntry entry)
|
||||
=> TryAdd(identifier, new EqpEntryInternal(entry, identifier.Slot));
|
||||
|
||||
|
||||
public bool TryAdd(EqdpIdentifier identifier, EqdpEntryInternal entry)
|
||||
{
|
||||
if (!_eqdp.TryAdd(identifier, entry))
|
||||
return false;
|
||||
|
||||
++Count;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryAdd(EqdpIdentifier identifier, EqdpEntry entry)
|
||||
=> TryAdd(identifier, new EqdpEntryInternal(entry, identifier.Slot));
|
||||
|
||||
|
|
@ -159,6 +147,73 @@ public sealed class MetaDictionary : IEnumerable<MetaManipulation>
|
|||
TryAdd(identifier);
|
||||
}
|
||||
|
||||
/// <summary> Try to merge all manipulations from manips into this, and return the first failure, if any. </summary>
|
||||
public bool MergeForced(MetaDictionary manips, out IMetaIdentifier failedIdentifier)
|
||||
{
|
||||
foreach (var (identifier, entry) in manips._imc)
|
||||
{
|
||||
if (!TryAdd(identifier, entry))
|
||||
{
|
||||
failedIdentifier = identifier;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (identifier, entry) in manips._eqp)
|
||||
{
|
||||
if (!TryAdd(identifier, entry))
|
||||
{
|
||||
failedIdentifier = identifier;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (identifier, entry) in manips._eqdp)
|
||||
{
|
||||
if (!TryAdd(identifier, entry))
|
||||
{
|
||||
failedIdentifier = identifier;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (identifier, entry) in manips._gmp)
|
||||
{
|
||||
if (!TryAdd(identifier, entry))
|
||||
{
|
||||
failedIdentifier = identifier;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (identifier, entry) in manips._rsp)
|
||||
{
|
||||
if (!TryAdd(identifier, entry))
|
||||
{
|
||||
failedIdentifier = identifier;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (identifier, entry) in manips._est)
|
||||
{
|
||||
if (!TryAdd(identifier, entry))
|
||||
{
|
||||
failedIdentifier = identifier;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var identifier in manips._globalEqp)
|
||||
{
|
||||
if (!TryAdd(identifier))
|
||||
{
|
||||
failedIdentifier = identifier;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetValue(EstIdentifier identifier, out EstEntry value)
|
||||
=> _est.TryGetValue(identifier, out value);
|
||||
|
||||
|
|
@ -318,22 +373,4 @@ public sealed class MetaDictionary : IEnumerable<MetaManipulation>
|
|||
return dict;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryAdd(EqpIdentifier identifier, EqpEntryInternal entry)
|
||||
{
|
||||
if (!_eqp.TryAdd(identifier, entry))
|
||||
return false;
|
||||
|
||||
++Count;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryAdd(EqdpIdentifier identifier, EqdpEntryInternal entry)
|
||||
{
|
||||
if (!_eqdp.TryAdd(identifier, entry))
|
||||
return false;
|
||||
|
||||
++Count;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,32 +53,38 @@ public class ItemSwapContainer
|
|||
{
|
||||
foreach (var swap in Swaps.SelectMany(s => s.WithChildren()))
|
||||
{
|
||||
switch (swap)
|
||||
if (swap is FileSwap file)
|
||||
{
|
||||
case FileSwap file:
|
||||
// Skip, nothing to do
|
||||
if (file.SwapToModdedEqualsOriginal)
|
||||
continue;
|
||||
// Skip, nothing to do
|
||||
if (file.SwapToModdedEqualsOriginal)
|
||||
continue;
|
||||
|
||||
if (writeType == WriteType.UseSwaps && file.SwapToModdedExistsInGame && !file.DataWasChanged)
|
||||
{
|
||||
convertedSwaps.TryAdd(file.SwapFromRequestPath, file.SwapToModded);
|
||||
}
|
||||
else
|
||||
{
|
||||
var path = file.GetNewPath(directory.FullName);
|
||||
var bytes = file.FileData.Write();
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
_manager.Compactor.WriteAllBytes(path, bytes);
|
||||
convertedFiles.TryAdd(file.SwapFromRequestPath, new FullPath(path));
|
||||
}
|
||||
|
||||
break;
|
||||
case IMetaSwap meta:
|
||||
if (!meta.SwapAppliedIsDefault)
|
||||
convertedManips.TryAdd(meta.SwapFromIdentifier, meta.SwapToModdedEntry);
|
||||
|
||||
break;
|
||||
if (writeType == WriteType.UseSwaps && file.SwapToModdedExistsInGame && !file.DataWasChanged)
|
||||
{
|
||||
convertedSwaps.TryAdd(file.SwapFromRequestPath, file.SwapToModded);
|
||||
}
|
||||
else
|
||||
{
|
||||
var path = file.GetNewPath(directory.FullName);
|
||||
var bytes = file.FileData.Write();
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
_manager.Compactor.WriteAllBytes(path, bytes);
|
||||
convertedFiles.TryAdd(file.SwapFromRequestPath, new FullPath(path));
|
||||
}
|
||||
}
|
||||
else if (swap is IMetaSwap { SwapAppliedIsDefault: false })
|
||||
{
|
||||
// @formatter:off
|
||||
_ = swap switch
|
||||
{
|
||||
MetaSwap<EstIdentifier, EstEntry> meta => convertedManips.TryAdd(meta.SwapFromIdentifier, meta.SwapToModdedEntry),
|
||||
MetaSwap<EqpIdentifier, EqpEntryInternal> meta => convertedManips.TryAdd(meta.SwapFromIdentifier, meta.SwapToModdedEntry),
|
||||
MetaSwap<EqdpIdentifier, EqdpEntryInternal> meta => convertedManips.TryAdd(meta.SwapFromIdentifier, meta.SwapToModdedEntry),
|
||||
MetaSwap<ImcIdentifier, ImcEntry>meta => convertedManips.TryAdd(meta.SwapFromIdentifier, meta.SwapToModdedEntry),
|
||||
MetaSwap<GmpIdentifier, GmpEntry>meta => convertedManips.TryAdd(meta.SwapFromIdentifier, meta.SwapToModdedEntry),
|
||||
_ => false,
|
||||
};
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,11 +64,9 @@ public static class SubMod
|
|||
data.FileSwaps.TryAdd(p, new FullPath(property.Value.ToObject<string>()!));
|
||||
}
|
||||
|
||||
var manips = json[nameof(data.Manipulations)];
|
||||
var manips = json[nameof(data.Manipulations)]?.ToObject<MetaDictionary>();
|
||||
if (manips != null)
|
||||
foreach (var s in manips.Children().Select(c => c.ToObject<MetaManipulation>())
|
||||
.Where(m => m.Validate()))
|
||||
data.Manipulations.Add(s);
|
||||
data.Manipulations.UnionWith(manips);
|
||||
}
|
||||
|
||||
/// <summary> Load the relevant data for a selectable option from a JToken of that option. </summary>
|
||||
|
|
|
|||
|
|
@ -93,8 +93,8 @@ public class TemporaryMod : IMod
|
|||
}
|
||||
}
|
||||
|
||||
foreach (var manip in collection.MetaCache?.Manipulations ?? Array.Empty<MetaManipulation>())
|
||||
defaultMod.Manipulations.Add(manip);
|
||||
MetaDictionary manips = [.. collection.MetaCache?.Manipulations ?? []];
|
||||
defaultMod.Manipulations.UnionWith(manips);
|
||||
|
||||
saveService.ImmediateSave(new ModSaveGroup(dir, defaultMod, config.ReplaceNonAsciiOnImport));
|
||||
modManager.AddMod(dir);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue