mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-22 16:20:19 +01:00
Show index, show refs and symrefs
This commit is contained in:
parent
0059b7b196
commit
4e45330ad0
7 changed files with 183 additions and 36 deletions
5
arrow.gd
5
arrow.gd
|
@ -7,9 +7,12 @@ func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var t = get_node("../..").objects[target]
|
var t = get_node("/root/Main").objects[target]
|
||||||
|
#print(t)
|
||||||
$Line.points[1] = t.position - global_position
|
$Line.points[1] = t.position - global_position
|
||||||
$Label.position = ($Line.points[0] + $Line.points[1])/2
|
$Label.position = ($Line.points[0] + $Line.points[1])/2
|
||||||
|
$Tip.position = ($Line.points[0] + $Line.points[1])/2
|
||||||
|
$Tip.rotation = PI+$Line.points[0].angle_to($Line.points[1])
|
||||||
|
|
||||||
func label_set(new_label):
|
func label_set(new_label):
|
||||||
label = new_label
|
label = new_label
|
||||||
|
|
12
arrow.tscn
12
arrow.tscn
|
@ -7,7 +7,17 @@ script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="Line" type="Line2D" parent="."]
|
[node name="Line" type="Line2D" parent="."]
|
||||||
z_index = -1
|
z_index = -1
|
||||||
points = PoolVector2Array( -0.480499, -0.11055, 205.769, 94.6112 )
|
points = PoolVector2Array( -0.480499, -0.11055, 158.301, 0.581757 )
|
||||||
|
default_color = Color( 0.447059, 0.447059, 0.447059, 1 )
|
||||||
|
|
||||||
|
[node name="Tip" type="Node2D" parent="."]
|
||||||
|
position = Vector2( 149.835, 0.290878 )
|
||||||
|
|
||||||
|
[node name="Polygon" type="Polygon2D" parent="Tip"]
|
||||||
|
position = Vector2( -9.66138, -2.89842 )
|
||||||
|
z_index = -1
|
||||||
|
color = Color( 0.447059, 0.447059, 0.447059, 1 )
|
||||||
|
polygon = PoolVector2Array( -19.8744, 17.0372, 47.7551, 11.8845, -10.5351, -21.2861 )
|
||||||
|
|
||||||
[node name="Label" type="Node2D" parent="."]
|
[node name="Label" type="Node2D" parent="."]
|
||||||
position = Vector2( 102, 46 )
|
position = Vector2( 102, 46 )
|
||||||
|
|
147
main.gd
147
main.gd
|
@ -4,43 +4,102 @@ var node = preload("res://node.tscn")
|
||||||
|
|
||||||
var objects = {}
|
var objects = {}
|
||||||
|
|
||||||
|
var dragged = null
|
||||||
|
|
||||||
|
var viewport_size
|
||||||
|
|
||||||
func _ready():
|
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()
|
||||||
|
|
||||||
|
update_head()
|
||||||
|
update_refs()
|
||||||
|
update_index()
|
||||||
|
update_objects()
|
||||||
|
apply_forces()
|
||||||
|
|
||||||
|
func update_index():
|
||||||
|
$Index.text = git("ls-files")
|
||||||
|
|
||||||
|
func update_objects():
|
||||||
for o in all_objects():
|
for o in all_objects():
|
||||||
|
if objects.has(o):
|
||||||
|
continue
|
||||||
var n = node.instance()
|
var n = node.instance()
|
||||||
n.id = o
|
n.id = o
|
||||||
n.type = object_type(o)
|
n.type = object_type(o)
|
||||||
n.content = object_content(o)
|
n.content = object_content(o)
|
||||||
var viewport_size = get_viewport_rect().size
|
|
||||||
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
|
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
|
||||||
|
|
||||||
print(" ")
|
if true:
|
||||||
print(o)
|
#print(" ")
|
||||||
var type = object_type(o)
|
#print(o)
|
||||||
print(type)
|
var type = object_type(o)
|
||||||
#print(object_content(o))
|
#print(type)
|
||||||
match type:
|
#print(object_content(o))
|
||||||
"blob":
|
match type:
|
||||||
pass
|
"blob":
|
||||||
"tree":
|
pass
|
||||||
print("Children:")
|
"tree":
|
||||||
print(tree_children(o))
|
#print("Children:")
|
||||||
n.children = tree_children(o)
|
#print(tree_children(o))
|
||||||
"commit":
|
n.children = tree_children(o)
|
||||||
print("Tree:")
|
"commit":
|
||||||
print(commit_tree(o))
|
#print("Tree:")
|
||||||
|
#print(commit_tree(o))
|
||||||
print("Parents:")
|
|
||||||
print(commit_parents(o))
|
#print("Parents:")
|
||||||
|
#print(commit_parents(o))
|
||||||
n.children = [commit_tree(o)] + commit_parents(o)
|
|
||||||
|
var c = {}
|
||||||
|
c[commit_tree(o)] = ""
|
||||||
|
for p in commit_parents(o):
|
||||||
|
c[p] = ""
|
||||||
|
n.children = c
|
||||||
add_child(n)
|
add_child(n)
|
||||||
objects[o] = n
|
objects[o] = n
|
||||||
|
|
||||||
|
func update_refs():
|
||||||
|
for r in all_refs():
|
||||||
|
if not objects.has(r):
|
||||||
|
var n = node.instance()
|
||||||
|
n.id = r
|
||||||
|
n.type = "ref"
|
||||||
|
n.content = ""
|
||||||
|
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
|
||||||
|
objects[r] = n
|
||||||
|
add_child(n)
|
||||||
|
var n = objects[r]
|
||||||
|
n.children = {ref_id(r): ""}
|
||||||
|
|
||||||
|
func apply_forces():
|
||||||
|
for o in objects.values():
|
||||||
|
for o2 in objects.values():
|
||||||
|
if o == o2:
|
||||||
|
continue
|
||||||
|
var d = o.position.distance_to(o2.position)
|
||||||
|
var dir = (o.global_position - o2.global_position).normalized()
|
||||||
|
var f = 3000/pow(d+0.00001,1.5)
|
||||||
|
o.position += dir*f
|
||||||
|
o2.position -= dir*f
|
||||||
|
|
||||||
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/wip/wurst-day-ever")
|
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]
|
||||||
|
@ -51,6 +110,26 @@ func git(args, splitlines = false):
|
||||||
o = o.substr(0,len(o)-1)
|
o = o.substr(0,len(o)-1)
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
func update_head():
|
||||||
|
if not objects.has("HEAD"):
|
||||||
|
var n = node.instance()
|
||||||
|
n.id = "HEAD"
|
||||||
|
n.type = "head"
|
||||||
|
n.content = ""
|
||||||
|
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
|
||||||
|
objects["HEAD"] = n
|
||||||
|
add_child(n)
|
||||||
|
|
||||||
|
n = node.instance()
|
||||||
|
n.id = "refs/heads/master"
|
||||||
|
n.type = "ref"
|
||||||
|
n.content = ""
|
||||||
|
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
|
||||||
|
objects[n.id] = n
|
||||||
|
add_child(n)
|
||||||
|
var n = objects["HEAD"]
|
||||||
|
n.children = {symref_target("HEAD"): ""}
|
||||||
|
|
||||||
func all_objects():
|
func all_objects():
|
||||||
return git("cat-file --batch-check=%(objectname) --batch-all-objects", true)
|
return git("cat-file --batch-check=%(objectname) --batch-all-objects", true)
|
||||||
|
|
||||||
|
@ -62,10 +141,10 @@ func object_content(id):
|
||||||
|
|
||||||
func tree_children(id):
|
func tree_children(id):
|
||||||
var children = git("cat-file -p "+id, true)
|
var children = git("cat-file -p "+id, true)
|
||||||
var ids = []
|
var ids = {}
|
||||||
for c in children:
|
for c in children:
|
||||||
var a = c.split(" ")
|
var a = c.split(" ")
|
||||||
ids.push_back(a[2].split("\t")[0])
|
ids[a[2].split("\t")[0]] = a[2].split("\t")[1]
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
func commit_tree(id):
|
func commit_tree(id):
|
||||||
|
@ -86,3 +165,21 @@ func commit_parents(id):
|
||||||
"parent":
|
"parent":
|
||||||
parents.push_back(ccc[1])
|
parents.push_back(ccc[1])
|
||||||
return parents
|
return parents
|
||||||
|
|
||||||
|
func all_refs():
|
||||||
|
var refs = []
|
||||||
|
for line in git("show-ref", true):
|
||||||
|
line = line.split(" ")
|
||||||
|
var id = line[0]
|
||||||
|
var name = line[1]
|
||||||
|
refs.push_back(name)
|
||||||
|
return refs
|
||||||
|
|
||||||
|
func ref_id(ref):
|
||||||
|
return git("show-ref "+ref).split(" ")[0]
|
||||||
|
|
||||||
|
func symref_target(symref):
|
||||||
|
var ret = git("symbolic-ref -q "+symref)
|
||||||
|
if ret != "":
|
||||||
|
return ret
|
||||||
|
return git("show-ref --head "+symref).split(" ")[0]
|
||||||
|
|
21
main.tscn
21
main.tscn
|
@ -4,3 +4,24 @@
|
||||||
|
|
||||||
[node name="Main" type="Node2D"]
|
[node name="Main" type="Node2D"]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Index" type="Label" parent="."]
|
||||||
|
margin_left = 35.0
|
||||||
|
margin_top = 120.0
|
||||||
|
margin_right = 374.0
|
||||||
|
margin_bottom = 1044.0
|
||||||
|
text = "file1
|
||||||
|
file2"
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="IndexLabel" type="Label" parent="."]
|
||||||
|
margin_left = 38.0
|
||||||
|
margin_top = 69.0
|
||||||
|
margin_right = 377.0
|
||||||
|
margin_bottom = 108.0
|
||||||
|
text = "Index:"
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
27
node.gd
27
node.gd
|
@ -4,7 +4,7 @@ var id setget id_set
|
||||||
var content setget content_set
|
var content setget content_set
|
||||||
var type setget type_set
|
var type setget type_set
|
||||||
|
|
||||||
var children = [] setget children_set
|
var children = {} setget children_set
|
||||||
|
|
||||||
var arrow = preload("res://arrow.tscn")
|
var arrow = preload("res://arrow.tscn")
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@ func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
for c in children:
|
for c in children.keys():
|
||||||
var other = get_node("..").objects[c]
|
var other = get_node("..").objects[c]
|
||||||
var d = other.position.distance_to(position)
|
var d = other.position.distance_to(position)
|
||||||
var dir = (other.position - position).normalized()
|
var dir = (other.position - position).normalized()
|
||||||
var f = ((d-400)*0.01)
|
var f = (d*0.05)
|
||||||
position += dir*f
|
position += dir*f
|
||||||
other.position -= dir*f
|
other.position -= dir*f
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@ func content_set(new_content):
|
||||||
|
|
||||||
func type_set(new_type):
|
func type_set(new_type):
|
||||||
type = new_type
|
type = new_type
|
||||||
$ID.text = new_type + " " + $ID.text.substr(0,8)
|
if type != "ref":
|
||||||
|
$ID.text = $ID.text.substr(0,8)
|
||||||
match new_type:
|
match new_type:
|
||||||
"blob":
|
"blob":
|
||||||
$Rect.color = Color.gray
|
$Rect.color = Color.gray
|
||||||
|
@ -40,14 +41,22 @@ func type_set(new_type):
|
||||||
$Rect.color = Color.orange
|
$Rect.color = Color.orange
|
||||||
"tag":
|
"tag":
|
||||||
$Rect.color = Color.blue
|
$Rect.color = Color.blue
|
||||||
|
"ref":
|
||||||
|
$Rect.color = Color("#6680ff")
|
||||||
|
"head":
|
||||||
|
$Rect.color = Color.red
|
||||||
|
|
||||||
func children_set(new_children):
|
func children_set(new_children):
|
||||||
|
for c in $Arrows.get_children():
|
||||||
|
if not new_children.has(c.target):
|
||||||
|
c.queue_free()
|
||||||
|
for c in new_children:
|
||||||
|
if not children.has(c):
|
||||||
|
var a = arrow.instance()
|
||||||
|
a.label = new_children[c]
|
||||||
|
a.target = c
|
||||||
|
$Arrows.add_child(a)
|
||||||
children = new_children
|
children = new_children
|
||||||
for c in children:
|
|
||||||
var a = arrow.instance()
|
|
||||||
a.label = "test"
|
|
||||||
a.target = c
|
|
||||||
add_child(a)
|
|
||||||
|
|
||||||
func _on_hover():
|
func _on_hover():
|
||||||
$Content.visible = true
|
$Content.visible = true
|
||||||
|
|
|
@ -46,5 +46,7 @@ __meta__ = {
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area"]
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
|
[node name="Arrows" type="Node2D" parent="."]
|
||||||
[connection signal="mouse_entered" from="Area" to="." method="_on_hover"]
|
[connection signal="mouse_entered" from="Area" to="." method="_on_hover"]
|
||||||
[connection signal="mouse_exited" from="Area" to="." method="_on_unhover"]
|
[connection signal="mouse_exited" from="Area" to="." method="_on_unhover"]
|
||||||
|
|
|
@ -55,3 +55,8 @@ down={
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
click={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue