From 2f94af8e60fe84c515e543c3a19b94e8c96a17d0 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Wed, 10 Jun 2020 18:25:41 +0200 Subject: [PATCH] Add a terminal --- main.gd | 29 ++++++++++++++++++----------- main.tscn | 28 +++++++++++++++++++++++++++- terminal.gd | 17 +++++++++++++++++ 3 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 terminal.gd diff --git a/main.gd b/main.gd index 3071104..165858a 100644 --- a/main.gd +++ b/main.gd @@ -12,17 +12,18 @@ func _ready(): viewport_size = get_viewport_rect().size func _process(delta): - if Input.is_action_just_pressed("click"): - var mindist = 9999999 - for o in objects.values(): - var d = o.position.distance_to(get_global_mouse_position()) - if d < mindist: - mindist = d - dragged = o - if Input.is_action_just_released("click"): - dragged = null - if dragged: - dragged.position = get_global_mouse_position() + if true or get_global_mouse_position().x < get_viewport_rect().size.x*0.7: + if Input.is_action_just_pressed("click"): + var mindist = 9999999 + for o in objects.values(): + var d = o.position.distance_to(get_global_mouse_position()) + if d < mindist: + mindist = d + dragged = o + if Input.is_action_just_released("click"): + dragged = null + if dragged: + dragged.position = get_global_mouse_position() update_head() update_refs() @@ -94,11 +95,17 @@ func apply_forces(): var f = 3000/pow(d+0.00001,1.5) o.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): var output = [] var a = args.split(" ") #print ("Running: ", a) + a.insert(0, "-C") + a.insert(1, "/home/seb/tmp/godotgit") OS.execute("git", a, true, output, true) var o = output[0] if splitlines: diff --git a/main.tscn b/main.tscn index 92abd16..471c0dd 100644 --- a/main.tscn +++ b/main.tscn @@ -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] [node name="Main" type="Node2D"] @@ -25,3 +26,28 @@ text = "Index:" __meta__ = { "_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"] diff --git a/terminal.gd b/terminal.gd new file mode 100644 index 0000000..2d27b68 --- /dev/null +++ b/terminal.gd @@ -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