diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-04-06 18:24:59 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-04-06 18:24:59 -0400 |
commit | a593eda30f82af474887d91458b0e9158f66fefc (patch) | |
tree | 8aa0e0586e3cce7627e8c4ff445a953665953f8f /src/SMAPI/Framework | |
parent | 29f909a8d5dbb83d6df1a54d2680e6f9898f3b19 (diff) | |
download | SMAPI-a593eda30f82af474887d91458b0e9158f66fefc.tar.gz SMAPI-a593eda30f82af474887d91458b0e9158f66fefc.tar.bz2 SMAPI-a593eda30f82af474887d91458b0e9158f66fefc.zip |
use target-typed new
Diffstat (limited to 'src/SMAPI/Framework')
33 files changed, 83 insertions, 83 deletions
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<string> args = new List<string>(); - 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 *********/ /// <summary>The deprecations which have already been logged (as 'mod name::noun phrase::version').</summary> - private readonly HashSet<string> LoggedDeprecations = new HashSet<string>(StringComparer.OrdinalIgnoreCase); + private readonly HashSet<string> LoggedDeprecations = new(StringComparer.OrdinalIgnoreCase); /// <summary>Encapsulates monitoring and logging for a given module.</summary> 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; /// <summary>The underlying event handlers.</summary> - private readonly List<ManagedEventHandler<TEventArgs>> Handlers = new List<ManagedEventHandler<TEventArgs>>(); + private readonly List<ManagedEventHandler<TEventArgs>> Handlers = new(); /// <summary>A cached snapshot of <see cref="Handlers"/>, or <c>null</c> to rebuild it next raise.</summary> private ManagedEventHandler<TEventArgs>[] CachedHandlers = Array.Empty<ManagedEventHandler<TEventArgs>>(); 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; /// <summary>The pressed buttons.</summary> - private readonly HashSet<Keys> PressedButtons = new HashSet<Keys>(); + private readonly HashSet<Keys> 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; /// <summary>The buttons to press until the game next handles input.</summary> - private readonly HashSet<SButton> CustomPressedKeys = new HashSet<SButton>(); + private readonly HashSet<SButton> CustomPressedKeys = new(); /// <summary>The buttons to consider released until the actual button is released.</summary> - private readonly HashSet<SButton> CustomReleasedKeys = new HashSet<SButton>(); + private readonly HashSet<SButton> CustomReleasedKeys = new(); /// <summary>Whether there are new overrides in <see cref="CustomPressedKeys"/> or <see cref="CustomReleasedKeys"/> that haven't been applied to the previous state.</summary> 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<SButton> reallyDown = new HashSet<SButton>(this.GetPressedButtons(keyboard, mouse, controller)); @@ -203,8 +203,8 @@ namespace StardewModdingAPI.Framework.Input /// <param name="zoomMultiplier">The multiplier applied to pixel coordinates to adjust them for pixel zoom.</param> 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; /// <summary>Provides assembly symbol readers for Mono.Cecil.</summary> - private readonly SymbolReaderProvider SymbolReaderProvider = new SymbolReaderProvider(); + private readonly SymbolReaderProvider SymbolReaderProvider = new(); /// <summary>Provides assembly symbol writers for Mono.Cecil.</summary> - private readonly SymbolWriterProvider SymbolWriterProvider = new SymbolWriterProvider(); + private readonly SymbolWriterProvider SymbolWriterProvider = new(); /// <summary>The objects to dispose as part of this instance.</summary> - private readonly HashSet<IDisposable> Disposables = new HashSet<IDisposable>(); + private readonly HashSet<IDisposable> Disposables = new(); /// <summary>Whether to rewrite mods for compatibility.</summary> 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); /// <summary>The symbol data loaded by absolute assembly path.</summary> - private readonly Dictionary<string, Stream> SymbolsByAssemblyPath = new Dictionary<string, Stream>(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary<string, Stream> 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 *********/ /// <summary>The registered mod data.</summary> - private readonly List<IModMetadata> Mods = new List<IModMetadata>(); + private readonly List<IModMetadata> Mods = new(); /// <summary>An assembly full name => mod lookup.</summary> private readonly IDictionary<string, IModMetadata> ModNamesByAssembly = new Dictionary<string, IModMetadata>(); @@ -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 }; /// <summary>The default values for <see cref="SuppressUpdateChecks"/>, to log changes if different.</summary> - private static readonly HashSet<string> DefaultSuppressUpdateChecks = new HashSet<string>(StringComparer.OrdinalIgnoreCase) + private static readonly HashSet<string> 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 *********/ /// <summary>The cached fields and methods found via reflection.</summary> - private readonly MemoryCache Cache = new MemoryCache(typeof(Reflector).FullName); + private readonly MemoryCache Cache = new(typeof(Reflector).FullName); /// <summary>The sliding cache expiration time.</summary> 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; /// <summary>The maximum number of consecutive attempts SMAPI should make to recover from a draw error.</summary> - private readonly Countdown DrawCrashTimer = new Countdown(60); // 60 ticks = roughly one second + private readonly Countdown DrawCrashTimer = new(60); // 60 ticks = roughly one second /// <summary>Simplifies access to private game code.</summary> private readonly Reflector Reflection; @@ -71,14 +71,14 @@ namespace StardewModdingAPI.Framework public WatcherCore Watchers { get; private set; } /// <summary>A snapshot of the current <see cref="Watchers"/> state.</summary> - public WatcherSnapshot WatcherSnapshot { get; } = new WatcherSnapshot(); + public WatcherSnapshot WatcherSnapshot { get; } = new(); /// <summary>Whether the current update tick is the first one for this instance.</summary> public bool IsFirstTick = true; /// <summary>The number of ticks until SMAPI should notify mods that the game has loaded.</summary> /// <remarks>Skipping a few frames ensures the game finishes initializing the world before mods try to change it.</remarks> - public Countdown AfterLoadTimer { get; } = new Countdown(5); + public Countdown AfterLoadTimer { get; } = new(5); /// <summary>Whether the game is saving and SMAPI has already raised <see cref="IGameLoopEvents.Saving"/>.</summary> 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 /// <param name="instanceIndex">The instance index.</param> 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; /// <summary>The backing field for <see cref="Peers"/>.</summary> - private readonly PerScreen<IDictionary<long, MultiplayerPeer>> PeersImpl = new PerScreen<IDictionary<long, MultiplayerPeer>>(() => new Dictionary<long, MultiplayerPeer>()); + private readonly PerScreen<IDictionary<long, MultiplayerPeer>> PeersImpl = new(() => new Dictionary<long, MultiplayerPeer>()); /// <summary>The backing field for <see cref="HostPeer"/>.</summary> - private readonly PerScreen<MultiplayerPeer> HostPeerImpl = new PerScreen<MultiplayerPeer>(); + private readonly PerScreen<MultiplayerPeer> 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 /// <summary>Get the fields to include in a context sync message sent to other players.</summary> 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<T> where T : new() { /// <summary>The singleton instance.</summary> - 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 *********/ /// <summary>The removed values.</summary> - private readonly List<T> RemovedImpl = new List<T>(); + private readonly List<T> RemovedImpl = new(); /// <summary>The added values.</summary> - private readonly List<T> AddedImpl = new List<T>(); + private readonly List<T> 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<Item, int> StackSizes; /// <summary>Items added since the last update.</summary> - private readonly HashSet<Item> Added = new HashSet<Item>(new ObjectReferenceComparer<Item>()); + private readonly HashSet<Item> Added = new(new ObjectReferenceComparer<Item>()); /// <summary>Items removed since the last update.</summary> - private readonly HashSet<Item> Removed = new HashSet<Item>(new ObjectReferenceComparer<Item>()); + private readonly HashSet<Item> Removed = new(new ObjectReferenceComparer<Item>()); /// <summary>The underlying inventory watcher.</summary> private readonly ICollectionWatcher<Item> 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<TValue> LastValues; /// <summary>The pairs added since the last reset.</summary> - private readonly List<TValue> AddedImpl = new List<TValue>(); + private readonly List<TValue> AddedImpl = new(); /// <summary>The pairs removed since the last reset.</summary> - private readonly List<TValue> RemovedImpl = new List<TValue>(); + private readonly List<TValue> 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 *********/ /// <summary>A singleton collection watcher instance.</summary> - public static ImmutableCollectionWatcher<TValue> Instance { get; } = new ImmutableCollectionWatcher<TValue>(); + public static ImmutableCollectionWatcher<TValue> Instance { get; } = new(); /// <summary>Whether the collection changed since the last reset.</summary> 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<TValue> Field; /// <summary>The pairs added since the last reset.</summary> - private readonly List<TValue> AddedImpl = new List<TValue>(); + private readonly List<TValue> AddedImpl = new(); /// <summary>The pairs removed since the last reset.</summary> - private readonly List<TValue> RemovedImpl = new List<TValue>(); + private readonly List<TValue> 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<TValue> Field; /// <summary>The pairs added since the last reset.</summary> - private readonly List<TValue> AddedImpl = new List<TValue>(); + private readonly List<TValue> AddedImpl = new(); /// <summary>The pairs removed since the last reset.</summary> - private readonly List<TValue> RemovedImpl = new List<TValue>(); + private readonly List<TValue> RemovedImpl = new(); /// <summary>The previous values as of the last update.</summary> - private readonly List<TValue> PreviousValues = new List<TValue>(); + private readonly List<TValue> 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 *********/ /// <summary>The underlying watchers.</summary> - private readonly List<IWatcher> Watchers = new List<IWatcher>(); + private readonly List<IWatcher> 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; /// <summary>The underlying watchers.</summary> - private readonly List<IWatcher> Watchers = new List<IWatcher>(); + private readonly List<IWatcher> 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; } /// <summary>Tracks added or removed buildings.</summary> - public SnapshotListDiff<Building> Buildings { get; } = new SnapshotListDiff<Building>(); + public SnapshotListDiff<Building> Buildings { get; } = new(); /// <summary>Tracks added or removed debris.</summary> - public SnapshotListDiff<Debris> Debris { get; } = new SnapshotListDiff<Debris>(); + public SnapshotListDiff<Debris> Debris { get; } = new(); /// <summary>Tracks added or removed large terrain features.</summary> - public SnapshotListDiff<LargeTerrainFeature> LargeTerrainFeatures { get; } = new SnapshotListDiff<LargeTerrainFeature>(); + public SnapshotListDiff<LargeTerrainFeature> LargeTerrainFeatures { get; } = new(); /// <summary>Tracks added or removed NPCs.</summary> - public SnapshotListDiff<NPC> Npcs { get; } = new SnapshotListDiff<NPC>(); + public SnapshotListDiff<NPC> Npcs { get; } = new(); /// <summary>Tracks added or removed objects.</summary> - public SnapshotListDiff<KeyValuePair<Vector2, Object>> Objects { get; } = new SnapshotListDiff<KeyValuePair<Vector2, Object>>(); + public SnapshotListDiff<KeyValuePair<Vector2, Object>> Objects { get; } = new(); /// <summary>Tracks added or removed terrain features.</summary> - public SnapshotListDiff<KeyValuePair<Vector2, TerrainFeature>> TerrainFeatures { get; } = new SnapshotListDiff<KeyValuePair<Vector2, TerrainFeature>>(); + public SnapshotListDiff<KeyValuePair<Vector2, TerrainFeature>> TerrainFeatures { get; } = new(); /// <summary>Tracks added or removed furniture.</summary> - public SnapshotListDiff<Furniture> Furniture { get; } = new SnapshotListDiff<Furniture>(); + public SnapshotListDiff<Furniture> Furniture { get; } = new(); /// <summary>Tracks changed chest inventories.</summary> public IDictionary<Chest, SnapshotItemListDiff> ChestItems { get; } = new Dictionary<Chest, SnapshotItemListDiff>(); 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 *********/ /// <summary>An empty item list diff.</summary> - private readonly SnapshotItemListDiff EmptyItemListDiff = new SnapshotItemListDiff(Array.Empty<Item>(), Array.Empty<Item>(), Array.Empty<ItemStackSizeChange>()); + private readonly SnapshotItemListDiff EmptyItemListDiff = new(Array.Empty<Item>(), Array.Empty<Item>(), Array.Empty<ItemStackSizeChange>()); /********* @@ -24,7 +24,7 @@ namespace StardewModdingAPI.Framework.StateTracking.Snapshots public Farmer Player { get; } /// <summary>The player's current location.</summary> - public SnapshotDiff<GameLocation> Location { get; } = new SnapshotDiff<GameLocation>(); + public SnapshotDiff<GameLocation> Location { get; } = new(); /// <summary>Tracks changes to the player's skill levels.</summary> public IDictionary<SkillType, SnapshotDiff<int>> 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 *********/ /// <summary>Tracks changes to the window size.</summary> - public SnapshotDiff<Point> WindowSize { get; } = new SnapshotDiff<Point>(); + public SnapshotDiff<Point> WindowSize { get; } = new(); /// <summary>Tracks changes to the current player.</summary> public PlayerSnapshot CurrentPlayer { get; private set; } /// <summary>Tracks changes to the time of day (in 24-hour military format).</summary> - public SnapshotDiff<int> Time { get; } = new SnapshotDiff<int>(); + public SnapshotDiff<int> Time { get; } = new(); /// <summary>Tracks changes to the save ID.</summary> - public SnapshotDiff<ulong> SaveID { get; } = new SnapshotDiff<ulong>(); + public SnapshotDiff<ulong> SaveID { get; } = new(); /// <summary>Tracks changes to the game's locations.</summary> - public WorldLocationsSnapshot Locations { get; } = new WorldLocationsSnapshot(); + public WorldLocationsSnapshot Locations { get; } = new(); /// <summary>Tracks changes to <see cref="Game1.activeClickableMenu"/>.</summary> - public SnapshotDiff<IClickableMenu> ActiveMenu { get; } = new SnapshotDiff<IClickableMenu>(); + public SnapshotDiff<IClickableMenu> ActiveMenu { get; } = new(); /// <summary>Tracks changes to the cursor position.</summary> - public SnapshotDiff<ICursorPosition> Cursor { get; } = new SnapshotDiff<ICursorPosition>(); + public SnapshotDiff<ICursorPosition> Cursor { get; } = new(); /// <summary>Tracks changes to the mouse wheel scroll.</summary> - public SnapshotDiff<int> MouseWheelScroll { get; } = new SnapshotDiff<int>(); + public SnapshotDiff<int> MouseWheelScroll { get; } = new(); /// <summary>Tracks changes to the content locale.</summary> - public SnapshotDiff<LocalizedContentManager.LanguageCode> Locale { get; } = new SnapshotDiff<LocalizedContentManager.LanguageCode>(); + public SnapshotDiff<LocalizedContentManager.LanguageCode> 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 *********/ /// <summary>A map of tracked locations.</summary> - private readonly Dictionary<GameLocation, LocationSnapshot> LocationsDict = new Dictionary<GameLocation, LocationSnapshot>(new ObjectReferenceComparer<GameLocation>()); + private readonly Dictionary<GameLocation, LocationSnapshot> LocationsDict = new(new ObjectReferenceComparer<GameLocation>()); /********* ** Accessors *********/ /// <summary>Tracks changes to the location list.</summary> - public SnapshotListDiff<GameLocation> LocationList { get; } = new SnapshotListDiff<GameLocation>(); + public SnapshotListDiff<GameLocation> LocationList { get; } = new(); /// <summary>The tracked locations.</summary> public IEnumerable<LocationSnapshot> 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<Type, CacheFixEntry> _CacheFixed = new ConditionalWeakTable<Type, CacheFixEntry>(); + private static readonly ConditionalWeakTable<Type, CacheFixEntry> _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 *********/ /// <summary>The underlying watchers for convenience. These are accessible individually as separate properties.</summary> - private readonly List<IWatcher> Watchers = new List<IWatcher>(); + private readonly List<IWatcher> Watchers = new(); /********* |