mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-22 20:32:38 +01:00
Add a terminal
This commit is contained in:
parent
6e62e80ea0
commit
2f94af8e60
3 changed files with 62 additions and 12 deletions
29
main.gd
29
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:
|
||||
|
|
28
main.tscn
28
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"]
|
||||
|
|
17
terminal.gd
Normal file
17
terminal.gd
Normal 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
|
Loading…
Reference in a new issue