Add a terminal

This commit is contained in:
Sebastian Morr 2020-06-10 18:25:41 +02:00
parent 6e62e80ea0
commit 2f94af8e60
3 changed files with 62 additions and 12 deletions

View file

@ -12,6 +12,7 @@ func _ready():
viewport_size = get_viewport_rect().size viewport_size = get_viewport_rect().size
func _process(delta): func _process(delta):
if true or get_global_mouse_position().x < get_viewport_rect().size.x*0.7:
if Input.is_action_just_pressed("click"): if Input.is_action_just_pressed("click"):
var mindist = 9999999 var mindist = 9999999
for o in objects.values(): for o in objects.values():
@ -94,11 +95,17 @@ func apply_forces():
var f = 3000/pow(d+0.00001,1.5) var f = 3000/pow(d+0.00001,1.5)
o.position += dir*f o.position += dir*f
o2.position -= dir*f o2.position -= dir*f
var d = o.position.distance_to(Vector2(viewport_size.x/3, viewport_size.y/2))
var dir = (o.global_position - Vector2(viewport_size.x/3, viewport_size.y/2)).normalized()
var f = (d+0.00001)*0.02
o.position -= dir*f
func git(args, splitlines = false): func git(args, splitlines = false):
var output = [] var output = []
var a = args.split(" ") var a = args.split(" ")
#print ("Running: ", a) #print ("Running: ", a)
a.insert(0, "-C")
a.insert(1, "/home/seb/tmp/godotgit")
OS.execute("git", a, true, output, true) OS.execute("git", a, true, output, true)
var o = output[0] var o = output[0]
if splitlines: if splitlines:

View file

@ -1,5 +1,6 @@
[gd_scene load_steps=2 format=2] [gd_scene load_steps=3 format=2]
[ext_resource path="res://terminal.gd" type="Script" id=1]
[ext_resource path="res://main.gd" type="Script" id=2] [ext_resource path="res://main.gd" type="Script" id=2]
[node name="Main" type="Node2D"] [node name="Main" type="Node2D"]
@ -25,3 +26,28 @@ text = "Index:"
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Terminal" type="Node2D" parent="."]
visible = false
z_index = 1
script = ExtResource( 1 )
[node name="Output" type="TextEdit" parent="Terminal"]
margin_left = 1416.1
margin_top = 4.0
margin_right = 1915.1
margin_bottom = 1008.0
readonly = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Input" type="LineEdit" parent="Terminal"]
margin_left = 1414.0
margin_top = 1019.0
margin_right = 1913.0
margin_bottom = 1075.0
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="text_entered" from="Terminal/Input" to="Terminal" method="send_command"]

17
terminal.gd Normal file
View file

@ -0,0 +1,17 @@
extends Node2D
func _ready():
pass
func send_command(new_text):
var parts = new_text.split(" ")
var cmd = parts[0]
var args = parts
args.remove(0)
var output = []
OS.execute(cmd, args, true, output, true)
$Input.text = ""
$Output.text = $Output.text + "$ " + new_text + "\n" + output[0]
$Output.scroll_vertical = 999999