mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-24 20:33:19 +01:00
Display index and HEAD versions in the file browser
This commit is contained in:
parent
833475e80b
commit
96e4c56521
4 changed files with 62 additions and 55 deletions
|
@ -33,23 +33,24 @@ func _input(event):
|
|||
if event.is_action_pressed("save"):
|
||||
if text_edit.visible:
|
||||
save()
|
||||
# if event.is_action_pressed("down", true):
|
||||
# player.move(Vector2(0,1))
|
||||
# if event.is_action_pressed("up", true):
|
||||
# player.move(Vector2(0,-1))
|
||||
# if event.is_action_pressed("right", true):
|
||||
# player.move(Vector2(1,0))
|
||||
# if event.is_action_pressed("left", true):
|
||||
# player.move(Vector2(-1,0))
|
||||
# if event.is_action_pressed("pickup"):
|
||||
# if player.held:
|
||||
# player.held = null
|
||||
# else:
|
||||
# for item in world.get_children():
|
||||
# if item.label != "":
|
||||
# if item.position == player.position:
|
||||
# player.held = item
|
||||
# print("player picked up item " + item.label)
|
||||
var speed = 30
|
||||
if event.is_action_pressed("down", true):
|
||||
player.move(Vector2(0,speed))
|
||||
if event.is_action_pressed("up", true):
|
||||
player.move(Vector2(0,-speed))
|
||||
if event.is_action_pressed("right", true):
|
||||
player.move(Vector2(speed, 0))
|
||||
if event.is_action_pressed("left", true):
|
||||
player.move(Vector2(-speed,0))
|
||||
if event.is_action_pressed("pickup"):
|
||||
if player.held:
|
||||
player.held = null
|
||||
else:
|
||||
for item in world.get_children():
|
||||
if item != player:
|
||||
if item.position.distance_to(player.position) < 50:
|
||||
player.held = item
|
||||
print("player picked up item " + item.label)
|
||||
|
||||
func clear():
|
||||
pass
|
||||
|
@ -66,6 +67,39 @@ func update():
|
|||
match mode:
|
||||
FileBrowserMode.WORKING_DIRECTORY:
|
||||
if shell:
|
||||
# Populate HEAD versions.
|
||||
|
||||
if shell.run("test -d .git && echo yes || echo no") == "yes\n":
|
||||
var files = Array(shell.run("git ls-tree --name-only -r %s" % "HEAD").split("\n"))
|
||||
# The last entry is an empty string, remove it.
|
||||
files.pop_back()
|
||||
for file_path in files:
|
||||
var item = preload("res://scenes/item.tscn").instance()
|
||||
item.label = file_path
|
||||
item.item_type = "head"
|
||||
item.type = "nothing"
|
||||
item.file_browser = self
|
||||
world.add_child(item)
|
||||
|
||||
# Populate index.
|
||||
|
||||
if shell.run("test -d .git && echo yes || echo no") == "yes\n":
|
||||
var index_files = Array(shell.run("git ls-files -s | cut -f2 | uniq").split("\n"))
|
||||
#var deleted_files = Array(repository.shell.run("git status -s | grep '^D' | sed 's/^...//'").split("\n"))
|
||||
# The last entries are empty strings, remove them.
|
||||
index_files.pop_back()
|
||||
#deleted_files.pop_back()
|
||||
var files = index_files# + deleted_files
|
||||
for file_path in files:
|
||||
var item = preload("res://scenes/item.tscn").instance()
|
||||
item.label = file_path
|
||||
item.item_type = "index"
|
||||
item.type = "nothing"
|
||||
item.file_browser = self
|
||||
#item.connect("clicked", self, "item_clicked")
|
||||
#item.status = get_file_status(file_path, repository.shell, 0)
|
||||
world.add_child(item)
|
||||
|
||||
# Populate working directory.
|
||||
|
||||
var wd_files = Array(shell.run("find . -type f").split("\n"))
|
||||
|
@ -80,6 +114,7 @@ func update():
|
|||
|
||||
var files = wd_files + deleted_files
|
||||
|
||||
player = null
|
||||
files.sort_custom(self, "very_best_sort")
|
||||
for file_path in files:
|
||||
if file_path.substr(0, 5) == ".git/":
|
||||
|
@ -93,27 +128,8 @@ func update():
|
|||
#item.position = Vector2(rand_range(0, world.rect_size.x), rand_range(0, world.rect_size.y))
|
||||
#randomize()
|
||||
world.add_child(item)
|
||||
|
||||
# Populate index.
|
||||
|
||||
if shell.run("test -d .git && echo yes || echo no") == "yes\n":
|
||||
var index_files = Array(shell.run("git ls-files -s | cut -f2 | uniq").split("\n"))
|
||||
#var deleted_files = Array(repository.shell.run("git status -s | grep '^D' | sed 's/^...//'").split("\n"))
|
||||
# The last entries are empty strings, remove them.
|
||||
index_files.pop_back()
|
||||
#deleted_files.pop_back()
|
||||
files = index_files# + deleted_files
|
||||
for file_path in files:
|
||||
var item = preload("res://scenes/item.tscn").instance()
|
||||
item.label = file_path
|
||||
item.item_type = "index"
|
||||
item.type = "nothing"
|
||||
item.file_browser = self
|
||||
print(item)
|
||||
#item.connect("clicked", self, "item_clicked")
|
||||
#item.status = get_file_status(file_path, repository.shell, 0)
|
||||
world.add_child(item)
|
||||
|
||||
if not player:
|
||||
player = item
|
||||
|
||||
FileBrowserMode.COMMIT:
|
||||
if commit:
|
||||
|
|
|
@ -33,7 +33,10 @@ func read_from_file():
|
|||
content = file_browser.shell.run("cat '%s'" % label)
|
||||
"index":
|
||||
content = file_browser.shell.run("git show :'%s'" % label)
|
||||
modulate = Color(0, 0, 255.0)
|
||||
modulate = Color(0, 0, 1.0)
|
||||
"head":
|
||||
content = file_browser.shell.run("git show HEAD:'%s'" % label)
|
||||
modulate = Color(0, 0, 0, 0.5)
|
||||
|
||||
attributes = helpers.parse(content)
|
||||
position.x = int(attributes["x"])
|
||||
|
|
|
@ -18,7 +18,7 @@ onready var level_description = $Rows/Columns/RightSide/LevelInfo/LevelPanel/Tex
|
|||
onready var level_congrats = $Rows/Columns/RightSide/LevelInfo/LevelPanel/Text/LevelCongrats
|
||||
onready var cards = $Rows/Controls/Cards
|
||||
onready var file_browser = $Rows/Columns/RightSide/FileBrowser
|
||||
onready var index = $Rows/Columns/RightSide/Index
|
||||
#onready var index = $Rows/Columns/RightSide/Index
|
||||
|
||||
func _ready():
|
||||
var args = helpers.parse_args()
|
||||
|
@ -87,8 +87,8 @@ func load_level(level_id):
|
|||
if new_repo.label == "yours":
|
||||
file_browser.shell = new_repo.shell
|
||||
file_browser.update()
|
||||
index.repository = new_repo
|
||||
index.update()
|
||||
# index.repository = new_repo
|
||||
# index.update()
|
||||
repositories_node.add_child(new_repo)
|
||||
repositories[r] = new_repo
|
||||
|
||||
|
@ -143,7 +143,7 @@ func update_repos():
|
|||
var repo = repositories[r]
|
||||
repo.update_everything()
|
||||
file_browser.update()
|
||||
index.update()
|
||||
#index.update()
|
||||
|
||||
if levels.chapters[current_chapter].levels[current_level].check_win():
|
||||
show_win_status()
|
||||
|
|
|
@ -191,18 +191,6 @@ __meta__ = {
|
|||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Index" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )]
|
||||
visible = false
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_top = 391.0
|
||||
margin_right = 633.0
|
||||
margin_bottom = 582.0
|
||||
size_flags_vertical = 3
|
||||
size_flags_stretch_ratio = 0.5
|
||||
title = "Plan for the next commit"
|
||||
mode = 2
|
||||
|
||||
[node name="FileBrowser" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
|
|
Loading…
Reference in a new issue