File scoped namespaces (#3529)

[Language Reference](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces)

Updates all the files, one less level of indentation.

Some small changes were made to API surfaces, renaming `PKM pkm` -> `PKM pk`, and `LegalityAnalysis.pkm` -> `LegalityAnalysis.Entity`
This commit is contained in:
Kurt 2022-06-18 11:04:24 -07:00 committed by GitHub
parent 78092e070d
commit fc754b346b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1124 changed files with 138713 additions and 139627 deletions

45
.editorconfig Normal file
View file

@ -0,0 +1,45 @@
root = true
# All Files
[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
# Solution Files
[*.sln]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
# XML Project Files
[*.csproj]
indent_style = space
indent_size = 2
# Code Files
[*.cs]
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
tab_width = 4
end_of_line = crlf
csharp_prefer_braces = when_multiline:warning
dotnet_diagnostic.IDE0047.severity = none
dotnet_diagnostic.IDE0048.severity = none
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggest
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggest
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggest
dotnet_style_parentheses_in_other_operators = always_for_clarity:suggest
[*.{cs,vb}]
#### Naming styles ####
# Naming styles
dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.capitalization = pascal_case

View file

@ -3,24 +3,24 @@ using System.Collections.Generic;
using System.Linq;
using static PKHeX.Core.Ball;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Contains logic to apply a new <see cref="Ball"/> value to a <see cref="PKM"/>.
/// </summary>
public static class BallApplicator
{
/// <summary>
/// Contains logic to apply a new <see cref="Ball"/> value to a <see cref="PKM"/>.
/// </summary>
public static class BallApplicator
{
/// <summary>
/// Gets all balls that are legal for the input <see cref="PKM"/>.
/// </summary>
/// <remarks>
/// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried.
/// </remarks>
/// <param name="pkm">Pokémon to retrieve a list of valid balls for.</param>
/// <param name="pk">Pokémon to retrieve a list of valid balls for.</param>
/// <returns>Enumerable list of <see cref="Ball"/> values that the <see cref="PKM"/> is legal with.</returns>
public static IEnumerable<Ball> GetLegalBalls(PKM pkm)
public static IEnumerable<Ball> GetLegalBalls(PKM pk)
{
var clone = pkm.Clone();
var clone = pk.Clone();
foreach (var b in BallList)
{
clone.Ball = (int)b;
@ -35,12 +35,12 @@ namespace PKHeX.Core
/// <remarks>
/// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried.
/// </remarks>
/// <param name="pkm">Pokémon to modify.</param>
public static int ApplyBallLegalRandom(PKM pkm)
/// <param name="pk">Pokémon to modify.</param>
public static int ApplyBallLegalRandom(PKM pk)
{
var balls = GetBallListFromColor(pkm).ToArray();
var balls = GetBallListFromColor(pk).ToArray();
Util.Shuffle(balls.AsSpan());
return ApplyFirstLegalBall(pkm, balls);
return ApplyFirstLegalBall(pk, balls);
}
/// <summary>
@ -49,33 +49,33 @@ namespace PKHeX.Core
/// <remarks>
/// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried.
/// </remarks>
/// <param name="pkm">Pokémon to modify.</param>
public static int ApplyBallLegalByColor(PKM pkm)
/// <param name="pk">Pokémon to modify.</param>
public static int ApplyBallLegalByColor(PKM pk)
{
var balls = GetBallListFromColor(pkm);
return ApplyFirstLegalBall(pkm, balls);
var balls = GetBallListFromColor(pk);
return ApplyFirstLegalBall(pk, balls);
}
/// <summary>
/// Applies a random ball value in a cyclical manner.
/// </summary>
/// <param name="pkm">Pokémon to modify.</param>
public static int ApplyBallNext(PKM pkm)
/// <param name="pk">Pokémon to modify.</param>
public static int ApplyBallNext(PKM pk)
{
var balls = GetBallList(pkm.Ball);
var balls = GetBallList(pk.Ball);
var next = balls.First();
return pkm.Ball = (int)next;
return pk.Ball = (int)next;
}
private static int ApplyFirstLegalBall(PKM pkm, IEnumerable<Ball> balls)
private static int ApplyFirstLegalBall(PKM pk, IEnumerable<Ball> balls)
{
foreach (var b in balls)
{
pkm.Ball = (int)b;
if (new LegalityAnalysis(pkm).Valid)
pk.Ball = (int)b;
if (new LegalityAnalysis(pk).Valid)
break;
}
return pkm.Ball;
return pk.Ball;
}
private static IEnumerable<Ball> GetBallList(int ball)
@ -85,13 +85,13 @@ namespace PKHeX.Core
return GetCircularOnce(balls, currentBall);
}
private static IEnumerable<Ball> GetBallListFromColor(PKM pkm)
private static IEnumerable<Ball> GetBallListFromColor(PKM pk)
{
// Gen1/2 don't store color in personal info
var pi = pkm.Format >= 3 ? pkm.PersonalInfo : PersonalTable.USUM.GetFormEntry(pkm.Species, 0);
var pi = pk.Format >= 3 ? pk.PersonalInfo : PersonalTable.USUM.GetFormEntry(pk.Species, 0);
var color = (PersonalColor)pi.Color;
var balls = BallColors[color];
var currentBall = (Ball)pkm.Ball;
var currentBall = (Ball)pk.Ball;
return GetCircularOnce(balls, currentBall);
}
@ -158,5 +158,4 @@ namespace PKHeX.Core
White,
Pink,
}
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for applying a <see cref="PK1.Catch_Rate"/> value.
/// </summary>
public static class CatchRateApplicator
{
/// <summary>
/// Logic for applying a <see cref="PK1.Catch_Rate"/> value.
/// </summary>
public static class CatchRateApplicator
{
public static int GetSuggestedCatchRate(PK1 pk1, SaveFile sav)
{
var la = new LegalityAnalysis(pk1);
@ -36,5 +36,4 @@
}
}
}
}
}

View file

@ -1,9 +1,9 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
public static class GenderApplicator
{
public static class GenderApplicator
{
/// <summary>
/// Sets the <see cref="PKM.Gender"/> value, with special consideration for the <see cref="PKM.Format"/> values which derive the <see cref="PKM.Gender"/> value.
/// </summary>
@ -72,5 +72,4 @@ namespace PKHeX.Core
while (pk.Gender != gender)
pk.IV_ATK = rnd.Next(16);
}
}
}

View file

@ -1,9 +1,9 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
public static class HiddenPowerApplicator
{
public static class HiddenPowerApplicator
{
/// <summary>
/// Sets the <see cref="PKM.IVs"/> to match a provided <see cref="hiddenPowerType"/>.
/// </summary>
@ -23,5 +23,4 @@ namespace PKHeX.Core
/// <param name="pk">Pokémon to modify.</param>
/// <param name="hiddenPowerType">Desired Hidden Power typing.</param>
public static void SetHiddenPower(this PKM pk, MoveType hiddenPowerType) => pk.SetHiddenPower((int)hiddenPowerType);
}
}

View file

@ -1,12 +1,12 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for modifying the <see cref="PKM.MarkValue"/>.
/// </summary>
public static class MarkingApplicator
{
/// <summary>
/// Logic for modifying the <see cref="PKM.MarkValue"/>.
/// </summary>
public static class MarkingApplicator
{
/// <summary>
/// Default <see cref="MarkingMethod"/> when applying markings.
/// </summary>
@ -65,5 +65,4 @@ namespace PKHeX.Core
_ => 0,
};
}
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for modifying the Memory parameters of a <see cref="PKM"/>.
/// </summary>
public static class MemoryApplicator
{
/// <summary>
/// Logic for modifying the Memory parameters of a <see cref="PKM"/>.
/// </summary>
public static class MemoryApplicator
{
/// <summary>
/// Sets all Memory related data to the default value (zero).
/// </summary>
@ -47,5 +47,4 @@
pk.OT_Intensity = 6;
pk.OT_Feeling = MemoryContext6.GetRandomFeeling6(pk.OT_Memory);
}
}
}

View file

@ -1,12 +1,12 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for applying a moveset to a <see cref="PKM"/>.
/// </summary>
public static class MoveApplicator
{
/// <summary>
/// Logic for applying a moveset to a <see cref="PKM"/>.
/// </summary>
public static class MoveApplicator
{
/// <summary>
/// Sets the individual PP Up count values depending if a Move is present in the move's slot or not.
/// </summary>
@ -75,5 +75,4 @@ namespace PKHeX.Core
/// <param name="pk">Pokémon to modify.</param>
/// <param name="index">Move PP to refresh.</param>
public static void SetSuggestedMovePP(this PKM pk, int index) => pk.HealPPIndex(index);
}
}

View file

@ -2,13 +2,13 @@
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for getting valid movesets.
/// </summary>
public static class MoveSetApplicator
{
/// <summary>
/// Logic for getting valid movesets.
/// </summary>
public static class MoveSetApplicator
{
/// <summary>
/// Gets a moveset for the provided <see cref="PKM"/> data.
/// </summary>
@ -46,7 +46,7 @@ namespace PKHeX.Core
if (!m.All(z => learn.Contains(z)))
m = m.Intersect(learn).ToArray();
if (random && !la.pkm.IsEgg)
if (random && !la.Entity.IsEgg)
Util.Shuffle(m.AsSpan());
const int count = 4;
@ -88,7 +88,7 @@ namespace PKHeX.Core
if (!moves[i].ShouldBeInRelearnMoves())
continue;
var move = legal.pkm.GetMove(i);
var move = legal.Entity.GetMove(i);
if (dn.CanBeDexNavMove(move))
return new[] { move, 0, 0, 0 };
}
@ -102,7 +102,7 @@ namespace PKHeX.Core
if (!moves[i].ShouldBeInRelearnMoves())
continue;
var move = legal.pkm.GetMove(i);
var move = legal.Entity.GetMove(i);
if (ug.CanBeUndergroundMove(move))
return new[] { move, 0, 0, 0 };
}
@ -111,11 +111,10 @@ namespace PKHeX.Core
return new[] { any, 0, 0, 0 };
}
var encounter = EncounterSuggestion.GetSuggestedMetInfo(legal.pkm);
var encounter = EncounterSuggestion.GetSuggestedMetInfo(legal.Entity);
if (encounter is IRelearn {Relearn: {Count: > 0} r})
return r;
return m;
}
}
}

View file

@ -1,82 +1,83 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for applying ribbons.
/// </summary>
public static class RibbonApplicator
{
/// <summary>
/// Logic for applying ribbons.
/// </summary>
public static class RibbonApplicator
{
private static List<string> GetAllRibbonNames(PKM pkm) => RibbonInfo.GetRibbonInfo(pkm).Select(z => z.Name).ToList();
private static List<string> GetAllRibbonNames(PKM pk) => RibbonInfo.GetRibbonInfo(pk).Select(z => z.Name).ToList();
/// <summary>
/// Gets a list of valid ribbons for the <see cref="pkm"/>.
/// Gets a list of valid ribbons for the <see cref="pk"/>.
/// </summary>
/// <param name="pkm">Entity to fetch the list for.</param>
/// <param name="pk">Entity to fetch the list for.</param>
/// <param name="allRibbons">All ribbon names.</param>
/// <returns>List of all valid ribbon names.</returns>
public static IReadOnlyList<string> GetValidRibbons(PKM pkm, IList<string> allRibbons)
public static IReadOnlyList<string> GetValidRibbons(PKM pk, IList<string> allRibbons)
{
var pk = pkm.Clone();
return SetAllValidRibbons(allRibbons, pk);
var clone = pk.Clone();
return SetAllValidRibbons(allRibbons, clone);
}
/// <summary>
/// Gets a list of valid ribbons for the <see cref="pkm"/>.
/// Gets a list of valid ribbons for the <see cref="pk"/>.
/// </summary>
/// <param name="pkm">Entity to fetch the list for.</param>
/// <param name="pk">Entity to fetch the list for.</param>
/// <returns>List of all valid ribbon names.</returns>
public static IReadOnlyList<string> GetValidRibbons(PKM pkm)
public static IReadOnlyList<string> GetValidRibbons(PKM pk)
{
var names = GetAllRibbonNames(pkm);
return GetValidRibbons(pkm, names);
var names = GetAllRibbonNames(pk);
return GetValidRibbons(pk, names);
}
/// <summary>
/// Gets a list of valid ribbons for the <see cref="pkm"/> that can be removed.
/// Gets a list of valid ribbons for the <see cref="pk"/> that can be removed.
/// </summary>
/// <param name="pkm">Entity to fetch the list for.</param>
/// <param name="pk">Entity to fetch the list for.</param>
/// <param name="allRibbons">All ribbon names.</param>
/// <returns>List of all removable ribbon names.</returns>
public static IReadOnlyList<string> GetRemovableRibbons(PKM pkm, IList<string> allRibbons)
public static IReadOnlyList<string> GetRemovableRibbons(PKM pk, IList<string> allRibbons)
{
var pk = pkm.Clone();
return RemoveAllValidRibbons(allRibbons, pk);
var clone = pk.Clone();
return RemoveAllValidRibbons(allRibbons, clone);
}
/// <summary>
/// Gets a list of valid ribbons for the <see cref="pkm"/> that can be removed.
/// Gets a list of valid ribbons for the <see cref="pk"/> that can be removed.
/// </summary>
/// <param name="pkm">Entity to fetch the list for.</param>
/// <param name="pk">Entity to fetch the list for.</param>
/// <returns>List of all removable ribbon names.</returns>
public static IReadOnlyList<string> GetRemovableRibbons(PKM pkm)
public static IReadOnlyList<string> GetRemovableRibbons(PKM pk)
{
var names = GetAllRibbonNames(pkm);
return GetRemovableRibbons(pkm, names);
var names = GetAllRibbonNames(pk);
return GetRemovableRibbons(pk, names);
}
/// <summary>
/// Sets all valid ribbons to the <see cref="pkm"/>.
/// Sets all valid ribbons to the <see cref="pk"/>.
/// </summary>
/// <param name="pkm">Entity to set ribbons for.</param>
/// <param name="pk">Entity to set ribbons for.</param>
/// <returns>True if any ribbons were applied.</returns>
public static bool SetAllValidRibbons(PKM pkm)
public static bool SetAllValidRibbons(PKM pk)
{
var ribNames = GetAllRibbonNames(pkm);
ribNames.RemoveAll(z => z.StartsWith("RibbonMark")); // until marking legality is handled
return SetAllValidRibbons(pkm, ribNames);
var ribNames = GetAllRibbonNames(pk);
ribNames.RemoveAll(z => z.StartsWith("RibbonMark", StringComparison.Ordinal)); // until marking legality is handled
return SetAllValidRibbons(pk, ribNames);
}
/// <summary>
/// Sets all valid ribbons to the <see cref="pkm"/>.
/// Sets all valid ribbons to the <see cref="pk"/>.
/// </summary>
/// <param name="pkm">Entity to set ribbons for.</param>
/// <param name="pk">Entity to set ribbons for.</param>
/// <param name="ribNames">Ribbon names to try setting.</param>
/// <returns>True if any ribbons were applied.</returns>
public static bool SetAllValidRibbons(PKM pkm, List<string> ribNames)
public static bool SetAllValidRibbons(PKM pk, List<string> ribNames)
{
var list = SetAllValidRibbons(ribNames, pkm);
var list = SetAllValidRibbons(ribNames, pk);
return list.Count != 0;
}
@ -98,25 +99,25 @@ namespace PKHeX.Core
}
/// <summary>
/// Sets all valid ribbons to the <see cref="pkm"/>.
/// Sets all valid ribbons to the <see cref="pk"/>.
/// </summary>
/// <param name="pkm">Entity to set ribbons for.</param>
/// <param name="pk">Entity to set ribbons for.</param>
/// <returns>True if any ribbons were removed.</returns>
public static bool RemoveAllValidRibbons(PKM pkm)
public static bool RemoveAllValidRibbons(PKM pk)
{
var ribNames = GetAllRibbonNames(pkm);
return RemoveAllValidRibbons(pkm, ribNames);
var ribNames = GetAllRibbonNames(pk);
return RemoveAllValidRibbons(pk, ribNames);
}
/// <summary>
/// Sets all valid ribbons to the <see cref="pkm"/>.
/// Sets all valid ribbons to the <see cref="pk"/>.
/// </summary>
/// <param name="pkm">Entity to set ribbons for.</param>
/// <param name="pk">Entity to set ribbons for.</param>
/// <param name="ribNames">Ribbon names to try setting.</param>
/// <returns>True if any ribbons were removed.</returns>
public static bool RemoveAllValidRibbons(PKM pkm, List<string> ribNames)
public static bool RemoveAllValidRibbons(PKM pk, List<string> ribNames)
{
var list = RemoveAllValidRibbons(ribNames, pkm);
var list = RemoveAllValidRibbons(ribNames, pk);
return list.Count != 0;
}
@ -216,7 +217,7 @@ namespace PKHeX.Core
ReflectUtil.SetValue(pk, rib, value * (pk.Gen4 ? 20 : 40));
break;
default:
if (rib.StartsWith("RibbonCountG3"))
if (rib.StartsWith("RibbonCountG3", StringComparison.Ordinal))
ReflectUtil.SetValue(pk, rib, value * 4);
else
ReflectUtil.SetValue(pk, rib, value != 0);
@ -237,5 +238,4 @@ namespace PKHeX.Core
if (!result)
c6.RibbonMasterToughness = c6.RibbonContestStar = !desiredState;
}
}
}

