-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLevelConfig.gd
More file actions
42 lines (36 loc) · 1.17 KB
/
LevelConfig.gd
File metadata and controls
42 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class_name LevelConfig
const Data = preload("res://Util/Data.gd")
const SpecCompiler = preload("res://SpecCompiler.gd")
var config
var camera_provider
var event_bus
var flag_provider
func _init(level_name, the_camera_provider, the_event_bus, the_flag_provider):
config = Data.load_config(level_name)[1]
camera_provider = the_camera_provider
event_bus = the_event_bus
flag_provider = the_flag_provider
func compile():
var specs = []
for section in config.get_sections():
var spec = section_to_dict(section)
var with_camera = add_camera_provider(spec)
var compiled = SpecCompiler.compile_spec(with_camera)
specs.push_back(compiled)
return specs
func section_to_dict(section):
var dict = {"id": section}
var keys = config.get_section_keys(section)
for j in keys.size():
dict[keys[j]] = config.get_value(section, keys[j])
return dict
func add_camera_provider(spec):
spec["camera_provider"] = camera_provider
spec["event_bus"] = event_bus
spec["flag_provider"] = flag_provider
if spec.has("subsections"):
var subspecs = []
for subsection in spec["subsections"]:
subspecs.push_back(add_camera_provider(subsection))
spec["subsections"] = subspecs
return spec