/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.bindedobjects.core.loaders;
import transientlibs.bindedobjects.core.datasets.*;
import java.io.File;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.datasets.BindedValue;
import transientlibs.bindedobjects.core.Binding;
import transientlibs.bindedobjects.core.Req;
import transientlibs.bindedobjects.core.Tex;
import transientlibs.processors.tex.AbstractActivator;
import transientlibs.processors.misc.Detonator;
import transientlibs.objects.general.TransientArrayList;
import transientlibs.tex.ActList;
import transientlibs.tex.Branch;
import transientlibs.tex.BranchList;
import transientlibs.tex.ReqList;
import transientlibs.tex.StringAnalyst;
/**
*
* @author kibertoad
*/
public class EventsLoader extends BindedValueLoader{
public boolean isRecurring = false;
//public static Events lastEvent;
//public String group;
//public static TransientArrayList<Events> events = new TransientArrayList<Events>();
public static ReqList globalReqs = new ReqList();
public static ReqList globalActivationReq = new ReqList();
public static ActList globalActs = new ActList();
public static ArrayList<String> globalTags = new ArrayList<String>();
//public static String globalGroup = "-";
public static ReqList mainReqList;
public static ActList mainActList;
// public Branch eval = null;
// public BranchList tex = null;
public EventsLoader(BindedValueContainer container) {
super(container);
}
public BindedValueContainer getContainer (){
return (BindedValueContainer) container;
}
public void loadAllEvents() {
File dir = new File(Detonator.INSTANCE.currentModule.dirName + "events");
String[] fileList = dir.list();
if (fileList == null) {
Log.warn(Detonator.INSTANCE.currentModule.dirName + "events");
Log.warn("Specified directory does not exist!");
} else {
for (int x = 0; x < fileList.length; x++) {
if ((!(fileList[x].equals(".svn"))) && (fileList[x].endsWith(".dat"))) {
Log.info(fileList[x]);
//loadMap("maps/" + fileList[x]);
globalActs.clear();
globalActivationReq.clear();
globalTags.clear();
globalReqs.clear();
globalGroup = "-";
//loadActionFile("events/" + fileList[x]);
loadFromFile("events/" + fileList[x]);
}
}
}
}
//"actions.dat"
/*
public static void loadActionFile(String fromFile) {
if (StringAnalyst.isFileExist(fromFile)) {
StringAnalyst reader = new StringAnalyst();
reader.openFile(fromFile);
while (!reader.eof) {
reader.readRow();
analyzeStringForEvents(reader);
}
reader.closeFile();
}
}
public static void analyzeStringForEvents (StringAnalyst analyst) {
analyzeStringForEffects ("-NO-", analyst);
}
*/
public Events lastEvent (){
return (Events) container.lastElement;
}
@Override
public boolean analyzeString (String getString, StringAnalyst analyst) {
if (!"-NO-".equals(getString)) {analyst.fullStr = getString;}
analyst.getNextString();
String nowStr = analyst.lastStr;
boolean withResult = false;
if (nowStr.equals("event")) {
container.add(new Events ());
container.getID(analyst);
//lastEvent = events.get(events.size()-1);
//lastEvent.ID = analyst.getBinding (Binding.eventBinding);
ReqList.lastReqList = getContainer().getLastElement().reqs;
ActList.lastActList = getContainer().getLastElement().acts;
for (AbstractActivator a : globalActs) {
ActList.lastActList.add(a);
}
for (Req r : globalActivationReq) {
ReqList.lastActiveReqList.add(r);
}
for (Req r : globalReqs) {
ReqList.lastReqList.add(r);
}
for (String s : globalTags) {
getContainer().getLastElement().tags.add(s);
}
if (!"-".equals(globalGroup)) {
getContainer().getLastElement().group = globalGroup;
getContainer().getLastElement().ofType = Binding.getBinding(Binding.eventBinding, globalGroup);
}
//ReqList.lastReqList = lastEffect.trainReqs;
withResult = true;
}
/*
if (nowStr.equals("name")) {
lastEvent.LName.value = analyst.getNextString();
withResult = true;
}
if (nowStr.equals("desc")) {
lastEvent.desc = analyst.restOfRow();
withResult = true;
}
*/
if (nowStr.equals("recurring")) {
lastEvent().isRecurring = analyst.getNextBoolean();
withResult = true;
}
if (nowStr.equals("globalreqs")) {
ReqList.lastReqList = globalReqs;
withResult = true;
}
if (nowStr.equals("globaltag")) {
globalTags.add(analyst.getNextString());
withResult = true;
}
//if (nowStr.equals("globalgroup")) {
// globalGroup = analyst.getNextString();
// withResult = true;
//}
if (nowStr.equals("globalacts")) {
ActList.lastActList = globalActs;
withResult = true;
}
if (nowStr.equals("reqs")) {
ReqList.lastReqList = lastEvent().reqs;
Tex.continousAnalysisForTex(analyst);
withResult = true;
}
/*
if (nowStr.equals("tag")) {
lastEvent.tags.add(analyst.getNextString());
withResult = true;
}
if (nowStr.equals("group")) {
lastEvent.ofType = analyst.getBinding(Binding.actionGroupBinding);
lastEvent.group = analyst.lastStr;
withResult = true;
}
*/
if (nowStr.equals("tex")) {
mainReqList = ReqList.lastReqList;
mainActList = ActList.lastActList;
if (lastEvent().tex == null) {
lastEvent().tex = new BranchList();
BranchList.lastBranchList = lastEvent().tex;
}
Tex.continousAnalysisForTex(analyst);
ReqList.lastReqList = mainReqList;
ActList.lastActList = mainActList;
withResult = true;
}
if (nowStr.equals("eval")) {
mainReqList = ReqList.lastReqList;
mainActList = ActList.lastActList;
if (lastEvent().eval == null) {
//Log.info("added eval branch");
lastEvent().eval = new Branch();
Branch.lastBranch = lastEvent().eval;
//if (Branch.lastBranch == null) {
// Log.error("Branch was not set!");
// }
}
Tex.continousAnalysisForTex(analyst);
ReqList.lastReqList = mainReqList;
ActList.lastActList = mainActList;
withResult = true;
}
if (withResult == false) {
withResult = super.analyzeString(analyst.fullStr, analyst);
}
if ((withResult == false) && (nowStr.length()>2) && (!nowStr.startsWith("//"))) {
Log.error("Unknown string: "+nowStr); }
return withResult;
}
}