View file

@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for modifying the Technical Record flags of a <see cref="PK8"/>.
/// </summary>
public static class TechnicalRecordApplicator
{
/// <summary>
/// Logic for modifying the Technical Record flags of a <see cref="PK8"/>.
/// </summary>
public static class TechnicalRecordApplicator
{
/// <summary>
/// Sets the Technical Record flags for the <see cref="pk"/>.
/// </summary>
@ -61,5 +61,4 @@ namespace PKHeX.Core
pk.SetMoveRecordFlag(i, true);
}
}
}
}

View file

@ -1,21 +1,20 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using static PKHeX.Core.MessageStrings;
using static PKHeX.Core.BatchModifications;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for editing many <see cref="PKM"/> with user provided <see cref="StringInstruction"/> list.
/// </summary>
public static class BatchEditing
{
/// <summary>
/// Logic for editing many <see cref="PKM"/> with user provided <see cref="StringInstruction"/> list.
/// </summary>
public static class BatchEditing
{
public static readonly Type[] Types =
{
typeof (PK8), typeof (PA8), typeof (PB8),
@ -67,7 +66,8 @@ namespace PKHeX.Core
internal const string CONST_SHINY = "$shiny";
internal const string CONST_SUGGEST = "$suggest";
private const string CONST_BYTES = "$[]";
private const string CONST_POINTER = "*";
private const char CONST_POINTER = '*';
internal const char CONST_SPECIAL = '$';
internal const string PROP_LEGAL = "Legal";
internal const string PROP_TYPENAME = "ObjectType";
@ -187,7 +187,7 @@ namespace PKHeX.Core
foreach (var i in il.Where(i => !i.PropertyValue.All(char.IsDigit)))
{
string pv = i.PropertyValue;
if (pv.StartsWith("$") && !pv.StartsWith(CONST_BYTES) && pv.Contains(','))
if (pv.StartsWith(CONST_SPECIAL) && !pv.StartsWith(CONST_BYTES, StringComparison.Ordinal) && pv.Contains(','))
i.SetRandRange(pv);
SetInstructionScreenedValue(i);
@ -351,10 +351,10 @@ namespace PKHeX.Core
private static ModifyResult SetPKMProperty(StringInstruction cmd, BatchInfo info, IReadOnlyDictionary<string, PropertyInfo> props)
{
var pk = info.Entity;
if (cmd.PropertyValue.StartsWith(CONST_BYTES))
if (cmd.PropertyValue.StartsWith(CONST_BYTES, StringComparison.Ordinal))
return SetByteArrayProperty(pk, cmd);
if (cmd.PropertyValue.StartsWith(CONST_SUGGEST, true, CultureInfo.CurrentCulture))
if (cmd.PropertyValue.StartsWith(CONST_SUGGEST, StringComparison.OrdinalIgnoreCase))
return SetSuggestedPKMProperty(cmd.PropertyName, info, cmd.PropertyValue);
if (cmd.PropertyValue == CONST_RAND && cmd.PropertyName == nameof(PKM.Moves))
return SetMoves(pk, info.Legality.GetMoveSet(true));
@ -470,7 +470,7 @@ namespace PKHeX.Core
/// <returns>True if modified, false if no modifications done.</returns>
private static bool SetComplexProperty(PKM pk, StringInstruction cmd)
{
if (cmd.PropertyName.StartsWith("IV") && cmd.PropertyValue == CONST_RAND)
if (cmd.PropertyName.StartsWith("IV", StringComparison.Ordinal) && cmd.PropertyValue == CONST_RAND)
{
SetRandomIVs(pk, cmd);
return true;
@ -500,5 +500,4 @@ namespace PKHeX.Core
if (TryGetHasProperty(pk, cmd.PropertyName, out var pi))
ReflectUtil.SetValue(pi, pk, Util.Rand.Next(pk.MaxIV + 1));
}
}
}

View file

@ -4,13 +4,13 @@ using System.Diagnostics;
using System.Linq;
using static PKHeX.Core.MessageStrings;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Carries out a batch edit and contains information summarizing the results.
/// </summary>
public sealed class BatchEditor
{
/// <summary>
/// Carries out a batch edit and contains information summarizing the results.
/// </summary>
public sealed class BatchEditor
{
private int Modified { get; set; }
private int Iterated { get; set; }
private int Failed { get; set; }
@ -18,15 +18,15 @@ namespace PKHeX.Core
/// <summary>
/// Tries to modify the <see cref="PKM"/>.
/// </summary>
/// <param name="pkm">Object to modify.</param>
/// <param name="pk">Object to modify.</param>
/// <param name="filters">Filters which must be satisfied prior to any modifications being made.</param>
/// <param name="modifications">Modifications to perform on the <see cref="pkm"/>.</param>
/// <param name="modifications">Modifications to perform on the <see cref="pk"/>.</param>
/// <returns>Result of the attempted modification.</returns>
public bool Process(PKM pkm, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications)
public bool Process(PKM pk, IEnumerable<StringInstruction> filters, IEnumerable<StringInstruction> modifications)
{
if (pkm.Species <= 0)
if (pk.Species <= 0)
return false;
if (!pkm.Valid)
if (!pk.Valid)
{
Iterated++;
const string reason = "Not Valid.";
@ -34,7 +34,7 @@ namespace PKHeX.Core
return false;
}
var result = BatchEditing.TryModifyPKM(pkm, filters, modifications);
var result = BatchEditing.TryModifyPKM(pk, filters, modifications);
if (result != ModifyResult.Invalid)
Iterated++;
if (result == ModifyResult.Error)
@ -42,7 +42,7 @@ namespace PKHeX.Core
if (result != ModifyResult.Modified)
return false;
pkm.RefreshChecksum();
pk.RefreshChecksum();
Modified++;
return true;
}
@ -82,5 +82,4 @@ namespace PKHeX.Core
{
++Iterated;
}
}
}

View file

@ -1,18 +1,18 @@
using System.Collections.Generic;
using System.Collections.Generic;
using static PKHeX.Core.BatchEditing;
namespace PKHeX.Core
namespace PKHeX.Core;
public static class BatchFilters
{
public static class BatchFilters
{
public static readonly List<IComplexFilter> FilterMods = new()
{
new ComplexFilter(PROP_LEGAL,
(pkm, cmd) => bool.TryParse(cmd.PropertyValue, out var b) && (b == new LegalityAnalysis(pkm).Valid) == cmd.Evaluator,
(pk, cmd) => bool.TryParse(cmd.PropertyValue, out var b) && (b == new LegalityAnalysis(pk).Valid) == cmd.Evaluator,
(info, cmd) => bool.TryParse(cmd.PropertyValue, out var b) && (b == info.Legality.Valid) == cmd.Evaluator),
new ComplexFilter(PROP_TYPENAME,
(pkm, cmd) => (pkm.GetType().Name == cmd.PropertyValue) == cmd.Evaluator,
(pk, cmd) => (pk.GetType().Name == cmd.PropertyValue) == cmd.Evaluator,
(info, cmd) => (info.Entity.GetType().Name == cmd.PropertyValue) == cmd.Evaluator),
};
@ -27,5 +27,4 @@ namespace PKHeX.Core
new MetaFilter(nameof(ISlotInfo.Slot),
(obj, cmd) => obj is SlotCache s && int.TryParse(cmd.PropertyValue, out var slot) && s.Source.Slot + 1 == slot),
};
}
}

View file

@ -1,12 +1,12 @@
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Information wrapper used for Batch Editing to apply suggested values.
/// </summary>
public sealed class BatchInfo
{
/// <summary>
/// Information wrapper used for Batch Editing to apply suggested values.
/// </summary>
public sealed class BatchInfo
{
internal PKM Entity { get; }
internal BatchInfo(PKM pk) => Entity = pk;
@ -15,5 +15,4 @@ namespace PKHeX.Core
public bool Legal => Legality.Valid;
internal IReadOnlyList<int> SuggestedRelearn => Legality.GetSuggestedRelearnMoves();
}
}

View file

@ -3,10 +3,10 @@ using System.Collections.Generic;
using System.Globalization;
using static PKHeX.Core.BatchEditing;
namespace PKHeX.Core
namespace PKHeX.Core;
public static class BatchMods
{
public static class BatchMods
{
public static readonly List<ISuggestModification> SuggestionMods = new()
{
// Interface Specific
@ -60,8 +60,8 @@ namespace PKHeX.Core
new ComplexSet(nameof(PKM.PID), value => value == nameof(PKM.EncryptionConstant), (pk, _) => pk.PID = pk.EncryptionConstant),
// Realign to Derived Value
new ComplexSet(nameof(PKM.Ability), value => value.StartsWith("$"), (pk, cmd) => pk.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30)),
new ComplexSet(nameof(PKM.AbilityNumber), value => value.StartsWith("$"), (pk, cmd) => pk.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30)),
new ComplexSet(nameof(PKM.Ability), value => value.StartsWith(CONST_SPECIAL), (pk, cmd) => pk.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30)),
new ComplexSet(nameof(PKM.AbilityNumber), value => value.StartsWith(CONST_SPECIAL), (pk, cmd) => pk.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30)),
// Random
new ComplexSet(nameof(PKM.EncryptionConstant), value => value == CONST_RAND, (pk, _) => pk.EncryptionConstant = Util.Rand32()),
@ -85,13 +85,12 @@ namespace PKHeX.Core
pk.SetEVs(evs);
}
private static Shiny GetRequestedShinyState(string text)
private static Shiny GetRequestedShinyState(string text) => text.Length == 0 ? Shiny.Random : GetRequestedShinyState(text[^1]);
private static Shiny GetRequestedShinyState(char last) => last switch
{
if (text.EndsWith("0"))
return Shiny.AlwaysSquare;
if (text.EndsWith("1"))
return Shiny.AlwaysStar;
return Shiny.Random;
}
}
'0' => Shiny.AlwaysSquare,
'1' => Shiny.AlwaysStar,
_ => Shiny.Random,
};
}

View file

@ -1,10 +1,10 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <inheritdoc cref="IComplexFilter"/>
public sealed class ComplexFilter : IComplexFilter
{
/// <inheritdoc cref="IComplexFilter"/>
public sealed class ComplexFilter : IComplexFilter
{
private readonly string Property;
private readonly Func<PKM, StringInstruction, bool> FilterPKM;
private readonly Func<BatchInfo, StringInstruction, bool> FilterBulk;
@ -20,7 +20,6 @@ namespace PKHeX.Core
}
public bool IsMatch(string prop) => prop == Property;
public bool IsFiltered(PKM pkm, StringInstruction cmd) => FilterPKM(pkm, cmd);
public bool IsFiltered(BatchInfo info, StringInstruction cmd) => FilterBulk(info, cmd);
}
public bool IsFiltered(PKM pk, StringInstruction value) => FilterPKM(pk, value);
public bool IsFiltered(BatchInfo info, StringInstruction value) => FilterBulk(info, value);
}

View file

@ -1,10 +1,10 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <inheritdoc cref="IComplexSet"/>
public sealed class ComplexSet : IComplexSet
{
/// <inheritdoc cref="IComplexSet"/>
public sealed class ComplexSet : IComplexSet
{
public readonly string PropertyName;
public readonly Func<string, bool> IsValueCompatible = _ => true;
private readonly Action<PKM, StringInstruction> Action;
@ -20,5 +20,4 @@ namespace PKHeX.Core
public bool IsMatch(string name, string value) => name == PropertyName && IsValueCompatible(value);
public void Modify(PKM pk, StringInstruction instr) => Action(pk, instr);
}
}

View file

@ -1,12 +1,11 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Complex filter of data based on a string value.
/// </summary>
public interface IComplexFilter
{
/// <summary>
/// Complex filter of data based on a string value.
/// </summary>
public interface IComplexFilter
{
bool IsMatch(string prop);
bool IsFiltered(PKM pkm, StringInstruction value);
bool IsFiltered(PKM pk, StringInstruction value);
bool IsFiltered(BatchInfo info, StringInstruction value);
}
}

View file

@ -1,11 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Complex filter of data based on a string value.
/// </summary>
public interface IComplexFilterMeta
{
/// <summary>
/// Complex filter of data based on a string value.
/// </summary>
public interface IComplexFilterMeta
{
bool IsMatch(string prop);
bool IsFiltered(object cache, StringInstruction value);
}
}

View file

@ -1,11 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Complex modification of data to a string value.
/// </summary>
public interface IComplexSet
{
/// <summary>
/// Complex modification of data to a string value.
/// </summary>
public interface IComplexSet
{
bool IsMatch(string name, string value);
void Modify(PKM pk, StringInstruction instr);
}
}

View file

@ -1,10 +1,10 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <inheritdoc cref="IComplexFilter"/>
public sealed class MetaFilter : IComplexFilterMeta
{
/// <inheritdoc cref="IComplexFilter"/>
public sealed class MetaFilter : IComplexFilterMeta
{
private readonly string Property;
private readonly Func<object, StringInstruction, bool> FilterPKM;
@ -17,6 +17,5 @@ namespace PKHeX.Core
}
public bool IsMatch(string prop) => prop == Property;
public bool IsFiltered(object pkm, StringInstruction cmd) => FilterPKM(pkm, cmd);
}
public bool IsFiltered(object pk, StringInstruction value) => FilterPKM(pk, value);
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Batch Editor Modification result for an individual <see cref="PKM"/>.
/// </summary>
public enum ModifyResult
{
/// <summary>
/// Batch Editor Modification result for an individual <see cref="PKM"/>.
/// </summary>
public enum ModifyResult
{
/// <summary>
/// The <see cref="PKM"/> has invalid data and is not a suitable candidate for modification.
/// </summary>
@ -24,5 +24,4 @@
/// The <see cref="PKM"/> was modified.
/// </summary>
Modified,
}
}

View file

