Basic visualization

This commit is contained in:
Sebastian Morr 2020-03-18 16:20:55 +01:00
parent 1d6fdb9b8a
commit 89b96f24d5
6 changed files with 128 additions and 7 deletions

19
arrow.gd Normal file
View file

@ -0,0 +1,19 @@
extends Node2D
var label = "label" setget label_set
var target = Vector2(0,0) setget target_set
func _ready():
pass
func _process(delta):
var t = get_node("../..").objects[target]
$Line.points[1] = t.position - global_position
$Label.position = ($Line.points[0] + $Line.points[1])/2
func label_set(new_label):
label = new_label
$Label/ID.text = label
func target_set(new_target):
target = new_target

24
arrow.tscn Normal file
View file

@ -0,0 +1,24 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://arrow.gd" type="Script" id=1]
[node name="Arrow" type="Node2D"]
script = ExtResource( 1 )
[node name="Line" type="Line2D" parent="."]
z_index = -1
points = PoolVector2Array( -0.480499, -0.11055, 205.769, 94.6112 )
[node name="Label" type="Node2D" parent="."]
position = Vector2( 102, 46 )
[node name="ID" type="Label" parent="Label"]
margin_left = -19.374
margin_top = -5.93085
margin_right = 20.626
margin_bottom = 8.06915
text = "label"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}

19
main.gd
View file

@ -1,7 +1,17 @@
extends Node2D
var node = preload("res://node.tscn")
var objects = {}
func _ready():
for o in all_objects():
var n = node.instance()
n.id = o
n.type = object_type(o)
var viewport_size = get_viewport_rect().size
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
print(" ")
print(o)
var type = object_type(o)
@ -13,18 +23,23 @@ func _ready():
"tree":
print("Children:")
print(tree_children(o))
n.children = tree_children(o)
"commit":
print("Tree:")
print(commit_tree(o))
print("Parents:")
print(commit_parents(o))
n.children = [commit_tree(o)] + commit_parents(o)
add_child(n)
objects[o] = n
func git(args, splitlines = false):
var output = []
var a = args.split(" ")
a.insert(0, "-C")
a.insert(1, "/home/seb/tmp/godotgit")
#a.insert(0, "-C")
#a.insert(1, "/home/seb/tmp/godotgit")
#print ("Running: ", a)
OS.execute("git", a, true, output, true)
var o = output[0]

View file

@ -1,10 +1,6 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=2 format=2]
[ext_resource path="res://player.tscn" type="PackedScene" id=1]
[ext_resource path="res://main.gd" type="Script" id=2]
[node name="Main" type="Node2D"]
script = ExtResource( 2 )
[node name="Player" parent="." instance=ExtResource( 1 )]
position = Vector2( 960, 540 )

40
node.gd Normal file
View file

@ -0,0 +1,40 @@
extends Node2D
var id setget id_set
var type setget type_set
var children = [] setget children_set
var arrow = preload("res://arrow.tscn")
func _ready():
pass
func _process(delta):
pass
func id_set(new_id):
id = new_id
$ID.text = id
func type_set(new_type):
type = new_type
$ID.text = new_type + " " + $ID.text.substr(0,8)
match new_type:
"blob":
$Rect.color = Color.gray
"tree":
$Rect.color = Color.darkgreen
"commit":
$Rect.color = Color.orange
"tag":
$Rect.color = Color.blue
func children_set(new_children):
children = new_children
for c in children:
var a = arrow.instance()
a.label = "test"
a.target = c
add_child(a)

27
node.tscn Normal file
View file

@ -0,0 +1,27 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://node.gd" type="Script" id=1]
[node name="Node" type="Node2D"]
script = ExtResource( 1 )
[node name="Rect" type="ColorRect" parent="."]
margin_left = -62.0578
margin_top = -20.6286
margin_right = 61.9422
margin_bottom = 21.3714
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ID" type="Label" parent="."]
margin_left = -57.0578
margin_top = -7.6286
margin_right = 58.9422
margin_bottom = 16.3714
custom_colors/font_color = Color( 0, 0, 0, 1 )
text = "object_id"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}