Skip to content

Commit 6c88d42

Browse files
authored
Merge pull request #3 from XanatosX/develop
Release 0.1.0
2 parents 6afb0a8 + 1ac79d8 commit 6c88d42

33 files changed

+1091
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Normalize EOL for all files that Git considers text files.
2+
* text=auto eol=lf

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Godot 4+ specific ignores
2+
.godot/
3+
4+
# Godot-specific ignores
5+
.import/
6+
export.cfg
7+
export_presets.cfg
8+
9+
# Imported translations (automatically generated from CSV files)
10+
*.translation
11+
12+
# Mono-specific ignores
13+
.mono/
14+
data_*/
15+
mono_crash.*.json
16+
17+
.vscode/

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Godot Game Console
2+
3+
This Godot addon will add a game console to your game. This console can be used to run commands on your game.
4+
5+
To learn how to add and remove custom commands please checkout the example [script][example-gdscript].
6+
7+
I do know there is a addon like this already in development, check it out at the end of this readme. I still wanted to create my own interpretation of this used in games I created. But as I already developed it I decided to make it public and give something back to the Godot developer community.
8+
9+
## How to install
10+
11+
To install the addon download the source files and put the "addons" folder on a root level to your project. After that enable the plugin via the Godot plugin menu.
12+
13+
Checkout this part of the [Godot documentation][installing-and-enable-plugin]
14+
15+
## Example Project
16+
17+
I added a test and example project to this addon so you can check out the console in action. The example is not much but does show the usage in a really basic manner.
18+
19+
## Built in commands
20+
21+
This is a list with build in commands and there purpose
22+
23+
| Name | Description | example |
24+
| ------------- | --------------------------------------------------------------------------------------------------------------------- | ------------- |
25+
| list_commands | This will list all the built in and custom commands currently available | list_commands |
26+
| clear | Clear the output of the console window | clear |
27+
| man | Get a more detailed description of a command, also including examples if any. Requires the command name as a argument | man clear |
28+
| pause | Pause the game by pausing the root tree | pause |
29+
| unpause | unpause the game by unpausing the root | unpause |
30+
| quit | Close the game, does not work on a web build. | quit |
31+
32+
33+
## Thanks to
34+
35+
As this addon is influenced by the godot console addon check it out as well.
36+
37+
- https://github.com/jitspoe/godot-console
38+
39+
[example-gdscript]: ./example/console_example.gd
40+
[installing-and-enable-plugin]: https://docs.godotengine.org/en/stable/tutorials/plugins/editor/installing_plugins.html#enabling-a-plugin
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extends CommandTemplate
2+
3+
func create_command() -> Command:
4+
var command = Command.new("argument not matching", _argument_count_not_matching, ["command_name"], "The provided arguments do not match")
5+
command.is_hidden = true
6+
return command
7+
8+
func _argument_count_not_matching(command_name: String) -> String:
9+
var return_data = "";
10+
var command = Console._console_commands[command_name]
11+
var command_arguments = command.get_arguments()
12+
return_data += "[color=red]The arguments provided do not match the arguments %s of command[/color]" % [command_arguments]
13+
return return_data
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extends CommandTemplate
2+
3+
func create_command() -> Command:
4+
var command = Command.new("_close", _close, [], "_close the console")
5+
return command
6+
7+
func _close() -> String:
8+
Console.hide_console()
9+
return ""
10+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
extends CommandTemplate
2+
3+
func create_command() -> Command:
4+
var command = Command.new("list commands", _list_commands, [], "List all commands", "This command will list all the commands currently available in the console")
5+
return command
6+
7+
func _list_commands() -> String:
8+
var commands = Console.get_all_commands() as Array[Command]
9+
var built_in = commands.filter(func(command): return command.built_in) as Array[Command]
10+
var custom = commands.filter(func(command): return !command.built_in) as Array[Command]
11+
var return_data = "[color=yellow]=== All commands ===[/color]\n"
12+
return_data += "== Built In ==\n"
13+
return_data += _generate_command_list(built_in)
14+
return_data += "\n== Custom ==\n"
15+
return_data += _generate_command_list(custom)
16+
return return_data
17+
18+
func _generate_command_list(commands: Array) -> String:
19+
commands.sort_custom(_sort_commands)
20+
var return_data = "";
21+
for command in commands:
22+
if command is Command:
23+
return_data += command.get_self_listed()
24+
25+
return return_data
26+
27+
func _sort_commands(a: Command, b: Command) -> bool:
28+
return a.command < b.command
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extends CommandTemplate
2+
3+
func create_command() -> Command:
4+
var command = Command.new("man", manual, ["Name of the command"], "Command to get a manual for an command")
5+
return command
6+
7+
func manual(command_name: String) -> String:
8+
var command = Console.get_specific_command(command_name)
9+
if command == null or command.built_in:
10+
return "[color=red]No command with name %s was found[/color]" % command_name
11+
return command.get_man_page()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extends CommandTemplate
2+
3+
func create_command() -> Command:
4+
var command = Command.new("_no_command_provided", _no_command_provided, [], "")
5+
command.is_hidden = true
6+
return command
7+
8+
func _no_command_provided() -> String:
9+
return "[color=red]Please enter a command[/color]"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extends CommandTemplate
2+
3+
func create_command() -> Command:
4+
var command = Command.new("not found", _not_found, ["Command name"], "Command was not found")
5+
command.is_hidden = true
6+
return command
7+
8+
func _not_found(name: String) -> String:
9+
return "[color=red]Command %s was not found[/color]" % name
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extends CommandTemplate
2+
3+
func create_command() -> Command:
4+
var command = Command.new("_pause", _pause, [], "_pause the game")
5+
return command
6+
7+
func _pause() -> String:
8+
Console.get_tree().paused = true
9+
return "[color=red]paused[/color]"
10+

0 commit comments

Comments
 (0)