Skip to content

Commit

Permalink
Implemented feature #18 : It is now possible to add gameplay features
Browse files Browse the repository at this point in the history
  • Loading branch information
LMH01 committed Mar 15, 2021
1 parent 7bfe6ae commit 36b2b4e
Show file tree
Hide file tree
Showing 6 changed files with 512 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class AnalyzeExistingGameplayFeatures {

private static final Logger LOGGER = LoggerFactory.getLogger(AnalyzeExistingGameplayFeatures.class);
public static List<Map<String, String>> gameplayFeatures;
public static Map<Integer, String> gameplayFeatureNames;
public static int maxGameplayFeatureId = 0;

/**
Expand Down Expand Up @@ -64,9 +63,9 @@ public static String[] getGameplayFeaturesByAlphabet(){
}

/**
* Returns -1 when genre name does not exist.
* Returns -1 when gameplay feature name does not exist.
* @param gameplayFeatureName The gameplay feature name
* @return Returns the genre id for the specified name.
* @return Returns the gameplay feature id for the specified name.
*/
public static int getGameplayFeatureIdByName(String gameplayFeatureName){
int genreId = -1;
Expand All @@ -82,4 +81,20 @@ public static int getGameplayFeatureIdByName(String gameplayFeatureName){
}
return genreId;
}

/**
* @param gameplayFeatureNameEn The gameplay feature for which the map should be returned.
* @return Returns a map containing all values for the specified gameplay feature.
*/
public static Map<String, String> getSingleGameplayFeatureByNameMap(String gameplayFeatureNameEn){
List<Map<String, String>> list = gameplayFeatures;
Map<String, String> mapSingleGenre = null;
int publisherPosition = getGameplayFeatureIdByName(gameplayFeatureNameEn);
for(int i=0; i<list.size(); i++){
if(i == publisherPosition){
mapSingleGenre = list.get(i);
}
}
return mapSingleGenre;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.github.lmh01.mgt2mt.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
Expand All @@ -15,6 +14,105 @@
public class EditGameplayFeaturesFile {
private static final Logger LOGGER = LoggerFactory.getLogger(Settings.class);

/**
* Adds a new genre to the GameplayFeatures.txt file
* @param map The values that stand in this map are used to print the file. This includes the translations.
*/
public static void addGameplayFeature(Map<String, String> map) throws IOException {
AnalyzeExistingGameplayFeatures.analyzeGameplayFeatures();
LOGGER.info("Adding new gameplay feature...");
File gameplayFeatureFile = Utils.getGameplayFeaturesFile();
if(gameplayFeatureFile.exists()){
gameplayFeatureFile.delete();
}
gameplayFeatureFile.createNewFile();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(gameplayFeatureFile), StandardCharsets.UTF_8));
bw.write("\ufeff");
for(Map<String, String> existingGameplayFeatures : AnalyzeExistingGameplayFeatures.gameplayFeatures){
bw.write("[ID]" + existingGameplayFeatures.get("ID"));bw.write(System.getProperty("line.separator"));
bw.write("[TYP]" + existingGameplayFeatures.get("TYP"));bw.write(System.getProperty("line.separator"));
TranslationManager.printLanguages(bw, existingGameplayFeatures);
bw.write("[DATE]" + existingGameplayFeatures.get("DATE"));bw.write(System.getProperty("line.separator"));
bw.write("[RES POINTS]" + existingGameplayFeatures.get("RES POINTS"));bw.write(System.getProperty("line.separator"));
bw.write("[PRICE]" + existingGameplayFeatures.get("PRICE"));bw.write(System.getProperty("line.separator"));
bw.write("[DEV COSTS]" + existingGameplayFeatures.get("DEV COSTS"));bw.write(System.getProperty("line.separator"));
bw.write("[PIC]" + existingGameplayFeatures.get("PIC"));bw.write(System.getProperty("line.separator"));
bw.write("[GAMEPLAY]" + existingGameplayFeatures.get("GAMEPLAY"));bw.write(System.getProperty("line.separator"));
bw.write("[GRAPHIC]" + existingGameplayFeatures.get("GRAPHIC"));bw.write(System.getProperty("line.separator"));
bw.write("[SOUND]" + existingGameplayFeatures.get("SOUND"));bw.write(System.getProperty("line.separator"));
bw.write("[TECH]" + existingGameplayFeatures.get("TECH"));bw.write(System.getProperty("line.separator"));
if(existingGameplayFeatures.get("GOOD") == null){
existingGameplayFeatures.put("GOOD", "");
}
if(existingGameplayFeatures.get("BAD") == null){
existingGameplayFeatures.put("BAD", "");
}
bw.write("[GOOD]" + existingGameplayFeatures.get("GOOD"));bw.write(System.getProperty("line.separator"));
bw.write("[BAD]" + existingGameplayFeatures.get("BAD"));bw.write(System.getProperty("line.separator"));
bw.write(System.getProperty("line.separator"));
}
bw.write("[ID]" + map.get("ID"));bw.write(System.getProperty("line.separator"));
bw.write("[TYP]" + map.get("TYP"));bw.write(System.getProperty("line.separator"));
TranslationManager.printLanguages(bw, map);
bw.write("[DATE]" + map.get("DATE"));bw.write(System.getProperty("line.separator"));
bw.write("[RES POINTS]" + map.get("RES POINTS"));bw.write(System.getProperty("line.separator"));
bw.write("[PRICE]" + map.get("PRICE"));bw.write(System.getProperty("line.separator"));
bw.write("[DEV COSTS]" + map.get("DEV COSTS"));bw.write(System.getProperty("line.separator"));
bw.write("[PIC]" + map.get("PIC"));bw.write(System.getProperty("line.separator"));
bw.write("[GAMEPLAY]" + map.get("GAMEPLAY"));bw.write(System.getProperty("line.separator"));
bw.write("[GRAPHIC]" + map.get("GRAPHIC"));bw.write(System.getProperty("line.separator"));
bw.write("[SOUND]" + map.get("SOUND"));bw.write(System.getProperty("line.separator"));
bw.write("[TECH]" + map.get("TECH"));bw.write(System.getProperty("line.separator"));
bw.write("[GOOD]" + map.get("GOOD"));bw.write(System.getProperty("line.separator"));
bw.write("[BAD]" + map.get("BAD"));bw.write(System.getProperty("line.separator"));
bw.write(System.getProperty("line.separator"));
bw.write("[EOF]");
bw.close();
}

/**
* Removes the input gameplay feature id from the GameplayFeatures.txt file
* @param gameplayFeatureId The gameplay feature id for which the gameplay feature should be removed
*/
public static void removeGameplayFeature(int gameplayFeatureId) throws IOException {
AnalyzeExistingGameplayFeatures.analyzeGameplayFeatures();
LOGGER.info("Adding new gameplay feature...");
File gameplayFeatureFile = Utils.getGameplayFeaturesFile();
if(gameplayFeatureFile.exists()){
gameplayFeatureFile.delete();
}
gameplayFeatureFile.createNewFile();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(gameplayFeatureFile), StandardCharsets.UTF_8));
bw.write("\ufeff");
for(Map<String, String> existingGameplayFeatures : AnalyzeExistingGameplayFeatures.gameplayFeatures){
if(Integer.parseInt(existingGameplayFeatures.get("ID")) != gameplayFeatureId){
bw.write("[ID]" + existingGameplayFeatures.get("ID"));bw.write(System.getProperty("line.separator"));
bw.write("[TYP]" + existingGameplayFeatures.get("TYP"));bw.write(System.getProperty("line.separator"));
TranslationManager.printLanguages(bw, existingGameplayFeatures);
bw.write("[DATE]" + existingGameplayFeatures.get("DATE"));bw.write(System.getProperty("line.separator"));
bw.write("[RES POINTS]" + existingGameplayFeatures.get("RES POINTS"));bw.write(System.getProperty("line.separator"));
bw.write("[PRICE]" + existingGameplayFeatures.get("PRICE"));bw.write(System.getProperty("line.separator"));
bw.write("[DEV COSTS]" + existingGameplayFeatures.get("DEV COSTS"));bw.write(System.getProperty("line.separator"));
bw.write("[PIC]" + existingGameplayFeatures.get("PIC"));bw.write(System.getProperty("line.separator"));
bw.write("[GAMEPLAY]" + existingGameplayFeatures.get("GAMEPLAY"));bw.write(System.getProperty("line.separator"));
bw.write("[GRAPHIC]" + existingGameplayFeatures.get("GRAPHIC"));bw.write(System.getProperty("line.separator"));
bw.write("[SOUND]" + existingGameplayFeatures.get("SOUND"));bw.write(System.getProperty("line.separator"));
bw.write("[TECH]" + existingGameplayFeatures.get("TECH"));bw.write(System.getProperty("line.separator"));
if(existingGameplayFeatures.get("GOOD") == null){
existingGameplayFeatures.put("GOOD", "");
}
if(existingGameplayFeatures.get("BAD") == null){
existingGameplayFeatures.put("BAD", "");
}
bw.write("[GOOD]" + existingGameplayFeatures.get("GOOD"));bw.write(System.getProperty("line.separator"));
bw.write("[BAD]" + existingGameplayFeatures.get("BAD"));bw.write(System.getProperty("line.separator"));
}
}
bw.write(System.getProperty("line.separator"));
bw.write("[EOF]");
bw.close();
}

/**
* Edits the GameplayFeatures.txt file to add genre id to the input gameplay feature
* @param gameplayFeaturesIdsToEdit The map containing the gameplay features where the operation should be executed
Expand Down
Loading

0 comments on commit 36b2b4e

Please sign in to comment.