From ee9197f27623380b8cbe27e7c1edbc6d4818150a Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 19 Jun 2024 10:30:45 -0400 Subject: [PATCH] refactor: apply lints --- Model/IWhen.cs | 18 +++++------------- Model/WhenLevel.cs | 32 +++++++++++++++++--------------- Model/WhenStatus.cs | 2 ++ Plugin.cs | 17 +++++++++-------- Util/OnDispose.cs | 2 +- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/Model/IWhen.cs b/Model/IWhen.cs index 99e2baf..9f851a8 100644 --- a/Model/IWhen.cs +++ b/Model/IWhen.cs @@ -24,19 +24,11 @@ public class WhenNodeDeserialiser : INodeDeserializer { throw new YamlException("invalid when: missing key"); } - switch (name.Value) { - case "quest": { - value = nestedObjectDeserializer(reader, typeof(WhenQuest)); - break; - } - case "level": { - value = nestedObjectDeserializer(reader, typeof(WhenLevel)); - break; - } - default: { - throw new YamlException($"invalid when: unknown type \"{name.Value}\""); - } - } + value = name.Value switch { + "quest" => nestedObjectDeserializer(reader, typeof(WhenQuest)), + "level" => nestedObjectDeserializer(reader, typeof(WhenLevel)), + _ => throw new YamlException($"invalid when: unknown type \"{name.Value}\""), + }; reader.Consume(); diff --git a/Model/WhenLevel.cs b/Model/WhenLevel.cs index 3b70233..8a656e7 100644 --- a/Model/WhenLevel.cs +++ b/Model/WhenLevel.cs @@ -31,7 +31,7 @@ public class WhenLevelConverter : IYamlTypeConverter { return type == typeof(WhenLevel); } - public object? ReadYaml(IParser parser, Type type) { + public object ReadYaml(IParser parser, Type type) { parser.Consume(); string? text = null; @@ -46,20 +46,6 @@ public class WhenLevelConverter : IYamlTypeConverter { var value = parser.Consume(); - void ParseOperation(int comparer) { - if (comparerResult != null) { - throw new YamlException("duplicate operations in whenlevel"); - } - - comparerResult = comparer; - - if (!uint.TryParse(value.Value, out var lvl)) { - throw new YamlException("invalid whenlevel: level was not numeric"); - } - - level = lvl; - } - switch (key.Value) { case "greaterThan": { ParseOperation(1); @@ -88,6 +74,22 @@ public class WhenLevelConverter : IYamlTypeConverter { continue; } } + + continue; + + void ParseOperation(int comparer) { + if (comparerResult != null) { + throw new YamlException("duplicate operations in whenlevel"); + } + + comparerResult = comparer; + + if (!uint.TryParse(value.Value, out var lvl)) { + throw new YamlException("invalid whenlevel: level was not numeric"); + } + + level = lvl; + } } parser.Consume(); diff --git a/Model/WhenStatus.cs b/Model/WhenStatus.cs index 4fe62ab..335ca5c 100644 --- a/Model/WhenStatus.cs +++ b/Model/WhenStatus.cs @@ -1,3 +1,5 @@ +namespace TimePasses.Model; + [Serializable] public enum QuestStatus { Complete, diff --git a/Plugin.cs b/Plugin.cs index a124bb6..d47540b 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -8,6 +8,7 @@ using Dalamud.Plugin; using Dalamud.Plugin.Services; using Dalamud.Utility.Signatures; using TimePasses.Model; +using TimePasses.Util; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; @@ -99,15 +100,15 @@ public sealed class Plugin : IDalamudPlugin { } var when = rep.When.FirstOrDefault(when => when.IsValid(this)); - if (when == null) { - if (rep.Text != null) { - return this.GetOrCreateReplacementPointer(rep.Text, rep.Slowly); - } - - return null; + if (when != null) { + return this.GetOrCreateReplacementPointer(when.Text, when.Slowly); } - return this.GetOrCreateReplacementPointer(when.Text, when.Slowly); + if (rep.Text != null) { + return this.GetOrCreateReplacementPointer(rep.Text, rep.Slowly); + } + + return null; } private nint GetOrCreateReplacementPointer(string text, bool slowly) { @@ -174,7 +175,7 @@ public sealed class Plugin : IDalamudPlugin { bytes[textBytes.Length] = 0; Marshal.Copy(textBytes, 0, (nint) bytes, textBytes.Length); - this.ReplacementPointers![(text, slowly)] = (nint) ptr; + this.ReplacementPointers[(text, slowly)] = (nint) ptr; return (nint) ptr; } catch { Marshal.FreeHGlobal((nint) ptr); diff --git a/Util/OnDispose.cs b/Util/OnDispose.cs index e4a6695..d77def1 100644 --- a/Util/OnDispose.cs +++ b/Util/OnDispose.cs @@ -1,4 +1,4 @@ -namespace TimePasses.Model; +namespace TimePasses.Util; internal class OnDispose : IDisposable { private bool _disposed;