diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-04-12 00:18:32 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-04-12 00:18:32 -0400 |
commit | 5997857064f4d6bb0747e84e1dbd1556c97b7481 (patch) | |
tree | 30d26d0f136213b21b1d42a6bb3b6132dfbca644 | |
parent | 9c1617c9ee51a0f6b93242fe8fc789336957460c (diff) | |
download | SMAPI-5997857064f4d6bb0747e84e1dbd1556c97b7481.tar.gz SMAPI-5997857064f4d6bb0747e84e1dbd1556c97b7481.tar.bz2 SMAPI-5997857064f4d6bb0747e84e1dbd1556c97b7481.zip |
fix various net field conversions in SMAPI code (#453)
-rw-r--r-- | src/SMAPI/Context.cs | 2 | ||||
-rw-r--r-- | src/SMAPI/Framework/SGame.cs | 7 | ||||
-rw-r--r-- | src/SMAPI/Metadata/CoreAssetPropagator.cs | 27 | ||||
-rw-r--r-- | src/SMAPI/StardewModdingAPI.csproj | 3 |
4 files changed, 22 insertions, 17 deletions
diff --git a/src/SMAPI/Context.cs b/src/SMAPI/Context.cs index 7ed9b052..79067b2d 100644 --- a/src/SMAPI/Context.cs +++ b/src/SMAPI/Context.cs @@ -35,7 +35,7 @@ namespace StardewModdingAPI ** Internal ****/ /// <summary>Whether a player save has been loaded.</summary> - internal static bool IsSaveLoaded => Game1.hasLoadedGame && !string.IsNullOrEmpty(Game1.player.name); + internal static bool IsSaveLoaded => Game1.hasLoadedGame && !string.IsNullOrEmpty(Game1.player.Name); /// <summary>Whether the game is currently writing to the save file.</summary> internal static bool IsSaving => Game1.activeClickableMenu is SaveGameMenu || Game1.activeClickableMenu is ShippingMenu; // saving is performed by SaveGameMenu, but it's wrapped by ShippingMenu on days when the player shipping something diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index b486f8cd..67390882 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -500,9 +500,9 @@ namespace StardewModdingAPI.Framework this.Events.Player_LeveledUp.Raise(new EventArgsLevelUp(EventArgsLevelUp.LevelType.Luck, Game1.player.luckLevel)); // raise player inventory changed - ItemStackChange[] changedItems = this.GetInventoryChanges(Game1.player.items, this.PreviousItems).ToArray(); + ItemStackChange[] changedItems = this.GetInventoryChanges(Game1.player.Items, this.PreviousItems).ToArray(); if (changedItems.Any()) - this.Events.Player_InventoryChanged.Raise(new EventArgsInventoryChanged(Game1.player.items, changedItems.ToList())); + this.Events.Player_InventoryChanged.Raise(new EventArgsInventoryChanged(Game1.player.Items, changedItems.ToList())); // raise current location's object list changed if (this.GetHash(Game1.currentLocation.objects) != this.PreviousLocationObjects) @@ -526,7 +526,7 @@ namespace StardewModdingAPI.Framework this.PreviousForagingLevel = Game1.player.foragingLevel; this.PreviousMiningLevel = Game1.player.miningLevel; this.PreviousLuckLevel = Game1.player.luckLevel; - this.PreviousItems = Game1.player.items.Where(n => n != null).Distinct().ToDictionary(n => n, n => n.Stack); + this.PreviousItems = Game1.player.Items.Where(n => n != null).Distinct().ToDictionary(n => n, n => n.Stack); this.PreviousLocationObjects = this.GetHash(Game1.currentLocation.objects); this.PreviousTime = Game1.timeOfDay; this.PreviousMineLevel = Game1.mine?.mineLevel ?? 0; @@ -633,6 +633,7 @@ namespace StardewModdingAPI.Framework [SuppressMessage("ReSharper", "RedundantCast", Justification = "copied from game code as-is")] [SuppressMessage("ReSharper", "RedundantExplicitNullableCreation", Justification = "copied from game code as-is")] [SuppressMessage("ReSharper", "RedundantTypeArgumentsOfMethod", Justification = "copied from game code as-is")] + [SuppressMessage("SMAPI.CommonErrors", "SMAPI002", Justification = "copied from game code as-is")] private void DrawImpl(GameTime gameTime) { if (Game1.debugMode) diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 01ea24df..37623f32 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -90,12 +90,12 @@ namespace StardewModdingAPI.Metadata return FarmerRenderer.accessoriesTexture = content.Load<Texture2D>(key); case "characters\\farmer\\farmer_base": // Farmer - if (Game1.player == null || !Game1.player.isMale) + if (Game1.player == null || !Game1.player.IsMale) return false; return Game1.player.FarmerRenderer = new FarmerRenderer(key); case "characters\\farmer\\farmer_girl_base": // Farmer - if (Game1.player == null || Game1.player.isMale) + if (Game1.player == null || Game1.player.IsMale) return false; return Game1.player.FarmerRenderer = new FarmerRenderer(key); @@ -372,16 +372,16 @@ namespace StardewModdingAPI.Metadata foreach (FarmAnimal animal in animals) { // get expected key - string expectedKey = animal.age < animal.ageWhenMature - ? $"Baby{(animal.type == "Duck" ? "White Chicken" : animal.type)}" + string expectedKey = animal.age.Value < animal.ageWhenMature.Value + ? $"Baby{(animal.type.Value == "Duck" ? "White Chicken" : animal.type.Value)}" : animal.type; - if (animal.showDifferentTextureWhenReadyForHarvest && animal.currentProduce <= 0) + if (animal.showDifferentTextureWhenReadyForHarvest && animal.currentProduce.Value <= 0) expectedKey = $"Sheared{expectedKey}"; expectedKey = $"Animals\\{expectedKey}"; // reload asset if (expectedKey == key) - this.SetSpriteTexture(animal.sprite, texture.Value); + this.SetSpriteTexture(animal.Sprite, texture.Value); } return texture.IsValueCreated; } @@ -397,7 +397,7 @@ namespace StardewModdingAPI.Metadata Building[] buildings = Game1.locations .OfType<BuildableGameLocation>() .SelectMany(p => p.buildings) - .Where(p => p.buildingType == type) + .Where(p => p.buildingType.Value == type) .ToArray(); // reload buildings @@ -427,7 +427,7 @@ namespace StardewModdingAPI.Metadata from fence in location.Objects.Values.OfType<Fence>() where fenceType == 1 ? fence.isGate - : fence.whichType == fenceType + : fence.whichType.Value == fenceType select fence ) .ToArray(); @@ -447,7 +447,7 @@ namespace StardewModdingAPI.Metadata { // get NPCs string name = this.GetNpcNameFromFileName(Path.GetFileName(key)); - NPC[] characters = this.GetCharacters().Where(npc => npc.name == name && npc.IsMonster == monster).ToArray(); + NPC[] characters = this.GetCharacters().Where(npc => npc.Name == name && npc.IsMonster == monster).ToArray(); if (!characters.Any()) return false; @@ -466,7 +466,7 @@ namespace StardewModdingAPI.Metadata { // get NPCs string name = this.GetNpcNameFromFileName(Path.GetFileName(key)); - NPC[] villagers = this.GetCharacters().Where(npc => npc.name == name && npc.isVillager()).ToArray(); + NPC[] villagers = this.GetCharacters().Where(npc => npc.Name == name && npc.isVillager()).ToArray(); if (!villagers.Any()) return false; @@ -486,7 +486,7 @@ namespace StardewModdingAPI.Metadata { Tree[] trees = Game1.locations .SelectMany(p => p.terrainFeatures.Values.OfType<Tree>()) - .Where(tree => tree.treeType == type) + .Where(tree => tree.treeType.Value == type) .ToArray(); if (trees.Any()) @@ -562,8 +562,9 @@ namespace StardewModdingAPI.Metadata { foreach (Building building in buildableLocation.buildings) { - if (building.indoors != null) - yield return building.indoors; + GameLocation indoors = building.indoors; + if (indoors != null) + yield return indoors; } } } diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index cf476193..c0d5386a 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -288,6 +288,9 @@ <Name>StardewModdingAPI.AssemblyRewriters</Name> </ProjectReference> </ItemGroup> + <ItemGroup> + <Analyzer Include="..\SMAPI.ModBuildConfig.Analyzer\bin\netstandard1.3\StardewModdingAPI.ModBuildConfig.Analyzer.dll" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\build\common.targets" /> </Project>
\ No newline at end of file |