Extract terminal in its own scene, add a few proper levels with a description

This commit is contained in:
Sebastian Morr 2020-09-03 19:22:46 +02:00
parent ebbb505283
commit 7373984d47
18 changed files with 179 additions and 92 deletions

View file

@ -0,0 +1,11 @@
At its core, Git is very simple. It stores "objects", which are basically files identified by an "identifier" (short: ID).
There are four types of objects: blobs, trees, commits, and tags. The simplest type is a "blob", which is just a piece of text.
Let's create some blobs! To do that, create a file with the desired content, and then use
$ git hash-object -w <file>
The flag -w means "write", and tells Git to actually write the new blob to the disk.
Create three new blobs!

View file

@ -0,0 +1,21 @@
Blobs just have some content and an ID. It would be convenient to be able to give names to a blob, right?
The second type of Git object is called a "tree" - a tree points a bunch of blobs, and gives each of them a name!
How can we build our own trees? Introducing: the index!
The index is like a "work in progress" version of a tree, where we can add and remove blobs. When we're happy with what we have built, we can make it into a real tree object!
We can use
$ git update-index --add <file>
to make the file's content into a blob, and to add that blob to the index using the file's name.
When we're happy with out index, we can convert it into a tree using
$ git write-tree
That command will output the ID of the newly crated tree.
Build a tree containing just the 'noises' file, which we conveniently placed in your current directory! :)

6
levels/02-tree/goal Normal file
View file

@ -0,0 +1,6 @@
echo 'meow' > noises
git update-index --add noises
git write-tree
rm noises
git update-index --remove noises

1
levels/02-tree/start Normal file
View file

@ -0,0 +1 @@
echo 'meow' > noises

View file

@ -0,0 +1,9 @@
So a tree describes the state of a directory structure at a specific point in time.
It would be nice if we could remember when that state existed, and who authored it, right?
Enter: commits. They are objects that point to a tree and contain some additional metadata. You can create a commit using
$ git commit-tree <tree> -m "Description of your commit"
Make a commit from the tree in this repository!

7
levels/03-commit/goal Normal file
View file

@ -0,0 +1,7 @@
touch empty_file
git add .
git write-tree
git commit-tree 3185 -m 'Clever commit message'
rm empty_file
git update-index --remove empty_file

6
levels/03-commit/start Normal file
View file

@ -0,0 +1,6 @@
touch empty_file
git add .
git write-tree
rm empty_file
git update-index --remove empty_file

View file

@ -0,0 +1,5 @@
When using the commit-tree command, you can optionally specify a parent:
$ git commit-tree <tree> -m "Description" -p <parent commit>
Can you make a string of three commits? We placed an empty tree in your repo to get you started.

2
levels/04-parents/goal Normal file
View file

@ -0,0 +1,2 @@
git write-tree
git commit-tree 4b82 -m 'We cannot really construct the goal yet :)'

1
levels/04-parents/start Normal file
View file

@ -0,0 +1 @@
git write-tree

View file

@ -1 +0,0 @@
git commit --allow-empty -m "Emtpy commit"

View file

@ -1,5 +0,0 @@
echo -e "bread\ntomato\nbread" > sandwich
git add sandwich
git commit -m "Initial sandwich"
echo -e "bread\ntomato\ncucumber\nbread" > sandwich
git commit -am "Add cucumber"

View file

@ -39,6 +39,7 @@ func list_levels():
levels.append(file)
dir.list_dir_end()
levels.sort()
return levels
func load_level(id):
@ -54,6 +55,9 @@ func load_level(id):
var goal_script = level_prefix+level+"/goal"
var active_script = level_prefix+level+"/start"
var description = game.read_file(level_prefix+level+"/description")
$LevelDescription.bbcode_text = description
OS.execute("rm", ["-r", active_repository_path], true)
OS.execute("rm", ["-r", goal_repository_path], true)
construct_repo(goal_script, goal_repository_path)

107
main.tscn
View file

