quentincaffeino / godot-console

In-game console for Godot 3.
MIT License
669 stars 49 forks source link
console csharp game-console gdscript godot godot-console

In-game console for Godot Logo

Godot Console

All Contributors

In-game console for Godot Screenshot

In-game console for Godot, which could be easily extended with new commands.

Features:

Installation:

Via Editor AssetLib:

  1. Open AssetLib.
  2. Search for Console, category is Scripts; Open it and click Download and then Install.
  3. Click install. Package installer will copy filestructure as-is so you will have this additional directories in your project: addons/@quentincaffeino/*, addons/quentincaffeino/*.
  4. Open Project > Project Settings > Plugins, search for quentincaffeino-console and check the Enable checkbox.
  5. You can activate the console with CTRL + ` while running your game (can be changed, see quentincaffeino_console_toggle action).

Via GIT:

  1. Clone this project or download latest release.
  2. Copy./addons/@quentincaffeino and ./addons/quentincaffeino into your projects addons folder.

So you will have this structure:

res://
├── addons
│   ├── @quentincaffeino
│   ├── quentincaffeino
│   ├── ...
  1. Open Project > Project Settings > Plugins, search for quentincaffeino-console and check the Enable checkbox.
  2. You can activate the console with CTRL + ` while running your game (can be changed, see quentincaffeino_console_toggle action).

Example usage:

Usage we will get:

$ sayHello "Adam Smith"
Hello Adam Smith!

GDScript

# Function that will be called by our command
func print_hello(name = ''):
    Console.write_line('Hello ' + name + '!')

func _ready():
    # Registering command
    # 1. argument is command name
    # 2. arg. is target (target could be a funcref)
    # 3. arg. is target name (name is not required if it is the same as first arg or target is a funcref)
    Console.add_command('sayHello', self, 'print_hello')\
        .set_description('Prints "Hello %name%!"')\
        .add_argument('name', TYPE_STRING)\
        .register()

C

// Function that will be called by our command
public string PrintHello(string name = null) {
    GD.Print("Hello " + name + "!");
    return "test";
}

public override void _Ready()
{
    // Registering command
    // 1. argument is command name
    // 2. arg. is target (target could be a funcref)
    // 3. arg. is target name (name is not required if it is the same as first arg or target is a funcref)
    (((GetNode("/root/Console").Call("add_command", "sayHello", this, "PrintHello") as Godot.Object)
        .Call("set_description", "prints \"hello %name%!\"") as Godot.Object)
        .Call("add_argument", "name", Variant.Type.String) as Godot.Object)
        .Call("register");
}

C# with wrapper (Note this is WIP and some methods may be missing)

  1. Instead of enabling the Console checkbox from the addon tab you will want to enable CSharpConsole via the plugin checkbox
  2. See the example below for how to use once plugin is enabled

Example:

public override void _Ready()
{
    _wrapper = GetTree().Root.GetNode<Console>("CSharpConsole");
    _wrapper.AddCommand("sayHello", this, nameof(PrintHello))
            .SetDescription("prints \"hello %name%!\"")
            .AddArgument("name", Variant.Type.String)
            .Register();
}

public void PrintHello(string name = null) {
    GD.Print($"Hello {name}!");
}

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Sergei ZH
Sergei ZH

💻 💬 📖 🤔 👀
Michael Brune
Michael Brune

️️️️♿️ 🐛
Michael Aganier
Michael Aganier

🐛
hpn332
hpn332

🐛
Danil
Danil

🐛
Paul Hocker
Paul Hocker

🐛
Samantha Clarke
Samantha Clarke

🐛
Hugo Locurcio
Hugo Locurcio

️️️️♿️
Dmitry Derbin
Dmitry Derbin

💬
VitexHD
VitexHD

🐛
hilfazer
hilfazer

💻 🐛
Crazy Chenz
Crazy Chenz

💻
Marcus Schütte
Marcus Schütte

💻
Kimmo Salmela
Kimmo Salmela

💻
GuillaumeCailhe
GuillaumeCailhe

🐛 🤔 💬
Josh DeGraw
Josh DeGraw

💻
Lyaaaaaaaaaaaaaaa
Lyaaaaaaaaaaaaaaa

🚇
Gamemap
Gamemap

📖
Spyrex
Spyrex

💻
Zhwt
Zhwt

💻
Ryan Linehan
Ryan Linehan

💻
Kurt
Kurt

📖
eisclimber
eisclimber

🐛 💻
Rafael Correa
Rafael Correa

💻
PraxTube
PraxTube

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

License

Licensed under the MIT license, see LICENSE.md for more information.