@ -2,19 +2,19 @@
using System.Collections.Generic;
using System.Diagnostics;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Batch Editing instruction
/// </summary>
/// <remarks>
/// Can be a filter (skip), or a modification instruction (modify)
/// </remarks>
/// <see cref="Exclude"/>
/// <see cref="Require"/>
/// <see cref="Apply"/>
public sealed class StringInstruction
{
/// <summary>
/// Batch Editing instruction
/// </summary>
/// <remarks>
/// Can be a filter (skip), or a modification instruction (modify)
/// </remarks>
/// <see cref="Exclude"/>
/// <see cref="Require"/>
/// <see cref="Apply"/>
public sealed class StringInstruction
{
public string PropertyName { get; }
public string PropertyValue { get; private set; }
@ -120,5 +120,4 @@ namespace PKHeX.Core
yield return new StringInstruction(name.ToString(), value);
}
}
}
}

View file

@ -1,13 +1,14 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Processes input of strings into a list of valid Filters and Instructions.
/// </summary>
public sealed class StringInstructionSet
{
/// <summary>
/// Processes input of strings into a list of valid Filters and Instructions.
/// </summary>
public sealed class StringInstructionSet
{
public readonly IReadOnlyList<StringInstruction> Filters;
public readonly IReadOnlyList<StringInstruction> Instructions;
@ -30,9 +31,8 @@ namespace PKHeX.Core
int start = 0;
while (start < lines.Count)
{
var list = lines.Skip(start).TakeWhile(_ => !lines[start++].StartsWith(SetSeparator)).ToList();
var list = lines.Skip(start).TakeWhile(_ => !lines[start++].StartsWith(SetSeparator, StringComparison.Ordinal)).ToList();
yield return new StringInstructionSet(list);
}
}
}
}

View file

@ -1,15 +1,14 @@
using System;
using System.Globalization;
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Modifications using <see cref="BatchInfo"/> legality.
/// </summary>
internal static class BatchModifications
{
/// <summary>
/// Modifications using <see cref="BatchInfo"/> legality.
/// </summary>
internal static class BatchModifications
{
private static bool IsAll(string p) => p.EndsWith("All", true, CultureInfo.CurrentCulture);
private static bool IsNone(string p) => p.EndsWith("None", true, CultureInfo.CurrentCulture);
private static bool IsAll(string p) => p.EndsWith("All", StringComparison.OrdinalIgnoreCase);
private static bool IsNone(string p) => p.EndsWith("None", StringComparison.OrdinalIgnoreCase);
public static ModifyResult SetSuggestedRelearnData(BatchInfo info, string propValue)
{
@ -115,5 +114,4 @@ namespace PKHeX.Core
pk.SetSuggestedContestStats(la.EncounterMatch, la.Info.EvoChainsAllGens);
return ModifyResult.Modified;
}
}
}

View file

@ -1,10 +1,10 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <inheritdoc cref="ISuggestModification"/>
public sealed class ComplexSuggestion : ISuggestModification
{
/// <inheritdoc cref="ISuggestModification"/>
public sealed class ComplexSuggestion : ISuggestModification
{
public readonly string Keyword;
public readonly Func<PKM, bool> Criteria = _ => true;
public readonly Func<string, string, BatchInfo, ModifyResult> Action;
@ -34,5 +34,4 @@ namespace PKHeX.Core
{
return Action(name, value, info);
}
}
}

View file

@ -1,11 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Modifies a property to have a "correct" value based on derived legality.
/// </summary>
public interface ISuggestModification
{
/// <summary>
/// Modifies a property to have a "correct" value based on derived legality.
/// </summary>
public interface ISuggestModification
{
public bool IsMatch(string name, string value, BatchInfo info);
public ModifyResult Modify(string name, string value, BatchInfo info);
}
}

View file

@ -1,11 +1,11 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <inheritdoc cref="ISuggestModification"/>
/// <typeparam name="T">Specific (or not) type</typeparam>
public sealed class TypeSuggestion<T> : ISuggestModification
{
/// <inheritdoc cref="ISuggestModification"/>
/// <typeparam name="T">Specific (or not) type</typeparam>
public sealed class TypeSuggestion<T> : ISuggestModification
{
public readonly string Keyword;
public readonly Action<T, string> Action;
public readonly Func<T, bool> Criteria = _ => true;
@ -13,7 +13,7 @@ namespace PKHeX.Core
public TypeSuggestion(string keyword, Action<T> action)
{
Keyword = keyword;
Action = (pkm, _) => action(pkm);
Action = (pk, _) => action(pk);
}
public TypeSuggestion(string keyword, Func<T, bool> criteria, Action<T> action) : this(keyword, action)
@ -36,5 +36,4 @@ namespace PKHeX.Core
Action(x, value);
return ModifyResult.Modified;
}
}
}

View file

@ -1,13 +1,13 @@
using System;
using System;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Contains extension logic for modifying <see cref="PKM"/> data.
/// </summary>
public static class CommonEdits
{
/// <summary>
/// Contains extension logic for modifying <see cref="PKM"/> data.
/// </summary>
public static class CommonEdits
{
/// <summary>
/// Setting which enables/disables automatic manipulation of <see cref="PKM.MarkValue"/> when importing from a <see cref="IBattleTemplate"/>.
/// </summary>
@ -104,7 +104,6 @@ namespace PKHeX.Core
/// </summary>
/// <param name="pk">Pokémon to modify.</param>
/// <param name="shiny">Desired <see cref="PKM.IsShiny"/> state to set.</param>
/// <returns></returns>
public static bool SetIsShiny(this PKM pk, bool shiny) => shiny ? SetShiny(pk) : pk.SetUnshiny();
/// <summary>
@ -442,5 +441,4 @@ namespace PKHeX.Core
int location = eggmet ? pk.Egg_Location : pk.Met_Location;
return GameInfo.GetLocationName(eggmet, location, pk.Format, pk.Generation, (GameVersion)pk.Version);
}
}
}

View file

