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();
}
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);
}
}
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);
}
}
}
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);
}
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);
}
}
Aggregations