From 929dccb75a1405737975d76648e015a3e7c00177 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 7 Oct 2017 23:07:10 -0400 Subject: reorganise repo structure --- src/SMAPI/App.config | 9 + src/SMAPI/Constants.cs | 169 ++ src/SMAPI/ContentSource.cs | 12 + src/SMAPI/Context.cs | 37 + src/SMAPI/Events/ChangeType.cs | 15 + src/SMAPI/Events/ContentEvents.cs | 29 + src/SMAPI/Events/ControlEvents.cs | 112 ++ src/SMAPI/Events/EventArgsClickableMenuChanged.cs | 31 + src/SMAPI/Events/EventArgsClickableMenuClosed.cs | 26 + .../Events/EventArgsControllerButtonPressed.cs | 32 + .../Events/EventArgsControllerButtonReleased.cs | 32 + .../Events/EventArgsControllerTriggerPressed.cs | 37 + .../Events/EventArgsControllerTriggerReleased.cs | 37 + .../Events/EventArgsCurrentLocationChanged.cs | 31 + src/SMAPI/Events/EventArgsGameLocationsChanged.cs | 27 + src/SMAPI/Events/EventArgsInput.cs | 124 ++ src/SMAPI/Events/EventArgsIntChanged.cs | 29 + src/SMAPI/Events/EventArgsInventoryChanged.cs | 41 + src/SMAPI/Events/EventArgsKeyPressed.cs | 26 + src/SMAPI/Events/EventArgsKeyboardStateChanged.cs | 31 + src/SMAPI/Events/EventArgsLevelUp.cs | 52 + .../Events/EventArgsLocationObjectsChanged.cs | 28 + src/SMAPI/Events/EventArgsMineLevelChanged.cs | 30 + src/SMAPI/Events/EventArgsMouseStateChanged.cs | 42 + src/SMAPI/Events/EventArgsValueChanged.cs | 31 + src/SMAPI/Events/GameEvents.cs | 96 + src/SMAPI/Events/GraphicsEvents.cs | 116 ++ src/SMAPI/Events/InputEvents.cs | 43 + src/SMAPI/Events/ItemStackChange.cs | 20 + src/SMAPI/Events/LocationEvents.cs | 54 + src/SMAPI/Events/MenuEvents.cs | 40 + src/SMAPI/Events/MineEvents.cs | 28 + src/SMAPI/Events/PlayerEvents.cs | 43 + src/SMAPI/Events/SaveEvents.cs | 56 + src/SMAPI/Events/TimeEvents.cs | 37 + src/SMAPI/Framework/Command.cs | 40 + src/SMAPI/Framework/CommandManager.cs | 116 ++ src/SMAPI/Framework/Content/AssetData.cs | 44 + .../Framework/Content/AssetDataForDictionary.cs | 45 + src/SMAPI/Framework/Content/AssetDataForImage.cs | 70 + src/SMAPI/Framework/Content/AssetDataForObject.cs | 54 + src/SMAPI/Framework/Content/AssetInfo.cs | 82 + src/SMAPI/Framework/ContentManagerShim.cs | 50 + src/SMAPI/Framework/CursorPosition.cs | 35 + src/SMAPI/Framework/DeprecationLevel.cs | 15 + src/SMAPI/Framework/DeprecationManager.cs | 105 + .../Exceptions/SAssemblyLoadFailedException.cs | 16 + .../Framework/Exceptions/SContentLoadException.cs | 18 + src/SMAPI/Framework/Exceptions/SParseException.cs | 17 + src/SMAPI/Framework/GameVersion.cs | 68 + src/SMAPI/Framework/IModMetadata.cs | 47 + src/SMAPI/Framework/InternalExtensions.cs | 131 ++ .../Logging/ConsoleInterceptionManager.cs | 86 + .../Framework/Logging/InterceptingTextWriter.cs | 63 + src/SMAPI/Framework/Logging/LogFileManager.cs | 57 + src/SMAPI/Framework/ModHelpers/BaseHelper.cs | 23 + src/SMAPI/Framework/ModHelpers/CommandHelper.cs | 54 + src/SMAPI/Framework/ModHelpers/ContentHelper.cs | 476 +++++ src/SMAPI/Framework/ModHelpers/ModHelper.cs | 129 ++ .../Framework/ModHelpers/ModRegistryHelper.cs | 48 + src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs | 200 ++ .../Framework/ModHelpers/TranslationHelper.cs | 140 ++ .../ModLoading/AssemblyDefinitionResolver.cs | 61 + .../Framework/ModLoading/AssemblyLoadStatus.cs | 15 + src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 333 ++++ .../Framework/ModLoading/AssemblyParseResult.cs | 36 + .../Framework/ModLoading/Finders/EventFinder.cs | 82 + .../Framework/ModLoading/Finders/FieldFinder.cs | 82 + .../Framework/ModLoading/Finders/MethodFinder.cs | 82 + .../Framework/ModLoading/Finders/PropertyFinder.cs | 82 + .../Framework/ModLoading/Finders/TypeFinder.cs | 133 ++ .../Framework/ModLoading/IInstructionHandler.cs | 34 + .../ModLoading/IncompatibleInstructionException.cs | 35 + .../ModLoading/InstructionHandleResult.cs | 24 + .../ModLoading/InvalidModStateException.cs | 14 + .../Framework/ModLoading/ModDependencyStatus.cs | 18 + src/SMAPI/Framework/ModLoading/ModMetadata.cs | 68 + .../Framework/ModLoading/ModMetadataStatus.cs | 12 + src/SMAPI/Framework/ModLoading/ModResolver.cs | 366 ++++ src/SMAPI/Framework/ModLoading/Platform.cs | 12 + .../Framework/ModLoading/PlatformAssemblyMap.cs | 55 + src/SMAPI/Framework/ModLoading/RewriteHelper.cs | 94 + .../ModLoading/Rewriters/FieldReplaceRewriter.cs | 50 + .../Rewriters/FieldToPropertyRewriter.cs | 51 + .../ModLoading/Rewriters/MethodParentRewriter.cs | 88 + .../ModLoading/Rewriters/TypeReferenceRewriter.cs | 154 ++ .../Rewriters/VirtualEntryCallRemover.cs | 90 + src/SMAPI/Framework/ModRegistry.cs | 113 ++ src/SMAPI/Framework/Models/Manifest.cs | 47 + src/SMAPI/Framework/Models/ManifestDependency.cs | 34 + src/SMAPI/Framework/Models/ModCompatibility.cs | 55 + src/SMAPI/Framework/Models/ModDataID.cs | 85 + src/SMAPI/Framework/Models/ModDataRecord.cs | 63 + src/SMAPI/Framework/Models/ModStatus.cs | 18 + src/SMAPI/Framework/Models/SConfig.cs | 27 + src/SMAPI/Framework/Monitor.cs | 194 ++ src/SMAPI/Framework/Reflection/CacheEntry.cs | 30 + src/SMAPI/Framework/Reflection/PrivateField.cs | 93 + src/SMAPI/Framework/Reflection/PrivateMethod.cs | 99 + src/SMAPI/Framework/Reflection/PrivateProperty.cs | 93 + src/SMAPI/Framework/Reflection/Reflector.cs | 276 +++ src/SMAPI/Framework/RequestExitDelegate.cs | 7 + src/SMAPI/Framework/SContentManager.cs | 531 +++++ src/SMAPI/Framework/SGame.cs | 1403 +++++++++++++ src/SMAPI/Framework/Serialisation/JsonHelper.cs | 96 + .../Framework/Serialisation/SFieldConverter.cs | 121 ++ .../Serialisation/SelectiveStringEnumConverter.cs | 37 + src/SMAPI/Framework/Utilities/ContextHash.cs | 61 + src/SMAPI/Framework/Utilities/Countdown.cs | 44 + src/SMAPI/Framework/WebApiClient.cs | 73 + src/SMAPI/IAssetData.cs | 47 + src/SMAPI/IAssetDataForDictionary.cs | 26 + src/SMAPI/IAssetDataForImage.cs | 23 + src/SMAPI/IAssetEditor.cs | 17 + src/SMAPI/IAssetInfo.cs | 28 + src/SMAPI/IAssetLoader.cs | 17 + src/SMAPI/ICommandHelper.cs | 26 + src/SMAPI/IContentHelper.cs | 56 + src/SMAPI/ICursorPosition.cs | 17 + src/SMAPI/IManifest.cs | 41 + src/SMAPI/IManifestDependency.cs | 18 + src/SMAPI/IMod.cs | 26 + src/SMAPI/IModHelper.cs | 58 + src/SMAPI/IModLinked.cs | 12 + src/SMAPI/IModRegistry.cs | 20 + src/SMAPI/IMonitor.cs | 25 + src/SMAPI/IPrivateField.cs | 26 + src/SMAPI/IPrivateMethod.cs | 27 + src/SMAPI/IPrivateProperty.cs | 26 + src/SMAPI/IReflectionHelper.cs | 67 + src/SMAPI/ISemanticVersion.cs | 59 + src/SMAPI/ITranslationHelper.cs | 34 + src/SMAPI/LogLevel.cs | 24 + src/SMAPI/Metadata/CoreAssets.cs | 166 ++ src/SMAPI/Metadata/InstructionMetadata.cs | 101 + src/SMAPI/Mod.cs | 50 + src/SMAPI/PatchMode.cs | 12 + src/SMAPI/Program.cs | 966 +++++++++ src/SMAPI/Properties/AssemblyInfo.cs | 9 + src/SMAPI/SemanticVersion.cs | 237 +++ src/SMAPI/StardewModdingAPI.config.json | 2063 ++++++++++++++++++++ src/SMAPI/StardewModdingAPI.csproj | 277 +++ src/SMAPI/Translation.cs | 154 ++ src/SMAPI/Utilities/SButton.cs | 675 +++++++ src/SMAPI/Utilities/SDate.cs | 232 +++ src/SMAPI/icon.ico | Bin 0 -> 15086 bytes src/SMAPI/packages.config | 5 + src/SMAPI/steam_appid.txt | 1 + src/SMAPI/unix-launcher.sh | 88 + 149 files changed, 15259 insertions(+) create mode 100644 src/SMAPI/App.config create mode 100644 src/SMAPI/Constants.cs create mode 100644 src/SMAPI/ContentSource.cs create mode 100644 src/SMAPI/Context.cs create mode 100644 src/SMAPI/Events/ChangeType.cs create mode 100644 src/SMAPI/Events/ContentEvents.cs create mode 100644 src/SMAPI/Events/ControlEvents.cs create mode 100644 src/SMAPI/Events/EventArgsClickableMenuChanged.cs create mode 100644 src/SMAPI/Events/EventArgsClickableMenuClosed.cs create mode 100644 src/SMAPI/Events/EventArgsControllerButtonPressed.cs create mode 100644 src/SMAPI/Events/EventArgsControllerButtonReleased.cs create mode 100644 src/SMAPI/Events/EventArgsControllerTriggerPressed.cs create mode 100644 src/SMAPI/Events/EventArgsControllerTriggerReleased.cs create mode 100644 src/SMAPI/Events/EventArgsCurrentLocationChanged.cs create mode 100644 src/SMAPI/Events/EventArgsGameLocationsChanged.cs create mode 100644 src/SMAPI/Events/EventArgsInput.cs create mode 100644 src/SMAPI/Events/EventArgsIntChanged.cs create mode 100644 src/SMAPI/Events/EventArgsInventoryChanged.cs create mode 100644 src/SMAPI/Events/EventArgsKeyPressed.cs create mode 100644 src/SMAPI/Events/EventArgsKeyboardStateChanged.cs create mode 100644 src/SMAPI/Events/EventArgsLevelUp.cs create mode 100644 src/SMAPI/Events/EventArgsLocationObjectsChanged.cs create mode 100644 src/SMAPI/Events/EventArgsMineLevelChanged.cs create mode 100644 src/SMAPI/Events/EventArgsMouseStateChanged.cs create mode 100644 src/SMAPI/Events/EventArgsValueChanged.cs create mode 100644 src/SMAPI/Events/GameEvents.cs create mode 100644 src/SMAPI/Events/GraphicsEvents.cs create mode 100644 src/SMAPI/Events/InputEvents.cs create mode 100644 src/SMAPI/Events/ItemStackChange.cs create mode 100644 src/SMAPI/Events/LocationEvents.cs create mode 100644 src/SMAPI/Events/MenuEvents.cs create mode 100644 src/SMAPI/Events/MineEvents.cs create mode 100644 src/SMAPI/Events/PlayerEvents.cs create mode 100644 src/SMAPI/Events/SaveEvents.cs create mode 100644 src/SMAPI/Events/TimeEvents.cs create mode 100644 src/SMAPI/Framework/Command.cs create mode 100644 src/SMAPI/Framework/CommandManager.cs create mode 100644 src/SMAPI/Framework/Content/AssetData.cs create mode 100644 src/SMAPI/Framework/Content/AssetDataForDictionary.cs create mode 100644 src/SMAPI/Framework/Content/AssetDataForImage.cs create mode 100644 src/SMAPI/Framework/Content/AssetDataForObject.cs create mode 100644 src/SMAPI/Framework/Content/AssetInfo.cs create mode 100644 src/SMAPI/Framework/ContentManagerShim.cs create mode 100644 src/SMAPI/Framework/CursorPosition.cs create mode 100644 src/SMAPI/Framework/DeprecationLevel.cs create mode 100644 src/SMAPI/Framework/DeprecationManager.cs create mode 100644 src/SMAPI/Framework/Exceptions/SAssemblyLoadFailedException.cs create mode 100644 src/SMAPI/Framework/Exceptions/SContentLoadException.cs create mode 100644 src/SMAPI/Framework/Exceptions/SParseException.cs create mode 100644 src/SMAPI/Framework/GameVersion.cs create mode 100644 src/SMAPI/Framework/IModMetadata.cs create mode 100644 src/SMAPI/Framework/InternalExtensions.cs create mode 100644 src/SMAPI/Framework/Logging/ConsoleInterceptionManager.cs create mode 100644 src/SMAPI/Framework/Logging/InterceptingTextWriter.cs create mode 100644 src/SMAPI/Framework/Logging/LogFileManager.cs create mode 100644 src/SMAPI/Framework/ModHelpers/BaseHelper.cs create mode 100644 src/SMAPI/Framework/ModHelpers/CommandHelper.cs create mode 100644 src/SMAPI/Framework/ModHelpers/ContentHelper.cs create mode 100644 src/SMAPI/Framework/ModHelpers/ModHelper.cs create mode 100644 src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs create mode 100644 src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs create mode 100644 src/SMAPI/Framework/ModHelpers/TranslationHelper.cs create mode 100644 src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs create mode 100644 src/SMAPI/Framework/ModLoading/AssemblyLoadStatus.cs create mode 100644 src/SMAPI/Framework/ModLoading/AssemblyLoader.cs create mode 100644 src/SMAPI/Framework/ModLoading/AssemblyParseResult.cs create mode 100644 src/SMAPI/Framework/ModLoading/Finders/EventFinder.cs create mode 100644 src/SMAPI/Framework/ModLoading/Finders/FieldFinder.cs create mode 100644 src/SMAPI/Framework/ModLoading/Finders/MethodFinder.cs create mode 100644 src/SMAPI/Framework/ModLoading/Finders/PropertyFinder.cs create mode 100644 src/SMAPI/Framework/ModLoading/Finders/TypeFinder.cs create mode 100644 src/SMAPI/Framework/ModLoading/IInstructionHandler.cs create mode 100644 src/SMAPI/Framework/ModLoading/IncompatibleInstructionException.cs create mode 100644 src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs create mode 100644 src/SMAPI/Framework/ModLoading/InvalidModStateException.cs create mode 100644 src/SMAPI/Framework/ModLoading/ModDependencyStatus.cs create mode 100644 src/SMAPI/Framework/ModLoading/ModMetadata.cs create mode 100644 src/SMAPI/Framework/ModLoading/ModMetadataStatus.cs create mode 100644 src/SMAPI/Framework/ModLoading/ModResolver.cs create mode 100644 src/SMAPI/Framework/ModLoading/Platform.cs create mode 100644 src/SMAPI/Framework/ModLoading/PlatformAssemblyMap.cs create mode 100644 src/SMAPI/Framework/ModLoading/RewriteHelper.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/FieldReplaceRewriter.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/MethodParentRewriter.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/TypeReferenceRewriter.cs create mode 100644 src/SMAPI/Framework/ModLoading/Rewriters/VirtualEntryCallRemover.cs create mode 100644 src/SMAPI/Framework/ModRegistry.cs create mode 100644 src/SMAPI/Framework/Models/Manifest.cs create mode 100644 src/SMAPI/Framework/Models/ManifestDependency.cs create mode 100644 src/SMAPI/Framework/Models/ModCompatibility.cs create mode 100644 src/SMAPI/Framework/Models/ModDataID.cs create mode 100644 src/SMAPI/Framework/Models/ModDataRecord.cs create mode 100644 src/SMAPI/Framework/Models/ModStatus.cs create mode 100644 src/SMAPI/Framework/Models/SConfig.cs create mode 100644 src/SMAPI/Framework/Monitor.cs create mode 100644 src/SMAPI/Framework/Reflection/CacheEntry.cs create mode 100644 src/SMAPI/Framework/Reflection/PrivateField.cs create mode 100644 src/SMAPI/Framework/Reflection/PrivateMethod.cs create mode 100644 src/SMAPI/Framework/Reflection/PrivateProperty.cs create mode 100644 src/SMAPI/Framework/Reflection/Reflector.cs create mode 100644 src/SMAPI/Framework/RequestExitDelegate.cs create mode 100644 src/SMAPI/Framework/SContentManager.cs create mode 100644 src/SMAPI/Framework/SGame.cs create mode 100644 src/SMAPI/Framework/Serialisation/JsonHelper.cs create mode 100644 src/SMAPI/Framework/Serialisation/SFieldConverter.cs create mode 100644 src/SMAPI/Framework/Serialisation/SelectiveStringEnumConverter.cs create mode 100644 src/SMAPI/Framework/Utilities/ContextHash.cs create mode 100644 src/SMAPI/Framework/Utilities/Countdown.cs create mode 100644 src/SMAPI/Framework/WebApiClient.cs create mode 100644 src/SMAPI/IAssetData.cs create mode 100644 src/SMAPI/IAssetDataForDictionary.cs create mode 100644 src/SMAPI/IAssetDataForImage.cs create mode 100644 src/SMAPI/IAssetEditor.cs create mode 100644 src/SMAPI/IAssetInfo.cs create mode 100644 src/SMAPI/IAssetLoader.cs create mode 100644 src/SMAPI/ICommandHelper.cs create mode 100644 src/SMAPI/IContentHelper.cs create mode 100644 src/SMAPI/ICursorPosition.cs create mode 100644 src/SMAPI/IManifest.cs create mode 100644 src/SMAPI/IManifestDependency.cs create mode 100644 src/SMAPI/IMod.cs create mode 100644 src/SMAPI/IModHelper.cs create mode 100644 src/SMAPI/IModLinked.cs create mode 100644 src/SMAPI/IModRegistry.cs create mode 100644 src/SMAPI/IMonitor.cs create mode 100644 src/SMAPI/IPrivateField.cs create mode 100644 src/SMAPI/IPrivateMethod.cs create mode 100644 src/SMAPI/IPrivateProperty.cs create mode 100644 src/SMAPI/IReflectionHelper.cs create mode 100644 src/SMAPI/ISemanticVersion.cs create mode 100644 src/SMAPI/ITranslationHelper.cs create mode 100644 src/SMAPI/LogLevel.cs create mode 100644 src/SMAPI/Metadata/CoreAssets.cs create mode 100644 src/SMAPI/Metadata/InstructionMetadata.cs create mode 100644 src/SMAPI/Mod.cs create mode 100644 src/SMAPI/PatchMode.cs create mode 100644 src/SMAPI/Program.cs create mode 100644 src/SMAPI/Properties/AssemblyInfo.cs create mode 100644 src/SMAPI/SemanticVersion.cs create mode 100644 src/SMAPI/StardewModdingAPI.config.json create mode 100644 src/SMAPI/StardewModdingAPI.csproj create mode 100644 src/SMAPI/Translation.cs create mode 100644 src/SMAPI/Utilities/SButton.cs create mode 100644 src/SMAPI/Utilities/SDate.cs create mode 100644 src/SMAPI/icon.ico create mode 100644 src/SMAPI/packages.config create mode 100644 src/SMAPI/steam_appid.txt create mode 100644 src/SMAPI/unix-launcher.sh (limited to 'src/SMAPI') diff --git a/src/SMAPI/App.config b/src/SMAPI/App.config new file mode 100644 index 00000000..27cdf0f7 --- /dev/null +++ b/src/SMAPI/App.config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs new file mode 100644 index 00000000..4d0a9ca9 --- /dev/null +++ b/src/SMAPI/Constants.cs @@ -0,0 +1,169 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using StardewModdingAPI.Framework; +using StardewModdingAPI.Framework.ModLoading; +using StardewValley; + +namespace StardewModdingAPI +{ + /// Contains SMAPI's constants and assumptions. + public static class Constants + { + /********* + ** Properties + *********/ + /// The directory path containing the current save's data (if a save is loaded). + private static string RawSavePath => Context.IsSaveLoaded ? Path.Combine(Constants.SavesPath, Constants.GetSaveFolderName()) : null; + + /// Whether the directory containing the current save's data exists on disk. + private static bool SavePathReady => Context.IsSaveLoaded && Directory.Exists(Constants.RawSavePath); + + + /********* + ** Accessors + *********/ + /**** + ** Public + ****/ + /// SMAPI's current semantic version. + public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(2, 0, 0, "beta.1"); + + /// The minimum supported version of Stardew Valley. + public static ISemanticVersion MinimumGameVersion { get; } = new SemanticVersion("1.2.30"); + + /// The maximum supported version of Stardew Valley. + public static ISemanticVersion MaximumGameVersion { get; } = null; + + /// The path to the game folder. + public static string ExecutionPath { get; } = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + + /// The directory path containing Stardew Valley's app data. + public static string DataPath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley"); + + /// The directory path in which error logs should be stored. + public static string LogDir { get; } = Path.Combine(Constants.DataPath, "ErrorLogs"); + + /// The directory path where all saves are stored. + public static string SavesPath { get; } = Path.Combine(Constants.DataPath, "Saves"); + + /// The directory name containing the current save's data (if a save is loaded and the directory exists). + public static string SaveFolderName => Context.IsSaveLoaded ? Constants.GetSaveFolderName() : ""; + + /// The directory path containing the current save's data (if a save is loaded and the directory exists). + public static string CurrentSavePath => Constants.SavePathReady ? Path.Combine(Constants.SavesPath, Constants.GetSaveFolderName()) : ""; + + /**** + ** Internal + ****/ + /// The GitHub repository to check for updates. + internal const string GitHubRepository = "Pathoschild/SMAPI"; + + /// The file path for the SMAPI configuration file. + internal static string ApiConfigPath => Path.Combine(Constants.ExecutionPath, $"{typeof(Program).Assembly.GetName().Name}.config.json"); + + /// The file path to the log where the latest output should be saved. + internal static string DefaultLogPath => Path.Combine(Constants.LogDir, "SMAPI-latest.txt"); + + /// A copy of the log leading up to the previous fatal crash, if any. + internal static string FatalCrashLog => Path.Combine(Constants.LogDir, "SMAPI-crash.txt"); + + /// The file path which stores a fatal crash message for the next run. + internal static string FatalCrashMarker => Path.Combine(Constants.ExecutionPath, "StardewModdingAPI.crash.marker"); + + /// The full path to the folder containing mods. + internal static string ModPath { get; } = Path.Combine(Constants.ExecutionPath, "Mods"); + + /// The game's current semantic version. + internal static ISemanticVersion GameVersion { get; } = new GameVersion(Constants.GetGameVersion()); + + /// The target game platform. + internal static Platform TargetPlatform { get; } = +#if SMAPI_FOR_WINDOWS + Platform.Windows; +#else + Platform.Mono; +#endif + + /// Maps vendor keys (like Nexus) to their mod URL template (where {0} is the mod ID) during mod compatibility checks. This doesn't affect update checks, which defer to the remote web API. + internal static readonly IDictionary VendorModUrls = new Dictionary(StringComparer.InvariantCultureIgnoreCase) + { + ["Chucklefish"] = "https://community.playstarbound.com/resources/{0}", + ["Nexus"] = "http://nexusmods.com/stardewvalley/mods/{0}", + ["GitHub"] = "https://github.com/{0}/releases" + }; + + + /********* + ** Internal methods + *********/ + /// Get metadata for mapping assemblies to the current platform. + /// The target game platform. + internal static PlatformAssemblyMap GetAssemblyMap(Platform targetPlatform) + { + // get assembly changes needed for platform + string[] removeAssemblyReferences; + Assembly[] targetAssemblies; + switch (targetPlatform) + { + case Platform.Mono: + removeAssemblyReferences = new[] + { + "Stardew Valley", + "Microsoft.Xna.Framework", + "Microsoft.Xna.Framework.Game", + "Microsoft.Xna.Framework.Graphics" + }; + targetAssemblies = new[] + { + typeof(StardewValley.Game1).Assembly, + typeof(Microsoft.Xna.Framework.Vector2).Assembly + }; + break; + + case Platform.Windows: + removeAssemblyReferences = new[] + { + "StardewValley", + "MonoGame.Framework" + }; + targetAssemblies = new[] + { + typeof(StardewValley.Game1).Assembly, + typeof(Microsoft.Xna.Framework.Vector2).Assembly, + typeof(Microsoft.Xna.Framework.Game).Assembly, + typeof(Microsoft.Xna.Framework.Graphics.SpriteBatch).Assembly + }; + break; + + default: + throw new InvalidOperationException($"Unknown target platform '{targetPlatform}'."); + } + + return new PlatformAssemblyMap(targetPlatform, removeAssemblyReferences, targetAssemblies); + } + + + /********* + ** Private methods + *********/ + /// Get the name of a save directory for the current player. + private static string GetSaveFolderName() + { + string prefix = new string(Game1.player.name.Where(char.IsLetterOrDigit).ToArray()); + return $"{prefix}_{Game1.uniqueIDForThisGame}"; + } + + /// Get the game's current version string. + private static string GetGameVersion() + { + // we need reflection because it's a constant, so SMAPI's references to it are inlined at compile-time + FieldInfo field = typeof(Game1).GetField(nameof(Game1.version), BindingFlags.Public | BindingFlags.Static); + if (field == null) + throw new InvalidOperationException($"The {nameof(Game1)}.{nameof(Game1.version)} field could not be found."); + return (string)field.GetValue(null); + } + } +} diff --git a/src/SMAPI/ContentSource.cs b/src/SMAPI/ContentSource.cs new file mode 100644 index 00000000..35c8bc21 --- /dev/null +++ b/src/SMAPI/ContentSource.cs @@ -0,0 +1,12 @@ +namespace StardewModdingAPI +{ + /// Specifies a source containing content that can be loaded. + public enum ContentSource + { + /// Assets in the game's content manager (i.e. XNBs in the game's content folder). + GameContent, + + /// XNB files in the current mod's folder. + ModFolder + } +} diff --git a/src/SMAPI/Context.cs b/src/SMAPI/Context.cs new file mode 100644 index 00000000..119e14c8 --- /dev/null +++ b/src/SMAPI/Context.cs @@ -0,0 +1,37 @@ +using StardewModdingAPI.Events; +using StardewValley; +using StardewValley.Menus; + +namespace StardewModdingAPI +{ + /// Provides information about the current game state. + public static class Context + { + /********* + ** Accessors + *********/ + /**** + ** Public + ****/ + /// Whether the player has loaded a save and the world has finished initialising. + public static bool IsWorldReady { get; internal set; } + + /// Whether is true and the player is free to act in the world (no menu is displayed, no cutscene is in progress, etc). + public static bool IsPlayerFree => Context.IsWorldReady && Game1.activeClickableMenu == null && !Game1.dialogueUp && !Game1.eventUp; + + /// Whether is true and the player is free to move (e.g. not using a tool). + public static bool CanPlayerMove => Context.IsPlayerFree && Game1.player.CanMove; + + /// Whether the game is currently running the draw loop. This isn't relevant to most mods, since you should use to draw to the screen. + public static bool IsInDrawLoop { get; internal set; } + + /**** + ** Internal + ****/ + /// Whether a player save has been loaded. + internal static bool IsSaveLoaded => Game1.hasLoadedGame && !string.IsNullOrEmpty(Game1.player.name); + + /// Whether the game is currently writing to the save file. + internal static bool IsSaving => Game1.activeClickableMenu is SaveGameMenu || Game1.activeClickableMenu is ShippingMenu; // saving is performed by SaveGameMenu, but it's wrapped by ShippingMenu on days when the player shipping something + } +} diff --git a/src/SMAPI/Events/ChangeType.cs b/src/SMAPI/Events/ChangeType.cs new file mode 100644 index 00000000..4b207f08 --- /dev/null +++ b/src/SMAPI/Events/ChangeType.cs @@ -0,0 +1,15 @@ +namespace StardewModdingAPI.Events +{ + /// Indicates how an inventory item changed. + public enum ChangeType + { + /// The entire stack was removed. + Removed, + + /// The entire stack was added. + Added, + + /// The stack size changed. + StackChange + } +} \ No newline at end of file diff --git a/src/SMAPI/Events/ContentEvents.cs b/src/SMAPI/Events/ContentEvents.cs new file mode 100644 index 00000000..4b4e2ad0 --- /dev/null +++ b/src/SMAPI/Events/ContentEvents.cs @@ -0,0 +1,29 @@ +using System; +using StardewModdingAPI.Framework; + +namespace StardewModdingAPI.Events +{ + /// Events raised when the game loads content. + public static class ContentEvents + { + + /********* + ** Events + *********/ + /// Raised after the content language changes. + public static event EventHandler> AfterLocaleChanged; + + + /********* + ** Internal methods + *********/ + /// Raise an event. + /// Encapsulates monitoring and logging. + /// The previous locale. + /// The current locale. + internal static void InvokeAfterLocaleChanged(IMonitor monitor, string oldLocale, string newLocale) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ContentEvents)}.{nameof(ContentEvents.AfterLocaleChanged)}", ContentEvents.AfterLocaleChanged?.GetInvocationList(), null, new EventArgsValueChanged(oldLocale, newLocale)); + } + } +} diff --git a/src/SMAPI/Events/ControlEvents.cs b/src/SMAPI/Events/ControlEvents.cs new file mode 100644 index 00000000..80d0f547 --- /dev/null +++ b/src/SMAPI/Events/ControlEvents.cs @@ -0,0 +1,112 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; +using StardewModdingAPI.Framework; + +namespace StardewModdingAPI.Events +{ + /// Events raised when the player uses a controller, keyboard, or mouse. + public static class ControlEvents + { + /********* + ** Events + *********/ + /// Raised when the changes. That happens when the player presses or releases a key. + public static event EventHandler KeyboardChanged; + + /// Raised when the player presses a keyboard key. + public static event EventHandler KeyPressed; + + /// Raised when the player releases a keyboard key. + public static event EventHandler KeyReleased; + + /// Raised when the changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button. + public static event EventHandler MouseChanged; + + /// The player pressed a controller button. This event isn't raised for trigger buttons. + public static event EventHandler ControllerButtonPressed; + + /// The player released a controller button. This event isn't raised for trigger buttons. + public static event EventHandler ControllerButtonReleased; + + /// The player pressed a controller trigger button. + public static event EventHandler ControllerTriggerPressed; + + /// The player released a controller trigger button. + public static event EventHandler ControllerTriggerReleased; + + + /********* + ** Internal methods + *********/ + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The previous keyboard state. + /// The current keyboard state. + internal static void InvokeKeyboardChanged(IMonitor monitor, KeyboardState priorState, KeyboardState newState) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyboardChanged)}", ControlEvents.KeyboardChanged?.GetInvocationList(), null, new EventArgsKeyboardStateChanged(priorState, newState)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The previous mouse state. + /// The current mouse state. + /// The previous mouse position on the screen adjusted for the zoom level. + /// The current mouse position on the screen adjusted for the zoom level. + internal static void InvokeMouseChanged(IMonitor monitor, MouseState priorState, MouseState newState, Point priorPosition, Point newPosition) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.MouseChanged)}", ControlEvents.MouseChanged?.GetInvocationList(), null, new EventArgsMouseStateChanged(priorState, newState, priorPosition, newPosition)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The keyboard button that was pressed. + internal static void InvokeKeyPressed(IMonitor monitor, Keys key) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyPressed)}", ControlEvents.KeyPressed?.GetInvocationList(), null, new EventArgsKeyPressed(key)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The keyboard button that was released. + internal static void InvokeKeyReleased(IMonitor monitor, Keys key) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyReleased)}", ControlEvents.KeyReleased?.GetInvocationList(), null, new EventArgsKeyPressed(key)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The controller button that was pressed. + internal static void InvokeButtonPressed(IMonitor monitor, Buttons button) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonPressed)}", ControlEvents.ControllerButtonPressed?.GetInvocationList(), null, new EventArgsControllerButtonPressed(PlayerIndex.One, button)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The controller button that was released. + internal static void InvokeButtonReleased(IMonitor monitor, Buttons button) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonReleased)}", ControlEvents.ControllerButtonReleased?.GetInvocationList(), null, new EventArgsControllerButtonReleased(PlayerIndex.One, button)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The trigger button that was pressed. + /// The current trigger value. + internal static void InvokeTriggerPressed(IMonitor monitor, Buttons button, float value) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerPressed)}", ControlEvents.ControllerTriggerPressed?.GetInvocationList(), null, new EventArgsControllerTriggerPressed(PlayerIndex.One, button, value)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The trigger button that was pressed. + /// The current trigger value. + internal static void InvokeTriggerReleased(IMonitor monitor, Buttons button, float value) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerReleased)}", ControlEvents.ControllerTriggerReleased?.GetInvocationList(), null, new EventArgsControllerTriggerReleased(PlayerIndex.One, button, value)); + } + } +} diff --git a/src/SMAPI/Events/EventArgsClickableMenuChanged.cs b/src/SMAPI/Events/EventArgsClickableMenuChanged.cs new file mode 100644 index 00000000..2a2aa163 --- /dev/null +++ b/src/SMAPI/Events/EventArgsClickableMenuChanged.cs @@ -0,0 +1,31 @@ +using System; +using StardewValley.Menus; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsClickableMenuChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The previous menu. + public IClickableMenu NewMenu { get; } + + /// The current menu. + public IClickableMenu PriorMenu { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The previous menu. + /// The current menu. + public EventArgsClickableMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) + { + this.NewMenu = newMenu; + this.PriorMenu = priorMenu; + } + } +} diff --git a/src/SMAPI/Events/EventArgsClickableMenuClosed.cs b/src/SMAPI/Events/EventArgsClickableMenuClosed.cs new file mode 100644 index 00000000..5e6585f0 --- /dev/null +++ b/src/SMAPI/Events/EventArgsClickableMenuClosed.cs @@ -0,0 +1,26 @@ +using System; +using StardewValley.Menus; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsClickableMenuClosed : EventArgs + { + /********* + ** Accessors + *********/ + /// The menu that was closed. + public IClickableMenu PriorMenu { get; } + + + /********* + ** Accessors + *********/ + /// Construct an instance. + /// The menu that was closed. + public EventArgsClickableMenuClosed(IClickableMenu priorMenu) + { + this.PriorMenu = priorMenu; + } + } +} diff --git a/src/SMAPI/Events/EventArgsControllerButtonPressed.cs b/src/SMAPI/Events/EventArgsControllerButtonPressed.cs new file mode 100644 index 00000000..3243b80b --- /dev/null +++ b/src/SMAPI/Events/EventArgsControllerButtonPressed.cs @@ -0,0 +1,32 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsControllerButtonPressed : EventArgs + { + /********* + ** Accessors + *********/ + /// The player who pressed the button. + public PlayerIndex PlayerIndex { get; } + + /// The controller button that was pressed. + public Buttons ButtonPressed { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player who pressed the button. + /// The controller button that was pressed. + public EventArgsControllerButtonPressed(PlayerIndex playerIndex, Buttons button) + { + this.PlayerIndex = playerIndex; + this.ButtonPressed = button; + } + } +} diff --git a/src/SMAPI/Events/EventArgsControllerButtonReleased.cs b/src/SMAPI/Events/EventArgsControllerButtonReleased.cs new file mode 100644 index 00000000..e05a080b --- /dev/null +++ b/src/SMAPI/Events/EventArgsControllerButtonReleased.cs @@ -0,0 +1,32 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsControllerButtonReleased : EventArgs + { + /********* + ** Accessors + *********/ + /// The player who pressed the button. + public PlayerIndex PlayerIndex { get; } + + /// The controller button that was pressed. + public Buttons ButtonReleased { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player who pressed the button. + /// The controller button that was released. + public EventArgsControllerButtonReleased(PlayerIndex playerIndex, Buttons button) + { + this.PlayerIndex = playerIndex; + this.ButtonReleased = button; + } + } +} diff --git a/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs b/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs new file mode 100644 index 00000000..a2087733 --- /dev/null +++ b/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs @@ -0,0 +1,37 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsControllerTriggerPressed : EventArgs + { + /********* + ** Accessors + *********/ + /// The player who pressed the button. + public PlayerIndex PlayerIndex { get; } + + /// The controller button that was pressed. + public Buttons ButtonPressed { get; } + + /// The current trigger value. + public float Value { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player who pressed the trigger button. + /// The trigger button that was pressed. + /// The current trigger value. + public EventArgsControllerTriggerPressed(PlayerIndex playerIndex, Buttons button, float value) + { + this.PlayerIndex = playerIndex; + this.ButtonPressed = button; + this.Value = value; + } + } +} diff --git a/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs b/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs new file mode 100644 index 00000000..d2eecbec --- /dev/null +++ b/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs @@ -0,0 +1,37 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsControllerTriggerReleased : EventArgs + { + /********* + ** Accessors + *********/ + /// The player who pressed the button. + public PlayerIndex PlayerIndex { get; } + + /// The controller button that was released. + public Buttons ButtonReleased { get; } + + /// The current trigger value. + public float Value { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player who pressed the trigger button. + /// The trigger button that was released. + /// The current trigger value. + public EventArgsControllerTriggerReleased(PlayerIndex playerIndex, Buttons button, float value) + { + this.PlayerIndex = playerIndex; + this.ButtonReleased = button; + this.Value = value; + } + } +} diff --git a/src/SMAPI/Events/EventArgsCurrentLocationChanged.cs b/src/SMAPI/Events/EventArgsCurrentLocationChanged.cs new file mode 100644 index 00000000..25d3ebf3 --- /dev/null +++ b/src/SMAPI/Events/EventArgsCurrentLocationChanged.cs @@ -0,0 +1,31 @@ +using System; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsCurrentLocationChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The player's current location. + public GameLocation NewLocation { get; } + + /// The player's previous location. + public GameLocation PriorLocation { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player's previous location. + /// The player's current location. + public EventArgsCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) + { + this.NewLocation = newLocation; + this.PriorLocation = priorLocation; + } + } +} diff --git a/src/SMAPI/Events/EventArgsGameLocationsChanged.cs b/src/SMAPI/Events/EventArgsGameLocationsChanged.cs new file mode 100644 index 00000000..fb8c821e --- /dev/null +++ b/src/SMAPI/Events/EventArgsGameLocationsChanged.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsGameLocationsChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The current list of game locations. + public List NewLocations { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The current list of game locations. + public EventArgsGameLocationsChanged(List newLocations) + { + this.NewLocations = newLocations; + } + } +} diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs new file mode 100644 index 00000000..66cb19f2 --- /dev/null +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -0,0 +1,124 @@ +using System; +using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; +using StardewModdingAPI.Utilities; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Event arguments when a button is pressed or released. + public class EventArgsInput : EventArgs + { + /********* + ** Accessors + *********/ + /// The button on the controller, keyboard, or mouse. + public SButton Button { get; } + + /// The current cursor position. + public ICursorPosition Cursor { get; set; } + + /// Whether the input is considered a 'click' by the game for enabling action. + public bool IsClick { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The button on the controller, keyboard, or mouse. + /// The cursor position. + /// Whether the input is considered a 'click' by the game for enabling action. + public EventArgsInput(SButton button, ICursorPosition cursor, bool isClick) + { + this.Button = button; + this.Cursor = cursor; + this.IsClick = isClick; + } + + /// Prevent the game from handling the vurrent button press. This doesn't prevent other mods from receiving the event. + public void SuppressButton() + { + this.SuppressButton(this.Button); + } + + /// Prevent the game from handling a button press. This doesn't prevent other mods from receiving the event. + /// The button to suppress. + public void SuppressButton(SButton button) + { + // keyboard + if (this.Button.TryGetKeyboard(out Keys key)) + Game1.oldKBState = new KeyboardState(Game1.oldKBState.GetPressedKeys().Except(new[] { key }).ToArray()); + + // controller + else if (this.Button.TryGetController(out Buttons controllerButton)) + { + var newState = GamePad.GetState(PlayerIndex.One); + var thumbsticks = Game1.oldPadState.ThumbSticks; + var triggers = Game1.oldPadState.Triggers; + var buttons = Game1.oldPadState.Buttons; + var dpad = Game1.oldPadState.DPad; + + switch (controllerButton) + { + // d-pad + case Buttons.DPadDown: + dpad = new GamePadDPad(dpad.Up, newState.DPad.Down, dpad.Left, dpad.Right); + break; + case Buttons.DPadLeft: + dpad = new GamePadDPad(dpad.Up, dpad.Down, newState.DPad.Left, dpad.Right); + break; + case Buttons.DPadRight: + dpad = new GamePadDPad(dpad.Up, dpad.Down, dpad.Left, newState.DPad.Right); + break; + case Buttons.DPadUp: + dpad = new GamePadDPad(newState.DPad.Up, dpad.Down, dpad.Left, dpad.Right); + break; + + // trigger + case Buttons.LeftTrigger: + triggers = new GamePadTriggers(newState.Triggers.Left, triggers.Right); + break; + case Buttons.RightTrigger: + triggers = new GamePadTriggers(triggers.Left, newState.Triggers.Right); + break; + + // thumbstick + case Buttons.LeftThumbstickDown: + case Buttons.LeftThumbstickLeft: + case Buttons.LeftThumbstickRight: + case Buttons.LeftThumbstickUp: + thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Left, thumbsticks.Right); + break; + case Buttons.RightThumbstickDown: + case Buttons.RightThumbstickLeft: + case Buttons.RightThumbstickRight: + case Buttons.RightThumbstickUp: + thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Right, thumbsticks.Left); + break; + + // buttons + default: + var mask = + (buttons.A == ButtonState.Pressed ? Buttons.A : 0) + | (buttons.B == ButtonState.Pressed ? Buttons.B : 0) + | (buttons.Back == ButtonState.Pressed ? Buttons.Back : 0) + | (buttons.BigButton == ButtonState.Pressed ? Buttons.BigButton : 0) + | (buttons.LeftShoulder == ButtonState.Pressed ? Buttons.LeftShoulder : 0) + | (buttons.LeftStick == ButtonState.Pressed ? Buttons.LeftStick : 0) + | (buttons.RightShoulder == ButtonState.Pressed ? Buttons.RightShoulder : 0) + | (buttons.RightStick == ButtonState.Pressed ? Buttons.RightStick : 0) + | (buttons.Start == ButtonState.Pressed ? Buttons.Start : 0) + | (buttons.X == ButtonState.Pressed ? Buttons.X : 0) + | (buttons.Y == ButtonState.Pressed ? Buttons.Y : 0); + mask = mask ^ controllerButton; + buttons = new GamePadButtons(mask); + break; + } + + Game1.oldPadState = new GamePadState(thumbsticks, triggers, buttons, dpad); + } + } + } +} diff --git a/src/SMAPI/Events/EventArgsIntChanged.cs b/src/SMAPI/Events/EventArgsIntChanged.cs new file mode 100644 index 00000000..0c742d12 --- /dev/null +++ b/src/SMAPI/Events/EventArgsIntChanged.cs @@ -0,0 +1,29 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for an integer field that changed value. + public class EventArgsIntChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The previous value. + public int PriorInt { get; } + + /// The current value. + public int NewInt { get; } + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The previous value. + /// The current value. + public EventArgsIntChanged(int priorInt, int newInt) + { + this.PriorInt = priorInt; + this.NewInt = newInt; + } + } +} diff --git a/src/SMAPI/Events/EventArgsInventoryChanged.cs b/src/SMAPI/Events/EventArgsInventoryChanged.cs new file mode 100644 index 00000000..1ee02842 --- /dev/null +++ b/src/SMAPI/Events/EventArgsInventoryChanged.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsInventoryChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The player's inventory. + public List Inventory { get; } + + /// The added items. + public List Added { get; } + + /// The removed items. + public List Removed { get; } + + /// The items whose stack sizes changed. + public List QuantityChanged { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player's inventory. + /// The inventory changes. + public EventArgsInventoryChanged(List inventory, List changedItems) + { + this.Inventory = inventory; + this.Added = changedItems.Where(n => n.ChangeType == ChangeType.Added).ToList(); + this.Removed = changedItems.Where(n => n.ChangeType == ChangeType.Removed).ToList(); + this.QuantityChanged = changedItems.Where(n => n.ChangeType == ChangeType.StackChange).ToList(); + } + } +} diff --git a/src/SMAPI/Events/EventArgsKeyPressed.cs b/src/SMAPI/Events/EventArgsKeyPressed.cs new file mode 100644 index 00000000..d9d81e10 --- /dev/null +++ b/src/SMAPI/Events/EventArgsKeyPressed.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsKeyPressed : EventArgs + { + /********* + ** Accessors + *********/ + /// The keyboard button that was pressed. + public Keys KeyPressed { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The keyboard button that was pressed. + public EventArgsKeyPressed(Keys key) + { + this.KeyPressed = key; + } + } +} diff --git a/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs b/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs new file mode 100644 index 00000000..14e397ce --- /dev/null +++ b/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs @@ -0,0 +1,31 @@ +using System; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsKeyboardStateChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The previous keyboard state. + public KeyboardState NewState { get; } + + /// The current keyboard state. + public KeyboardState PriorState { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The previous keyboard state. + /// The current keyboard state. + public EventArgsKeyboardStateChanged(KeyboardState priorState, KeyboardState newState) + { + this.PriorState = priorState; + this.NewState = newState; + } + } +} diff --git a/src/SMAPI/Events/EventArgsLevelUp.cs b/src/SMAPI/Events/EventArgsLevelUp.cs new file mode 100644 index 00000000..fe6696d4 --- /dev/null +++ b/src/SMAPI/Events/EventArgsLevelUp.cs @@ -0,0 +1,52 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsLevelUp : EventArgs + { + /********* + ** Accessors + *********/ + /// The player skill that leveled up. + public LevelType Type { get; } + + /// The new skill level. + public int NewLevel { get; } + + /// The player skill types. + public enum LevelType + { + /// The combat skill. + Combat, + + /// The farming skill. + Farming, + + /// The fishing skill. + Fishing, + + /// The foraging skill. + Foraging, + + /// The mining skill. + Mining, + + /// The luck skill. + Luck + } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player skill that leveled up. + /// The new skill level. + public EventArgsLevelUp(LevelType type, int newLevel) + { + this.Type = type; + this.NewLevel = newLevel; + } + } +} diff --git a/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs b/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs new file mode 100644 index 00000000..058999e9 --- /dev/null +++ b/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs @@ -0,0 +1,28 @@ +using System; +using Microsoft.Xna.Framework; +using StardewValley; +using Object = StardewValley.Object; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsLocationObjectsChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The current list of objects in the current location. + public SerializableDictionary NewObjects { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The current list of objects in the current location. + public EventArgsLocationObjectsChanged(SerializableDictionary newObjects) + { + this.NewObjects = newObjects; + } + } +} diff --git a/src/SMAPI/Events/EventArgsMineLevelChanged.cs b/src/SMAPI/Events/EventArgsMineLevelChanged.cs new file mode 100644 index 00000000..c82fed35 --- /dev/null +++ b/src/SMAPI/Events/EventArgsMineLevelChanged.cs @@ -0,0 +1,30 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsMineLevelChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The previous mine level. + public int PreviousMineLevel { get; } + + /// The current mine level. + public int CurrentMineLevel { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The previous mine level. + /// The current mine level. + public EventArgsMineLevelChanged(int previousMineLevel, int currentMineLevel) + { +