Allow splitting win conditions in multiple parts

This commit is contained in:
blinry 2020-12-22 12:13:40 +01:00
parent 04e48a8bf2
commit 9cfbd9ff96
3 changed files with 25 additions and 19 deletions

View file

@ -38,8 +38,11 @@ git branch -d main
[win] [win]
# Is the child still there, and is the lion not hungry? # Is the child still there?
{ git ls-tree --name-only -r HEAD | grep child; } && { git show HEAD:cage/lion | grep -v "very hungry"; } git ls-tree --name-only -r HEAD | grep child
# Is the lion not hungry?
git show HEAD:cage/lion | grep -v "very hungry"
[congrats] [congrats]

View file

@ -37,7 +37,7 @@ func load(path):
for k in repo_setups: for k in repo_setups:
var repo var repo
if " " in k: if " " in k: # [setup yours]
repo = Array(k.split(" "))[1] repo = Array(k.split(" "))[1]
else: else:
repo = "yours" repo = "yours"
@ -51,18 +51,19 @@ func load(path):
repo = Array(k.split(" "))[1] repo = Array(k.split(" "))[1]
else: else:
repo = "yours" 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() var description = "Goal"
yours.setup_commands = helpers.read_file(path+"/start", "") for line in Array(config[k].split("\n")):
#goal_commands = helpers.read_file(path+"/goal", "") if line.length() > 0 and line[0] == "#":
yours.win_commands = helpers.read_file(path+"/win", "") 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"
repos["yours"] = yours # for desc in repos[repo].win_conditions:
# print("Desc: " + desc)
# print("Commands: " + repos[repo].win_conditions[desc])
else: else:
helpers.crash("Level %s does not exist." % path) helpers.crash("Level %s does not exist." % path)
@ -106,9 +107,11 @@ func check_win():
var any_checked = false var any_checked = false
for r in repos: for r in repos:
var repo = repos[r] var repo = repos[r]
if repo.win_commands != "": if repo.win_conditions.size() > 0:
any_checked = true any_checked = true
game.global_shell.cd(repo.path) 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": for description in repo.win_conditions:
won = false 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 return won and any_checked

View file

@ -4,4 +4,4 @@ class_name LevelRepo
var slug var slug
var path var path
var setup_commands = "" var setup_commands = ""
var win_commands = "" var win_conditions = {}