@ -114,11 +114,11 @@ public sealed class TrainerDatabase
}
/// <summary>
/// Adds the trainer details of the <see cref="pkm"/> to the <see cref="Database"/>.
/// Adds the trainer details of the <see cref="pk"/> to the <see cref="Database"/>.
/// </summary>
/// <param name="pkm">Pokémon with Trainer details to add.</param>
/// <param name="pk">Pokémon with Trainer details to add.</param>
/// <remarks>A copy of the object will be made to prevent modifications, just in case.</remarks>
public void RegisterCopy(PKM pkm) => Register(GetTrainerReference(pkm));
public void RegisterCopy(PKM pk) => Register(GetTrainerReference(pk));
/// <summary>
/// Adds the trainer details of the <see cref="info"/> to the <see cref="Database"/>.
@ -127,16 +127,16 @@ public sealed class TrainerDatabase
/// <remarks>A copy of the object will be made to prevent modifications, just in case.</remarks>
public void RegisterCopy(ITrainerInfo info) => Register(new SimpleTrainerInfo(info));
private static ITrainerInfo GetTrainerReference(PKM pkm)
private static ITrainerInfo GetTrainerReference(PKM pk)
{
var result = new SimpleTrainerInfo((GameVersion)pkm.Version)
var result = new SimpleTrainerInfo((GameVersion)pk.Version)
{
TID = pkm.TID, SID = pkm.SID, OT = pkm.OT_Name, Gender = pkm.OT_Gender,
Language = pkm.Language,
Generation = pkm.Generation,
TID = pk.TID, SID = pk.SID, OT = pk.OT_Name, Gender = pk.OT_Gender,
Language = pk.Language,
Generation = pk.Generation,
};
if (pkm is IRegionOrigin r)
if (pk is IRegionOrigin r)
r.CopyRegionOrigin(result);
else
result.SetDefaultRegionOrigins();

View file

@ -1,13 +1,13 @@
using System;
using System.Runtime.CompilerServices;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for calculating a Hidden Power Type based on IVs and generation-format.
/// </summary>
public static class HiddenPower
{
/// <summary>
/// Logic for calculating a Hidden Power Type based on IVs and generation-format.
/// </summary>
public static class HiddenPower
{
/// <summary>
/// Gets the current Hidden Power Type of the input <see cref="IVs"/> for the requested format generation.
/// </summary>
@ -213,5 +213,4 @@ namespace PKHeX.Core
0b111101, // Dragon
0b111111, // Dark
};
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Interface containing details relevant for battling.
/// </summary>
public interface IBattleTemplate : ISpeciesForm, IGigantamax, INature
{
/// <summary>
/// Interface containing details relevant for battling.
/// </summary>
public interface IBattleTemplate : ISpeciesForm, IGigantamax, INature
{
/// <summary>
/// <see cref="PKM.Format"/> of the Set entity it is specific to.
/// </summary>
@ -69,5 +69,4 @@
/// <see cref="PKM.Moves"/> of the Set entity.
/// </summary>
int[] Moves { get; }
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Simple interface representing a <see cref="PKM"/> viewer.
/// </summary>
public interface IPKMView
{
/// <summary>
/// Simple interface representing a <see cref="PKM"/> viewer.
/// </summary>
public interface IPKMView
{
/// <summary>
/// Fetches the currently loaded <see cref="PKM"/> data from the viewer.
/// </summary>
@ -44,5 +44,4 @@
/// <param name="focus">Cause the viewer to give focus to itself.</param>
/// <param name="skipConversionCheck">Cause the viewer to skip converting the data. Faster if it is known that the format is the same as the previous format.</param>
void PopulateFields(PKM pk, bool focus = true, bool skipConversionCheck = false);
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Plugin interface used by an editor to notify third-party code providers.
/// </summary>
public interface IPlugin
{
/// <summary>
/// Plugin interface used by an editor to notify third-party code providers.
/// </summary>
public interface IPlugin
{
/// <summary>
/// Plugin Name.
/// </summary>
@ -37,5 +37,4 @@
/// Retrieves the <see cref="ISaveFileProvider"/> object which can provide a <see cref="SaveFile"/>.
/// </summary>
ISaveFileProvider SaveFileEditor { get; }
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Simple interface representing a Save File viewer.
/// </summary>
public interface ISaveFileProvider
{
/// <summary>
/// Simple interface representing a Save File viewer.
/// </summary>
public interface ISaveFileProvider
{
/// <summary>
/// Retrieves the save file the <see cref="ISaveFileProvider"/> has control over.
/// </summary>
@ -19,5 +19,4 @@
/// Triggers a refresh of any individual <see cref="PKM"/> view slots.
/// </summary>
void ReloadSlots();
}
}

View file

@ -1,7 +1,7 @@
namespace PKHeX.Core
namespace PKHeX.Core;
public interface ISpriteBuilder<T>
{
public interface ISpriteBuilder<T>
{
T GetSprite(int species, int form, int gender, uint formarg, int heldItem, bool isEgg, bool isShiny,
int generation = -1,
bool isBoxBGRed = false,
@ -13,5 +13,4 @@
bool isAltShiny = false);
void Initialize(SaveFile sav);
}
}

View file

@ -2,26 +2,25 @@
using System.Linq;
using static PKHeX.Core.MessageStrings;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Utility for editing a <see cref="PKM"/>
/// </summary>
public static class EntitySuggestionUtil
{
/// <summary>
/// Utility for editing a <see cref="PKM"/>
/// </summary>
public static class EntitySuggestionUtil
{
public static List<string> GetMetLocationSuggestionMessage(PKM pkm, int level, int location, int minimumLevel)
public static List<string> GetMetLocationSuggestionMessage(PKM pk, int level, int location, int minimumLevel)
{
var suggestion = new List<string> { MsgPKMSuggestionStart };
if (pkm.Format >= 3)
if (pk.Format >= 3)
{
var metList = GameInfo.GetLocationList((GameVersion)pkm.Version, pkm.Context, egg: false);
var metList = GameInfo.GetLocationList((GameVersion)pk.Version, pk.Context, egg: false);
var locationName = metList.First(loc => loc.Value == location).Text;
suggestion.Add($"{MsgPKMSuggestionMetLocation} {locationName}");
suggestion.Add($"{MsgPKMSuggestionMetLevel} {level}");
}
if (pkm.CurrentLevel < minimumLevel)
if (pk.CurrentLevel < minimumLevel)
suggestion.Add($"{MsgPKMSuggestionLevel} {minimumLevel}");
return suggestion;
}
}
}

View file

@ -1,117 +1,117 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Bindable summary object that can fetch strings that summarize a <see cref="PKM"/>.
/// </summary>
public class EntitySummary // do NOT seal, allow inheritance
{
/// <summary>
/// Bindable summary object that can fetch strings that summarize a <see cref="PKM"/>.
/// </summary>
public class EntitySummary // do NOT seal, allow inheritance
{
private static readonly IReadOnlyList<string> GenderSymbols = GameInfo.GenderSymbolASCII;
private readonly GameStrings Strings;
private readonly ushort[] Stats;
protected readonly PKM pkm; // protected for children generating extra properties
protected readonly PKM pk; // protected for children generating extra properties
public virtual string Position => "???";
public string Nickname => pkm.Nickname;
public string Species => Get(Strings.specieslist, pkm.Species);
public string Nature => Get(Strings.natures, pkm.StatNature);
public string Gender => Get(GenderSymbols, pkm.Gender);
public string ESV => pkm.PSV.ToString("0000");
public string HP_Type => Get(Strings.types, pkm.HPType + 1);
public string Ability => Get(Strings.abilitylist, pkm.Ability);
public string Move1 => Get(Strings.movelist, pkm.Move1);
public string Move2 => Get(Strings.movelist, pkm.Move2);
public string Move3 => Get(Strings.movelist, pkm.Move3);
public string Move4 => Get(Strings.movelist, pkm.Move4);
public string HeldItem => GetSpan(Strings.GetItemStrings(pkm.Format), pkm.HeldItem);
public string Nickname => pk.Nickname;
public string Species => Get(Strings.specieslist, pk.Species);
public string Nature => Get(Strings.natures, pk.StatNature);
public string Gender => Get(GenderSymbols, pk.Gender);
public string ESV => pk.PSV.ToString("0000");
public string HP_Type => Get(Strings.types, pk.HPType + 1);
public string Ability => Get(Strings.abilitylist, pk.Ability);
public string Move1 => Get(Strings.movelist, pk.Move1);
public string Move2 => Get(Strings.movelist, pk.Move2);
public string Move3 => Get(Strings.movelist, pk.Move3);
public string Move4 => Get(Strings.movelist, pk.Move4);
public string HeldItem => GetSpan(Strings.GetItemStrings(pk.Format), pk.HeldItem);
public string HP => Stats[0].ToString();
public string ATK => Stats[1].ToString();
public string DEF => Stats[2].ToString();
public string SPA => Stats[4].ToString();
public string SPD => Stats[5].ToString();
public string SPE => Stats[3].ToString();
public string MetLoc => pkm.GetLocationString(eggmet: false);
public string EggLoc => pkm.GetLocationString(eggmet: true);
public string Ball => Get(Strings.balllist, pkm.Ball);
public string OT => pkm.OT_Name;
public string Version => Get(Strings.gamelist, pkm.Version);
public string OTLang => ((LanguageID)pkm.Language).ToString();
public string Legal { get { var la = new LegalityAnalysis(pkm); return la.Parsed ? la.Valid.ToString() : "-"; } }
public string MetLoc => pk.GetLocationString(eggmet: false);
public string EggLoc => pk.GetLocationString(eggmet: true);
public string Ball => Get(Strings.balllist, pk.Ball);
public string OT => pk.OT_Name;
public string Version => Get(Strings.gamelist, pk.Version);
public string OTLang => ((LanguageID)pk.Language).ToString();
public string Legal { get { var la = new LegalityAnalysis(pk); return la.Parsed ? la.Valid.ToString() : "-"; } }
#region Extraneous
public string EC => pkm.EncryptionConstant.ToString("X8");
public string PID => pkm.PID.ToString("X8");
public int HP_IV => pkm.IV_HP;
public int ATK_IV => pkm.IV_ATK;
public int DEF_IV => pkm.IV_DEF;
public int SPA_IV => pkm.IV_SPA;
public int SPD_IV => pkm.IV_SPD;
public int SPE_IV => pkm.IV_SPE;
public uint EXP => pkm.EXP;
public int Level => pkm.CurrentLevel;
public int HP_EV => pkm.EV_HP;
public int ATK_EV => pkm.EV_ATK;
public int DEF_EV => pkm.EV_DEF;
public int SPA_EV => pkm.EV_SPA;
public int SPD_EV => pkm.EV_SPD;
public int SPE_EV => pkm.EV_SPE;
public int Cool => pkm is IContestStats s ? s.CNT_Cool : 0;
public int Beauty => pkm is IContestStats s ? s.CNT_Beauty : 0;
public int Cute => pkm is IContestStats s ? s.CNT_Cute : 0;
public int Smart => pkm is IContestStats s ? s.CNT_Smart : 0;
public int Tough => pkm is IContestStats s ? s.CNT_Tough : 0;
public int Sheen => pkm is IContestStats s ? s.CNT_Sheen : 0;
public int Markings => pkm.MarkValue;
public string EC => pk.EncryptionConstant.ToString("X8");
public string PID => pk.PID.ToString("X8");
public int HP_IV => pk.IV_HP;
public int ATK_IV => pk.IV_ATK;
public int DEF_IV => pk.IV_DEF;
public int SPA_IV => pk.IV_SPA;
public int SPD_IV => pk.IV_SPD;
public int SPE_IV => pk.IV_SPE;
public uint EXP => pk.EXP;
public int Level => pk.CurrentLevel;
public int HP_EV => pk.EV_HP;
public int ATK_EV => pk.EV_ATK;
public int DEF_EV => pk.EV_DEF;
public int SPA_EV => pk.EV_SPA;
public int SPD_EV => pk.EV_SPD;
public int SPE_EV => pk.EV_SPE;
public int Cool => pk is IContestStats s ? s.CNT_Cool : 0;
public int Beauty => pk is IContestStats s ? s.CNT_Beauty : 0;
public int Cute => pk is IContestStats s ? s.CNT_Cute : 0;
public int Smart => pk is IContestStats s ? s.CNT_Smart : 0;
public int Tough => pk is IContestStats s ? s.CNT_Tough : 0;
public int Sheen => pk is IContestStats s ? s.CNT_Sheen : 0;
public int Markings => pk.MarkValue;
public string NotOT => pkm.Format > 5 ? pkm.HT_Name : "N/A";
public string NotOT => pk.Format > 5 ? pk.HT_Name : "N/A";
public int AbilityNum => pkm.Format > 5 ? pkm.AbilityNumber : -1;
public int GenderFlag => pkm.Gender;
public int Form => pkm.Form;
public int PKRS_Strain => pkm.PKRS_Strain;
public int PKRS_Days => pkm.PKRS_Days;
public int MetLevel => pkm.Met_Level;
public int OT_Gender => pkm.OT_Gender;
public int AbilityNum => pk.Format > 5 ? pk.AbilityNumber : -1;
public int GenderFlag => pk.Gender;
public int Form => pk.Form;
public int PKRS_Strain => pk.PKRS_Strain;
public int PKRS_Days => pk.PKRS_Days;
public int MetLevel => pk.Met_Level;
public int OT_Gender => pk.OT_Gender;
public bool FatefulFlag => pkm.FatefulEncounter;
public bool IsEgg => pkm.IsEgg;
public bool IsNicknamed => pkm.IsNicknamed;
public bool IsShiny => pkm.IsShiny;
public bool FatefulFlag => pk.FatefulEncounter;
public bool IsEgg => pk.IsEgg;
public bool IsNicknamed => pk.IsNicknamed;
public bool IsShiny => pk.IsShiny;
public int TID => pkm.DisplayTID;
public int SID => pkm.DisplaySID;
public int TSV => pkm.TSV;
public int Move1_PP => pkm.Move1_PP;
public int Move2_PP => pkm.Move2_PP;
public int Move3_PP => pkm.Move3_PP;
public int Move4_PP => pkm.Move4_PP;
public int Move1_PPUp => pkm.Move1_PPUps;
public int Move2_PPUp => pkm.Move2_PPUps;
public int Move3_PPUp => pkm.Move3_PPUps;
public int Move4_PPUp => pkm.Move4_PPUps;
public string Relearn1 => Get(Strings.movelist, pkm.RelearnMove1);
public string Relearn2 => Get(Strings.movelist, pkm.RelearnMove2);
public string Relearn3 => Get(Strings.movelist, pkm.RelearnMove3);
public string Relearn4 => Get(Strings.movelist, pkm.RelearnMove4);
public ushort Checksum => pkm is ISanityChecksum s ? s.Checksum : Checksums.CRC16_CCITT(pkm.Data.AsSpan(pkm.SIZE_STORED));
public int Friendship => pkm.OT_Friendship;
public int Egg_Year => pkm.EggMetDate.GetValueOrDefault().Year;
public int Egg_Month => pkm.EggMetDate.GetValueOrDefault().Month;
public int Egg_Day => pkm.EggMetDate.GetValueOrDefault().Day;
public int Met_Year => pkm.MetDate.GetValueOrDefault().Year;
public int Met_Month => pkm.MetDate.GetValueOrDefault().Month;
public int Met_Day => pkm.MetDate.GetValueOrDefault().Day;
public int TID => pk.DisplayTID;
public int SID => pk.DisplaySID;
public int TSV => pk.TSV;
public int Move1_PP => pk.Move1_PP;
public int Move2_PP => pk.Move2_PP;
public int Move3_PP => pk.Move3_PP;
public int Move4_PP => pk.Move4_PP;
public int Move1_PPUp => pk.Move1_PPUps;
public int Move2_PPUp => pk.Move2_PPUps;
public int Move3_PPUp => pk.Move3_PPUps;
public int Move4_PPUp => pk.Move4_PPUps;
public string Relearn1 => Get(Strings.movelist, pk.RelearnMove1);
public string Relearn2 => Get(Strings.movelist, pk.RelearnMove2);
public string Relearn3 => Get(Strings.movelist, pk.RelearnMove3);
public string Relearn4 => Get(Strings.movelist, pk.RelearnMove4);
public ushort Checksum => pk is ISanityChecksum s ? s.Checksum : Checksums.CRC16_CCITT(pk.Data.AsSpan(pk.SIZE_STORED));
public int Friendship => pk.OT_Friendship;
public int Egg_Year => pk.EggMetDate.GetValueOrDefault().Year;
public int Egg_Month => pk.EggMetDate.GetValueOrDefault().Month;
public int Egg_Day => pk.EggMetDate.GetValueOrDefault().Day;
public int Met_Year => pk.MetDate.GetValueOrDefault().Year;
public int Met_Month => pk.MetDate.GetValueOrDefault().Month;
public int Met_Day => pk.MetDate.GetValueOrDefault().Day;
#endregion
protected EntitySummary(PKM p, GameStrings strings)
{
pkm = p;
pk = p;
Strings = strings;
Stats = pkm.GetStats(pkm.PersonalInfo);
Stats = pk.GetStats(pk.PersonalInfo);
}
/// <summary>
@ -122,5 +122,4 @@ namespace PKHeX.Core
/// <returns>Null if array is null</returns>
private static string Get(IReadOnlyList<string> arr, int val) => (uint)val < arr.Count ? arr[val] : string.Empty;
private static string GetSpan(ReadOnlySpan<string> arr, int val) => (uint)val < arr.Length ? arr[val] : string.Empty;
}
}

View file

@ -1,12 +1,12 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for filling in template data for <see cref="PKM"/> objects.
/// </summary>
public static class EntityTemplates
{
/// <summary>
/// Logic for filling in template data for <see cref="PKM"/> objects.
/// </summary>
public static class EntityTemplates
{
/// <summary>
/// Applies junk data to a <see cref="SaveFile.BlankPKM"/>, which is preferable to a completely empty entity.
/// </summary>
@ -74,5 +74,4 @@ namespace PKHeX.Core
lang = (int)LanguageID.English;
return lang;
}
}
}

View file

@ -1,13 +1,13 @@
using System;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// QR Message reading &amp; writing logic
/// </summary>
public static class QRMessageUtil
{
/// <summary>
/// QR Message reading &amp; writing logic
/// </summary>
public static class QRMessageUtil
{
private const string QR6PathBad = "null/#";
private const string QR6Path = "http://lunarcookies.github.io/b1s1.html#";
private const string QR6PathWC = "http://lunarcookies.github.io/wc.html#";
@ -31,18 +31,18 @@ namespace PKHeX.Core
/// <summary>
/// Gets a QR Message from the input <see cref="PKM"/> data.
/// </summary>
/// <param name="pkm">Pokémon to encode</param>
/// <param name="pk">Pokémon to encode</param>
/// <returns>QR Message</returns>
public static string GetMessage(PKM pkm)
public static string GetMessage(PKM pk)
{
if (pkm is PK7 pk7)
if (pk is PK7 pk7)
{
byte[] payload = QR7.GenerateQRData(pk7);
return GetMessage(payload);
}
var server = GetExploitURLPrefixPKM(pkm.Format);
var data = pkm.EncryptedBoxData;
var server = GetExploitURLPrefixPKM(pk.Format);
var data = pk.EncryptedBoxData;
return GetMessageBase64(data, server);
}
@ -75,17 +75,20 @@ namespace PKHeX.Core
{
if (message.Length < 32) // arbitrary length check; everything should be greater than this
return null;
if (message.StartsWith(QR6PathBad)) // fake url
if (message.StartsWith(QR6PathBad, StringComparison.Ordinal)) // fake url
return DecodeMessageDataBase64(message);
if (message.StartsWith("http")) // inject url
if (message.StartsWith("http", StringComparison.Ordinal)) // inject url
return DecodeMessageDataBase64(message);
if (message.StartsWith("POKE") && message.Length > 0x30 + 0xE8) // G7 data
if (message.StartsWith("POKE", StringComparison.Ordinal) && message.Length > 0x30 + 0xE8) // G7 data
return GetBytesFromMessage(message, 0x30, 0xE8);
return null;
}
private static byte[]? DecodeMessageDataBase64(string url)
{
if (url.Length == 0 || url[^1] == '#')
return null;
try
{
int payloadBegin = url.IndexOf('#');
@ -94,7 +97,7 @@ namespace PKHeX.Core
url = url[(payloadBegin + 1)..]; // Trim URL to right after #
return Convert.FromBase64String(url);
}
catch
catch (FormatException)
{
return null;
}
@ -107,5 +110,4 @@ namespace PKHeX.Core
data[i] = (byte)seed[i + skip];
return data;
}
}
}

View file

@ -1,10 +1,10 @@
using System;
using static System.Buffers.Binary.BinaryPrimitives;
namespace PKHeX.Core
namespace PKHeX.Core;
public sealed class QRPK7 : IEncounterInfo
{
public sealed class QRPK7 : IEncounterInfo
{
public GameVersion Version => (GameVersion)CassetteVersion;
public bool EggEncounter => false;
public byte LevelMin => Level;
@ -61,12 +61,12 @@ namespace PKHeX.Core
/// <summary>
/// Converts the <see cref="Data"/> to a rough PKM.
/// </summary>
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
public PKM ConvertToPKM(ITrainerInfo tr) => ConvertToPKM(tr, EncounterCriteria.Unrestricted);
/// <summary>
/// Converts the <see cref="Data"/> to a rough PKM.
/// </summary>
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
public PKM ConvertToPKM(ITrainerInfo tr, EncounterCriteria criteria)
{
var pk = new PK7
{
@ -105,13 +105,13 @@ namespace PKHeX.Core
Ball = Ball,
Version = CassetteVersion,
OT_Name = sav.OT,
HT_Name = sav.OT,
OT_Name = tr.OT,
HT_Name = tr.OT,
CurrentLevel = Level,
Met_Level = Level,
MetDate = DateTime.Now,
};
RecentTrainerCache.SetConsoleRegionData3DS(pk, sav);
RecentTrainerCache.SetConsoleRegionData3DS(pk, tr);
pk.RefreshAbility(AbilityIndex >> 1);
pk.ForcePartyData();
@ -119,5 +119,4 @@ namespace PKHeX.Core
pk.RefreshChecksum();
return pk;
}
}
}

View file

@ -1,23 +1,23 @@
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
public static class QRPKM
{
public static class QRPKM
{
/// <summary>
/// Summarizes the details of a <see cref="PKM"/> into multiple lines for display in an image.
/// </summary>
/// <param name="pkm">Pokémon to generate details for.</param>
/// <param name="pk">Pokémon to generate details for.</param>
/// <returns>Lines representing a Header, Moves, and IVs/EVs</returns>
public static string[] GetQRLines(this PKM pkm)
public static string[] GetQRLines(this PKM pk)
{
var s = GameInfo.Strings;
var header = GetHeader(pkm, s);
string moves = string.Join(" / ", pkm.Moves.Select(move => move < s.movelist.Length ? s.movelist[move] : "ERROR"));
string IVs = $"IVs: {pkm.IV_HP:00}/{pkm.IV_ATK:00}/{pkm.IV_DEF:00}/{pkm.IV_SPA:00}/{pkm.IV_SPD:00}/{pkm.IV_SPE:00}";
string EVs = $"EVs: {pkm.EV_HP:00}/{pkm.EV_ATK:00}/{pkm.EV_DEF:00}/{pkm.EV_SPA:00}/{pkm.EV_SPD:00}/{pkm.EV_SPE:00}";
var header = GetHeader(pk, s);
string moves = string.Join(" / ", pk.Moves.Select(move => move < s.movelist.Length ? s.movelist[move] : "ERROR"));
string IVs = $"IVs: {pk.IV_HP:00}/{pk.IV_ATK:00}/{pk.IV_DEF:00}/{pk.IV_SPA:00}/{pk.IV_SPD:00}/{pk.IV_SPE:00}";
string EVs = $"EVs: {pk.EV_HP:00}/{pk.EV_ATK:00}/{pk.EV_DEF:00}/{pk.EV_SPA:00}/{pk.EV_SPD:00}/{pk.EV_SPE:00}";
return new[]
{
@ -27,34 +27,33 @@ namespace PKHeX.Core
};
}
private static IEnumerable<string> GetHeader(PKM pkm, GameStrings s)
private static IEnumerable<string> GetHeader(PKM pk, GameStrings s)
{
string filename = pkm.Nickname;
if ((uint) pkm.Species < s.Species.Count)
string filename = pk.Nickname;
if ((uint) pk.Species < s.Species.Count)
{
var name = s.Species[pkm.Species];
if (pkm.Nickname != name)
var name = s.Species[pk.Species];
if (pk.Nickname != name)
filename += $" ({name})";
}
yield return filename;
if (pkm.Format >= 3 && (uint)pkm.Ability < s.Ability.Count)
yield return $"[{s.Ability[pkm.Ability]}]";
if (pk.Format >= 3 && (uint)pk.Ability < s.Ability.Count)
yield return $"[{s.Ability[pk.Ability]}]";
var level = pkm.Stat_Level;
var level = pk.Stat_Level;
if (level == 0)
level = pkm.CurrentLevel;
level = pk.CurrentLevel;
yield return $"lv{level}";
if (pkm.HeldItem > 0)
if (pk.HeldItem > 0)
{
var items = s.GetItemStrings(pkm.Format);
if ((uint)pkm.HeldItem < items.Length)
yield return $" @ {items[pkm.HeldItem]}";
var items = s.GetItemStrings(pk.Format);
if ((uint)pk.HeldItem < items.Length)
yield return $" @ {items[pk.HeldItem]}";
}
if (pkm.Format >= 3 && (uint)pkm.Nature < s.Natures.Count)
yield return s.natures[pkm.Nature];
}
if (pk.Format >= 3 && (uint)pk.Nature < s.Natures.Count)
yield return s.natures[pk.Nature];
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Option to load a save file automatically to an editing environment.
/// </summary>
public enum AutoLoadSetting
{
/// <summary>
/// Option to load a save file automatically to an editing environment.
/// </summary>
public enum AutoLoadSetting
{
/// <summary>
/// Doesn't auto load a save file, and instead uses a fake save file data.
/// </summary>
@ -19,5 +19,4 @@
/// Loads the most recently opened Save File path.
/// </summary>
LastLoaded,
}
}

View file

@ -1,12 +1,12 @@
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Settings used for starting up an editing environment.
/// </summary>
public interface IStartupSettings
{
/// <summary>
/// Settings used for starting up an editing environment.
/// </summary>
public interface IStartupSettings
{
/// <summary>
/// Save File version to start the environment with if a preexisting save file has not been chosen.
/// </summary>
@ -21,5 +21,4 @@ namespace PKHeX.Core
/// List of recently loaded save file paths.
/// </summary>
List<string> RecentlyLoaded { get; }
}
}

View file

@ -3,13 +3,13 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic object that assembles parameters used for starting up an editing environment.
/// </summary>
public sealed class StartupArguments
{
/// <summary>
/// Logic object that assembles parameters used for starting up an editing environment.
/// </summary>
public sealed class StartupArguments
{
public PKM? Entity { get; private set; }
public SaveFile? SAV { get; private set; }
@ -31,9 +31,9 @@ namespace PKHeX.Core
s.Metadata.SetExtraInfo(path);
SAV = s;
}
else if (other is PKM pkm)
else if (other is PKM pk)
{
Entity = pkm;
Entity = pk;
}
else if (other is not null)
{
@ -61,10 +61,8 @@ namespace PKHeX.Core
{
if (Entity is not null)
return;
var sav = SAV;
if (sav is null)
throw new NullReferenceException(nameof(sav));
if (SAV is not { } sav)
return;
var pk = sav.LoadTemplate(path);
var isBlank = pk.Data.SequenceEqual(sav.BlankPKM.Data);
@ -74,10 +72,10 @@ namespace PKHeX.Core
Entity = pk;
}
private static SaveFile? ReadSettingsDefinedPKM(IStartupSettings startup, PKM pkm) => startup.AutoLoadSaveOnStartup switch
private static SaveFile? ReadSettingsDefinedPKM(IStartupSettings startup, PKM pk) => startup.AutoLoadSaveOnStartup switch
{
AutoLoadSetting.RecentBackup => SaveFinder.DetectSaveFiles().FirstOrDefault(z => z.IsCompatiblePKM(pkm)),
AutoLoadSetting.LastLoaded => GetMostRecentlyLoaded(startup.RecentlyLoaded).FirstOrDefault(z => z.IsCompatiblePKM(pkm)),
AutoLoadSetting.RecentBackup => SaveFinder.DetectSaveFiles().FirstOrDefault(z => z.IsCompatiblePKM(pk)),
AutoLoadSetting.LastLoaded => GetMostRecentlyLoaded(startup.RecentlyLoaded).FirstOrDefault(z => z.IsCompatiblePKM(pk)),
_ => null,
};
@ -124,5 +122,4 @@ namespace PKHeX.Core
}
}
#endregion
}
}

View file

@ -1,10 +1,10 @@
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
public static class BoxManipUtil
{
public static class BoxManipUtil
{
/// <summary>
/// Grouped categories of different <see cref="IBoxManip"/>.
/// </summary>
@ -60,5 +60,4 @@ namespace PKHeX.Core
}
return null;
}
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Manipulates boxes of a <see cref="SaveFile"/>.
/// </summary>
public abstract class BoxManipulator
{
/// <summary>
/// Manipulates boxes of a <see cref="SaveFile"/>.
/// </summary>
public abstract class BoxManipulator
{
protected abstract SaveFile SAV { get; }
/// <summary>
@ -59,7 +59,6 @@
/// <param name="end">End box</param>
/// <param name="prompt">Message asking about the operation.</param>
/// <param name="fail">Message indicating the operation cannot be performed.</param>
/// <returns></returns>
protected virtual bool CanManipulateRegion(int start, int end, string prompt, string fail) => !SAV.IsAnySlotLockedInBox(start, end);
/// <summary>
@ -69,5 +68,4 @@
/// <param name="all">Indicates if all boxes were manipulated, or just one box.</param>
/// <param name="count">Count of manipulated slots</param>
protected abstract void FinishBoxManipulation(string message, bool all, int count);
}
}

View file

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
public sealed class EventLabelCollection
{
public sealed class EventLabelCollection
{
public readonly IReadOnlyList<NamedEventWork> Work;
public readonly IReadOnlyList<NamedEventValue> Flag;
@ -28,10 +28,10 @@ namespace PKHeX.Core
var index = TryParseHexDec(split[0]);
if (index >= maxValue)
throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), index, "Value too high.");
if (processed.Contains(index))
throw new ArgumentException("Already have an entry for this!", nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), index, "Already have an entry for this!");
var type = GetEventType(split[1]);
var desc = split[2];
@ -59,10 +59,10 @@ namespace PKHeX.Core
var index = TryParseHexDecConst(split[0]);
if (index >= maxValue)
throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), index, "Value too high.");
if (processed.Contains(index))
throw new ArgumentException("Already have an entry for this!", nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), index, "Already have an entry for this!");
var type = GetEventType(split[1]);
var desc = split[2];
@ -83,7 +83,7 @@ namespace PKHeX.Core
{
var subsplit = entry.Split(':');
var name = subsplit[1];
var value = Convert.ToUInt16(subsplit[0]);
var value = Convert.ToUInt16(subsplit[0], 10);
result.Add(new NamedEventConst(name, value));
}
return result;
@ -91,16 +91,16 @@ namespace PKHeX.Core
private static int TryParseHexDec(string flag)
{
if (!flag.StartsWith("0x"))
return Convert.ToInt16(flag);
if (!flag.StartsWith("0x", StringComparison.Ordinal))
return Convert.ToInt16(flag, 10);
flag = flag[2..];
return Convert.ToInt16(flag, 16);
}
private static int TryParseHexDecConst(string c)
{
if (!c.StartsWith("0x40"))
return Convert.ToInt16(c);
if (!c.StartsWith("0x40", StringComparison.Ordinal))
return Convert.ToInt16(c, 10);
c = c[4..];
return Convert.ToInt16(c, 16);
}
@ -123,10 +123,10 @@ namespace PKHeX.Core
'r' => NamedEventType.Rebattle,
_ => NamedEventType.None,
};
}
}
public sealed class EventLabelCollectionSystem
{
public sealed class EventLabelCollectionSystem
{
public readonly IReadOnlyList<NamedEventWork> Work;
public readonly IReadOnlyList<NamedEventValue> Flag;
public readonly IReadOnlyList<NamedEventValue> System;
@ -153,10 +153,10 @@ namespace PKHeX.Core
var index = TryParseHexDec(split[0]);
if (index >= maxValue)
throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), index, "Value too high.");
if (processed.Contains(index))
throw new ArgumentException("Already have an entry for this!", nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), index, "Already have an entry for this!");
var type = GetEventType(split[1]);
var desc = split[2];
@ -184,10 +184,10 @@ namespace PKHeX.Core
var index = TryParseHexDecConst(split[0]);
if (index >= maxValue)
throw new ArgumentOutOfRangeException(nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), index, "Value too high.");
if (processed.Contains(index))
throw new ArgumentException("Already have an entry for this!", nameof(index));
throw new ArgumentOutOfRangeException(nameof(index), index, "Already have an entry for this!");
var type = GetEventType(split[1]);
var desc = split[2];
@ -208,7 +208,7 @@ namespace PKHeX.Core
{
var subsplit = entry.Split(':');
var name = subsplit[1];
var value = Convert.ToUInt16(subsplit[0]);
var value = Convert.ToUInt16(subsplit[0], 10);
result.Add(new NamedEventConst(name, value));
}
return result;
@ -216,16 +216,16 @@ namespace PKHeX.Core
private static int TryParseHexDec(string flag)
{
if (!flag.StartsWith("0x"))
return Convert.ToInt16(flag);
if (!flag.StartsWith("0x", StringComparison.Ordinal))
return Convert.ToInt16(flag, 10);
flag = flag[2..];
return Convert.ToInt16(flag, 16);
}
private static int TryParseHexDecConst(string c)
{
if (!c.StartsWith("0x40"))
return Convert.ToInt16(c);
if (!c.StartsWith("0x40", StringComparison.Ordinal))
return Convert.ToInt16(c, 10);
c = c[4..];
return Convert.ToInt16(c, 16);
}
@ -248,10 +248,10 @@ namespace PKHeX.Core
'r' => NamedEventType.Rebattle,
_ => NamedEventType.None,
};
}
}
public enum NamedEventType
{
public enum NamedEventType
{
None,
HiddenItem,
TrainerToggle,
@ -265,15 +265,14 @@ namespace PKHeX.Core
EncounterEvent,
GiftAvailable,
Rebattle = 100,
}
}
public record NamedEventValue(string Name, int Index, NamedEventType Type);
public record NamedEventValue(string Name, int Index, NamedEventType Type);
public sealed record NamedEventWork(string Name, int Index, NamedEventType Type, IReadOnlyList<NamedEventConst> PredefinedValues) : NamedEventValue(Name, Index, Type);
public sealed record NamedEventWork(string Name, int Index, NamedEventType Type, IReadOnlyList<NamedEventConst> PredefinedValues) : NamedEventValue(Name, Index, Type);
public sealed record NamedEventConst(string Name, ushort Value)
{
public sealed record NamedEventConst(string Name, ushort Value)
{
public bool IsCustom => Value == CustomMagicValue;
public const ushort CustomMagicValue = ushort.MaxValue;
}
}

