Skip to content

Commit

Permalink
Merge branch 'develop' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Apr 12, 2018
2 parents 46141a7 + 2d47e47 commit b9bc1a6
Show file tree
Hide file tree
Showing 49 changed files with 1,802 additions and 172 deletions.
4 changes: 2 additions & 2 deletions build/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Reflection;

[assembly: AssemblyProduct("SMAPI")]
[assembly: AssemblyVersion("2.5.4")]
[assembly: AssemblyFileVersion("2.5.4")]
[assembly: AssemblyVersion("2.5.5")]
[assembly: AssemblyFileVersion("2.5.5")]
20 changes: 20 additions & 0 deletions build/prepare-nuget-package.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
This build task is run from the ModBuildConfig project after it's been compiled, and copies the
package files to the bin\Pathoschild.Stardew.ModBuildConfig folder.
-->
<Target Name="AfterBuild">
<PropertyGroup>
<PackagePath>$(SolutionDir)\..\bin\Pathoschild.Stardew.ModBuildConfig</PackagePath>
</PropertyGroup>
<RemoveDir Directories="$(PackagePath)" />
<Copy SourceFiles="$(ProjectDir)/package.nuspec" DestinationFolder="$(PackagePath)" />
<Copy SourceFiles="$(ProjectDir)/build/smapi.targets" DestinationFiles="$(PackagePath)/build/Pathoschild.Stardew.ModBuildConfig.targets" />
<Copy SourceFiles="$(TargetDir)/StardewModdingAPI.ModBuildConfig.dll" DestinationFiles="$(PackagePath)/build/StardewModdingAPI.ModBuildConfig.dll" />
<Copy SourceFiles="$(SolutionDir)/SMAPI.ModBuildConfig.Analyzer/bin/netstandard1.3/StardewModdingAPI.ModBuildConfig.Analyzer.dll" DestinationFiles="$(PackagePath)/analyzers/dotnet/cs/StardewModdingAPI.ModBuildConfig.Analyzer.dll" />
<Copy SourceFiles="$(SolutionDir)/SMAPI.ModBuildConfig.Analyzer/tools/install.ps1" DestinationFiles="$(PackagePath)/tools/install.ps1" />
<Copy SourceFiles="$(SolutionDir)/SMAPI.ModBuildConfig.Analyzer/tools/uninstall.ps1" DestinationFiles="$(PackagePath)/tools/uninstall.ps1" />
</Target>
</Project>
81 changes: 74 additions & 7 deletions docs/mod-build-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ for SMAPI mods.

The package...

* lets your code compile on any computer (Linux/Mac/Windows) without needing to change the assembly
references or game path.
* packages the mod into the game's `Mods` folder when you rebuild the code (configurable).
* configures Visual Studio so you can debug into the mod code when the game is running (_Windows
only_).
* detects your game install path;
* adds the assembly references you need (with automatic support for Linux/Mac/Windows);
* packages the mod into your `Mods` folder when you rebuild the code (configurable);
* configures Visual Studio to enable debugging into the code when the game is running (_Windows only_);
* adds C# analyzers to warn for Stardew Valley-specific issues.

## Contents
* [Install](#install)
* [Configure](#configure)
* [Code analysis warnings](#code-analysis-warnings)
* [Troubleshoot](#troubleshoot)
* [Release notes](#release-notes)

Expand Down Expand Up @@ -121,7 +122,7 @@ The configuration will check your custom path first, then fall back to the defau
still compile on a different computer).

### Unit test projects
**(upcoming in 2.0.3)**
**(upcoming in 2.1)**

You can use the package in unit test projects too. Its optional unit test mode...

Expand All @@ -134,15 +135,81 @@ To enable it, add this above the first `</PropertyGroup>` in your `.csproj`:
<ModUnitTests>True</ModUnitTests>
```

## Code warnings
### Overview
The NuGet package adds code warnings in Visual Studio specific to Stardew Valley. For example:
![](screenshots/code-analyzer-example.png)

You can hide the warnings...
* [for specific code](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-pragma-warning);
* for a method using this attribute:
```cs
[System.Diagnostics.CodeAnalysis.SuppressMessage("SMAPI.CommonErrors", "SMAPI001")] // implicit net field conversion
```
* for an entire project:
1. Expand the _References_ node for the project in Visual Studio.
2. Right-click on _Analyzers_ and choose _Open Active Rule Set_.
4. Expand _StardewModdingAPI.ModBuildConfig.Analyzer_ and uncheck the warnings you want to hide.

See below for help with each specific warning.

### SMAPI001
**Implicit net field conversion:**
> This implicitly converts '{{expression}}' from {{net type}} to {{other type}}, but
> {{net type}} has unintuitive implicit conversion rules. Consider comparing against the actual
> value instead to avoid bugs.

Stardew Valley uses net types (like `NetBool` and `NetInt`) to handle multiplayer sync. These types
can implicitly convert to their equivalent normal values (like `bool x = new NetBool()`), but their
conversion rules are unintuitive and error-prone. For example,
`item?.category == null && item?.category != null` can both be true at once, and
`building.indoors != null` will be true for a null value in some cases.

Suggested fix:
* Some net fields have an equivalent non-net property like `monster.Health` (`int`) instead of
`monster.health` (`NetInt`). The package will add a separate [SMAPI002](#smapi002) warning for
these. Use the suggested property instead.
* For a reference type (i.e. one that can contain `null`), you can use the `.Value` property:
```c#
if (building.indoors.Value == null)
```
Or convert the value before comparison:
```c#
GameLocation indoors = building.indoors;
if(indoors == null)
// ...
```
* For a value type (i.e. one that can't contain `null`), check if the object is null (if applicable)
and compare with `.Value`:
```cs
if (item != null && item.category.Value == 0)
```

### SMAPI002
**Avoid net fields when possible:**
> '{{expression}}' is a {{net type}} field; consider using the {{property name}} property instead.

Your code accesses a net field, which has some unusual behavior (see [SMAPI001](#smapi001)). This
field has an equivalent non-net property that avoids those issues.

Suggested fix: access the suggested property name instead.

### SMAPI003
**Avoid obsolete fields:**
> The '{{old field}}' field is obsolete and should be replaced with '{{new field}}'.

Your code accesses a field which is obsolete or no longer works. Use the suggested field instead.

## Troubleshoot
### "Failed to find the game install path"
That error means the package couldn't find your game. You can specify the game path yourself; see
_[Game path](#game-path)_ above.

## Release notes
### 2.0.3 alpha
### 2.1 alpha
* Added support for Stardew Valley 1.3.
* Added support for unit test projects.
* Added C# analyzers to warn about implicit conversions of Netcode fields in Stardew Valley 1.3.

### 2.0.2
* Fixed compatibility issue on Linux.
Expand Down
18 changes: 16 additions & 2 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@
## 2.6 alpha
* For players:
* Added support for Stardew Valley 1.3+; no longer compatible with earlier versions.
* Fixed SMAPI update alerts linking to the GitHub repository instead of [smapi.io](https://smapi.io).
* Added `Context.IsMultiplayer` and `Context.IsMainPlayer` flags.
* Fixed SMAPI update checks not showing newer beta versions when using a beta version.
* For modders:
* Added code analysis to mod build config package to flag common issues as warnings.
* Dropped some deprecated APIs.
* Fixed some assets not being editable.
* Fixed assets loaded by temporary content managers not being editable.
* Fixed issue where assets didn't reload correctly when the player switches language.
* For SMAPI developers:
* Added prerelease versions to the mod update-check API response where available (GitHub only).
* Added support for beta releases on the home page.
-->

## 2.5.5
* For players:
* Fixed mod not loaded if it has an optional dependency that's loaded but skipped.
* Fixed mod update alerts not shown if one mod has an invalid remote version.
* Fixed SMAPI update alerts linking to the GitHub repository instead of [smapi.io](https://smapi.io).
* Fixed SMAPI update alerts for draft releases.
* Fixed error when two content packs use different capitalisation for the same required mod ID.
* Fixed rare crash if the game duplicates an item.

* For the [log parser][]:
* Tweaked UI.

## 2.5.4
* For players:
* Fixed some textures not updated when a mod changes them.
Expand Down
Binary file added docs/screenshots/code-analyzer-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions docs/technical-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mods, this section isn't relevant to you; see the main README to use or create m
* [Development](#development-2)
* [Local development](#local-development)
* [Deploying to Amazon Beanstalk](#deploying-to-amazon-beanstalk)
* [Mod build config package](#mod-build-config-package)

# SMAPI
## Development
Expand Down Expand Up @@ -222,3 +223,31 @@ property name | description
`LogParser:SectionUrl` | The root URL of the log page, like `https://log.smapi.io/`.
`ModUpdateCheck:GitHubPassword` | The password with which to authenticate to GitHub when fetching release info.
`ModUpdateCheck:GitHubUsername` | The username with which to authenticate to GitHub when fetching release info.

## Mod build config package
### Overview
The mod build config package is a NuGet package that mods reference to automatically set up
references, configure the build, and add analyzers specific to Stardew Valley mods.

This involves three projects:

project | purpose
------------------------------------------------- | ----------------
`StardewModdingAPI.ModBuildConfig` | Configures the build (references, deploying the mod files, setting up debugging, etc).
`StardewModdingAPI.ModBuildConfig.Analyzer` | Adds C# analyzers which show code warnings in Visual Studio.
`StardewModdingAPI.ModBuildConfig.Analyzer.Tests` | Unit tests for the C# analyzers.

When the projects are built, the relevant files are copied into `bin/Pathoschild.Stardew.ModBuildConfig`.

### Preparing a build
To prepare a build of the NuGet package:
1. Install the [NuGet CLI](https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools#nugetexe-cli).
1. Change the version and release notes in `package.nuspec`.
2. Rebuild the solution in _Release_ mode.
3. Open a terminal in the `bin/Pathoschild.Stardew.ModBuildConfig` package and run this command:
```bash
nuget.exe pack
```

That will create a `Pathoschild.Stardew.ModBuildConfig-<version>.nupkg` file in the same directory
which can be uploaded to NuGet or referenced directly.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// <generated />
using Microsoft.CodeAnalysis;
using System;

namespace SMAPI.ModBuildConfig.Analyzer.Tests.Framework
{
/// <summary>
/// Location where the diagnostic appears, as determined by path, line number, and column number.
/// </summary>
public struct DiagnosticResultLocation
{
public DiagnosticResultLocation(string path, int line, int column)
{
if (line < -1)
{
throw new ArgumentOutOfRangeException(nameof(line), "line must be >= -1");
}

if (column < -1)
{
throw new ArgumentOutOfRangeException(nameof(column), "column must be >= -1");
}

this.Path = path;
this.Line = line;
this.Column = column;
}

public string Path { get; }
public int Line { get; }
public int Column { get; }
}

/// <summary>
/// Struct that stores information about a Diagnostic appearing in a source
/// </summary>
public struct DiagnosticResult
{
private DiagnosticResultLocation[] locations;

public DiagnosticResultLocation[] Locations
{
get
{
if (this.locations == null)
{
this.locations = new DiagnosticResultLocation[] { };
}
return this.locations;
}

set
{
this.locations = value;
}
}

public DiagnosticSeverity Severity { get; set; }

public string Id { get; set; }

public string Message { get; set; }

public string Path
{
get
{
return this.Locations.Length > 0 ? this.Locations[0].Path : "";
}
}

public int Line
{
get
{
return this.Locations.Length > 0 ? this.Locations[0].Line : -1;
}
}

public int Column
{
get
{
return this.Locations.Length > 0 ? this.Locations[0].Column : -1;
}
}
}
}
Loading

0 comments on commit b9bc1a6

Please sign in to comment.