From 7373984d476646d447b9424f6f8378c1773b2059 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Thu, 3 Sep 2020 19:22:46 +0200 Subject: [PATCH] Extract terminal in its own scene, add a few proper levels with a description --- levels/01-blob/description | 11 ++++ levels/{blobs => 01-blob}/goal | 0 levels/{blobs => 01-blob}/start | 0 levels/02-tree/description | 21 +++++++ levels/02-tree/goal | 6 ++ levels/02-tree/start | 1 + levels/03-commit/description | 9 +++ levels/03-commit/goal | 7 +++ levels/03-commit/start | 6 ++ levels/04-parents/description | 5 ++ levels/04-parents/goal | 2 + levels/04-parents/start | 1 + levels/first/goal | 1 - levels/first/start | 5 -- main.gd | 4 ++ main.tscn | 107 ++++++++------------------------ repository.tscn | 11 ++-- terminal.tscn | 74 ++++++++++++++++++++++ 18 files changed, 179 insertions(+), 92 deletions(-) create mode 100644 levels/01-blob/description rename levels/{blobs => 01-blob}/goal (100%) rename levels/{blobs => 01-blob}/start (100%) create mode 100644 levels/02-tree/description create mode 100644 levels/02-tree/goal create mode 100644 levels/02-tree/start create mode 100644 levels/03-commit/description create mode 100644 levels/03-commit/goal create mode 100644 levels/03-commit/start create mode 100644 levels/04-parents/description create mode 100644 levels/04-parents/goal create mode 100644 levels/04-parents/start delete mode 100644 levels/first/goal delete mode 100644 levels/first/start create mode 100644 terminal.tscn diff --git a/levels/01-blob/description b/levels/01-blob/description new file mode 100644 index 0000000..d8a3e86 --- /dev/null +++ b/levels/01-blob/description @@ -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 + +The flag -w means "write", and tells Git to actually write the new blob to the disk. + +Create three new blobs! diff --git a/levels/blobs/goal b/levels/01-blob/goal similarity index 100% rename from levels/blobs/goal rename to levels/01-blob/goal diff --git a/levels/blobs/start b/levels/01-blob/start similarity index 100% rename from levels/blobs/start rename to levels/01-blob/start diff --git a/levels/02-tree/description b/levels/02-tree/description new file mode 100644 index 0000000..0ddfc7a --- /dev/null +++ b/levels/02-tree/description @@ -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 + +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! :) diff --git a/levels/02-tree/goal b/levels/02-tree/goal new file mode 100644 index 0000000..f436171 --- /dev/null +++ b/levels/02-tree/goal @@ -0,0 +1,6 @@ +echo 'meow' > noises +git update-index --add noises +git write-tree + +rm noises +git update-index --remove noises diff --git a/levels/02-tree/start b/levels/02-tree/start new file mode 100644 index 0000000..f2bfbe9 --- /dev/null +++ b/levels/02-tree/start @@ -0,0 +1 @@ +echo 'meow' > noises diff --git a/levels/03-commit/description b/levels/03-commit/description new file mode 100644 index 0000000..1cdd206 --- /dev/null +++ b/levels/03-commit/description @@ -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 -m "Description of your commit" + +Make a commit from the tree in this repository! diff --git a/levels/03-commit/goal b/levels/03-commit/goal new file mode 100644 index 0000000..792c523 --- /dev/null +++ b/levels/03-commit/goal @@ -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 diff --git a/levels/03-commit/start b/levels/03-commit/start new file mode 100644 index 0000000..f4fe58c --- /dev/null +++ b/levels/03-commit/start @@ -0,0 +1,6 @@ +touch empty_file +git add . +git write-tree + +rm empty_file +git update-index --remove empty_file diff --git a/levels/04-parents/description b/levels/04-parents/description new file mode 100644 index 0000000..9eda844 --- /dev/null +++ b/levels/04-parents/description @@ -0,0 +1,5 @@ +When using the commit-tree command, you can optionally specify a parent: + + $ git commit-tree -m "Description" -p + +Can you make a string of three commits? We placed an empty tree in your repo to get you started. diff --git a/levels/04-parents/goal b/levels/04-parents/goal new file mode 100644 index 0000000..7dd6ee2 --- /dev/null +++ b/levels/04-parents/goal @@ -0,0 +1,2 @@ +git write-tree +git commit-tree 4b82 -m 'We cannot really construct the goal yet :)' diff --git a/levels/04-parents/start b/levels/04-parents/start new file mode 100644 index 0000000..7654925 --- /dev/null +++ b/levels/04-parents/start @@ -0,0 +1 @@ +git write-tree diff --git a/levels/first/goal b/levels/first/goal deleted file mode 100644 index d5e174d..0000000 --- a/levels/first/goal +++ /dev/null @@ -1 +0,0 @@ -git commit --allow-empty -m "Emtpy commit" diff --git a/levels/first/start b/levels/first/start deleted file mode 100644 index 8d17c26..0000000 --- a/levels/first/start +++ /dev/null @@ -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" diff --git a/main.gd b/main.gd index 77387bd..56d569c 100644 --- a/main.gd +++ b/main.gd @@ -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) diff --git a/main.tscn b/main.tscn index b36266e..52fac23 100644 --- a/main.tscn +++ b/main.tscn @@ -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"] diff --git a/repository.tscn b/repository.tscn index 64f7065..830b593 100644 --- a/repository.tscn +++ b/repository.tscn @@ -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:" diff --git a/terminal.tscn b/terminal.tscn new file mode 100644 index 0000000..6b37128 --- /dev/null +++ b/terminal.tscn @@ -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"]