mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix default logic in 1G1R
This commit is contained in:
@@ -1970,12 +1970,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
// For sake of ease, the first thing we want to do is bucket by game
|
// For sake of ease, the first thing we want to do is bucket by game
|
||||||
datFile.Items.BucketBy(BucketedBy.Game, DedupeType.None, norename: true);
|
datFile.Items.BucketBy(BucketedBy.Game, DedupeType.None, norename: true);
|
||||||
|
|
||||||
// Then we want to get a mapping of all games to parents
|
// Then we want to get a mapping of all machines to parents
|
||||||
Dictionary<string, List<string>> parents = new Dictionary<string, List<string>>();
|
Dictionary<string, List<string>> parents = new Dictionary<string, List<string>>();
|
||||||
foreach (string key in datFile.Items.Keys)
|
foreach (string key in datFile.Items.Keys)
|
||||||
{
|
{
|
||||||
DatItem item = datFile.Items[key][0];
|
DatItem item = datFile.Items[key][0];
|
||||||
|
|
||||||
|
// Match on CloneOf first
|
||||||
if (!string.IsNullOrEmpty(item.CloneOf))
|
if (!string.IsNullOrEmpty(item.CloneOf))
|
||||||
{
|
{
|
||||||
if (!parents.ContainsKey(item.CloneOf.ToLowerInvariant()))
|
if (!parents.ContainsKey(item.CloneOf.ToLowerInvariant()))
|
||||||
@@ -1983,6 +1984,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
parents[item.CloneOf.ToLowerInvariant()].Add(item.MachineName.ToLowerInvariant());
|
parents[item.CloneOf.ToLowerInvariant()].Add(item.MachineName.ToLowerInvariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Then by RomOf
|
||||||
else if (!string.IsNullOrEmpty(item.RomOf))
|
else if (!string.IsNullOrEmpty(item.RomOf))
|
||||||
{
|
{
|
||||||
if (!parents.ContainsKey(item.RomOf.ToLowerInvariant()))
|
if (!parents.ContainsKey(item.RomOf.ToLowerInvariant()))
|
||||||
@@ -1990,6 +1993,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
parents[item.RomOf.ToLowerInvariant()].Add(item.MachineName.ToLowerInvariant());
|
parents[item.RomOf.ToLowerInvariant()].Add(item.MachineName.ToLowerInvariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Otherwise, treat it as a parent
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!parents.ContainsKey(item.MachineName.ToLowerInvariant()))
|
if (!parents.ContainsKey(item.MachineName.ToLowerInvariant()))
|
||||||
@@ -2004,44 +2009,27 @@ namespace SabreTools.Library.DatFiles
|
|||||||
if (regions == null)
|
if (regions == null)
|
||||||
regions = new List<string>();
|
regions = new List<string>();
|
||||||
|
|
||||||
// Once we have the full list of mappings, get a list of game names to keep
|
// Once we have the full list of mappings, filter out games to keep
|
||||||
List<string> keepMachines = new List<string>();
|
|
||||||
foreach (string key in parents.Keys)
|
foreach (string key in parents.Keys)
|
||||||
{
|
{
|
||||||
string keepMachine = null;
|
// Find the first machine that matches the regions in order, if possible
|
||||||
|
string machine = default;
|
||||||
// Loop over each region to see if we have a match first
|
|
||||||
foreach (string region in regions)
|
foreach (string region in regions)
|
||||||
{
|
{
|
||||||
// Loop over each machine to see if we have a region match
|
machine = parents[key].FirstOrDefault(m => Regex.IsMatch(m, @"\(.*" + region + @".*\)", RegexOptions.IgnoreCase));
|
||||||
foreach (string machine in parents[key])
|
if (machine != default)
|
||||||
{
|
|
||||||
if (Regex.IsMatch(machine, @"\(.*" + region + @".*\)", RegexOptions.IgnoreCase))
|
|
||||||
{
|
|
||||||
keepMachine = machine;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Break out further if we have something set
|
|
||||||
if (keepMachine != null)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we didn't match, use the parent by default
|
// If we didn't get a match, use the parent
|
||||||
if (keepMachine == null)
|
if (machine == default)
|
||||||
keepMachine = key;
|
machine = key;
|
||||||
|
|
||||||
keepMachines.Add(keepMachine);
|
// Remove the key from the list
|
||||||
}
|
parents[key].Remove(machine);
|
||||||
|
|
||||||
// Now that we have a list of machines to keep, weed out the ones that don't match
|
// Remove the rest of the items from this key
|
||||||
List<string> currentKeys = datFile.Items.Keys.ToList();
|
parents[key].ForEach(k => datFile.Items.Remove(k));
|
||||||
for (int i = 0; i < currentKeys.Count; i++)
|
|
||||||
{
|
|
||||||
string key = currentKeys[i];
|
|
||||||
if (!keepMachines.Contains(key))
|
|
||||||
datFile.Items.Remove(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, strip out the parent tags
|
// Finally, strip out the parent tags
|
||||||
|
|||||||
Reference in New Issue
Block a user