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.
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
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.
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.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.get_matches(text: String) -> PackedStringArray
- get a list of CVAR and CMD names that start with the giventext
.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.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.
GsomConsolePanel
The default UI console panel, 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.
Future Work / Contributions
The development focus of this plugin is following:
- Implement scripting logic:
alias
,wait
,;
,exec
. - Consider allowing the
+/-
commands if that is going to work at all. - Add components: top console plaque (Q1, Serious Sam), 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