diff --git a/arrow.gd b/arrow.gd index 7e07c58..7f1065e 100644 --- a/arrow.gd +++ b/arrow.gd @@ -4,19 +4,19 @@ var label = "label" setget label_set var target = Vector2(0,0) setget target_set func _ready(): - pass + pass func _process(delta): - var t = get_node("/root/Main").objects[target] - #print(t) - $Line.points[1] = t.position - global_position - $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]) - + var t = get_node("/root/Main").objects[target] + #print(t) + $Line.points[1] = t.position - global_position + $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): - label = new_label - $Label/ID.text = label + label = new_label + $Label/ID.text = label func target_set(new_target): - target = new_target + target = new_target diff --git a/game.gd b/game.gd index 24e1c0e..18758b8 100644 --- a/game.gd +++ b/game.gd @@ -4,29 +4,29 @@ var _file = "user://savegame.json" var state = {} func _ready(): - load_state() - + load_state() + func _initial_state(): - return {} - + return {} + func save_state() -> bool: - var savegame = File.new() - - savegame.open(_file, File.WRITE) - savegame.store_line(to_json(state)) - savegame.close() - return true - + var savegame = File.new() + + savegame.open(_file, File.WRITE) + savegame.store_line(to_json(state)) + savegame.close() + return true + func load_state() -> bool: - var savegame = File.new() - if not savegame.file_exists(_file): - return false - - savegame.open(_file, File.READ) - - state = _initial_state() - var new_state = parse_json(savegame.get_line()) - for key in new_state: - state[key] = new_state[key] - savegame.close() - return true \ No newline at end of file + var savegame = File.new() + if not savegame.file_exists(_file): + return false + + savegame.open(_file, File.READ) + + state = _initial_state() + var new_state = parse_json(savegame.get_line()) + for key in new_state: + state[key] = new_state[key] + savegame.close() + return true diff --git a/main.gd b/main.gd index 165858a..53f8ce9 100644 --- a/main.gd +++ b/main.gd @@ -9,182 +9,182 @@ var dragged = null var viewport_size func _ready(): - viewport_size = get_viewport_rect().size + viewport_size = get_viewport_rect().size func _process(delta): - 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() - + 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() + func update_index(): - $Index.text = git("ls-files") - + $Index.text = git("ls-files") + func update_objects(): - 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 - + 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 + 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): ""} - + 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 - 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 + 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 func git(args, splitlines = false): - var output = [] - var a = args.split(" ") - #print ("Running: ", a) - a.insert(0, "-C") - a.insert(1, "/home/seb/tmp/godotgit") - OS.execute("git", a, true, output, true) - var o = output[0] - if splitlines: - o = o.split("\n") - o.remove(len(o)-1) - else: - o = o.substr(0,len(o)-1) - return o + var output = [] + var a = args.split(" ") + #print ("Running: ", a) + a.insert(0, "-C") + a.insert(1, "/home/seb/tmp/godotgit") + OS.execute("git", a, true, output, true) + var o = output[0] + if splitlines: + o = o.split("\n") + o.remove(len(o)-1) + else: + o = o.substr(0,len(o)-1) + 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"): ""} + 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(): - return git("cat-file --batch-check=%(objectname) --batch-all-objects", true) + return git("cat-file --batch-check=%(objectname) --batch-all-objects", true) func object_type(id): - return git("cat-file -t "+id) + return git("cat-file -t "+id) func object_content(id): - return git("cat-file -p "+id) + return git("cat-file -p "+id) func tree_children(id): - 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 + 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 func commit_tree(id): - 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 + 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 func commit_parents(id): - 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 + 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 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 - + 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] + 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] + var ret = git("symbolic-ref -q "+symref) + if ret != "": + return ret + return git("show-ref --head "+symref).split(" ")[0] diff --git a/main.tscn b/main.tscn index 471c0dd..3b1442e 100644 --- a/main.tscn +++ b/main.tscn @@ -28,7 +28,6 @@ __meta__ = { } [node name="Terminal" type="Node2D" parent="."] -visible = false z_index = 1 script = ExtResource( 1 ) diff --git a/node.gd b/node.gd index 8a2766f..1a0e633 100644 --- a/node.gd +++ b/node.gd @@ -9,58 +9,58 @@ var children = {} setget children_set var arrow = preload("res://arrow.tscn") func _ready(): - pass + pass func _process(delta): - for c in children.keys(): - var other = get_node("..").objects[c] - var d = other.position.distance_to(position) - var dir = (other.position - position).normalized() - var f = (d*0.05) - position += dir*f - other.position -= dir*f - + for c in children.keys(): + var other = get_node("..").objects[c] + var d = other.position.distance_to(position) + var dir = (other.position - position).normalized() + var f = (d*0.05) + position += dir*f + other.position -= dir*f + func id_set(new_id): - id = new_id - $ID.text = id - + id = new_id + $ID.text = id + func content_set(new_content): - content = new_content - $Content.text = content + content = new_content + $Content.text = content func type_set(new_type): - type = new_type - if type != "ref": - $ID.text = $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 - "ref": - $Rect.color = Color("#6680ff") - "head": - $Rect.color = Color.red + type = new_type + if type != "ref": + $ID.text = $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 + "ref": + $Rect.color = Color("#6680ff") + "head": + $Rect.color = Color.red 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 + 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 func _on_hover(): - $Content.visible = true - + $Content.visible = true + func _on_unhover(): - $Content.visible = false + $Content.visible = false diff --git a/player.gd b/player.gd index c9b3753..0e26384 100644 --- a/player.gd +++ b/player.gd @@ -3,9 +3,9 @@ extends KinematicBody2D export var speed = 800 func _ready(): - pass + pass func _process(delta): - var right = Input.get_action_strength("right") - Input.get_action_strength("left") - var down = Input.get_action_strength("down") - Input.get_action_strength("up") - move_and_slide(Vector2(right, down).normalized()*speed) \ No newline at end of file + var right = Input.get_action_strength("right") - Input.get_action_strength("left") + var down = Input.get_action_strength("down") - Input.get_action_strength("up") + move_and_slide(Vector2(right, down).normalized()*speed) diff --git a/terminal.gd b/terminal.gd index 2d27b68..f447bff 100644 --- a/terminal.gd +++ b/terminal.gd @@ -1,17 +1,17 @@ extends Node2D func _ready(): - pass + pass func send_command(new_text): - var parts = new_text.split(" ") - var cmd = parts[0] - var args = parts - args.remove(0) - var output = [] - OS.execute(cmd, args, true, output, true) - $Input.text = "" - $Output.text = $Output.text + "$ " + new_text + "\n" + output[0] - $Output.scroll_vertical = 999999 + var parts = new_text.split(" ") + var cmd = parts[0] + var args = parts + args.remove(0) + var output = [] + OS.execute(cmd, args, true, output, true) + $Input.text = "" + $Output.text = $Output.text + "$ " + new_text + "\n" + output[0] + $Output.scroll_vertical = 999999