From 91a57c49d752da569b1a14ea75dcf438359d8ab1 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Wed, 30 Sep 2020 18:10:05 +0200 Subject: [PATCH] Load new level format --- level.gd | 28 ++++++++++++++----- .../top-down/{commit/description => commit} | 15 ++++++++++ levels/top-down/commit/goal | 2 -- levels/top-down/commit/start | 4 --- levels/top-down/commit/win | 1 - text_editor.gd | 2 +- 6 files changed, 37 insertions(+), 15 deletions(-) rename levels/top-down/{commit/description => commit} (58%) delete mode 100644 levels/top-down/commit/goal delete mode 100644 levels/top-down/commit/start delete mode 100644 levels/top-down/commit/win diff --git a/level.gd b/level.gd index 018a176..1082132 100644 --- a/level.gd +++ b/level.gd @@ -16,16 +16,30 @@ func load(path): var parts = path.split("/") slug = parts[parts.size()-1] - description = helpers.read_file(path+"/description", "(no description)") + var dir = Directory.new() + if dir.dir_exists(path): + # This is an old-style level. + description = helpers.read_file(path+"/description", "(no description)") + congrats = helpers.read_file(path+"/congrats", "Good job, you solved the level!\n\nFeel free to try a few more things or click 'Next Level'.") + start_commands = helpers.read_file(path+"/start", "") + goal_commands = helpers.read_file(path+"/goal", "") + win_commands = helpers.read_file(path+"/win", "exit 1\n") + elif dir.file_exists(path): + # This is a new-style level. + var config = helpers.parse(path) + + description = config.get("description", "(no description)") + congrats = config.get("congrats", "Good job, you solved the level!\n\nFeel free to try a few more things or click 'Next Level'.") + start_commands = config.get("setup", "") + goal_commands = "" + win_commands = config.get("win", "exit 1\n") + else: + helpers.crash("Level %s does not exist." % path) + # Surround all lines indented with four spaces with [code] tags. var monospace_regex = RegEx.new() monospace_regex.compile("\n (.*)\n") description = monospace_regex.sub(description, "\n [code]$1[/code]\n", true) - - congrats = helpers.read_file(path+"/congrats", "Good job, you solved the level!\n\nFeel free to try a few more things or click 'Next Level'.") - start_commands = helpers.read_file(path+"/start", "") - goal_commands = helpers.read_file(path+"/goal", "") - win_commands = helpers.read_file(path+"/win", "exit 1\n") func construct(): _construct_repo(start_commands +"\n"+ goal_commands, _goal_repository_path) @@ -44,4 +58,4 @@ func _construct_repo(script_content, path): func check_win(): game.global_shell.cd(_active_repository_path) - return game.global_shell.run("function win { %s }; win 2>/dev/null >/dev/null && echo yes || echo no" % win_commands) == "yes\n" + return game.global_shell.run("function win { %s; }; win 2>/dev/null >/dev/null && echo yes || echo no" % win_commands) == "yes\n" diff --git a/levels/top-down/commit/description b/levels/top-down/commit similarity index 58% rename from levels/top-down/commit/description rename to levels/top-down/commit index 490e884..cb18e51 100644 --- a/levels/top-down/commit/description +++ b/levels/top-down/commit @@ -1,3 +1,7 @@ +title = "fu" + +[description] + So you've been working on a project for a while, and decide you want to put it in a Git repository. Here's how to do it! First, you initialize a new Git repository in your current directory: @@ -11,3 +15,14 @@ Then say that you want to record the current state of all files: And then you make a commit, which gives the current state a description, a date, and your name: git commit + +[setup] + +mkdir recipes +echo -e "blueberries\nflour" > recipes/blueberry_cake.txt +echo -e "water\ncarrots" > recipes/carrot soup.txt +echo "Very good recipes!" > README.md + +[win] + +test "$(git rev-parse HEAD^{tree})" = 1e02e3151284d0e22cd9b07ca5c5dbae2f3cb521 diff --git a/levels/top-down/commit/goal b/levels/top-down/commit/goal deleted file mode 100644 index bf9390a..0000000 --- a/levels/top-down/commit/goal +++ /dev/null @@ -1,2 +0,0 @@ -git add . -git commit -m "Initial commit" diff --git a/levels/top-down/commit/start b/levels/top-down/commit/start deleted file mode 100644 index 7d6a06f..0000000 --- a/levels/top-down/commit/start +++ /dev/null @@ -1,4 +0,0 @@ -mkdir recipes -echo -e "blueberries\nflour" > recipes/blueberry_cake.txt -echo -e "water\ncarrots" > recipes/carrot soup.txt -echo "Very good recipes!" > README.md diff --git a/levels/top-down/commit/win b/levels/top-down/commit/win deleted file mode 100644 index 19d4d8f..0000000 --- a/levels/top-down/commit/win +++ /dev/null @@ -1 +0,0 @@ -test "$(git rev-parse HEAD^{tree})" = 1e02e3151284d0e22cd9b07ca5c5dbae2f3cb521 diff --git a/text_editor.gd b/text_editor.gd index 3cfc830..144de9b 100644 --- a/text_editor.gd +++ b/text_editor.gd @@ -15,7 +15,7 @@ func _process(_delta): _client_connection = _server.take_connection() var length = _client_connection.get_u8() var filename = _client_connection.get_string(length) - filename = filename.replace("%s/active/" % game.tmp_prefix_inside, "") + filename = filename.replace("%srepos/active/" % game.tmp_prefix_inside, "") open(filename) func open(filename):