View file

@ -5,10 +5,10 @@ public class EventUnlocker8b : EventUnlocker<SAV8BS>
public EventUnlocker8b(SAV8BS sav) : base(sav) { }
public bool UnlockReadySpiritomb => SAV.UgSaveData.TalkedNPC < 32;
public bool UnlockReadyBoxLegend => SAV.Work.GetFlag(308) && SAV.Work.GetWork(84) != 5; // FE_D05R0114_SPPOKE_GET, WK_SCENE_D05R0114 (1-3 story related, 4 = captured, 5 = can retry)
public bool UnlockReadyShaymin => SAV.Work.GetFlag(545) || !(SAV.Work.GetWork(276) == 1 && SAV.Zukan.HasNationalDex && SAV.Items.GetItemQuantity(452) == 1 && SAV.Work.GetSystemFlag(5)); // HAIHUEVENT_ID_D30, Oak's Letter
public bool UnlockReadyDarkrai => SAV.Work.GetFlag(301) || !(SAV.Work.GetWork(275) == 1 && SAV.Zukan.HasNationalDex && SAV.Items.GetItemQuantity(454) == 1); // HAIHUEVENT_ID_D18, Member Card
public bool UnlockReadyArceus => SAV.Work.GetFlag(531) || !(SAV.Work.GetWork(188) == 0 && SAV.Zukan.HasNationalDex && SAV.Items.GetItemQuantity(455) == 1 && SAV.Work.GetSystemFlag(5)); // FE_D05R0116_LEGEND_CLEAR, Azure Flute
public bool UnlockReadyBoxLegend => SAV.FlagWork.GetFlag(308) && SAV.FlagWork.GetWork(84) != 5; // FE_D05R0114_SPPOKE_GET, WK_SCENE_D05R0114 (1-3 story related, 4 = captured, 5 = can retry)
public bool UnlockReadyShaymin => SAV.FlagWork.GetFlag(545) || !(SAV.FlagWork.GetWork(276) == 1 && SAV.Zukan.HasNationalDex && SAV.Items.GetItemQuantity(452) == 1 && SAV.FlagWork.GetSystemFlag(5)); // HAIHUEVENT_ID_D30, Oak's Letter
public bool UnlockReadyDarkrai => SAV.FlagWork.GetFlag(301) || !(SAV.FlagWork.GetWork(275) == 1 && SAV.Zukan.HasNationalDex && SAV.Items.GetItemQuantity(454) == 1); // HAIHUEVENT_ID_D18, Member Card
public bool UnlockReadyArceus => SAV.FlagWork.GetFlag(531) || !(SAV.FlagWork.GetWork(188) == 0 && SAV.Zukan.HasNationalDex && SAV.Items.GetItemQuantity(455) == 1 && SAV.FlagWork.GetSystemFlag(5)); // FE_D05R0116_LEGEND_CLEAR, Azure Flute
// 0 = inactive, 1 = roaming, 2 = KOed, 3 = captured
public bool UnlockReadyRoamerMesprit => SAV.Encounter.Roamer1Encount != 1;
@ -18,10 +18,10 @@ public class EventUnlocker8b : EventUnlocker<SAV8BS>
public void UnlockBoxLegend()
{
SAV.Work.SetFlag(308, false); // captured
SAV.Work.SetFlag(393, false); // clear vanish
SAV.Work.SetFlag(1623, false); // can retry
SAV.Work.SetWork(84, 5); // can retry
SAV.FlagWork.SetFlag(308, false); // captured
SAV.FlagWork.SetFlag(393, false); // clear vanish
SAV.FlagWork.SetFlag(1623, false); // can retry
SAV.FlagWork.SetWork(84, 5); // can retry
}
public void UnlockSpiritomb()
@ -34,29 +34,29 @@ public class EventUnlocker8b : EventUnlocker<SAV8BS>
public void UnlockShaymin()
{
SAV.Zukan.HasNationalDex = true; // dex
SAV.Work.SetSystemFlag(5, true); // clear
SAV.Work.SetWork(276, 1); // haihu
SAV.FlagWork.SetSystemFlag(5, true); // clear
SAV.FlagWork.SetWork(276, 1); // haihu
SAV.Items.SetItemQuantity(452, 1); // letter
SAV.Work.SetFlag(545, false); // clear vanish
SAV.FlagWork.SetFlag(545, false); // clear vanish
}
public void UnlockDarkrai()
{
SAV.Zukan.HasNationalDex = true; // dex
SAV.Work.SetWork(275, 1); // haihu
SAV.FlagWork.SetWork(275, 1); // haihu
SAV.Items.SetItemQuantity(454, 1); // member
SAV.Work.SetFlag(301, false); // clear vanish
SAV.FlagWork.SetFlag(301, false); // clear vanish
}
public void UnlockArceus()
{
SAV.Zukan.HasNationalDex = true; // dex
SAV.Items.SetItemQuantity(455, 1); // flute
SAV.Work.SetSystemFlag(5, true); // clear
SAV.Work.SetFlag(1508, true); // wildcard
SAV.Work.SetFlag(244, false); // captured
SAV.Work.SetFlag(531, false); // clear vanish
SAV.Work.SetWork(188, 0); // staircase
SAV.FlagWork.SetSystemFlag(5, true); // clear
SAV.FlagWork.SetFlag(1508, true); // wildcard
SAV.FlagWork.SetFlag(244, false); // captured
SAV.FlagWork.SetFlag(531, false); // clear vanish
SAV.FlagWork.SetWork(188, 0); // staircase
}
public void UnlockZones()
@ -66,16 +66,16 @@ public class EventUnlocker8b : EventUnlocker<SAV8BS>
for (int i = ZONE_START; i <= ZONE_END; i++)
{
SAV.Work.SetSystemFlag(i, true);
SAV.FlagWork.SetSystemFlag(i, true);
}
// uncover hidden zones
SAV.Work.SetWork(278, 1); // Fullmoon Island
SAV.Work.SetWork(279, 1); // Newmoon Island
SAV.Work.SetWork(280, 1); // Spring Path / Sendoff Spring
SAV.Work.SetWork(281, 1); // Seabreak Path / Flower Paradise
SAV.Work.SetWork(291, 1); // Pokémon League (Victory Road entrance)
SAV.Work.SetWork(292, 1); // Ramanas Park
SAV.FlagWork.SetWork(278, 1); // Fullmoon Island
SAV.FlagWork.SetWork(279, 1); // Newmoon Island
SAV.FlagWork.SetWork(280, 1); // Spring Path / Sendoff Spring
SAV.FlagWork.SetWork(281, 1); // Seabreak Path / Flower Paradise
SAV.FlagWork.SetWork(291, 1); // Pokémon League (Victory Road entrance)
SAV.FlagWork.SetWork(292, 1); // Ramanas Park
}
public void RespawnRoamer()
@ -86,15 +86,15 @@ public class EventUnlocker8b : EventUnlocker<SAV8BS>
public void RespawnMesprit()
{
SAV.Work.SetFlag(249, false); // clear met
SAV.Work.SetFlag(420, false); // clear vanish
SAV.FlagWork.SetFlag(249, false); // clear met
SAV.FlagWork.SetFlag(420, false); // clear vanish
SAV.Encounter.Roamer1Encount = 0; // not actively roaming
}
public void RespawnCresselia()
{
SAV.Work.SetFlag(245, false); // clear met
SAV.Work.SetFlag(532, false); // clear vanish
SAV.FlagWork.SetFlag(245, false); // clear met
SAV.FlagWork.SetFlag(532, false); // clear vanish
SAV.Encounter.Roamer2Encount = 0; // not actively roaming
}
}

