2020-09-29 19:40:17 +02:00
|
|
|
extends Node
|
|
|
|
class_name Chapter
|
|
|
|
|
|
|
|
var slug
|
|
|
|
var levels
|
|
|
|
|
|
|
|
# Path is an outer path.
|
|
|
|
func load(path):
|
|
|
|
levels = []
|
|
|
|
|
|
|
|
var parts = path.split("/")
|
|
|
|
slug = parts[parts.size()-1]
|
|
|
|
|
|
|
|
var level_names = []
|
|
|
|
var dir = Directory.new()
|
2022-08-18 17:52:39 +02:00
|
|
|
dir.open("res://levels/%s" % slug)
|
2020-09-29 19:40:17 +02:00
|
|
|
dir.list_dir_begin()
|
|
|
|
|
|
|
|
while true:
|
|
|
|
var file = dir.get_next()
|
|
|
|
if file == "":
|
|
|
|
break
|
|
|
|
elif not file.begins_with(".") and file != "sequence":
|
|
|
|
level_names.append(file)
|
|
|
|
|
|
|
|
dir.list_dir_end()
|
|
|
|
level_names.sort()
|
|
|
|
|
|
|
|
var final_level_sequence = []
|
|
|
|
|
2022-08-18 17:52:39 +02:00
|
|
|
var level_sequence = Array(helpers.read_file("res://levels/%s/sequence" % slug, "").split("\n"))
|
2020-09-29 19:40:17 +02:00
|
|
|
|
|
|
|
for level in level_sequence:
|
|
|
|
if level == "":
|
|
|
|
continue
|
|
|
|
if not level_names.has(level):
|
|
|
|
helpers.crash("Level '%s' is specified in the sequence, but could not be found" % level)
|
|
|
|
level_names.erase(level)
|
|
|
|
final_level_sequence.push_back(level)
|
|
|
|
|
2021-02-02 16:42:55 +01:00
|
|
|
#final_level_sequence += level_names
|
2020-09-29 19:40:17 +02:00
|
|
|
|
|
|
|
for l in final_level_sequence:
|
|
|
|
var level = Level.new()
|
2022-08-18 17:52:39 +02:00
|
|
|
level.load("res://levels/%s/%s" % [slug, l])
|
2020-09-29 19:40:17 +02:00
|
|
|
levels.push_back(level)
|
|
|
|
|
|
|
|
func _to_string():
|
|
|
|
return str(levels)
|