Fixed Tutorial Listing Bug and Improved Listing
Fixed the bug that caused the dungeon creation tutorial to be listed as a schematic. We were listing all files in the custom schematic directory as a schematic, even though that file wasn't. I added filtering so that we only look at files that end with ".schematic". Also improved dungeon listing by sorting the name list in alphabetical order. That makes the list much easier to read through.
This commit is contained in:
@@ -4,6 +4,7 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -217,16 +218,19 @@ public class DungeonHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importCustomDungeons(String dir)
|
public void importCustomDungeons(String path)
|
||||||
{
|
{
|
||||||
File file = new File(dir);
|
File directory = new File(path);
|
||||||
File[] schematicNames = file.listFiles();
|
File[] schematicNames = directory.listFiles();
|
||||||
|
|
||||||
if (schematicNames != null)
|
if (schematicNames != null)
|
||||||
{
|
{
|
||||||
for (File schematicFile: schematicNames)
|
for (File schematicFile: schematicNames)
|
||||||
{
|
{
|
||||||
this.registerCustomDungeon(schematicFile);
|
if (schematicFile.getName().endsWith(SCHEMATIC_FILE_EXTENSION))
|
||||||
|
{
|
||||||
|
registerCustomDungeon(schematicFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -660,13 +664,18 @@ public class DungeonHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getDungeonNames() {
|
public Collection<String> getDungeonNames() {
|
||||||
|
|
||||||
//Use a HashSet to guarantee that all dungeon names will be distinct.
|
//Use a HashSet to guarantee that all dungeon names will be distinct.
|
||||||
//This shouldn't be necessary if we keep proper lists without repetitions,
|
//This shouldn't be necessary if we keep proper lists without repetitions,
|
||||||
//but it's a fool-proof workaround.
|
//but it's a fool-proof workaround.
|
||||||
HashSet<String> dungeonNames = new HashSet<String>();
|
HashSet<String> dungeonNames = new HashSet<String>();
|
||||||
dungeonNames.addAll( parseDungeonNames(registeredDungeons) );
|
dungeonNames.addAll( parseDungeonNames(registeredDungeons) );
|
||||||
dungeonNames.addAll( parseDungeonNames(customDungeons) );
|
dungeonNames.addAll( parseDungeonNames(customDungeons) );
|
||||||
return dungeonNames;
|
|
||||||
|
//Sort dungeon names alphabetically
|
||||||
|
ArrayList<String> sortedNames = new ArrayList<String>(dungeonNames);
|
||||||
|
Collections.sort(sortedNames);
|
||||||
|
return sortedNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayList<String> parseDungeonNames(ArrayList<DungeonGenerator> dungeons)
|
private static ArrayList<String> parseDungeonNames(ArrayList<DungeonGenerator> dungeons)
|
||||||
|
|||||||
Reference in New Issue
Block a user