Search in sources :

Example 26 with TrackedRuntimeException

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);
        }
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) ByteArrayInputStream(java.io.ByteArrayInputStream) JSONException(org.json.JSONException)

Example 27 with TrackedRuntimeException

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);
}
Also used : Callback(com.watabou.utils.Callback) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) TextureFilm(com.watabou.noosa.TextureFilm) JSONException(org.json.JSONException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 28 with TrackedRuntimeException

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);
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONException(org.json.JSONException)

Example 29 with TrackedRuntimeException

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";
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 30 with TrackedRuntimeException

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);
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SuppressLint(android.annotation.SuppressLint) BufferedReader(java.io.BufferedReader) File(java.io.File)

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