Search in sources :

Example 1 with TrackedRuntimeException

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

the class Dungeon method saveAllImpl.

private static void saveAllImpl() {
    float MBytesAvailable = Game.getAvailableInternalMemorySize() / 1024f / 1024f;
    if (MBytesAvailable < 2) {
        EventCollector.logEvent("saveGame", "lowMemory");
        Game.toast("Low memory condition");
    }
    if (hero.isAlive()) {
        Actor.fixTime();
        try {
            Position current = currentPosition();
            String saveToLevel = SaveUtils.depthFileForSave(hero.heroClass, DungeonGenerator.getLevelDepth(current.levelId), DungeonGenerator.getLevelKind(current.levelId), current.levelId);
            String saveToGame = SaveUtils.gameFile(hero.heroClass);
            saveGame("tmp.game");
            saveLevel("tmp.level");
            FileSystem.getInternalStorageFile(saveToGame).delete();
            FileSystem.getInternalStorageFile(saveToLevel).delete();
            FileSystem.getInternalStorageFile("tmp.game").renameTo(FileSystem.getInternalStorageFile(saveToGame));
            FileSystem.getInternalStorageFile("tmp.level").renameTo(FileSystem.getInternalStorageFile(saveToLevel));
        } catch (IOException e) {
            throw new TrackedRuntimeException("cannot write save", e);
        }
        GamesInProgress.set(hero.heroClass, depth, hero.lvl());
    } else if (WndResurrect.instance != null) {
        WndResurrect.instance.hide();
        Hero.reallyDie(WndResurrect.causeOfDeath);
    }
    Badges.saveGlobal();
    Library.saveLibrary();
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) Position(com.nyrds.pixeldungeon.utils.Position) IOException(java.io.IOException)

Example 2 with TrackedRuntimeException

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

the class Dungeon method save.

public static synchronized void save() {
    if (SystemTime.now() - lastSaveTimestamp < 250) {
        GLog.i("Saving too fast...");
        return;
    }
    lastSaveTimestamp = SystemTime.now();
    try {
        EventCollector.startTiming("saveGame");
        saveAllImpl();
        EventCollector.stopTiming("saveGame");
    } catch (Exception e) {
        throw new TrackedRuntimeException(e);
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) IOException(java.io.IOException)

Example 3 with TrackedRuntimeException

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

the class Buff method affect.

public static <T extends Buff> T affect(Char target, Class<T> buffClass) {
    T buff = target.buff(buffClass);
    if (buff != null) {
        return buff;
    } else {
        try {
            buff = buffClass.newInstance();
            buff.attachTo(target);
            return buff;
        } catch (Exception e) {
            throw new TrackedRuntimeException(e);
        }
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException)

Example 4 with TrackedRuntimeException

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

the class Library method infoHeader.

public static EntryHeader infoHeader(String category, String clazz) {
    EntryHeader ret = new EntryHeader();
    if (category.equals(ITEM)) {
        Item item = ItemFactory.itemByName(clazz);
        ret.header = Utils.capitalize(item.name());
        ret.icon = new ItemSprite(item);
        return ret;
    }
    if (category.equals(MOB)) {
        Mob mob = MobFactory.mobByName(clazz);
        ret.header = Utils.capitalize(mob.getName());
        ret.icon = new CompositeTextureImage();
        ((CompositeTextureImage) ret.icon).copy(mob.sprite().avatar());
        return ret;
    }
    throw new TrackedRuntimeException("unknown category: " + category);
}
Also used : Item(com.watabou.pixeldungeon.items.Item) WndInfoItem(com.watabou.pixeldungeon.windows.WndInfoItem) WndInfoMob(com.watabou.pixeldungeon.windows.WndInfoMob) Mob(com.watabou.pixeldungeon.actors.mobs.Mob) CompositeTextureImage(com.watabou.noosa.CompositeTextureImage) TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) ItemSprite(com.watabou.pixeldungeon.sprites.ItemSprite)

Example 5 with TrackedRuntimeException

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

the class Library method saveLibrary.

public static void saveLibrary() {
    if (!saveNeeded) {
        return;
    }
    saveNeeded = false;
    gson.toJson(mKnowledgeLevel);
    try {
        OutputStream output = FileSystem.getOutputStream(LIBRARY_FILE);
        output.write(gson.toJson(mKnowledgeLevel).getBytes());
        output.close();
    } catch (IOException e) {
        throw new TrackedRuntimeException(e);
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

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