diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index f36c3b9..6711eba 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; import java.util.Random; import java.util.regex.Pattern; @@ -25,11 +27,32 @@ public class DungeonHelper { private static DDProperties properties = null; - private Random rand = new Random(); + public static final Pattern NamePattern = Pattern.compile("[A-Za-z0-9_]+"); + private static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; private static final int DEFAULT_DUNGEON_WEIGHT = 100; - - public static Pattern NamePattern = Pattern.compile("[A-Za-z0-9_]+"); + + private static final String HUB_DUNGEON_TYPE = "Hub"; + private static final String TRAP_DUNGEON_TYPE = "Trap"; + private static final String SIMPLE_HALL_DUNGEON_TYPE = "SimpleHall"; + private static final String COMPLEX_HALL_DUNGEON_TYPE = "ComplexHall"; + private static final String EXIT_DUNGEON_TYPE = "Exit"; + private static final String DEAD_END_DUNGEON_TYPE = "DeadEnd"; + private static final String MAZE_DUNGEON_TYPE = "Maze"; + + //The list of dungeon types will be kept as an array for now. If we allow new + //dungeon types in the future, then this can be changed to an ArrayList. + private static final String[] DUNGEON_TYPES = new String[] { + HUB_DUNGEON_TYPE, + TRAP_DUNGEON_TYPE, + SIMPLE_HALL_DUNGEON_TYPE, + COMPLEX_HALL_DUNGEON_TYPE, + EXIT_DUNGEON_TYPE, + DEAD_END_DUNGEON_TYPE, + MAZE_DUNGEON_TYPE + }; + + private Random rand = new Random(); public HashMap customDungeonStatus = new HashMap(); @@ -45,15 +68,33 @@ public class DungeonHelper private ArrayList pistonTraps = new ArrayList(); private ArrayList exits = new ArrayList(); - public ArrayList tagList = new ArrayList(); - public ArrayList metadataFlipList = new ArrayList(); public ArrayList metadataNextList = new ArrayList(); public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true); - + private HashSet dungeonTypeChecker; + private Hashtable> dungeonTypeMapping; + public DungeonHelper() { + //Load the dungeon type checker with the list of all types in lowercase. + //Capitalization matters for matching in a hash set. + dungeonTypeChecker = new HashSet(); + for (String dungeonType : DUNGEON_TYPES) + { + dungeonTypeChecker.add(dungeonType.toLowerCase()); + } + + //Add all the basic dungeon types to dungeonTypeMapping + dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE, simpleHalls); + dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE, complexHalls); + dungeonTypeMapping.put(HUB_DUNGEON_TYPE, hubs); + dungeonTypeMapping.put(EXIT_DUNGEON_TYPE, exits); + dungeonTypeMapping.put(DEAD_END_DUNGEON_TYPE, deadEnds); + dungeonTypeMapping.put(MAZE_DUNGEON_TYPE, mazes); + dungeonTypeMapping.put(TRAP_DUNGEON_TYPE, pistonTraps); + + //Load our reference to the DDProperties singleton if (properties == null) properties = DDProperties.instance(); } @@ -66,8 +107,8 @@ public class DungeonHelper if (dungeonData.length < 3 || dungeonData.length > 4) return false; - //Check if the category is valid - if (!tagList.contains(dungeonData[0])) + //Check if the dungeon type is valid + if (!dungeonTypeChecker.contains(dungeonData[0].toLowerCase())) return false; //Check if the name is valid @@ -99,6 +140,7 @@ public class DungeonHelper public void registerCustomDungeon(File schematicFile) { String name = schematicFile.getName(); + String path = schematicFile.getAbsolutePath(); try { if (name.endsWith(SCHEMATIC_FILE_EXTENSION) && validateSchematicName(name)) @@ -106,58 +148,22 @@ public class DungeonHelper //Strip off the file extension while splitting the file name String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_"); - String path = schematicFile.getAbsolutePath(); + String dungeonType = dungeonData[0].toLowerCase(); boolean open = dungeonData[2].equals("open"); int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT; + + //Add this custom dungeon to the list corresponding to its type + DungeonGenerator generator = new DungeonGenerator(weight, path, open); - //Change this code so that instead of using IFs, we use a hash table mapping (category) -> (list) - /*while(count