Handle files without a position in them. Streamline cards a bit.

This commit is contained in:
blinry 2020-11-18 22:31:23 +01:00
parent ca09ad0245
commit 12e9aff7ff
5 changed files with 51 additions and 23 deletions

13
levels/2d/sandbox Normal file
View file

@ -0,0 +1,13 @@
title = Sandbox
cards = checkout add reset commit merge rebase-interactive file-new file-delete
[setup]
echo "x = 200
y = 100" > apple
echo "x = 400
y = 100" > pen
git add .
git commit -m "The beginning"

1
levels/2d/sequence Normal file
View file

@ -0,0 +1 @@
sandbox

View file

@ -11,7 +11,7 @@
},
{
"id": "checkout",
"command": "git checkout [commit, ref]",
"command": "git checkout [commit, ref, file]",
"description": "Drag this card to a commit or to a branch to travel to it!"
},
{
@ -56,7 +56,7 @@
},
{
"id": "reset",
"command": "git reset [commit]",
"command": "git reset [commit, file]",
"description": "Jump to the commit, and update the index. Keep the current environment."
},
{
@ -86,7 +86,7 @@
},
{
"id": "commit",
"command": "git commit",
"command": "git commit -m $RANDOM",
"description": "Make a commit from the plan."
},
{

View file

@ -79,16 +79,17 @@ func update():
# 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)
if shell.run("git rev-parse HEAD &> /dev/null && 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.
@ -116,12 +117,12 @@ func update():
wd_files.pop_back()
wd_files = helpers.map(wd_files, self, "substr2")
var deleted_files = []
if shell.run("test -d .git && echo yes || echo no") == "yes\n":
deleted_files = Array(shell.run("git status -s | grep '^.D' | sed 's/^...//'").split("\n"))
deleted_files.pop_back()
# var deleted_files = []
# if shell.run("test -d .git && echo yes || echo no") == "yes\n":
# deleted_files = Array(shell.run("git status -s | grep '^.D' | sed 's/^...//'").split("\n"))
# deleted_files.pop_back()
var files = wd_files + deleted_files
var files = wd_files# + deleted_files
player = null
files.sort_custom(self, "very_best_sort")

View file

@ -34,21 +34,28 @@ func read_from_file():
"index":
content = file_browser.shell.run("git show :'%s'" % label)
modulate = Color(0, 0, 1.0)
$Sprite.scale = Vector2(0.75, 0.75)
$Sprite.scale *= 1.2
"head":
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)
$Sprite.scale *= 1.4
content = file_browser.shell.run("git show %s:'%s'" % [commit, label])
attributes = helpers.parse(content)
position.x = int(attributes["x"])
position.y = int(attributes["y"])
if attributes.has("x"):
position.x = float(attributes["x"])
else:
position.x = rand_range(100, 400)
if attributes.has("y"):
position.y = float(attributes["y"])
else:
position.y = rand_range(100, 300)
write_to_file()
func write_to_file():
attributes["x"] = str(position.x)
attributes["y"] = str(position.y)
@ -62,6 +69,12 @@ func _set_label(new_label):
label = new_label
if label_node:
label_node.text = helpers.abbreviate(new_label, 30)
if new_label == "you":
$Sprite.texture = preload("res://nodes/head.svg")
else:
$Sprite.texture = preload("res://nodes/document.svg")
$Sprite.scale *= 0.85
#func _gui_input(event):
# if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_LEFT: