use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.
the class CustomLevel method readDescFile.
protected void readDescFile(String descFile) {
if (descFile.endsWith(".json")) {
mLevelDesc = JsonHelper.readJsonFromAsset(descFile);
return;
}
if (descFile.endsWith(".lua")) {
LuaEngine.getEngine().runScriptFile(descFile);
String desc = LuaEngine.getEngine().call("getJson").tojstring();
try {
mLevelDesc = JsonHelper.readJsonFromStream(new ByteArrayInputStream(desc.getBytes()));
} catch (JSONException e) {
throw new TrackedRuntimeException(e);
}
}
}
use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.
the class MobSpriteDef method selectKind.
@Override
public void selectKind(int kind) {
EventCollector.collectSessionData("selectKind", name);
this.kind = kind;
JSONObject json = defMap.get(name);
try {
texture(json.getString("texture"));
if (json.has("layers")) {
JSONArray layers = json.getJSONArray("layers");
for (int i = 0; i < layers.length(); ++i) {
JSONObject layer = layers.getJSONObject(i);
addLayer(layer.getString("id"), TextureCache.get(layer.get("texture")));
}
}
int width = json.getInt("width");
TextureFilm film = new TextureFilm(texture, width, json.getInt("height"));
bloodColor = 0xFFBB0000;
Object _bloodColor = json.opt("bloodColor");
if (_bloodColor instanceof Number) {
bloodColor = (int) _bloodColor;
}
if (_bloodColor instanceof String) {
bloodColor = Long.decode((String) _bloodColor).intValue();
}
levitating = json.optBoolean("levitating", false);
framesInRow = texture.width / width;
idle = readAnimation(json, "idle", film);
run = readAnimation(json, "run", film);
attack = readAnimation(json, "attack", film);
die = readAnimation(json, "die", film);
if (json.has("zap")) {
zap = readAnimation(json, "zap", film);
} else {
zap = attack.clone();
}
if (json.has("zapEffect")) {
zapEffect = json.getString("zapEffect");
zapCallback = new Callback() {
@Override
public void call() {
// ch.onZapComplete();
}
};
}
loadAdditionalData(json, film, kind);
} catch (Exception e) {
Game.toast(Utils.format("Something bad happens when loading %s", name), e);
throw new TrackedRuntimeException(Utils.format("Something bad happens when loading %s", name), e);
}
play(idle);
}
use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.
the class DungeonGenerator method initLevelsMap.
private static void initLevelsMap() {
if (BuildConfig.DEBUG) {
mDungeonMap = JsonHelper.readJsonFromAsset("levelsDesc/Dungeon_debug.json");
} else {
mDungeonMap = JsonHelper.readJsonFromAsset("levelsDesc/Dungeon.json");
}
try {
mLevels = mDungeonMap.getJSONObject("Levels");
mGraph = mDungeonMap.getJSONObject("Graph");
} catch (JSONException e) {
throw new TrackedRuntimeException(e);
}
mLevelKindList = new HashMap<>();
registerLevelClass(SewerLevel.class);
registerLevelClass(SewerBossLevel.class);
registerLevelClass(SpiderLevel.class);
registerLevelClass(PrisonLevel.class);
registerLevelClass(PrisonBossLevel.class);
registerLevelClass(CavesLevel.class);
registerLevelClass(CavesBossLevel.class);
registerLevelClass(CityLevel.class);
registerLevelClass(CityBossLevel.class);
registerLevelClass(LastShopLevel.class);
registerLevelClass(HallsLevel.class);
registerLevelClass(HallsBossLevel.class);
registerLevelClass(LastLevel.class);
registerLevelClass(DeadEndLevel.class);
registerLevelClass(PredesignedLevel.class);
registerLevelClass(GutsLevel.class);
registerLevelClass(ShadowLordLevel.class);
registerLevelClass(FakeLastLevel.class);
registerLevelClass(NecroLevel.class);
registerLevelClass(NecroBossLevel.class);
registerLevelClass(IceCavesLevel.class);
registerLevelClass(IceCavesBossLevel.class);
registerLevelClass(RandomLevel.class);
registerLevelClass(TownShopLevel.class);
}
use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.
the class DungeonGenerator method guessLevelId.
static String guessLevelId(String levelKind, int levelDepth) {
try {
JSONArray ids = mLevels.names();
for (int i = 0; i < ids.length(); i++) {
String id = ids.getString(i);
JSONObject levelDesc = mLevels.getJSONObject(id);
if (levelDesc.getString("kind").equals(levelKind)) {
if (levelDesc.getInt("depth") == levelDepth) {
return id;
}
}
}
} catch (JSONException e) {
throw new TrackedRuntimeException(e);
}
return "1";
}
use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.
the class StringsManager method parseStrings.
private static void parseStrings(String resource) {
File jsonFile = ModdingMode.getFile(resource);
if (jsonFile == null || !jsonFile.exists()) {
return;
}
String line = "";
try {
InputStream fis = new FileInputStream(jsonFile);
InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
JSONArray entry = new JSONArray(line);
String keyString = entry.getString(0);
Integer key = keyToInt.get(keyString);
if (entry.length() == 2) {
String value = entry.getString(1);
if (key != null) {
stringMap.put(key, value);
}
sStringMap.put(keyString, value);
}
if (entry.length() > 2) {
String[] values = new String[entry.length() - 1];
for (int i = 1; i < entry.length(); i++) {
values[i - 1] = entry.getString(i);
}
if (key != null) {
stringsMap.put(key, values);
}
sStringsMap.put(keyString, values);
}
}
br.close();
} catch (IOException e) {
throw new TrackedRuntimeException(e);
} catch (JSONException e) {
Game.toast("malformed json: [%s] in [%s] ignored ", line, resource);
}
}
Aggregations