/** * Returns a set of all Cannons from the database * * @return */ public ArrayList<Cannon> getAll() { final String SQLGet = "SELECT * FROM cannons"; ArrayList<Cannon> result = new ArrayList<>(); Cursor cursor = db.rawQuery(SQLGet, new String[] {}); try { cursor.moveToFirst(); while (!cursor.isAfterLast()) { Cannon cannon = new Cannon(); cannon.setAttachPoint(new Coordinate(cursor.getString(1))); cannon.setEmitPoint(new Coordinate(cursor.getString(2))); String attackImagePath = cursor.getString(3); int attackImageID = ContentManager.getInstance().loadImage(attackImagePath); if (attackImageID == -1) { Log.i("modelPopulate", "Failed to load image " + attackImagePath); throw new Exception("Cannon failed to populate"); } int attackImageHeight = cursor.getInt(4); int attackImageWidth = cursor.getInt(5); String attackSoundPath = cursor.getString(6); ViewableObject attackViewable = new ViewableObject(attackImagePath, attackImageWidth, attackImageHeight, attackImageID); int attackSoundID = ContentManager.getInstance().loadSound(attackSoundPath); int damage = cursor.getInt(7); cannon.setLaserShot(new Laser(attackViewable, attackSoundPath, attackSoundID, damage)); String imagePath = cursor.getString(8); int imageID = ContentManager.getInstance().loadImage(imagePath); if (imageID == -1) { Log.i("modelPopulate", "Failed to load image " + imagePath); throw new Exception("Cannon failed to populate"); } int imageWidth = cursor.getInt(9); int imageHeight = cursor.getInt(10); cannon.setMainViewableInfo(new ViewableObject(imagePath, imageWidth, imageHeight, imageID)); result.add(cannon); cursor.moveToNext(); } } catch (Exception e) { Log.i("modelPopulate", e.getMessage()); } finally { cursor.close(); } return result; }