View file

@ -36,7 +36,7 @@ public sealed class EventBlockDiff<T, T2> : IEventWorkDiff where T : IEventFlagA
Diff(t1, t2);
}
private EventWorkDiffCompatibility SanityCheckSaveInfo(T s1, T s2)
private static EventWorkDiffCompatibility SanityCheckSaveInfo(T s1, T s2)
{
if (s1.GetType() != s2.GetType())
return DifferentGameGroup;
@ -74,9 +74,9 @@ public sealed class EventBlockDiff<T, T2> : IEventWorkDiff where T : IEventFlagA
public IReadOnlyList<string> Summarize()
{
var fOn = SetFlags.Select(z => z.ToString());
var fOff = ClearedFlags.Select(z => z.ToString());
var wt = WorkChanged.Select((z, _) => z.ToString());
var fOn = SetFlags.Select(z => $"{z}");
var fOff = ClearedFlags.Select(z => $"{z}");
var wt = WorkChanged.Select((z, _) => $"{z}");
var list = new List<string> { "Flags: ON", "=========" };
list.AddRange(fOn);

View file

@ -46,9 +46,9 @@ public sealed class EventWorkDiff8b : IEventWorkDiff
return;
}
DiffSavesFlag(s1.Work, s2.Work, SetFlags, ClearedFlags);
DiffSavesSystem(s1.Work, s2.Work, SetSystem, ClearedSystem);
DiffSavesWork(s1.Work, s2.Work, WorkChanged, WorkDiff);
DiffSavesFlag(s1.FlagWork, s2.FlagWork, SetFlags, ClearedFlags);
DiffSavesSystem(s1.FlagWork, s2.FlagWork, SetSystem, ClearedSystem);
DiffSavesWork(s1.FlagWork, s2.FlagWork, WorkChanged, WorkDiff);
S1 = s1;
}

View file

@ -1,16 +1,15 @@
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Event Flag that toggles certain features / entities on and off.
/// </summary>
public sealed class EventFlag : EventVar
{
/// <summary>
/// Event Flag that toggles certain features / entities on and off.
/// </summary>
public sealed class EventFlag : EventVar
{
public bool Flag;
public EventFlag(int index, EventVarType t, IReadOnlyList<string> pieces) : base(index, t, pieces[1])
{
}
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Event variable used to determine game events.
/// </summary>
public abstract class EventVar
{
/// <summary>
/// Event variable used to determine game events.
/// </summary>
public abstract class EventVar
{
/// <summary>
/// Name of event variable
/// </summary>
@ -31,5 +31,4 @@ namespace PKHeX.Core
Type = t;
Name = name;
}
}
}

View file

@ -1,12 +1,11 @@
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
public sealed class EventVarGroup
{
public sealed class EventVarGroup
{
public readonly EventVarType Type;
public readonly List<EventVar> Vars = new();
public EventVarGroup(EventVarType type) => Type = type;
}
}

View file

@ -1,14 +1,14 @@
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Event number storage for more complex logic events.
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class EventWork<T> : EventVar where T : struct
{
/// <summary>
/// Event number storage for more complex logic events.
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class EventWork<T> : EventVar where T : struct
{
public T Value;
public readonly IList<EventWorkVal> Options = new List<EventWorkVal> { new() };
@ -28,5 +28,4 @@ namespace PKHeX.Core
Options.Add(new EventWorkVal(s[1], value));
}
}
}
}

View file

@ -4,13 +4,13 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using static PKHeX.Core.MessageStrings;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Provides utility for various <see cref="EventWork{T}"/> logic.
/// </summary>
public static class EventWorkUtil
{
/// <summary>
/// Provides utility for various <see cref="EventWork{T}"/> logic.
/// </summary>
public static class EventWorkUtil
{
private static readonly Dictionary<char, EventVarType> TypeDict = new()
{
['z'] = EventVarType.Zone,
@ -147,5 +147,4 @@ namespace PKHeX.Core
Message = null;
return true;
}
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Represents a known value for a <see cref="EventWork{T}"/> of type <see cref="int"/>.
/// </summary>
public sealed class EventWorkVal
{
/// <summary>
/// Represents a known value for a <see cref="EventWork{T}"/> of type <see cref="int"/>.
/// </summary>
public sealed class EventWorkVal
{
public readonly bool Custom;
public readonly string Text;
public readonly int Value;
@ -21,5 +21,4 @@
Text = text;
Value = val;
}
}
}

View file

@ -1,14 +1,14 @@
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Editor object that unpacks <see cref="EventWork{T}"/> into flags & work groups, and handles value get/set operations.
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class SplitEventEditor<T> where T : struct
{
/// <summary>
/// Editor object that unpacks <see cref="EventWork{T}"/> into flags & work groups, and handles value get/set operations.
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class SplitEventEditor<T> where T : struct
{
public readonly IList<EventVarGroup> Work;
public readonly IList<EventVarGroup> Flag;
public readonly IEventVar<T> Block;
@ -63,5 +63,4 @@ namespace PKHeX.Core
}
}
}
}
}

View file

@ -1,9 +1,8 @@
namespace PKHeX.Core
namespace PKHeX.Core;
public interface INamedFolderPath
{
public interface INamedFolderPath
{
string Path { get; }
string DisplayText { get; }
bool Custom { get; }
}
}

View file

@ -1,13 +1,14 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Bindable Summary of a <see cref="SaveFile"/> for use in a sortable table.
/// </summary>
public sealed class SavePreview
{
/// <summary>
/// Bindable Summary of a <see cref="SaveFile"/> for use in a sortable table.
/// </summary>
public sealed class SavePreview
{
public readonly SaveFile Save;
public readonly string FilePath;
@ -23,7 +24,7 @@ namespace PKHeX.Core
var meta = sav.Metadata;
var dir = meta.FileFolder;
const string notFound = "???";
var parent = dir == null ? notFound : paths.Find(z => dir.StartsWith(z.Path))?.DisplayText ?? new DirectoryInfo(dir).Name;
var parent = dir == null ? notFound : paths.Find(z => dir.StartsWith(z.Path, StringComparison.Ordinal))?.DisplayText ?? new DirectoryInfo(dir).Name;
Save = sav;
Folder = parent;
@ -45,5 +46,4 @@ namespace PKHeX.Core
public string Folder { get; }
public string Name => Path.GetFileName(FilePath);
}
}

View file

@ -1,12 +1,12 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Represents a Box Editor that loads the contents for easy manipulation.
/// </summary>
public sealed class BoxEdit
{
/// <summary>
/// Represents a Box Editor that loads the contents for easy manipulation.
/// </summary>
public sealed class BoxEdit
{
private readonly SaveFile SAV;
private readonly PKM[] CurrentContents;
@ -54,5 +54,4 @@ namespace PKHeX.Core
LoadBox(newBox);
return newBox;
}
}
}

View file

@ -1,9 +1,9 @@
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
public static partial class Extensions
{
public static partial class Extensions
{
public static IReadOnlyList<PKM> GetAllPKM(this SaveFile sav)
{
var result = new List<PKM>();
@ -224,5 +224,4 @@ namespace PKHeX.Core
{
return new List<SlotInfoMisc>();
}
}
}

View file

@ -1,13 +1,13 @@
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Slot Viewer that shows many slots of <see cref="PKM"/> data.
/// </summary>
/// <typeparam name="T">Object that displays the <see cref="PKM"/> slot.</typeparam>
public interface ISlotViewer<T>
{
/// <summary>
/// Slot Viewer that shows many slots of <see cref="PKM"/> data.
/// </summary>
/// <typeparam name="T">Object that displays the <see cref="PKM"/> slot.</typeparam>
public interface ISlotViewer<T>
{
/// <summary>
/// Current index the viewer is viewing.
/// </summary>
@ -24,21 +24,19 @@ namespace PKHeX.Core
/// </summary>
/// <param name="slot">Last interacted slot</param>
/// <param name="type">Last interacted slot interaction type</param>
/// <param name="pkm">Last interacted slot interaction data</param>
void NotifySlotChanged(ISlotInfo slot, SlotTouchType type, PKM pkm);
/// <param name="pk">Last interacted slot interaction data</param>
void NotifySlotChanged(ISlotInfo slot, SlotTouchType type, PKM pk);
/// <summary>
/// Gets the information for the requested slot's view picture.
/// </summary>
/// <param name="view"></param>
/// <returns></returns>
ISlotInfo GetSlotData(T view);
/// <summary>
/// Gets the index of the <see cref="T"/> view within the <see cref="ISlotViewer{T}"/>'s list of slots.
/// </summary>
/// <param name="slot"></param>
/// <returns></returns>
int GetViewIndex(ISlotInfo slot);
/// <summary>
@ -50,5 +48,4 @@ namespace PKHeX.Core
/// Save data the <see cref="ISlotViewer{T}"/> is showing data from.
/// </summary>
SaveFile SAV { get; }
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Data representing info for an individual slot.
/// </summary>
public interface ISlotInfo
{
/// <summary>
/// Data representing info for an individual slot.
/// </summary>
public interface ISlotInfo
{
/// <summary>
/// Indicates the type of format the slot originates. Useful for legality purposes.
/// </summary>
@ -23,26 +23,25 @@ namespace PKHeX.Core
bool CanWriteTo(SaveFile sav);
/// <summary>
/// Checks if the <see cref="pkm"/> can be written to the <see cref="sav"/> for this slot.
/// Checks if the <see cref="pk"/> can be written to the <see cref="sav"/> for this slot.
/// </summary>
/// <param name="sav">Save file to try writing to.</param>
/// <param name="pkm">Entity data to try writing.</param>
/// <param name="pk">Entity data to try writing.</param>
/// <returns>True if can write to</returns>
WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pkm);
WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk);
/// <summary>
/// Tries writing the <see cref="pkm"/> to the <see cref="sav"/>.
/// Tries writing the <see cref="pk"/> to the <see cref="sav"/>.
/// </summary>
/// <param name="sav">Save file to try writing to.</param>
/// <param name="pkm">Entity data to try writing.</param>
/// <param name="setting">Setting to use when importing the <see cref="pkm"/> data</param>
/// <param name="pk">Entity data to try writing.</param>
/// <param name="setting">Setting to use when importing the <see cref="pk"/> data</param>
/// <returns>Returns false if it did not succeed.</returns>
bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault);
bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault);
/// <summary>
/// Reads a <see cref="PKM"/> from the <see cref="sav"/>.
/// </summary>
/// <param name="sav">Save file to read from.</param>
PKM Read(SaveFile sav);
}
}

View file

@ -1,12 +1,12 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Contains slot data and metadata indicating where the <see cref="PKM"/> originated from.
/// </summary>
public sealed class SlotCache : IComparable<SlotCache>
{
/// <summary>
/// Contains slot data and metadata indicating where the <see cref="PKM"/> originated from.
/// </summary>
public sealed class SlotCache : IComparable<SlotCache>
{
/// <summary>
/// Information regarding how the <see cref="Entity"/> was obtained.
/// </summary>
@ -91,5 +91,4 @@ namespace PKHeX.Core
return c2;
return CompareTo(other);
}
}
}

View file

@ -1,20 +1,19 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Box Data <see cref="ISlotInfo"/>
/// </summary>
public sealed record SlotInfoBox(int Box, int Slot) : ISlotInfo
{
/// <summary>
/// Box Data <see cref="ISlotInfo"/>
/// </summary>
public sealed record SlotInfoBox(int Box, int Slot) : ISlotInfo
{
public SlotOrigin Origin => SlotOrigin.Box;
public bool CanWriteTo(SaveFile sav) => sav.HasBox && !sav.IsSlotLocked(Box, Slot);
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pkm) => WriteBlockedMessage.None;
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk) => WriteBlockedMessage.None;
public bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault)
public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault)
{
sav.SetBoxSlotAtIndex(pkm, Box, Slot, setting, setting);
sav.SetBoxSlotAtIndex(pk, Box, Slot, setting, setting);
return true;
}
public PKM Read(SaveFile sav) => sav.GetBoxSlotAtIndex(Box, Slot);
}
}

View file

@ -1,13 +1,12 @@
namespace PKHeX.Core
namespace PKHeX.Core;
public sealed record SlotInfoFile(string Path) : ISlotInfo
{
public sealed record SlotInfoFile(string Path) : ISlotInfo
{
public SlotOrigin Origin => SlotOrigin.Party;
public int Slot => 0;
public bool CanWriteTo(SaveFile sav) => false;
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pkm) => WriteBlockedMessage.InvalidDestination;
public bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault) => false;
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk) => WriteBlockedMessage.InvalidDestination;
public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault) => false;
public PKM Read(SaveFile sav) => sav.BlankPKM;
}
}

View file

@ -2,10 +2,10 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
namespace PKHeX.Core
namespace PKHeX.Core;
public static class SlotInfoLoader
{
public static class SlotInfoLoader
{
// The "Add" method isn't shared for any interface... so we'll just do this twice.
#region ConcurrentBag Implementation
@ -157,5 +157,4 @@ namespace PKHeX.Core
}
}
#endregion
}
}

View file

