Skip to content

Commit fc754b3

Browse files
authored
File scoped namespaces (kwsch#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`
1 parent 78092e0 commit fc754b3

File tree

1,124 files changed

+129600
-130514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,124 files changed

+129600
-130514
lines changed

.editorconfig

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
root = true
2+
3+
# All Files
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
# Solution Files
12+
[*.sln]
13+
indent_style = space
14+
indent_size = 4
15+
insert_final_newline = true
16+
trim_trailing_whitespace = true
17+
18+
# XML Project Files
19+
[*.csproj]
20+
indent_style = space
21+
indent_size = 2
22+
23+
# Code Files
24+
[*.cs]
25+
insert_final_newline = true
26+
trim_trailing_whitespace = true
27+
indent_style = space
28+
indent_size = 4
29+
tab_width = 4
30+
end_of_line = crlf
31+
csharp_prefer_braces = when_multiline:warning
32+
dotnet_diagnostic.IDE0047.severity = none
33+
dotnet_diagnostic.IDE0048.severity = none
34+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggest
35+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggest
36+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggest
37+
dotnet_style_parentheses_in_other_operators = always_for_clarity:suggest
38+
39+
[*.{cs,vb}]
40+
#### Naming styles ####
41+
42+
# Naming styles
43+
44+
dotnet_naming_style.begins_with_i.required_prefix = I
45+
dotnet_naming_style.begins_with_i.capitalization = pascal_case

PKHeX.Core/Editing/Applicators/BallApplicator.cs

+131-132
Original file line numberDiff line numberDiff line change
@@ -3,160 +3,159 @@
33
using System.Linq;
44
using static PKHeX.Core.Ball;
55

6-
namespace PKHeX.Core
6+
namespace PKHeX.Core;
7+
8+
/// <summary>
9+
/// Contains logic to apply a new <see cref="Ball"/> value to a <see cref="PKM"/>.
10+
/// </summary>
11+
public static class BallApplicator
712
{
813
/// <summary>
9-
/// Contains logic to apply a new <see cref="Ball"/> value to a <see cref="PKM"/>.
14+
/// Gets all balls that are legal for the input <see cref="PKM"/>.
1015
/// </summary>
11-
public static class BallApplicator
16+
/// <remarks>
17+
/// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried.
18+
/// </remarks>
19+
/// <param name="pk">Pokémon to retrieve a list of valid balls for.</param>
20+
/// <returns>Enumerable list of <see cref="Ball"/> values that the <see cref="PKM"/> is legal with.</returns>
21+
public static IEnumerable<Ball> GetLegalBalls(PKM pk)
1222
{
13-
/// <summary>
14-
/// Gets all balls that are legal for the input <see cref="PKM"/>.
15-
/// </summary>
16-
/// <remarks>
17-
/// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried.
18-
/// </remarks>
19-
/// <param name="pkm">Pokémon to retrieve a list of valid balls for.</param>
20-
/// <returns>Enumerable list of <see cref="Ball"/> values that the <see cref="PKM"/> is legal with.</returns>
21-
public static IEnumerable<Ball> GetLegalBalls(PKM pkm)
23+
var clone = pk.Clone();
24+
foreach (var b in BallList)
2225
{
23-
var clone = pkm.Clone();
24-
foreach (var b in BallList)
25-
{
26-
clone.Ball = (int)b;
27-
if (new LegalityAnalysis(clone).Valid)
28-
yield return b;
29-
}
26+
clone.Ball = (int)b;
27+
if (new LegalityAnalysis(clone).Valid)
28+
yield return b;
3029
}
30+
}
3131

32-
/// <summary>
33-
/// Applies a random legal ball value if any exist.
34-
/// </summary>
35-
/// <remarks>
36-
/// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried.
37-
/// </remarks>
38-
/// <param name="pkm">Pokémon to modify.</param>
39-
public static int ApplyBallLegalRandom(PKM pkm)
40-
{
41-
var balls = GetBallListFromColor(pkm).ToArray();
42-
Util.Shuffle(balls.AsSpan());
43-
return ApplyFirstLegalBall(pkm, balls);
44-
}
32+
/// <summary>
33+
/// Applies a random legal ball value if any exist.
34+
/// </summary>
35+
/// <remarks>
36+
/// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried.
37+
/// </remarks>
38+
/// <param name="pk">Pokémon to modify.</param>
39+
public static int ApplyBallLegalRandom(PKM pk)
40+
{
41+
var balls = GetBallListFromColor(pk).ToArray();
42+
Util.Shuffle(balls.AsSpan());
43+
return ApplyFirstLegalBall(pk, balls);
44+
}
4545

46-
/// <summary>
47-
/// Applies a legal ball value if any exist, ordered by color.
48-
/// </summary>
49-
/// <remarks>
50-
/// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried.
51-
/// </remarks>
52-
/// <param name="pkm">Pokémon to modify.</param>
53-
public static int ApplyBallLegalByColor(PKM pkm)
54-
{
55-
var balls = GetBallListFromColor(pkm);
56-
return ApplyFirstLegalBall(pkm, balls);
57-
}
46+
/// <summary>
47+
/// Applies a legal ball value if any exist, ordered by color.
48+
/// </summary>
49+
/// <remarks>
50+
/// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried.
51+
/// </remarks>
52+
/// <param name="pk">Pokémon to modify.</param>
53+
public static int ApplyBallLegalByColor(PKM pk)
54+
{
55+
var balls = GetBallListFromColor(pk);
56+
return ApplyFirstLegalBall(pk, balls);
57+
}
5858

59-
/// <summary>
60-
/// Applies a random ball value in a cyclical manner.
61-
/// </summary>
62-
/// <param name="pkm">Pokémon to modify.</param>
63-
public static int ApplyBallNext(PKM pkm)
64-
{
65-
var balls = GetBallList(pkm.Ball);
66-
var next = balls.First();
67-
return pkm.Ball = (int)next;
68-
}
59+
/// <summary>
60+
/// Applies a random ball value in a cyclical manner.
61+
/// </summary>
62+
/// <param name="pk">Pokémon to modify.</param>
63+
public static int ApplyBallNext(PKM pk)
64+
{
65+
var balls = GetBallList(pk.Ball);
66+
var next = balls.First();
67+
return pk.Ball = (int)next;
68+
}
6969

70-
private static int ApplyFirstLegalBall(PKM pkm, IEnumerable<Ball> balls)
70+
private static int ApplyFirstLegalBall(PKM pk, IEnumerable<Ball> balls)
71+
{
72+
foreach (var b in balls)
7173
{
72-
foreach (var b in balls)
73-
{
74-
pkm.Ball = (int)b;
75-
if (new LegalityAnalysis(pkm).Valid)
76-
break;
77-
}
78-
return pkm.Ball;
74+
pk.Ball = (int)b;
75+
if (new LegalityAnalysis(pk).Valid)
76+
break;
7977
}
78+
return pk.Ball;
79+
}
8080

81-
private static IEnumerable<Ball> GetBallList(int ball)
82-
{
83-
var balls = BallList;
84-
var currentBall = (Ball)ball;
85-
return GetCircularOnce(balls, currentBall);
86-
}
81+
private static IEnumerable<Ball> GetBallList(int ball)
82+
{
83+
var balls = BallList;
84+
var currentBall = (Ball)ball;
85+
return GetCircularOnce(balls, currentBall);
86+
}
8787

88-
private static IEnumerable<Ball> GetBallListFromColor(PKM pkm)
89-
{
90-
// Gen1/2 don't store color in personal info
91-
var pi = pkm.Format >= 3 ? pkm.PersonalInfo : PersonalTable.USUM.GetFormEntry(pkm.Species, 0);
92-
var color = (PersonalColor)pi.Color;
93-
var balls = BallColors[color];
94-
var currentBall = (Ball)pkm.Ball;
95-
return GetCircularOnce(balls, currentBall);
96-
}
88+
private static IEnumerable<Ball> GetBallListFromColor(PKM pk)
89+
{
90+
// Gen1/2 don't store color in personal info
91+
var pi = pk.Format >= 3 ? pk.PersonalInfo : PersonalTable.USUM.GetFormEntry(pk.Species, 0);
92+
var color = (PersonalColor)pi.Color;
93+
var balls = BallColors[color];
94+
var currentBall = (Ball)pk.Ball;
95+
return GetCircularOnce(balls, currentBall);
96+
}
9797

98-
private static IEnumerable<T> GetCircularOnce<T>(T[] items, T current)
99-
{
100-
var currentIndex = Array.IndexOf(items, current);
101-
if (currentIndex < 0)
102-
currentIndex = items.Length - 2;
103-
for (int i = currentIndex + 1; i < items.Length; i++)
104-
yield return items[i];
105-
for (int i = 0; i <= currentIndex; i++)
106-
yield return items[i];
107-
}
98+
private static IEnumerable<T> GetCircularOnce<T>(T[] items, T current)
99+
{
100+
var currentIndex = Array.IndexOf(items, current);
101+
if (currentIndex < 0)
102+
currentIndex = items.Length - 2;
103+
for (int i = currentIndex + 1; i < items.Length; i++)
104+
yield return items[i];
105+
for (int i = 0; i <= currentIndex; i++)
106+
yield return items[i];
107+
}
108108

109-
private static readonly Ball[] BallList = (Ball[]) Enum.GetValues(typeof(Ball));
109+
private static readonly Ball[] BallList = (Ball[]) Enum.GetValues(typeof(Ball));
110110

111-
static BallApplicator()
111+
static BallApplicator()
112+
{
113+
var exclude = new[] {None, Poke};
114+
var end = new[] {Poke};
115+
var allBalls = BallList.Except(exclude).ToArray();
116+
var colors = (PersonalColor[])Enum.GetValues(typeof(PersonalColor));
117+
foreach (var c in colors)
112118
{
113-
var exclude = new[] {None, Poke};
114-
var end = new[] {Poke};
115-
var allBalls = BallList.Except(exclude).ToArray();
116-
var colors = (PersonalColor[])Enum.GetValues(typeof(PersonalColor));
117-
foreach (var c in colors)
118-
{
119-
var matchingColors = BallColors[c];
120-
var extra = allBalls.Except(matchingColors).ToArray();
121-
Util.Shuffle(extra.AsSpan());
122-
BallColors[c] = ArrayUtil.ConcatAll(matchingColors, extra, end);
123-
}
119+
var matchingColors = BallColors[c];
120+
var extra = allBalls.Except(matchingColors).ToArray();
121+
Util.Shuffle(extra.AsSpan());
122+
BallColors[c] = ArrayUtil.ConcatAll(matchingColors, extra, end);
124123
}
124+
}
125125

126-
/// <summary>
127-
/// Priority Match ball IDs that match the color ID in descending order
128-
/// </summary>
129-
private static readonly Dictionary<PersonalColor, Ball[]> BallColors = new()
130-
{
131-
[PersonalColor.Red] = new[] { Cherish, Repeat, Fast, Heal, Great, Dream, Lure },
132-
[PersonalColor.Blue] = new[] { Dive, Net, Great, Beast, Lure },
133-
[PersonalColor.Yellow] = new[] { Level, Ultra, Repeat, Quick, Moon },
134-
[PersonalColor.Green] = new[] { Safari, Friend, Nest, Dusk },
135-
[PersonalColor.Black] = new[] { Luxury, Heavy, Ultra, Moon, Net, Beast },
126+
/// <summary>
127+
/// Priority Match ball IDs that match the color ID in descending order
128+
/// </summary>
129+
private static readonly Dictionary<PersonalColor, Ball[]> BallColors = new()
130+
{
131+
[PersonalColor.Red] = new[] { Cherish, Repeat, Fast, Heal, Great, Dream, Lure },
132+
[PersonalColor.Blue] = new[] { Dive, Net, Great, Beast, Lure },
133+
[PersonalColor.Yellow] = new[] { Level, Ultra, Repeat, Quick, Moon },
134+
[PersonalColor.Green] = new[] { Safari, Friend, Nest, Dusk },
135+
[PersonalColor.Black] = new[] { Luxury, Heavy, Ultra, Moon, Net, Beast },
136136

137-
[PersonalColor.Brown] = new[] { Level, Heavy },
138-
[PersonalColor.Purple] = new[] { Master, Love, Dream, Heal },
139-
[PersonalColor.Gray] = new[] { Heavy, Premier, Luxury },
140-
[PersonalColor.White] = new[] { Premier, Timer, Luxury, Ultra },
141-
[PersonalColor.Pink] = new[] { Love, Dream, Heal },
142-
};
137+
[PersonalColor.Brown] = new[] { Level, Heavy },
138+
[PersonalColor.Purple] = new[] { Master, Love, Dream, Heal },
139+
[PersonalColor.Gray] = new[] { Heavy, Premier, Luxury },
140+
[PersonalColor.White] = new[] { Premier, Timer, Luxury, Ultra },
141+
[PersonalColor.Pink] = new[] { Love, Dream, Heal },
142+
};
143143

144-
/// <summary>
145-
/// Personal Data color IDs
146-
/// </summary>
147-
private enum PersonalColor : byte
148-
{
149-
Red,
150-
Blue,
151-
Yellow,
152-
Green,
153-
Black,
144+
/// <summary>
145+
/// Personal Data color IDs
146+
/// </summary>
147+
private enum PersonalColor : byte
148+
{
149+
Red,
150+
Blue,
151+
Yellow,
152+
Green,
153+
Black,
154154

155-
Brown,
156-
Purple,
157-
Gray,
158-
White,
159-
Pink,
160-
}
155+
Brown,
156+
Purple,
157+
Gray,
158+
White,
159+
Pink,
161160
}
162161
}

0 commit comments

Comments
 (0)