Skip to content

Commit 0487f67

Browse files
authored
Merge pull request #21 from XanatosX/develop
Prototype 0.3.1
2 parents 196ad01 + 89b4321 commit 0487f67

File tree

9 files changed

+54
-50
lines changed

9 files changed

+54
-50
lines changed

addons/gameconsole/builtin/command_help.gd

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@ var list_command_executer: Interaction
44
var enter_man_command: Interaction
55

66
func _init():
7-
list_command_executer = Interaction.new()
8-
list_command_executer.from_raw("execute", "list_commands")
9-
10-
enter_man_command = Interaction.new()
11-
enter_man_command.from_raw("enter", "man")
7+
list_command_executer = Interaction.new()
8+
list_command_executer.from_raw("execute", "list_commands")
9+
10+
enter_man_command = Interaction.new()
11+
enter_man_command.from_raw("enter", "man")
1212

1313
func create_command() -> Command:
14-
var command = Command.new("help", _get_help, [], "Get help for this console")
15-
return command
14+
var command = Command.new("help", _get_help, [], "Get help for this console")
15+
return command
1616

1717
func _get_help() -> String:
18-
var config = Console.get_plugin_config()
19-
var section = config.get_sections()[0]
20-
var addon_name = config.get_value(section, "name")
21-
var author_name = config.get_value(section, "author")
22-
var version = config.get_value(section, "version")
23-
var return_data = "[center][b]%s[/b] by %s[/center]\n" % [addon_name, author_name] \
24-
+ "[center]%s[/center]\n" % version \
25-
+ _get_description() \
26-
+ "[center][url=%s]List commands[/url][/center]" % list_command_executer.get_as_string()
27-
return return_data
18+
var information = Console.get_console_information()
19+
20+
var addon_name = information.get_or_add("name", "UNKNOWN KEY: name")
21+
var author_list = information.get_or_add("authors", "UNKNOWN KEY: author")
22+
var version = information.get_or_add("version", "UNKNOWN KEY: version")
23+
24+
var return_data = "[center][b][font_size=20]%s[/font_size][/b][/center]" % addon_name \
25+
+ "[center][font_size=10]by %s[/font_size][/center]\n" % author_list \
26+
+ "[center][font_size=10]Version: %s[/font_size][/center]\n" % version \
27+
+ _get_description() \
28+
+ "[center][url=%s]List commands[/url][/center]" % list_command_executer.get_as_string()
29+
return return_data
2830

2931
func _get_description() -> String:
30-
return "[center]This addon does allow you to run built in or custom commands for your game.\n" \
31-
+ " If you need help run the [url=%s]man[/url] command followed by the command you need help with.\n" % enter_man_command.get_as_string() \
32-
+ " Also if text is underlined you might be able to click it, test the \"[u]List Commands[/u]\" below [/center]\n\n"
32+
return "\n[p][center]This addon does allow you to run built in or custom commands for your game.\n" \
33+
+ " If you need help run the [url=%s]man[/url] command followed by the command you need help with.\n" % enter_man_command.get_as_string() \
34+
+ " Also if text is underlined you might be able to click it, test the \"[u]List Commands[/u]\" below [/center][/p]\n\n"

addons/gameconsole/builtin/command_list_commands.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ func _list_commands() -> String:
99
var built_in = commands.filter(func(command): return command.built_in) as Array[Command]
1010
var custom = commands.filter(func(command): return !command.built_in) as Array[Command]
1111
var return_data = "[color=yellow][b]All commands[/b][/color]\n"
12-
return_data += "[u]Built In[/u]\n"
12+
return_data += "\n[p][b]Built In[/b][/p]\n"
1313
return_data += _generate_command_list(built_in)
14-
return_data += "\n[u]Custom[/u]\n"
14+
return_data += "\n[p][b]Custom[/b][/p]\n"
1515
return_data += _generate_command_list(custom)
1616
return return_data
1717

1818
func _generate_command_list(commands: Array) -> String:
1919
commands.sort_custom(_sort_commands)
20-
var return_data = "";
20+
var cell_data = "";
2121
for command in commands:
2222
if command is Command:
23-
return_data += command.get_self_listed()
23+
cell_data += "[cell][left]%s[/left][/cell][cell][right] %s[/right][/cell]" % [command.get_interactive_command(), command.get_command_short_description()]
2424

25-
return return_data
25+
return "\n[p][table=2][cell][i]Command[/i][/cell][cell][right][i]Description[/i][/right][/cell]%s[/table][/p]\n" % cell_data
2626

2727
func _sort_commands(a: Command, b: Command) -> bool:
2828
return a.command < b.command

addons/gameconsole/builtin/command_quit_game.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extends CommandTemplate
33
func create_command() -> Command:
44
if OS.has_feature("web"):
55
return null
6-
var command = Command.new("quit", _quit_game, [], "quit the game")
6+
var command = Command.new("quit", _quit_game, [], "quit the game, this only works on non web builds")
77
command.built_in
88
return command
99

addons/gameconsole/console/command/command.gd

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ func execute(arguments: Array) -> String:
4747
data = ""
4848
return data
4949

50-
func get_self_listed():
50+
func get_interactive_command():
5151
var url_part = "[url=%s]" % self_man_link.get_as_string()
52-
var return_data = "- %s%s %s[/url]" % [url_part, get_command_name(), get_arguments()]
53-
if short_description != "":
54-
return_data += " => %s" % short_description
55-
56-
return_data += "\n"
57-
return return_data
52+
return "%s%s %s[/url]" % [url_part, get_command_name(), get_arguments()]
53+
54+
func get_command_short_description():
55+
return short_description
5856

