GsomConsole
by RaubTieR
gsom_console
A Half-Life 1 inspired console for Godot projects.
There is a singleton, and optional UI (that doesn't autoload).
It's also possible to craft your own UI instead.
Future versions may provide additional UI implementations as well.
The core idea: you have CVARs (console variables) and CMDs (commands).
You can use CVARs as global variables and settings. CMDs are like global events/signals.
There are special built-in commands like alias
, exec
, wait
, echo
, map
, quit
.
Supported variable types: bool, int, float, String
- the variable type
is determined when it is registered with an initial value.
After that, new values are interpreted as being of that type.
GsomConsole.register_cvar("test", 5, "Description.")
- will register an int
CVAR.
test
-> output 5test 6
-> nowtest
is6
test 7.1
-> now test is7
because it isint
Registering commands simply declares them for future calls. The console
doesn't do anything specific per CMD call - only emits the called_cmd
signal.
GsomConsole.register_cmd("do_something", "Description.")
- will register the do_something
CMD.
do_something
-> will emitcalled_cmd.emit("do_something", [])
.do_something abc -1 20 true 3.3
-> will
emitcalled_cmd.emit("do_something", ["abc", "-1", "20", "true", "3.3"])
.
See example script.
GsomConsole
This is an autoload singleton, that becomes globally available when you enable the plugin.
It holds all the common console logic and is not tied to any specific UI.
Signals
signal changed_cvar(cvar_name: String)
- a CVAR has been changed.
You may fetch its updated value withget_cvar(cvar_name)
and react to the change.signal called_cmd(cmd_name: String, args: PackedStringArray)
- a CMD was called.
All listeners will receive the command name and list of args.signal toggled(is_visible: bool)
- console visibility toggled.
This is optional - if you use the default visibility logic that comes with this singleton.signal logged(rich_text: String)
- a log string was added. Only the latest addition
is passed to the signal. The whole log text is available aslog_text
prop.
Properties
tick_mode: TickMode
- defaultTickMode.TICK_MODE_AUTO
,
the mode of calling postponed (bywait
) commands. By default, it happens every
frame automatically. But you can seize manual control over this process.exec_paths: PackedStringArray
- default['user://', 'res://']
,
the list of search directories to load console scripts from. The loader
will look through the directories in that very order. So if you want to add a
high-priority directory - you are to prepend it, and not append.log_text: String
- the whole log text content. This may be also used to reset the log.is_visible: bool
- current visibility status. As the UI is not directly linked to
the singleton, this visibility flag is just for convenience. You can implement any
other visibility logic separately and disregard this flag.history: PackedStringArray
- history of inserted commands.
Latest command is last. Duplicate commands not stored.COLORS_HELP: Array[String]
- default["#d4fdeb", "#d4e6fd", "#fdd4e6", "#fdebd4"]
,
a set of colors that help lists will use to alternate between strings. There
may be any number of colors - the strings will cycle through them.COLOR_PRIMARY: String
- default"#ecf4fe"
, color to display names of CVARs.COLOR_SECONDARY: String
- default"#a3b0c7"
, secondary color related
to names of CVARs (used for ":").COLOR_TYPE: String
- default"#95c1fb"
, color to display types of CVARs.COLOR_VALUE: String
- default"#f6d386"
, color to display values of CVARs.COLOR_INFO: String
- default"#a29cf5"
, color forinfo()
logging.COLOR_DEBUG: String
- default"#c3e2e5"
, color fordebug()
logging.COLOR_WARN: String
- default"#f89d2c"
, color forwarn()
logging.COLOR_ERROR: String
- default"#ff3c2c"
, color forerror()
logging.CMD_SEPARATOR: String
- default";"
, a character to use as a separator between commands.CMD_WAIT: String
- default"wait"
, this command is treated aswait
,
if you want to change the default name.EXEC_EXT: String
- default".cfg"
, used to facilitate the search for config scripts
by automatically checking the provided path with this suffix.
Methods
register_cvar(cvar_name: String, value: Variant, help_text: String = "") -> void
- makes a new
CVAR available with default value and optional help note.register_cmd(cmd_name: String, help_text: String = "") -> void
- makes a new
CMD available with an optional help note.alias(alias_name: String, alias_text: String = "") -> void
- makes a new
ALIAS available, or removes an existing one ifalias_text
is empty.call_cmd(cmd_name: String, args: PackedStringArray) -> void
- manually call a command,
as if the call was parsed from user input.set_cvar(cvar_name: String, value: Variant) -> void
- assign new value to the CVAR.get_cvar(cvar_name: String) -> Variant
- inspect the current CVAR value.list_cvars() -> Array
- list all CVAR names.has_cvar(cvar_name: String) -> bool
- check if there is a CVAR with given name.has_cmd(cmd_name: String) -> bool
- check if there is a CMD with given name.has_alias(alias_name: String) -> bool
- check if there is an ALIAS with given name.get_matches(text: String) -> PackedStringArray
- get a list of CVAR and CMD
names that start with the giventext
.tick() -> void
- calls the enqueued by "wait" commands, if any. By default
it is called automatically every frame.hide() -> void
- setis_visible
tofalse
if it wastrue
.
Only emitstoggled
if indeed changed.show() -> void
- setis_visible
totrue
if it wasfalse
.
Only emitstoggled
if indeed changed.toggle() -> void
- change theis_visible
value to the opposite and emitstoggled
.submit(expression: String) -> void
- submit user input for parsing.log(msg: String) -> void
- appendsmsg
tolog_text
and emitslogged
.info(msg: String) -> void
- wrapsmsg
with color BBCode and callslog
.debug(msg: String) -> void
- wrapsmsg
with color BBCode and callslog
.warn(msg: String) -> void
- wrapsmsg
with color BBCode and callslog
.error(msg: String) -> void
- wrapsmsg
with color BBCode and callslog
.
Commands:
help [name1, name2, ...]
- collect and display the currently available CVARs and CMDs.
If any optional parametersnameN
are provided, the console will
only display the matching info.exec name[.ext]
- executes a config script line-by-line.alias [name, "any text"]
- without arguments it will list all available aliases.
If only name is given, it will erase the alias. If the alias text is also provided,
then it will be stored for future use under that name.echo "any text"
- logs back the given text.map [name]
- if called without arguments, shows the current scene name. With an argument,
it will try to change scene to the given one (by path). E.g.map a/b/c
-> change
scene tores://a/b/c.tscn
. The.tscn
suffix is optional for this command.mainscene
- immediately switch to the project's main scene, as per project settings.quit
- immediately closes the application.wait
- a special command to postpone the execution by 1 tick. This makes most sense
together withalias
and some frame-by-frame logic. For example,
cmd1; wait; cmd2
- the two commands will be executed on different frames.
GsomConsolePanel
The default UI console panel (like Half-Life 1 Steam),
available as a descendant of Control
node.
Properties
float blur
[default: 0.6] [property: setter, getter] -
Background blur intensity. Blur is only visible whilecolor.a
is below 1.Color color
[default: Color(0.1, 0.1, 0.1, 0.4)] [property: setter, getter] -
Panel background color. When alpha is 0 - only blur applied, if 1 no blur visible.String label_window
[default: "Console"] [property: setter, getter] -
The window title displayed at the top left corner.String label_submit
[default: "submit"] [property: setter, getter] -
The label on "submit" button at the bottom right.bool is_resize_enabled
[default: true] [property: setter, getter] -
Makes window borders draggable.bool is_draggable
[default: true] [property: setter, getter] -
Makes window panel draggable.bool is_disabled
[default: false] [property: setter, getter] -
Hides this console UI regardless of the singleton visibility state.
GsomPlaquePanel
The plaque-mode UI (like Q1, Serious Sam),
available as a descendant of Control
node.
Properties
float blur
[default: 0.6] [property: setter, getter] -
Background blur intensity. Blur is only visible whilecolor.a
is below 1.Color color
[default: Color(0.1, 0.1, 0.1, 0.4)] [property: setter, getter] -
Panel background color. When alpha is 0 - only blur applied, if 1 no blur visible.String label_submit
[default: "submit"] [property: setter, getter] -
The label on "submit" button at the bottom right.bool is_resize_enabled
[default: true] [property: setter, getter] -
Makes window borders draggable.bool is_disabled
[default: false] [property: setter, getter] -
Hides this console UI regardless of the singleton visibility state.
Future Work / Contributions
The development focus of this plugin is following:
- Consider allowing the
+/-
commands if that is going to work at all. - Add components: log overlay, bottom-left console (TES Oblivion/Skyrim).
- Expand component options: colors, verbosity/log levels - maybe also
add cvars that control those on runtime. - Improve autocompletion/matching and hints.
- Think about some generic commands/cvars that are relevant for ALL projects.
Download
Support
If you need help or have questions about this plugin, please contact the author.
Contact Author