Display index and HEAD versions in the file browser

This commit is contained in:
blinry 2020-11-18 19:08:27 +01:00
parent 833475e80b
commit 96e4c56521
4 changed files with 62 additions and 55 deletions

View file

@ -33,23 +33,24 @@ func _input(event):
if event.is_action_pressed("save"): if event.is_action_pressed("save"):
if text_edit.visible: if text_edit.visible:
save() save()
# if event.is_action_pressed("down", true): var speed = 30
# player.move(Vector2(0,1)) if event.is_action_pressed("down", true):
# if event.is_action_pressed("up", true): player.move(Vector2(0,speed))
# player.move(Vector2(0,-1)) if event.is_action_pressed("up", true):
# if event.is_action_pressed("right", true): player.move(Vector2(0,-speed))
# player.move(Vector2(1,0)) if event.is_action_pressed("right", true):
# if event.is_action_pressed("left", true): player.move(Vector2(speed, 0))
# player.move(Vector2(-1,0)) if event.is_action_pressed("left", true):
# if event.is_action_pressed("pickup"): player.move(Vector2(-speed,0))
# if player.held: if event.is_action_pressed("pickup"):
# player.held = null if player.held:
# else: player.held = null
# for item in world.get_children(): else:
# if item.label != "": for item in world.get_children():
# if item.position == player.position: if item != player:
# player.held = item if item.position.distance_to(player.position) < 50:
# print("player picked up item " + item.label) player.held = item
print("player picked up item " + item.label)
func clear(): func clear():
pass pass
@ -66,6 +67,39 @@ func update():
match mode: match mode:
FileBrowserMode.WORKING_DIRECTORY: FileBrowserMode.WORKING_DIRECTORY:
if shell: 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. # Populate working directory.
var wd_files = Array(shell.run("find . -type f").split("\n")) var wd_files = Array(shell.run("find . -type f").split("\n"))
@ -80,6 +114,7 @@ func update():
var files = wd_files + deleted_files var files = wd_files + deleted_files
player = null
files.sort_custom(self, "very_best_sort") files.sort_custom(self, "very_best_sort")
for file_path in files: for file_path in files:
if file_path.substr(0, 5) == ".git/": 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)) #item.position = Vector2(rand_range(0, world.rect_size.x), rand_range(0, world.rect_size.y))
#randomize() #randomize()
world.add_child(item) world.add_child(item)
if not player:
# Populate index. player = item
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)
FileBrowserMode.COMMIT: FileBrowserMode.COMMIT:
if commit: if commit:

View file

@ -33,7 +33,10 @@ func read_from_file():
content = file_browser.shell.run("cat '%s'" % label) content = file_browser.shell.run("cat '%s'" % label)
"index": "index":
content = file_browser.shell.run("git show :'%s'" % label) 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) attributes = helpers.parse(content)
position.x = int(attributes["x"]) position.x = int(attributes["x"])

View file

@ -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 level_congrats = $Rows/Columns/RightSide/LevelInfo/LevelPanel/Text/LevelCongrats
onready var cards = $Rows/Controls/Cards onready var cards = $Rows/Controls/Cards
onready var file_browser = $Rows/Columns/RightSide/FileBrowser onready var file_browser = $Rows/Columns/RightSide/FileBrowser
onready var index = $Rows/Columns/RightSide/Index #onready var index = $Rows/Columns/RightSide/Index
func _ready(): func _ready():
var args = helpers.parse_args() var args = helpers.parse_args()
@ -87,8 +87,8 @@ func load_level(level_id):
if new_repo.label == "yours": if new_repo.label == "yours":
file_browser.shell = new_repo.shell file_browser.shell = new_repo.shell
file_browser.update() file_browser.update()
index.repository = new_repo # index.repository = new_repo
index.update() # index.update()
repositories_node.add_child(new_repo) repositories_node.add_child(new_repo)
repositories[r] = new_repo repositories[r] = new_repo
@ -143,7 +143,7 @@ func update_repos():
var repo = repositories[r] var repo = repositories[r]
repo.update_everything() repo.update_everything()
file_browser.update() file_browser.update()
index.update() #index.update()
if levels.chapters[current_chapter].levels[current_level].check_win(): if levels.chapters[current_chapter].levels[current_level].check_win():
show_win_status() show_win_status()

View file

@ -191,18 +191,6 @@ __meta__ = {
"_edit_use_anchors_": false "_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 )] [node name="FileBrowser" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )]
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0