/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.bindedobjects.core;
import transientlibs.bindedobjects.core.datasets.LesserBindedValue;
import transientlibs.objects.general.Node;
import transientlibs.tex.ReqList;
import transientlibs.tex.StringAnalyst;
import java.io.File;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.processors.misc.Detonator;
/**
*
* @author kibertoad
*/
public class Module extends LesserBindedValue {
public String dirName;
public static ArrayList<Module> modules = new ArrayList<Module>();
public static Module lastModule;
public static void loadModules() {
String fileName = "data";
if (Detonator.INSTANCE.pathToData != null) {
fileName = Detonator.INSTANCE.pathToData + fileName;
}
File dir = new File(fileName);
String[] fileList = dir.list();
if (fileList == null) {
Log.error("Specified module directory does not exist.");
}
for (int x = 0; x < fileList.length; x++) {
if ((!(fileList[x].equals(".svn")))
&& (!(fileList[x].equals("init")))) {
Log.info(fileList[x]);
loadModule("data/" + fileList[x] + "/");
}
}
// outputAll (modules);
// System.exit(0);
}
public static void loadModule(String fromDir) {
String fileName = fromDir + "module.dat";
String checkFileName = fileName;
if (Detonator.INSTANCE.pathToData != null) {
checkFileName = Detonator.INSTANCE.pathToData + fileName;
}
boolean validFile = (new File(checkFileName)).exists();
if (validFile) {
StringAnalyst reader = new StringAnalyst();
reader.openFile(checkFileName);
// Log.info("add module from dir: "+fromDir);
modules.add(new Module());
lastModule = modules.get(modules.size() - 1);
lastModule.dirName = fromDir;
if (Detonator.INSTANCE.pathToData != null) {
lastModule.dirName = Detonator.INSTANCE.pathToData + lastModule.dirName;
}
while (!reader.eof) {
reader.readRow();
analyzeStringForModules(reader);
}
reader.closeFile();
} else {
Log.info("File: " + fileName + " not found.");
}
}
public static void analyzeStringForModules(StringAnalyst analyst) {
analyzeStringForModules("-NO-", analyst);
}
public static void analyzeStringForModules(String getString, StringAnalyst analyst) {
if (!"-NO-".equals(getString)) {
analyst.fullStr = getString;
}
analyst.checkForAliases();
analyst.getNextString();
String nowStr = analyst.lastStr;
boolean withResult = false;
if (nowStr.equals("module")) {
lastModule.ID = analyst.getBinding(Binding.moduleBinding);
withResult = true;
}
if (nowStr.equals("name")) {
lastModule.LName.value = analyst.restOfRow();
withResult = true;
}
if (nowStr.equals("desc")) {
lastModule.desc = analyst.restOfRow();
withResult = true;
}
if ((withResult == false) && (nowStr.length() > 2) && (!nowStr.startsWith("//"))) {
Log.error("Unknown string: " + nowStr);
}
}
}