5957
func get_arguments() -> String:
6058
var return_arguments = ""
@@ -76,14 +74,19 @@ func get_man_page() -> String:
7674
description_to_show = short_description
7775
return_text += "%s\n" % description_to_show
7876
if arguments.size() > 0:
79-
return_text += "\n[i][b]Arguments[/b][/i]\n"
77+
return_text += "\n[i][b]Arguments[/b][/i]\n\n"
78+
return_text += "[ul]"
8079
for argument in arguments:
81-
return_text += "- %s\n" % argument
80+
return_text += "%s\n" % argument
81+
return_text += "[/ul]"
8282
if examples.size() > 0:
83-
return_text += "\n[i][b]Examples[/b][/i]\n"
83+
return_text += "\n\n[i][b]Examples[/b][/i]\n\n"
84+
return_text += "[ul]"
8485
for example in examples:
8586
var link = self_example_links[example] as Interaction
87+
8688
var example_url = "[url=%s]" % link.get_as_string()
87-
return_text += "- %s%s[/url]\n" % [example_url, example]
89+
return_text += "%s%s[/url]\n" % [example_url, example]
90+
return_text += "[/ul]"
8891

8992
return return_text

addons/gameconsole/console/console.gd

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ signal copy_command_to_input(command: String)
1010
signal unknown_interaction_request(interaction: Interaction)
1111

1212
@onready var console_template: PackedScene = preload("res://addons/gameconsole/console/console/default_console_template.tscn")
13-
var config_file = "res://addons/gameconsole/plugin.cfg"
14-
var _plugin_config: ConfigFile = null
1513

1614
var _console_commands := {}
1715
var _used_template: PackedScene
@@ -26,18 +24,20 @@ var _last_state: bool = false
2624
var _stored_console_content: String = ""
2725
var _console_key: int = KEY_QUOTELEFT
2826
var _first_time_open: bool = true
27+
var _console_information := {
28+
"name": "Game Console",
29+
"authors": "Xanatos",
30+
"version": "0.3.1"
31+
}
2932

3033
func _ready():
3134
_preregister_commands()
3235
add_child(_overlay_node)
3336
_used_template = console_template
3437
process_mode = PROCESS_MODE_ALWAYS
35-
_plugin_config = ConfigFile.new()
36-
if _plugin_config.load(config_file) != OK:
37-
printerr("addon config not loaded correctly")
3838

39-
func get_plugin_config() -> ConfigFile:
40-
return _plugin_config
39+
func get_console_information() -> Dictionary:
40+
return _console_information
4141

4242
func should_pause_on_open(pause: bool):
4343
_should_pause = pause
@@ -173,7 +173,7 @@ func _register_commands_in_directory(directory: String):
173173
var loaded_scripts: Array[Resource]
174174
var files = dir.get_files()
175175
for file in files:
176-
if !file.ends_with(".gd"):
176+
if !file.ends_with(".gd") and !file.ends_with(".gdc"):
177177
continue
178178
var path = directory + file
179179
var script = load(path)
@@ -236,8 +236,6 @@ func get_specific_command(command_name: String) -> Command:
236236

237237
func url_requested(interaction: Interaction):
238238
match interaction.get_type():
239-
"UNKNOWN":
240-
search_and_execute_command("man list_commands")
241239
"man":
242240
search_and_execute_command("man %s" % interaction.get_data())
243241
"enter":

addons/gameconsole/console/console/command_enter.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func _update_selection_text():
5858
text = _current_history[selection]
5959

6060
text_changed.emit(text)
61+
caret_column = text.length()
6162
get_tree().get_root().set_input_as_handled()
6263

6364
func autocomplete_accepted(autocomplete_text: String):

addons/gameconsole/console/console/default_console_template.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ script = ExtResource("2_5ui7n")
1414
process_mode = 3
1515
layer = 20
1616
script = ExtResource("1_wfkix")
17+
autocomplete_service = SubResource("Resource_vkyqv")
1718
console_content_output = NodePath("PanelContainer/MarginContainer/VBoxContainer/ConsoleOutput")
1819
console_input = NodePath("PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/HBoxContainer/ConsoleInput")
1920
console_send_button = NodePath("PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/HBoxContainer/ConsoleSendButton")
20-
autocomplete_service = SubResource("Resource_vkyqv")
2121

2222
[node name="PanelContainer" type="PanelContainer" parent="."]
2323
anchors_preset = 10

addons/gameconsole/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="Game Console"
44
description="Addon to add a console to the game, allowing you to register and run commands."
55
author="Xanatos"
6-
version="0.3.0"
6+
version="0.3.1"
77
script="gameconsole.gd"

example/custom_console_template.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ bg_color = Color(0.136826, 0.136826, 0.136826, 1)
1515

1616
[node name="CustomConsoleTemplate" type="CanvasLayer" node_paths=PackedStringArray("console_content_output", "console_input", "console_send_button")]
1717
script = ExtResource("1_rkm11")
18+
autocomplete_service = SubResource("Resource_lhmvy")
1819
console_content_output = NodePath("PanelContainer/MarginContainer/VBoxContainer/ConsoleOutput")
1920
console_input = NodePath("PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/ConsoleInput")
2021
console_send_button = NodePath("PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/ConsoleSendButton")
21-
autocomplete_service = SubResource("Resource_lhmvy")
2222

2323
[node name="PanelContainer" type="PanelContainer" parent="."]
2424
anchors_preset = 9

0 commit comments

Comments
 (0)