Fixed Bugs in DungeonHelper
1. Added converting dungeon type names to lowercase before adding them to dungeonTypeMapping (a HashMap that associates dungeon type strings with their lists). Keeping the original casing was causing a NullPointerException when the HashMap returned null and we expected to receive a non-null list. 2. Added code to strip out the file extension of a schematic in validateSchematicName(). The extension was getting dragged along with the dungeon's weight, which would cause parsing to fail and the name was considered invalid. This means that none of the custom dungeons were being registered for generation since the system saw them as badly tagged. They also wouldn't generate Monoliths even if tagged as closed because we would ignore the tags. 3. Changed a comparison for the "open" tag to be case insensitive. 4. Minor changes
This commit is contained in:
parent
3ad7a3b5a2
commit
bbb39da808
1 changed files with 17 additions and 12 deletions
|
@ -91,14 +91,15 @@ public class DungeonHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add all the basic dungeon types to dungeonTypeMapping
|
//Add all the basic dungeon types to dungeonTypeMapping
|
||||||
|
//Dungeon type names must be passed in lowercase to make matching easier.
|
||||||
dungeonTypeMapping = new HashMap<String, ArrayList<DungeonGenerator>>();
|
dungeonTypeMapping = new HashMap<String, ArrayList<DungeonGenerator>>();
|
||||||
dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE, simpleHalls);
|
dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE.toLowerCase(), simpleHalls);
|
||||||
dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE, complexHalls);
|
dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE.toLowerCase(), complexHalls);
|
||||||
dungeonTypeMapping.put(HUB_DUNGEON_TYPE, hubs);
|
dungeonTypeMapping.put(HUB_DUNGEON_TYPE.toLowerCase(), hubs);
|
||||||
dungeonTypeMapping.put(EXIT_DUNGEON_TYPE, exits);
|
dungeonTypeMapping.put(EXIT_DUNGEON_TYPE.toLowerCase(), exits);
|
||||||
dungeonTypeMapping.put(DEAD_END_DUNGEON_TYPE, deadEnds);
|
dungeonTypeMapping.put(DEAD_END_DUNGEON_TYPE.toLowerCase(), deadEnds);
|
||||||
dungeonTypeMapping.put(MAZE_DUNGEON_TYPE, mazes);
|
dungeonTypeMapping.put(MAZE_DUNGEON_TYPE.toLowerCase(), mazes);
|
||||||
dungeonTypeMapping.put(TRAP_DUNGEON_TYPE, pistonTraps);
|
dungeonTypeMapping.put(TRAP_DUNGEON_TYPE.toLowerCase(), pistonTraps);
|
||||||
|
|
||||||
//Load our reference to the DDProperties singleton
|
//Load our reference to the DDProperties singleton
|
||||||
if (properties == null)
|
if (properties == null)
|
||||||
|
@ -162,13 +163,17 @@ public class DungeonHelper
|
||||||
|
|
||||||
public boolean isCustomDungeon(int dimensionID)
|
public boolean isCustomDungeon(int dimensionID)
|
||||||
{
|
{
|
||||||
//TODO: Should we simply treat all pocket dimensions as valid custom dungeons? ~SenseiKiwi
|
|
||||||
return customDungeonStatus.containsKey(dimensionID);
|
return customDungeonStatus.containsKey(dimensionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean validateSchematicName(String name)
|
public boolean validateSchematicName(String name)
|
||||||
{
|
{
|
||||||
String[] dungeonData = name.split("_");
|
String[] dungeonData;
|
||||||
|
|
||||||
|
if (!name.endsWith(SCHEMATIC_FILE_EXTENSION))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_");
|
||||||
|
|
||||||
//Check for a valid number of parts
|
//Check for a valid number of parts
|
||||||
if (dungeonData.length < 3 || dungeonData.length > 4)
|
if (dungeonData.length < 3 || dungeonData.length > 4)
|
||||||
|
@ -210,17 +215,17 @@ public class DungeonHelper
|
||||||
String path = schematicFile.getAbsolutePath();
|
String path = schematicFile.getAbsolutePath();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (name.endsWith(SCHEMATIC_FILE_EXTENSION) && validateSchematicName(name))
|
if (validateSchematicName(name))
|
||||||
{
|
{
|
||||||
//Strip off the file extension while splitting the file name
|
//Strip off the file extension while splitting the file name
|
||||||
String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_");
|
String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_");
|
||||||
|
|
||||||
String dungeonType = dungeonData[0].toLowerCase();
|
String dungeonType = dungeonData[0].toLowerCase();
|
||||||
boolean open = dungeonData[2].equals("open");
|
boolean isOpen = dungeonData[2].equalsIgnoreCase("open");
|
||||||
int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT;
|
int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT;
|
||||||
|
|
||||||
//Add this custom dungeon to the list corresponding to its type
|
//Add this custom dungeon to the list corresponding to its type
|
||||||
DungeonGenerator generator = new DungeonGenerator(weight, path, open);
|
DungeonGenerator generator = new DungeonGenerator(weight, path, isOpen);
|
||||||
|
|
||||||
dungeonTypeMapping.get(dungeonType).add(generator);
|
dungeonTypeMapping.get(dungeonType).add(generator);
|
||||||
registeredDungeons.add(generator);
|
registeredDungeons.add(generator);
|
||||||
|
|
Loading…
Reference in a new issue