mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 05:04:15 +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()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
=> 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)
|
public bool TryAdd(ImcIdentifier identifier, ImcEntry entry)
|
||||||
{
|
{
|
||||||
if (!_imc.TryAdd(identifier, entry))
|
if (!_imc.TryAdd(identifier, entry))
|
||||||
|
|
@ -93,9 +61,29 @@ public sealed class MetaDictionary : IEnumerable<MetaManipulation>
|
||||||
return true;
|
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)
|
public bool TryAdd(EqpIdentifier identifier, EqpEntry entry)
|
||||||
=> TryAdd(identifier, new EqpEntryInternal(entry, identifier.Slot));
|
=> 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)
|
public bool TryAdd(EqdpIdentifier identifier, EqdpEntry entry)
|
||||||
=> TryAdd(identifier, new EqdpEntryInternal(entry, identifier.Slot));
|
=> TryAdd(identifier, new EqdpEntryInternal(entry, identifier.Slot));
|
||||||
|
|
||||||
|
|
@ -159,6 +147,73 @@ public sealed class MetaDictionary : IEnumerable<MetaManipulation>
|
||||||
TryAdd(identifier);
|
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)
|
public bool TryGetValue(EstIdentifier identifier, out EstEntry value)
|
||||||
=> _est.TryGetValue(identifier, out value);
|
=> _est.TryGetValue(identifier, out value);
|
||||||
|
|
||||||
|
|
@ -318,22 +373,4 @@ public sealed class MetaDictionary : IEnumerable<MetaManipulation>
|
||||||
return dict;
|
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()))
|
foreach (var swap in Swaps.SelectMany(s => s.WithChildren()))
|
||||||
{
|
{
|
||||||
switch (swap)
|
if (swap is FileSwap file)
|
||||||
{
|
{
|
||||||
case FileSwap file:
|
// Skip, nothing to do
|
||||||
// Skip, nothing to do
|
if (file.SwapToModdedEqualsOriginal)
|
||||||
if (file.SwapToModdedEqualsOriginal)
|
continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
if (writeType == WriteType.UseSwaps && file.SwapToModdedExistsInGame && !file.DataWasChanged)
|
if (writeType == WriteType.UseSwaps && file.SwapToModdedExistsInGame && !file.DataWasChanged)
|
||||||
{
|
{
|
||||||
convertedSwaps.TryAdd(file.SwapFromRequestPath, file.SwapToModded);
|
convertedSwaps.TryAdd(file.SwapFromRequestPath, file.SwapToModded);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var path = file.GetNewPath(directory.FullName);
|
var path = file.GetNewPath(directory.FullName);
|
||||||
var bytes = file.FileData.Write();
|
var bytes = file.FileData.Write();
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||||
_manager.Compactor.WriteAllBytes(path, bytes);
|
_manager.Compactor.WriteAllBytes(path, bytes);
|
||||||
convertedFiles.TryAdd(file.SwapFromRequestPath, new FullPath(path));
|
convertedFiles.TryAdd(file.SwapFromRequestPath, new FullPath(path));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
else if (swap is IMetaSwap { SwapAppliedIsDefault: false })
|
||||||
case IMetaSwap meta:
|
{
|
||||||
if (!meta.SwapAppliedIsDefault)
|
// @formatter:off
|
||||||
convertedManips.TryAdd(meta.SwapFromIdentifier, meta.SwapToModdedEntry);
|
_ = swap switch
|
||||||
|
{
|
||||||
break;
|
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>()!));
|
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)
|
if (manips != null)
|
||||||
foreach (var s in manips.Children().Select(c => c.ToObject<MetaManipulation>())
|
data.Manipulations.UnionWith(manips);
|
||||||
.Where(m => m.Validate()))
|
|
||||||
data.Manipulations.Add(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Load the relevant data for a selectable option from a JToken of that option. </summary>
|
/// <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>())
|
MetaDictionary manips = [.. collection.MetaCache?.Manipulations ?? []];
|
||||||
defaultMod.Manipulations.Add(manip);
|
defaultMod.Manipulations.UnionWith(manips);
|
||||||
|
|
||||||
saveService.ImmediateSave(new ModSaveGroup(dir, defaultMod, config.ReplaceNonAsciiOnImport));
|
saveService.ImmediateSave(new ModSaveGroup(dir, defaultMod, config.ReplaceNonAsciiOnImport));
|
||||||
modManager.AddMod(dir);
|
modManager.AddMod(dir);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue