Skip to content

Latest commit

 

History

History
147 lines (96 loc) · 6.78 KB

README.md

File metadata and controls

147 lines (96 loc) · 6.78 KB

KeybindLib

GitHub Workflow Status Codacy Badge Nonexistent Tests

KeybindLib is a Slime Rancher library mod for adding new keybinds.

Usage

End Users

If you want to use a mod that requires KeyebindLib, just place KeybindLib.dll in your SRML mods folder (SRML/Mods).

Releases

You can download KeybindLib from the releases page (below the changelog) or from the Nexus page (in the "FILES" tab).

Mod Conflicts

KeybindLib should not have any conflicts with existing mods, except possibly the crouching mod. Any new mods that also add their own keybinds may be incompatible if they don't use KeybindLib.

Modders

The following is for modders who want to use KeybindLib in your mod. Keep in mind that if your mod uses KeybindLib, anyone using your mod needs to have KeybindLib installed.

References

You need to add KeybindLib.dll as a reference to your project, the same way you would add SRML.dll as described on the wiki. It's highly recommended to also have KeybindLib.xml in the same directory as KeybindLib.dll, as it will allow you to see KeybindLib's XML documentation while you're programming.

You will also need InControl.dll as a reference, because KeybindLib uses a few of the types from it.

modinfo.json

You also need to add this mod as a dependency of your mod, and you'll need to add it to your mod's load_before list. Do not add this mod to your load_after list, it will not work. Here's an example of a modinfo.json that's set up to use KeybindLib.

{
  "id": "dashing",
  "name": "Dashing",
  "author": "Esper89",
  "description": "Allows you to air-dash!",
  "version": "1.0",
  "dependencies": [
    "keybindlib 1.0"
  ],
  "load_before": [
    "keybindlib"
  ]
}

If your mod can function without KeybindLib despite using some of it's features, you don't need to add it as a dependency, but it still needs to be in your mod's load_before list.

Nexus

If you publish your mod on nexus, it is recommended to add KeybindLib as a required mod (in the "Requirements and mirrors" tab of the mod creation page), the same way you would add SRML. This will notify people downloading your mod that they need to download this mod as well.

API

KeybindLib's API is documented by XML comments throughout the code, which are automatically converted to markdown and committed to src/KeybindLib/README.md. You can check that for a quick reference. If you just want to learn how to use KeybindLib, see below for a small example.

using InControl;
using KeybindLib;
using SRML;
using SRML.Console;
using static MessageDirector;

public class Main : ModEntryPoint                       // Your mod's entry point.
{
    public override void PreLoad()                      // Keybinds must be set up during PreLoad.
    {
        Keybind hello = new Keybind(                    // Create a new keybind.
            name: "key.hello",                          // The name of this keybind. Must have `key.` prefix.
            comesBefore: "key.map",                     // The keybind that this one appears directly before in the keybind list.
            defaultBinding: Key.H,                      // The default binding for this keybind.
            translation: "Hello"                        // The english translation for this keybind.
            keyPressed: (player) =>                     // A delegate to run when this key is pressed.
            {
                Console.Log("Hello World!");            // This code will run every time the key is pressed.
            }
        );

        KeybindRegistry.Register(hello);                // Register the keybind.
    }
}

KeybindLib has other useful features, like multiple default keybinds, multiple translations, keyReleased and keyDownUpdate, and more. To see examples of all of them, check out src/ExampleMod. Every KeybindLib release comes with an ExampleMod.zip bundled with it.

If you have any questions, feel free to message me on Discord (Esper#8989) or matrix (@esper89:matrix.org).

Features

  • Adding new keybinds.

  • Controlling your keybind's position in the keybind list.

  • Setting any number of default bindings for your keybind.

  • Automatically registering translations.

  • Translation API support, for multiple languages. (CURRENTLY BROKEN)

  • Events that run on key press, key release, and every frame that they key is down.

  • Attaching delegates to vanilla actions.

  • An event that runs every frame that keybinds are updated.

  • A HashSet of all vanilla keybinds and their internal names.

  • An example/test mod for easy testing and learning.

  • Very shiny transpilers that I'm very proud of.

Limitations

  • May not be compatible with mods that manually add their own keybinds.

Contributing

Contributions of any kind - issues, pull requests, feature requests - are all welcome. You can submit suggestions and bug reports as an issue, or code contributions as a pull request.

Scope

Anything to do with keybinds can be considered within the scope of KeybindLib.

Also, KeybindLib is a library mod, so it doesn't change any gameplay mechanics on it's own.

Building

KeybindLib's build system is in the build directory. See build/README.md for a guide to building KeybindLib.

License

Copyright (c) 2021 Esper Thomson

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.