Indent using tabs, which is Godot's default behavior

This should make it easier for new people to contribute.
This commit is contained in:
Sebastian Morr 2020-08-24 16:48:30 +02:00
parent 2f94af8e60
commit f3c311be58
7 changed files with 243 additions and 244 deletions

View file

@ -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

46
game.gd
View file

@ -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
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

304
main.gd
View file

@ -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]

View file

@ -28,7 +28,6 @@ __meta__ = {
}
[node name="Terminal" type="Node2D" parent="."]
visible = false
z_index = 1
script = ExtResource( 1 )

86
node.gd
View file

@ -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

View file

@ -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)
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)

View file

@ -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