@ -1,13 +1,13 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Miscellaneous origination <see cref="ISlotInfo"/>
/// </summary>
public sealed record SlotInfoMisc(byte[] Data, int Slot, int Offset, bool PartyFormat = false) : ISlotInfo
{
/// <summary>
/// Miscellaneous origination <see cref="ISlotInfo"/>
/// </summary>
public sealed record SlotInfoMisc(byte[] Data, int Slot, int Offset, bool PartyFormat = false) : ISlotInfo
{
public SlotOrigin Origin => PartyFormat ? SlotOrigin.Party : SlotOrigin.Box;
public bool CanWriteTo(SaveFile sav) => false;
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pkm) => WriteBlockedMessage.InvalidDestination;
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk) => WriteBlockedMessage.InvalidDestination;
public StorageSlotType Type { get; init; }
public SlotInfoMisc(SaveFile sav, int slot, int offset, bool party = false) : this(GetBuffer(sav), slot, offset, party) { }
@ -19,12 +19,12 @@ namespace PKHeX.Core
_ => sav.Data,
};
public bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault)
public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault)
{
if (PartyFormat)
sav.SetSlotFormatParty(pkm, Data, Offset, setting, setting);
sav.SetSlotFormatParty(pk, Data, Offset, setting, setting);
else
sav.SetSlotFormatStored(pkm, Data, Offset, setting, setting);
sav.SetSlotFormatStored(pk, Data, Offset, setting, setting);
return true;
}
@ -32,5 +32,4 @@ namespace PKHeX.Core
{
return PartyFormat ? sav.GetPartySlot(Data, Offset) : sav.GetStoredSlot(Data, Offset);
}
}
}

View file

@ -1,33 +1,32 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Party Data <see cref="ISlotInfo"/>
/// </summary>
public sealed record SlotInfoParty(int Slot) : ISlotInfo
{
/// <summary>
/// Party Data <see cref="ISlotInfo"/>
/// </summary>
public sealed record SlotInfoParty(int Slot) : ISlotInfo
{
public int Slot { get; private set; } = Slot;
public SlotOrigin Origin => SlotOrigin.Party;
public bool CanWriteTo(SaveFile sav) => sav.HasParty;
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pkm) => pkm.IsEgg && sav.IsPartyAllEggs(Slot)
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk) => pk.IsEgg && sav.IsPartyAllEggs(Slot)
? WriteBlockedMessage.InvalidPartyConfiguration
: WriteBlockedMessage.None;
public bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault)
public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault)
{
if (pkm.Species == 0)
if (pk.Species == 0)
{
sav.DeletePartySlot(Slot);
Slot = Math.Max(0, sav.PartyCount - 1);
return true;
}
Slot = Math.Min(Slot, sav.PartyCount); // realign if necessary
sav.SetPartySlotAtIndex(pkm, Slot, setting, setting);
sav.SetPartySlotAtIndex(pk, Slot, setting, setting);
return true;
}
public PKM Read(SaveFile sav) => sav.GetPartySlotAtIndex(Slot);
}
}

View file

@ -1,8 +1,7 @@
namespace PKHeX.Core
namespace PKHeX.Core;
public enum SlotOrigin : byte
{
public enum SlotOrigin : byte
{
Party = 0,
Box = 1,
}
}

View file

@ -1,13 +1,12 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Message enumeration indicating why a Write Operation would be blocked for a given <see cref="ISlotInfo"/>
/// </summary>
public enum WriteBlockedMessage
{
/// <summary>
/// Message enumeration indicating why a Write Operation would be blocked for a given <see cref="ISlotInfo"/>
/// </summary>
public enum WriteBlockedMessage
{
None,
InvalidPartyConfiguration,
IncompatibleFormat,
InvalidDestination,
}
}

View file

@ -1,12 +1,12 @@
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Tracks <see cref="PKM"/> slot changes and provides the ability to revert a change.
/// </summary>
public sealed class SlotChangelog
{
/// <summary>
/// Tracks <see cref="PKM"/> slot changes and provides the ability to revert a change.
/// </summary>
public sealed class SlotChangelog
{
private readonly SaveFile SAV;
private readonly Stack<SlotReversion> UndoStack = new();
private readonly Stack<SlotReversion> RedoStack = new();
@ -80,5 +80,4 @@ namespace PKHeX.Core
public override void Revert(SaveFile sav) => Info.WriteTo(sav, Entity, PKMImportSetting.Skip);
}
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Facilitates interaction with a <see cref="SaveFile"/> or other data location's slot data.
/// </summary>
public sealed class SlotEditor<T>
{
/// <summary>
/// Facilitates interaction with a <see cref="SaveFile"/> or other data location's slot data.
/// </summary>
public sealed class SlotEditor<T>
{
private readonly SaveFile SAV;
public readonly SlotChangelog Changelog;
public readonly SlotPublisher<T> Publisher;
@ -16,7 +16,7 @@
Publisher = new SlotPublisher<T>();
}
private void NotifySlotChanged(ISlotInfo slot, SlotTouchType type, PKM pkm) => Publisher.NotifySlotChanged(slot, type, pkm);
private void NotifySlotChanged(ISlotInfo slot, SlotTouchType type, PKM pk) => Publisher.NotifySlotChanged(slot, type, pk);
/// <summary>
/// Gets data from a slot.
@ -35,16 +35,16 @@
/// Sets data to a slot.
/// </summary>
/// <param name="slot">Slot to be set to.</param>
/// <param name="pkm">Data to set.</param>
/// <param name="pk">Data to set.</param>
/// <param name="type">Type of slot action</param>
/// <returns>Operation succeeded or not via enum value.</returns>
public SlotTouchResult Set(ISlotInfo slot, PKM pkm, SlotTouchType type = SlotTouchType.Set)
public SlotTouchResult Set(ISlotInfo slot, PKM pk, SlotTouchType type = SlotTouchType.Set)
{
if (!slot.CanWriteTo(SAV))
return SlotTouchResult.FailWrite;
WriteSlot(slot, pkm, type);
NotifySlotChanged(slot, type, pkm);
WriteSlot(slot, pk, type);
NotifySlotChanged(slot, type, pk);
return SlotTouchResult.Success;
}
@ -84,20 +84,20 @@
return SlotTouchResult.Success;
}
private void WriteSlot(ISlotInfo slot, PKM pkm, SlotTouchType type = SlotTouchType.Set)
private void WriteSlot(ISlotInfo slot, PKM pk, SlotTouchType type = SlotTouchType.Set)
{
Changelog.AddNewChange(slot);
var setDetail = type is SlotTouchType.Swap ? PKMImportSetting.Skip : PKMImportSetting.UseDefault;
var result = slot.WriteTo(SAV, pkm, setDetail);
var result = slot.WriteTo(SAV, pk, setDetail);
if (result)
NotifySlotChanged(slot, type, pkm);
NotifySlotChanged(slot, type, pk);
}
private PKM DeleteSlot(ISlotInfo slot)
{
var pkm = SAV.BlankPKM;
WriteSlot(slot, pkm, SlotTouchType.Delete);
return pkm;
var pk = SAV.BlankPKM;
WriteSlot(slot, pk, SlotTouchType.Delete);
return pk;
}
public void Undo()
@ -115,5 +115,4 @@
var slot = Changelog.Redo();
NotifySlotChanged(slot, SlotTouchType.Set, slot.Read(SAV));
}
}
}

View file

@ -1,12 +1,12 @@
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Pushes slot update notifications out to all subscribers.
/// </summary>
public sealed class SlotPublisher<T>
{
/// <summary>
/// Pushes slot update notifications out to all subscribers.
/// </summary>
public sealed class SlotPublisher<T>
{
/// <summary>
/// All <see cref="ISlotViewer{T}"/> instances that provide a view on individual <see cref="ISlotInfo"/> content.
/// </summary>
@ -21,23 +21,23 @@ namespace PKHeX.Core
/// </summary>
/// <param name="slot">Last interacted slot</param>
/// <param name="type">Last interacted slot interaction type</param>
/// <param name="pkm">Last interacted slot interaction data</param>
public void NotifySlotChanged(ISlotInfo slot, SlotTouchType type, PKM pkm)
/// <param name="pk">Last interacted slot interaction data</param>
public void NotifySlotChanged(ISlotInfo slot, SlotTouchType type, PKM pk)
{
foreach (var sub in Subscribers)
ResetView(sub, slot, type, pkm);
ResetView(sub, slot, type, pk);
Previous = slot;
PreviousType = type;
PreviousEntity = pkm;
PreviousEntity = pk;
}
private void ResetView(ISlotViewer<T> sub, ISlotInfo slot, SlotTouchType type, PKM pkm)
private void ResetView(ISlotViewer<T> sub, ISlotInfo slot, SlotTouchType type, PKM pk)
{
if (Previous != null)
sub.NotifySlotOld(Previous);
if (slot is not SlotInfoBox b || sub.ViewIndex == b.Box)
sub.NotifySlotChanged(slot, type, pkm);
sub.NotifySlotChanged(slot, type, pk);
}
public void ResetView(ISlotViewer<T> sub)
@ -46,5 +46,4 @@ namespace PKHeX.Core
return;
ResetView(sub, Previous, PreviousType, PreviousEntity);
}
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Result indicators for modifying a Slot within a <see cref="SaveFile"/> or other data location.
/// </summary>
public enum SlotTouchResult
{
/// <summary>
/// Result indicators for modifying a Slot within a <see cref="SaveFile"/> or other data location.
/// </summary>
public enum SlotTouchResult
{
/// <summary>
/// Slot interaction was successful.
/// </summary>
@ -34,5 +34,4 @@
/// Slot interaction failed due to a bad/unmodifiable destination.
/// </summary>
FailDestination,
}
}

View file

@ -1,16 +1,15 @@
namespace PKHeX.Core
namespace PKHeX.Core;
public enum SlotTouchType
{
public enum SlotTouchType
{
None,
Get,
Set,
Delete,
Swap,
}
public static class SlotTouchTypeUtil
{
public static bool IsContentChange(this SlotTouchType t) => t > SlotTouchType.Get;
}
}
public static class SlotTouchTypeUtil
{
public static bool IsContentChange(this SlotTouchType t) => t > SlotTouchType.Get;
}

View file

@ -1,19 +1,19 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Tuple containing data for a <see cref="Slot"/> and the originating <see cref="View"/>
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class SlotViewInfo<T> : IEquatable<T>
{
/// <summary>
/// Tuple containing data for a <see cref="Slot"/> and the originating <see cref="View"/>
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class SlotViewInfo<T> : IEquatable<T>
{
public readonly ISlotInfo Slot;
public readonly ISlotViewer<T> View;
public PKM ReadCurrent() => Slot.Read(View.SAV);
public bool CanWriteTo() => Slot.CanWriteTo(View.SAV);
public WriteBlockedMessage CanWriteTo(PKM pkm) => Slot.CanWriteTo(View.SAV, pkm);
public WriteBlockedMessage CanWriteTo(PKM pk) => Slot.CanWriteTo(View.SAV, pk);
public SlotViewInfo(ISlotInfo slot, ISlotViewer<T> view)
{
@ -35,5 +35,4 @@ namespace PKHeX.Core
public override bool Equals(object obj) => ReferenceEquals(this, obj) || (obj is SlotViewInfo<T> other && Equals(other));
public override int GetHashCode() => (Slot.GetHashCode() * 397) ^ View.GetHashCode();
bool IEquatable<T>.Equals(T other) => other != null && Equals(other);
}
}

View file

@ -1,7 +1,7 @@
namespace PKHeX.Core
namespace PKHeX.Core;
public enum StorageSlotType
{
public enum StorageSlotType
{
Box,
Party,
BattleBox,
@ -10,5 +10,4 @@
Fused,
Misc,
Resort,
}
}

View file

@ -1,15 +1,15 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using static PKHeX.Core.Species;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for parsing details for <see cref="ShowdownSet"/> objects.
/// </summary>
public static class ShowdownParsing
{
/// <summary>
/// Logic for parsing details for <see cref="ShowdownSet"/> objects.
/// </summary>
public static class ShowdownParsing
{
private static readonly string[] genderForms = { "", "F", "" };
/// <summary>
@ -36,7 +36,6 @@ namespace PKHeX.Core
/// <param name="strings"></param>
/// <param name="species"></param>
/// <param name="format"></param>
/// <returns></returns>
public static string GetStringFromForm(int form, GameStrings strings, int species, int format)
{
if (form <= 0)
@ -69,7 +68,7 @@ namespace PKHeX.Core
(int)Basculin when form is "Blue" => "Blue-Striped",
(int)Vivillon when form is "Poké Ball" => "Pokeball",
(int)Zygarde => form.Replace("-C", string.Empty).Replace("50%", string.Empty),
(int)Minior when form.StartsWith("M-") => MiniorFormName,
(int)Minior when form.StartsWith("M-", StringComparison.Ordinal) => MiniorFormName,
(int)Minior => form.Replace("C-", string.Empty),
(int)Necrozma when form is "Dusk" => $"{form}-Mane",
(int)Necrozma when form is "Dawn" => $"{form}-Wings",
@ -109,7 +108,7 @@ namespace PKHeX.Core
(int)Rockruff when ability == 020 => "Dusk", // Rockruff-1
(int)Urshifu or (int)Pikachu or (int)Alcremie => form.Replace('-', ' '), // Strike and Cosplay
_ => Legal.Totem_USUM.Contains(species) && form.EndsWith("Totem") ? "Large" : form,
_ => Legal.Totem_USUM.Contains(species) && form.EndsWith("Totem", StringComparison.Ordinal) ? "Large" : form,
};
}
@ -142,13 +141,13 @@ namespace PKHeX.Core
/// <summary>
/// Converts the <see cref="PKM"/> data into an importable set format for Pokémon Showdown.
/// </summary>
/// <param name="pkm">PKM to convert to string</param>
/// <param name="pk">PKM to convert to string</param>
/// <returns>Multi line set data</returns>
public static string GetShowdownText(PKM pkm)
public static string GetShowdownText(PKM pk)
{
if (pkm.Species == 0)
if (pk.Species == 0)
return string.Empty;
return new ShowdownSet(pkm).Text;
return new ShowdownSet(pk).Text;
}
/// <summary>
@ -179,5 +178,4 @@ namespace PKHeX.Core
set.Nature = Experience.GetNatureVC(pk.EXP);
return set.LocalizedText(language);
}
}
}

View file

@ -2,13 +2,13 @@
using System.Collections.Generic;
using static PKHeX.Core.Species;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Logic for exporting and importing <see cref="PKM"/> data in Pokémon Showdown's text format.
/// </summary>
public sealed class ShowdownSet : IBattleTemplate
{
/// <summary>
/// Logic for exporting and importing <see cref="PKM"/> data in Pokémon Showdown's text format.
/// </summary>
public sealed class ShowdownSet : IBattleTemplate
{
private static readonly string[] StatNames = { "HP", "Atk", "Def", "SpA", "SpD", "Spe" };
private static readonly string[] Splitters = {"\r\n", "\n"};
private static readonly string[] StatSplitters = { " / ", " " };
@ -184,7 +184,7 @@ namespace PKHeX.Core
private bool ParseSingle(string identifier)
{
if (!identifier.EndsWith("Nature"))
if (!identifier.EndsWith("Nature", StringComparison.Ordinal))
return false;
var naturestr = identifier.Split(' ')[0].Trim();
return (Nature = StringUtil.FindIndexIgnoreCase(Strings.natures, naturestr)) >= 0;
@ -358,42 +358,42 @@ namespace PKHeX.Core
/// <summary>
/// Converts the <see cref="PKM"/> data into an importable set format for Pokémon Showdown.
/// </summary>
/// <param name="pkm">PKM to convert to string</param>
/// <returns>New ShowdownSet object representing the input <see cref="pkm"/></returns>
public ShowdownSet(PKM pkm)
/// <param name="pk">PKM to convert to string</param>
/// <returns>New ShowdownSet object representing the input <see cref="pk"/></returns>
public ShowdownSet(PKM pk)
{
if (pkm.Species <= 0)
if (pk.Species <= 0)
return;
Format = pkm.Format;
Format = pk.Format;
Nickname = pkm.Nickname;
Species = pkm.Species;
HeldItem = pkm.HeldItem;
Ability = pkm.Ability;
EVs = pkm.EVs;
IVs = pkm.IVs;
Moves = pkm.Moves;
Nature = pkm.StatNature;
Gender = pkm.Gender < 2 ? pkm.Gender : 2;
Friendship = pkm.CurrentFriendship;
Level = Experience.GetLevel(pkm.EXP, pkm.PersonalInfo.EXPGrowth);
Shiny = pkm.IsShiny;
Nickname = pk.Nickname;
Species = pk.Species;
HeldItem = pk.HeldItem;
Ability = pk.Ability;
EVs = pk.EVs;
IVs = pk.IVs;
Moves = pk.Moves;
Nature = pk.StatNature;
Gender = pk.Gender < 2 ? pk.Gender : 2;
Friendship = pk.CurrentFriendship;
Level = Experience.GetLevel(pk.EXP, pk.PersonalInfo.EXPGrowth);
Shiny = pk.IsShiny;
if (pkm is IGigantamax g)
if (pk is IGigantamax g)
CanGigantamax = g.CanGigantamax;
HiddenPowerType = HiddenPower.GetType(IVs, Format);
if (pkm is IHyperTrain h)
if (pk is IHyperTrain h)
{
for (int i = 0; i < 6; i++)
{
if (h.IsHyperTrained(i))
IVs[i] = pkm.MaxIV;
IVs[i] = pk.MaxIV;
}
}
FormName = ShowdownParsing.GetStringFromForm(Form = pkm.Form, Strings, Species, Format);
FormName = ShowdownParsing.GetStringFromForm(Form = pk.Form, Strings, Species, Format);
}
private void ParseFirstLine(string first)
@ -437,12 +437,12 @@ namespace PKHeX.Core
private void ParseFirstLineNoItem(string line)
{
// Gender Detection
if (line.EndsWith("(M)"))
if (line.EndsWith("(M)", StringComparison.Ordinal))
{
line = line[..^3];
Gender = 0;
}
else if (line.EndsWith("(F)"))
else if (line.EndsWith("(F)", StringComparison.Ordinal))
{
line = line[..^3];
Gender = 1;
@ -463,7 +463,7 @@ namespace PKHeX.Core
if (speciesLine.Length == 0)
return false;
if (speciesLine.EndsWith(Gmax))
if (speciesLine.EndsWith(Gmax, StringComparison.Ordinal))
{
CanGigantamax = true;
speciesLine = speciesLine[..^Gmax.Length];
@ -487,7 +487,7 @@ namespace PKHeX.Core
foreach (var e in DashedSpecies)
{
var sn = Strings.Species[e];
if (!speciesLine.StartsWith(sn.Replace("♂", "-M").Replace("♀", "-F")))
if (!speciesLine.StartsWith(sn.Replace("♂", "-M").Replace("♀", "-F"), StringComparison.Ordinal))
continue;
Species = e;
FormName = speciesLine[sn.Length..];
@ -539,13 +539,16 @@ namespace PKHeX.Core
private string ParseLineMove(string line)
{
const int hiddenPower = 237;
string moveString = line[(line[1] == ' ' ? 2 : 1)..].Split('/')[0].Trim();
if (!moveString.StartsWith(Strings.Move[hiddenPower])) // Hidden Power
const int hiddenPower = 237;
var hiddenPowerName = Strings.Move[hiddenPower];
if (!moveString.StartsWith(hiddenPowerName, StringComparison.Ordinal)) // Hidden Power
return moveString; // regular move
// Assumes English...
if (moveString.Length <= 13)
return Strings.Move[hiddenPower];
return hiddenPowerName;
// Defined Hidden Power
string type = moveString[13..];
@ -625,5 +628,4 @@ namespace PKHeX.Core
.Replace("SDef", "SpD").Replace("Sp Def", "SpD")
.Replace("Spd", "Spe").Replace("Speed", "Spe").Split(StatSplitters, StringSplitOptions.None);
}
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Indicates or coerces values pertaining to <see cref="Species.Wurmple"/> and its branched evolutions.
/// </summary>
public static class WurmpleUtil
{
/// <summary>
/// Indicates or coerces values pertaining to <see cref="Species.Wurmple"/> and its branched evolutions.
/// </summary>
public static class WurmpleUtil
{
/// <summary>
/// Gets the Wurmple Evolution Value for a given <see cref="PKM.EncryptionConstant"/>
/// </summary>
@ -45,15 +45,14 @@
}
/// <summary>
/// Checks to see if the input <see cref="pkm"/>, with species being that of Wurmple's evo chain, is valid.
/// Checks to see if the input <see cref="pk"/>, with species being that of Wurmple's evo chain, is valid.
/// </summary>
/// <param name="pkm">Pokémon data</param>
/// <param name="pk">Pokémon data</param>
/// <returns>True if valid, false if invalid</returns>
public static bool IsWurmpleEvoValid(PKM pkm)
public static bool IsWurmpleEvoValid(PKM pk)
{
uint evoVal = GetWurmpleEvoVal(pkm.EncryptionConstant);
int wIndex = GetWurmpleEvoGroup(pkm.Species);
uint evoVal = GetWurmpleEvoVal(pk.EncryptionConstant);
int wIndex = GetWurmpleEvoGroup(pk.Species);
return evoVal == wIndex;
}
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Ability IDs for the corresponding English ability name.
/// </summary>
public enum Ability
{
/// <summary>
/// Ability IDs for the corresponding English ability name.
/// </summary>
public enum Ability
{
None,
Stench,
Drizzle,
@ -274,5 +274,4 @@
AsOneI,
AsOneG,
MAX_COUNT,
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Ball IDs for the corresponding English ball name.
/// </summary>
public enum Ball : byte
{
/// <summary>
/// Ball IDs for the corresponding English ball name.
/// </summary>
public enum Ball : byte
{
None = 0,
Master = 1,
@ -51,15 +51,14 @@ namespace PKHeX.Core
LALeaden = 35,
LAGigaton = 36,
LAOrigin = 37,
}
}
public static class BallExtensions
{
public static class BallExtensions
{
/// <summary>
/// Checks if the <see cref="ball"/> is an Apricorn Ball (HG/SS)
/// </summary>
/// <param name="ball">Ball ID</param>
/// <returns>True if Apricorn, false if not.</returns>
public static bool IsApricornBall(this Ball ball) => ball is >= Ball.Fast and <= Ball.Moon;
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// <see cref="GameVersion"/> analogues used by Colosseum/XD instead of the main-series values.
/// </summary>
public enum GCVersion : byte
{
/// <summary>
/// <see cref="GameVersion"/> analogues used by Colosseum/XD instead of the main-series values.
/// </summary>
public enum GCVersion : byte
{
None = 0,
FR = 1,
LG = 2,
@ -12,10 +12,10 @@
R = 9,
E = 10,
CXD = 11,
}
}
public static class GCVersionExtensions
{
public static class GCVersionExtensions
{
/// <summary>
/// Translates a main-series <see cref="GameVersion"/> to the corresponding <see cref="GCVersion"/> value.
/// </summary>
@ -47,5 +47,4 @@
GCVersion.CXD => GameVersion.CXD,
_ => GameVersion.Unknown,
};
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Game Version ID enum shared between actual Version IDs and lumped version groupings.
/// </summary>
public enum GameVersion
{
/// <summary>
/// Game Version ID enum shared between actual Version IDs and lumped version groupings.
/// </summary>
public enum GameVersion
{
#region Indicators for method empty arguments & result indication. Not stored values.
Invalid = -2,
Any = -1,
@ -221,7 +221,7 @@
SP = 49,
#endregion
// The following values are not actually stored values in pkm data,
// The following values are not actually stored values in pk data,
// These values are assigned within PKHeX as properties for various logic branching.
#region Game Groupings (SaveFile type, roughly)
@ -481,5 +481,4 @@
/// </summary>
Stadium2,
#endregion
}
}

View file

@ -1,15 +1,14 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Gender a <see cref="PKM"/> can have
/// </summary>
/// <remarks><see cref="Random"/> provided to function for Encounter template values</remarks>
public enum Gender : byte
{
/// <summary>
/// Gender a <see cref="PKM"/> can have
/// </summary>
/// <remarks><see cref="Random"/> provided to function for Encounter template values</remarks>
public enum Gender : byte
{
Male = 0,
Female = 1,
Genderless = 2,
Random = Genderless,
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// <see cref="GameVersion.CXD"/> Game Language IDs
/// </summary>
public enum LanguageGC : byte
{
/// <summary>
/// <see cref="GameVersion.CXD"/> Game Language IDs
/// </summary>
public enum LanguageGC : byte
{
/// <summary>
/// Undefined Language ID, usually indicative of a value not being set.
/// </summary>
@ -46,5 +46,4 @@
/// </summary>
/// <remarks>Was reserved for Korean in Gen3 but never utilized.</remarks>
UNUSED_6 = 7,
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Contiguous series Game Language IDs
/// </summary>
public enum LanguageID : byte
{
/// <summary>
/// Contiguous series Game Language IDs
/// </summary>
public enum LanguageID : byte
{
/// <summary>
/// Undefined Language ID, usually indicative of a value not being set.
/// </summary>
@ -61,5 +61,4 @@
/// Chinese Traditional (繁體中文)
/// </summary>
ChineseT = 10,
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Move IDs for the corresponding English move name.
/// </summary>
public enum Move
{
/// <summary>
/// Move IDs for the corresponding English move name.
/// </summary>
public enum Move
{
None,
Pound,
KarateChop,
@ -857,5 +857,4 @@
LunarBlessing,
TakeHeart,
MAX_COUNT,
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Elemental type a move has; additionally, types a <see cref="PKM"/> can have.
/// </summary>
public enum MoveType : sbyte
{
/// <summary>
/// Elemental type a move has; additionally, types a <see cref="PKM"/> can have.
/// </summary>
public enum MoveType : sbyte
{
Any = -1,
Normal,
Fighting,
@ -24,10 +24,10 @@
Dragon,
Dark,
Fairy,
}
}
public static class MoveTypeExtensions
{
public static class MoveTypeExtensions
{
public static MoveType GetMoveTypeGeneration(this MoveType type, int generation)
{
if (generation <= 2)
@ -45,5 +45,4 @@
type -= 10; // 10 Normal duplicates
return type;
}
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Nature ID values for the corresponding English nature name.
/// </summary>
public enum Nature : byte
{
/// <summary>
/// Nature ID values for the corresponding English nature name.
/// </summary>
public enum Nature : byte
{
Hardy = 0,
Lonely = 1,
Brave = 2,
@ -32,10 +32,10 @@
Quirky = 24,
Random = 25,
}
}
public static class NatureUtil
{
public static class NatureUtil
{
public static Nature GetNature(int value) => value switch
{
< 0 or >= (int)Nature.Random => Nature.Random,
@ -45,5 +45,4 @@
public static bool IsFixed(this Nature value) => value is >= 0 and < Nature.Random;
public static bool IsNeutral(this Nature value) => value.IsFixed() && (byte)value % 6 == 0;
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// 3DS Console Region Identifiers used for Generation 6 &amp; 7 Mystery Gifts
/// </summary>
public enum Region3DSIndex : byte
{
/// <summary>
/// 3DS Console Region Identifiers used for Generation 6 &amp; 7 Mystery Gifts
/// </summary>
public enum Region3DSIndex : byte
{
None = 0,
Japan = 1,
NorthAmerica = 2,
@ -12,5 +12,4 @@
China = 4,
Korea = 5,
Taiwan = 6,
}
}

View file

@ -1,10 +1,10 @@
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Species IDs for the corresponding English species name.
/// </summary>
public enum Species : ushort
{
/// <summary>
/// Species IDs for the corresponding English species name.
/// </summary>
public enum Species : ushort
{
None,
Bulbasaur,
Ivysaur,
@ -912,5 +912,4 @@
Overqwil,
Enamorus,
MAX_COUNT,
}
}

View file

@ -2,13 +2,13 @@
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// <see cref="SaveFile"/> sensitive provider for <see cref="ComboItem"/> data sources.
/// </summary>
public sealed class FilteredGameDataSource
{
/// <summary>
/// <see cref="SaveFile"/> sensitive provider for <see cref="ComboItem"/> data sources.
/// </summary>
public sealed class FilteredGameDataSource
{
public FilteredGameDataSource(SaveFile sav, GameDataSource source, bool HaX = false)
{
Source = source;
@ -78,10 +78,10 @@ namespace PKHeX.Core
public readonly IReadOnlyList<ComboItem> G4GroundTiles;
public readonly IReadOnlyList<ComboItem> ConsoleRegions = GameDataSource.Regions;
public IReadOnlyList<ComboItem> GetAbilityList(PKM pkm)
public IReadOnlyList<ComboItem> GetAbilityList(PKM pk)
{
var abilities = pkm.PersonalInfo.Abilities;
int format = pkm.Format;
var abilities = pk.PersonalInfo.Abilities;
int format = pk.Format;
return GetAbilityList(abilities, format);
}
@ -102,5 +102,4 @@ namespace PKHeX.Core
}
private static readonly string[] AbilityIndexSuffixes = { " (1)", " (2)", " (H)" };
}
}

View file

@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Bundles raw string inputs into lists that can be used in data binding.
/// </summary>
public sealed class GameDataSource
{
/// <summary>
/// Bundles raw string inputs into lists that can be used in data binding.
/// </summary>
public sealed class GameDataSource
{
public static readonly IReadOnlyList<ComboItem> Regions = new List<ComboItem>
{
new ("Japan (日本)", 0),
@ -123,5 +123,4 @@ namespace PKHeX.Core
languages.RemoveAll(l => l.Value > (int)LanguageID.Korean);
return languages;
}
}
}

View file

@ -1,12 +1,12 @@
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Shared instance for fetching <see cref="GameStrings"/> data
/// </summary>
public static class GameInfo
{
/// <summary>
/// Shared instance for fetching <see cref="GameStrings"/> data
/// </summary>
public static class GameInfo
{
private static readonly GameStrings?[] Languages = new GameStrings[GameLanguage.LanguageCount];
public static string CurrentLanguage { get; set; } = GameLanguage.DefaultLanguage;
@ -79,5 +79,4 @@ namespace PKHeX.Core
{
return Sources.Met.GetLocationList(version, context, egg);
}
}
}

View file

@ -1,12 +1,12 @@
using System;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Language code &amp; string asset loading.
/// </summary>
public static class GameLanguage
{
/// <summary>
/// Language code &amp; string asset loading.
/// </summary>
public static class GameLanguage
{
public const string DefaultLanguage = "en"; // English
public static int DefaultLanguageIndex => Array.IndexOf(LanguageCodes, DefaultLanguage);
public static string Language2Char(int lang) => lang > LanguageCodes.Length ? DefaultLanguage : LanguageCodes[lang];
@ -52,10 +52,10 @@ namespace PKHeX.Core
return data;
}
}
}
public enum ProgramLanguage
{
public enum ProgramLanguage
{
/// <summary>
/// Japanese
/// </summary>
@ -95,5 +95,4 @@ namespace PKHeX.Core
/// Chinese
/// </summary>
,
}
}

View file

@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
namespace PKHeX.Core;
/// <summary>
/// Repository of localized game strings for a given <see cref="LanguageID"/>.
/// </summary>
public sealed class GameStrings : IBasicStrings
{
/// <summary>
/// Repository of localized game strings for a given <see cref="LanguageID"/>.
/// </summary>
public sealed class GameStrings : IBasicStrings
{
// PKM Info
public readonly string[] specieslist, movelist, itemlist, abilitylist, types, natures, forms,
memories, genloc, feeling6, feeling8, intensity,
@ -766,5 +766,4 @@ namespace PKHeX.Core
6 => metBDSP_60000,
_ => Array.Empty<string>(),
};
}
}

Some files were not shown because too many files have changed in this diff Show more