add public platform constant for mods

This commit is contained in:
Jesse Plamondon-Willard 2018-05-01 19:15:56 -04:00
parent 009a387526
commit b1a24452ee
7 changed files with 27 additions and 5 deletions

View File

@ -11,6 +11,7 @@
* For modders:
* Added code analysis to mod build config package to flag common issues as warnings.
* Added `Context.IsMultiplayer` and `Context.IsMainPlayer` flags.
* Added `Constants.TargetPlatform` which says whether the game is running on Linux, Mac, or Windows.
* Fixed assets loaded by temporary content managers not being editable by mods.
* Fixed assets not reloaded consistently when the player switches language.
* Fixed console command input not saved to the log.

View File

@ -46,6 +46,9 @@ namespace StardewModdingAPI
/// <summary>The maximum supported version of Stardew Valley.</summary>
public static ISemanticVersion MaximumGameVersion { get; } = null;
/// <summary>The target game platform.</summary>
public static GamePlatform TargetPlatform => (GamePlatform)Constants.Platform;
/// <summary>The path to the game folder.</summary>
public static string ExecutionPath { get; } = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
@ -92,7 +95,7 @@ namespace StardewModdingAPI
internal static ISemanticVersion GameVersion { get; } = new GameVersion(Constants.GetGameVersion());
/// <summary>The target game platform.</summary>
internal static Platform TargetPlatform { get; } = EnvironmentUtility.DetectPlatform();
internal static Platform Platform { get; } = EnvironmentUtility.DetectPlatform();
/*********

View File

@ -53,7 +53,7 @@ namespace StardewModdingAPI.Framework.Content
this.Cache = reflection.GetField<Dictionary<string, object>>(contentManager, "loadedAssets").GetValue();
// get key normalisation logic
if (Constants.TargetPlatform == Platform.Windows)
if (Constants.Platform == Platform.Windows)
{
IReflectedMethod method = reflection.GetMethod(typeof(TitleContainer), "GetCleanPath");
this.NormaliseAssetNameForPlatform = path => method.Invoke<string>(path);

View File

@ -167,7 +167,7 @@ namespace StardewModdingAPI.Framework
// auto detect color scheme
if (colorScheme == MonitorColorScheme.AutoDetect)
{
if (Constants.TargetPlatform == Platform.Mac)
if (Constants.Platform == Platform.Mac)
colorScheme = MonitorColorScheme.LightBackground; // MacOS doesn't provide console background color info, but it's usually white.
else
colorScheme = Monitor.IsDark(Console.BackgroundColor) ? MonitorColorScheme.DarkBackground : MonitorColorScheme.LightBackground;

17
src/SMAPI/GamePlatform.cs Normal file
View File

@ -0,0 +1,17 @@
using StardewModdingAPI.Internal;
namespace StardewModdingAPI
{
/// <summary>The game's platform version.</summary>
public enum GamePlatform
{
/// <summary>The Linux version of the game.</summary>
Linux = Platform.Linux,
/// <summary>The Mac version of the game.</summary>
Mac = Platform.Mac,
/// <summary>The Windows version of the game.</summary>
Windows = Platform.Windows
}
}

View File

@ -172,7 +172,7 @@ namespace StardewModdingAPI
try
{
// init logging
this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {EnvironmentUtility.GetFriendlyPlatformName(Constants.TargetPlatform)}", LogLevel.Info);
this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform)}", LogLevel.Info);
this.Monitor.Log($"Mods go here: {Constants.ModPath}");
this.Monitor.Log($"Log started at {DateTime.UtcNow:s} UTC", LogLevel.Trace);
@ -741,7 +741,7 @@ namespace StardewModdingAPI
);
// get assembly loaders
AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.TargetPlatform, this.Monitor, this.Settings.DeveloperMode);
AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.DeveloperMode);
AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => modAssemblyLoader.ResolveAssembly(e.Name);
InterfaceProxyFactory proxyFactory = new InterfaceProxyFactory();

View File

@ -262,6 +262,7 @@
<Compile Include="Metadata\InstructionMetadata.cs" />
<Compile Include="Mod.cs" />
<Compile Include="PatchMode.cs" />
<Compile Include="GamePlatform.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Framework\SGame.cs" />