Changed type to group
This commit is contained in:
parent
a60c9fd5f0
commit
bf70fe8d25
1 changed files with 31 additions and 31 deletions
|
@ -18,87 +18,87 @@ import cr0s.warpdrive.conf.WarpDriveConfig;
|
|||
|
||||
|
||||
public class StructureManager {
|
||||
|
||||
|
||||
private static ArrayList<Star> stars = new ArrayList<Star>();
|
||||
private static ArrayList<Planetoid> moons = new ArrayList<Planetoid>();
|
||||
private static ArrayList<Planetoid> gasClouds = new ArrayList<Planetoid>();
|
||||
|
||||
|
||||
public static void loadStructures(String structureConfDir) {
|
||||
loadStructures(new File(structureConfDir));
|
||||
}
|
||||
|
||||
|
||||
public static void loadStructures(File dir) {
|
||||
|
||||
|
||||
dir.mkdir();
|
||||
|
||||
|
||||
if (!dir.isDirectory()) {
|
||||
throw new IllegalArgumentException("File path " + dir.getPath() + " must be a directory!");
|
||||
}
|
||||
|
||||
|
||||
File[] files = dir.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file_notUsed, String name) {
|
||||
return name.startsWith("structure") && name.endsWith(".xml");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
for (File file : files) {
|
||||
try {
|
||||
|
||||
|
||||
WarpDrive.logger.info("Loading structure data file " + file.getPath());
|
||||
|
||||
|
||||
loadXmlStructureFile(file);
|
||||
|
||||
|
||||
WarpDrive.logger.info("Finished loading structure data file " + file.getPath());
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
WarpDrive.logger.error("Error loading file " + file.getPath() + ": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void loadXmlStructureFile(File f) throws SAXException, IOException, InvalidXmlException {
|
||||
Document base = WarpDriveConfig.getXmlDocumentBuilder().parse(f);
|
||||
|
||||
String res = ModRequirementChecker.checkModRequirements(base.getDocumentElement());
|
||||
|
||||
String res = ModRequirementChecker.checkModRequirements(base.getDocumentElement());
|
||||
|
||||
if (!res.isEmpty()) {
|
||||
WarpDrive.logger.info("Skippping structure data file " + f.getPath() + " because the mods " + res + " are not loaded");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ModRequirementChecker.doModReqSanitation(base);
|
||||
|
||||
|
||||
NodeList structures = base.getElementsByTagName("structure");
|
||||
for (int i = 0; i < structures.getLength(); i++) {
|
||||
|
||||
|
||||
Element struct = (Element) structures.item(i);
|
||||
|
||||
String type = struct.getAttribute("type");
|
||||
|
||||
String group = struct.getAttribute("group");
|
||||
String name = struct.getAttribute("name");
|
||||
|
||||
if(type.isEmpty())
|
||||
throw new InvalidXmlException("Structure must have a type!");
|
||||
|
||||
|
||||
if (group.isEmpty())
|
||||
throw new InvalidXmlException("Structure must have a group!");
|
||||
|
||||
int radius;
|
||||
try {
|
||||
radius = Integer.parseInt(struct.getAttribute("radius"));
|
||||
} catch(NumberFormatException e) {
|
||||
throw new InvalidXmlException("Structure radius is invalid!");
|
||||
}
|
||||
|
||||
if (type.equalsIgnoreCase("star")) {
|
||||
|
||||
if (group.equalsIgnoreCase("star")) {
|
||||
Star s = new Star(radius);
|
||||
s.loadFromXmlElement(struct);
|
||||
stars.add(s);
|
||||
} else if(type.equalsIgnoreCase("moon")) {
|
||||
} else if (group.equalsIgnoreCase("moon")) {
|
||||
Planetoid pl = new Planetoid(radius);
|
||||
pl.loadFromXmlElement(struct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static DeployableStructure getStructure(Random random, final String name, final String type) {
|
||||
if (name == null || name.length() == 0) {
|
||||
if (type == null || type.length() == 0) {
|
||||
|
@ -114,19 +114,19 @@ public class StructureManager {
|
|||
return star;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// not found or nothing defined => return null
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static DeployableStructure getStar(Random random, final String name) {
|
||||
return getStructure(random, name, "star");
|
||||
}
|
||||
|
||||
|
||||
public static DeployableStructure getMoon(Random random, final String name) {
|
||||
return getStructure(random, name, "moon");
|
||||
}
|
||||
|
||||
|
||||
public static DeployableStructure getGasCloud(Random random, final String name) {
|
||||
return getStructure(random, name, "cloud");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue