mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 14:30:56 +00:00
Add ability to sideload key names
This commit is contained in:
parent
4f039fe732
commit
043ba3b6f0
2 changed files with 41 additions and 6 deletions
|
@ -10,17 +10,26 @@ namespace PKHeX.Core
|
||||||
private readonly List<string> TypesChanged = new List<string>();
|
private readonly List<string> TypesChanged = new List<string>();
|
||||||
private readonly List<string> ValueChanged = 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)
|
public SCBlockCompare(SCBlockAccessor s1, SCBlockAccessor s2)
|
||||||
{
|
{
|
||||||
var b1 = s1.BlockInfo;
|
var b1 = s1.BlockInfo;
|
||||||
var b2 = s2.BlockInfo;
|
var b2 = s2.BlockInfo;
|
||||||
var names = GetKeyNames(s1, b1, b2);
|
KeyNames = GetKeyNames(s1, b1, b2);
|
||||||
|
SCBlockMetadata.AddExtraKeyNames(KeyNames);
|
||||||
string GetKeyName(uint key) => names.TryGetValue(key, out var val) ? val : $"{key:X8}";
|
|
||||||
|
|
||||||
var hs1 = new HashSet<uint>(b1.Select(z => z.Key));
|
var hs1 = new HashSet<uint>(b1.Select(z => z.Key));
|
||||||
var hs2 = new HashSet<uint>(b2.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);
|
var unique = new HashSet<uint>(hs1);
|
||||||
unique.SymmetricExceptWith(hs2);
|
unique.SymmetricExceptWith(hs2);
|
||||||
foreach (var k in unique)
|
foreach (var k in unique)
|
||||||
|
@ -37,9 +46,11 @@ namespace PKHeX.Core
|
||||||
AddedKeys.Add($"{name} - {b.Type}");
|
AddedKeys.Add($"{name} - {b.Type}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hs1.IntersectWith(hs2);
|
private void LoadChanged(SCBlockAccessor s1, SCBlockAccessor s2, IEnumerable<uint> shared)
|
||||||
foreach (var k in hs1)
|
{
|
||||||
|
foreach (var k in shared)
|
||||||
{
|
{
|
||||||
var x1 = s1.GetBlock(k);
|
var x1 = s1.GetBlock(k);
|
||||||
var x2 = s2.GetBlock(k);
|
var x2 = s2.GetBlock(k);
|
||||||
|
@ -106,7 +117,7 @@ namespace PKHeX.Core
|
||||||
|
|
||||||
return result;
|
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)
|
if (list.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace PKHeX.Core
|
namespace PKHeX.Core
|
||||||
|
@ -20,6 +22,7 @@ namespace PKHeX.Core
|
||||||
|
|
||||||
BlockList = aType.GetAllPropertiesOfType<SaveBlock>(accessor);
|
BlockList = aType.GetAllPropertiesOfType<SaveBlock>(accessor);
|
||||||
ValueList = aType.GetAllConstantsOfType<uint>();
|
ValueList = aType.GetAllConstantsOfType<uint>();
|
||||||
|
AddExtraKeyNames(ValueList);
|
||||||
Accessor = accessor;
|
Accessor = accessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +35,27 @@ namespace PKHeX.Core
|
||||||
return list;
|
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)
|
private static string GetSortKey(in ComboItem item)
|
||||||
{
|
{
|
||||||
var text = item.Text;
|
var text = item.Text;
|
||||||
|
|
Loading…
Reference in a new issue