mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-22 16:20:19 +01:00
Basic visualization
This commit is contained in:
parent
1d6fdb9b8a
commit
89b96f24d5
6 changed files with 128 additions and 7 deletions
19
arrow.gd
Normal file
19
arrow.gd
Normal 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
24
arrow.tscn
Normal 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
19
main.gd
|
@ -1,7 +1,17 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
|
var node = preload("res://node.tscn")
|
||||||
|
|
||||||
|
var objects = {}
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
for o in all_objects():
|
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(" ")
|
||||||
print(o)
|
print(o)
|
||||||
var type = object_type(o)
|
var type = object_type(o)
|
||||||
|
@ -13,6 +23,7 @@ func _ready():
|
||||||
"tree":
|
"tree":
|
||||||
print("Children:")
|
print("Children:")
|
||||||
print(tree_children(o))
|
print(tree_children(o))
|
||||||
|
n.children = tree_children(o)
|
||||||
"commit":
|
"commit":
|
||||||
print("Tree:")
|
print("Tree:")
|
||||||
print(commit_tree(o))
|
print(commit_tree(o))
|
||||||
|
@ -20,11 +31,15 @@ func _ready():
|
||||||
print("Parents:")
|
print("Parents:")
|
||||||
print(commit_parents(o))
|
print(commit_parents(o))
|
||||||
|
|
||||||
|
n.children = [commit_tree(o)] + commit_parents(o)
|
||||||
|
add_child(n)
|
||||||
|
objects[o] = n
|
||||||
|
|
||||||
func git(args, splitlines = false):
|
func git(args, splitlines = false):
|
||||||
var output = []
|
var output = []
|
||||||
var a = args.split(" ")
|
var a = args.split(" ")
|
||||||
a.insert(0, "-C")
|
#a.insert(0, "-C")
|
||||||
a.insert(1, "/home/seb/tmp/godotgit")
|
#a.insert(1, "/home/seb/tmp/godotgit")
|
||||||
#print ("Running: ", a)
|
#print ("Running: ", a)
|
||||||
OS.execute("git", a, true, output, true)
|
OS.execute("git", a, true, output, true)
|
||||||
var o = output[0]
|
var o = output[0]
|
||||||
|
|
|
@ -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]
|
[ext_resource path="res://main.gd" type="Script" id=2]
|
||||||
|
|
||||||
[node name="Main" type="Node2D"]
|
[node name="Main" type="Node2D"]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource( 1 )]
|
|
||||||
position = Vector2( 960, 540 )
|
|
||||||
|
|
40
node.gd
Normal file
40
node.gd
Normal 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
27
node.tscn
Normal 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
|
||||||
|
}
|
Loading…
Reference in a new issue