Stardew Valley(星露谷物语)Mod开发之路1环境配置

it2022-05-09  59

首先来说明一下,我写这个章节本身也是对学习过程的记录,主要参考了http://canimod.com/guides/creating-a-smapi-mod中的内容。也推荐大家看看。

*这些是我的开发环境*

  操作系统:

    macOS

  SDK:

       1 MonoFramework-MDK-4.6.2.16.macos10.xamarin.universal.pkg (貌似是.net平台)

     2 XamarinStudio-6.1.2.44.dmg (这个应该是IDE)

  ps:具体的版本依照实际的操作系统来定,或者安装vs。同时你也可以向上面那个英文教程学习~ 

*正式*

  然而在正式配置环境之前,是的,你得保证游戏正常运行。然后依次安装上面两个软件(我相信这是一个很容易的过程,谢谢)。

*创建一个项目*

  &恩,详细过程我还是直接借用过来翻译一下算了~

 

打开 Visual Studio 或者 MonoDevelop.创建一个新的 solution with a library project. 在 Visual Studio中, 选择 Visual C# » Class Library. (确保你选择的是 “Class Library”, 而不是 “Class Library (.NET Core)” 或者 “Class Library (Portable)”.)在 MonoDevelop中, 选择 Other » .NET » Library.改变 the target framework to .NET 4.5 (for compatibility with Linux). 在 Visual Studio中: 右键 project, 选择 Properties, 单击Application 标签, 并且将 Target framework dropdown 选成 .NET Framework 4.5.在 MonoDevelop中: 右键 project, 选择 Options, 单击 the Build » General 标签, 并且将Target framework dropdown 选成 Mono / .NET 4.5.删除项目中的 Class1.cs 或者 MyClass.cs 文件.

  ps:按照上面步骤,我这里新建了一个solution和project名称都为firstMod的项目。需要注意后面的一些配置信息要与这里对应

 

*配置项目*

  项目需要引用这个包 Pathoschild.Stardew.ModBuildConfig NuGet package. 它能够自动配置你的项目,针对当前的平台,正确加载合适的依赖库。

  1.双击下图画圈的部分

  

  2.弹出了如下界面,然后在搜索框中“Pathoschild.Stardew.ModBuildConfig”,安装并等待完成。

  

      3.添加一个cs文件,名称 “ModEntry”

  

  4.将如下内容复制进ModEntry.cs

1 using System; 2 using Microsoft.Xna.Framework; 3 using StardewModdingAPI; 4 using StardewModdingAPI.Events; 5 using StardewValley; 6 7 namespace firstMod 8 { 9 /// <summary>The mod entry point.</summary> 10 public class ModEntry : Mod 11 { 12 /// <summary>Initialise the mod.</summary> 13 /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param> 14 public override void Entry(IModHelper helper) 15 { 16 ControlEvents.KeyPressed += this.ReceiveKeyPress; 17 } 18 19 /********* 20 ** Private methods 21 *********/ 22 /// <summary>The method invoked when the player presses a keyboard button.</summary> 23 /// <param name="sender">The event sender.</param> 24 /// <param name="e">The event data.</param> 25 private void ReceiveKeyPress(object sender, EventArgsKeyPressed e) 26 { 27 this.Monitor.Log($"Player pressed {e.KeyPressed}."); 28 } 29 } 30 } View Code

   5.创建manifest.json文件,内容如下,存放至工程目录下,其实位置无所谓,主要是最终应该放在游戏mod的目录下

{ "Name": "firstMod", "Author": "iamfine", "Version": { "MajorVersion": 1, "MinorVersion": 0, "PatchVersion": 0, "Build": "" }, "Description": "获取按键消息", "UniqueID": "iamfine.firstMod", "EntryDll": "firstMod.dll" }

  6.编译整个工程后得到如下文件

  

  7.将firstMod.dll 和 manifest.json两个文件复制到游戏的Mods目录下,如下图所示。

  

   ps:安装smapi后,在macOS下,mod的目录是

/Users/huqian/Library/Application Support/Steam/steamapps/common/Stardew Valley/Contents/MacOS/Mods

 

  8.运行游戏后,这个mod会记录玩家在游戏界面中的按键信息,如下图。

 

转载于:https://www.cnblogs.com/Dream-Chaser/p/6377946.html

相关资源:各显卡算力对照表!

最新回复(0)