From a593eda30f82af474887d91458b0e9158f66fefc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 6 Apr 2022 18:24:59 -0400 Subject: use target-typed new --- src/SMAPI/Context.cs | 4 ++-- src/SMAPI/Framework/CommandManager.cs | 2 +- src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs | 2 +- src/SMAPI/Framework/Content/AssetDataForMap.cs | 4 ++-- src/SMAPI/Framework/DeprecationManager.cs | 2 +- src/SMAPI/Framework/Events/ManagedEvent.cs | 2 +- src/SMAPI/Framework/Input/KeyboardStateBuilder.cs | 2 +- src/SMAPI/Framework/Input/SInputState.cs | 10 +++++----- src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 16 ++++++++-------- src/SMAPI/Framework/ModLoading/ModResolver.cs | 2 +- .../ModLoading/Symbols/SymbolReaderProvider.cs | 2 +- src/SMAPI/Framework/ModRegistry.cs | 4 ++-- src/SMAPI/Framework/Models/SConfig.cs | 2 +- src/SMAPI/Framework/Networking/SGalaxyNetServer.cs | 6 +++--- src/SMAPI/Framework/Networking/SLidgrenServer.cs | 4 ++-- src/SMAPI/Framework/Reflection/Reflector.cs | 4 ++-- src/SMAPI/Framework/SGame.cs | 8 ++++---- src/SMAPI/Framework/SGameRunner.cs | 2 +- src/SMAPI/Framework/SMultiplayer.cs | 18 +++++++++--------- src/SMAPI/Framework/Singleton.cs | 2 +- src/SMAPI/Framework/SnapshotListDiff.cs | 4 ++-- src/SMAPI/Framework/StateTracking/ChestTracker.cs | 4 ++-- .../FieldWatchers/ComparableListWatcher.cs | 4 ++-- .../FieldWatchers/ImmutableCollectionWatcher.cs | 2 +- .../FieldWatchers/NetCollectionWatcher.cs | 4 ++-- .../FieldWatchers/ObservableCollectionWatcher.cs | 6 +++--- src/SMAPI/Framework/StateTracking/LocationTracker.cs | 2 +- src/SMAPI/Framework/StateTracking/PlayerTracker.cs | 2 +- .../StateTracking/Snapshots/LocationSnapshot.cs | 14 +++++++------- .../StateTracking/Snapshots/PlayerSnapshot.cs | 4 ++-- .../StateTracking/Snapshots/WatcherSnapshot.cs | 16 ++++++++-------- .../StateTracking/Snapshots/WorldLocationsSnapshot.cs | 4 ++-- .../Framework/TemporaryHacks/MiniMonoModHotfix.cs | 4 ++-- src/SMAPI/Framework/WatcherCore.cs | 2 +- src/SMAPI/Program.cs | 2 +- 35 files changed, 86 insertions(+), 86 deletions(-) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Context.cs b/src/SMAPI/Context.cs index a745592c..4fbc9c42 100644 --- a/src/SMAPI/Context.cs +++ b/src/SMAPI/Context.cs @@ -14,10 +14,10 @@ namespace StardewModdingAPI ** Fields *********/ /// Whether the player has loaded a save and the world has finished initializing. - private static readonly PerScreen IsWorldReadyForScreen = new PerScreen(); + private static readonly PerScreen IsWorldReadyForScreen = new(); /// The current stage in the game's loading process. - private static readonly PerScreen LoadStageForScreen = new PerScreen(); + private static readonly PerScreen LoadStageForScreen = new(); /// Whether a player save has been loaded. internal static bool IsSaveLoaded => Game1.hasLoadedGame && !(Game1.activeClickableMenu is TitleMenu); diff --git a/src/SMAPI/Framework/CommandManager.cs b/src/SMAPI/Framework/CommandManager.cs index ff540ad8..a7b64cb7 100644 --- a/src/SMAPI/Framework/CommandManager.cs +++ b/src/SMAPI/Framework/CommandManager.cs @@ -166,7 +166,7 @@ namespace StardewModdingAPI.Framework { bool inQuotes = false; IList args = new List(); - StringBuilder currentArg = new StringBuilder(); + StringBuilder currentArg = new(); foreach (char ch in input) { if (ch == '"') diff --git a/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs b/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs index 45b34556..643267ce 100644 --- a/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs +++ b/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs @@ -30,7 +30,7 @@ namespace StardewModdingAPI.Framework.Commands { SearchResult[] matches = this.FilterPatches(args).OrderBy(p => p.MethodName).ToArray(); - StringBuilder result = new StringBuilder(); + StringBuilder result = new(); if (!matches.Any()) result.AppendLine("No current patches match your search."); diff --git a/src/SMAPI/Framework/Content/AssetDataForMap.cs b/src/SMAPI/Framework/Content/AssetDataForMap.cs index 26e4986e..0458f80a 100644 --- a/src/SMAPI/Framework/Content/AssetDataForMap.cs +++ b/src/SMAPI/Framework/Content/AssetDataForMap.cs @@ -96,8 +96,8 @@ namespace StardewModdingAPI.Framework.Content for (int y = 0; y < sourceArea.Value.Height; y++) { // calculate tile positions - Point sourcePos = new Point(sourceArea.Value.X + x, sourceArea.Value.Y + y); - Point targetPos = new Point(targetArea.Value.X + x, targetArea.Value.Y + y); + Point sourcePos = new(sourceArea.Value.X + x, sourceArea.Value.Y + y); + Point targetPos = new(targetArea.Value.X + x, targetArea.Value.Y + y); // replace tiles on target-only layers if (replaceAll) diff --git a/src/SMAPI/Framework/DeprecationManager.cs b/src/SMAPI/Framework/DeprecationManager.cs index fc1b434b..ad6a3677 100644 --- a/src/SMAPI/Framework/DeprecationManager.cs +++ b/src/SMAPI/Framework/DeprecationManager.cs @@ -11,7 +11,7 @@ namespace StardewModdingAPI.Framework ** Fields *********/ /// The deprecations which have already been logged (as 'mod name::noun phrase::version'). - private readonly HashSet LoggedDeprecations = new HashSet(StringComparer.OrdinalIgnoreCase); + private readonly HashSet LoggedDeprecations = new(StringComparer.OrdinalIgnoreCase); /// Encapsulates monitoring and logging for a given module. private readonly IMonitor Monitor; diff --git a/src/SMAPI/Framework/Events/ManagedEvent.cs b/src/SMAPI/Framework/Events/ManagedEvent.cs index 154ef659..1c8b9d04 100644 --- a/src/SMAPI/Framework/Events/ManagedEvent.cs +++ b/src/SMAPI/Framework/Events/ManagedEvent.cs @@ -18,7 +18,7 @@ namespace StardewModdingAPI.Framework.Events protected readonly ModRegistry ModRegistry; /// The underlying event handlers. - private readonly List> Handlers = new List>(); + private readonly List> Handlers = new(); /// A cached snapshot of , or null to rebuild it next raise. private ManagedEventHandler[] CachedHandlers = Array.Empty>(); diff --git a/src/SMAPI/Framework/Input/KeyboardStateBuilder.cs b/src/SMAPI/Framework/Input/KeyboardStateBuilder.cs index eadb7a8a..09bc48b6 100644 --- a/src/SMAPI/Framework/Input/KeyboardStateBuilder.cs +++ b/src/SMAPI/Framework/Input/KeyboardStateBuilder.cs @@ -14,7 +14,7 @@ namespace StardewModdingAPI.Framework.Input private KeyboardState? State; /// The pressed buttons. - private readonly HashSet PressedButtons = new HashSet(); + private readonly HashSet PressedButtons = new(); /********* diff --git a/src/SMAPI/Framework/Input/SInputState.cs b/src/SMAPI/Framework/Input/SInputState.cs index a8d1f371..5ff7432b 100644 --- a/src/SMAPI/Framework/Input/SInputState.cs +++ b/src/SMAPI/Framework/Input/SInputState.cs @@ -21,10 +21,10 @@ namespace StardewModdingAPI.Framework.Input private Vector2? LastPlayerTile; /// The buttons to press until the game next handles input. - private readonly HashSet CustomPressedKeys = new HashSet(); + private readonly HashSet CustomPressedKeys = new(); /// The buttons to consider released until the actual button is released. - private readonly HashSet CustomReleasedKeys = new HashSet(); + private readonly HashSet CustomReleasedKeys = new(); /// Whether there are new overrides in or that haven't been applied to the previous state. private bool HasNewOverrides; @@ -72,7 +72,7 @@ namespace StardewModdingAPI.Framework.Input var controller = new GamePadStateBuilder(base.GetGamePadState()); var keyboard = new KeyboardStateBuilder(base.GetKeyboardState()); var mouse = new MouseStateBuilder(base.GetMouseState()); - Vector2 cursorAbsolutePos = new Vector2((mouse.X * zoomMultiplier) + Game1.viewport.X, (mouse.Y * zoomMultiplier) + Game1.viewport.Y); + Vector2 cursorAbsolutePos = new((mouse.X * zoomMultiplier) + Game1.viewport.X, (mouse.Y * zoomMultiplier) + Game1.viewport.Y); Vector2? playerTilePos = Context.IsPlayerFree ? Game1.player.getTileLocation() : (Vector2?)null; HashSet reallyDown = new HashSet(this.GetPressedButtons(keyboard, mouse, controller)); @@ -203,8 +203,8 @@ namespace StardewModdingAPI.Framework.Input /// The multiplier applied to pixel coordinates to adjust them for pixel zoom. private CursorPosition GetCursorPosition(MouseState mouseState, Vector2 absolutePixels, float zoomMultiplier) { - Vector2 screenPixels = new Vector2(mouseState.X * zoomMultiplier, mouseState.Y * zoomMultiplier); - Vector2 tile = new Vector2((int)((Game1.viewport.X + screenPixels.X) / Game1.tileSize), (int)((Game1.viewport.Y + screenPixels.Y) / Game1.tileSize)); + Vector2 screenPixels = new(mouseState.X * zoomMultiplier, mouseState.Y * zoomMultiplier); + Vector2 tile = new((int)((Game1.viewport.X + screenPixels.X) / Game1.tileSize), (int)((Game1.viewport.Y + screenPixels.Y) / Game1.tileSize)); Vector2 grabTile = (Game1.mouseCursorTransparency > 0 && Utility.tileWithinRadiusOfPlayer((int)tile.X, (int)tile.Y, 1, Game1.player)) // derived from Game1.pressActionButton ? tile : Game1.player.GetGrabTile(); diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index cb5fa2ae..4480f4e8 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -36,13 +36,13 @@ namespace StardewModdingAPI.Framework.ModLoading private readonly AssemblyDefinitionResolver AssemblyDefinitionResolver; /// Provides assembly symbol readers for Mono.Cecil. - private readonly SymbolReaderProvider SymbolReaderProvider = new SymbolReaderProvider(); + private readonly SymbolReaderProvider SymbolReaderProvider = new(); /// Provides assembly symbol writers for Mono.Cecil. - private readonly SymbolWriterProvider SymbolWriterProvider = new SymbolWriterProvider(); + private readonly SymbolWriterProvider SymbolWriterProvider = new(); /// The objects to dispose as part of this instance. - private readonly HashSet Disposables = new HashSet(); + private readonly HashSet Disposables = new(); /// Whether to rewrite mods for compatibility. private readonly bool RewriteMods; @@ -141,8 +141,8 @@ namespace StardewModdingAPI.Framework.ModLoading this.Monitor.Log($" Loading {assembly.File.Name} (rewritten)...", LogLevel.Trace); // load assembly - using MemoryStream outAssemblyStream = new MemoryStream(); - using MemoryStream outSymbolStream = new MemoryStream(); + using MemoryStream outAssemblyStream = new(); + using MemoryStream outSymbolStream = new(); assembly.Definition.Write(outAssemblyStream, new WriterParameters { WriteSymbols = true, SymbolStream = outSymbolStream, SymbolWriterProvider = this.SymbolWriterProvider }); byte[] bytes = outAssemblyStream.ToArray(); lastAssembly = Assembly.Load(bytes, outSymbolStream.ToArray()); @@ -241,7 +241,7 @@ namespace StardewModdingAPI.Framework.ModLoading try { // read assembly with symbols - FileInfo symbolsFile = new FileInfo(Path.Combine(Path.GetDirectoryName(file.FullName)!, Path.GetFileNameWithoutExtension(file.FullName)) + ".pdb"); + FileInfo symbolsFile = new(Path.Combine(Path.GetDirectoryName(file.FullName)!, Path.GetFileNameWithoutExtension(file.FullName)) + ".pdb"); if (symbolsFile.Exists) this.SymbolReaderProvider.TryAddSymbolData(file.Name, () => this.TrackForDisposal(symbolsFile.OpenRead())); assembly = this.TrackForDisposal(AssemblyDefinition.ReadAssembly(readStream, new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = assemblyResolver, InMemory = true, ReadSymbols = true, SymbolReaderProvider = this.SymbolReaderProvider })); @@ -266,7 +266,7 @@ namespace StardewModdingAPI.Framework.ModLoading // yield referenced assemblies foreach (AssemblyNameReference dependency in assembly.MainModule.AssemblyReferences) { - FileInfo dependencyFile = new FileInfo(Path.Combine(file.Directory.FullName, $"{dependency.Name}.dll")); + FileInfo dependencyFile = new(Path.Combine(file.Directory.FullName, $"{dependency.Name}.dll")); foreach (AssemblyParseResult result in this.GetReferencedLocalAssemblies(dependencyFile, visitedAssemblyNames, assemblyResolver)) yield return result; } @@ -333,7 +333,7 @@ namespace StardewModdingAPI.Framework.ModLoading // find or rewrite code IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers(this.ParanoidMode, platformChanged, this.RewriteMods).ToArray(); - RecursiveRewriter rewriter = new RecursiveRewriter( + RecursiveRewriter rewriter = new( module: module, rewriteModule: curModule => { diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs index 4b05d1e5..e3386f75 100644 --- a/src/SMAPI/Framework/ModLoading/ModResolver.cs +++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs @@ -401,7 +401,7 @@ namespace StardewModdingAPI.Framework.ModLoading { foreach (string modRootPath in Directory.GetDirectories(rootPath)) { - DirectoryInfo directory = new DirectoryInfo(modRootPath); + DirectoryInfo directory = new(modRootPath); // if a folder only contains another folder, check the inner folder instead while (!directory.GetFiles().Any() && directory.GetDirectories().Length == 1) diff --git a/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs b/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs index 44074337..d28c4a22 100644 --- a/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs +++ b/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs @@ -16,7 +16,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Symbols private readonly ISymbolReaderProvider BaseProvider = new DefaultSymbolReaderProvider(throwIfNoSymbol: false); /// The symbol data loaded by absolute assembly path. - private readonly Dictionary SymbolsByAssemblyPath = new Dictionary(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary SymbolsByAssemblyPath = new(StringComparer.OrdinalIgnoreCase); /********* diff --git a/src/SMAPI/Framework/ModRegistry.cs b/src/SMAPI/Framework/ModRegistry.cs index ef389337..99548cf8 100644 --- a/src/SMAPI/Framework/ModRegistry.cs +++ b/src/SMAPI/Framework/ModRegistry.cs @@ -13,7 +13,7 @@ namespace StardewModdingAPI.Framework ** Fields *********/ /// The registered mod data. - private readonly List Mods = new List(); + private readonly List Mods = new(); /// An assembly full name => mod lookup. private readonly IDictionary ModNamesByAssembly = new Dictionary(); @@ -94,7 +94,7 @@ namespace StardewModdingAPI.Framework public IModMetadata GetFromStack() { // get stack frames - StackTrace stack = new StackTrace(); + StackTrace stack = new(); StackFrame[] frames = stack.GetFrames(); if (frames == null) return null; diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs index 9174aea6..35180df2 100644 --- a/src/SMAPI/Framework/Models/SConfig.cs +++ b/src/SMAPI/Framework/Models/SConfig.cs @@ -26,7 +26,7 @@ namespace StardewModdingAPI.Framework.Models }; /// The default values for , to log changes if different. - private static readonly HashSet DefaultSuppressUpdateChecks = new HashSet(StringComparer.OrdinalIgnoreCase) + private static readonly HashSet DefaultSuppressUpdateChecks = new(StringComparer.OrdinalIgnoreCase) { "SMAPI.ConsoleCommands", "SMAPI.ErrorHandler", diff --git a/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs b/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs index ac9cf313..71e11576 100644 --- a/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs +++ b/src/SMAPI/Framework/Networking/SGalaxyNetServer.cs @@ -45,8 +45,8 @@ namespace StardewModdingAPI.Framework.Networking [SuppressMessage("ReSharper", "AccessToDisposedClosure", Justification = "The callback is invoked synchronously.")] protected override void onReceiveMessage(GalaxyID peer, Stream messageStream) { - using IncomingMessage message = new IncomingMessage(); - using BinaryReader reader = new BinaryReader(messageStream); + using IncomingMessage message = new(); + using BinaryReader reader = new(messageStream); message.Read(reader); ulong peerID = peer.ToUint64(); // note: GalaxyID instances get reused, so need to store the underlying ID instead @@ -57,7 +57,7 @@ namespace StardewModdingAPI.Framework.Networking else if (message.MessageType == StardewValley.Multiplayer.playerIntroduction) { NetFarmerRoot farmer = this.Multiplayer.readFarmer(message.Reader); - GalaxyID capturedPeer = new GalaxyID(peerID); + GalaxyID capturedPeer = new(peerID); this.gameServer.checkFarmhandRequest(Convert.ToString(peerID), this.getConnectionId(peer), farmer, msg => this.sendMessage(capturedPeer, msg), () => this.peers[farmer.Value.UniqueMultiplayerID] = capturedPeer.ToUint64()); } }); diff --git a/src/SMAPI/Framework/Networking/SLidgrenServer.cs b/src/SMAPI/Framework/Networking/SLidgrenServer.cs index 05c8b872..ff871e64 100644 --- a/src/SMAPI/Framework/Networking/SLidgrenServer.cs +++ b/src/SMAPI/Framework/Networking/SLidgrenServer.cs @@ -44,9 +44,9 @@ namespace StardewModdingAPI.Framework.Networking { // add hook to call multiplayer core NetConnection peer = rawMessage.SenderConnection; - using IncomingMessage message = new IncomingMessage(); + using IncomingMessage message = new(); using Stream readStream = new NetBufferReadStream(rawMessage); - using BinaryReader reader = new BinaryReader(readStream); + using BinaryReader reader = new(readStream); while (rawMessage.LengthBits - rawMessage.Position >= 8) { diff --git a/src/SMAPI/Framework/Reflection/Reflector.cs b/src/SMAPI/Framework/Reflection/Reflector.cs index 889c7ed6..3a93ab5d 100644 --- a/src/SMAPI/Framework/Reflection/Reflector.cs +++ b/src/SMAPI/Framework/Reflection/Reflector.cs @@ -13,7 +13,7 @@ namespace StardewModdingAPI.Framework.Reflection ** Fields *********/ /// The cached fields and methods found via reflection. - private readonly MemoryCache Cache = new MemoryCache(typeof(Reflector).FullName); + private readonly MemoryCache Cache = new(typeof(Reflector).FullName); /// The sliding cache expiration time. private readonly TimeSpan SlidingCacheExpiry = TimeSpan.FromMinutes(5); @@ -268,7 +268,7 @@ namespace StardewModdingAPI.Framework.Reflection // fetch & cache new value TMemberInfo result = fetch(); - CacheEntry cacheEntry = new CacheEntry(result != null, result); + CacheEntry cacheEntry = new(result != null, result); this.Cache.Add(key, cacheEntry, new CacheItemPolicy { SlidingExpiration = this.SlidingCacheExpiry }); return result; } diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 104cf330..989b59d8 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -37,7 +37,7 @@ namespace StardewModdingAPI.Framework private readonly EventManager Events; /// The maximum number of consecutive attempts SMAPI should make to recover from a draw error. - private readonly Countdown DrawCrashTimer = new Countdown(60); // 60 ticks = roughly one second + private readonly Countdown DrawCrashTimer = new(60); // 60 ticks = roughly one second /// Simplifies access to private game code. private readonly Reflector Reflection; @@ -71,14 +71,14 @@ namespace StardewModdingAPI.Framework public WatcherCore Watchers { get; private set; } /// A snapshot of the current state. - public WatcherSnapshot WatcherSnapshot { get; } = new WatcherSnapshot(); + public WatcherSnapshot WatcherSnapshot { get; } = new(); /// Whether the current update tick is the first one for this instance. public bool IsFirstTick = true; /// The number of ticks until SMAPI should notify mods that the game has loaded. /// Skipping a few frames ensures the game finishes initializing the world before mods try to change it. - public Countdown AfterLoadTimer { get; } = new Countdown(5); + public Countdown AfterLoadTimer { get; } = new(5); /// Whether the game is saving and SMAPI has already raised . public bool IsBetweenSaveEvents { get; set; } @@ -624,7 +624,7 @@ namespace StardewModdingAPI.Framework if (tile != null) { Vector2 vector_draw_position = Game1.GlobalToLocal(Game1.viewport, tile_position * 64f); - Location draw_location = new Location((int)vector_draw_position.X, (int)vector_draw_position.Y); + Location draw_location = new((int)vector_draw_position.X, (int)vector_draw_position.Y); Game1.mapDisplayDevice.DrawTile(tile, draw_location, (tile_position.Y * 64f - 1f) / 10000f); } } diff --git a/src/SMAPI/Framework/SGameRunner.cs b/src/SMAPI/Framework/SGameRunner.cs index b816bb7c..81cac145 100644 --- a/src/SMAPI/Framework/SGameRunner.cs +++ b/src/SMAPI/Framework/SGameRunner.cs @@ -93,7 +93,7 @@ namespace StardewModdingAPI.Framework /// The instance index. public override Game1 CreateGameInstance(PlayerIndex playerIndex = PlayerIndex.One, int instanceIndex = 0) { - SInputState inputState = new SInputState(); + SInputState inputState = new(); return new SGame(playerIndex, instanceIndex, this.Monitor, this.Reflection, this.Events, inputState, this.ModHooks, this.Multiplayer, this.ExitGameImmediately, this.OnPlayerInstanceUpdating, this.OnGameContentLoaded); } diff --git a/src/SMAPI/Framework/SMultiplayer.cs b/src/SMAPI/Framework/SMultiplayer.cs index 5956b63f..3981e4e5 100644 --- a/src/SMAPI/Framework/SMultiplayer.cs +++ b/src/SMAPI/Framework/SMultiplayer.cs @@ -56,10 +56,10 @@ namespace StardewModdingAPI.Framework private readonly bool LogNetworkTraffic; /// The backing field for . - private readonly PerScreen> PeersImpl = new PerScreen>(() => new Dictionary()); + private readonly PerScreen> PeersImpl = new(() => new Dictionary()); /// The backing field for . - private readonly PerScreen HostPeerImpl = new PerScreen(); + private readonly PerScreen HostPeerImpl = new(); /********* @@ -196,7 +196,7 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($"Received context for farmhand {message.FarmerID} running {(model != null ? $"SMAPI {model.ApiVersion} with {model.Mods.Length} mods" : "vanilla")}.", LogLevel.Trace); // store peer - MultiplayerPeer newPeer = new MultiplayerPeer( + MultiplayerPeer newPeer = new( playerID: message.FarmerID, screenID: this.GetScreenId(message.FarmerID), model: model, @@ -244,7 +244,7 @@ namespace StardewModdingAPI.Framework if (!this.Peers.ContainsKey(message.FarmerID)) { this.Monitor.Log($"Received connection for vanilla player {message.FarmerID}.", LogLevel.Trace); - MultiplayerPeer peer = new MultiplayerPeer( + MultiplayerPeer peer = new( playerID: message.FarmerID, screenID: this.GetScreenId(message.FarmerID), model: null, @@ -292,7 +292,7 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($"Received context for {(model?.IsHost == true ? "host" : "farmhand")} {message.FarmerID} running {(model != null ? $"SMAPI {model.ApiVersion} with {model.Mods.Length} mods" : "vanilla")}.", LogLevel.Trace); // store peer - MultiplayerPeer peer = new MultiplayerPeer( + MultiplayerPeer peer = new( playerID: message.FarmerID, screenID: this.GetScreenId(message.FarmerID), model: model, @@ -420,7 +420,7 @@ namespace StardewModdingAPI.Framework } // get data to send - ModMessageModel model = new ModMessageModel( + ModMessageModel model = new( fromPlayerID: Game1.player.UniqueMultiplayerID, fromModID: fromModID, toModIDs: toModIDs, @@ -513,7 +513,7 @@ namespace StardewModdingAPI.Framework // forward to other players if (Context.IsMainPlayer && playerIDs.Any(p => p != Game1.player.UniqueMultiplayerID)) { - ModMessageModel newModel = new ModMessageModel(model); + ModMessageModel newModel = new(model); foreach (long playerID in playerIDs) { if (playerID != Game1.player.UniqueMultiplayerID && playerID != model.FromPlayerID && this.Peers.TryGetValue(playerID, out MultiplayerPeer peer)) @@ -544,7 +544,7 @@ namespace StardewModdingAPI.Framework /// Get the fields to include in a context sync message sent to other players. private object[] GetContextSyncMessageFields() { - RemoteContextModel model = new RemoteContextModel + RemoteContextModel model = new() { IsHost = Context.IsWorldReady && Context.IsMainPlayer, Platform = Constants.TargetPlatform, @@ -571,7 +571,7 @@ namespace StardewModdingAPI.Framework if (!peer.HasSmapi) return new object[] { "{}" }; - RemoteContextModel model = new RemoteContextModel + RemoteContextModel model = new() { IsHost = peer.IsHost, Platform = peer.Platform.Value, diff --git a/src/SMAPI/Framework/Singleton.cs b/src/SMAPI/Framework/Singleton.cs index 399a8bf0..1bf318c4 100644 --- a/src/SMAPI/Framework/Singleton.cs +++ b/src/SMAPI/Framework/Singleton.cs @@ -5,6 +5,6 @@ namespace StardewModdingAPI.Framework internal static class Singleton where T : new() { /// The singleton instance. - public static T Instance { get; } = new T(); + public static T Instance { get; } = new(); } } diff --git a/src/SMAPI/Framework/SnapshotListDiff.cs b/src/SMAPI/Framework/SnapshotListDiff.cs index 2d0efa0d..1c3ebfba 100644 --- a/src/SMAPI/Framework/SnapshotListDiff.cs +++ b/src/SMAPI/Framework/SnapshotListDiff.cs @@ -11,10 +11,10 @@ namespace StardewModdingAPI.Framework ** Fields *********/ /// The removed values. - private readonly List RemovedImpl = new List(); + private readonly List RemovedImpl = new(); /// The added values. - private readonly List AddedImpl = new List(); + private readonly List AddedImpl = new(); /********* diff --git a/src/SMAPI/Framework/StateTracking/ChestTracker.cs b/src/SMAPI/Framework/StateTracking/ChestTracker.cs index 65f58ee7..56aeeb3c 100644 --- a/src/SMAPI/Framework/StateTracking/ChestTracker.cs +++ b/src/SMAPI/Framework/StateTracking/ChestTracker.cs @@ -18,10 +18,10 @@ namespace StardewModdingAPI.Framework.StateTracking private readonly IDictionary StackSizes; /// Items added since the last update. - private readonly HashSet Added = new HashSet(new ObjectReferenceComparer()); + private readonly HashSet Added = new(new ObjectReferenceComparer()); /// Items removed since the last update. - private readonly HashSet Removed = new HashSet(new ObjectReferenceComparer()); + private readonly HashSet Removed = new(new ObjectReferenceComparer()); /// The underlying inventory watcher. private readonly ICollectionWatcher InventoryWatcher; diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs index 32ec8c7e..256370ce 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs @@ -17,10 +17,10 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers private HashSet LastValues; /// The pairs added since the last reset. - private readonly List AddedImpl = new List(); + private readonly List AddedImpl = new(); /// The pairs removed since the last reset. - private readonly List RemovedImpl = new List(); + private readonly List RemovedImpl = new(); /********* diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs index 009e0282..84340fbf 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs @@ -11,7 +11,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers ** Accessors *********/ /// A singleton collection watcher instance. - public static ImmutableCollectionWatcher Instance { get; } = new ImmutableCollectionWatcher(); + public static ImmutableCollectionWatcher Instance { get; } = new(); /// Whether the collection changed since the last reset. public bool IsChanged { get; } = false; diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs index 21e84c47..676c9fb4 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs @@ -15,10 +15,10 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers private readonly NetCollection Field; /// The pairs added since the last reset. - private readonly List AddedImpl = new List(); + private readonly List AddedImpl = new(); /// The pairs removed since the last reset. - private readonly List RemovedImpl = new List(); + private readonly List RemovedImpl = new(); /********* diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs index c29d2783..3e9fa8b1 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs @@ -16,13 +16,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers private readonly ObservableCollection Field; /// The pairs added since the last reset. - private readonly List AddedImpl = new List(); + private readonly List AddedImpl = new(); /// The pairs removed since the last reset. - private readonly List RemovedImpl = new List(); + private readonly List RemovedImpl = new(); /// The previous values as of the last update. - private readonly List PreviousValues = new List(); + private readonly List PreviousValues = new(); /********* diff --git a/src/SMAPI/Framework/StateTracking/LocationTracker.cs b/src/SMAPI/Framework/StateTracking/LocationTracker.cs index 748e4ecc..f86f86ee 100644 --- a/src/SMAPI/Framework/StateTracking/LocationTracker.cs +++ b/src/SMAPI/Framework/StateTracking/LocationTracker.cs @@ -19,7 +19,7 @@ namespace StardewModdingAPI.Framework.StateTracking ** Fields *********/ /// The underlying watchers. - private readonly List Watchers = new List(); + private readonly List Watchers = new(); /********* diff --git a/src/SMAPI/Framework/StateTracking/PlayerTracker.cs b/src/SMAPI/Framework/StateTracking/PlayerTracker.cs index cf49a7c1..3d470b5c 100644 --- a/src/SMAPI/Framework/StateTracking/PlayerTracker.cs +++ b/src/SMAPI/Framework/StateTracking/PlayerTracker.cs @@ -24,7 +24,7 @@ namespace StardewModdingAPI.Framework.StateTracking private GameLocation LastValidLocation; /// The underlying watchers. - private readonly List Watchers = new List(); + private readonly List Watchers = new(); /********* diff --git a/src/SMAPI/Framework/StateTracking/Snapshots/LocationSnapshot.cs b/src/SMAPI/Framework/StateTracking/Snapshots/LocationSnapshot.cs index 6c9cc4f5..2563d10c 100644 --- a/src/SMAPI/Framework/StateTracking/Snapshots/LocationSnapshot.cs +++ b/src/SMAPI/Framework/StateTracking/Snapshots/LocationSnapshot.cs @@ -17,25 +17,25 @@ namespace StardewModdingAPI.Framework.StateTracking.Snapshots public GameLocation Location { get; } /// Tracks added or removed buildings. - public SnapshotListDiff Buildings { get; } = new SnapshotListDiff(); + public SnapshotListDiff Buildings { get; } = new(); /// Tracks added or removed debris. - public SnapshotListDiff Debris { get; } = new SnapshotListDiff(); + public SnapshotListDiff Debris { get; } = new(); /// Tracks added or removed large terrain features. - public SnapshotListDiff LargeTerrainFeatures { get; } = new SnapshotListDiff(); + public SnapshotListDiff LargeTerrainFeatures { get; } = new(); /// Tracks added or removed NPCs. - public SnapshotListDiff Npcs { get; } = new SnapshotListDiff(); + public SnapshotListDiff Npcs { get; } = new(); /// Tracks added or removed objects. - public SnapshotListDiff> Objects { get; } = new SnapshotListDiff>(); + public SnapshotListDiff> Objects { get; } = new(); /// Tracks added or removed terrain features. - public SnapshotListDiff> TerrainFeatures { get; } = new SnapshotListDiff>(); + public SnapshotListDiff> TerrainFeatures { get; } = new(); /// Tracks added or removed furniture. - public SnapshotListDiff Furniture { get; } = new SnapshotListDiff(); + public SnapshotListDiff Furniture { get; } = new(); /// Tracks changed chest inventories. public IDictionary ChestItems { get; } = new Dictionary(); diff --git a/src/SMAPI/Framework/StateTracking/Snapshots/PlayerSnapshot.cs b/src/SMAPI/Framework/StateTracking/Snapshots/PlayerSnapshot.cs index 72f45a87..f3e42948 100644 --- a/src/SMAPI/Framework/StateTracking/Snapshots/PlayerSnapshot.cs +++ b/src/SMAPI/Framework/StateTracking/Snapshots/PlayerSnapshot.cs @@ -14,7 +14,7 @@ namespace StardewModdingAPI.Framework.StateTracking.Snapshots ** Fields *********/ /// An empty item list diff. - private readonly SnapshotItemListDiff EmptyItemListDiff = new SnapshotItemListDiff(Array.Empty(), Array.Empty(), Array.Empty()); + private readonly SnapshotItemListDiff EmptyItemListDiff = new(Array.Empty(), Array.Empty(), Array.Empty()); /********* @@ -24,7 +24,7 @@ namespace StardewModdingAPI.Framework.StateTracking.Snapshots public Farmer Player { get; } /// The player's current location. - public SnapshotDiff Location { get; } = new SnapshotDiff(); + public SnapshotDiff Location { get; } = new(); /// Tracks changes to the player's skill levels. public IDictionary> Skills { get; } = diff --git a/src/SMAPI/Framework/StateTracking/Snapshots/WatcherSnapshot.cs b/src/SMAPI/Framework/StateTracking/Snapshots/WatcherSnapshot.cs index cf51e040..afea7fb4 100644 --- a/src/SMAPI/Framework/StateTracking/Snapshots/WatcherSnapshot.cs +++ b/src/SMAPI/Framework/StateTracking/Snapshots/WatcherSnapshot.cs @@ -11,31 +11,31 @@ namespace StardewModdingAPI.Framework.StateTracking.Snapshots ** Accessors *********/ /// Tracks changes to the window size. - public SnapshotDiff WindowSize { get; } = new SnapshotDiff(); + public SnapshotDiff WindowSize { get; } = new(); /// Tracks changes to the current player. public PlayerSnapshot CurrentPlayer { get; private set; } /// Tracks changes to the time of day (in 24-hour military format). - public SnapshotDiff Time { get; } = new SnapshotDiff(); + public SnapshotDiff Time { get; } = new(); /// Tracks changes to the save ID. - public SnapshotDiff SaveID { get; } = new SnapshotDiff(); + public SnapshotDiff SaveID { get; } = new(); /// Tracks changes to the game's locations. - public WorldLocationsSnapshot Locations { get; } = new WorldLocationsSnapshot(); + public WorldLocationsSnapshot Locations { get; } = new(); /// Tracks changes to . - public SnapshotDiff ActiveMenu { get; } = new SnapshotDiff(); + public SnapshotDiff ActiveMenu { get; } = new(); /// Tracks changes to the cursor position. - public SnapshotDiff Cursor { get; } = new SnapshotDiff(); + public SnapshotDiff Cursor { get; } = new(); /// Tracks changes to the mouse wheel scroll. - public SnapshotDiff MouseWheelScroll { get; } = new SnapshotDiff(); + public SnapshotDiff MouseWheelScroll { get; } = new(); /// Tracks changes to the content locale. - public SnapshotDiff Locale { get; } = new SnapshotDiff(); + public SnapshotDiff Locale { get; } = new(); /********* diff --git a/src/SMAPI/Framework/StateTracking/Snapshots/WorldLocationsSnapshot.cs b/src/SMAPI/Framework/StateTracking/Snapshots/WorldLocationsSnapshot.cs index 73ed2d8f..7dee09ca 100644 --- a/src/SMAPI/Framework/StateTracking/Snapshots/WorldLocationsSnapshot.cs +++ b/src/SMAPI/Framework/StateTracking/Snapshots/WorldLocationsSnapshot.cs @@ -12,14 +12,14 @@ namespace StardewModdingAPI.Framework.StateTracking.Snapshots ** Fields *********/ /// A map of tracked locations. - private readonly Dictionary LocationsDict = new Dictionary(new ObjectReferenceComparer()); + private readonly Dictionary LocationsDict = new(new ObjectReferenceComparer()); /********* ** Accessors *********/ /// Tracks changes to the location list. - public SnapshotListDiff LocationList { get; } = new SnapshotListDiff(); + public SnapshotListDiff LocationList { get; } = new(); /// The tracked locations. public IEnumerable Locations => this.LocationsDict.Values; diff --git a/src/SMAPI/Framework/TemporaryHacks/MiniMonoModHotfix.cs b/src/SMAPI/Framework/TemporaryHacks/MiniMonoModHotfix.cs index 173438f1..cab1a94c 100644 --- a/src/SMAPI/Framework/TemporaryHacks/MiniMonoModHotfix.cs +++ b/src/SMAPI/Framework/TemporaryHacks/MiniMonoModHotfix.cs @@ -55,7 +55,7 @@ namespace MonoMod.Utils .GetType("System.RuntimeType+RuntimeTypeCache") ?.GetMethod("GetPropertyList", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); - private static readonly ConditionalWeakTable _CacheFixed = new ConditionalWeakTable(); + private static readonly ConditionalWeakTable _CacheFixed = new(); public static void Apply() { @@ -144,7 +144,7 @@ namespace MonoMod.Utils continue; CacheFixEntry entry = _CacheFixed.GetValue(type, rt => { - CacheFixEntry entryNew = new CacheFixEntry(); + CacheFixEntry entryNew = new(); object cache; Array properties, fields; diff --git a/src/SMAPI/Framework/WatcherCore.cs b/src/SMAPI/Framework/WatcherCore.cs index 62a0c3b8..a1612e75 100644 --- a/src/SMAPI/Framework/WatcherCore.cs +++ b/src/SMAPI/Framework/WatcherCore.cs @@ -17,7 +17,7 @@ namespace StardewModdingAPI.Framework ** Fields *********/ /// The underlying watchers for convenience. These are accessible individually as separate properties. - private readonly List Watchers = new List(); + private readonly List Watchers = new(); /********* diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index f2f65287..29f4be1b 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -199,7 +199,7 @@ namespace StardewModdingAPI } // load SMAPI - using SCore core = new SCore(modsPath, writeToConsole); + using SCore core = new(modsPath, writeToConsole); core.RunInteractively(); } -- cgit