Skip to content

Getting Started

Justin Oroz edited this page Sep 12, 2020 · 28 revisions

Contents

Requirements

Project Setup

After setting up an SMAPI mod there are a few quick steps to adding your mod to the Mod Config tab.

Add Framework Reference

First, we need to allow your project to reference the Framework. There are 2 methods:

NOTE: These images are of the Mac client, although Windows has a similar process.

NuGet Package (RECOMMENDED)

The NuGet package makes it quick and easy to add the framework in Visual Studio.

Download the DLL (ALTERNATIVE)

1. Open the project Solution in Visual Studio

2. Right click the References option in the Solution Explorer, usually on the left side, and select Edit References.

Edit References

3. Select the .Net Assembly tab and browse for the downloaded StardewConfigFramework.dll. Download here. Ensure the assembly file is selected with a check by the name.

Add Assembly

4. That's it! Hit OK, and you now have a reference to the Framework.

Add Dependency to Manifest

For the Framework to be accessed it must be loaded before your mod, to ensure this, we will add StardewConfigFramework as a dependency. Add the following lines to your manifest.json file.

"Dependencies": [
    { "UniqueID": "Juice805.StardewConfigMenu" }
]

For Example, your manifest may look like this:

{
    "Name": "Framework Example",
    "Authour": "Juice805",
    "Version": "1.0.0",
    "Description": "A short description of your app.",
    "UniqueID": "You.ModID",
    "EntryDll": "Example.dll",
    "Dependencies": [
        { "UniqueID": "Juice805.StardewConfigMenu" }
    ]
}

For more up to date Manifest examples and properties check the wiki

Initialize Options Package

Congratulations! You have setup your project and are ready to do some actual work. To begin we will modify your ModEntry class by adding a few lines. Notice in the example we add an event handler to GameEvents.FirstUpdateTick where we retrieve the menu reference and add the options; this is required as Helper.ModRegistry.GetApi cannot be called until all mods Entry methods are called as explained on the wiki.

There are multiple methods for packaging up your mod's options at this stage: For a mod with multiple option tabs and max configurability use a TabbedOptionsPackage, for simpler mods with a single tab it is recommended to use a SimpleOptionsPackage which contains convenience methods for a single tab. For the basic example we will use a SimpleOptionsPackage. For more information about the differences between the two packages check the Options Package page.

using System;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewConfigFramework; // Add the framework

namespace YourMod
{
    public class ModEntry: Mod
    {

        internal SimpleOptionsPackage Package;

        public override void Entry(IModHelper helper)
        {
            GameEvents.FirstUpdateTick += AddPackageToMenu;
        }

        void AddPackageToMenu(object sender, System.EventArgs e) {
            Menu = Helper.ModRegistry.GetApi<IConfigMenu>("Juice805.StardewConfigMenu");
            Package = new SimpleOptionsPackage(this);
            Menu.AddOptionsPackage(Package);

            // Add options to your package
        }
    }
}

That's it! Your mod has a page in the options menu! Check out other pages on the Wiki for detailed instructions on how to use the IOptionPackage objects and each option individually

Clone this wiki locally