mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-13 19:04:54 +01:00
Indent using tabs, which is Godot's default behavior
This should make it easier for new people to contribute.
This commit is contained in:
parent
2f94af8e60
commit
f3c311be58
7 changed files with 243 additions and 244 deletions
20
arrow.gd
20
arrow.gd
|
@ -4,19 +4,19 @@ var label = "label" setget label_set
|
||||||
var target = Vector2(0,0) setget target_set
|
var target = Vector2(0,0) setget target_set
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var t = get_node("/root/Main").objects[target]
|
var t = get_node("/root/Main").objects[target]
|
||||||
#print(t)
|
#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.position = ($Line.points[0] + $Line.points[1])/2
|
||||||
$Tip.rotation = PI+$Line.points[0].angle_to($Line.points[1])
|
$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
|
||||||
$Label/ID.text = label
|
$Label/ID.text = label
|
||||||
|
|
||||||
func target_set(new_target):
|
func target_set(new_target):
|
||||||
target = new_target
|
target = new_target
|
||||||
|
|
34
game.gd
34
game.gd
|
@ -4,29 +4,29 @@ var _file = "user://savegame.json"
|
||||||
var state = {}
|
var state = {}
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
load_state()
|
load_state()
|
||||||
|
|
||||||
func _initial_state():
|
func _initial_state():
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
func save_state() -> bool:
|
func save_state() -> bool:
|
||||||
var savegame = File.new()
|
var savegame = File.new()
|
||||||
|
|
||||||
savegame.open(_file, File.WRITE)
|
savegame.open(_file, File.WRITE)
|
||||||
savegame.store_line(to_json(state))
|
savegame.store_line(to_json(state))
|
||||||
savegame.close()
|
savegame.close()
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func load_state() -> bool:
|
func load_state() -> bool:
|
||||||
var savegame = File.new()
|
var savegame = File.new()
|
||||||
if not savegame.file_exists(_file):
|
if not savegame.file_exists(_file):
|
||||||
return false
|
return false
|
||||||
|
|
||||||
savegame.open(_file, File.READ)
|
savegame.open(_file, File.READ)
|
||||||
|
|
||||||
state = _initial_state()
|
state = _initial_state()
|
||||||
var new_state = parse_json(savegame.get_line())
|
var new_state = parse_json(savegame.get_line())
|
||||||
for key in new_state:
|
for key in new_state:
|
||||||
state[key] = new_state[key]
|
state[key] = new_state[key]
|
||||||
savegame.close()
|
savegame.close()
|
||||||
return true
|
return true
|
||||||
|
|
284
main.gd
284
main.gd
|
@ -9,182 +9,182 @@ var dragged = null
|
||||||
var viewport_size
|
var viewport_size
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
viewport_size = get_viewport_rect().size
|
viewport_size = get_viewport_rect().size
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if true or get_global_mouse_position().x < get_viewport_rect().size.x*0.7:
|
if true or get_global_mouse_position().x < get_viewport_rect().size.x*0.7:
|
||||||
if Input.is_action_just_pressed("click"):
|
if Input.is_action_just_pressed("click"):
|
||||||
var mindist = 9999999
|
var mindist = 9999999
|
||||||
for o in objects.values():
|
for o in objects.values():
|
||||||
var d = o.position.distance_to(get_global_mouse_position())
|
var d = o.position.distance_to(get_global_mouse_position())
|
||||||
if d < mindist:
|
if d < mindist:
|
||||||
mindist = d
|
mindist = d
|
||||||
dragged = o
|
dragged = o
|
||||||
if Input.is_action_just_released("click"):
|
if Input.is_action_just_released("click"):
|
||||||
dragged = null
|
dragged = null
|
||||||
if dragged:
|
if dragged:
|
||||||
dragged.position = get_global_mouse_position()
|
dragged.position = get_global_mouse_position()
|
||||||
|
|
||||||
update_head()
|
update_head()
|
||||||
update_refs()
|
update_refs()
|
||||||
update_index()
|
update_index()
|
||||||
update_objects()
|
update_objects()
|
||||||
apply_forces()
|
apply_forces()
|
||||||
|
|
||||||
func update_index():
|
func update_index():
|
||||||
$Index.text = git("ls-files")
|
$Index.text = git("ls-files")
|
||||||
|
|
||||||
func update_objects():
|
func update_objects():
|
||||||
for o in all_objects():
|
for o in all_objects():
|
||||||
if objects.has(o):
|
if objects.has(o):
|
||||||
continue
|
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)
|
||||||
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))
|
||||||
|
|
||||||
if true:
|
if true:
|
||||||
#print(" ")
|
#print(" ")
|
||||||
#print(o)
|
#print(o)
|
||||||
var type = object_type(o)
|
var type = object_type(o)
|
||||||
#print(type)
|
#print(type)
|
||||||
#print(object_content(o))
|
#print(object_content(o))
|
||||||
match type:
|
match type:
|
||||||
"blob":
|
"blob":
|
||||||
pass
|
pass
|
||||||
"tree":
|
"tree":
|
||||||
#print("Children:")
|
#print("Children:")
|
||||||
#print(tree_children(o))
|
#print(tree_children(o))
|
||||||
n.children = tree_children(o)
|
n.children = tree_children(o)
|
||||||
"commit":
|
"commit":
|
||||||
#print("Tree:")
|
#print("Tree:")
|
||||||
#print(commit_tree(o))
|
#print(commit_tree(o))
|
||||||
|
|
||||||
#print("Parents:")
|
#print("Parents:")
|
||||||
#print(commit_parents(o))
|
#print(commit_parents(o))
|
||||||
|
|
||||||
var c = {}
|
var c = {}
|
||||||
c[commit_tree(o)] = ""
|
c[commit_tree(o)] = ""
|
||||||
for p in commit_parents(o):
|
for p in commit_parents(o):
|
||||||
c[p] = ""
|
c[p] = ""
|
||||||
n.children = c
|
n.children = c
|
||||||
add_child(n)
|
add_child(n)
|
||||||
objects[o] = n
|
objects[o] = n
|
||||||
|
|
||||||
func update_refs():
|
func update_refs():
|
||||||
for r in all_refs():
|
for r in all_refs():
|
||||||
if not objects.has(r):
|
if not objects.has(r):
|
||||||
var n = node.instance()
|
var n = node.instance()
|
||||||
n.id = r
|
n.id = r
|
||||||
n.type = "ref"
|
n.type = "ref"
|
||||||
n.content = ""
|
n.content = ""
|
||||||
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))
|
||||||
objects[r] = n
|
objects[r] = n
|
||||||
add_child(n)
|
add_child(n)
|
||||||
var n = objects[r]
|
var n = objects[r]
|
||||||
n.children = {ref_id(r): ""}
|
n.children = {ref_id(r): ""}
|
||||||
|
|
||||||
func apply_forces():
|
func apply_forces():
|
||||||
for o in objects.values():
|
for o in objects.values():
|
||||||
for o2 in objects.values():
|
for o2 in objects.values():
|
||||||
if o == o2:
|
if o == o2:
|
||||||
continue
|
continue
|
||||||
var d = o.position.distance_to(o2.position)
|
var d = o.position.distance_to(o2.position)
|
||||||
var dir = (o.global_position - o2.global_position).normalized()
|
var dir = (o.global_position - o2.global_position).normalized()
|
||||||
var f = 3000/pow(d+0.00001,1.5)
|
var f = 3000/pow(d+0.00001,1.5)
|
||||||
o.position += dir*f
|
o.position += dir*f
|
||||||
o2.position -= dir*f
|
o2.position -= dir*f
|
||||||
var d = o.position.distance_to(Vector2(viewport_size.x/3, viewport_size.y/2))
|
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 dir = (o.global_position - Vector2(viewport_size.x/3, viewport_size.y/2)).normalized()
|
||||||
var f = (d+0.00001)*0.02
|
var f = (d+0.00001)*0.02
|
||||||
o.position -= dir*f
|
o.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(" ")
|
||||||
#print ("Running: ", a)
|
#print ("Running: ", a)
|
||||||
a.insert(0, "-C")
|
a.insert(0, "-C")
|
||||||
a.insert(1, "/home/seb/tmp/godotgit")
|
a.insert(1, "/home/seb/tmp/godotgit")
|
||||||
OS.execute("git", a, true, output, true)
|
OS.execute("git", a, true, output, true)
|
||||||
var o = output[0]
|
var o = output[0]
|
||||||
if splitlines:
|
if splitlines:
|
||||||
o = o.split("\n")
|
o = o.split("\n")
|
||||||
o.remove(len(o)-1)
|
o.remove(len(o)-1)
|
||||||
else:
|
else:
|
||||||
o = o.substr(0,len(o)-1)
|
o = o.substr(0,len(o)-1)
|
||||||
return o
|
return o
|
||||||
|
|
||||||
func update_head():
|
func update_head():
|
||||||
if not objects.has("HEAD"):
|
if not objects.has("HEAD"):
|
||||||
var n = node.instance()
|
var n = node.instance()
|
||||||
n.id = "HEAD"
|
n.id = "HEAD"
|
||||||
n.type = "head"
|
n.type = "head"
|
||||||
n.content = ""
|
n.content = ""
|
||||||
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))
|
||||||
objects["HEAD"] = n
|
objects["HEAD"] = n
|
||||||
add_child(n)
|
add_child(n)
|
||||||
|
|
||||||
n = node.instance()
|
n = node.instance()
|
||||||
n.id = "refs/heads/master"
|
n.id = "refs/heads/master"
|
||||||
n.type = "ref"
|
n.type = "ref"
|
||||||
n.content = ""
|
n.content = ""
|
||||||
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))
|
||||||
objects[n.id] = n
|
objects[n.id] = n
|
||||||
add_child(n)
|
add_child(n)
|
||||||
var n = objects["HEAD"]
|
var n = objects["HEAD"]
|
||||||
n.children = {symref_target("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)
|
||||||
|
|
||||||
func object_type(id):
|
func object_type(id):
|
||||||
return git("cat-file -t "+id)
|
return git("cat-file -t "+id)
|
||||||
|
|
||||||
func object_content(id):
|
func object_content(id):
|
||||||
return git("cat-file -p "+id)
|
return git("cat-file -p "+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[a[2].split("\t")[0]] = a[2].split("\t")[1]
|
ids[a[2].split("\t")[0]] = a[2].split("\t")[1]
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
func commit_tree(id):
|
func commit_tree(id):
|
||||||
var c = git("cat-file -p "+id, true)
|
var c = git("cat-file -p "+id, true)
|
||||||
for cc in c:
|
for cc in c:
|
||||||
var ccc = cc.split(" ", 2)
|
var ccc = cc.split(" ", 2)
|
||||||
match ccc[0]:
|
match ccc[0]:
|
||||||
"tree":
|
"tree":
|
||||||
return ccc[1]
|
return ccc[1]
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func commit_parents(id):
|
func commit_parents(id):
|
||||||
var parents = []
|
var parents = []
|
||||||
var c = git("cat-file -p "+id, true)
|
var c = git("cat-file -p "+id, true)
|
||||||
for cc in c:
|
for cc in c:
|
||||||
var ccc = cc.split(" ", 2)
|
var ccc = cc.split(" ", 2)
|
||||||
match ccc[0]:
|
match ccc[0]:
|
||||||
"parent":
|
"parent":
|
||||||
parents.push_back(ccc[1])
|
parents.push_back(ccc[1])
|
||||||
return parents
|
return parents
|
||||||
|
|
||||||
func all_refs():
|
func all_refs():
|
||||||
var refs = []
|
var refs = []
|
||||||
for line in git("show-ref", true):
|
for line in git("show-ref", true):
|
||||||
line = line.split(" ")
|
line = line.split(" ")
|
||||||
var id = line[0]
|
var id = line[0]
|
||||||
var name = line[1]
|
var name = line[1]
|
||||||
refs.push_back(name)
|
refs.push_back(name)
|
||||||
return refs
|
return refs
|
||||||
|
|
||||||
func ref_id(ref):
|
func ref_id(ref):
|
||||||
return git("show-ref "+ref).split(" ")[0]
|
return git("show-ref "+ref).split(" ")[0]
|
||||||
|
|
||||||
func symref_target(symref):
|
func symref_target(symref):
|
||||||
var ret = git("symbolic-ref -q "+symref)
|
var ret = git("symbolic-ref -q "+symref)
|
||||||
if ret != "":
|
if ret != "":
|
||||||
return ret
|
return ret
|
||||||
return git("show-ref --head "+symref).split(" ")[0]
|
return git("show-ref --head "+symref).split(" ")[0]
|
||||||
|
|
|
@ -28,7 +28,6 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Terminal" type="Node2D" parent="."]
|
[node name="Terminal" type="Node2D" parent="."]
|
||||||
visible = false
|
|
||||||
z_index = 1
|
z_index = 1
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
|
80
node.gd
80
node.gd
|
@ -9,58 +9,58 @@ var children = {} setget children_set
|
||||||
var arrow = preload("res://arrow.tscn")
|
var arrow = preload("res://arrow.tscn")
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
for c in children.keys():
|
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*0.05)
|
var f = (d*0.05)
|
||||||
position += dir*f
|
position += dir*f
|
||||||
other.position -= dir*f
|
other.position -= dir*f
|
||||||
|
|
||||||
func id_set(new_id):
|
func id_set(new_id):
|
||||||
id = new_id
|
id = new_id
|
||||||
$ID.text = id
|
$ID.text = id
|
||||||
|
|
||||||
func content_set(new_content):
|
func content_set(new_content):
|
||||||
content = new_content
|
content = new_content
|
||||||
$Content.text = content
|
$Content.text = content
|
||||||
|
|
||||||
func type_set(new_type):
|
func type_set(new_type):
|
||||||
type = new_type
|
type = new_type
|
||||||
if type != "ref":
|
if type != "ref":
|
||||||
$ID.text = $ID.text.substr(0,8)
|
$ID.text = $ID.text.substr(0,8)
|
||||||
match new_type:
|
match new_type:
|
||||||
"blob":
|
"blob":
|
||||||
$Rect.color = Color.gray
|
$Rect.color = Color.gray
|
||||||
"tree":
|
"tree":
|
||||||
$Rect.color = Color.darkgreen
|
$Rect.color = Color.darkgreen
|
||||||
"commit":
|
"commit":
|
||||||
$Rect.color = Color.orange
|
$Rect.color = Color.orange
|
||||||
"tag":
|
"tag":
|
||||||
$Rect.color = Color.blue
|
$Rect.color = Color.blue
|
||||||
"ref":
|
"ref":
|
||||||
$Rect.color = Color("#6680ff")
|
$Rect.color = Color("#6680ff")
|
||||||
"head":
|
"head":
|
||||||
$Rect.color = Color.red
|
$Rect.color = Color.red
|
||||||
|
|
||||||
func children_set(new_children):
|
func children_set(new_children):
|
||||||
for c in $Arrows.get_children():
|
for c in $Arrows.get_children():
|
||||||
if not new_children.has(c.target):
|
if not new_children.has(c.target):
|
||||||
c.queue_free()
|
c.queue_free()
|
||||||
for c in new_children:
|
for c in new_children:
|
||||||
if not children.has(c):
|
if not children.has(c):
|
||||||
var a = arrow.instance()
|
var a = arrow.instance()
|
||||||
a.label = new_children[c]
|
a.label = new_children[c]
|
||||||
a.target = c
|
a.target = c
|
||||||
$Arrows.add_child(a)
|
$Arrows.add_child(a)
|
||||||
children = new_children
|
children = new_children
|
||||||
|
|
||||||
func _on_hover():
|
func _on_hover():
|
||||||
$Content.visible = true
|
$Content.visible = true
|
||||||
|
|
||||||
func _on_unhover():
|
func _on_unhover():
|
||||||
$Content.visible = false
|
$Content.visible = false
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ extends KinematicBody2D
|
||||||
export var speed = 800
|
export var speed = 800
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var right = Input.get_action_strength("right") - Input.get_action_strength("left")
|
var right = Input.get_action_strength("right") - Input.get_action_strength("left")
|
||||||
var down = Input.get_action_strength("down") - Input.get_action_strength("up")
|
var down = Input.get_action_strength("down") - Input.get_action_strength("up")
|
||||||
move_and_slide(Vector2(right, down).normalized()*speed)
|
move_and_slide(Vector2(right, down).normalized()*speed)
|
||||||
|
|
20
terminal.gd
20
terminal.gd
|
@ -1,17 +1,17 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func send_command(new_text):
|
func send_command(new_text):
|
||||||
var parts = new_text.split(" ")
|
var parts = new_text.split(" ")
|
||||||
var cmd = parts[0]
|
var cmd = parts[0]
|
||||||
var args = parts
|
var args = parts
|
||||||
args.remove(0)
|
args.remove(0)
|
||||||
var output = []
|
var output = []
|
||||||
OS.execute(cmd, args, true, output, true)
|
OS.execute(cmd, args, true, output, true)
|
||||||
$Input.text = ""
|
$Input.text = ""
|
||||||
$Output.text = $Output.text + "$ " + new_text + "\n" + output[0]
|
$Output.text = $Output.text + "$ " + new_text + "\n" + output[0]
|
||||||
$Output.scroll_vertical = 999999
|
$Output.scroll_vertical = 999999
|
||||||
|
|
Loading…
Reference in a new issue