private OutputStream getLevelDataOutputStream(LevelData levelData) throws FileNotFoundException { Chapter chapter = levelData.getChapter(); return getLevelResourceFileAsOutputStream( chapter.getPlayMode().getLevelFolderName() + "/" + chapter.getFolderName() + "/" + levelData.getLevelFileName()); }
public LevelData saveLevelData(LevelData levelData) throws FileNotFoundException { PrintWriter writer = new PrintWriter(getLevelDataOutputStream(levelData)); writer.print(levelData.getLevelDataJSON()); writer.close(); String fileName = levelData.getLevelFileName(); Chapter chapter = levelData.getChapter(); for (int i = 0; i < chapter.getLevelDataList().size(); i++) { if (chapter.getLevelDataList().get(i).getLevelFileName().equals(fileName)) { chapter.getLevelDataList().remove(i); chapter.getLevelDataList().add(i, levelData); break; } } return levelData; }
public Scene getNextLevelPlayScene(LevelData currentLevel) { Chapter chapter = currentLevel.getChapter(); List<LevelData> levelList = chapter.getLevelDataList(); if (levelList.indexOf(currentLevel) < levelList.size() - 1) { // Not last level return new PlayScene(levelList.get(levelList.indexOf(currentLevel) + 1)); } else { List<Chapter> chapterList = (currentLevel.getPlayerCount() == 1) ? singlePlayerChapterList : coopModeChapterList; int i = chapterList.indexOf(chapter) + 1; while (i < chapterList.size()) { if (!chapterList.get(i).isUserFolder() && chapterList.get(i).getLevelDataList().size() > 0) { return new PlayScene(chapterList.get(i).getLevelDataList().get(0)); } i++; } } return new MainMenuScene(false); }