From f3675aa466e429810fd4254a0413403e203c942e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 28 Nov 2016 20:51:57 -0500 Subject: move assembly map into constants (#166) --- src/StardewModdingAPI/Constants.cs | 52 ++++++++++++++++++++++ .../Framework/ModAssemblyLoader.cs | 48 +------------------- 2 files changed, 53 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs index 05e410ab..66eb1336 100644 --- a/src/StardewModdingAPI/Constants.cs +++ b/src/StardewModdingAPI/Constants.cs @@ -2,6 +2,8 @@ using System.IO; using System.Linq; using System.Reflection; +using StardewModdingAPI.Framework; +using StardewModdingAPI.Framework.AssemblyRewriting; using StardewValley; namespace StardewModdingAPI @@ -62,6 +64,56 @@ namespace StardewModdingAPI public static string LogPath => Path.Combine(Constants.LogDir, "MODDED_ProgramLog.Log_LATEST.txt"); + /********* + ** Internal field + *********/ + /// 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 field *********/ diff --git a/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs b/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs index 3d08ec64..b6d98bde 100644 --- a/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs +++ b/src/StardewModdingAPI/Framework/ModAssemblyLoader.cs @@ -38,7 +38,7 @@ namespace StardewModdingAPI.Framework { this.CacheDirPath = cacheDirPath; this.Monitor = monitor; - this.AssemblyMap = this.GetAssemblyMap(targetPlatform); + this.AssemblyMap = Constants.GetAssemblyMap(targetPlatform); this.AssemblyTypeRewriter = new AssemblyTypeRewriter(this.AssemblyMap, monitor); } @@ -123,51 +123,5 @@ namespace StardewModdingAPI.Framework string cacheHashPath = Path.Combine(dirPath, $"{key}.hash"); return new CachePaths(dirPath, cacheAssemblyPath, cacheHashPath); } - - /// Get metadata for mapping assemblies to the current platform. - /// The target game platform. - private 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); - } } } -- cgit