use of com.nyrds.pixeldungeon.levels.PredesignedLevel in project pixel-dungeon-remix by NYRDS.
the class DungeonGenerator method createLevel.
public static Level createLevel(Position pos) {
Class<? extends Level> levelClass = mLevelKindList.get(getLevelKind(pos.levelId));
if (levelClass == null) {
GLog.w("Unknown level type: %s", getLevelKind(pos.levelId));
return createLevel(pos);
}
try {
Level ret;
String levelId = pos.levelId;
if (levelClass == PredesignedLevel.class) {
String levelFile = mLevels.getJSONObject(levelId).getString("file");
ret = new PredesignedLevel(levelFile);
} else if (levelClass == RandomLevel.class) {
String levelFile = mLevels.getJSONObject(levelId).getString("file");
ret = new RandomLevel(levelFile);
} else {
ret = levelClass.newInstance();
}
ret.levelId = levelId;
JSONObject levelDesc = mLevels.getJSONObject(pos.levelId);
int xs = 32;
int ys = 32;
if (levelDesc.has("size")) {
JSONArray levelSize = levelDesc.getJSONArray("size");
xs = levelSize.optInt(0, 32);
ys = levelSize.optInt(1, 32);
}
ret.create(xs, ys);
return ret;
} catch (InstantiationException | IllegalAccessException | JSONException e) {
throw new TrackedRuntimeException(e);
}
}
Aggregations