25 lines
553 B
GDScript
25 lines
553 B
GDScript
class_name Levels
|
|
extends RefCounted
|
|
|
|
const PATH := "res://data/levels.json"
|
|
|
|
|
|
static func load_all() -> Array:
|
|
if not FileAccess.file_exists(PATH):
|
|
push_warning("No level file at %s. Run tools/generate_levels.gd." % PATH)
|
|
return []
|
|
|
|
var file := FileAccess.open(PATH, FileAccess.READ)
|
|
if file == null:
|
|
push_warning("Could not open %s." % PATH)
|
|
return []
|
|
|
|
var parsed = JSON.parse_string(file.get_as_text())
|
|
file.close()
|
|
|
|
if typeof(parsed) != TYPE_ARRAY:
|
|
push_warning("%s did not contain a JSON array." % PATH)
|
|
return []
|
|
|
|
return parsed
|