Savegames!

This commit is contained in:
blinry 2021-01-07 11:36:11 +01:00
parent 76c4aab834
commit 5c1f1ce722
4 changed files with 20 additions and 8 deletions

View file

@ -48,6 +48,8 @@ func update():
wd_files.pop_back()
wd_files = helpers.map(wd_files, self, "substr2")
var files = wd_files
var head_files
var index_files
@ -61,13 +63,12 @@ func update():
# The last entry is an empty string, remove it.
index_files.pop_back()
var files = wd_files
for f in head_files:
if not f in files:
files.push_back(f)
for f in index_files:
if not f in files:
files.push_back(f)
for f in head_files:
if not f in files:
files.push_back(f)
for f in index_files:
if not f in files:
files.push_back(f)
files.sort_custom(self, "very_best_sort")

View file

@ -28,7 +28,7 @@ func copy_script_to_game_env(name):
global_shell.run("chmod u+x '%s'" % (tmp_prefix + name))
func _initial_state():
return {"history": []}
return {"history": [], "solved_levels": []}
func save_state():
var savegame = File.new()

View file

@ -36,6 +36,11 @@ func reload():
b.text = level.title
b.align = HALIGN_LEFT
b.connect("pressed", self, "load", [chapter_id, level_id])
var slug = chapter.slug + "/" + level.slug
if slug in game.state["solved_levels"]:
b.set("custom_colors/font_color", Color(0.1, 0.8, 0.1, 1))
b.set("custom_colors/font_color_hover", Color(0.1, 0.8, 0.1, 1))
b.set("custom_colors/font_color_pressed", Color(0.1, 0.8, 0.1, 1))
level_list.add_child(b)
level_id += 1

View file

@ -143,6 +143,12 @@ func show_win_status(win_states):
level_description.hide()
level_congrats.show()
$SuccessSound.play()
if not game.state.has("solved_levels"):
game.state["solved_levels"] = []
var slug = levels.chapters[game.current_chapter].slug + "/" + level.slug
if not slug in game.state["solved_levels"]:
game.state["solved_levels"].push_back(slug)
game.save_state()
func repopulate_levels():
levels.reload()