Search in sources :

Example 11 with TrackedRuntimeException

use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.

the class StringsManager method addMappingForClass.

private static void addMappingForClass(Class<?> clazz) {
    for (Field f : clazz.getDeclaredFields()) {
        if (f.isSynthetic()) {
            continue;
        }
        int key;
        try {
            key = f.getInt(null);
        } catch (IllegalAccessException | IllegalArgumentException e) {
            throw new TrackedRuntimeException(e);
        }
        String name = f.getName();
        keyToInt.put(name, key);
    }
}
Also used : Field(java.lang.reflect.Field) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) SuppressLint(android.annotation.SuppressLint)

Example 12 with TrackedRuntimeException

use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.

the class TextureCache method getBitmap.

public static Bitmap getBitmap(Object src) {
    if (src instanceof String) {
        String resName = (String) src;
        InputStream stream = ModdingMode.getInputStream(resName);
        if (stream != null) {
            return BitmapFactory.decodeStream(stream);
        }
        throw new TrackedRuntimeException("Failed to load " + resName + "(mod: " + ModdingMode.activeMod() + ")");
    } else if (src instanceof Bitmap) {
        return (Bitmap) src;
    }
    throw new TrackedRuntimeException("Bad resource source for Bitmap " + src.getClass().getName());
}
Also used : Bitmap(android.graphics.Bitmap) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) InputStream(java.io.InputStream)

Example 13 with TrackedRuntimeException

use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.

the class PredesignedLevel method create.

@Override
public void create(int w, int h) {
    try {
        width = mLevelDesc.getInt("width");
        height = mLevelDesc.getInt("height");
        initSizeDependentStuff();
        JSONArray map = mLevelDesc.getJSONArray("map");
        for (int i = 0; i < map.length(); i++) {
            set(i, map.getInt(i));
        }
        readLevelParams();
        placeObjects();
        setupLinks();
    } catch (JSONException e) {
        throw new TrackedRuntimeException(e);
    }
    buildFlagMaps();
    cleanWalls();
    createMobs();
    createItems();
    createScript();
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 14 with TrackedRuntimeException

use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.

the class RandomLevel method create.

@Override
public void create(int w, int h) {
    try {
        width = mLevelDesc.getInt("width");
        height = mLevelDesc.getInt("height");
        initSizeDependentStuff();
        feeling = DungeonGenerator.getLevelFeeling(levelId);
        if (mLevelDesc.has("items")) {
            JSONArray itemsDesc = mLevelDesc.getJSONArray("items");
            for (int i = 0; i < itemsDesc.length(); ++i) {
                JSONObject itemDesc = itemsDesc.optJSONObject(i);
                Item item = ItemFactory.createItemFromDesc(itemDesc);
                addItemToSpawn(item);
            }
        }
    } catch (JSONException e) {
        throw new TrackedRuntimeException(e);
    } catch (InstantiationException e) {
        throw new TrackedRuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new TrackedRuntimeException(e);
    }
    do {
        Arrays.fill(map, feeling == Feeling.CHASM ? Terrain.CHASM : Terrain.WALL);
    } while (!build());
    buildFlagMaps();
    cleanWalls();
    createMobs();
    createItems();
    createScript();
}
Also used : Item(com.watabou.pixeldungeon.items.Item) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 15 with TrackedRuntimeException

use of com.nyrds.android.util.TrackedRuntimeException in project pixel-dungeon-remix by NYRDS.

the class RandomLevel method createMob.

@Override
protected Mob createMob() {
    try {
        if (mLevelDesc.has("mobs")) {
            JSONArray mobsDesc = mLevelDesc.getJSONArray("mobs");
            if (mobsSpawned < mobsDesc.length()) {
                JSONObject mobDesc = mobsDesc.optJSONObject(mobsSpawned);
                mobsSpawned++;
                String kind = mobDesc.getString("kind");
                Mob mob = MobFactory.mobByName(kind);
                mob.fromJson(mobDesc);
                setMobSpawnPos(mob);
                return mob;
            }
        }
    } catch (JSONException e) {
        throw new TrackedRuntimeException("invalid mob desc", e);
    } catch (Exception e) {
        EventCollector.logException(e);
    }
    return super.createMob();
}
Also used : Mob(com.watabou.pixeldungeon.actors.mobs.Mob) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONException(org.json.JSONException)

Aggregations

TrackedRuntimeException (com.nyrds.android.util.TrackedRuntimeException)41 JSONException (org.json.JSONException)24 JSONArray (org.json.JSONArray)15 JSONObject (org.json.JSONObject)10 IOException (java.io.IOException)5 Mob (com.watabou.pixeldungeon.actors.mobs.Mob)4 Item (com.watabou.pixeldungeon.items.Item)3 SuppressLint (android.annotation.SuppressLint)2 Pushing (com.watabou.pixeldungeon.effects.Pushing)2 Bitmap (android.graphics.Bitmap)1 Nullable (android.support.annotation.Nullable)1 FakeLastLevel (com.nyrds.pixeldungeon.levels.FakeLastLevel)1 GutsLevel (com.nyrds.pixeldungeon.levels.GutsLevel)1 IceCavesBossLevel (com.nyrds.pixeldungeon.levels.IceCavesBossLevel)1 IceCavesLevel (com.nyrds.pixeldungeon.levels.IceCavesLevel)1 NecroBossLevel (com.nyrds.pixeldungeon.levels.NecroBossLevel)1 NecroLevel (com.nyrds.pixeldungeon.levels.NecroLevel)1 PredesignedLevel (com.nyrds.pixeldungeon.levels.PredesignedLevel)1 RandomLevel (com.nyrds.pixeldungeon.levels.RandomLevel)1 ShadowLordLevel (com.nyrds.pixeldungeon.levels.ShadowLordLevel)1