Load new level format

This commit is contained in:
Sebastian Morr 2020-09-30 18:10:05 +02:00
parent 08db98f41c
commit 91a57c49d7
6 changed files with 37 additions and 15 deletions

View file

@ -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"

View file

@ -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

View file

@ -1,2 +0,0 @@
git add .
git commit -m "Initial commit"

View file

@ -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

View file

@ -1 +0,0 @@
test "$(git rev-parse HEAD^{tree})" = 1e02e3151284d0e22cd9b07ca5c5dbae2f3cb521

View file

@ -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):