Added ability to invert a mod requirement
aka mods="!IC2" means ic2 must not be loaded
This commit is contained in:
parent
1925594177
commit
87ed479f93
3 changed files with 52 additions and 14 deletions
|
@ -1,5 +1,8 @@
|
|||
package cr0s.warpdrive.config;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
@ -18,9 +21,9 @@ public class XmlPreprocessor {
|
|||
* @return A string, which is empty if all the mods are loaded.
|
||||
* @throws InvalidXmlException
|
||||
*/
|
||||
public static String checkModRequirements(Element e) {
|
||||
public static ModCheckResults checkModRequirements(Element e) {
|
||||
|
||||
String missingMods = "";
|
||||
ModCheckResults modErrors = new ModCheckResults();
|
||||
|
||||
for (String mod : e.getAttribute("mods").split(",")) {
|
||||
|
||||
|
@ -30,13 +33,17 @@ public class XmlPreprocessor {
|
|||
if (mod.isEmpty())
|
||||
continue;
|
||||
|
||||
if (!Loader.isModLoaded(mod)) {
|
||||
missingMods = missingMods + mod + ", ";
|
||||
}
|
||||
if (mod.startsWith("!")) {
|
||||
|
||||
if (Loader.isModLoaded(mod.substring(1)))
|
||||
modErrors.addMod(mod, "loaded");
|
||||
|
||||
} else if (!Loader.isModLoaded(mod))
|
||||
modErrors.addMod(mod, "not loaded");
|
||||
|
||||
}
|
||||
|
||||
return missingMods;
|
||||
return modErrors;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,11 +61,11 @@ public class XmlPreprocessor {
|
|||
|
||||
if (child instanceof Element) {
|
||||
|
||||
String res = checkModRequirements((Element) child);
|
||||
ModCheckResults res = checkModRequirements((Element) child);
|
||||
|
||||
if (!res.isEmpty()) {
|
||||
base.removeChild(child);
|
||||
WarpDrive.logger.info("Removed child element " + child.getBaseURI() + " of element " + base.getBaseURI() + " because these mods arent loaded: " + res);
|
||||
WarpDrive.logger.info("Removed child element " + child.getBaseURI() + " of element " + base.getBaseURI() + ", results: " + res);
|
||||
} else {
|
||||
|
||||
doModReqSanitation(child);
|
||||
|
@ -70,4 +77,33 @@ public class XmlPreprocessor {
|
|||
|
||||
}
|
||||
|
||||
public static class ModCheckResults {
|
||||
|
||||
private TreeMap<String, String> mods;
|
||||
|
||||
public ModCheckResults() {
|
||||
mods = new TreeMap<String, String>();
|
||||
}
|
||||
|
||||
public void addMod(String name, String error) {
|
||||
mods.put(name, error);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return mods.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "{";
|
||||
|
||||
for (Entry<String, String> e : mods.entrySet())
|
||||
s = s + e.getKey() + ": " + e.getValue() + ", ";
|
||||
|
||||
return s + "}";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,8 +15,9 @@ import org.xml.sax.SAXException;
|
|||
import scala.actors.threadpool.Arrays;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.config.InvalidXmlException;
|
||||
import cr0s.warpdrive.config.XmlPreprocessor;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.config.XmlPreprocessor;
|
||||
import cr0s.warpdrive.config.XmlPreprocessor.ModCheckResults;
|
||||
|
||||
public class FillerManager {
|
||||
|
||||
|
@ -69,10 +70,10 @@ public class FillerManager {
|
|||
|
||||
Document base = WarpDriveConfig.getXmlDocumentBuilder().parse(file);
|
||||
|
||||
String res = XmlPreprocessor.checkModRequirements(base.getDocumentElement());
|
||||
ModCheckResults res = XmlPreprocessor.checkModRequirements(base.getDocumentElement());
|
||||
|
||||
if (!res.isEmpty()) {
|
||||
WarpDrive.logger.info("Skippping filler data file " + file.getPath() + " because the mods " + res + " are not loaded");
|
||||
WarpDrive.logger.info("Skippping filler data file " + file.getPath() + " because of: " + res);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,9 @@ import org.xml.sax.SAXException;
|
|||
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.config.InvalidXmlException;
|
||||
import cr0s.warpdrive.config.XmlPreprocessor;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.config.XmlPreprocessor;
|
||||
import cr0s.warpdrive.config.XmlPreprocessor.ModCheckResults;
|
||||
|
||||
|
||||
public class StructureManager {
|
||||
|
@ -61,10 +62,10 @@ public class StructureManager {
|
|||
private static void loadXmlStructureFile(File f) throws SAXException, IOException, InvalidXmlException {
|
||||
Document base = WarpDriveConfig.getXmlDocumentBuilder().parse(f);
|
||||
|
||||
String res = XmlPreprocessor.checkModRequirements(base.getDocumentElement());
|
||||
ModCheckResults res = XmlPreprocessor.checkModRequirements(base.getDocumentElement());
|
||||
|
||||
if (!res.isEmpty()) {
|
||||
WarpDrive.logger.info("Skippping structure data file " + f.getPath() + " because the mods " + res + " are not loaded");
|
||||
WarpDrive.logger.info("Skippping structure data file " + f.getPath() + " because of: " + res);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue