Merge branch 'develop' into stable

This commit is contained in:
Jesse Plamondon-Willard 2018-12-07 13:40:44 -05:00
commit a78b193592
No known key found for this signature in database
GPG Key ID: 7D7C8097B62033CE
118 changed files with 1495 additions and 333 deletions

View File

@ -1,5 +1,5 @@
using System.Reflection;
[assembly: AssemblyProduct("SMAPI")]
[assembly: AssemblyVersion("2.8.2")]
[assembly: AssemblyFileVersion("2.8.2")]
[assembly: AssemblyVersion("2.9.0")]
[assembly: AssemblyFileVersion("2.9.0")]

View File

@ -97,9 +97,9 @@
<Error Condition="!Exists('$(GamePath)')" Text="Failed to find the game install path automatically; edit the *.csproj file and manually add a &lt;GamePath&gt; setting with the full directory path containing the Stardew Valley executable." />
</Target>
<!-- copy files into game directory and enable debugging (only in debug mode) -->
<!-- copy files into game directory and enable debugging -->
<Target Name="AfterBuild">
<CallTarget Targets="CopySMAPI;CopyDefaultMods" Condition="'$(Configuration)' == 'Debug'" />
<CallTarget Targets="CopySMAPI;CopyDefaultMods" />
</Target>
<Target Name="CopySMAPI" Condition="'$(MSBuildProjectName)' == 'StardewModdingAPI'">
<Copy SourceFiles="$(TargetDir)\$(TargetName).exe" DestinationFolder="$(GamePath)" />
@ -116,19 +116,19 @@
<Copy SourceFiles="$(TargetDir)\$(TargetName).pdb" DestinationFolder="$(GamePath)\Mods\$(AssemblyName)" Condition="Exists('$(TargetDir)\$(TargetName).pdb')" />
<Copy SourceFiles="$(TargetDir)\manifest.json" DestinationFolder="$(GamePath)\Mods\$(AssemblyName)" />
</Target>
<Target Name="CopyToolkit" Condition="'$(MSBuildProjectName)' == 'StardewModdingAPI.Toolkit' AND '$(Configuration)' == 'Debug' AND $(TargetFramework) == 'net4.5'" AfterTargets="PostBuildEvent">
<Target Name="CopyToolkit" Condition="'$(MSBuildProjectName)' == 'StardewModdingAPI.Toolkit' AND $(TargetFramework) == 'net4.5'" AfterTargets="PostBuildEvent">
<Copy SourceFiles="$(TargetDir)\$(TargetName).dll" DestinationFolder="$(GamePath)\smapi-internal" />
<Copy SourceFiles="$(TargetDir)\$(TargetName).pdb" DestinationFolder="$(GamePath)\smapi-internal" />
<Copy SourceFiles="$(TargetDir)\$(TargetName).xml" DestinationFolder="$(GamePath)\smapi-internal" />
</Target>
<Target Name="CopyToolkitCoreInterfaces" Condition="'$(MSBuildProjectName)' == 'StardewModdingAPI.Toolkit.CoreInterfaces' AND '$(Configuration)' == 'Debug' AND $(TargetFramework) == 'net4.5'" AfterTargets="PostBuildEvent">
<Target Name="CopyToolkitCoreInterfaces" Condition="'$(MSBuildProjectName)' == 'StardewModdingAPI.Toolkit.CoreInterfaces' AND $(TargetFramework) == 'net4.5'" AfterTargets="PostBuildEvent">
<Copy SourceFiles="$(TargetDir)\$(TargetName).dll" DestinationFolder="$(GamePath)\smapi-internal" />
<Copy SourceFiles="$(TargetDir)\$(TargetName).pdb" DestinationFolder="$(GamePath)\smapi-internal" />
<Copy SourceFiles="$(TargetDir)\$(TargetName).xml" DestinationFolder="$(GamePath)\smapi-internal" />
</Target>
<!-- launch SMAPI on debug -->
<PropertyGroup Condition="$(Configuration) == 'Debug'">
<!-- launch SMAPI through Visual Studio -->
<PropertyGroup>
<StartAction>Program</StartAction>
<StartProgram>$(GamePath)\StardewModdingAPI.exe</StartProgram>
<StartWorkingDirectory>$(GamePath)</StartWorkingDirectory>

View File

@ -1,9 +1,36 @@
# Release notes
## 2.9
* For players:
* Added support for ModDrop in update checks and the mod compatibility list.
* Added friendly error for Steam players when Steam isn't loaded.
* Fixed cryptic error when running the installer from inside a zip file on Windows.
* Fixed error when leaving and rejoining a multiplayer server in the same session.
* Fixed empty "mods with warnings" list in some cases due to hidden warnings.
* Fixed Console Commands' handling of tool upgrade levels for item commands.
* For modders:
* Added ModDrop update keys (see [docs](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Manifest#Update_checks)).
* Added `IsLocalPlayer` to new player events.
* Added `helper.CreateTemporaryContentPack` to replace the deprecated `CreateTransitionalContentPack`.
* Reloading a map asset will now update affected locations.
* Reloading the `Data\NPCDispositions` asset will now update affected NPCs.
* Disabled trace messages related to paranoid mode when it's disabled.
* Fixed world events like `ObjectListChanged` not working in the mines.
* Fixed some map tilesheets not editable if not playing in English.
* Fixed newlines in manifest fields not being ignored.
* Fixed `Display.RenderedWorld` event invoked after overlays are rendered.
* **Deprecations:**
* All static events are deprecated and will be removed in SMAPI 3.0. Mods should use the new event system available through `helper.Events` instead; see [_migrate to SMAPI 3.0_](https://stardewvalleywiki.com/Modding:Migrate_to_SMAPI_3.0) for details.
* For the web UI:
* Added stats to compatibility list.
* Fixed compatibility list showing beta header when there's no beta in progress.
## 2.8.2
* Fixed game crash in MacOS since SMAPI 2.8.
* Fixed game crash in MacOS with SMAPI 2.8.
## 2.8.1
* Fixed installer error on Windows.
* Fixed installer error on Windows with SMAPI 2.8.
## 2.8
* For players:

View File

@ -105,8 +105,8 @@ SMAPI uses a small number of conditional compilation constants, which you can se
flag | purpose
---- | -------
`SMAPI_FOR_WINDOWS` | Indicates that SMAPI is being compiled on Windows for players on Windows. Set automatically in `crossplatform.targets`.
`SMAPI_FOR_WINDOWS` | Whether SMAPI is being compiled on Windows for players on Windows. Set automatically in `crossplatform.targets`.
`SMAPI_3_0_STRICT` | Whether to exclude all deprecated APIs from compilation. This is useful for testing mods for SMAPI 3.0 compatibility.
# SMAPI web services
## Overview

View File

@ -1 +1,8 @@
START /WAIT /B internal/windows-install.exe
@echo off
echo %~dp0 | findstr /C:"%TEMP%" 1>nul
if not errorlevel 1 (
echo Oops! It looks like you're running the installer from inside a zip file. Make sure you unzip the download first.
pause
) else (
start /WAIT /B internal/windows-install.exe
)

View File

@ -47,7 +47,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World
{
// define conversion between game time and TimeSpan
TimeSpan ToTimeSpan(int value) => new TimeSpan(0, value / 100, value % 100, 0);
int FromTimeSpan(TimeSpan span) => (int)((span.Hours * 100) + span.Minutes);
int FromTimeSpan(TimeSpan span) => (span.Hours * 100) + span.Minutes;
// transition to new time
int intervals = (int)((ToTimeSpan(time) - ToTimeSpan(Game1.timeOfDay)).TotalMinutes / 10);

View File

@ -25,15 +25,11 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework
public IEnumerable<SearchableItem> GetAll()
{
// get tools
for (int quality = Tool.stone; quality <= Tool.iridium; quality++)
{
yield return new SearchableItem(ItemType.Tool, ToolFactory.axe, ToolFactory.getToolFromDescription(ToolFactory.axe, quality));
yield return new SearchableItem(ItemType.Tool, ToolFactory.hoe, ToolFactory.getToolFromDescription(ToolFactory.hoe, quality));
yield return new SearchableItem(ItemType.Tool, ToolFactory.pickAxe, ToolFactory.getToolFromDescription(ToolFactory.pickAxe, quality));
yield return new SearchableItem(ItemType.Tool, ToolFactory.wateringCan, ToolFactory.getToolFromDescription(ToolFactory.wateringCan, quality));
if (quality != Tool.iridium)
yield return new SearchableItem(ItemType.Tool, ToolFactory.fishingRod, ToolFactory.getToolFromDescription(ToolFactory.fishingRod, quality));
}
yield return new SearchableItem(ItemType.Tool, ToolFactory.axe, ToolFactory.getToolFromDescription(ToolFactory.axe, 0));
yield return new SearchableItem(ItemType.Tool, ToolFactory.hoe, ToolFactory.getToolFromDescription(ToolFactory.hoe, 0));
yield return new SearchableItem(ItemType.Tool, ToolFactory.pickAxe, ToolFactory.getToolFromDescription(ToolFactory.pickAxe, 0));
yield return new SearchableItem(ItemType.Tool, ToolFactory.wateringCan, ToolFactory.getToolFromDescription(ToolFactory.wateringCan, 0));
yield return new SearchableItem(ItemType.Tool, ToolFactory.fishingRod, ToolFactory.getToolFromDescription(ToolFactory.fishingRod, 0));
yield return new SearchableItem(ItemType.Tool, this.CustomIDOffset, new MilkPail()); // these don't have any sort of ID, so we'll just assign some arbitrary ones
yield return new SearchableItem(ItemType.Tool, this.CustomIDOffset + 1, new Shears());
yield return new SearchableItem(ItemType.Tool, this.CustomIDOffset + 2, new Pan());

View File

@ -29,7 +29,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands
helper.ConsoleCommands.Add(command.Name, command.Description, (name, args) => this.HandleCommand(command, name, args));
// hook events
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked;
}
@ -39,7 +39,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands
/// <summary>The method invoked when the game updates its state.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void GameEvents_UpdateTick(object sender, EventArgs e)
private void OnUpdateTicked(object sender, EventArgs e)
{
if (!Context.IsWorldReady)
return;

View File

@ -15,7 +15,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<Optimize>false</Optimize>
<OutputPath>$(SolutionDir)\..\bin\Debug\Mods\ConsoleCommands\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>

View File

@ -1,9 +1,9 @@
{
"Name": "Console Commands",
"Author": "SMAPI",
"Version": "2.8.0",
"Version": "2.9.0",
"Description": "Adds SMAPI console commands that let you manipulate the game.",
"UniqueID": "SMAPI.ConsoleCommands",
"EntryDll": "ConsoleCommands.dll",
"MinimumApiVersion": "2.8.2"
"MinimumApiVersion": "2.9.0"
}

View File

@ -1,9 +1,9 @@
{
"Name": "Save Backup",
"Author": "SMAPI",
"Version": "2.8.0",
"Version": "2.9.0",
"Description": "Automatically backs up all your saves once per day into its folder.",
"UniqueID": "SMAPI.SaveBackup",
"EntryDll": "SaveBackup.dll",
"MinimumApiVersion": "2.8.2"
"MinimumApiVersion": "2.9.0"
}

View File

@ -47,7 +47,7 @@ namespace StardewModdingAPI.Tests.Utilities
Assert.AreEqual(major, version.MajorVersion, "The major version doesn't match the given value.");
Assert.AreEqual(minor, version.MinorVersion, "The minor version doesn't match the given value.");
Assert.AreEqual(patch, version.PatchVersion, "The patch version doesn't match the given value.");
Assert.AreEqual(string.IsNullOrWhiteSpace(tag) ? null : tag.Trim(), version.Build, "The tag doesn't match the given value.");
Assert.AreEqual(string.IsNullOrWhiteSpace(tag) ? null : tag.Trim(), version.PrereleaseTag, "The tag doesn't match the given value.");
return version.ToString();
}

View File

@ -15,6 +15,7 @@ using StardewModdingAPI.Toolkit.Framework.ModData;
using StardewModdingAPI.Toolkit.Framework.UpdateData;
using StardewModdingAPI.Web.Framework.Clients.Chucklefish;
using StardewModdingAPI.Web.Framework.Clients.GitHub;
using StardewModdingAPI.Web.Framework.Clients.ModDrop;
using StardewModdingAPI.Web.Framework.Clients.Nexus;
using StardewModdingAPI.Web.Framework.ConfigModels;
using StardewModdingAPI.Web.Framework.ModRepositories;
@ -60,8 +61,9 @@ namespace StardewModdingAPI.Web.Controllers
/// <param name="configProvider">The config settings for mod update checks.</param>
/// <param name="chucklefish">The Chucklefish API client.</param>
/// <param name="github">The GitHub API client.</param>
/// <param name="modDrop">The ModDrop API client.</param>
/// <param name="nexus">The Nexus API client.</param>
public ModsApiController(IHostingEnvironment environment, IMemoryCache cache, IOptions<ModUpdateCheckConfig> configProvider, IChucklefishClient chucklefish, IGitHubClient github, INexusClient nexus)
public ModsApiController(IHostingEnvironment environment, IMemoryCache cache, IOptions<ModUpdateCheckConfig> configProvider, IChucklefishClient chucklefish, IGitHubClient github, IModDropClient modDrop, INexusClient nexus)
{
this.ModDatabase = new ModToolkit().GetModDatabase(Path.Combine(environment.WebRootPath, "StardewModdingAPI.metadata.json"));
ModUpdateCheckConfig config = configProvider.Value;
@ -76,6 +78,7 @@ namespace StardewModdingAPI.Web.Controllers
{
new ChucklefishRepository(chucklefish),
new GitHubRepository(github),
new ModDropRepository(modDrop),
new NexusRepository(nexus)
}
.ToDictionary(p => p.VendorKey);
@ -291,6 +294,8 @@ namespace StardewModdingAPI.Web.Controllers
yield return $"Nexus:{entry.NexusID}";
if (entry.ChucklefishID.HasValue)
yield return $"Chucklefish:{entry.ChucklefishID}";
if (entry.ModDropID.HasValue)
yield return $"ModDrop:{entry.ModDropID}";
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Threading.Tasks;
namespace StardewModdingAPI.Web.Framework.Clients.ModDrop
{
/// <summary>An HTTP client for fetching mod metadata from the ModDrop API.</summary>
internal interface IModDropClient : IDisposable
{
/*********
** Methods
*********/
/// <summary>Get metadata about a mod.</summary>
/// <param name="id">The ModDrop mod ID.</param>
/// <returns>Returns the mod info if found, else <c>null</c>.</returns>
Task<ModDropMod> GetModAsync(long id);
}
}

View File

@ -0,0 +1,96 @@
using System.Threading.Tasks;
using Pathoschild.Http.Client;
using StardewModdingAPI.Toolkit;
using StardewModdingAPI.Web.Framework.Clients.ModDrop.ResponseModels;
namespace StardewModdingAPI.Web.Framework.Clients.ModDrop
{
/// <summary>An HTTP client for fetching mod metadata from the ModDrop API.</summary>
internal class ModDropClient : IModDropClient
{
/*********
** Properties
*********/
/// <summary>The underlying HTTP client.</summary>
private readonly IClient Client;
/// <summary>The URL for a ModDrop mod page for the user, where {0} is the mod ID.</summary>
private readonly string ModUrlFormat;
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="userAgent">The user agent for the API client.</param>
/// <param name="apiUrl">The base URL for the ModDrop API.</param>
/// <param name="modUrlFormat">The URL for a ModDrop mod page for the user, where {0} is the mod ID.</param>
public ModDropClient(string userAgent, string apiUrl, string modUrlFormat)
{
this.Client = new FluentClient(apiUrl).SetUserAgent(userAgent);
this.ModUrlFormat = modUrlFormat;
}
/// <summary>Get metadata about a mod.</summary>
/// <param name="id">The ModDrop mod ID.</param>
/// <returns>Returns the mod info if found, else <c>null</c>.</returns>
public async Task<ModDropMod> GetModAsync(long id)
{
// get raw data
ModListModel response = await this.Client
.PostAsync("")
.WithBody(new
{
ModIDs = new[] { id },
Files = true,
Mods = true
})
.As<ModListModel>();
ModModel mod = response.Mods[id];
if (mod.Mod?.Title == null || mod.Mod.ErrorCode.HasValue)
return null;
// get latest versions
ISemanticVersion latest = null;
ISemanticVersion optional = null;
foreach (FileDataModel file in mod.Files)
{
if (file.IsOld || file.IsDeleted || file.IsHidden)
continue;
if (!SemanticVersion.TryParse(file.Version, out ISemanticVersion version))
continue;
if (file.IsDefault)
{
if (latest == null || version.IsNewerThan(latest))
latest = version;
}
else if (optional == null || version.IsNewerThan(optional))
optional = version;
}
if (latest == null)
{
latest = optional;
optional = null;
}
if (optional != null && latest.IsNewerThan(optional))
optional = null;
// generate result
return new ModDropMod
{
Name = mod.Mod?.Title,
LatestDefaultVersion = latest,
LatestOptionalVersion = optional,
Url = string.Format(this.ModUrlFormat, id)
};
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
public void Dispose()
{
this.Client?.Dispose();
}
}
}

View File

@ -0,0 +1,24 @@
namespace StardewModdingAPI.Web.Framework.Clients.ModDrop
{
/// <summary>Mod metadata from the ModDrop API.</summary>
internal class ModDropMod
{
/*********
** Accessors
*********/
/// <summary>The mod name.</summary>
public string Name { get; set; }
/// <summary>The latest default file version.</summary>
public ISemanticVersion LatestDefaultVersion { get; set; }
/// <summary>The latest optional file version.</summary>
public ISemanticVersion LatestOptionalVersion { get; set; }
/// <summary>The mod's web URL.</summary>
public string Url { get; set; }
/// <summary>A user-friendly error which indicates why fetching the mod info failed (if applicable).</summary>
public string Error { get; set; }
}
}

View File

@ -0,0 +1,21 @@
namespace StardewModdingAPI.Web.Framework.Clients.ModDrop.ResponseModels
{
/// <summary>Metadata from the ModDrop API about a mod file.</summary>
public class FileDataModel
{
/// <summary>Whether the file is deleted.</summary>
public bool IsDeleted { get; set; }
/// <summary>Whether the file is hidden from users.</summary>
public bool IsHidden { get; set; }
/// <summary>Whether this is the default file for the mod.</summary>
public bool IsDefault { get; set; }
/// <summary>Whether this is an archived file.</summary>
public bool IsOld { get; set; }
/// <summary>The file version.</summary>
public string Version { get; set; }
}
}

View File

@ -0,0 +1,15 @@
namespace StardewModdingAPI.Web.Framework.Clients.ModDrop.ResponseModels
{
/// <summary>Metadata about a mod from the ModDrop API.</summary>
public class ModDataModel
{
/// <summary>The mod's unique ID on ModDrop.</summary>
public int ID { get; set; }
/// <summary>The error code, if any.</summary>
public int? ErrorCode { get; set; }
/// <summary>The mod name.</summary>
public string Title { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace StardewModdingAPI.Web.Framework.Clients.ModDrop.ResponseModels
{
/// <summary>A list of mods from the ModDrop API.</summary>
public class ModListModel
{
/// <summary>The mod data.</summary>
public IDictionary<long, ModModel> Mods { get; set; }
}
}

View File

@ -0,0 +1,12 @@
namespace StardewModdingAPI.Web.Framework.Clients.ModDrop.ResponseModels
{
/// <summary>An entry in a mod list from the ModDrop API.</summary>
public class ModModel
{
/// <summary>The available file downloads.</summary>
public FileDataModel[] Files { get; set; }
/// <summary>The mod metadata.</summary>
public ModDataModel Mod { get; set; }
}
}

View File

@ -44,6 +44,15 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels
/// <summary>The password with which to authenticate to the GitHub API (if any).</summary>
public string GitHubPassword { get; set; }
/****
** ModDrop
****/
/// <summary>The base URL for the ModDrop API.</summary>
public string ModDropApiUrl { get; set; }
/// <summary>The URL for a ModDrop mod page for the user, where {0} is the mod ID.</summary>
public string ModDropModPageUrl { get; set; }
/****
** Nexus Mods
****/

View File

@ -0,0 +1,59 @@
using System;
using System.Threading.Tasks;
using StardewModdingAPI.Toolkit.Framework.UpdateData;
using StardewModdingAPI.Web.Framework.Clients.ModDrop;
namespace StardewModdingAPI.Web.Framework.ModRepositories
{
/// <summary>An HTTP client for fetching mod metadata from the ModDrop API.</summary>
internal class ModDropRepository : RepositoryBase
{
/*********
** Properties
*********/
/// <summary>The underlying ModDrop API client.</summary>
private readonly IModDropClient Client;
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="client">The underlying Nexus Mods API client.</param>
public ModDropRepository(IModDropClient client)
: base(ModRepositoryKey.ModDrop)
{
this.Client = client;
}
/// <summary>Get metadata about a mod in the repository.</summary>
/// <param name="id">The mod ID in this repository.</param>
public override async Task<ModInfoModel> GetModInfoAsync(string id)
{
// validate ID format
if (!long.TryParse(id, out long modDropID))
return new ModInfoModel($"The value '{id}' isn't a valid ModDrop mod ID, must be an integer ID.");
// fetch info
try
{
ModDropMod mod = await this.Client.GetModAsync(modDropID);
if (mod == null)
return new ModInfoModel("Found no mod with this ID.");
if (mod.Error != null)
return new ModInfoModel(mod.Error);
return new ModInfoModel(name: mod.Name, version: mod.LatestDefaultVersion?.ToString(), previewVersion: mod.LatestOptionalVersion?.ToString(), url: mod.Url);
}
catch (Exception ex)
{
return new ModInfoModel(ex.ToString());
}
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
public override void Dispose()
{
this.Client.Dispose();
}
}
}

View File

@ -11,6 +11,7 @@ using StardewModdingAPI.Toolkit.Serialisation;
using StardewModdingAPI.Web.Framework;
using StardewModdingAPI.Web.Framework.Clients.Chucklefish;
using StardewModdingAPI.Web.Framework.Clients.GitHub;
using StardewModdingAPI.Web.Framework.Clients.ModDrop;
using StardewModdingAPI.Web.Framework.Clients.Nexus;
using StardewModdingAPI.Web.Framework.Clients.Pastebin;
using StardewModdingAPI.Web.Framework.ConfigModels;
@ -86,6 +87,12 @@ namespace StardewModdingAPI.Web
password: api.GitHubPassword
));
services.AddSingleton<IModDropClient>(new ModDropClient(
userAgent: userAgent,
apiUrl: api.ModDropApiUrl,
modUrlFormat: api.ModDropModPageUrl
));
services.AddSingleton<INexusClient>(new NexusWebScrapeClient(
userAgent: userAgent,
baseUrl: api.NexusBaseUrl,
@ -155,6 +162,7 @@ namespace StardewModdingAPI.Web
// shortcut redirects
redirects.Add(new RedirectToUrlRule(@"^/buildmsg(?:/?(.*))$", "https://github.com/Pathoschild/SMAPI/blob/develop/docs/mod-build-config.md#$1"));
redirects.Add(new RedirectToUrlRule(@"^/compat\.?$", "https://mods.smapi.io"));
redirects.Add(new RedirectToUrlRule(@"^/3\.0\.?$", "https://stardewvalleywiki.com/Modding:Migrate_to_SMAPI_3.0"));
redirects.Add(new RedirectToUrlRule(@"^/docs\.?$", "https://stardewvalleywiki.com/Modding:Index"));
redirects.Add(new RedirectToUrlRule(@"^/install\.?$", "https://stardewvalleywiki.com/Modding:Player_Guide/Getting_Started#Install_SMAPI"));

View File

@ -96,6 +96,11 @@ namespace StardewModdingAPI.Web.ViewModels
anyFound = true;
yield return new ModLinkModel($"https://community.playstarbound.com/resources/{entry.ChucklefishID}", "Chucklefish");
}
if (entry.ModDropID.HasValue)
{
anyFound = true;
yield return new ModLinkModel($"https://www.moddrop.com/sdv/mod/467243/{entry.ModDropID}", "ModDrop");
}
// fallback
if (!anyFound && !string.IsNullOrWhiteSpace(entry.CustomUrl))

View File

@ -108,6 +108,7 @@ else
<a href="https://www.nexusmods.com/users/12252523">Karmylla</a>,
Pucklynn,
Robby LaFarge,
Tarryn K.,
and a few anonymous users for their ongoing support; you're awesome! 🏅
</p>

View File

@ -4,11 +4,11 @@
ViewData["Title"] = "SMAPI mod compatibility";
}
@section Head {
<link rel="stylesheet" href="~/Content/css/mods.css?r=20181109" />
<link rel="stylesheet" href="~/Content/css/mods.css?r=20181122" />
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/tablesorter@2.31.0/dist/js/jquery.tablesorter.combined.min.js" crossorigin="anonymous"></script>
<script src="~/Content/js/mods.js?r=20181109"></script>
<script src="~/Content/js/mods.js?r=20181122"></script>
<script>
$(function() {
var data = @Json.Serialize(Model.Mods, new JsonSerializerSettings { Formatting = Formatting.None });
@ -36,7 +36,7 @@
</div>
<div id="filter-area">
<input type="checkbox" id="show-advanced" v-model="showAdvanced" />
<label for="show-advanced">show detailed options</label>
<label for="show-advanced">show advanced info and options</label>
<div id="filters" v-show="showAdvanced">
<div v-for="(filterGroup, key) in filters">
{{key}}: <span v-for="filter in filterGroup" v-bind:class="{ active: filter.value }"><input type="checkbox" v-bind:id="filter.id" v-model="filter.value" v-on:change="applyFilters" /> <label v-bind:for="filter.id">{{filter.label}}</label></span>
@ -44,7 +44,10 @@
</div>
</div>
</div>
<div id="mod-count" v-show="showAdvanced">{{visibleCount}} mods shown.</div>
<div id="mod-count" v-show="showAdvanced">
<span v-if="visibleStats.total > 0">{{visibleStats.total}} mods shown ({{Math.round((visibleStats.compatible + visibleStats.workaround) / visibleStats.total * 100)}}% compatible or have a workaround, {{Math.round((visibleStats.soon + visibleStats.broken) / visibleStats.total * 100)}}% broken, {{Math.round(visibleStats.abandoned / visibleStats.total * 100)}}% obsolete).</span>
<span v-else>No matching mods found.</span>
</div>
<table class="wikitable" id="mod-list">
<thead>
<tr>

View File

@ -35,6 +35,9 @@
"GitHubUsername": null, // see top note
"GitHubPassword": null, // see top note
"ModDropApiUrl": "https://www.moddrop.com/api/mods/data",
"ModDropModPageUrl": "https://www.moddrop.com/sdv/mod/{0}",
"NexusBaseUrl": "https://www.nexusmods.com/stardewvalley/",
"NexusModUrlFormat": "mods/{0}",
"NexusModScrapeUrlFormat": "mods/{0}?tab=files",

View File

@ -4,10 +4,19 @@ var smapi = smapi || {};
var app;
smapi.modList = function (mods) {
// init data
var defaultStats = {
total: 0,
compatible: 0,
workaround: 0,
soon: 0,
broken: 0,
abandoned: 0,
invalid: 0
};
var data = {
mods: mods,
visibleCount: mods.length,
showAdvanced: false,
visibleStats: $.extend({}, defaultStats),
filters: {
source: {
open: {
@ -64,6 +73,11 @@ smapi.modList = function (mods) {
id: "show-chucklefish",
value: true
},
moddrop: {
label: "ModDrop",
id: "show-moddrop",
value: true
},
nexus: {
label: "Nexus",
id: "show-nexus",
@ -130,27 +144,16 @@ smapi.modList = function (mods) {
var words = data.search.toLowerCase().split(" ");
// apply criteria
data.visibleCount = data.mods.length;
var stats = data.visibleStats = $.extend({}, defaultStats);
for (var i = 0; i < data.mods.length; i++) {
var mod = data.mods[i];
mod.Visible = true;
// check filters
if (!this.matchesFilters(mod)) {
mod.Visible = false;
data.visibleCount--;
continue;
}
// check search terms (all search words should match)
if (words.length) {
for (var w = 0; w < words.length; w++) {
if (mod.SearchableText.indexOf(words[w]) === -1) {
mod.Visible = false;
data.visibleCount--;
break;
}
}
mod.Visible = this.matchesFilters(mod, words);
if (mod.Visible) {
stats.total++;
stats[this.getCompatibilityGroup(mod)]++;
}
}
},
@ -159,9 +162,10 @@ smapi.modList = function (mods) {
/**
* Get whether a mod matches the current filters.
* @param {object} mod The mod to check.
* @param {string[]} searchWords The search words to match.
* @returns {bool} Whether the mod matches the filters.
*/
matchesFilters: function(mod) {
matchesFilters: function(mod, searchWords) {
var filters = data.filters;
// check source
@ -180,6 +184,8 @@ smapi.modList = function (mods) {
if (!filters.download.chucklefish.value)
ignoreSites.push("Chucklefish");
if (!filters.download.moddrop.value)
ignoreSites.push("ModDrop");
if (!filters.download.nexus.value)
ignoreSites.push("Nexus");
if (!filters.download.custom.value)
@ -198,8 +204,50 @@ smapi.modList = function (mods) {
return false;
}
// check search terms
for (var w = 0; w < searchWords.length; w++) {
if (mod.SearchableText.indexOf(searchWords[w]) === -1)
return false;
}
return true;
},
/**
* Get a mod's compatibility group for mod metrics.
* @param {object} mod The mod to check.
* @returns {string} The compatibility group (one of 'compatible', 'workaround', 'soon', 'broken', 'abandoned', or 'invalid').
*/
getCompatibilityGroup: function (mod) {
var status = (mod.BetaCompatibility || mod.Compatibility).Status;
switch (status) {
// obsolete
case "abandoned":
case "obsolete":
return "abandoned";
// compatible
case "ok":
case "optional":
return "compatible";
// workaround
case "workaround":
case "unofficial":
return "workaround";
// soon/broken
case "broken":
if (mod.SourceUrl)
return "soon";
else
return "broken";
default:
return "invalid";
}
}
}
});
app.applyFilters();
};

View File

@ -29,7 +29,7 @@ namespace StardewModdingAPI
** Public
****/
/// <summary>SMAPI's current semantic version.</summary>
public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("2.8.2");
public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("2.9.0");
/// <summary>The minimum supported version of Stardew Valley.</summary>
public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.3.32");
@ -91,9 +91,12 @@ namespace StardewModdingAPI
/// <summary>The file path which stores the detected update version for the next run.</summary>
internal static string UpdateMarker => Path.Combine(Constants.InternalFilesPath, "StardewModdingAPI.update.marker");
/// <summary>The full path to the folder containing mods.</summary>
/// <summary>The default full path to search for mods.</summary>
internal static string DefaultModsPath { get; } = Path.Combine(Constants.ExecutionPath, "Mods");
/// <summary>The actual full path to search for mods.</summary>
internal static string ModsPath { get; set; }
/// <summary>The game's current semantic version.</summary>
internal static ISemanticVersion GameVersion { get; } = new GameVersion(Constants.GetGameVersion());

View File

@ -22,7 +22,7 @@ namespace StardewModdingAPI
/// <summary>Whether <see cref="IsPlayerFree"/> is true and the player is free to move (e.g. not using a tool).</summary>
public static bool CanPlayerMove => Context.IsPlayerFree && Game1.player.CanMove;
/// <summary>Whether the game is currently running the draw loop. This isn't relevant to most mods, since you should use <see cref="GraphicsEvents.OnPostRenderEvent"/> to draw to the screen.</summary>
/// <summary>Whether the game is currently running the draw loop. This isn't relevant to most mods, since you should use <see cref="IDisplayEvents"/> events to draw to the screen.</summary>
public static bool IsInDrawLoop { get; internal set; }
/// <summary>Whether <see cref="IsWorldReady"/> and the player loaded the save in multiplayer mode (regardless of whether any other players are connected).</summary>

View File

@ -29,7 +29,7 @@ namespace StardewModdingAPI.Events
/// <param name="location">The location which changed.</param>
/// <param name="added">The buildings added to the location.</param>
/// <param name="removed">The buildings removed from the location.</param>
public BuildingListChangedEventArgs(GameLocation location, IEnumerable<Building> added, IEnumerable<Building> removed)
internal BuildingListChangedEventArgs(GameLocation location, IEnumerable<Building> added, IEnumerable<Building> removed)
{
this.Location = location;
this.Added = added.ToArray();

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when the game loads content.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class ContentEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,7 +25,11 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after the content language changes.</summary>
public static event EventHandler<EventArgsValueChanged<string>> AfterLocaleChanged
{
add => ContentEvents.EventManager.Legacy_LocaleChanged.Add(value);
add
{
ContentEvents.DeprecationManager.WarnForOldEvents();
ContentEvents.EventManager.Legacy_LocaleChanged.Add(value);
}
remove => ContentEvents.EventManager.Legacy_LocaleChanged.Remove(value);
}
@ -29,9 +39,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
ContentEvents.EventManager = eventManager;
ContentEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -1,10 +1,13 @@
#if !SMAPI_3_0_STRICT
using System;
using Microsoft.Xna.Framework.Input;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when the player uses a controller, keyboard, or mouse.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class ControlEvents
{
/*********
@ -13,6 +16,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -20,56 +26,88 @@ namespace StardewModdingAPI.Events
/// <summary>Raised when the <see cref="KeyboardState"/> changes. That happens when the player presses or releases a key.</summary>
public static event EventHandler<EventArgsKeyboardStateChanged> KeyboardChanged
{
add => ControlEvents.EventManager.Legacy_KeyboardChanged.Add(value);
add
{
ControlEvents.DeprecationManager.WarnForOldEvents();
ControlEvents.EventManager.Legacy_KeyboardChanged.Add(value);
}
remove => ControlEvents.EventManager.Legacy_KeyboardChanged.Remove(value);
}
/// <summary>Raised after the player presses a keyboard key.</summary>
public static event EventHandler<EventArgsKeyPressed> KeyPressed
{
add => ControlEvents.EventManager.Legacy_KeyPressed.Add(value);
add
{
ControlEvents.DeprecationManager.WarnForOldEvents();
ControlEvents.EventManager.Legacy_KeyPressed.Add(value);
}
remove => ControlEvents.EventManager.Legacy_KeyPressed.Remove(value);
}
/// <summary>Raised after the player releases a keyboard key.</summary>
public static event EventHandler<EventArgsKeyPressed> KeyReleased
{
add => ControlEvents.EventManager.Legacy_KeyReleased.Add(value);
add
{
ControlEvents.DeprecationManager.WarnForOldEvents();
ControlEvents.EventManager.Legacy_KeyReleased.Add(value);
}
remove => ControlEvents.EventManager.Legacy_KeyReleased.Remove(value);
}
/// <summary>Raised when the <see cref="MouseState"/> changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button.</summary>
public static event EventHandler<EventArgsMouseStateChanged> MouseChanged
{
add => ControlEvents.EventManager.Legacy_MouseChanged.Add(value);
add
{
ControlEvents.DeprecationManager.WarnForOldEvents();
ControlEvents.EventManager.Legacy_MouseChanged.Add(value);
}
remove => ControlEvents.EventManager.Legacy_MouseChanged.Remove(value);
}
/// <summary>The player pressed a controller button. This event isn't raised for trigger buttons.</summary>
public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed
{
add => ControlEvents.EventManager.Legacy_ControllerButtonPressed.Add(value);
add
{
ControlEvents.DeprecationManager.WarnForOldEvents();
ControlEvents.EventManager.Legacy_ControllerButtonPressed.Add(value);
}
remove => ControlEvents.EventManager.Legacy_ControllerButtonPressed.Remove(value);
}
/// <summary>The player released a controller button. This event isn't raised for trigger buttons.</summary>
public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased
{
add => ControlEvents.EventManager.Legacy_ControllerButtonReleased.Add(value);
add
{
ControlEvents.DeprecationManager.WarnForOldEvents();
ControlEvents.EventManager.Legacy_ControllerButtonReleased.Add(value);
}
remove => ControlEvents.EventManager.Legacy_ControllerButtonReleased.Remove(value);
}
/// <summary>The player pressed a controller trigger button.</summary>
public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed
{
add => ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Add(value);
add
{
ControlEvents.DeprecationManager.WarnForOldEvents();
ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Add(value);
}
remove => ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Remove(value);
}
/// <summary>The player released a controller trigger button.</summary>
public static event EventHandler<EventArgsControllerTriggerReleased> ControllerTriggerReleased
{
add => ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Add(value);
add
{
ControlEvents.DeprecationManager.WarnForOldEvents();
ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Add(value);
}
remove => ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Remove(value);
}
@ -79,9 +117,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
ControlEvents.EventManager = eventManager;
ControlEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -21,7 +21,7 @@ namespace StardewModdingAPI.Events
/// <summary>Construct an instance.</summary>
/// <param name="oldPosition">The previous cursor position.</param>
/// <param name="newPosition">The new cursor position.</param>
public CursorMovedEventArgs(ICursorPosition oldPosition, ICursorPosition newPosition)
internal CursorMovedEventArgs(ICursorPosition oldPosition, ICursorPosition newPosition)
{
this.OldPosition = oldPosition;
this.NewPosition = newPosition;

View File

@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events
/// <param name="location">The location which changed.</param>
/// <param name="added">The debris added to the location.</param>
/// <param name="removed">The debris removed from the location.</param>
public DebrisListChangedEventArgs(GameLocation location, IEnumerable<Debris> added, IEnumerable<Debris> removed)
internal DebrisListChangedEventArgs(GameLocation location, IEnumerable<Debris> added, IEnumerable<Debris> removed)
{
this.Location = location;
this.Added = added.ToArray();

View File

@ -1,4 +1,5 @@
using System;
#if !SMAPI_3_0_STRICT
using System;
using StardewValley.Menus;
namespace StardewModdingAPI.Events
@ -29,3 +30,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,4 +1,5 @@
using System;
#if !SMAPI_3_0_STRICT
using System;
using StardewValley.Menus;
namespace StardewModdingAPI.Events
@ -24,3 +25,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
@ -30,3 +31,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,4 +1,5 @@
using System;
#if !SMAPI_3_0_STRICT
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
@ -30,3 +31,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
@ -35,3 +36,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,4 +1,5 @@
using System;
#if !SMAPI_3_0_STRICT
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
@ -35,3 +36,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using System.Collections.Generic;
@ -60,3 +61,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
namespace StardewModdingAPI.Events
@ -28,3 +29,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using System.Collections.Generic;
using System.Linq;
@ -39,3 +40,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using Microsoft.Xna.Framework.Input;
@ -24,3 +25,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using Microsoft.Xna.Framework.Input;
@ -29,3 +30,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Enums;
@ -51,3 +52,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using System.Collections.Generic;
using System.Linq;
@ -37,3 +38,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using System.Collections.Generic;
using System.Linq;
@ -38,3 +39,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using System.Collections.Generic;
using System.Linq;
@ -31,3 +32,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,4 +1,5 @@
using System;
#if !SMAPI_3_0_STRICT
using System;
namespace StardewModdingAPI.Events
{
@ -28,3 +29,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,4 +1,5 @@
using System;
#if !SMAPI_3_0_STRICT
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
@ -40,3 +41,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,3 +1,4 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewValley;
@ -30,3 +31,4 @@ namespace StardewModdingAPI.Events
}
}
}
#endif

View File

@ -1,4 +1,5 @@
using System;
#if !SMAPI_3_0_STRICT
using System;
namespace StardewModdingAPI.Events
{
@ -28,4 +29,5 @@ namespace StardewModdingAPI.Events
this.NewValue = newValue;
}
}
}
}
#endif

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when the game changes state.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class GameEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,56 +25,88 @@ namespace StardewModdingAPI.Events
/// <summary>Raised when the game updates its state (≈60 times per second).</summary>
public static event EventHandler UpdateTick
{
add => GameEvents.EventManager.Legacy_UpdateTick.Add(value);
add
{
GameEvents.DeprecationManager.WarnForOldEvents();
GameEvents.EventManager.Legacy_UpdateTick.Add(value);
}
remove => GameEvents.EventManager.Legacy_UpdateTick.Remove(value);
}
/// <summary>Raised every other tick (≈30 times per second).</summary>
public static event EventHandler SecondUpdateTick
{
add => GameEvents.EventManager.Legacy_SecondUpdateTick.Add(value);
add
{
GameEvents.DeprecationManager.WarnForOldEvents();
GameEvents.EventManager.Legacy_SecondUpdateTick.Add(value);
}
remove => GameEvents.EventManager.Legacy_SecondUpdateTick.Remove(value);
}
/// <summary>Raised every fourth tick (≈15 times per second).</summary>
public static event EventHandler FourthUpdateTick
{
add => GameEvents.EventManager.Legacy_FourthUpdateTick.Add(value);
add
{
GameEvents.DeprecationManager.WarnForOldEvents();
GameEvents.EventManager.Legacy_FourthUpdateTick.Add(value);
}
remove => GameEvents.EventManager.Legacy_FourthUpdateTick.Remove(value);
}
/// <summary>Raised every eighth tick (≈8 times per second).</summary>
public static event EventHandler EighthUpdateTick
{
add => GameEvents.EventManager.Legacy_EighthUpdateTick.Add(value);
add
{
GameEvents.DeprecationManager.WarnForOldEvents();
GameEvents.EventManager.Legacy_EighthUpdateTick.Add(value);
}
remove => GameEvents.EventManager.Legacy_EighthUpdateTick.Remove(value);
}
/// <summary>Raised every 15th tick (≈4 times per second).</summary>
public static event EventHandler QuarterSecondTick
{
add => GameEvents.EventManager.Legacy_QuarterSecondTick.Add(value);
add
{
GameEvents.DeprecationManager.WarnForOldEvents();
GameEvents.EventManager.Legacy_QuarterSecondTick.Add(value);
}
remove => GameEvents.EventManager.Legacy_QuarterSecondTick.Remove(value);
}
/// <summary>Raised every 30th tick (≈twice per second).</summary>
public static event EventHandler HalfSecondTick
{
add => GameEvents.EventManager.Legacy_HalfSecondTick.Add(value);
add
{
GameEvents.DeprecationManager.WarnForOldEvents();
GameEvents.EventManager.Legacy_HalfSecondTick.Add(value);
}
remove => GameEvents.EventManager.Legacy_HalfSecondTick.Remove(value);
}
/// <summary>Raised every 60th tick (≈once per second).</summary>
public static event EventHandler OneSecondTick
{
add => GameEvents.EventManager.Legacy_OneSecondTick.Add(value);
add
{
GameEvents.DeprecationManager.WarnForOldEvents();
GameEvents.EventManager.Legacy_OneSecondTick.Add(value);
}
remove => GameEvents.EventManager.Legacy_OneSecondTick.Remove(value);
}
/// <summary>Raised once after the game initialises and all <see cref="IMod.Entry"/> methods have been called.</summary>
public static event EventHandler FirstUpdateTick
{
add => GameEvents.EventManager.Legacy_FirstUpdateTick.Add(value);
add
{
GameEvents.DeprecationManager.WarnForOldEvents();
GameEvents.EventManager.Legacy_FirstUpdateTick.Add(value);
}
remove => GameEvents.EventManager.Legacy_FirstUpdateTick.Remove(value);
}
@ -78,9 +116,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
GameEvents.EventManager = eventManager;
GameEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised during the game's draw loop, when the game is rendering content to the window.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class GraphicsEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,7 +25,11 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after the game window is resized.</summary>
public static event EventHandler Resize
{
add => GraphicsEvents.EventManager.Legacy_Resize.Add(value);
add
{
GraphicsEvents.DeprecationManager.WarnForOldEvents();
GraphicsEvents.EventManager.Legacy_Resize.Add(value);
}
remove => GraphicsEvents.EventManager.Legacy_Resize.Remove(value);
}
@ -29,14 +39,22 @@ namespace StardewModdingAPI.Events
/// <summary>Raised before drawing the world to the screen.</summary>
public static event EventHandler OnPreRenderEvent
{
add => GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Add(value);
add
{
GraphicsEvents.DeprecationManager.WarnForOldEvents();
GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Add(value);
}
remove => GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Remove(value);
}
/// <summary>Raised after drawing the world to the screen.</summary>
public static event EventHandler OnPostRenderEvent
{
add => GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Add(value);
add
{
GraphicsEvents.DeprecationManager.WarnForOldEvents();
GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Add(value);
}
remove => GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Remove(value);
}
@ -46,14 +64,22 @@ namespace StardewModdingAPI.Events
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)</summary>
public static event EventHandler OnPreRenderHudEvent
{
add => GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Add(value);
add
{
GraphicsEvents.DeprecationManager.WarnForOldEvents();
GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Add(value);
}
remove => GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Remove(value);
}
/// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)</summary>
public static event EventHandler OnPostRenderHudEvent
{
add => GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Add(value);
add
{
GraphicsEvents.DeprecationManager.WarnForOldEvents();
GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Add(value);
}
remove => GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Remove(value);
}
@ -63,14 +89,22 @@ namespace StardewModdingAPI.Events
/// <summary>Raised before drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.</summary>
public static event EventHandler OnPreRenderGuiEvent
{
add => GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Add(value);
add
{
GraphicsEvents.DeprecationManager.WarnForOldEvents();
GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Add(value);
}
remove => GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Remove(value);
}
/// <summary>Raised after drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.</summary>
public static event EventHandler OnPostRenderGuiEvent
{
add => GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Add(value);
add
{
GraphicsEvents.DeprecationManager.WarnForOldEvents();
GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Add(value);
}
remove => GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Remove(value);
}
@ -80,9 +114,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
GraphicsEvents.EventManager = eventManager;
GraphicsEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when the player uses a controller, keyboard, or mouse button.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class InputEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,14 +25,22 @@ namespace StardewModdingAPI.Events
/// <summary>Raised when the player presses a button on the keyboard, controller, or mouse.</summary>
public static event EventHandler<EventArgsInput> ButtonPressed
{
add => InputEvents.EventManager.Legacy_ButtonPressed.Add(value);
add
{
InputEvents.DeprecationManager.WarnForOldEvents();
InputEvents.EventManager.Legacy_ButtonPressed.Add(value);
}
remove => InputEvents.EventManager.Legacy_ButtonPressed.Remove(value);
}
/// <summary>Raised when the player releases a keyboard key on the keyboard, controller, or mouse.</summary>
public static event EventHandler<EventArgsInput> ButtonReleased
{
add => InputEvents.EventManager.Legacy_ButtonReleased.Add(value);
add
{
InputEvents.DeprecationManager.WarnForOldEvents();
InputEvents.EventManager.Legacy_ButtonReleased.Add(value);
}
remove => InputEvents.EventManager.Legacy_ButtonReleased.Remove(value);
}
@ -36,9 +50,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
InputEvents.EventManager = eventManager;
InputEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -23,6 +23,9 @@ namespace StardewModdingAPI.Events
/// <summary>The items whose stack sizes changed, with the relative change.</summary>
public IEnumerable<ItemStackSizeChange> QuantityChanged { get; }
/// <summary>Whether the affected player is the local one.</summary>
public bool IsLocalPlayer => this.Player.IsLocalPlayer;
/*********
** Public methods
@ -30,7 +33,7 @@ namespace StardewModdingAPI.Events
/// <summary>Construct an instance.</summary>
/// <param name="player">The player whose inventory changed.</param>
/// <param name="changedItems">The inventory changes.</param>
public InventoryChangedEventArgs(Farmer player, ItemStackChange[] changedItems)
internal InventoryChangedEventArgs(Farmer player, ItemStackChange[] changedItems)
{
this.Player = player;
this.Added = changedItems

View File

@ -29,7 +29,7 @@ namespace StardewModdingAPI.Events
/// <param name="location">The location which changed.</param>
/// <param name="added">The large terrain features added to the location.</param>
/// <param name="removed">The large terrain features removed from the location.</param>
public LargeTerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<LargeTerrainFeature> added, IEnumerable<LargeTerrainFeature> removed)
internal LargeTerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<LargeTerrainFeature> added, IEnumerable<LargeTerrainFeature> removed)
{
this.Location = location;
this.Added = added.ToArray();

View File

@ -22,6 +22,9 @@ namespace StardewModdingAPI.Events
/// <summary>The new skill level.</summary>
public int NewLevel { get; }
/// <summary>Whether the affected player is the local one.</summary>
public bool IsLocalPlayer => this.Player.IsLocalPlayer;
/*********
** Public methods
@ -31,7 +34,7 @@ namespace StardewModdingAPI.Events
/// <param name="skill">The skill whose level changed.</param>
/// <param name="oldLevel">The previous skill level.</param>
/// <param name="newLevel">The new skill level.</param>
public LevelChangedEventArgs(Farmer player, SkillType skill, int oldLevel, int newLevel)
internal LevelChangedEventArgs(Farmer player, SkillType skill, int oldLevel, int newLevel)
{
this.Player = player;
this.Skill = skill;

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when the player transitions between game locations, a location is added or removed, or the objects in the current location change.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class LocationEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,21 +25,33 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after a game location is added or removed.</summary>
public static event EventHandler<EventArgsLocationsChanged> LocationsChanged
{
add => LocationEvents.EventManager.Legacy_LocationsChanged.Add(value);
add
{
LocationEvents.DeprecationManager.WarnForOldEvents();
LocationEvents.EventManager.Legacy_LocationsChanged.Add(value);
}
remove => LocationEvents.EventManager.Legacy_LocationsChanged.Remove(value);
}
/// <summary>Raised after buildings are added or removed in a location.</summary>
public static event EventHandler<EventArgsLocationBuildingsChanged> BuildingsChanged
{
add => LocationEvents.EventManager.Legacy_BuildingsChanged.Add(value);
add
{
LocationEvents.DeprecationManager.WarnForOldEvents();
LocationEvents.EventManager.Legacy_BuildingsChanged.Add(value);
}
remove => LocationEvents.EventManager.Legacy_BuildingsChanged.Remove(value);
}
/// <summary>Raised after objects are added or removed in a location.</summary>
public static event EventHandler<EventArgsLocationObjectsChanged> ObjectsChanged
{
add => LocationEvents.EventManager.Legacy_ObjectsChanged.Add(value);
add
{
LocationEvents.DeprecationManager.WarnForOldEvents();
LocationEvents.EventManager.Legacy_ObjectsChanged.Add(value);
}
remove => LocationEvents.EventManager.Legacy_ObjectsChanged.Remove(value);
}
@ -43,9 +61,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
LocationEvents.EventManager = eventManager;
LocationEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -24,7 +24,7 @@ namespace StardewModdingAPI.Events
/// <summary>Construct an instance.</summary>
/// <param name="added">The added locations.</param>
/// <param name="removed">The removed locations.</param>
public LocationListChangedEventArgs(IEnumerable<GameLocation> added, IEnumerable<GameLocation> removed)
internal LocationListChangedEventArgs(IEnumerable<GameLocation> added, IEnumerable<GameLocation> removed)
{
this.Added = added.ToArray();
this.Removed = removed.ToArray();

View File

@ -22,7 +22,7 @@ namespace StardewModdingAPI.Events
/// <summary>Construct an instance.</summary>
/// <param name="oldMenu">The previous menu.</param>
/// <param name="newMenu">The current menu.</param>
public MenuChangedEventArgs(IClickableMenu oldMenu, IClickableMenu newMenu)
internal MenuChangedEventArgs(IClickableMenu oldMenu, IClickableMenu newMenu)
{
this.OldMenu = oldMenu;
this.NewMenu = newMenu;

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when a game menu is opened or closed (including internal menus like the title screen).</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class MenuEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,14 +25,22 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after a game menu is opened or replaced with another menu. This event is not invoked when a menu is closed.</summary>
public static event EventHandler<EventArgsClickableMenuChanged> MenuChanged
{
add => MenuEvents.EventManager.Legacy_MenuChanged.Add(value);
add
{
MenuEvents.DeprecationManager.WarnForOldEvents();
MenuEvents.EventManager.Legacy_MenuChanged.Add(value);
}
remove => MenuEvents.EventManager.Legacy_MenuChanged.Remove(value);
}
/// <summary>Raised after a game menu is closed.</summary>
public static event EventHandler<EventArgsClickableMenuClosed> MenuClosed
{
add => MenuEvents.EventManager.Legacy_MenuClosed.Add(value);
add
{
MenuEvents.DeprecationManager.WarnForOldEvents();
MenuEvents.EventManager.Legacy_MenuClosed.Add(value);
}
remove => MenuEvents.EventManager.Legacy_MenuClosed.Remove(value);
}
@ -36,9 +50,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
MenuEvents.EventManager = eventManager;
MenuEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when something happens in the mines.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class MineEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,7 +25,11 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after the player warps to a new level of the mine.</summary>
public static event EventHandler<EventArgsMineLevelChanged> MineLevelChanged
{
add => MineEvents.EventManager.Legacy_MineLevelChanged.Add(value);
add
{
MineEvents.DeprecationManager.WarnForOldEvents();
MineEvents.EventManager.Legacy_MineLevelChanged.Add(value);
}
remove => MineEvents.EventManager.Legacy_MineLevelChanged.Remove(value);
}
@ -29,9 +39,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
MineEvents.EventManager = eventManager;
MineEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events
/// <param name="position">The cursor position.</param>
/// <param name="oldValue">The old scroll value.</param>
/// <param name="newValue">The new scroll value.</param>
public MouseWheelScrolledEventArgs(ICursorPosition position, int oldValue, int newValue)
internal MouseWheelScrolledEventArgs(ICursorPosition position, int oldValue, int newValue)
{
this.Position = position;
this.OldValue = oldValue;

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised during the multiplayer sync process.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class MultiplayerEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,28 +25,44 @@ namespace StardewModdingAPI.Events
/// <summary>Raised before the game syncs changes from other players.</summary>
public static event EventHandler BeforeMainSync
{
add => MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Add(value);
add
{
MultiplayerEvents.DeprecationManager.WarnForOldEvents();
MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Add(value);
}
remove => MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Remove(value);
}
/// <summary>Raised after the game syncs changes from other players.</summary>
public static event EventHandler AfterMainSync
{
add => MultiplayerEvents.EventManager.Legacy_AfterMainSync.Add(value);
add
{
MultiplayerEvents.DeprecationManager.WarnForOldEvents();
MultiplayerEvents.EventManager.Legacy_AfterMainSync.Add(value);
}
remove => MultiplayerEvents.EventManager.Legacy_AfterMainSync.Remove(value);
}
/// <summary>Raised before the game broadcasts changes to other players.</summary>
public static event EventHandler BeforeMainBroadcast
{
add => MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Add(value);
add
{
MultiplayerEvents.DeprecationManager.WarnForOldEvents();
MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Add(value);
}
remove => MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Remove(value);
}
/// <summary>Raised after the game broadcasts changes to other players.</summary>
public static event EventHandler AfterMainBroadcast
{
add => MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Add(value);
add
{
MultiplayerEvents.DeprecationManager.WarnForOldEvents();
MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Add(value);
}
remove => MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Remove(value);
}
@ -50,9 +72,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
MultiplayerEvents.EventManager = eventManager;
MultiplayerEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events
/// <param name="location">The location which changed.</param>
/// <param name="added">The NPCs added to the location.</param>
/// <param name="removed">The NPCs removed from the location.</param>
public NpcListChangedEventArgs(GameLocation location, IEnumerable<NPC> added, IEnumerable<NPC> removed)
internal NpcListChangedEventArgs(GameLocation location, IEnumerable<NPC> added, IEnumerable<NPC> removed)
{
this.Location = location;
this.Added = added.ToArray();

View File

@ -30,7 +30,7 @@ namespace StardewModdingAPI.Events
/// <param name="location">The location which changed.</param>
/// <param name="added">The objects added to the location.</param>
/// <param name="removed">The objects removed from the location.</param>
public ObjectListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, Object>> added, IEnumerable<KeyValuePair<Vector2, Object>> removed)
internal ObjectListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, Object>> added, IEnumerable<KeyValuePair<Vector2, Object>> removed)
{
this.Location = location;
this.Added = added.ToArray();

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when the player data changes.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class PlayerEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,21 +25,33 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after the player's inventory changes in any way (added or removed item, sorted, etc).</summary>
public static event EventHandler<EventArgsInventoryChanged> InventoryChanged
{
add => PlayerEvents.EventManager.Legacy_InventoryChanged.Add(value);
add
{
PlayerEvents.DeprecationManager.WarnForOldEvents();
PlayerEvents.EventManager.Legacy_InventoryChanged.Add(value);
}
remove => PlayerEvents.EventManager.Legacy_InventoryChanged.Remove(value);
}
/// <summary>Raised after the player levels up a skill. This happens as soon as they level up, not when the game notifies the player after their character goes to bed.</summary>
public static event EventHandler<EventArgsLevelUp> LeveledUp
{
add => PlayerEvents.EventManager.Legacy_LeveledUp.Add(value);
add
{
PlayerEvents.DeprecationManager.WarnForOldEvents();
PlayerEvents.EventManager.Legacy_LeveledUp.Add(value);
}
remove => PlayerEvents.EventManager.Legacy_LeveledUp.Remove(value);
}
/// <summary>Raised after the player warps to a new location.</summary>
public static event EventHandler<EventArgsPlayerWarped> Warped
{
add => PlayerEvents.EventManager.Legacy_PlayerWarped.Add(value);
add
{
PlayerEvents.DeprecationManager.WarnForOldEvents();
PlayerEvents.EventManager.Legacy_PlayerWarped.Add(value);
}
remove => PlayerEvents.EventManager.Legacy_PlayerWarped.Remove(value);
}
@ -44,9 +62,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
PlayerEvents.EventManager = eventManager;
PlayerEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised before and after the player saves/loads the game.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class SaveEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,42 +25,66 @@ namespace StardewModdingAPI.Events
/// <summary>Raised before the game creates the save file.</summary>
public static event EventHandler BeforeCreate
{
add => SaveEvents.EventManager.Legacy_BeforeCreateSave.Add(value);
add
{
SaveEvents.DeprecationManager.WarnForOldEvents();
SaveEvents.EventManager.Legacy_BeforeCreateSave.Add(value);
}
remove => SaveEvents.EventManager.Legacy_BeforeCreateSave.Remove(value);
}
/// <summary>Raised after the game finishes creating the save file.</summary>
public static event EventHandler AfterCreate
{
add => SaveEvents.EventManager.Legacy_AfterCreateSave.Add(value);
add
{
SaveEvents.DeprecationManager.WarnForOldEvents();
SaveEvents.EventManager.Legacy_AfterCreateSave.Add(value);
}
remove => SaveEvents.EventManager.Legacy_AfterCreateSave.Remove(value);
}
/// <summary>Raised before the game begins writes data to the save file.</summary>
public static event EventHandler BeforeSave
{
add => SaveEvents.EventManager.Legacy_BeforeSave.Add(value);
add
{
SaveEvents.DeprecationManager.WarnForOldEvents();
SaveEvents.EventManager.Legacy_BeforeSave.Add(value);
}
remove => SaveEvents.EventManager.Legacy_BeforeSave.Remove(value);
}
/// <summary>Raised after the game finishes writing data to the save file.</summary>
public static event EventHandler AfterSave
{
add => SaveEvents.EventManager.Legacy_AfterSave.Add(value);
add
{
SaveEvents.DeprecationManager.WarnForOldEvents();
SaveEvents.EventManager.Legacy_AfterSave.Add(value);
}
remove => SaveEvents.EventManager.Legacy_AfterSave.Remove(value);
}
/// <summary>Raised after the player loads a save slot.</summary>
public static event EventHandler AfterLoad
{
add => SaveEvents.EventManager.Legacy_AfterLoad.Add(value);
add
{
SaveEvents.DeprecationManager.WarnForOldEvents();
SaveEvents.EventManager.Legacy_AfterLoad.Add(value);
}
remove => SaveEvents.EventManager.Legacy_AfterLoad.Remove(value);
}
/// <summary>Raised after the game returns to the title screen.</summary>
public static event EventHandler AfterReturnToTitle
{
add => SaveEvents.EventManager.Legacy_AfterReturnToTitle.Add(value);
add
{
SaveEvents.DeprecationManager.WarnForOldEvents();
SaveEvents.EventManager.Legacy_AfterReturnToTitle.Add(value);
}
remove => SaveEvents.EventManager.Legacy_AfterReturnToTitle.Remove(value);
}
@ -64,9 +94,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
SaveEvents.EventManager = eventManager;
SaveEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events serving specialised edge cases that shouldn't be used by most mods.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class SpecialisedEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,7 +25,11 @@ namespace StardewModdingAPI.Events
/// <summary>Raised when the game updates its state (≈60 times per second), regardless of normal SMAPI validation. This event is not thread-safe and may be invoked while game logic is running asynchronously. Changes to game state in this method may crash the game or corrupt an in-progress save. Do not use this event unless you're fully aware of the context in which your code will be run. Mods using this method will trigger a stability warning in the SMAPI console.</summary>
public static event EventHandler UnvalidatedUpdateTick
{
add => SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Add(value);
add
{
SpecialisedEvents.DeprecationManager.WarnForOldEvents();
SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Add(value);
}
remove => SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Remove(value);
}
@ -29,9 +39,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
SpecialisedEvents.EventManager = eventManager;
SpecialisedEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -30,7 +30,7 @@ namespace StardewModdingAPI.Events
/// <param name="location">The location which changed.</param>
/// <param name="added">The terrain features added to the location.</param>
/// <param name="removed">The terrain features removed from the location.</param>
public TerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> added, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> removed)
internal TerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> added, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> removed)
{
this.Location = location;
this.Added = added.ToArray();

View File

@ -21,7 +21,7 @@ namespace StardewModdingAPI.Events
/// <summary>Construct an instance.</summary>
/// <param name="oldTime">The previous time of day in 24-hour notation (like 1600 for 4pm).</param>
/// <param name="newTime">The current time of day in 24-hour notation (like 1600 for 4pm).</param>
public TimeChangedEventArgs(int oldTime, int newTime)
internal TimeChangedEventArgs(int oldTime, int newTime)
{
this.OldTime = oldTime;
this.NewTime = newTime;

View File

@ -1,9 +1,12 @@
#if !SMAPI_3_0_STRICT
using System;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Events;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when the in-game date or time changes.</summary>
[Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")]
public static class TimeEvents
{
/*********
@ -12,6 +15,9 @@ namespace StardewModdingAPI.Events
/// <summary>The core event manager.</summary>
private static EventManager EventManager;
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
/*********
** Events
@ -19,14 +25,22 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after the game begins a new day, including when loading a save.</summary>
public static event EventHandler AfterDayStarted
{
add => TimeEvents.EventManager.Legacy_AfterDayStarted.Add(value);
add
{
TimeEvents.DeprecationManager.WarnForOldEvents();
TimeEvents.EventManager.Legacy_AfterDayStarted.Add(value);
}
remove => TimeEvents.EventManager.Legacy_AfterDayStarted.Remove(value);
}
/// <summary>Raised after the in-game clock changes.</summary>
public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged
{
add => TimeEvents.EventManager.Legacy_TimeOfDayChanged.Add(value);
add
{
TimeEvents.DeprecationManager.WarnForOldEvents();
TimeEvents.EventManager.Legacy_TimeOfDayChanged.Add(value);
}
remove => TimeEvents.EventManager.Legacy_TimeOfDayChanged.Remove(value);
}
@ -36,9 +50,12 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Initialise the events.</summary>
/// <param name="eventManager">The core event manager.</param>
internal static void Init(EventManager eventManager)
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Init(EventManager eventManager, DeprecationManager deprecationManager)
{
TimeEvents.EventManager = eventManager;
TimeEvents.DeprecationManager = deprecationManager;
}
}
}
#endif

View File

@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Construct an instance.</summary>
/// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param>
public UnvalidatedUpdateTickedEventArgs(uint ticks)
internal UnvalidatedUpdateTickedEventArgs(uint ticks)
{
this.Ticks = ticks;
this.IsOneSecond = this.IsMultipleOf(60);

View File

@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Construct an instance.</summary>
/// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param>
public UnvalidatedUpdateTickingEventArgs(uint ticks)
internal UnvalidatedUpdateTickingEventArgs(uint ticks)
{
this.Ticks = ticks;
this.IsOneSecond = this.IsMultipleOf(60);

View File

@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Construct an instance.</summary>
/// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param>
public UpdateTickedEventArgs(uint ticks)
internal UpdateTickedEventArgs(uint ticks)
{
this.Ticks = ticks;
this.IsOneSecond = this.IsMultipleOf(60);

View File

@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events
*********/
/// <summary>Construct an instance.</summary>
/// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param>
public UpdateTickingEventArgs(uint ticks)
internal UpdateTickingEventArgs(uint ticks)
{
this.Ticks = ticks;
this.IsOneSecond = this.IsMultipleOf(60);

View File

@ -18,6 +18,9 @@ namespace StardewModdingAPI.Events
/// <summary>The player's current location.</summary>
public GameLocation NewLocation { get; }
/// <summary>Whether the affected player is the local one.</summary>
public bool IsLocalPlayer => this.Player.IsLocalPlayer;
/*********
@ -27,7 +30,7 @@ namespace StardewModdingAPI.Events
/// <param name="player">The player who warped to a new location.</param>
/// <param name="oldLocation">The player's previous location.</param>
/// <param name="newLocation">The player's current location.</param>
public WarpedEventArgs(Farmer player, GameLocation oldLocation, GameLocation newLocation)
internal WarpedEventArgs(Farmer player, GameLocation oldLocation, GameLocation newLocation)
{
this.Player = player;
this.NewLocation = newLocation;

View File

@ -22,7 +22,7 @@ namespace StardewModdingAPI.Events
/// <summary>Construct an instance.</summary>
/// <param name="oldSize">The previous window size.</param>
/// <param name="newSize">The current window size.</param>
public WindowResizedEventArgs(Point oldSize, Point newSize)
internal WindowResizedEventArgs(Point oldSize, Point newSize)
{
this.OldSize = oldSize;
this.NewSize = newSize;

View File

@ -238,28 +238,30 @@ namespace StardewModdingAPI.Framework
public IEnumerable<string> InvalidateCache(Func<string, Type, bool> predicate, bool dispose = false)
{
// invalidate cache
HashSet<string> removedAssetNames = new HashSet<string>();
IDictionary<string, Type> removedAssetNames = new Dictionary<string, Type>(StringComparer.InvariantCultureIgnoreCase);
foreach (IContentManager contentManager in this.ContentManagers)
{
foreach (string name in contentManager.InvalidateCache(predicate, dispose))
removedAssetNames.Add(name);
foreach (Tuple<string, Type> asset in contentManager.InvalidateCache(predicate, dispose))
removedAssetNames[asset.Item1] = asset.Item2;
}
// reload core game assets
int reloaded = 0;
foreach (string key in removedAssetNames)
foreach (var pair in removedAssetNames)
{
if (this.CoreAssets.Propagate(this.MainContentManager, key)) // use an intercepted content manager
string key = pair.Key;
Type type = pair.Value;
if (this.CoreAssets.Propagate(this.MainContentManager, key, type)) // use an intercepted content manager
reloaded++;
}
// report result
if (removedAssetNames.Any())
this.Monitor.Log($"Invalidated {removedAssetNames.Count} asset names: {string.Join(", ", removedAssetNames.OrderBy(p => p, StringComparer.InvariantCultureIgnoreCase))}. Reloaded {reloaded} core assets.", LogLevel.Trace);
this.Monitor.Log($"Invalidated {removedAssetNames.Count} asset names: {string.Join(", ", removedAssetNames.Keys.OrderBy(p => p, StringComparer.InvariantCultureIgnoreCase))}. Reloaded {reloaded} core assets.", LogLevel.Trace);
else
this.Monitor.Log("Invalidated 0 cache entries.", LogLevel.Trace);
return removedAssetNames;
return removedAssetNames.Keys;
}
/// <summary>Dispose held resources.</summary>

View File

@ -32,12 +32,12 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <summary>Whether the content coordinator has been disposed.</summary>
private bool IsDisposed;
/// <summary>The language enum values indexed by locale code.</summary>
private readonly IDictionary<string, LanguageCode> LanguageCodes;
/// <summary>A callback to invoke when the content manager is being disposed.</summary>
private readonly Action<BaseContentManager> OnDisposing;
/// <summary>The language enum values indexed by locale code.</summary>
protected IDictionary<string, LanguageCode> LanguageCodes { get; }
/*********
** Accessors
@ -200,23 +200,25 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <summary>Purge matched assets from the cache.</summary>
/// <param name="predicate">Matches the asset keys to invalidate.</param>
/// <param name="dispose">Whether to dispose invalidated assets. This should only be <c>true</c> when they're being invalidated as part of a dispose, to avoid crashing the game.</param>
/// <returns>Returns the number of invalidated assets.</returns>
public IEnumerable<string> InvalidateCache(Func<string, Type, bool> predicate, bool dispose = false)
/// <returns>Returns the invalidated asset names and types.</returns>
public IEnumerable<Tuple<string, Type>> InvalidateCache(Func<string, Type, bool> predicate, bool dispose = false)
{
HashSet<string> removeAssetNames = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
Dictionary<string, Type> removeAssetNames = new Dictionary<string, Type>(StringComparer.InvariantCultureIgnoreCase);
this.Cache.Remove((key, type) =>
{
this.ParseCacheKey(key, out string assetName, out _);
if (removeAssetNames.Contains(assetName) || predicate(assetName, type))
if (removeAssetNames.ContainsKey(assetName))
return true;
if (predicate(assetName, type))
{
removeAssetNames.Add(assetName);
removeAssetNames[assetName] = type;
return true;
}
return false;
});
return removeAssetNames;
return removeAssetNames.Select(p => Tuple.Create(p.Key, p.Value));
}
/// <summary>Dispose held resources.</summary>

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using StardewModdingAPI.Framework.Content;
using StardewModdingAPI.Framework.Exceptions;
using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Framework.Utilities;
using StardewValley;
@ -52,7 +53,10 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <param name="language">The language code for which to load content.</param>
public override T Load<T>(string assetName, LanguageCode language)
{
// normalise asset name
assetName = this.AssertAndNormaliseAssetName(assetName);
if (this.TryParseExplicitLanguageAssetKey(assetName, out string newAssetName, out LanguageCode newLanguage))
return this.Load<T>(newAssetName, newLanguage);
// get from cache
if (this.IsLoaded(assetName))
@ -124,6 +128,29 @@ namespace StardewModdingAPI.Framework.ContentManagers
return false;
}
/// <summary>Parse an asset key that contains an explicit language into its asset name and language, if applicable.</summary>
/// <param name="rawAsset">The asset key to parse.</param>
/// <param name="assetName">The asset name without the language code.</param>
/// <param name="language">The language code removed from the asset name.</param>
private bool TryParseExplicitLanguageAssetKey(string rawAsset, out string assetName, out LanguageCode language)
{
if (string.IsNullOrWhiteSpace(rawAsset))
throw new SContentLoadException("The asset key is empty.");
// extract language code
int splitIndex = rawAsset.LastIndexOf('.');
if (splitIndex != -1 && this.LanguageCodes.TryGetValue(rawAsset.Substring(splitIndex + 1), out language))
{
assetName = rawAsset.Substring(0, splitIndex);
return true;
}
// no explicit language code found
assetName = rawAsset;
language = this.Language;
return false;
}
/// <summary>Load the initial asset from the registered <see cref="Loaders"/>.</summary>
/// <param name="info">The basic asset metadata.</param>
/// <returns>Returns the loaded asset metadata, or <c>null</c> if no loader matched.</returns>

View File

@ -80,7 +80,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <summary>Purge matched assets from the cache.</summary>
/// <param name="predicate">Matches the asset keys to invalidate.</param>
/// <param name="dispose">Whether to dispose invalidated assets. This should only be <c>true</c> when they're being invalidated as part of a dispose, to avoid crashing the game.</param>
/// <returns>Returns the number of invalidated assets.</returns>
IEnumerable<string> InvalidateCache(Func<string, Type, bool> predicate, bool dispose = false);
/// <returns>Returns the invalidated asset names and types.</returns>
IEnumerable<Tuple<string, Type>> InvalidateCache(Func<string, Type, bool> predicate, bool dispose = false);
}
}

View File

@ -35,6 +35,12 @@ namespace StardewModdingAPI.Framework
this.ModRegistry = modRegistry;
}
/// <summary>Log a deprecation warning for the old-style events.</summary>
public void WarnForOldEvents()
{
this.Warn("legacy events", "2.9", DeprecationLevel.Notice);
}
/// <summary>Log a deprecation warning.</summary>
/// <param name="nounPhrase">A noun phrase describing what is deprecated.</param>
/// <param name="version">The SMAPI version which deprecated it.</param>

View File

@ -1,5 +1,7 @@
using System.Diagnostics.CodeAnalysis;
#if !SMAPI_3_0_STRICT
using Microsoft.Xna.Framework.Input;
#endif
using StardewModdingAPI.Events;
namespace StardewModdingAPI.Framework.Events
@ -156,6 +158,7 @@ namespace StardewModdingAPI.Framework.Events
public readonly ManagedEvent<UnvalidatedUpdateTickedEventArgs> UnvalidatedUpdateTicked;
#if !SMAPI_3_0_STRICT
/*********
** Events (old)
*********/
@ -342,6 +345,7 @@ namespace StardewModdingAPI.Framework.Events
/// <summary>Raised after the in-game clock changes.</summary>
public readonly ManagedEvent<EventArgsIntChanged> Legacy_TimeOfDayChanged;
#endif
/*********
@ -354,7 +358,9 @@ namespace StardewModdingAPI.Framework.Events
{
// create shortcut initialisers
ManagedEvent<TEventArgs> ManageEventOf<TEventArgs>(string typeName, string eventName) => new ManagedEvent<TEventArgs>($"{typeName}.{eventName}", monitor, modRegistry);
#if !SMAPI_3_0_STRICT
ManagedEvent ManageEvent(string typeName, string eventName) => new ManagedEvent($"{typeName}.{eventName}", monitor, modRegistry);
#endif
// init events (new)
this.MenuChanged = ManageEventOf<MenuChangedEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.MenuChanged));
@ -405,6 +411,7 @@ namespace StardewModdingAPI.Framework.Events
this.UnvalidatedUpdateTicking = ManageEventOf<UnvalidatedUpdateTickingEventArgs>(nameof(IModEvents.Specialised), nameof(ISpecialisedEvents.UnvalidatedUpdateTicking));
this.UnvalidatedUpdateTicked = ManageEventOf<UnvalidatedUpdateTickedEventArgs>(nameof(IModEvents.Specialised), nameof(ISpecialisedEvents.UnvalidatedUpdateTicked));
#if !SMAPI_3_0_STRICT
// init events (old)
this.Legacy_LocaleChanged = ManageEventOf<EventArgsValueChanged<string>>(nameof(ContentEvents), nameof(ContentEvents.AfterLocaleChanged));
@ -466,6 +473,7 @@ namespace StardewModdingAPI.Framework.Events
this.Legacy_AfterDayStarted = ManageEvent(nameof(TimeEvents), nameof(TimeEvents.AfterDayStarted));
this.Legacy_TimeOfDayChanged = ManageEventOf<EventArgsIntChanged>(nameof(TimeEvents), nameof(TimeEvents.TimeOfDayChanged));
#endif
}
}
}

View File

@ -21,8 +21,10 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>Create a transitional content pack.</summary>
private readonly Func<string, IManifest, IContentPack> CreateContentPack;
#if !SMAPI_3_0_STRICT
/// <summary>Manages deprecation warnings.</summary>
private readonly DeprecationManager DeprecationManager;
#endif
/*********
@ -31,8 +33,10 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>The full path to the mod's folder.</summary>
public string DirectoryPath { get; }
#if !SMAPI_3_0_STRICT
/// <summary>Encapsulates SMAPI's JSON file parsing.</summary>
private readonly JsonHelper JsonHelper;
#endif
/// <summary>Manages access to events raised by SMAPI, which let your mod react when something happens in the game.</summary>
public IModEvents Events { get; }
@ -94,7 +98,6 @@ namespace StardewModdingAPI.Framework.ModHelpers
// initialise
this.DirectoryPath = modDirectory;
this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper));
this.Content = contentHelper ?? throw new ArgumentNullException(nameof(contentHelper));
this.Data = dataHelper ?? throw new ArgumentNullException(nameof(dataHelper));
this.Input = new InputHelper(modID, inputState);
@ -105,8 +108,11 @@ namespace StardewModdingAPI.Framework.ModHelpers
this.Translation = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper));
this.ContentPacks = new Lazy<IContentPack[]>(contentPacks);
this.CreateContentPack = createContentPack;
this.DeprecationManager = deprecationManager;
this.Events = events;
#if !SMAPI_3_0_STRICT
this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper));
this.DeprecationManager = deprecationManager;
#endif
}
/****
@ -131,6 +137,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
this.Data.WriteJsonFile("config.json", config);
}
#if !SMAPI_3_0_STRICT
/****
** Generic JSON files
****/
@ -159,23 +166,20 @@ namespace StardewModdingAPI.Framework.ModHelpers
path = Path.Combine(this.DirectoryPath, PathUtilities.NormalisePathSeparators(path));
this.JsonHelper.WriteJsonFile(path, model);
}
#endif
/****
** Content packs
****/
/// <summary>Manually create a transitional content pack to support pre-SMAPI content packs. This provides a way to access legacy content packs using the SMAPI content pack APIs, but the content pack will not be visible in the log or validated by SMAPI.</summary>
/// <summary>Create a temporary content pack to read files from a directory. Temporary content packs will not appear in the SMAPI log and update checks will not be performed.</summary>
/// <param name="directoryPath">The absolute directory path containing the content pack files.</param>
/// <param name="id">The content pack's unique ID.</param>
/// <param name="name">The content pack name.</param>
/// <param name="description">The content pack description.</param>
/// <param name="author">The content pack author's name.</param>
/// <param name="version">The content pack version.</param>
[Obsolete("This method supports mods which previously had their own content packs, and shouldn't be used by new mods. It will be removed in SMAPI 3.0.")]
public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version)
public IContentPack CreateTemporaryContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version)
{
// raise deprecation notice
this.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice);
// validate
if (string.IsNullOrWhiteSpace(directoryPath))
throw new ArgumentNullException(nameof(directoryPath));
@ -200,6 +204,22 @@ namespace StardewModdingAPI.Framework.ModHelpers
return this.CreateContentPack(directoryPath, manifest);
}
#if !SMAPI_3_0_STRICT
/// <summary>Manually create a transitional content pack to support pre-SMAPI content packs. This provides a way to access legacy content packs using the SMAPI content pack APIs, but the content pack will not be visible in the log or validated by SMAPI.</summary>
/// <param name="directoryPath">The absolute directory path containing the content pack files.</param>
/// <param name="id">The content pack's unique ID.</param>
/// <param name="name">The content pack name.</param>
/// <param name="description">The content pack description.</param>
/// <param name="author">The content pack author's name.</param>
/// <param name="version">The content pack version.</param>
[Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.CreateTemporaryContentPack) + " instead")]
public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version)
{
this.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice);
return this.CreateTemporaryContentPack(directoryPath, id, name, description, author, version);
}
#endif
/// <summary>Get all content packs loaded for this mod.</summary>
public IEnumerable<IContentPack> GetContentPacks()
{

View File

@ -20,6 +20,9 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <summary>Encapsulates monitoring and logging.</summary>
private readonly IMonitor Monitor;
/// <summary>Whether to detect paranoid mode issues.</summary>
private readonly bool ParanoidMode;
/// <summary>Metadata for mapping assemblies to the current platform.</summary>
private readonly PlatformAssemblyMap AssemblyMap;
@ -39,9 +42,11 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <summary>Construct an instance.</summary>
/// <param name="targetPlatform">The current game platform.</param>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
public AssemblyLoader(Platform targetPlatform, IMonitor monitor)
/// <param name="paranoidMode">Whether to detect paranoid mode issues.</param>
public AssemblyLoader(Platform targetPlatform, IMonitor monitor, bool paranoidMode)
{
this.Monitor = monitor;
this.ParanoidMode = paranoidMode;
this.AssemblyMap = this.TrackForDisposal(Constants.GetAssemblyMap(targetPlatform));
this.AssemblyDefinitionResolver = this.TrackForDisposal(new AssemblyDefinitionResolver());
this.AssemblyDefinitionResolver.AddSearchDirectory(Constants.ExecutionPath);
@ -275,7 +280,7 @@ namespace StardewModdingAPI.Framework.ModLoading
// find (and optionally rewrite) incompatible instructions
bool anyRewritten = false;
IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers().ToArray();
IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers(this.ParanoidMode).ToArray();
foreach (MethodDefinition method in this.GetMethods(module))
{
// check method definition

View File

@ -23,7 +23,7 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <summary>The instruction is compatible, but uses the <c>dynamic</c> keyword which won't work on Linux/Mac.</summary>
DetectedDynamic,
/// <summary>The instruction is compatible, but references <see cref="SpecialisedEvents.UnvalidatedUpdateTick"/> which may impact stability.</summary>
/// <summary>The instruction is compatible, but references <see cref="ISpecialisedEvents.UnvalidatedUpdateTicking"/> or <see cref="ISpecialisedEvents.UnvalidatedUpdateTicked"/> which may impact stability.</summary>
DetectedUnvalidatedUpdateTick,
/// <summary>The instruction accesses the filesystem directly.</summary>

View File

@ -22,7 +22,7 @@ namespace StardewModdingAPI.Framework.ModLoading
/// <summary>The mod uses the <c>dynamic</c> keyword which won't work on Linux/Mac.</summary>
UsesDynamic = 8,
/// <summary>The mod references <see cref="SpecialisedEvents.UnvalidatedUpdateTick"/> which may impact stability.</summary>
/// <summary>The mod references <see cref="ISpecialisedEvents.UnvalidatedUpdateTicking"/> or <see cref="ISpecialisedEvents.UnvalidatedUpdateTicked"/> which may impact stability.</summary>
UsesUnvalidatedUpdateTick = 16,
/// <summary>The mod has no update keys set.</summary>

View File

@ -99,11 +99,25 @@ namespace StardewModdingAPI.Framework
new Regex(@"^static SerializableDictionary<.+>\(\) called\.$", RegexOptions.Compiled | RegexOptions.CultureInvariant),
};
/// <summary>Regex patterns which match console messages to show a more friendly error for.</summary>
private readonly Tuple<Regex, string, LogLevel>[] ReplaceConsolePatterns =
{
Tuple.Create(
new Regex(@"^System\.InvalidOperationException: Steamworks is not initialized\.", RegexOptions.Compiled | RegexOptions.CultureInvariant),
#if SMAPI_FOR_WINDOWS
"Oops! Steam achievements won't work because Steam isn't loaded. You can launch the game through Steam to fix that (see 'Part 2: Configure Steam' in the install guide for more info: https://smapi.io/install).",
#else
"Oops! Steam achievements won't work because Steam isn't loaded. You can launch the game through Steam to fix that.",
#endif
LogLevel.Error
)
};
/// <summary>The mod toolkit used for generic mod interactions.</summary>
private readonly ModToolkit Toolkit = new ModToolkit();
/// <summary>The path to search for mods.</summary>
private readonly string ModsPath;
private string ModsPath => Constants.ModsPath;
/*********
@ -117,7 +131,7 @@ namespace StardewModdingAPI.Framework
// init paths
this.VerifyPath(modsPath);
this.VerifyPath(Constants.LogDir);
this.ModsPath = modsPath;
Constants.ModsPath = modsPath;
// init log file
this.PurgeNormalLogs();
@ -180,20 +194,22 @@ namespace StardewModdingAPI.Framework
// initialise SMAPI
try
{
#if !SMAPI_3_0_STRICT
// hook up events
ContentEvents.Init(this.EventManager);
ControlEvents.Init(this.EventManager);
GameEvents.Init(this.EventManager);
GraphicsEvents.Init(this.EventManager);
InputEvents.Init(this.EventManager);
LocationEvents.Init(this.EventManager);
MenuEvents.Init(this.EventManager);
MineEvents.Init(this.EventManager);
MultiplayerEvents.Init(this.EventManager);
PlayerEvents.Init(this.EventManager);
SaveEvents.Init(this.EventManager);
SpecialisedEvents.Init(this.EventManager);
TimeEvents.Init(this.EventManager);
ContentEvents.Init(this.EventManager, this.DeprecationManager);
ControlEvents.Init(this.EventManager, this.DeprecationManager);
GameEvents.Init(this.EventManager, this.DeprecationManager);
GraphicsEvents.Init(this.EventManager, this.DeprecationManager);
InputEvents.Init(this.EventManager, this.DeprecationManager);
LocationEvents.Init(this.EventManager, this.DeprecationManager);
MenuEvents.Init(this.EventManager, this.DeprecationManager);
MineEvents.Init(this.EventManager, this.DeprecationManager);
MultiplayerEvents.Init(this.EventManager, this.DeprecationManager);
PlayerEvents.Init(this.EventManager, this.DeprecationManager);
SaveEvents.Init(this.EventManager, this.DeprecationManager);
SpecialisedEvents.Init(this.EventManager, this.DeprecationManager);
TimeEvents.Init(this.EventManager, this.DeprecationManager);
#endif
// init JSON parser
JsonConverter[] converters = {
@ -216,7 +232,7 @@ namespace StardewModdingAPI.Framework
// override game
SGame.ConstructorHack = new SGameConstructorHack(this.Monitor, this.Reflection, this.Toolkit.JsonHelper);
this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, this.DeprecationManager, this.InitialiseAfterGameStart, this.Dispose);
this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, this.DeprecationManager, this.OnLocaleChanged, this.InitialiseAfterGameStart, this.Dispose);
StardewValley.Program.gamePtr = this.GameInstance;
// add exit handler
@ -239,12 +255,13 @@ namespace StardewModdingAPI.Framework
}
}).Start();
// hook into game events
ContentEvents.AfterLocaleChanged += (sender, e) => this.OnLocaleChanged();
// set window titles
this.GameInstance.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion}";
Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}";
#if SMAPI_3_0_STRICT
this.GameInstance.Window.Title += " [SMAPI 3.0 strict mode]";
Console.Title += " [SMAPI 3.0 strict mode]";
#endif
}
catch (Exception ex)
{
@ -348,8 +365,11 @@ namespace StardewModdingAPI.Framework
private void InitialiseAfterGameStart()
{
// add headers
#if SMAPI_3_0_STRICT
this.Monitor.Log($"You're running SMAPI 3.0 strict mode, so most mods won't work correctly. If that wasn't intended, install the normal version of SMAPI from https://smapi.io instead.", LogLevel.Warn);
#endif
if (this.Settings.DeveloperMode)
this.Monitor.Log($"You configured SMAPI to run in developer mode. The console may be much more verbose. You can disable developer mode by installing the non-developer version of SMAPI, or by editing {Constants.ApiConfigPath}.", LogLevel.Info);
this.Monitor.Log($"You have SMAPI for developers, so the console will be much more verbose. You can disable developer mode by installing the non-developer version of SMAPI, or by editing {Constants.ApiConfigPath}.", LogLevel.Info);
if (!this.Settings.CheckForUpdates)
this.Monitor.Log($"You configured SMAPI to not check for updates. Running an old version of SMAPI is not recommended. You can enable update checks by reinstalling SMAPI or editing {Constants.ApiConfigPath}.", LogLevel.Warn);
if (!this.Monitor.WriteToConsole)
@ -409,6 +429,11 @@ namespace StardewModdingAPI.Framework
int modsLoaded = this.ModRegistry.GetAll().Count();
this.GameInstance.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion} with {modsLoaded} mods";
Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion} with {modsLoaded} mods";
#if SMAPI_3_0_STRICT
this.GameInstance.Window.Title += " [SMAPI 3.0 strict mode]";
Console.Title += " [SMAPI 3.0 strict mode]";
#endif
// start SMAPI console
new Thread(this.RunConsoleLoop).Start();
@ -701,7 +726,7 @@ namespace StardewModdingAPI.Framework
// load mods
IDictionary<IModMetadata, Tuple<string, string>> skippedMods = new Dictionary<IModMetadata, Tuple<string, string>>();
using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor))
using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.ParanoidWarnings))
{
// init
HashSet<string> suppressUpdateChecks = new HashSet<string>(this.Settings.SuppressUpdateChecks, StringComparer.InvariantCultureIgnoreCase);
@ -891,11 +916,13 @@ namespace StardewModdingAPI.Framework
return false;
}
#if !SMAPI_3_0_STRICT
// add deprecation warning for old version format
{
if (mod.Manifest?.Version is Toolkit.SemanticVersion version && version.IsLegacyFormat)
this.DeprecationManager.Warn(mod.DisplayName, "non-string manifest version", "2.8", DeprecationLevel.Notice);
}
#endif
// validate dependencies
// Although dependences are validated before mods are loaded, a dependency may have failed to load.
@ -1262,9 +1289,9 @@ namespace StardewModdingAPI.Framework
}
/// <summary>Redirect messages logged directly to the console to the given monitor.</summary>
/// <param name="monitor">The monitor with which to log messages.</param>
/// <param name="gameMonitor">The monitor with which to log messages as the game.</param>
/// <param name="message">The message to log.</param>
private void HandleConsoleMessage(IMonitor monitor, string message)
private void HandleConsoleMessage(IMonitor gameMonitor, string message)
{
// detect exception
LogLevel level = message.Contains("Exception") ? LogLevel.Error : LogLevel.Trace;
@ -1273,8 +1300,19 @@ namespace StardewModdingAPI.Framework
if (level != LogLevel.Error && this.SuppressConsolePatterns.Any(p => p.IsMatch(message)))
return;
// show friendly error if applicable
foreach (var entry in this.ReplaceConsolePatterns)
{
if (entry.Item1.IsMatch(message))
{
this.Monitor.Log(entry.Item2, entry.Item3);
gameMonitor.Log(message, LogLevel.Trace);
return;
}
}
// forward to monitor
monitor.Log(message, level);
gameMonitor.Log(message, level);
}
/// <summary>Show a 'press any key to exit' message, and exit when they press a key.</summary>

View File

@ -9,7 +9,9 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#if !SMAPI_3_0_STRICT
using Microsoft.Xna.Framework.Input;
#endif
using Netcode;
using StardewModdingAPI.Enums;
using StardewModdingAPI.Events;
@ -29,7 +31,7 @@ using StardewValley.TerrainFeatures;
using StardewValley.Tools;
using xTile.Dimensions;
using xTile.Layers;
using Object = StardewValley.Object;
using SObject = StardewValley.Object;
namespace StardewModdingAPI.Framework
{
@ -70,12 +72,15 @@ namespace StardewModdingAPI.Framework
/// <summary>Whether the after-load events were raised for this session.</summary>
private bool RaisedAfterLoadEvent;
/// <summary>Whether the game is saving and SMAPI has already raised <see cref="SaveEvents.BeforeSave"/>.</summary>
/// <summary>Whether the game is saving and SMAPI has already raised <see cref="IGameLoopEvents.Saving"/>.</summary>
private bool IsBetweenSaveEvents;
/// <summary>Whether the game is creating the save file and SMAPI has already raised <see cref="SaveEvents.BeforeCreate"/>.</summary>
/// <summary>Whether the game is creating the save file and SMAPI has already raised <see cref="IGameLoopEvents.SaveCreating"/>.</summary>
private bool IsBetweenCreateEvents;
/// <summary>A callback to invoke after the content language changes.</summary>
private readonly Action OnLocaleChanged;
/// <summary>A callback to invoke after the game finishes initialising.</summary>
private readonly Action OnGameInitialised;
@ -138,9 +143,10 @@ namespace StardewModdingAPI.Framework
/// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
/// <param name="modRegistry">Tracks the installed mods.</param>
/// <param name="deprecationManager">Manages deprecation warnings.</param>
/// <param name="onLocaleChanged">A callback to invoke after the content language changes.</param>
/// <param name="onGameInitialised">A callback to invoke after the game finishes initialising.</param>
/// <param name="onGameExiting">A callback to invoke when the game exits.</param>
internal SGame(IMonitor monitor, IMonitor monitorForGame, Reflector reflection, EventManager eventManager, JsonHelper jsonHelper, ModRegistry modRegistry, DeprecationManager deprecationManager, Action onGameInitialised, Action onGameExiting)
internal SGame(IMonitor monitor, IMonitor monitorForGame, Reflector reflection, EventManager eventManager, JsonHelper jsonHelper, ModRegistry modRegistry, DeprecationManager deprecationManager, Action onLocaleChanged, Action onGameInitialised, Action onGameExiting)
{
SGame.ConstructorHack = null;
@ -158,6 +164,7 @@ namespace StardewModdingAPI.Framework
this.ModRegistry = modRegistry;
this.Reflection = reflection;
this.DeprecationManager = deprecationManager;
this.OnLocaleChanged = onLocaleChanged;
this.OnGameInitialised = onGameInitialised;
this.OnGameExiting = onGameExiting;
Game1.input = new SInputState();
@ -206,6 +213,17 @@ namespace StardewModdingAPI.Framework
this.Events.ModMessageReceived.RaiseForMods(new ModMessageReceivedEventArgs(message), mod => mod != null && modIDs.Contains(mod.Manifest.UniqueID));
}
/// <summary>A callback raised when the player quits a save and returns to the title screen.</summary>
private void OnReturnedToTitle()
{
this.Monitor.Log("Context: returned to title", LogLevel.Trace);
this.Multiplayer.Peers.Clear();
this.Events.ReturnedToTitle.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_AfterReturnToTitle.Raise();
#endif
}
/// <summary>Constructor a content manager to read XNB files.</summary>
/// <param name="serviceProvider">The service provider to use to locate services.</param>
/// <param name="rootDirectory">The root directory to search for content.</param>
@ -287,7 +305,9 @@ namespace StardewModdingAPI.Framework
this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed));
base.Update(gameTime);
this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_UnvalidatedUpdateTick.Raise();
#endif
return;
}
@ -334,7 +354,9 @@ namespace StardewModdingAPI.Framework
// This should *always* run, even when suppressing mod events, since the game uses
// this too. For example, doing this after mod event suppression would prevent the
// user from doing anything on the overnight shipping screen.
#if !SMAPI_3_0_STRICT
SInputState previousInputState = this.Input.Clone();
#endif
SInputState inputState = this.Input;
if (this.IsActive)
inputState.TrueUpdate();
@ -355,7 +377,9 @@ namespace StardewModdingAPI.Framework
this.IsBetweenCreateEvents = true;
this.Monitor.Log("Context: before save creation.", LogLevel.Trace);
this.Events.SaveCreating.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_BeforeCreateSave.Raise();
#endif
}
// raise before-save
@ -364,14 +388,18 @@ namespace StardewModdingAPI.Framework
this.IsBetweenSaveEvents = true;
this.Monitor.Log("Context: before save.", LogLevel.Trace);
this.Events.Saving.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_BeforeSave.Raise();
#endif
}
// suppress non-save events
this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed));
base.Update(gameTime);
this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_UnvalidatedUpdateTick.Raise();
#endif
return;
}
if (this.IsBetweenCreateEvents)
@ -380,7 +408,9 @@ namespace StardewModdingAPI.Framework
this.IsBetweenCreateEvents = false;
this.Monitor.Log($"Context: after save creation, starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}.", LogLevel.Trace);
this.Events.SaveCreated.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_AfterCreateSave.Raise();
#endif
}
if (this.IsBetweenSaveEvents)
{
@ -389,9 +419,10 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Context: after save, starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}.", LogLevel.Trace);
this.Events.Saved.RaiseEmpty();
this.Events.DayStarted.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_AfterSave.Raise();
this.Events.Legacy_AfterDayStarted.Raise();
#endif
}
/*********
@ -421,7 +452,11 @@ namespace StardewModdingAPI.Framework
var now = this.Watchers.LocaleWatcher.CurrentValue;
this.Monitor.Log($"Context: locale set to {now}.", LogLevel.Trace);
this.OnLocaleChanged();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_LocaleChanged.Raise(new EventArgsValueChanged<string>(was.ToString(), now.ToString()));
#endif
this.Watchers.LocaleWatcher.Reset();
}
@ -430,11 +465,7 @@ namespace StardewModdingAPI.Framework
** Load / return-to-title events
*********/
if (wasWorldReady && !Context.IsWorldReady)
{
this.Monitor.Log("Context: returned to title", LogLevel.Trace);
this.Events.ReturnedToTitle.RaiseEmpty();
this.Events.Legacy_AfterReturnToTitle.Raise();
}
this.OnReturnedToTitle();
else if (!this.RaisedAfterLoadEvent && Context.IsWorldReady)
{
// print context
@ -452,9 +483,10 @@ namespace StardewModdingAPI.Framework
this.RaisedAfterLoadEvent = true;
this.Events.SaveLoaded.RaiseEmpty();
this.Events.DayStarted.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_AfterLoad.Raise();
this.Events.Legacy_AfterDayStarted.Raise();
#endif
}
/*********
@ -473,7 +505,9 @@ namespace StardewModdingAPI.Framework
Point newSize = this.Watchers.WindowSizeWatcher.CurrentValue;
this.Events.WindowResized.Raise(new WindowResizedEventArgs(oldSize, newSize));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_Resize.Raise();
#endif
this.Watchers.WindowSizeWatcher.Reset();
}
@ -522,9 +556,10 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Events: button {button} pressed.", LogLevel.Trace);
this.Events.ButtonPressed.Raise(new ButtonPressedEventArgs(button, cursor, inputState));
this.Events.Legacy_ButtonPressed.Raise(new EventArgsInput(button, cursor, inputState.SuppressButtons));
#if !SMAPI_3_0_STRICT
// legacy events
this.Events.Legacy_ButtonPressed.Raise(new EventArgsInput(button, cursor, inputState.SuppressButtons));
if (button.TryGetKeyboard(out Keys key))
{
if (key != Keys.None)
@ -537,6 +572,7 @@ namespace StardewModdingAPI.Framework
else
this.Events.Legacy_ControllerButtonPressed.Raise(new EventArgsControllerButtonPressed(PlayerIndex.One, controllerButton));
}
#endif
}
else if (status == InputStatus.Released)
{
@ -544,9 +580,10 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Events: button {button} released.", LogLevel.Trace);
this.Events.ButtonReleased.Raise(new ButtonReleasedEventArgs(button, cursor, inputState));
this.Events.Legacy_ButtonReleased.Raise(new EventArgsInput(button, cursor, inputState.SuppressButtons));
#if !SMAPI_3_0_STRICT
// legacy events
this.Events.Legacy_ButtonReleased.Raise(new EventArgsInput(button, cursor, inputState.SuppressButtons));
if (button.TryGetKeyboard(out Keys key))
{
if (key != Keys.None)
@ -559,14 +596,17 @@ namespace StardewModdingAPI.Framework
else
this.Events.Legacy_ControllerButtonReleased.Raise(new EventArgsControllerButtonReleased(PlayerIndex.One, controllerButton));
}
#endif
}
}
#if !SMAPI_3_0_STRICT
// raise legacy state-changed events
if (inputState.RealKeyboard != previousInputState.RealKeyboard)
this.Events.Legacy_KeyboardChanged.Raise(new EventArgsKeyboardStateChanged(previousInputState.RealKeyboard, inputState.RealKeyboard));
if (inputState.RealMouse != previousInputState.RealMouse)
this.Events.Legacy_MouseChanged.Raise(new EventArgsMouseStateChanged(previousInputState.RealMouse, inputState.RealMouse, new Point((int)previousInputState.CursorPosition.ScreenPixels.X, (int)previousInputState.CursorPosition.ScreenPixels.Y), new Point((int)inputState.CursorPosition.ScreenPixels.X, (int)inputState.CursorPosition.ScreenPixels.Y)));
#endif
}
}
@ -584,10 +624,12 @@ namespace StardewModdingAPI.Framework
// raise menu events
this.Events.MenuChanged.Raise(new MenuChangedEventArgs(was, now));
#if !SMAPI_3_0_STRICT
if (now != null)
this.Events.Legacy_MenuChanged.Raise(new EventArgsClickableMenuChanged(was, now));
else
this.Events.Legacy_MenuClosed.Raise(new EventArgsClickableMenuClosed(was));
#endif
}
/*********
@ -615,7 +657,9 @@ namespace StardewModdingAPI.Framework
}
this.Events.LocationListChanged.Raise(new LocationListChangedEventArgs(added, removed));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_LocationsChanged.Raise(new EventArgsLocationsChanged(added, removed));
#endif
}
// raise location contents changed
@ -632,7 +676,9 @@ namespace StardewModdingAPI.Framework
watcher.BuildingsWatcher.Reset();
this.Events.BuildingListChanged.Raise(new BuildingListChangedEventArgs(location, added, removed));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_BuildingsChanged.Raise(new EventArgsLocationBuildingsChanged(location, added, removed));
#endif
}
// debris changed
@ -672,12 +718,14 @@ namespace StardewModdingAPI.Framework
if (watcher.ObjectsWatcher.IsChanged)
{
GameLocation location = watcher.Location;
KeyValuePair<Vector2, Object>[] added = watcher.ObjectsWatcher.Added.ToArray();
KeyValuePair<Vector2, Object>[] removed = watcher.ObjectsWatcher.Removed.ToArray();
KeyValuePair<Vector2, SObject>[] added = watcher.ObjectsWatcher.Added.ToArray();
KeyValuePair<Vector2, SObject>[] removed = watcher.ObjectsWatcher.Removed.ToArray();
watcher.ObjectsWatcher.Reset();
this.Events.ObjectListChanged.Raise(new ObjectListChangedEventArgs(location, added, removed));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_ObjectsChanged.Raise(new EventArgsLocationObjectsChanged(location, added, removed));
#endif
}
// terrain features changed
@ -707,7 +755,9 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Events: time changed from {was} to {now}.", LogLevel.Trace);
this.Events.TimeChanged.Raise(new TimeChangedEventArgs(was, now));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_TimeOfDayChanged.Raise(new EventArgsIntChanged(was, now));
#endif
}
else
this.Watchers.TimeWatcher.Reset();
@ -725,7 +775,9 @@ namespace StardewModdingAPI.Framework
GameLocation oldLocation = playerTracker.LocationWatcher.PreviousValue;
this.Events.Warped.Raise(new WarpedEventArgs(playerTracker.Player, oldLocation, newLocation));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_PlayerWarped.Raise(new EventArgsPlayerWarped(oldLocation, newLocation));
#endif
}
// raise player leveled up a skill
@ -735,7 +787,9 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Events: player skill '{pair.Key}' changed from {pair.Value.PreviousValue} to {pair.Value.CurrentValue}.", LogLevel.Trace);
this.Events.LevelChanged.Raise(new LevelChangedEventArgs(playerTracker.Player, pair.Key, pair.Value.PreviousValue, pair.Value.CurrentValue));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_LeveledUp.Raise(new EventArgsLevelUp((EventArgsLevelUp.LevelType)pair.Key, pair.Value.CurrentValue));
#endif
}
// raise player inventory changed
@ -745,7 +799,9 @@ namespace StardewModdingAPI.Framework
if (this.Monitor.IsVerbose)
this.Monitor.Log("Events: player inventory changed.", LogLevel.Trace);
this.Events.InventoryChanged.Raise(new InventoryChangedEventArgs(playerTracker.Player, changedItems));
#if !SMAPI_3_0_STRICT
this.Events.Legacy_InventoryChanged.Raise(new EventArgsInventoryChanged(Game1.player.Items, changedItems));
#endif
}
// raise mine level changed
@ -753,7 +809,9 @@ namespace StardewModdingAPI.Framework
{
if (this.Monitor.IsVerbose)
this.Monitor.Log($"Context: mine level changed to {mineLevel}.", LogLevel.Trace);
#if !SMAPI_3_0_STRICT
this.Events.Legacy_MineLevelChanged.Raise(new EventArgsMineLevelChanged(playerTracker.MineLevelWatcher.PreviousValue, mineLevel));
#endif
}
}
this.Watchers.CurrentPlayerTracker?.Reset();
@ -785,6 +843,7 @@ namespace StardewModdingAPI.Framework
/*********
** Update events
*********/
#if !SMAPI_3_0_STRICT
this.Events.Legacy_UnvalidatedUpdateTick.Raise();
if (this.TicksElapsed == 1)
this.Events.Legacy_FirstUpdateTick.Raise();
@ -801,6 +860,7 @@ namespace StardewModdingAPI.Framework
this.Events.Legacy_HalfSecondTick.Raise();
if (this.CurrentUpdateTick % 60 == 0)
this.Events.Legacy_OneSecondTick.Raise();
#endif
this.CurrentUpdateTick += 1;
if (this.CurrentUpdateTick >= 60)
this.CurrentUpdateTick = 0;
@ -890,10 +950,14 @@ namespace StardewModdingAPI.Framework
try
{
this.Events.RenderingActiveMenu.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPreRenderGuiEvent.Raise();
#endif
activeClickableMenu.draw(Game1.spriteBatch);
this.Events.RenderedActiveMenu.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPostRenderGuiEvent.Raise();
#endif
}
catch (Exception ex)
{
@ -901,7 +965,9 @@ namespace StardewModdingAPI.Framework
activeClickableMenu.exitThisMenu();
}
this.Events.Rendered.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPostRenderEvent.Raise();
#endif
Game1.spriteBatch.End();
}
@ -925,10 +991,14 @@ namespace StardewModdingAPI.Framework
{
Game1.activeClickableMenu.drawBackground(Game1.spriteBatch);
this.Events.RenderingActiveMenu.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPreRenderGuiEvent.Raise();
#endif
Game1.activeClickableMenu.draw(Game1.spriteBatch);
this.Events.RenderedActiveMenu.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPostRenderGuiEvent.Raise();
#endif
}
catch (Exception ex)
{
@ -936,7 +1006,9 @@ namespace StardewModdingAPI.Framework
Game1.activeClickableMenu.exitThisMenu();
}
this.Events.Rendered.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPostRenderEvent.Raise();
#endif
Game1.spriteBatch.End();
this.drawOverlays(Game1.spriteBatch);
if ((double)Game1.options.zoomLevel != 1.0)
@ -961,7 +1033,9 @@ namespace StardewModdingAPI.Framework
Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3686"), new Vector2(16f, 32f), new Color(0, (int)byte.MaxValue, 0));
Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.parseText(Game1.errorMessage, Game1.dialogueFont, Game1.graphics.GraphicsDevice.Viewport.Width), new Vector2(16f, 48f), Color.White);
this.Events.Rendered.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPostRenderEvent.Raise();
#endif
Game1.spriteBatch.End();
}
else if (Game1.currentMinigame != null)
@ -974,7 +1048,9 @@ namespace StardewModdingAPI.Framework
Game1.spriteBatch.End();
}
this.drawOverlays(Game1.spriteBatch);
#if !SMAPI_3_0_STRICT
this.RaisePostRender(needsNewBatch: true);
#endif
if ((double)Game1.options.zoomLevel == 1.0)
return;
this.GraphicsDevice.SetRenderTarget((RenderTarget2D)null);
@ -992,10 +1068,14 @@ namespace StardewModdingAPI.Framework
try
{
this.Events.RenderingActiveMenu.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPreRenderGuiEvent.Raise();
#endif
Game1.activeClickableMenu.draw(Game1.spriteBatch);
this.Events.RenderedActiveMenu.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPostRenderGuiEvent.Raise();
#endif
}
catch (Exception ex)
{
@ -1085,7 +1165,9 @@ namespace StardewModdingAPI.Framework
if (++batchOpens == 1)
this.Events.Rendering.RaiseEmpty();
this.Events.RenderingWorld.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPreRenderEvent.Raise();
#endif
if (Game1.background != null)
Game1.background.draw(Game1.spriteBatch);
Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch);
@ -1340,6 +1422,7 @@ namespace StardewModdingAPI.Framework
}
Game1.spriteBatch.End();
}
this.Events.RenderedWorld.RaiseEmpty();
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
if (Game1.drawGrid)
{
@ -1397,10 +1480,14 @@ namespace StardewModdingAPI.Framework
if ((Game1.displayHUD || Game1.eventUp) && (Game1.currentBillboard == 0 && Game1.gameMode == (byte)3) && (!Game1.freezeControls && !Game1.panMode && !Game1.HostPaused))
{
this.Events.RenderingHud.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPreRenderHudEvent.Raise();
#endif
this.drawHUD();
this.Events.RenderedHud.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPostRenderHudEvent.Raise();
#endif
}
else if (Game1.activeClickableMenu == null && Game1.farmEvent == null)
Game1.spriteBatch.Draw(Game1.mouseCursors, new Vector2((float)Game1.getOldMouseX(), (float)Game1.getOldMouseY()), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 0, 16, 16)), Color.White, 0.0f, Vector2.Zero, (float)(4.0 + (double)Game1.dialogueButtonScale / 150.0), SpriteEffects.None, 1f);
@ -1509,10 +1596,14 @@ namespace StardewModdingAPI.Framework
try
{
this.Events.RenderingActiveMenu.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPreRenderGuiEvent.Raise();
#endif
Game1.activeClickableMenu.draw(Game1.spriteBatch);
this.Events.RenderedActiveMenu.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPostRenderGuiEvent.Raise();
#endif
}
catch (Exception ex)
{
@ -1527,9 +1618,11 @@ namespace StardewModdingAPI.Framework
string s = Game1.content.LoadString("Strings\\StringsFromCSFiles:DayTimeMoneyBox.cs.10378");
SpriteText.drawStringWithScrollBackground(Game1.spriteBatch, s, 96, 32, "", 1f, -1);
}
this.Events.RenderedWorld.RaiseEmpty();
this.Events.Rendered.RaiseEmpty();
#if !SMAPI_3_0_STRICT
this.Events.Legacy_OnPostRenderEvent.Raise();
#endif
Game1.spriteBatch.End();
this.drawOverlays(Game1.spriteBatch);
this.renderScreenBuffer();
@ -1549,6 +1642,7 @@ namespace StardewModdingAPI.Framework
this.RaisedAfterLoadEvent = false;
}
#if !SMAPI_3_0_STRICT
/// <summary>Raise the <see cref="GraphicsEvents.OnPostRenderEvent"/> if there are any listeners.</summary>
/// <param name="needsNewBatch">Whether to create a new sprite batch.</param>
private void RaisePostRender(bool needsNewBatch = false)
@ -1562,5 +1656,6 @@ namespace StardewModdingAPI.Framework
Game1.spriteBatch.End();
}
}
#endif
}
}

View File

@ -82,6 +82,7 @@ namespace StardewModdingAPI.Framework
this.OnModMessageReceived = onModMessageReceived;
}
#if !SMAPI_3_0_STRICT
/// <summary>Handle sync messages from other players and perform other initial sync logic.</summary>
public override void UpdateEarly()
{
@ -97,6 +98,7 @@ namespace StardewModdingAPI.Framework
base.UpdateLate(forceSync);
this.EventManager.Legacy_AfterMainBroadcast.Raise();
}
#endif
/// <summary>Initialise a client before the game connects to a remote server.</summary>
/// <param name="client">The client to initialise.</param>

View File

@ -0,0 +1,83 @@
using System.Collections.Generic;
using System.Linq;
namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
{
/// <summary>A watcher which detects changes to a collection of values using a specified <see cref="IEqualityComparer{T}"/> instance.</summary>
/// <typeparam name="TValue">The value type within the collection.</typeparam>
internal class ComparableListWatcher<TValue> : BaseDisposableWatcher, ICollectionWatcher<TValue>
{
/*********
** Properties
*********/
/// <summary>The collection to watch.</summary>
private readonly ICollection<TValue> CurrentValues;
/// <summary>The values during the previous update.</summary>
private HashSet<TValue> LastValues;
/// <summary>The pairs added since the last reset.</summary>
private readonly List<TValue> AddedImpl = new List<TValue>();
/// <summary>The pairs removed since the last reset.</summary>
private readonly List<TValue> RemovedImpl = new List<TValue>();
/*********
** Accessors
*********/
/// <summary>Whether the value changed since the last reset.</summary>
public bool IsChanged => this.AddedImpl.Count > 0 || this.RemovedImpl.Count > 0;
/// <summary>The values added since the last reset.</summary>
public IEnumerable<TValue> Added => this.AddedImpl;
/// <summary>The values removed since the last reset.</summary>
public IEnumerable<TValue> Removed => this.RemovedImpl;
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="values">The collection to watch.</param>
/// <param name="comparer">The equality comparer which indicates whether two values are the same.</param>
public ComparableListWatcher(ICollection<TValue> values, IEqualityComparer<TValue> comparer)
{
this.CurrentValues = values;
this.LastValues = new HashSet<TValue>(comparer);
}
/// <summary>Update the current value if needed.</summary>
public void Update()
{
this.AssertNotDisposed();
// optimise for zero items
if (this.CurrentValues.Count == 0)
{
if (this.LastValues.Count > 0)
{
this.AddedImpl.AddRange(this.LastValues);
this.LastValues.Clear();
}
return;
}
// detect changes
HashSet<TValue> curValues = new HashSet<TValue>(this.CurrentValues, this.LastValues.Comparer);
this.RemovedImpl.AddRange(from value in this.LastValues where !curValues.Contains(value) select value);
this.AddedImpl.AddRange(from value in curValues where !this.LastValues.Contains(value) select value);
this.LastValues = curValues;
}
/// <summary>Set the current value as the baseline.</summary>
public void Reset()
{
this.AssertNotDisposed();
this.AddedImpl.Clear();
this.RemovedImpl.Clear();
}
}
}

View File

@ -4,26 +4,27 @@ using System.Collections.Generic;
namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
{
/// <summary>A watcher which detects changes to a value using a specified <see cref="IEqualityComparer{T}"/> instance.</summary>
internal class ComparableWatcher<T> : IValueWatcher<T>
/// <typeparam name="TValue">The comparable value type.</typeparam>
internal class ComparableWatcher<TValue> : IValueWatcher<TValue>
{
/*********
** Properties
*********/
/// <summary>Get the current value.</summary>
private readonly Func<T> GetValue;
private readonly Func<TValue> GetValue;
/// <summary>The equality comparer.</summary>
private readonly IEqualityComparer<T> Comparer;
private readonly IEqualityComparer<TValue> Comparer;
/*********
** Accessors
*********/
/// <summary>The field value at the last reset.</summary>
public T PreviousValue { get; private set; }
public TValue PreviousValue { get; private set; }
/// <summary>The latest value.</summary>
public T CurrentValue { get; private set; }
public TValue CurrentValue { get; private set; }
/// <summary>Whether the value changed since the last reset.</summary>
public bool IsChanged { get; private set; }
@ -35,7 +36,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
/// <summary>Construct an instance.</summary>
/// <param name="getValue">Get the current value.</param>
/// <param name="comparer">The equality comparer which indicates whether two values are the same.</param>
public ComparableWatcher(Func<T> getValue, IEqualityComparer<T> comparer)
public ComparableWatcher(Func<TValue> getValue, IEqualityComparer<TValue> comparer)
{
this.GetValue = getValue;
this.Comparer = comparer;

View File

@ -4,6 +4,7 @@ using Netcode;
namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
{
/// <summary>A watcher which detects changes to a Netcode collection.</summary>
/// <typeparam name="TValue">The value type within the collection.</typeparam>
internal class NetCollectionWatcher<TValue> : BaseDisposableWatcher, ICollectionWatcher<TValue>
where TValue : class, INetObject<INetSerializable>
{
@ -16,7 +17,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
/// <summary>The pairs added since the last reset.</summary>
private readonly List<TValue> AddedImpl = new List<TValue>();
/// <summary>The pairs demoved since the last reset.</summary>
/// <summary>The pairs removed since the last reset.</summary>
private readonly List<TValue> RemovedImpl = new List<TValue>();

View File

@ -20,7 +20,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
/// <summary>The pairs added since the last reset.</summary>
private readonly IDictionary<TKey, TValue> PairsAdded = new Dictionary<TKey, TValue>();
/// <summary>The pairs demoved since the last reset.</summary>
/// <summary>The pairs removed since the last reset.</summary>
private readonly IDictionary<TKey, TValue> PairsRemoved = new Dictionary<TKey, TValue>();
/// <summary>The field being watched.</summary>

View File

@ -3,13 +3,15 @@ using Netcode;
namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
{
/// <summary>A watcher which detects changes to a net value field.</summary>
internal class NetValueWatcher<T, TSelf> : BaseDisposableWatcher, IValueWatcher<T> where TSelf : NetFieldBase<T, TSelf>
/// <typeparam name="TValue">The value type wrapped by the net field.</typeparam>
/// <typeparam name="TNetField">The net field type.</typeparam>
internal class NetValueWatcher<TValue, TNetField> : BaseDisposableWatcher, IValueWatcher<TValue> where TNetField : NetFieldBase<TValue, TNetField>
{
/*********
** Properties
*********/
/// <summary>The field being watched.</summary>
private readonly NetFieldBase<T, TSelf> Field;
private readonly NetFieldBase<TValue, TNetField> Field;
/*********
@ -19,10 +21,10 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
public bool IsChanged { get; private set; }
/// <summary>The field value at the last reset.</summary>
public T PreviousValue { get; private set; }
public TValue PreviousValue { get; private set; }
/// <summary>The latest value.</summary>
public T CurrentValue { get; private set; }
public TValue CurrentValue { get; private set; }
/*********
@ -30,7 +32,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
*********/
/// <summary>Construct an instance.</summary>
/// <param name="field">The field to watch.</param>
public NetValueWatcher(NetFieldBase<T, TSelf> field)
public NetValueWatcher(NetFieldBase<TValue, TNetField> field)
{
this.Field = field;
this.PreviousValue = field.Value;
@ -74,7 +76,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
/// <param name="field">The field being watched.</param>
/// <param name="oldValue">The old field value.</param>
/// <param name="newValue">The new field value.</param>
private void OnValueChanged(TSelf field, T oldValue, T newValue)
private void OnValueChanged(TNetField field, TValue oldValue, TValue newValue)
{
this.CurrentValue = newValue;
this.IsChanged = true;

View File

@ -6,6 +6,7 @@ using System.Linq;
namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
{
/// <summary>A watcher which detects changes to an observable collection.</summary>
/// <typeparam name="TValue">The value type within the collection.</typeparam>
internal class ObservableCollectionWatcher<TValue> : BaseDisposableWatcher, ICollectionWatcher<TValue>
{
/*********
@ -17,7 +18,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers
/// <summary>The pairs added since the last reset.</summary>
private readonly List<TValue> AddedImpl = new List<TValue>();
/// <summary>The pairs demoved since the last reset.</summary>
/// <summary>The pairs removed since the last reset.</summary>
private readonly List<TValue> RemovedImpl = new List<TValue>();

Some files were not shown because too many files have changed in this diff Show More