From 9cfbd9ff96c52c3aa6ada9e3b5e871975c52b509 Mon Sep 17 00:00:00 2001 From: blinry Date: Tue, 22 Dec 2020 12:13:40 +0100 Subject: [PATCH] Allow splitting win conditions in multiple parts --- levels/time-machine/branching | 7 +++++-- scenes/level.gd | 35 +++++++++++++++++++---------------- scenes/level_repo.gd | 2 +- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/levels/time-machine/branching b/levels/time-machine/branching index cb1968e..114decd 100644 --- a/levels/time-machine/branching +++ b/levels/time-machine/branching @@ -38,8 +38,11 @@ git branch -d main [win] -# Is the child still there, and is the lion not hungry? -{ git ls-tree --name-only -r HEAD | grep child; } && { git show HEAD:cage/lion | grep -v "very hungry"; } +# Is the child still there? +git ls-tree --name-only -r HEAD | grep child + +# Is the lion not hungry? +git show HEAD:cage/lion | grep -v "very hungry" [congrats] diff --git a/scenes/level.gd b/scenes/level.gd index 13610c0..25ef896 100644 --- a/scenes/level.gd +++ b/scenes/level.gd @@ -37,7 +37,7 @@ func load(path): for k in repo_setups: var repo - if " " in k: + if " " in k: # [setup yours] repo = Array(k.split(" "))[1] else: repo = "yours" @@ -51,18 +51,19 @@ func load(path): repo = Array(k.split(" "))[1] else: repo = "yours" - repos[repo].win_commands = config[k] - elif dir.file_exists(path+"/description"): - # 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'.") - - var yours = LevelRepo.new() - yours.setup_commands = helpers.read_file(path+"/start", "") - #goal_commands = helpers.read_file(path+"/goal", "") - yours.win_commands = helpers.read_file(path+"/win", "") - - repos["yours"] = yours + + var description = "Goal" + for line in Array(config[k].split("\n")): + if line.length() > 0 and line[0] == "#": + description = line.substr(1) + else: + if not repos[repo].win_conditions.has(description): + repos[repo].win_conditions[description] = "" + repos[repo].win_conditions[description] += line+"\n" + +# for desc in repos[repo].win_conditions: +# print("Desc: " + desc) +# print("Commands: " + repos[repo].win_conditions[desc]) else: helpers.crash("Level %s does not exist." % path) @@ -106,9 +107,11 @@ func check_win(): var any_checked = false for r in repos: var repo = repos[r] - if repo.win_commands != "": + if repo.win_conditions.size() > 0: any_checked = true game.global_shell.cd(repo.path) - if not game.global_shell.run("function win { %s\n}; win 2>/dev/null >/dev/null && echo yes || echo no" % repo.win_commands) == "yes\n": - won = false + for description in repo.win_conditions: + var commands = repo.win_conditions[description] + if not game.global_shell.run("function win { %s\n}; win 2>/dev/null >/dev/null && echo yes || echo no" % commands) == "yes\n": + won = false return won and any_checked diff --git a/scenes/level_repo.gd b/scenes/level_repo.gd index aafb04b..407e5f4 100644 --- a/scenes/level_repo.gd +++ b/scenes/level_repo.gd @@ -4,4 +4,4 @@ class_name LevelRepo var slug var path var setup_commands = "" -var win_commands = "" +var win_conditions = {}