Add ability to sideload key names

This commit is contained in:
Kurt 2020-05-26 15:58:48 -07:00
parent 4f039fe732
commit 043ba3b6f0
2 changed files with 41 additions and 6 deletions

View file

@ -10,17 +10,26 @@ namespace PKHeX.Core
private readonly List<string> TypesChanged = new List<string>();
private readonly List<string> ValueChanged = new List<string>();
private readonly Dictionary<uint, string> KeyNames;
private string GetKeyName(uint key) => KeyNames.TryGetValue(key, out var val) ? val : $"{key:X8}";
public SCBlockCompare(SCBlockAccessor s1, SCBlockAccessor s2)
{
var b1 = s1.BlockInfo;
var b2 = s2.BlockInfo;
var names = GetKeyNames(s1, b1, b2);
string GetKeyName(uint key) => names.TryGetValue(key, out var val) ? val : $"{key:X8}";
KeyNames = GetKeyNames(s1, b1, b2);
SCBlockMetadata.AddExtraKeyNames(KeyNames);
var hs1 = new HashSet<uint>(b1.Select(z => z.Key));
var hs2 = new HashSet<uint>(b2.Select(z => z.Key));
LoadAddRemove(s1, s2, hs1, hs2);
hs1.IntersectWith(hs2);
LoadChanged(s1, s2, hs1);
}
private void LoadAddRemove(SCBlockAccessor s1, SCBlockAccessor s2, ICollection<uint> hs1, IEnumerable<uint> hs2)
{
var unique = new HashSet<uint>(hs1);
unique.SymmetricExceptWith(hs2);
foreach (var k in unique)
@ -37,9 +46,11 @@ namespace PKHeX.Core
AddedKeys.Add($"{name} - {b.Type}");
}
}
}
hs1.IntersectWith(hs2);
foreach (var k in hs1)
private void LoadChanged(SCBlockAccessor s1, SCBlockAccessor s2, IEnumerable<uint> shared)
{
foreach (var k in shared)
{
var x1 = s1.GetBlock(k);
var x2 = s2.GetBlock(k);
@ -106,7 +117,7 @@ namespace PKHeX.Core
return result;
static void AddIfPresent(List<string> result, IList<string> list, string hdr)
static void AddIfPresent(List<string> result, ICollection<string> list, string hdr)
{
if (list.Count == 0)
return;

View file

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
namespace PKHeX.Core
@ -20,6 +22,7 @@ namespace PKHeX.Core
BlockList = aType.GetAllPropertiesOfType<SaveBlock>(accessor);
ValueList = aType.GetAllConstantsOfType<uint>();
AddExtraKeyNames(ValueList);
Accessor = accessor;
}
@ -32,6 +35,27 @@ namespace PKHeX.Core
return list;
}
public static void AddExtraKeyNames(IDictionary<uint, string> names, string extra = "SCBlocks.txt")
{
if (!File.Exists(extra))
return;
var lines = File.ReadLines(extra);
foreach (var line in lines)
{
var split = line.IndexOf('\t');
if (split < 0)
continue;
var hex = line.Substring(0, split);
if (!ulong.TryParse(hex, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out var value))
continue;
var name = line.Substring(split + 1);
if (!names.ContainsKey((uint)value))
names[(uint)value] = name;
}
}
private static string GetSortKey(in ComboItem item)
{
var text = item.Text;