From 89b96f24d5739d76af6d2a0c1ae09b530ccbe9fb Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Wed, 18 Mar 2020 16:20:55 +0100 Subject: [PATCH] Basic visualization --- arrow.gd | 19 +++++++++++++++++++ arrow.tscn | 24 ++++++++++++++++++++++++ main.gd | 19 +++++++++++++++++-- main.tscn | 6 +----- node.gd | 40 ++++++++++++++++++++++++++++++++++++++++ node.tscn | 27 +++++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 arrow.gd create mode 100644 arrow.tscn create mode 100644 node.gd create mode 100644 node.tscn diff --git a/arrow.gd b/arrow.gd new file mode 100644 index 0000000..4a312c4 --- /dev/null +++ b/arrow.gd @@ -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 diff --git a/arrow.tscn b/arrow.tscn new file mode 100644 index 0000000..f0863b5 --- /dev/null +++ b/arrow.tscn @@ -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 +} diff --git a/main.gd b/main.gd index f436dfc..f9ca184 100644 --- a/main.gd +++ b/main.gd @@ -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] diff --git a/main.tscn b/main.tscn index dda2ed6..e1ee0ca 100644 --- a/main.tscn +++ b/main.tscn @@ -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 ) diff --git a/node.gd b/node.gd new file mode 100644 index 0000000..7124958 --- /dev/null +++ b/node.gd @@ -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) diff --git a/node.tscn b/node.tscn new file mode 100644 index 0000000..fdf21fa --- /dev/null +++ b/node.tscn @@ -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 +}