Loads the level
Source
load() async {
// Download and decode the level.json
final body = await HttpRequest.getString(path);
final Map data = JSON.decode(body);
// Check for spawnText
if (data.containsKey("spawnText") && data["spawnText"] is String) {
_spawnText = data["spawnText"];
}
// Check for size
if (data.containsKey("size") && _isVec2List(data["size"])) {
_size = _listToVec2(data["size"]);
}
// Check for the actors
if (data.containsKey("actors") && data["actors"] is List) {
_actors.clear();
for (final actdata in data["actors"]) {
if (actdata["type"] != null && _isVec2List(actdata["location"])) {
final actor = new ActorData();
actor.factory = () => _parseActor(actdata["type"].toString());
actor.location = _listToVec2(actdata["location"]);
if (_isVec2List(actdata["rotation"])) {
actor.rotation = _listToVec2(actdata["rotation"]);
}
if (_isVec2List(actdata["scale"])) {
actor.scale = _listToVec2(actdata["scale"]);
}
_actors.add(actor);
}
}
}
_ready = true;
}