From 39702646dc9c9f693d5cec73a8f942385c8f2680 Mon Sep 17 00:00:00 2001 From: Leroy Hopson Date: Sat, 3 Jul 2021 20:44:51 +0700 Subject: [PATCH] Add namespace Adds a globally unique namespace `GDXterm` that can be used to conveniently access scripts. --- addons/godot_xterm/namespace.gd | 5 +++++ examples/menu/menu.gd | 8 +++----- examples/terminal/terminal.gd | 2 +- project.godot | 12 +++++++++++- 4 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 addons/godot_xterm/namespace.gd diff --git a/addons/godot_xterm/namespace.gd b/addons/godot_xterm/namespace.gd new file mode 100644 index 0000000..8e0375c --- /dev/null +++ b/addons/godot_xterm/namespace.gd @@ -0,0 +1,5 @@ +class_name GDXterm + +const Terminal := preload("./nodes/terminal/terminal.gd") +const PTYUnix := preload("./nodes/pty/unix/pty_unix.gd") +const TPut := preload("./util/tput.gd") diff --git a/examples/menu/menu.gd b/examples/menu/menu.gd index f3d9c94..38e15cc 100644 --- a/examples/menu/menu.gd +++ b/examples/menu/menu.gd @@ -8,8 +8,6 @@ extends Control # - https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html # - https://www.youtube.com/watch?v=jTSQlIK_92w -const TPut := preload("res://addons/godot_xterm/util/tput.gd") - # Title generated using command: toilet -f pagga GODOT XTERM const TITLE = """ ░█▀▀░█▀█░█▀▄░█▀█░▀█▀░░░█░█░▀█▀░█▀▀░█▀▄░█▄█\r @@ -38,7 +36,7 @@ var row: int var menu_start_row: int var offset: int -onready var tput = TPut.new($Terminal) +onready var tput = GDXterm.TPut.new($Terminal) func _ready(): @@ -105,10 +103,10 @@ func draw_menu(): func _on_Terminal_key_pressed(data: String, event: InputEventKey) -> void: match data: - TPut.CURSOR_UP: # Up arrow key + tput.CURSOR_UP: # Up arrow key selected_index = int(clamp(selected_index - 1, 0, menu_items.size() - 1)) draw_menu() - TPut.CURSOR_DOWN: # Down arrow key + tput.CURSOR_DOWN: # Down arrow key selected_index = int(clamp(selected_index + 1, 0, menu_items.size() - 1)) draw_menu() "1": diff --git a/examples/terminal/terminal.gd b/examples/terminal/terminal.gd index 901567a..851ac19 100644 --- a/examples/terminal/terminal.gd +++ b/examples/terminal/terminal.gd @@ -1,4 +1,4 @@ -extends "res://addons/godot_xterm/nodes/terminal/terminal.gd" +extends GDXterm.Terminal onready var pty = $PTY diff --git a/project.godot b/project.godot index 04abc27..4eebafa 100644 --- a/project.godot +++ b/project.godot @@ -8,6 +8,16 @@ config_version=4 +_global_script_classes=[ { +"base": "Reference", +"class": "GDXterm", +"language": "GDScript", +"path": "res://addons/godot_xterm/namespace.gd" +} ] +_global_script_class_icons={ +"GDXterm": "" +} + [application] config/name="Godot Xterm" @@ -20,7 +30,7 @@ window/vsync/use_vsync=false [editor_plugins] -enabled=PoolStringArray( "res://addons/godot_xterm/plugin.cfg", "res://addons/gut/plugin.cfg" ) +enabled=PoolStringArray( "res://addons/godot_xterm/plugin.cfg" ) [rendering]