Skip to content

Commit

Permalink
Fixed a bug where it would fail when a genre was exported after a gen…
Browse files Browse the repository at this point in the history
…re has been deleted.
  • Loading branch information
LMH01 committed Mar 22, 2021
1 parent 0e8f7f7 commit e1c32fe
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ public static int getFreeGenreID(){
return maxGenreID+1;
}

/**
* @param genreId The genre id for which the position should be returned
* @return Returns the position in the genre list where the input genre id is stored in.
*/
public static int getPositionInGenreListByGenreId(int genreId){
for(int i=0; i<genreList.size(); i++){
if(genreList.get(i).get("ID").equals(Integer.toString(genreId))){
return i;
}
}
return -1;
}

/**
* Writes a help file with genres by id.
*/
Expand Down Expand Up @@ -144,7 +157,12 @@ public static String[] getCustomGenresByAlphabetWithoutId(){
* @throws ArrayIndexOutOfBoundsException Is thrown when the requested genre id does not exist in the map.
*/
public static String getGenreNameById(int id) throws ArrayIndexOutOfBoundsException{
return getGenreNamesInUse().get(id);
for(int i=0; i<genreList.size(); i++){
if(genreList.get(i).get("ID").equals(Integer.toString(id))){
return genreList.get(i).get("NAME EN");
}
}
return "Genre not available";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public class SharingHandler {
*/
public static boolean exportGenre(String genreName) throws IOException {
int genreId = AnalyzeExistingGenres.getGenreIdByName(genreName);
int positionInGenreList = AnalyzeExistingGenres.getPositionInGenreListByGenreId(genreId);
final String EXPORTED_GENRE_MAIN_FOLDER_PATH = Settings.MGT2_MOD_MANAGER_PATH + "//Export//Genres//" + genreName;
final String EXPORTED_GENRE_DATA_FOLDER_PATH = EXPORTED_GENRE_MAIN_FOLDER_PATH + "//DATA//";
File fileDataFolder = new File(EXPORTED_GENRE_DATA_FOLDER_PATH);
File fileExportedGenre = new File(EXPORTED_GENRE_MAIN_FOLDER_PATH + "//genre.txt");
File fileExportedGenreIcon = new File(EXPORTED_GENRE_DATA_FOLDER_PATH + "//icon.png");
File fileGenreIconToExport = new File(Utils.getMGT2GenreIconsPath() + "icon" + AnalyzeExistingGenres.genreList.get(genreId).get("NAME EN").replaceAll(" ", "") + ".png");
File fileGenreIconToExport = new File(Utils.getMGT2GenreIconsPath() + "icon" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("NAME EN").replaceAll(" ", "") + ".png");
File fileGenreScreenshotsToExport = new File(Utils.getMGT2ScreenshotsPath() + genreId);
if(!fileExportedGenreIcon.exists()){
fileDataFolder.mkdirs();
Expand All @@ -50,36 +51,36 @@ public static boolean exportGenre(String genreName) throws IOException {
bw.print("[MGT2MT VERSION]" + MadGamesTycoon2ModTool.VERSION + System.getProperty("line.separator"));
bw.print("[GENRE START]" + System.getProperty("line.separator"));
for(String translationKey : TranslationManager.TRANSLATION_KEYS){
bw.print("[NAME " + translationKey + "]" + AnalyzeExistingGenres.genreList.get(genreId).get("NAME " + translationKey) + System.getProperty("line.separator"));
bw.print("[DESC " + translationKey + "]" + AnalyzeExistingGenres.genreList.get(genreId).get("DESC " + translationKey) + System.getProperty("line.separator"));
}
bw.print("[DATE]" + AnalyzeExistingGenres.genreList.get(genreId).get("DATE") + System.getProperty("line.separator"));
bw.print("[RES POINTS]" + AnalyzeExistingGenres.genreList.get(genreId).get("RES POINTS") + System.getProperty("line.separator"));
bw.print("[PRICE]" + AnalyzeExistingGenres.genreList.get(genreId).get("PRICE") + System.getProperty("line.separator"));
bw.print("[DEV COSTS]" + AnalyzeExistingGenres.genreList.get(genreId).get("DEV COSTS") + System.getProperty("line.separator"));
bw.print("[TGROUP]" + AnalyzeExistingGenres.genreList.get(genreId).get("TGROUP") + System.getProperty("line.separator"));
bw.print("[GAMEPLAY]" + AnalyzeExistingGenres.genreList.get(genreId).get("GAMEPLAY") + System.getProperty("line.separator"));
bw.print("[GRAPHIC]" + AnalyzeExistingGenres.genreList.get(genreId).get("GRAPHIC") + System.getProperty("line.separator"));
bw.print("[SOUND]" + AnalyzeExistingGenres.genreList.get(genreId).get("SOUND") + System.getProperty("line.separator"));
bw.print("[CONTROL]" + AnalyzeExistingGenres.genreList.get(genreId).get("CONTROL") + System.getProperty("line.separator"));
bw.print("[NAME " + translationKey + "]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("NAME " + translationKey) + System.getProperty("line.separator"));
bw.print("[DESC " + translationKey + "]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("DESC " + translationKey) + System.getProperty("line.separator"));
}
bw.print("[DATE]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("DATE") + System.getProperty("line.separator"));
bw.print("[RES POINTS]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("RES POINTS") + System.getProperty("line.separator"));
bw.print("[PRICE]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("PRICE") + System.getProperty("line.separator"));
bw.print("[DEV COSTS]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("DEV COSTS") + System.getProperty("line.separator"));
bw.print("[TGROUP]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("TGROUP") + System.getProperty("line.separator"));
bw.print("[GAMEPLAY]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("GAMEPLAY") + System.getProperty("line.separator"));
bw.print("[GRAPHIC]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("GRAPHIC") + System.getProperty("line.separator"));
bw.print("[SOUND]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("SOUND") + System.getProperty("line.separator"));
bw.print("[CONTROL]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("CONTROL") + System.getProperty("line.separator"));
bw.print("[GENRE COMB]" + getGenreNames(genreId) + System.getProperty("line.separator"));
bw.print("[THEME COMB]" + Utils.getCompatibleThemeIdsForGenre(genreId) + System.getProperty("line.separator"));
bw.print("[FOCUS0]" + AnalyzeExistingGenres.genreList.get(genreId).get("FOCUS0") + System.getProperty("line.separator"));
bw.print("[FOCUS1]" + AnalyzeExistingGenres.genreList.get(genreId).get("FOCUS1") + System.getProperty("line.separator"));
bw.print("[FOCUS2]" + AnalyzeExistingGenres.genreList.get(genreId).get("FOCUS2") + System.getProperty("line.separator"));
bw.print("[FOCUS3]" + AnalyzeExistingGenres.genreList.get(genreId).get("FOCUS3") + System.getProperty("line.separator"));
bw.print("[FOCUS4]" + AnalyzeExistingGenres.genreList.get(genreId).get("FOCUS4") + System.getProperty("line.separator"));
bw.print("[FOCUS5]" + AnalyzeExistingGenres.genreList.get(genreId).get("FOCUS5") + System.getProperty("line.separator"));
bw.print("[FOCUS6]" + AnalyzeExistingGenres.genreList.get(genreId).get("FOCUS6") + System.getProperty("line.separator"));
bw.print("[FOCUS7]" + AnalyzeExistingGenres.genreList.get(genreId).get("FOCUS7") + System.getProperty("line.separator"));
bw.print("[ALIGN0]" + AnalyzeExistingGenres.genreList.get(genreId).get("ALIGN0") + System.getProperty("line.separator"));
bw.print("[ALIGN1]" + AnalyzeExistingGenres.genreList.get(genreId).get("ALIGN1") + System.getProperty("line.separator"));
bw.print("[ALIGN2]" + AnalyzeExistingGenres.genreList.get(genreId).get("ALIGN2") + System.getProperty("line.separator"));
bw.print("[THEME COMB]" + Utils.getCompatibleThemeIdsForGenre(positionInGenreList) + System.getProperty("line.separator"));
bw.print("[FOCUS0]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("FOCUS0") + System.getProperty("line.separator"));
bw.print("[FOCUS1]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("FOCUS1") + System.getProperty("line.separator"));
bw.print("[FOCUS2]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("FOCUS2") + System.getProperty("line.separator"));
bw.print("[FOCUS3]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("FOCUS3") + System.getProperty("line.separator"));
bw.print("[FOCUS4]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("FOCUS4") + System.getProperty("line.separator"));
bw.print("[FOCUS5]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("FOCUS5") + System.getProperty("line.separator"));
bw.print("[FOCUS6]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("FOCUS6") + System.getProperty("line.separator"));
bw.print("[FOCUS7]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("FOCUS7") + System.getProperty("line.separator"));
bw.print("[ALIGN0]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("ALIGN0") + System.getProperty("line.separator"));
bw.print("[ALIGN1]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("ALIGN1") + System.getProperty("line.separator"));
bw.print("[ALIGN2]" + AnalyzeExistingGenres.genreList.get(positionInGenreList).get("ALIGN2") + System.getProperty("line.separator"));
bw.print("[GAMEPLAYFEATURE GOOD]" + Utils.getCompatibleGameplayFeatureIdsForGenre(genreId, true) + System.getProperty("line.separator"));
bw.print("[GAMEPLAYFEATURE BAD]" + Utils.getCompatibleGameplayFeatureIdsForGenre(genreId, false) + System.getProperty("line.separator"));
bw.print("[GENRE END]");
bw.close();
ChangeLog.addLogEntry(17, AnalyzeExistingGenres.genreList.get(genreId).get("NAME EN"));
ChangeLog.addLogEntry(17, AnalyzeExistingGenres.genreList.get(positionInGenreList).get("NAME EN"));
return true;
}

Expand Down Expand Up @@ -519,7 +520,8 @@ public static String importGameplayFeature(String importFolderPath, boolean show
* @return Returns a list of genre names
*/
private static String getGenreNames(int genreId){
String genreNumbersRaw = AnalyzeExistingGenres.genreList.get(genreId).get("GENRE COMB");
int genrePositionInList = AnalyzeExistingGenres.getPositionInGenreListByGenreId(genreId);
String genreNumbersRaw = AnalyzeExistingGenres.genreList.get(genrePositionInList).get("GENRE COMB");
StringBuilder genreNames = new StringBuilder();
int charPositon = 0;
StringBuilder currentNumber = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class SharingManager {
//This class contains functions with which it is easy to export/import things
private static final Logger LOGGER = LoggerFactory.getLogger(SharingManager.class);
public static final String[] GENRE_IMPORT_COMPATIBLE_MOD_TOOL_VERSIONS = {MadGamesTycoon2ModTool.VERSION};
public static final String[] GENRE_IMPORT_COMPATIBLE_MOD_TOOL_VERSIONS = {MadGamesTycoon2ModTool.VERSION,"1.8.3b","1.9.0", "1.10.0"};
public static final String[] PUBLISHER_IMPORT_COMPATIBLE_MOD_TOOL_VERSIONS = {MadGamesTycoon2ModTool.VERSION,"1.6.0", "1.7.0", "1.7.1", "1.8.0", "1.8.1", "1.8.2", "1.8.3", "1.8.3a", "1.9.0", "1.10.0"};
public static final String[] THEME_IMPORT_COMPATIBLE_MOD_TOOL_VERSIONS = {MadGamesTycoon2ModTool.VERSION,"1.8.0", "1.8.1", "1.8.2", "1.8.3", "1.8.3a", "1.9.0", "1.10.0"};
public static final String[] ENGINE_FEATURE_IMPORT_COMPATIBLE_MOD_TOOL_VERSIONS = {MadGamesTycoon2ModTool.VERSION,"1.8.0", "1.8.1", "1.8.2", "1.8.3", "1.8.3a", "1.9.0", "1.10.0"};
Expand Down

0 comments on commit e1c32fe

Please sign in to comment.