Skip to content

ryan-linehan/limbo_console_sharp

Repository files navigation

LimboConsole.Sharp

NuGet License Build Status Platform Godot Version NuGet Downloads

This nuget package is a c# wrapper that helps facilitate using the limbo_console godot plugin in c#.

Table of Contents

✨ Features

  • Simplified Integration: Easily interact with the πŸ’» limbo_console godot plugin from a c# godot game.
  • Command Registration: Register commands with descriptions and auto-complete sources.
  • Auto-Complete Support: Add auto-complete sources for command arguments.
  • Demo Project: Includes examples for initialization, commands, and advanced features.

πŸ› οΈ Requirements

  • Godot Engine: Version 4.4.X or higher.
  • .NET SDK: Version 8.0
  • limbo_console plugin: Installed and enabled in your godot project. See πŸ’» limbo console.

πŸ–₯️ Installation

  1. Ensure the πŸ’» limbo console plugin is installed and enabled in your godot project:

    • Go to Project > Project Settings > Plugins and enable the plugin.
  2. Install the nuget package for your godot c# project (compatible with godot 4.4.X).

Using dotnet CLI

Run the following command:

dotnet add package LimboConsole.Sharp

Using csproj

Add the following line to your godot game's csproj

<PackageReference Include="LimboConsole.Sharp" Version="<specify.your.version>" />

πŸ“ Getting started

Register a Command

// Access the console statically from any node within the tree
LimboConsole.RegisterCommand(new Callable(this, MethodName.StartGame), "start_game", "Starts the game");

private void StartGame() {
    // Do something
}

Using the [ConsoleCommand] Attribute

You can also use the [ConsoleCommand] attribute to easily define commands.

πŸ’‘You must call RegisterConsoleCommands() to enable your class's [ConsoleCommands].

  // By default use name of function exactly
  [ConsoleCommand]
  private void LogFromAttribute() => LimboConsole.Info($"{GlobalPosition}");

  // Pass a custom name
  [ConsoleCommand("CoolName")]
  private void AFunctionName() => LogFromAttribute();

  // Pass a custom name and description
  [ConsoleCommand("Say", "Shows a message in the console")]
  private void Print(string message) => LimboConsole.Info(message);

  // Remember to register the commands!
  private void _Ready() {
      // This will register the commands
      RegisterConsoleCommands();
  }

ConsoleCommand Attribute In Use

Register an Auto-Complete Source

You can also add auto-complete sources for command arguments:

LimboConsole.AddArgumentAutocompleteSource("abc", 1, Callable.From(() => new string[] { "a", "b", "c" }));

This example adds an auto-complete source for the first argument of the abc command, suggesting the values a, b, or c.

Note: when registering an argument index starts at 1 not 0 and currently has a max of 5 arguments

Using the [AutoComplete] Attribute

You can also use the [AutoComplete] attribute to quickly define autocompletes for your attribute based console commands

πŸ’‘You must call RegisterConsoleCommands() to enable your class's [AutoComplete]'s!

Method-based autocomplete:

[ConsoleCommand]
[AutoComplete(nameof(Colors))]
public void FavoriteColorCommand(string colors) {
  // Do something
}

private string[] Colors() {
  return new [] {"red", "blue", "green"};
}

This example adds an auto-complete source for the first argument of the FavoriteColorCommand command, suggesting the values red, blue, and green.

Inline array autocomplete:

You can also define autocomplete values inline without needing a separate method:

[ConsoleCommand]
[AutoComplete(new string[] { "red", "white", "orange", "green" })]
public void ColorCommand(string color) {
  // Do something
}

For multi-parameter commands, specify the argument index (note: parameter indices are 0-based):

[ConsoleCommand]
[AutoComplete(new string[] { "apple", "banana", "cherry", "date" }, 1)]
public void FruitCommand(int quantity, string fruit) {
  // Do something with quantity and fruit
}

In newer C# versions, you can use collection expressions:

[ConsoleCommand]
[AutoComplete(["red", "white", "orange", "green"])]
public void ColorCommand(string color) {
  // Do something
}

More examples

See run the demo project and see Demo.cs for more examples of how to use the package

πŸ“š Documentation

See summary comments in nuget package or refer to πŸ’» limbo_console

For a detailed history of changes, see the Changelog.

🀝 Contributing

Thanks for your interest in contributing. Please follow these guidelines to keep the project consistent and maintainable in the long-term. Keep in mind this is just a wrapper. Feature or bug fixes for the requests for the console itself should go here πŸ’» limbo_console.

After a feature is added and/or the public api changes this repo will need to be updated so help keeping it up to date is appreciated!

See something you want or could improve upon? Make a PR! ✨

Project structure

  • Limbo.Console.Sharp: The root of the nuget package.

    • Pack: Use dotnet pack to create the package. Alternatively, run the provided .bat script on Windows to automate packaging to the demo project.

    The .bat file is a helpful reference for understanding how the demo project and the nuget package interact. It automates the packaging process for Windows users to test changes in the demo project.

  • Demo Project: A sample godot project included to demonstrate:

    • Registering commands and auto-complete sources.
    • Using advanced features like signals and callable commands.

Note: Currently, there is no quick script for packaging on non-Windows platforms. Contributions to add this functionality are welcome!

Code Style & Recommendations

πŸ“‹ Changelog

See the CHANGELOG.md file for a detailed list of changes in each version.

πŸ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ‘₯ Contributors

Thanks to these wonderful people for their contributions:

ryan-linehan fahall

About

A simple c# wrapper for the limbo_console plug-in for godot

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •