Clean up memory generation parameter fetching

This commit is contained in:
Kurt 2021-08-25 19:45:47 -07:00
parent 0e2dac3ff6
commit 87a268fa7f
5 changed files with 25 additions and 22 deletions

View file

@ -14,7 +14,7 @@ namespace PKHeX.Core
{
private readonly GameStrings s;
public MemoryStrings(GameStrings strings, int format)
public MemoryStrings(GameStrings strings)
{
s = strings;
memories = new Lazy<List<ComboItem>>(GetMemories);
@ -27,9 +27,9 @@ namespace PKHeX.Core
specific = new Lazy<List<ComboItem>>(() => Util.GetCBList(s.metXY_00000, Legal.Met_XY_0));
}
private List<ComboItem> GetItems(int format)
private List<ComboItem> GetItems(int memoryGen)
{
var permit = Memories.GetMemoryItemParams(format);
var permit = Memories.GetMemoryItemParams(memoryGen);
var asInt = permit.Select(z => (int) z).ToArray();
return Util.GetCBList(s.itemlist, asInt);
}

View file

@ -16,12 +16,12 @@ namespace PKHeX.Core
private static readonly HashSet<int> MemoryItem = new() { 5, 15, 26, 34, 40, 51, 84, 88 };
private static readonly HashSet<int> MemorySpecies = new() { 7, 9, 13, 14, 17, 21, 18, 25, 29, 44, 45, 50, 60, 70, 71, 72, 75, 82, 83, 87 };
public static MemoryArgType GetMemoryArgType(int memory, int format)
public static MemoryArgType GetMemoryArgType(int memory, int memoryGen)
{
if (MemoryGeneral.Contains(memory)) return MemoryArgType.GeneralLocation;
if (MemorySpecific.Contains(memory))
{
if (format == 6)
if (memoryGen <= 7)
return MemoryArgType.SpecificLocation;
return MemoryArgType.GeneralLocation;
}
@ -33,12 +33,12 @@ namespace PKHeX.Core
return MemoryArgType.None;
}
public static MemoryContext GetContext(int format) => format switch
public static MemoryContext GetContext(int memoryGen) => memoryGen switch
{
6 or 7 => Memory6,
<=7 => Memory6,
_ => Memory8,
};
public static IEnumerable<ushort> GetMemoryItemParams(int format) => GetContext(format).GetMemoryItemParams();
public static IEnumerable<ushort> GetMemoryItemParams(int memoryGen) => GetContext(memoryGen).GetMemoryItemParams();
}
}

View file

@ -38,7 +38,7 @@ namespace PKHeX.Core
public override IEnumerable<ushort> GetMemoryItemParams() => Legal.HeldItem_AO.Distinct()
.Concat(GetKeyItemParams())
.Concat(Legal.TMHM_AO.Take(100).Select(z => (ushort)z))
.Where(z => z < Legal.MaxItemID_6_AO);
.Where(z => z <= Legal.MaxItemID_6_AO);
public override bool IsUsedKeyItemUnspecific(int item) => KeyItemUsableObserve6.Contains((ushort)item);
public override bool IsUsedKeyItemSpecific(int item, int species) => KeyItemMemoryArgsGen6.TryGetValue(species, out var value) && value.Contains((ushort)item);

View file

@ -12,7 +12,7 @@ namespace PKHeX.Core
public override IEnumerable<ushort> GetMemoryItemParams() => Legal.HeldItem_AO.Concat(Legal.HeldItems_SWSH).Distinct()
.Concat(GetKeyItemParams())
.Concat(Legal.TMHM_AO.Take(100).Select(z => (ushort)z))
.Where(z => z < Legal.MaxItemID_8_R2);
.Where(z => z <= Legal.MaxItemID_8_R2);
public override bool CanUseItemGeneric(int item) => true; // todo

View file

@ -14,7 +14,7 @@ namespace PKHeX.WinForms
InitializeComponent();
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
pkm = pk;
MemStrings = new MemoryStrings(GameInfo.Strings, pkm.Format);
MemStrings = new MemoryStrings(GameInfo.Strings);
PrevCountries = new[] { CB_Country0, CB_Country1, CB_Country2, CB_Country3, CB_Country4 };
PrevRegions = new[] { CB_Region0, CB_Region1, CB_Region2, CB_Region3, CB_Region4 };
string[] arguments = L_Arguments.Text.Split(new[] {" ; "}, StringSplitOptions.None);
@ -235,16 +235,19 @@ namespace PKHeX.WinForms
private void UpdateMemoryDisplay(object sender)
{
if (sender == CB_CTMemory)
if (sender == CB_OTMemory)
{
int memoryGen = pkm.Generation;
if (memoryGen < 0)
memoryGen = pkm.Format;
int memory = WinFormsUtil.GetIndex((ComboBox)sender);
var memIndex = Memories.GetMemoryArgType(memory, memoryGen);
var argvals = MemStrings.GetArgumentStrings(memIndex, memoryGen);
CB_CTVar.InitializeBinding();
CB_CTVar.DataSource = new BindingSource(argvals, null);
LCTV.Text = TextArgs.GetMemoryCategory(memIndex, pkm.Generation);
LCTV.Visible = CB_CTVar.Visible = CB_CTVar.Enabled = argvals.Count > 1;
CB_OTVar.InitializeBinding();
CB_OTVar.DataSource = new BindingSource(argvals, null);
LOTV.Text = TextArgs.GetMemoryCategory(memIndex, memoryGen);
LOTV.Visible = CB_OTVar.Visible = CB_OTVar.Enabled = argvals.Count > 1;
}
else
{
@ -252,10 +255,10 @@ namespace PKHeX.WinForms
int memory = WinFormsUtil.GetIndex((ComboBox)sender);
var memIndex = Memories.GetMemoryArgType(memory, memoryGen);
var argvals = MemStrings.GetArgumentStrings(memIndex, memoryGen);
CB_OTVar.InitializeBinding();
CB_OTVar.DataSource = new BindingSource(argvals, null);
LOTV.Text = TextArgs.GetMemoryCategory(memIndex, pkm.Format);
LOTV.Visible = CB_OTVar.Visible = CB_OTVar.Enabled = argvals.Count > 1;
CB_CTVar.InitializeBinding();
CB_CTVar.DataSource = new BindingSource(argvals, null);
LCTV.Text = TextArgs.GetMemoryCategory(memIndex, memoryGen);
LCTV.Visible = CB_CTVar.Visible = CB_CTVar.Enabled = argvals.Count > 1;
}
}
@ -381,10 +384,10 @@ namespace PKHeX.WinForms
if (!string.IsNullOrWhiteSpace(args[9])) Location = args[9] + ":";
}
public string GetMemoryCategory(MemoryArgType type, int format) => type switch
public string GetMemoryCategory(MemoryArgType type, int memoryGen) => type switch
{
MemoryArgType.GeneralLocation => Area,
MemoryArgType.SpecificLocation when format == 6 => Location,
MemoryArgType.SpecificLocation when memoryGen <= 7 => Location,
MemoryArgType.Species => Species,
MemoryArgType.Move => Move,
MemoryArgType.Item => Item,