Description
Changelog
Reviews

Command Terminal

Command Terminal is an addon for Godot 4.x that manages a developer-created, hierarchical command system (think Minecraft), with the focus of providing flexible commands, with direct and strongly-typed interaction with business logic, through fairly readable declarative source.

  • Register and execute commands, anywhere and anytime.
  • Easily create powerful, flexible, and type-safe commands.
  • Provides node to input commands, with rich autocompletion and live validation included.

Overview

Suppose your project is a 2D-platformer that has a player.gd script for a CharacterBody2D:

class_name Player extends CharacterBody2D

signal coin_collected()

var WALK_SPEED = 300.0
var ACCELERATION_SPEED = WALK_SPEED * 6.0
var JUMP_VELOCITY = 725.0
var TERMINAL_VELOCITY = 700

var gravity: int = ProjectSettings.get("physics/2d/default_gravity")

Everything done hereafter requires no alterations to the above code.

Creating a command to give the player a coin may be done by emitting the coin_collected() signal when it is ran. The following code creates command "player give coin" to do just that.

func register_commands() -> void:
    CommandServer.register_command(
        CommandBuilder.new()
            .Literal("player").Literal("give").Literal("coin")
            .Callback(player.coin_collected.emit)
        .Build()
    )

The following code creates command "player set walk_speed " to alter WALK_SPEED. Values inputted that are not valid, positive floats are visibly flagged. Validated arguments include a default value which is supplied when autocompleteed.

func register_commands() -> void:
    CommandServer.register_command(
        CommandBuilder.new()
            .Literal("player").Literal("set").Literal("walk_speed")
            .Validated("value", _is_valid_float_positive, 300).Tag_gn("float")
            .Callback(player.set, ["WALK_SPEED", "value"])
        .Build()
    )

func _is_valid_float_positive(s : String) -> bool:
    if not value.is_valid_float(): return false
    var value : float = float(value)
    return value > 0

More

These are very simple commands. The addon is capable of much more.

Further reading is available in the included documentation, /docs/.

Changelog for version v0.1.5

No changelog provided for this version.