Fixed Dungeon Listing and Formatting Bugs

Added a workaround so that the dungeon list produced by
CommandAddDungeonRift does not have repeated names. Also cleaned up the
code a bit - it's a mess in there. Part of the rewrite eliminated the
bug that caused some dungeon names to be preceded by a backslash (or
slash). I've noticed a different bug now - the dungeon tutorial file is
being included in the list of dungeons. I'll be fixing that in the next
commit.
This commit is contained in:
SenseiKiwi
2013-06-17 06:18:15 -04:00
parent 3b88d3a116
commit 17c9118126
2 changed files with 36 additions and 41 deletions

View File

@@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.helpers;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
@@ -657,4 +658,30 @@ public class DungeonHelper
}
dimHelper.dimList.get(incoming.destDimID).dungeonGenerator = dungeon;
}
public Collection<String> getDungeonNames() {
//Use a HashSet to guarantee that all dungeon names will be distinct.
//This shouldn't be necessary if we keep proper lists without repetitions,
//but it's a fool-proof workaround.
HashSet<String> dungeonNames = new HashSet<String>();
dungeonNames.addAll( parseDungeonNames(registeredDungeons) );
dungeonNames.addAll( parseDungeonNames(customDungeons) );
return dungeonNames;
}
private static ArrayList<String> parseDungeonNames(ArrayList<DungeonGenerator> dungeons)
{
String name;
File schematic;
ArrayList<String> names = new ArrayList<String>(dungeons.size());
for (DungeonGenerator dungeon : dungeons)
{
schematic = new File(dungeon.schematicPath);
name = schematic.getName();
name = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length());
names.add(name);
}
return names;
}
}