2020-03-18 15:23:38 +01:00
|
|
|
extends Node2D
|
|
|
|
|
2020-03-18 16:20:55 +01:00
|
|
|
var node = preload("res://node.tscn")
|
|
|
|
|
|
|
|
var objects = {}
|
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
var dragged = null
|
|
|
|
|
|
|
|
var viewport_size
|
|
|
|
|
2020-09-01 15:14:01 +02:00
|
|
|
var server
|
|
|
|
var client_connection
|
|
|
|
|
2020-03-18 15:23:38 +01:00
|
|
|
func _ready():
|
2020-08-24 16:48:30 +02:00
|
|
|
viewport_size = get_viewport_rect().size
|
2020-09-01 15:14:01 +02:00
|
|
|
|
|
|
|
server = TCP_Server.new()
|
|
|
|
server.listen(1234)
|
2020-03-18 20:03:17 +01:00
|
|
|
|
2020-09-01 15:14:01 +02:00
|
|
|
func _connected(id, proto):
|
|
|
|
print("!!!")
|
|
|
|
print(id)
|
|
|
|
|
|
|
|
func _player_connected(id):
|
|
|
|
print("connected")
|
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
func _process(delta):
|
2020-09-01 15:14:01 +02:00
|
|
|
if server.is_connection_available():
|
|
|
|
client_connection = server.take_connection()
|
|
|
|
read_commit_message()
|
2020-08-24 16:48:30 +02:00
|
|
|
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()
|
|
|
|
update_index()
|
|
|
|
update_objects()
|
|
|
|
apply_forces()
|
2020-09-01 15:14:01 +02:00
|
|
|
|
|
|
|
func read_commit_message():
|
|
|
|
$CommitMessage.show()
|
|
|
|
$Terminal/Input.editable = false
|
|
|
|
var file_path = "/tmp/githydragit/.git/COMMIT_EDITMSG"
|
|
|
|
var file = File.new()
|
|
|
|
file.open(file_path, File.READ)
|
|
|
|
var content = file.get_as_text()
|
|
|
|
file.close()
|
|
|
|
$CommitMessage.text = content
|
|
|
|
|
|
|
|
func save_commit_message():
|
|
|
|
var file = File.new()
|
|
|
|
var file_path = "/tmp/githydragit/.git/COMMIT_EDITMSG"
|
|
|
|
file.open(file_path, File.WRITE)
|
|
|
|
var content = $CommitMessage.text
|
|
|
|
file.store_string(content)
|
|
|
|
file.close()
|
|
|
|
print("disconnect")
|
|
|
|
client_connection.disconnect_from_host()
|
|
|
|
$Terminal/Input.editable = true
|
|
|
|
$CommitMessage.text = ""
|
|
|
|
$CommitMessage.hide()
|
2020-08-24 16:48:30 +02:00
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
func update_index():
|
2020-08-24 16:48:30 +02:00
|
|
|
$Index.text = git("ls-files")
|
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
func update_objects():
|
2020-08-24 16:48:30 +02:00
|
|
|
for o in all_objects():
|
|
|
|
if objects.has(o):
|
|
|
|
continue
|
|
|
|
var n = node.instance()
|
|
|
|
n.id = o
|
|
|
|
n.type = object_type(o)
|
|
|
|
n.content = object_content(o)
|
|
|
|
n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y))
|
|
|
|
|
|
|
|
if true:
|
|
|
|
#print(" ")
|
|
|
|
#print(o)
|
|
|
|
var type = object_type(o)
|
|
|
|
#print(type)
|
|
|
|
#print(object_content(o))
|
|
|
|
match type:
|
|
|
|
"blob":
|
|
|
|
pass
|
|
|
|
"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))
|
|
|
|
|
|
|
|
var c = {}
|
|
|
|
c[commit_tree(o)] = ""
|
|
|
|
for p in commit_parents(o):
|
|
|
|
c[p] = ""
|
|
|
|
n.children = c
|
|
|
|
add_child(n)
|
|
|
|
objects[o] = n
|
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
func update_refs():
|
2020-08-24 16:48:30 +02:00
|
|
|
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): ""}
|
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
func apply_forces():
|
2020-08-24 16:48:30 +02:00
|
|
|
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
|
|
|
|
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
|
2020-03-18 15:23:38 +01:00
|
|
|
|
|
|
|
func git(args, splitlines = false):
|
2020-08-24 16:48:30 +02:00
|
|
|
var output = []
|
|
|
|
var a = args.split(" ")
|
|
|
|
#print ("Running: ", a)
|
|
|
|
a.insert(0, "-C")
|
2020-09-01 14:03:18 +02:00
|
|
|
a.insert(1, "/tmp/githydragit")
|
2020-08-24 16:48:30 +02:00
|
|
|
OS.execute("git", a, true, output, true)
|
|
|
|
var o = output[0]
|
2020-09-01 14:03:18 +02:00
|
|
|
|
2020-08-24 16:48:30 +02:00
|
|
|
if splitlines:
|
|
|
|
o = o.split("\n")
|
2020-09-01 14:03:18 +02:00
|
|
|
# Remove last empty line.
|
2020-08-24 16:48:30 +02:00
|
|
|
o.remove(len(o)-1)
|
|
|
|
else:
|
2020-09-01 14:03:18 +02:00
|
|
|
# Remove trailing newline.
|
2020-08-24 16:48:30 +02:00
|
|
|
o = o.substr(0,len(o)-1)
|
|
|
|
return o
|
2020-03-18 15:23:38 +01:00
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
func update_head():
|
2020-08-24 16:48:30 +02:00
|
|
|
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)
|
|
|
|
var n = objects["HEAD"]
|
|
|
|
n.children = {symref_target("HEAD"): ""}
|
2020-03-18 20:03:17 +01:00
|
|
|
|
2020-03-18 15:23:38 +01:00
|
|
|
func all_objects():
|
2020-08-24 16:48:30 +02:00
|
|
|
return git("cat-file --batch-check=%(objectname) --batch-all-objects", true)
|
2020-03-18 15:23:38 +01:00
|
|
|
|
|
|
|
func object_type(id):
|
2020-08-24 16:48:30 +02:00
|
|
|
return git("cat-file -t "+id)
|
2020-03-18 15:23:38 +01:00
|
|
|
|
|
|
|
func object_content(id):
|
2020-08-24 16:48:30 +02:00
|
|
|
return git("cat-file -p "+id)
|
2020-03-18 15:23:38 +01:00
|
|
|
|
|
|
|
func tree_children(id):
|
2020-08-24 16:48:30 +02:00
|
|
|
var children = git("cat-file -p "+id, true)
|
|
|
|
var ids = {}
|
|
|
|
for c in children:
|
|
|
|
var a = c.split(" ")
|
|
|
|
ids[a[2].split("\t")[0]] = a[2].split("\t")[1]
|
|
|
|
return ids
|
2020-03-18 15:23:38 +01:00
|
|
|
|
|
|
|
func commit_tree(id):
|
2020-08-24 16:48:30 +02:00
|
|
|
var c = git("cat-file -p "+id, true)
|
|
|
|
for cc in c:
|
|
|
|
var ccc = cc.split(" ", 2)
|
|
|
|
match ccc[0]:
|
|
|
|
"tree":
|
|
|
|
return ccc[1]
|
|
|
|
return null
|
2020-03-18 15:23:38 +01:00
|
|
|
|
|
|
|
func commit_parents(id):
|
2020-08-24 16:48:30 +02:00
|
|
|
var parents = []
|
|
|
|
var c = git("cat-file -p "+id, true)
|
|
|
|
for cc in c:
|
|
|
|
var ccc = cc.split(" ", 2)
|
|
|
|
match ccc[0]:
|
|
|
|
"parent":
|
|
|
|
parents.push_back(ccc[1])
|
|
|
|
return parents
|
2020-03-18 20:03:17 +01:00
|
|
|
|
|
|
|
func all_refs():
|
2020-08-24 16:48:30 +02:00
|
|
|
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
|
|
|
|
|
2020-03-18 20:03:17 +01:00
|
|
|
func ref_id(ref):
|
2020-08-24 16:48:30 +02:00
|
|
|
return git("show-ref "+ref).split(" ")[0]
|
2020-03-18 20:03:17 +01:00
|
|
|
|
|
|
|
func symref_target(symref):
|
2020-08-24 16:48:30 +02:00
|
|
|
var ret = git("symbolic-ref -q "+symref)
|
|
|
|
if ret != "":
|
|
|
|
return ret
|
|
|
|
return git("show-ref --head "+symref).split(" ")[0]
|