From ca09ad02450bb43495d28535262c0a5662979cad Mon Sep 17 00:00:00 2001 From: blinry Date: Wed, 18 Nov 2020 21:19:16 +0100 Subject: [PATCH] Put tiny 2D worlds into all the commits --- scenes/file_browser.gd | 48 ++++++++++++++-------------------------- scenes/file_browser.tscn | 2 +- scenes/item.gd | 11 ++++++--- scenes/node.gd | 2 ++ scenes/node.tscn | 12 +++++++++- scenes/repository.gd | 2 ++ 6 files changed, 41 insertions(+), 36 deletions(-) diff --git a/scenes/file_browser.gd b/scenes/file_browser.gd index 462c737..e3ff87f 100644 --- a/scenes/file_browser.gd +++ b/scenes/file_browser.gd @@ -47,10 +47,10 @@ func _input(event): get_tree().set_input_as_handled() func clear(): - pass - for item in world.get_children(): - if item.label != "": - item.queue_free() + if world: + for item in world.get_children(): + if item.label != "": + item.queue_free() func substr2(s): return s.substr(2) @@ -142,32 +142,17 @@ func update(): FileBrowserMode.COMMIT: if commit: - var files = Array(commit.repository.shell.run("git ls-tree --name-only -r %s" % commit.id).split("\n")) - # The last entry is an empty string, remove it. - files.pop_back() - for file_path in files: - var item = preload("res://scenes/file_browser_item.tscn").instance() - item.label = file_path - item.connect("clicked", self, "item_clicked") - #grid.add_child(item) - FileBrowserMode.INDEX: - #var is_visible = false - if repository and repository.there_is_a_git(): - var index_files = Array(repository.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/file_browser_item.tscn").instance() - item.label = file_path - item.connect("clicked", self, "item_clicked") - item.status = get_file_status(file_path, repository.shell, 0) - #grid.add_child(item) - #if item.status != item.IconStatus.NONE: - # is_visible = true - #visible = is_visible + if shell.run("test -d .git && echo yes || echo no") == "yes\n": + var files = Array(shell.run("git ls-tree --name-only -r %s" % commit.id).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) func get_file_status(file_path, the_shell, idx): var file_status = the_shell.run("git status -s '%s'" % file_path) @@ -228,7 +213,8 @@ func save(): func _set_commit(new_commit): commit = new_commit - update() + #update() + shell = commit.repository.shell func _set_mode(new_mode): mode = new_mode diff --git a/scenes/file_browser.tscn b/scenes/file_browser.tscn index af66858..b5b8d6d 100644 --- a/scenes/file_browser.tscn +++ b/scenes/file_browser.tscn @@ -48,6 +48,7 @@ __meta__ = { } [node name="Title" type="Label" parent="Panel/Margin/Rows"] +visible = false margin_right = 1904.0 margin_bottom = 29.0 text = "title" @@ -73,7 +74,6 @@ margin_bottom = 50.0 text = "dir" [node name="World" type="Control" parent="Panel/Margin/Rows"] -margin_top = 29.0 margin_right = 1904.0 margin_bottom = 1064.0 mouse_filter = 1 diff --git a/scenes/item.gd b/scenes/item.gd index da86a8a..674512c 100644 --- a/scenes/item.gd +++ b/scenes/item.gd @@ -36,9 +36,14 @@ func read_from_file(): modulate = Color(0, 0, 1.0) $Sprite.scale = Vector2(0.75, 0.75) "head": - content = file_browser.shell.run("git show HEAD:'%s'" % label) - modulate = Color(0, 0, 0, 0.2) - $Sprite.scale = Vector2(0.8, 0.8) + var commit = "HEAD" + if file_browser.commit: + commit = file_browser.commit.id + else: + modulate = Color(0, 0, 0, 0.2) + $Sprite.scale = Vector2(0.8, 0.8) + content = file_browser.shell.run("git show %s:'%s'" % [commit, label]) + attributes = helpers.parse(content) position.x = int(attributes["x"]) diff --git a/scenes/node.gd b/scenes/node.gd index 7150532..cc7a49f 100644 --- a/scenes/node.gd +++ b/scenes/node.gd @@ -15,6 +15,7 @@ var hovered = false var arrow = preload("res://scenes/arrow.tscn") func _ready(): + $FileBrowser.hide() content_set(content) type_set(type) if not repository.simplified_view or (type != "tree" and type != "blob"): @@ -75,6 +76,7 @@ func type_set(new_type): $Sprite.texture = preload("res://nodes/tree.svg") "commit": $Sprite.texture = preload("res://nodes/commit.svg") + $FileBrowser.show() "tag": $Sprite.texture = preload("res://nodes/blob.svg") "ref": diff --git a/scenes/node.tscn b/scenes/node.tscn index d335ec1..2957801 100644 --- a/scenes/node.tscn +++ b/scenes/node.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1] [ext_resource path="res://scenes/node.gd" type="Script" id=2] [ext_resource path="res://nodes/blob.svg" type="Texture" id=3] +[ext_resource path="res://scenes/file_browser.tscn" type="PackedScene" id=4] [ext_resource path="res://nodes/pop.wav" type="AudioStream" id=5] [ext_resource path="res://scenes/drop_area.tscn" type="PackedScene" id=6] @@ -80,6 +81,15 @@ custom_colors/font_color = Color( 1, 1, 1, 1 ) __meta__ = { "_edit_use_anchors_": false } + +[node name="FileBrowser" parent="." instance=ExtResource( 4 )] +margin_left = -21.0 +margin_top = -20.0 +margin_right = 578.0 +margin_bottom = 559.0 +rect_min_size = Vector2( 0, 0 ) +rect_scale = Vector2( 0.07, 0.07 ) +mouse_filter = 2 [connection signal="mouse_entered" from="Rect" to="." method="_on_hover"] [connection signal="mouse_exited" from="Rect" to="." method="_on_unhover"] [connection signal="mouse_entered" from="Area2D" to="." method="_on_hover"] diff --git a/scenes/repository.gd b/scenes/repository.gd index 8222a3b..7c07700 100644 --- a/scenes/repository.gd +++ b/scenes/repository.gd @@ -107,6 +107,8 @@ func update_objects(): for p in commit_parents(o): c[p] = "" n.children = c + n.find_node("FileBrowser").mode = n.find_node("FileBrowser").FileBrowserMode.COMMIT + n.find_node("FileBrowser").commit = n _commit_count += 1 # if _commit_count >= 3 and not simplified_view: