From 625f9c89e4db470c0325b5d148c5286c1b5e54eb Mon Sep 17 00:00:00 2001 From: Gormogon Date: Sun, 29 May 2016 16:13:24 -0400 Subject: Take advantage of some new language opportunities. --- StardewModdingAPI/Inheritance/Menus/SBobberBar.cs | 8 ++--- StardewModdingAPI/Inheritance/Menus/SGameMenu.cs | 3 +- .../Inheritance/Menus/SInventoryPage.cs | 3 +- StardewModdingAPI/Inheritance/SGame.cs | 13 ++++----- StardewModdingAPI/Inheritance/SObject.cs | 34 ++++++++++++---------- StardewModdingAPI/ModItem.cs | 5 +--- StardewModdingAPI/Program.cs | 13 +++------ TrainerMod/TrainerMod.cs | 3 +- 8 files changed, 33 insertions(+), 49 deletions(-) diff --git a/StardewModdingAPI/Inheritance/Menus/SBobberBar.cs b/StardewModdingAPI/Inheritance/Menus/SBobberBar.cs index 5f410280..1e424f73 100644 --- a/StardewModdingAPI/Inheritance/Menus/SBobberBar.cs +++ b/StardewModdingAPI/Inheritance/Menus/SBobberBar.cs @@ -267,15 +267,11 @@ namespace StardewModdingAPI.Inheritance.Menus set { GetBaseFieldInfo("bobberBarAcceleration").SetValue(BaseBobberBar, value); } } - public static FieldInfo[] PrivateFields - { - get { return GetPrivateFields(); } - } + public static FieldInfo[] PrivateFields => GetPrivateFields(); public static SBobberBar ConstructFromBaseClass(BobberBar baseClass) { - var b = new SBobberBar(0, 0, false, 0); - b.BaseBobberBar = baseClass; + var b = new SBobberBar(0, 0, false, 0) {BaseBobberBar = baseClass}; return b; } diff --git a/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs b/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs index 7264faac..a4d3d8d0 100644 --- a/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs +++ b/StardewModdingAPI/Inheritance/Menus/SGameMenu.cs @@ -22,8 +22,7 @@ namespace StardewModdingAPI.Inheritance.Menus public static SGameMenu ConstructFromBaseClass(GameMenu baseClass) { - var s = new SGameMenu(); - s.BaseGameMenu = baseClass; + var s = new SGameMenu {BaseGameMenu = baseClass}; return s; } diff --git a/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs b/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs index a51b2d71..436b834d 100644 --- a/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs +++ b/StardewModdingAPI/Inheritance/Menus/SInventoryPage.cs @@ -12,8 +12,7 @@ namespace StardewModdingAPI.Inheritance.Menus public static SInventoryPage ConstructFromBaseClass(InventoryPage baseClass) { - var s = new SInventoryPage(0, 0, 0, 0); - s.BaseInventoryPage = baseClass; + var s = new SInventoryPage(0, 0, 0, 0) {BaseInventoryPage = baseClass}; return s; } } diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 5597e463..9b69434a 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -506,8 +506,7 @@ namespace StardewModdingAPI.Inheritance //this.checkForEscapeKeys(); updateMusic(); updateRaindropPosition(); - if (bloom != null) - bloom.tick(gameTime); + bloom?.tick(gameTime); if (globalFade) { if (!dialogueUp) @@ -559,8 +558,7 @@ namespace StardewModdingAPI.Inheritance if (pauseThenDoFunctionTimer <= 0) { freezeControls = false; - if (afterPause != null) - afterPause(); + afterPause?.Invoke(); } } if (gameMode == 3 || gameMode == 2) @@ -657,8 +655,8 @@ namespace StardewModdingAPI.Inheritance currentMinigame.releaseLeftClick(getMouseX(), getMouseY()); foreach (Buttons b in Utility.getPressedButtons(oldPadState, state3)) currentMinigame.receiveKeyRelease(Utility.mapGamePadButtonToKey(b)); - if (state3.IsConnected && state3.IsButtonDown(Buttons.A) && currentMinigame != null) - currentMinigame.leftClickHeld(0, 0); + if (state3.IsConnected && state3.IsButtonDown(Buttons.A)) + currentMinigame?.leftClickHeld(0, 0); } if (currentMinigame == null) { @@ -774,8 +772,7 @@ namespace StardewModdingAPI.Inheritance if (gameMode == 10) UpdateOther(gameTime); } - if (audioEngine != null) - audioEngine.Update(); + audioEngine?.Update(); if (multiplayerMode == 2 && gameMode == 3) server.sendMessages(gameTime); } diff --git a/StardewModdingAPI/Inheritance/SObject.cs b/StardewModdingAPI/Inheritance/SObject.cs index 9ffe2a85..639b85b1 100644 --- a/StardewModdingAPI/Inheritance/SObject.cs +++ b/StardewModdingAPI/Inheritance/SObject.cs @@ -181,22 +181,24 @@ namespace StardewModdingAPI.Inheritance public SObject Clone() { - var toRet = new SObject(); - - toRet.Name = Name; - toRet.CategoryName = CategoryName; - toRet.Description = Description; - toRet.Texture = Texture; - toRet.IsPassable = IsPassable; - toRet.IsPlaceable = IsPlaceable; - toRet.quality = quality; - toRet.scale = scale; - toRet.isSpawnedObject = isSpawnedObject; - toRet.isRecipe = isRecipe; - toRet.questItem = questItem; - toRet.stack = 1; - toRet.HasBeenRegistered = HasBeenRegistered; - toRet.RegisteredId = RegisteredId; + var toRet = new SObject + { + Name = Name, + CategoryName = CategoryName, + Description = Description, + Texture = Texture, + IsPassable = IsPassable, + IsPlaceable = IsPlaceable, + quality = quality, + scale = scale, + isSpawnedObject = isSpawnedObject, + isRecipe = isRecipe, + questItem = questItem, + stack = 1, + HasBeenRegistered = HasBeenRegistered, + RegisteredId = RegisteredId + }; + return toRet; } diff --git a/StardewModdingAPI/ModItem.cs b/StardewModdingAPI/ModItem.cs index 10c4fde4..cf2e10b2 100644 --- a/StardewModdingAPI/ModItem.cs +++ b/StardewModdingAPI/ModItem.cs @@ -5,10 +5,7 @@ namespace StardewModdingAPI { internal class ModItem : Object { - public Item AsItem - { - get { return this; } - } + public Item AsItem => this; public override string Name { get; set; } public string Description { get; set; } diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 60e6efb4..35963b08 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -89,25 +89,23 @@ namespace StardewModdingAPI { Log.AsyncY("Validating api paths..."); - _modPaths = new List(); + _modPaths = new List {Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods"), Path.Combine(Constants.ExecutionPath, "Mods")}; //_modContentPaths = new List(); //TODO: Have an app.config and put the paths inside it so users can define locations to load mods from - _modPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods")); - _modPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods")); //Mods need to make their own content paths, since we're doing a different, manifest-driven, approach. //_modContentPaths.Add(Path.Combine(Constants.ExecutionPath, "Mods", "Content")); //_modContentPaths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "Mods", "Content")); //Checks that all defined modpaths exist as directories - _modPaths.ForEach(path => VerifyPath(path)); + _modPaths.ForEach(VerifyPath); //_modContentPaths.ForEach(path => VerifyPath(path)); VerifyPath(Constants.LogDir); if (!File.Exists(Constants.ExecutionPath + "\\Stardew Valley.exe")) { - throw new FileNotFoundException(string.Format("Could not found: {0}\\Stardew Valley.exe", Constants.ExecutionPath)); + throw new FileNotFoundException($"Could not found: {Constants.ExecutionPath}\\Stardew Valley.exe"); } } @@ -440,10 +438,7 @@ namespace StardewModdingAPI Log.AsyncR("The command specified could not be found"); else { - if (fnd.CommandArgs.Length > 0) - Log.AsyncY($"{fnd.CommandName}: {fnd.CommandDesc} - {fnd.CommandArgs.ToSingular()}"); - else - Log.AsyncY($"{fnd.CommandName}: {fnd.CommandDesc}"); + Log.AsyncY(fnd.CommandArgs.Length > 0 ? $"{fnd.CommandName}: {fnd.CommandDesc} - {fnd.CommandArgs.ToSingular()}" : $"{fnd.CommandName}: {fnd.CommandDesc}"); } } else diff --git a/TrainerMod/TrainerMod.cs b/TrainerMod/TrainerMod.cs index 91db4c88..da5365cb 100644 --- a/TrainerMod/TrainerMod.cs +++ b/TrainerMod/TrainerMod.cs @@ -629,8 +629,7 @@ namespace TrainerMod } } - var o = new Object(e.Command.CalledArgs[0].AsInt32(), count); - o.quality = quality; + var o = new Object(e.Command.CalledArgs[0].AsInt32(), count) {quality = quality}; Game1.player.addItemByMenuIfNecessary(o); } -- cgit