Future load()

Loads all levels

Source

load() async {

    // Get the levels.json
    String body = await HttpRequest.getString(path);
    List data = JSON.decode(body);
    if (!(data is List)) return [];

    // Reset the state
    _levels = [];
    _ready = false;

    // Load each level
    for (final lvldata in data) {
        if (lvldata is Map && lvldata["path"] != null) {
            final level = new Level(lvldata["path"]);
            try {
                await level.load();
                if (level.ready) {
                    _levels.add(level);
                }
            } catch(err) {}
        }
    }

    // Indicate we finished loading
    _ready = true;
}