@ -1,17 +1,10 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://terminal.gd" type="Script" id=1]
[ext_resource path="res://terminal.tscn" type="PackedScene" id=1]
[ext_resource path="res://main.gd" type="Script" id=2]
[ext_resource path="res://repository.tscn" type="PackedScene" id=3]
[ext_resource path="res://command_button.tscn" type="PackedScene" id=4]
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=5]
[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0, 0, 0, 1 )
[sub_resource type="StyleBoxFlat" id=2]
bg_color = Color( 0, 0, 0, 1 )
[node name="Main" type="Node2D"]
script = ExtResource( 2 )
@ -24,71 +17,13 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Terminal" type="Control" parent="."]
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Control" type="VBoxContainer" parent="Terminal"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 1208.0
margin_top = 6.0
margin_right = 1908.0
margin_bottom = 1070.0
custom_constants/separation = 0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Output" type="TextEdit" parent="Terminal/Control"]
margin_right = 700.0
margin_bottom = 1038.0
focus_mode = 0
size_flags_vertical = 3
custom_styles/read_only = SubResource( 1 )
custom_fonts/font = ExtResource( 5 )
readonly = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Button" parent="Terminal/Control" instance=ExtResource( 4 )]
visible = false
margin_left = 0.0
margin_top = 852.0
margin_right = 700.0
margin_bottom = 905.0
align = 0
[node name="Button2" parent="Terminal/Control" instance=ExtResource( 4 )]
visible = false
margin_left = 0.0
margin_top = 905.0
margin_right = 700.0
margin_bottom = 958.0
text = "git switch -c $RANDOM"
align = 0
[node name="Button3" parent="Terminal/Control" instance=ExtResource( 4 )]
visible = false
margin_left = 0.0
margin_top = 958.0
margin_right = 700.0
margin_bottom = 1011.0
text = "git checkout HEAD^"
align = 0
[node name="Input" type="LineEdit" parent="Terminal/Control"]
margin_top = 1038.0
margin_right = 700.0
margin_bottom = 1064.0
custom_styles/normal = SubResource( 2 )
custom_fonts/font = ExtResource( 5 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Terminal" parent="." instance=ExtResource( 1 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 1223.0
margin_top = 484.0
margin_right = 1898.0
margin_bottom = 1059.0
[node name="CommitMessage" type="TextEdit" parent="."]
visible = false
@ -111,10 +46,10 @@ __meta__ = {
}
[node name="LevelSelect" type="MenuButton" parent="."]
margin_left = 11.5584
margin_top = 1036.1
margin_right = 173.558
margin_bottom = 1068.1
margin_left = 1226.25
margin_top = 16.2615
margin_right = 1388.25
margin_bottom = 48.2615
custom_fonts/font = ExtResource( 5 )
text = "Select level..."
flat = false
@ -153,6 +88,18 @@ margin_right = 1198.0
margin_bottom = 1033.0
size_flags_horizontal = 3
size_flags_vertical = 3
label = "Yours!"
[connection signal="text_entered" from="Terminal/Control/Input" to="Terminal" method="send_command"]
label = "Your repository"
[node name="LevelDescription" type="RichTextLabel" parent="."]
margin_left = 1224.0
margin_top = 58.0
margin_right = 1889.0
margin_bottom = 472.0
custom_fonts/normal_font = ExtResource( 5 )
bbcode_enabled = true
bbcode_text = "Level description here!"
text = "Level description here!"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="CommitMessage/SaveButton" to="." method="save_commit_message"]

View file

@ -17,11 +17,11 @@ __meta__ = {
}
[node name="Index" type="Label" parent="."]
visible = false
margin_left = 36.0787
margin_top = 120.0
margin_left = 32.0
margin_top = 80.0
margin_right = 375.079
margin_bottom = 1044.0
custom_fonts/font = ExtResource( 2 )
text = "file1
file2"
__meta__ = {
@ -29,9 +29,8 @@ __meta__ = {
}
[node name="IndexLabel" type="Label" parent="."]
visible = false
margin_left = 38.0
margin_top = 69.0
margin_left = 21.0
margin_top = 65.0
margin_right = 377.0
margin_bottom = 108.0
text = "Index:"

74
terminal.tscn Normal file
View file

@ -0,0 +1,74 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=1]
[ext_resource path="res://terminal.gd" type="Script" id=2]
[ext_resource path="res://command_button.tscn" type="PackedScene" id=4]
[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0, 0, 0, 1 )
[sub_resource type="StyleBoxFlat" id=2]
bg_color = Color( 0, 0, 0, 1 )
[node name="Terminal" type="Container"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Control" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
custom_constants/separation = 0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Output" type="TextEdit" parent="Control"]
margin_right = 1920.0
margin_bottom = 1054.0
focus_mode = 0
size_flags_vertical = 3
custom_styles/read_only = SubResource( 1 )
custom_fonts/font = ExtResource( 1 )
readonly = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Button" parent="Control" instance=ExtResource( 4 )]
visible = false
margin_top = 852.0
margin_right = 700.0
margin_bottom = 905.0
align = 0
[node name="Button2" parent="Control" instance=ExtResource( 4 )]
visible = false
margin_top = 905.0
margin_right = 700.0
margin_bottom = 958.0
text = "git switch -c $RANDOM"
align = 0
[node name="Button3" parent="Control" instance=ExtResource( 4 )]
visible = false
margin_top = 958.0
margin_right = 700.0
margin_bottom = 1011.0
text = "git checkout HEAD^"
align = 0
[node name="Input" type="LineEdit" parent="Control"]
margin_top = 1054.0
margin_right = 1920.0
margin_bottom = 1080.0
custom_styles/normal = SubResource( 2 )
custom_fonts/font = ExtResource( 1 )
caret_blink = true
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="text_entered" from="Control/Input" to="." method="send_command"]