Skip to content

Commit c40f5f8

Browse files
committed
refactoring and cleanup
1 parent 6cd2ff1 commit c40f5f8

15 files changed

+46
-57
lines changed

TinyCmds/Attributes/ArgumentsAttribute.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
namespace PrincessRTFM.TinyCmds.Attributes;
55

66
[AttributeUsage(AttributeTargets.Class)]
7-
internal class ArgumentsAttribute: Attribute {
7+
internal class ArgumentsAttribute(params string[] args): Attribute {
88
public string ArgumentDescription => string.Join(" ", this.Arguments.Select(a => a.EndsWith('?') ? $"[{a.TrimEnd('?')}]" : $"<{a}>"));
9-
public string[] Arguments { get; }
10-
public int RequiredArguments => this.Arguments.Where(a => !a.EndsWith('?')).Count();
9+
public string[] Arguments { get; } = args;
10+
public int RequiredArguments => this.Arguments.Count(a => !a.EndsWith('?'));
1111
public int MaxArguments => this.Arguments.Length;
12-
13-
public ArgumentsAttribute(params string[] args) => this.Arguments = args;
1412
}

TinyCmds/Attributes/CommandAttribute.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
namespace PrincessRTFM.TinyCmds.Attributes;
44

55
[AttributeUsage(AttributeTargets.Class)]
6-
internal class CommandAttribute: Attribute {
7-
public string Command { get; }
8-
public string[] Aliases { get; }
9-
10-
public CommandAttribute(string command, params string[] aliases) {
11-
this.Command = command;
12-
this.Aliases = aliases;
13-
}
6+
internal class CommandAttribute(string command, params string[] aliases): Attribute {
7+
public string Command { get; } = command;
8+
public string[] Aliases { get; } = aliases;
149
}

TinyCmds/Attributes/HelpTextAttribute.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace PrincessRTFM.TinyCmds.Attributes;
44

55
[AttributeUsage(AttributeTargets.Class)]
6-
internal class HelpTextAttribute: Attribute {
7-
public string HelpMessage { get; }
8-
9-
public HelpTextAttribute(params string[] helpMessage) => this.HelpMessage = string.Join("\n", helpMessage);
6+
internal class HelpTextAttribute(params string[] helpMessage): Attribute {
7+
public string HelpMessage { get; } = string.Join("\n", helpMessage);
108
}

TinyCmds/Attributes/SummaryAttribute.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace PrincessRTFM.TinyCmds.Attributes;
44

55
[AttributeUsage(AttributeTargets.Class)]
6-
internal class SummaryAttribute: Attribute {
7-
public string Summary { get; }
8-
9-
public SummaryAttribute(string helpMessage) => this.Summary = helpMessage;
6+
internal class SummaryAttribute(string helpMessage): Attribute {
7+
public string Summary { get; } = helpMessage;
108
}

TinyCmds/Chat/ChatUtil.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ internal static List<Payload> GenerateMessagePayloads(params object[] payloads)
3333

3434
#region Chatlog functions
3535
public static void ShowMessage(params object[] payloads) {
36-
if (payloads.Length < 1 || !payloads.Where(e => e is not null).Any())
36+
if (payloads.Length < 1 || !payloads.Any(e => e is not null))
3737
return;
3838
Plugin.Chat.Print(new SeString(GenerateMessagePayloads(payloads)));
3939
}
4040
public static void ShowPrefixedMessage(params object[] payloads) {
41-
if (payloads.Length < 1 || !payloads.Where(e => e is not null).Any())
41+
if (payloads.Length < 1 || !payloads.Any(e => e is not null))
4242
return;
4343
List<object> plList = [
4444
ChatColour.PREFIX,
@@ -49,12 +49,12 @@ public static void ShowPrefixedMessage(params object[] payloads) {
4949
ShowMessage(plList.ToArray());
5050
}
5151
public static void ShowError(params object[] payloads) {
52-
if (payloads.Length < 1 || !payloads.Where(e => e is not null).Any())
52+
if (payloads.Length < 1 || !payloads.Any(e => e is not null))
5353
return;
5454
Plugin.Chat.PrintError(new SeString(GenerateMessagePayloads(payloads)));
5555
}
5656
public static void ShowPrefixedError(params object[] payloads) {
57-
if (payloads.Length < 1 || !payloads.Where(e => e is not null).Any())
57+
if (payloads.Length < 1 || !payloads.Any(e => e is not null))
5858
return;
5959
List<object> plList = [
6060
ChatColour.PREFIX,

TinyCmds/CommandAssertionFailureException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace PrincessRTFM.TinyCmds;
66
[Serializable]
77
public class CommandAssertionFailureException: Exception {
88
public CommandAssertionFailureException() { }
9-
public CommandAssertionFailureException(string message) : base(message) { }
10-
public CommandAssertionFailureException(string message, Exception inner) : base(message, inner) { }
9+
public CommandAssertionFailureException(string? message) : base(message) { }
10+
public CommandAssertionFailureException(string? message, Exception? inner) : base(message, inner) { }
1111
}

TinyCmds/Commands/LocateBestFATECommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,8 @@ protected override unsafe void Execute(string? command, string rawArguments, Fla
118118
uint originalTime = minTime;
119119
uint originalProgress = maxProgress;
120120
List<Fate> fates = new(Plugin.Fates.Length);
121-
foreach (Fate? fate in Plugin.Fates) {
122-
if (fate is not null)
123-
fates.Add(fate);
124-
}
125-
byte fateLevel = fates.Where(f => f.Level <= maxLevel).Any()
121+
fates.AddRange(Plugin.Fates.Where(f => f is not null));
122+
byte fateLevel = fates.Any(f => f.Level <= maxLevel)
126123
? fates.OrderByDescending(f => f.Level).First().Level
127124
: fates.OrderBy(f => f.Level).First().Level;
128125
Fate[] filtered = fates.Where(f => f.Level == fateLevel).ToArray();
@@ -205,7 +202,6 @@ protected override unsafe void Execute(string? command, string rawArguments, Fla
205202
if (flags['f']) {
206203
uint zone = Plugin.Client.TerritoryType;
207204
Map map = Plugin.Data.GetExcelSheet<TerritoryType>()?.GetRowOrDefault(zone)?.Map.Value ?? throw new NullReferenceException("Cannot find map ID");
208-
ExcelSheet<TerritoryTypeTransient>? transientSheet = Plugin.Data.Excel.GetSheet<TerritoryTypeTransient>();
209205
uint mapId = map.RowId;
210206
AgentMap* agentMap = AgentMap.Instance();
211207
Vector3 pos = accepted[0].Position;

TinyCmds/Commands/LocateGameObject.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ protected override unsafe void Execute(string? command, string rawArguments, Fla
7575

7676
uint zone = Plugin.Client.TerritoryType;
7777
Map map = Plugin.Data.GetExcelSheet<TerritoryType>()?.GetRowOrDefault(zone)?.Map.Value ?? throw new NullReferenceException("Cannot find map ID");
78-
ExcelSheet<TerritoryTypeTransient>? transientSheet = Plugin.Data.Excel.GetSheet<TerritoryTypeTransient>();
7978
uint mapId = map.RowId;
8079
int count = found.Count();
8180

TinyCmds/Internal/GameFunctionBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public T? Delegate {
2323
return null;
2424
}
2525
}
26-
internal GameFunctionBase(string sig, int offset = 0) {
26+
protected GameFunctionBase(string sig, int offset = 0) {
2727
if (Plugin.Scanner.TryScanText(sig, out this.addr)) {
2828
this.addr += offset;
2929
ulong totalOffset = (ulong)this.Address.ToInt64() - (ulong)Plugin.Scanner.Module.BaseAddress.ToInt64();
@@ -34,7 +34,7 @@ internal GameFunctionBase(string sig, int offset = 0) {
3434
}
3535
}
3636
[SuppressMessage("Reliability", "CA2020:Prevent from behavioral change", Justification = "If that explodes, we SHOULD be throwing")]
37-
internal GameFunctionBase(IntPtr address, int offset = 0) {
37+
protected GameFunctionBase(IntPtr address, int offset = 0) {
3838
this.addr = address + offset;
3939
ulong totalOffset = (ulong)this.Address.ToInt64() - (ulong)Plugin.Scanner.Module.BaseAddress.ToInt64();
4040
Logger.Info($"{this.GetType().Name} loaded; address = 0x{this.Address.ToInt64():X16}, base memory offset = 0x{totalOffset:X16}");

TinyCmds/Internal/Logger.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@ private static string msgPrefix {
1616
[Conditional("DEBUG")]
1717
internal static void Debug(string tmpl, params object[] args) => Plugin.Log.Debug($"{msgPrefix} {string.Format(tmpl, args)}");
1818
[Conditional("DEBUG")]
19-
internal static void Verbose(string tmpl, params object[] args) => Plugin.Log.Verbose($"{msgPrefix} {string.Format(tmpl, args)}");
20-
internal static void Info(string tmpl, params object[] args) => Plugin.Log.Information($"{msgPrefix} {string.Format(tmpl, args)}");
21-
internal static void Warning(string tmpl, params object[] args) => Plugin.Log.Warning($"{msgPrefix} {string.Format(tmpl, args)}");
22-
internal static void Error(string tmpl, params object[] args) => Plugin.Log.Error($"{msgPrefix} {string.Format(tmpl, args)}");
23-
internal static void Fatal(string tmpl, params object[] args) => Plugin.Log.Fatal($"{msgPrefix} {string.Format(tmpl, args)}");
24-
[Conditional("DEBUG")]
2519
internal static void Debug(Exception ex, string tmpl, params object[] args) => Plugin.Log.Debug(ex, $"{msgPrefix} {string.Format(tmpl, args)}");
20+
21+
[Conditional("DEBUG")]
22+
internal static void Verbose(string tmpl, params object[] args) => Plugin.Log.Verbose($"{msgPrefix} {string.Format(tmpl, args)}");
2623
[Conditional("DEBUG")]
2724
internal static void Verbose(Exception ex, string tmpl, params object[] args) => Plugin.Log.Verbose(ex, $"{msgPrefix} {string.Format(tmpl, args)}");
25+
26+
internal static void Info(string tmpl, params object[] args) => Plugin.Log.Information($"{msgPrefix} {string.Format(tmpl, args)}");
2827
internal static void Info(Exception ex, string tmpl, params object[] args) => Plugin.Log.Information(ex, $"{msgPrefix} {string.Format(tmpl, args)}");
28+
29+
internal static void Warning(string tmpl, params object[] args) => Plugin.Log.Warning($"{msgPrefix} {string.Format(tmpl, args)}");
2930
internal static void Warning(Exception ex, string tmpl, params object[] args) => Plugin.Log.Warning(ex, $"{msgPrefix} {string.Format(tmpl, args)}");
31+
32+
internal static void Error(string tmpl, params object[] args) => Plugin.Log.Error($"{msgPrefix} {string.Format(tmpl, args)}");
3033
internal static void Error(Exception ex, string tmpl, params object[] args) => Plugin.Log.Error(ex, $"{msgPrefix} {string.Format(tmpl, args)}");
34+
35+
internal static void Fatal(string tmpl, params object[] args) => Plugin.Log.Fatal($"{msgPrefix} {string.Format(tmpl, args)}");
3136
internal static void Fatal(Exception ex, string tmpl, params object[] args) => Plugin.Log.Fatal(ex, $"{msgPrefix} {string.Format(tmpl, args)}");
37+
3238
}

0 commit comments

Comments
 (0)